dongzuo-paixu.vue
6.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<template>
<view>
<!-- 动作排序弹窗 -->
<up-popup :show="actionSortShow" mode="bottom" bgColor="#242424" round="24rpx">
<view class="action-sort-popup">
<view class="sort-header">
<view class="operate">
<view class="close" @click="actionSortShow = false">
<up-icon name="close" color="#fff" size="20"></up-icon>
</view>
<view class="title">动作排序</view>
<view class="add" @click="addActionsPopup">
<up-icon name="plus" color="#F2DC0B" size="15"></up-icon>
<text>添加</text>
</view>
</view>
</view>
<scroll-view scroll-y class="sort-scroll-view" :scroll-with-animation="true">
<view v-for="(item, index) in sortList" :key="item.unitId || index" class="drag-item-card">
<view class="item-left">
<up-icon name="trash" color="#fff" size="22" @click="deleteUnit(item, index)"></up-icon>
<image class="item-img" :src="item.exercises?.[0]?.url3dAnimation || item.exercises?.[0]?.exerciseCover ||
item.exercises?.[0]?.urlImage" v-if="item.unitType === 1" mode="aspectFill" />
<image class="item-img"
src="https://fitness-hcxtec-bucket.oss-cn-shenzhen.aliyuncs.com/20260507/超级组_1778117889451.png" v-else
mode="aspectFill" />
<view class="item-info">
<view class="item-name">{{ item.unitName || item.exercises?.[0]?.exerciseName || '未命名动作' }}</view>
<view class="item-tags" v-if="item.unitType === 2">超级组</view>
<view class="item-tags" v-if="item.unitType === 1">
{{ item.exercises?.[0]?.categoryDescription || '' }}
{{ item.exercises?.[0]?.equipmentDescription || '' }}
</view>
</view>
</view>
<view class="item-right">
<up-icon name="plus-circle" color="#666" size="22" @click="copyUnit(item, index)"></up-icon>
</view>
</view>
</scroll-view>
</view>
</up-popup>
<!-- 动作新增组件 -->
<!-- <addActions :show="addActionsShow" @close="addActionsShow = false" /> -->
</view>
</template>
<script setup>
import { ref } from 'vue';
import { useTrainingStore } from '@/sheep/store/trainingStore'
const emit = defineEmits(['open-add-actions'])
const trainingStore = useTrainingStore()
// --- 动作排序 ---弹窗
const actionSortShow = ref(false);
const sortList = ref([])
// 这里是打开动作排序的方法
const openActionSort = () => {
sortList.value = trainingStore.actionDetail?.units?.map((unit, index) => ({
...unit,
exercises: unit.exercises || []
})) || [];
actionSortShow.value = true;
console.log('打印排序列表:', sortList.value);
};
// const addActionsPopup = () => {
// if (actionSortShow.value === true) {
// actionSortShow.value = false
// }
// console.log("==================== 点击了加号!")
// addActionsShow.value = true // 打开弹窗
// console.log("✅ 弹窗打开:", addActionsShow.value)
// }
const addActionsPopup = () => {
actionSortShow.value = false
// 不在这里打开,而是通知父页面
emit('open-add-actions')
}
const deleteUnit = (item, index) => {
console.log('🗑️ 点击删除:', item)
console.log('🗑️ 删除索引:', index)
uni.showModal({
title: '确认删除',
content: `确定要删除【${item.unitName}】吗?`,
success: (res) => {
if (res.confirm) {
console.log('✅ 用户确认删除')
sortList.value.splice(index, 1)
trainingStore.actionDetail.units.splice(index, 1)
console.log('✅ 删除后剩余 units:', trainingStore.actionDetail.units)
} else {
console.log('❌ 用户取消删除')
}
}
})
}
// 复制当前 unit,并插入到下方
const copyUnit = (item, index) => {
console.log('📋 点击复制:', item)
console.log('📋 复制索引:', index)
const newUnit = JSON.parse(JSON.stringify(item))
sortList.value.splice(index + 1, 0, newUnit)
trainingStore.actionDetail.units.splice(index + 1, 0, newUnit)
console.log('✅ 复制成功!当前列表:', sortList.value)
uni.showToast({
title: '已复制到下方',
icon: 'success'
})
}
defineExpose({
openActionSort
})
</script>
<style lang="scss" scoped>
/* ========== 拖拽排序 优化样式 ========== */
.action-sort-popup {
width: 100%;
height: 80vh;
display: flex;
flex-direction: column;
background: #242424;
border-radius: 20rpx 20rpx 0 0;
}
.sort-header {
padding: 30rpx;
color: #fff;
height: 10vh;
box-sizing: border-box;
.operate {
display: flex;
align-items: center;
justify-content: space-between;
.title {
font-size: 32rpx;
font-weight: bold;
}
.add {
display: flex;
align-items: center;
color: #f2dc0b;
font-size: 26rpx;
gap: 8rpx;
}
}
// .tip {
// font-size: 24rpx;
// color: #8e8e93;
// margin-top: 16rpx;
// }
}
.sort-scroll-view {
height: 70vh;
}
// .drag-area {
// width: 100%;
// position: relative;
// }
// .drag-view {
// width: 100%;
// position: absolute;
// transition: transform 0.2s ease;
// }
/* 拖拽项卡片 */
.drag-item-card {
width: 100%;
background: #2c2c2e;
border-radius: 16rpx;
padding: 24rpx;
margin-bottom: 16rpx;
display: flex;
align-items: center;
justify-content: space-between;
box-sizing: border-box;
transition: all 0.2s ease;
border: 2rpx solid transparent;
}
/* 拖拽中高亮效果 */
.drag-item-card.is-active {
background: #3a3a3c;
border-color: #fbdf09;
transform: scale(1.02);
box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.4);
}
.item-left {
display: flex;
align-items: center;
gap: 20rpx;
}
.item-img {
width: 120rpx;
height: 120rpx;
border-radius: 12rpx;
object-fit: cover;
}
.item-info {
display: flex;
flex-direction: column;
gap: 8rpx;
}
.item-name {
font-size: 28rpx;
color: #fff;
font-weight: 500;
}
.item-tags {
font-size: 22rpx;
color: #8e8e93;
}
.item-right {
display: flex;
align-items: center;
gap: 30rpx;
}
/* 拖拽手柄 */
.drag-handle {
padding: 20rpx;
/* 增大点击区域 */
color: #8e8e93;
transition: all 0.2s ease;
display: flex;
align-items: center;
justify-content: center;
}
/* 激活状态下的高亮 */
.drag-item-card.is-active .drag-handle {
color: #fbdf09;
transform: scale(1.1);
}
/* 提示用户可长按 */
.drag-handle:active {
opacity: 0.7;
}
</style>