vue_zhongyou 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="mobile-sort-bar">
|
|
3
|
+
<div
|
|
4
|
+
v-for="option in normalizedOptions"
|
|
5
|
+
:key="option.value"
|
|
6
|
+
class="sort-item"
|
|
7
|
+
@click="handleSelect(option)"
|
|
8
|
+
>
|
|
9
|
+
<span class="label">{{ option.label }}</span>
|
|
10
|
+
<div class="icons">
|
|
11
|
+
<up-one
|
|
12
|
+
style="margin-bottom: -18px;"
|
|
13
|
+
theme="filled"
|
|
14
|
+
size="18"
|
|
15
|
+
:fill="option.value === currentField && currentOrder === 'asc' ? '#1989fa':'#ddd'"
|
|
16
|
+
/>
|
|
17
|
+
<down-one
|
|
18
|
+
style="margin-top: 5px;margin-bottom: -2px;"
|
|
19
|
+
theme="filled"
|
|
20
|
+
size="18"
|
|
21
|
+
:fill="option.value === currentField && currentOrder === 'desc' ? '#1989fa':'#ddd'"
|
|
22
|
+
/>
|
|
23
|
+
|
|
24
|
+
</div>
|
|
25
|
+
</div>
|
|
26
|
+
</div>
|
|
27
|
+
</template>
|
|
28
|
+
|
|
29
|
+
<script setup>
|
|
30
|
+
import { computed, ref, watch } from 'vue'
|
|
31
|
+
import { UpOne,DownOne } from '@icon-park/vue-next'
|
|
32
|
+
const props = defineProps({
|
|
33
|
+
modelValue: {
|
|
34
|
+
type: Object,
|
|
35
|
+
default: () => ({ field: '', order: 'desc' })
|
|
36
|
+
},
|
|
37
|
+
options: {
|
|
38
|
+
type: Array,
|
|
39
|
+
default: () => []
|
|
40
|
+
},
|
|
41
|
+
defaultOrder: {
|
|
42
|
+
type: String,
|
|
43
|
+
default: 'desc'
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
const emit = defineEmits(['update:modelValue', 'change'])
|
|
48
|
+
|
|
49
|
+
const currentField = ref(props.modelValue.field || props.options[0]?.value || '')
|
|
50
|
+
const currentOrder = ref(props.modelValue.order || props.defaultOrder)
|
|
51
|
+
|
|
52
|
+
const normalizedOptions = computed(() =>
|
|
53
|
+
(props.options.length ? props.options : [{ label: '默认排序', value: 'default' }]).map(
|
|
54
|
+
(item) => ({
|
|
55
|
+
...item,
|
|
56
|
+
value: item.value ?? item.label
|
|
57
|
+
})
|
|
58
|
+
)
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
watch(
|
|
62
|
+
() => props.modelValue,
|
|
63
|
+
(val) => {
|
|
64
|
+
if (!val) return
|
|
65
|
+
if (val.field !== undefined) currentField.value = val.field
|
|
66
|
+
if (val.order !== undefined) currentOrder.value = val.order
|
|
67
|
+
}
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
const emitChange = () => {
|
|
71
|
+
const payload = {
|
|
72
|
+
field: currentField.value,
|
|
73
|
+
order: currentOrder.value
|
|
74
|
+
}
|
|
75
|
+
emit('update:modelValue', payload)
|
|
76
|
+
emit('change', payload)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const handleSelect = (option) => {
|
|
80
|
+
if (currentField.value === option.value) {
|
|
81
|
+
currentOrder.value = currentOrder.value === 'desc' ? 'asc' : 'desc'
|
|
82
|
+
} else {
|
|
83
|
+
currentField.value = option.value
|
|
84
|
+
currentOrder.value = option.defaultOrder || props.defaultOrder
|
|
85
|
+
}
|
|
86
|
+
emitChange()
|
|
87
|
+
}
|
|
88
|
+
</script>
|
|
89
|
+
|
|
90
|
+
<style scoped lang="scss">
|
|
91
|
+
.mobile-sort-bar {
|
|
92
|
+
display: flex;
|
|
93
|
+
align-items: center;
|
|
94
|
+
justify-content: space-between;
|
|
95
|
+
padding: 8px 12px;
|
|
96
|
+
background-color: #fff;
|
|
97
|
+
border-radius: 12px;
|
|
98
|
+
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
|
|
99
|
+
gap: 8px;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.sort-item {
|
|
103
|
+
flex: 1;
|
|
104
|
+
display: flex;
|
|
105
|
+
align-items: center;
|
|
106
|
+
justify-content: center;
|
|
107
|
+
gap: 4px;
|
|
108
|
+
padding: 6px;
|
|
109
|
+
border-radius: 999px;
|
|
110
|
+
color: #666;
|
|
111
|
+
font-size: 14px;
|
|
112
|
+
border: 1px solid transparent;
|
|
113
|
+
|
|
114
|
+
.icons {
|
|
115
|
+
display: flex;
|
|
116
|
+
flex-direction: column;
|
|
117
|
+
line-height: 1;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.icon {
|
|
121
|
+
font-size: 12px;
|
|
122
|
+
color: #c8c9cc;
|
|
123
|
+
&.on {
|
|
124
|
+
color: #1989fa;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
&.active {
|
|
129
|
+
color: #1989fa;
|
|
130
|
+
border-color: rgba(25, 137, 250, 0.2);
|
|
131
|
+
background-color: rgba(25, 137, 250, 0.08);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
</style>
|
|
135
|
+
|