|
...
|
...
|
@@ -43,20 +43,18 @@ const isRenderDongzuo = ref(false) |
|
|
|
// 标记是否需要删除当前动作组
|
|
|
|
const needDeleteUnit = ref(false)
|
|
|
|
|
|
|
|
// watch(
|
|
|
|
// () => templateStore.replaceId,
|
|
|
|
// (id) => {
|
|
|
|
// if (id) {
|
|
|
|
// needReplaceUnit.value = true
|
|
|
|
// uni.showToast({
|
|
|
|
// title: '已标记替换',
|
|
|
|
// icon: 'success'
|
|
|
|
// })
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// )
|
|
|
|
|
|
|
|
// 原watch不动,补充拉取新数据、替换source.unit
|
|
|
|
// 缓存打开弹窗传入的数据
|
|
|
|
let sourceInfo = ref({
|
|
|
|
unit: null,
|
|
|
|
unitIndex: null,
|
|
|
|
dailyTemplate: null
|
|
|
|
})
|
|
|
|
// 当前操作的unit和下标
|
|
|
|
const currUnit = computed(() => sourceInfo.value.unit || {})
|
|
|
|
const currUnitIndex = computed(() => sourceInfo.value.unitIndex ?? 0)
|
|
|
|
|
|
|
|
//当替换动作的时候, 原watch不动,补充拉取新数据、替换source.unit
|
|
|
|
const replaceCacheUnit = ref(null)
|
|
|
|
watch(
|
|
|
|
() => templateStore.replaceId,
|
|
|
|
async (id) => {
|
|
...
|
...
|
@@ -97,7 +95,29 @@ watch( |
|
|
|
}
|
|
|
|
console.log('newUnit', newUnit);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ============【新增改动】缓存拼装好的替换单元,保存复用============
|
|
|
|
replaceCacheUnit.value = newUnit
|
|
|
|
// =================================================================
|
|
|
|
|
|
|
|
|
|
|
|
sourceInfo.value.unit = newUnit
|
|
|
|
|
|
|
|
// ========== 新增:同步初始化当前unitIndex的Pinia训练记录 ==========
|
|
|
|
const unitIdx = sourceInfo.value.unitIndex
|
|
|
|
const exercises = newUnit.exercises || []
|
|
|
|
let records = {}
|
|
|
|
exercises.forEach(ex => {
|
|
|
|
// 新动作无历史sets,给默认空白一组(和open初始化逻辑统一)
|
|
|
|
records[ex.exerciseId] = [{
|
|
|
|
h: '00', m: '00', s: '00', quickTimeDisplay: '60s',
|
|
|
|
distance: '', weight: '', reps: '', duration: '', restTime: '', isActive: false
|
|
|
|
}]
|
|
|
|
})
|
|
|
|
// 覆盖当前unitIndex的仓库记录
|
|
|
|
trainingStore.saveUnitRecord(unitIdx, { records, userWeight: 70 })
|
|
|
|
// =================================================================
|
|
|
|
|
|
|
|
// 销毁重建dongzuo实现刷新
|
|
|
|
isRenderDongzuo.value = false
|
|
|
|
await nextTick()
|
|
...
|
...
|
@@ -106,49 +126,7 @@ watch( |
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// 缓存打开弹窗传入的数据
|
|
|
|
let sourceInfo = ref({
|
|
|
|
unit: null,
|
|
|
|
unitIndex: null,
|
|
|
|
dailyTemplate: null
|
|
|
|
})
|
|
|
|
// 当前操作的unit和下标
|
|
|
|
const currUnit = computed(() => sourceInfo.value.unit || {})
|
|
|
|
const currUnitIndex = computed(() => sourceInfo.value.unitIndex ?? 0)
|
|
|
|
|
|
|
|
// 格式化数据:统一 动作 / 超级组 结构 → 给 dongzuo 组件用
|
|
|
|
// const formatDongzuoData = (unit) => {
|
|
|
|
// if (!unit) return {}
|
|
|
|
// console.log('++每日模板的unit++', unit);
|
|
|
|
|
|
|
|
// if (unit.unitType === 1) {
|
|
|
|
// const ex = unit.exercises?.[0] || {}
|
|
|
|
// return {
|
|
|
|
// id: ex.exerciseId,
|
|
|
|
// name: ex.exerciseName,
|
|
|
|
// urlImage: ex.url3dAnimation,
|
|
|
|
// exerciseType: ex.exerciseType,
|
|
|
|
// categoryDescription: ex.categoryDescription || '',
|
|
|
|
// equipmentDescription: ex.equipmentDescription || '',
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (unit.unitType === 2) {
|
|
|
|
// return {
|
|
|
|
// id: unit.unitId,
|
|
|
|
// name: unit.unitName || '超级组',
|
|
|
|
// exercises: unit.exercises?.map(ex => ({
|
|
|
|
// id: ex.exerciseId,
|
|
|
|
// name: ex.exerciseName,
|
|
|
|
// urlImage: ex.url3dAnimation,
|
|
|
|
// exerciseType: ex.exerciseType,
|
|
|
|
// })) || []
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return {}
|
|
|
|
// }
|
|
|
|
// 格式化传入动作组件的unit
|
|
|
|
const formatDongzuoData = (unit) => {
|
|
|
|
if (!unit) return {}
|
|
|
|
console.log('++每日模板的unit++', unit);
|
|
...
|
...
|
@@ -183,6 +161,8 @@ const formatDongzuoData = (unit) => { |
|
|
|
console.log('格式化后结果:', result) // 打印最终数据
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
const handleDeleteAction = () => {
|
|
|
|
console.log('父组件处理删除动作')
|
|
|
|
needDeleteUnit.value = true
|
|
...
|
...
|
@@ -262,10 +242,12 @@ const closePop = () => { |
|
|
|
|
|
|
|
// 【保存修改:核心,组装参数调用更新接口】
|
|
|
|
const saveEdit = async () => {
|
|
|
|
if (!dongzuoSingleRef.value) return uni.showToast({ title: '获取数据失败', icon: 'none' })
|
|
|
|
if (!dongzuoSingleRef.value)
|
|
|
|
return uni.showToast({ title: '获取数据失败', icon: 'none' })
|
|
|
|
|
|
|
|
const { unit, unitIndex, dailyTemplate } = sourceInfo.value
|
|
|
|
|
|
|
|
// ================== 新增:删除逻辑 ==================
|
|
|
|
// ================== 删除逻辑 ==================
|
|
|
|
if (needDeleteUnit.value) {
|
|
|
|
// 1. 复制所有 unit,删掉当前这个
|
|
|
|
const allUnits = [...dailyTemplate.units]
|
|
...
|
...
|
@@ -290,112 +272,19 @@ const saveEdit = async () => { |
|
|
|
// 直接 return,不执行后面的修改逻辑
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// ====================================================
|
|
|
|
|
|
|
|
// ========================替换
|
|
|
|
if (needReplaceUnit.value) {
|
|
|
|
const replaceId = templateStore.replaceId
|
|
|
|
const replaceType = templateStore.replaceType
|
|
|
|
// ========================替换==================
|
|
|
|
// =========【新增:替换动作分支,覆盖基础unit】=========
|
|
|
|
let baseUnit = { ...unit }
|
|
|
|
|
|
|
|
if (!replaceId || !replaceType) {
|
|
|
|
uni.showToast({ title: '替换异常', icon: 'none' })
|
|
|
|
return
|
|
|
|
if (needReplaceUnit.value && replaceCacheUnit.value) {
|
|
|
|
// 使用watch提前缓存好的替换单元作为基础载体
|
|
|
|
baseUnit = { ...replaceCacheUnit.value }
|
|
|
|
}
|
|
|
|
// =====================================================
|
|
|
|
|
|
|
|
try {
|
|
|
|
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) {
|
|
|
|
uni.showToast({ title: '获取动作详情失败', icon: 'none' })
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// ======================
|
|
|
|
// 组装 newUnit
|
|
|
|
// ======================
|
|
|
|
let newUnit = null
|
|
|
|
if (replaceType === 1) {
|
|
|
|
newUnit = {
|
|
|
|
unitType: 1,
|
|
|
|
unitId: detail.id,
|
|
|
|
unitName: detail.name,
|
|
|
|
exercises: [
|
|
|
|
{
|
|
|
|
exerciseId: detail.id,
|
|
|
|
exerciseName: detail.name,
|
|
|
|
exerciseType: detail.exerciseType,
|
|
|
|
urlImage: detail.url3dAnimation || detail.exerciseCover,
|
|
|
|
// urlImage: detail.urlImage || detail.url3dAnimation,
|
|
|
|
categoryDescription: detail.categoryDescription || '',
|
|
|
|
equipmentDescription: detail.equipmentDescription || '',
|
|
|
|
sets: []
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
} else if (replaceType === 2) {
|
|
|
|
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.url3dAnimation || e.exerciseCover,
|
|
|
|
sets: []
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ======================
|
|
|
|
// 替换到模板数组
|
|
|
|
// ======================
|
|
|
|
const allUnits = [...dailyTemplate.units]
|
|
|
|
allUnits[unitIndex] = newUnit
|
|
|
|
|
|
|
|
console.log('allUnits[unitIndex]=', allUnits[unitIndex]);
|
|
|
|
|
|
|
|
await dailytemplateApi.updateDailyTemplate({
|
|
|
|
dailyTemplateId: dailyTemplate.id,
|
|
|
|
units: allUnits
|
|
|
|
})
|
|
|
|
|
|
|
|
uni.showToast({ title: '替换成功', icon: 'success' })
|
|
|
|
needReplaceUnit.value = false
|
|
|
|
emit('saveSuccess')
|
|
|
|
closePop()
|
|
|
|
return
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
uni.showToast({ title: '替换失败', icon: 'none' })
|
|
|
|
} finally {
|
|
|
|
// 最后清空
|
|
|
|
templateStore.clearReplaceAction()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 动作替换
|
|
|
|
|
|
|
|
let targetExercises = [...unit.exercises]
|
|
|
|
let targetExercises = [...baseUnit.exercises]
|
|
|
|
if (unit.unitType === 1) {
|
|
|
|
// 单动作:exercises只有1个
|
|
|
|
const exItem = targetExercises[0]
|
...
|
...
|
|