Skip to content

Commit 1e8945d

Browse files
author
puhui999
committed
SPU: 新增完善活动优先级拖拽排序
1 parent 01d7842 commit 1e8945d

File tree

4 files changed

+68
-11
lines changed

4 files changed

+68
-11
lines changed

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ VITE_OPEN=true
1111
VITE_APP_TENANT_ENABLE=true
1212

1313
# 验证码的开关
14-
VITE_APP_CAPTCHA_ENABLE=true
14+
VITE_APP_CAPTCHA_ENABLE=false
1515

1616
# 百度统计
1717
VITE_APP_BAIDU_CODE = a1ff8825baa73c3a78eb96aa40325abc

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"pinia": "^2.1.6",
5959
"qrcode": "^1.5.3",
6060
"qs": "^6.11.2",
61+
"sortablejs": "^1.15.0",
6162
"steady-xml": "^0.1.0",
6263
"url": "^0.11.3",
6364
"video.js": "^7.21.5",
@@ -82,10 +83,11 @@
8283
"@types/nprogress": "^0.2.0",
8384
"@types/qrcode": "^1.5.2",
8485
"@types/qs": "^6.9.8",
86+
"@types/sortablejs": "^1.15.4",
8587
"@typescript-eslint/eslint-plugin": "^6.7.2",
8688
"@typescript-eslint/parser": "^6.7.2",
87-
"@unocss/transformer-variant-group": "^0.56.1",
8889
"@unocss/eslint-config": "^0.56.1",
90+
"@unocss/transformer-variant-group": "^0.56.1",
8991
"@vitejs/plugin-legacy": "^4.1.1",
9092
"@vitejs/plugin-vue": "^4.3.4",
9193
"@vitejs/plugin-vue-jsx": "^3.0.2",
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<template>
2+
<div ref="elTagWrappingRef">
3+
<template v-if="activityOrders && activityOrders.length > 0">
4+
<el-tag
5+
v-for="activityType in activityOrders"
6+
:key="activityType"
7+
:type="promotionTypes.find((item) => item.value === activityType)?.colorType"
8+
class="mr-[10px]"
9+
>
10+
{{ promotionTypes.find((item) => item.value === activityType)?.label }}
11+
</el-tag>
12+
</template>
13+
<template v-else>
14+
<el-tag
15+
v-for="type in promotionTypes"
16+
:key="type.value as number"
17+
:type="type.colorType"
18+
class="mr-[10px]"
19+
>
20+
{{ type.label }}
21+
</el-tag>
22+
</template>
23+
</div>
24+
</template>
25+
<script lang="ts" setup>
26+
import Sortable from 'sortablejs'
27+
import type { DictDataType } from '@/utils/dict'
28+
29+
defineOptions({ name: 'ActivityOrdersSort' })
30+
const props = defineProps<{
31+
promotionTypes: DictDataType[]
32+
activityOrders: number[]
33+
}>()
34+
const emit = defineEmits<{
35+
(e: 'update:activityOrders', v: number[])
36+
}>()
37+
const elTagWrappingRef = ref() // elTag 容器 Ref
38+
39+
const initSortable = () => {
40+
new Sortable(elTagWrappingRef.value, {
41+
swapThreshold: 1,
42+
animation: 150,
43+
onEnd: (el) => {
44+
const innerText = el.to.innerText
45+
// 将字符串按换行符分割成数组
46+
const activityOrder = innerText.split('\n')
47+
// 根据字符串中的顺序重新排序数组
48+
const sortedActivityOrder = activityOrder.map((activityName) => {
49+
return props.promotionTypes.find((item) => item.label === activityName)?.value
50+
})
51+
emit('update:activityOrders', sortedActivityOrder as number[])
52+
}
53+
})
54+
}
55+
onMounted(async () => {
56+
await nextTick()
57+
initSortable()
58+
})
59+
</script>

src/views/mall/product/spu/form/OtherSettingsForm.vue

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,11 @@
4141
</el-form-item>
4242
</el-col>
4343
<el-col :span="24">
44-
<!-- TODO @puhui999:tag展示暂时不考虑排序;支持拖动排序 -->
4544
<el-form-item label="活动优先级">
46-
<el-tag
47-
v-for="type in promotionTypes"
48-
:key="type.value as number"
49-
:type="type.colorType"
50-
class="mr-[10px]"
51-
>
52-
{{ type.label }}
53-
</el-tag>
45+
<ActivityOrdersSort
46+
v-model:activity-orders="formData.activityOrders"
47+
:promotion-types="promotionTypes"
48+
/>
5449
</el-form-item>
5550
</el-col>
5651
<el-col :span="24">
@@ -115,6 +110,7 @@ import { copyValueToTarget } from '@/utils'
115110
import { otherSettingsSchema } from './spu.data'
116111
import { DICT_TYPE, DictDataType, getIntDictOptions } from '@/utils/dict'
117112
import CouponSelect from './CouponSelect.vue'
113+
import ActivityOrdersSort from './ActivityOrdersSort.vue'
118114
119115
defineOptions({ name: 'OtherSettingsForm' })
120116

0 commit comments

Comments
 (0)