diff --git a/track-uniapp/src/pages/scan/components/TaskSwipeCards.vue b/track-uniapp/src/pages/scan/components/TaskSwipeCards.vue index 08204e5..96f4d63 100644 --- a/track-uniapp/src/pages/scan/components/TaskSwipeCards.vue +++ b/track-uniapp/src/pages/scan/components/TaskSwipeCards.vue @@ -6,7 +6,7 @@ {{ lanes[currentLane].label }} - 步骤 {{ lanes[currentLane]._cardIdx + 1 }}/{{ lanes[currentLane].cards.length }} + 步骤 {{ getCardIdx(lanes[currentLane]._key) + 1 }}/{{ lanes[currentLane].cards.length }} · ← 左右滑切换分支 → @@ -20,7 +20,7 @@ :style="{ height: swiperHeight + 'px' }" duration="250"> - @@ -85,7 +85,7 @@ + :class="['ss-dot', i === getCardIdx(lanes[currentLane]._key) ? 'ss-dot-active' : '', c._isMain ? 'ss-dot-main' : '']"> {{ i + 1 }} @@ -104,9 +104,17 @@ export default { data() { return { currentLane: 0, + cardIndices: {}, // { laneKey: currentCardIndex } — 独立管理避免computed重置 swiperHeight: 600, }; }, + watch: { + // product 变化时重置所有滑动位置 + product: { + immediate: true, + handler() { this.cardIndices = {}; }, + }, + }, computed: { branchLabelMap() { const map = {}; @@ -133,7 +141,7 @@ export default { const result = []; if (!this.product || !this.product.task_tree) return result; - const mainLane = { _key: 'main', label: '主分支', cards: [], _cardIdx: 0 }; + const mainLane = { _key: 'main', label: '主分支', cards: [] }; const sortTasks = (tasks) => { if (!tasks) return []; @@ -160,7 +168,7 @@ export default { const spawns = t.child_tasks.filter(c => c.task_type === 'SPAWN'); for (const sc of spawns) { const blabel = (this.branchLabelMap && this.branchLabelMap[sc.id]) || '协助分支'; - const branchLane = { _key: 'branch_' + sc.id, label: blabel, cards: [], _cardIdx: 0 }; + const branchLane = { _key: 'branch_' + sc.id, label: blabel, cards: [] }; result.push(branchLane); // 先占坑:父分支排在前面 followMain([sc], branchLane); // 再递归:孙子分支自然排在后面 } @@ -181,10 +189,13 @@ export default { }, methods: { formatUserName, + getCardIdx(laneKey) { return this.cardIndices[laneKey] || 0; }, + setCardIdx(laneKey, idx) { this.$set(this.cardIndices, laneKey, idx); }, onLaneSwipe(e) { this.currentLane = e.detail.current; }, onCardSwipe(e, laneIdx) { - if (this.lanes[laneIdx]) { - this.$set(this.lanes[laneIdx], '_cardIdx', e.detail.current); + const lane = this.lanes[laneIdx]; + if (lane) { + this.setCardIdx(lane._key, e.detail.current); } }, taskCardClass(t) {