@xuekl/cli-components 1.5.2 → 1.5.3
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/XklSelect.vue +24 -13
- package/package.json +1 -1
package/XklSelect.vue
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<el-select style="width: 100%;" @change="changeHandle">
|
|
2
|
+
<el-select v-model="selectData" style="width: 100%;" @change="changeHandle">
|
|
3
3
|
<el-option v-for="item in dataList" :key="item.id" :label="item.label" :value="item.value"></el-option>
|
|
4
4
|
</el-select>
|
|
5
5
|
</template>
|
|
@@ -9,15 +9,24 @@ export default {
|
|
|
9
9
|
}
|
|
10
10
|
</script>
|
|
11
11
|
<script setup lang="ts">
|
|
12
|
-
import { onBeforeMount, ref, Ref, watch } from 'vue'
|
|
12
|
+
import { onBeforeMount, ref, Ref, watch, computed } from 'vue'
|
|
13
13
|
import { SelectItem } from '@xuekl/cli-base/type.d'
|
|
14
14
|
import http from "@/utils/httpRequest"
|
|
15
|
-
const props = defineProps(['config', 'list'])
|
|
16
|
-
const emit = defineEmits(['update:label', 'loaded'])
|
|
15
|
+
const props = defineProps(['config', 'list', 'modelValue'])
|
|
16
|
+
const emit = defineEmits(['update:label', 'loaded', 'update:modelValue'])
|
|
17
17
|
const { config, list } = props
|
|
18
18
|
|
|
19
19
|
const dataList: Ref<SelectItem[]> = ref([])
|
|
20
20
|
|
|
21
|
+
const selectData = computed({
|
|
22
|
+
get() {
|
|
23
|
+
return dataList.value.length ? props.modelValue : ''
|
|
24
|
+
},
|
|
25
|
+
set(val) {
|
|
26
|
+
emit('update:modelValue', val)
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
|
|
21
30
|
const changeHandle = (val: string) => {
|
|
22
31
|
const item = dataList.value.find(res => res.value === val)
|
|
23
32
|
if (item) {
|
|
@@ -35,16 +44,18 @@ const handleData = (data) => {
|
|
|
35
44
|
}
|
|
36
45
|
}
|
|
37
46
|
|
|
38
|
-
data
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
47
|
+
if (data) {
|
|
48
|
+
data.forEach(inner => {
|
|
49
|
+
inner.value = inner[config?.valueTarget || 'value']
|
|
50
|
+
if (!split) {
|
|
51
|
+
inner.label = inner[labelTarget || 'label']
|
|
52
|
+
} else {
|
|
53
|
+
inner.label = labels.map(label => inner[label]).join(split)
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
}
|
|
45
57
|
|
|
46
|
-
|
|
47
|
-
return data
|
|
58
|
+
return data || []
|
|
48
59
|
}
|
|
49
60
|
|
|
50
61
|
if (typeof list === 'function') {
|