|
...
|
...
|
@@ -43,32 +43,43 @@ const isRenderDongzuo = ref(false) |
|
|
|
// 标记是否需要删除当前动作组
|
|
|
|
const needDeleteUnit = ref(false)
|
|
|
|
|
|
|
|
watch(
|
|
|
|
() => templateStore.replaceId,
|
|
|
|
(id) => {
|
|
|
|
if (id) {
|
|
|
|
needReplaceUnit.value = true
|
|
|
|
uni.showToast({
|
|
|
|
title: '已标记替换',
|
|
|
|
icon: 'success'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
// watch(
|
|
|
|
// () => templateStore.replaceId,
|
|
|
|
// (id) => {
|
|
|
|
// if (id) {
|
|
|
|
// needReplaceUnit.value = true
|
|
|
|
// uni.showToast({
|
|
|
|
// title: '已标记替换',
|
|
|
|
// icon: 'success'
|
|
|
|
// })
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// )
|
|
|
|
|
|
|
|
// 原watch不动,补充拉取新数据、替换source.unit
|
|
|
|
watch(
|
|
|
|
() => templateStore.replaceId,
|
|
|
|
async (id) => {
|
|
|
|
if (id) {
|
|
|
|
console.log('+++++每日模板修改替换++++++');
|
|
|
|
needReplaceUnit.value = true
|
|
|
|
uni.showToast({ title: '已标记替换', icon: 'success' })
|
|
|
|
// 新增代码:拉取新动作,替换弹窗数据源,触发页面刷新
|
|
|
|
const rid = templateStore.replaceId
|
|
|
|
const rtype = templateStore.replaceType
|
|
|
|
|
|
|
|
console.log('rid=', rid, 'rtype=', rtype);
|
|
|
|
|
|
|
|
let res, detail
|
|
|
|
if (rtype === 1) res = await ExercisesApi.getExerciseById(rid)
|
|
|
|
else res = await SupersetsApi.getSupersetsInfo(rid)
|
|
|
|
if (rtype === 1) {
|
|
|
|
res = await ExercisesApi.getExerciseById(rid)
|
|
|
|
console.log('每日模板res=', res);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
res = await SupersetsApi.getSupersetsInfo(rid)
|
|
|
|
console.log('每日模板res=', res);
|
|
|
|
}
|
|
|
|
console.log('每日模板res=', res);
|
|
|
|
detail = res.data
|
|
|
|
// 拼装新unit覆盖原sourceInfo.unit
|
|
|
|
let newUnit
|
|
...
|
...
|
@@ -77,11 +88,14 @@ watch( |
|
|
|
unitType: 1, unitId: detail.id, unitName: detail.name,
|
|
|
|
exercises: [{ exerciseId: detail.id, exerciseName: detail.name, exerciseType: detail.exerciseType, urlImage: detail.url3dAnimation || detail.urlImage, categoryDescription: detail.categoryDescription || '', equipmentDescription: detail.equipmentDescription || '', sets: [] }]
|
|
|
|
}
|
|
|
|
console.log('newUnit', newUnit);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
newUnit = {
|
|
|
|
unitType: 2, unitId: detail.id, unitName: detail.name,
|
|
|
|
exercises: detail.exercises.map(e => ({ exerciseId: e.id, exerciseName: e.name, exerciseType: e.exerciseType, urlImage: e.urlImage || e.url3dAnimation, sets: [] }))
|
|
|
|
exercises: detail.exercises.map(e => ({ exerciseId: e.id, exerciseName: e.name, exerciseType: e.exerciseType, urlImage: e.url3dAnimation || e.exerciseCover, sets: [] }))
|
|
|
|
}
|
|
|
|
console.log('newUnit', newUnit);
|
|
|
|
}
|
|
|
|
sourceInfo.value.unit = newUnit
|
|
|
|
// 销毁重建dongzuo实现刷新
|
|
...
|
...
|
@@ -146,7 +160,7 @@ const formatDongzuoData = (unit) => { |
|
|
|
result = {
|
|
|
|
id: ex.exerciseId,
|
|
|
|
name: ex.exerciseName,
|
|
|
|
urlImage: ex.url3dAnimation,
|
|
|
|
urlImage: ex.url3dAnimation || ex.exerciseCover || ex.urlImage,
|
|
|
|
exerciseType: ex.exerciseType,
|
|
|
|
categoryDescription: ex.categoryDescription || '',
|
|
|
|
equipmentDescription: ex.equipmentDescription || '',
|
|
...
|
...
|
@@ -160,7 +174,7 @@ const formatDongzuoData = (unit) => { |
|
|
|
exercises: unit.exercises?.map(ex => ({
|
|
|
|
id: ex.exerciseId,
|
|
|
|
name: ex.exerciseName,
|
|
|
|
urlImage: ex.url3dAnimation,
|
|
|
|
urlImage: ex.url3dAnimation || ex.exerciseCover || ex.urlImage,
|
|
|
|
exerciseType: ex.exerciseType,
|
|
|
|
})) || []
|
|
|
|
}
|
|
...
|
...
|
@@ -255,6 +269,10 @@ const saveEdit = async () => { |
|
|
|
if (needDeleteUnit.value) {
|
|
|
|
// 1. 复制所有 unit,删掉当前这个
|
|
|
|
const allUnits = [...dailyTemplate.units]
|
|
|
|
if (allUnits.length <= 1) {
|
|
|
|
uni.showToast({ title: '每日模板至少保留1个动作组,无法删除', icon: 'none' })
|
|
|
|
return
|
|
|
|
}
|
|
|
|
allUnits.splice(unitIndex, 1)
|
|
|
|
|
|
|
|
// 2. 调用你原来的保存接口
|
|
...
|
...
|
@@ -288,16 +306,19 @@ const saveEdit = async () => { |
|
|
|
let detail = null
|
|
|
|
|
|
|
|
// ======================
|
|
|
|
// 👇 完全移植你现成的接口逻辑
|
|
|
|
// 👇 完全移植你现成的接口逻辑(动作替换)
|
|
|
|
// ======================
|
|
|
|
if (replaceType === 1) {
|
|
|
|
// 普通动作
|
|
|
|
const res = await ExercisesApi.getExerciseById(replaceId)
|
|
|
|
detail = res.data
|
|
|
|
console.log('detail=', detail);
|
|
|
|
|
|
|
|
} else if (replaceType === 2) {
|
|
|
|
// 超级组
|
|
|
|
const res = await SupersetsApi.getSupersetsInfo(replaceId)
|
|
|
|
detail = res.data
|
|
|
|
console.log('detail=', detail);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!detail) {
|
|
...
|
...
|
@@ -309,7 +330,6 @@ const saveEdit = async () => { |
|
|
|
// 组装 newUnit
|
|
|
|
// ======================
|
|
|
|
let newUnit = null
|
|
|
|
|
|
|
|
if (replaceType === 1) {
|
|
|
|
newUnit = {
|
|
|
|
unitType: 1,
|
|
...
|
...
|
@@ -320,7 +340,8 @@ const saveEdit = async () => { |
|
|
|
exerciseId: detail.id,
|
|
|
|
exerciseName: detail.name,
|
|
|
|
exerciseType: detail.exerciseType,
|
|
|
|
urlImage: detail.urlImage || detail.url3dAnimation,
|
|
|
|
urlImage: detail.url3dAnimation || detail.exerciseCover,
|
|
|
|
// urlImage: detail.urlImage || detail.url3dAnimation,
|
|
|
|
categoryDescription: detail.categoryDescription || '',
|
|
|
|
equipmentDescription: detail.equipmentDescription || '',
|
|
|
|
sets: []
|
|
...
|
...
|
@@ -336,7 +357,7 @@ const saveEdit = async () => { |
|
|
|
exerciseId: e.id,
|
|
|
|
exerciseName: e.name,
|
|
|
|
exerciseType: e.exerciseType,
|
|
|
|
urlImage: e.urlImage || e.url3dAnimation,
|
|
|
|
urlImage: e.url3dAnimation || e.exerciseCover,
|
|
|
|
sets: []
|
|
|
|
}))
|
|
|
|
}
|
|
...
|
...
|
@@ -356,6 +377,7 @@ const saveEdit = async () => { |
|
|
|
})
|
|
|
|
|
|
|
|
uni.showToast({ title: '替换成功', icon: 'success' })
|
|
|
|
needReplaceUnit.value = false
|
|
|
|
emit('saveSuccess')
|
|
|
|
closePop()
|
|
|
|
return
|
|
...
|
...
|
@@ -368,6 +390,11 @@ const saveEdit = async () => { |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 动作替换
|
|
|
|
|
|
|
|
let targetExercises = [...unit.exercises]
|
|
|
|
if (unit.unitType === 1) {
|
|
|
|
// 单动作:exercises只有1个
|
...
|
...
|
|