@xuekl/cli-components 1.5.2 → 1.5.4

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.
Files changed (2) hide show
  1. package/XklSelect.vue +25 -13
  2. 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,19 +9,29 @@ 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', 'itemChange'])
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) {
24
33
  emit('update:label', item.label)
34
+ emit('itemChange', item)
25
35
  }
26
36
  }
27
37
 
@@ -35,16 +45,18 @@ const handleData = (data) => {
35
45
  }
36
46
  }
37
47
 
38
- data.forEach(inner => {
39
- inner.value = inner[config?.valueTarget || 'value']
40
- if (!split) {
41
- inner.label = inner[labelTarget || 'label']
42
- } else {
43
- inner.label = labels.map(label => inner[label]).join(split)
44
- }
48
+ if (data) {
49
+ data.forEach(inner => {
50
+ inner.value = inner[config?.valueTarget || 'value']
51
+ if (!split) {
52
+ inner.label = inner[labelTarget || 'label']
53
+ } else {
54
+ inner.label = labels.map(label => inner[label]).join(split)
55
+ }
56
+ })
57
+ }
45
58
 
46
- })
47
- return data
59
+ return data || []
48
60
  }
49
61
 
50
62
  if (typeof list === 'function') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuekl/cli-components",
3
- "version": "1.5.2",
3
+ "version": "1.5.4",
4
4
  "description": "",
5
5
  "main": "index.ts",
6
6
  "scripts": {