qtsk-vue3 0.0.18 → 0.0.19

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.
@@ -4,35 +4,36 @@
4
4
  placeholder="请选择省市区"
5
5
  size="default"
6
6
  :options="regionData"
7
- v-model="area"
7
+ v-model="modelValue"
8
+ clearable
9
+ @change="handleChange"
8
10
  >
9
11
  </el-cascader>
10
12
  </div>
11
13
  </template>
12
14
 
13
15
  <script setup>
14
- import { computed } from 'vue'
15
16
  import { ElCascader } from 'element-plus'
16
17
  import { regionData } from 'element-china-area-data'
18
+ import { treeToArray } from '../../utils/common'
19
+ const regionFlatData = treeToArray(regionData)
17
20
  defineOptions({
18
21
  name: 'Area',
19
22
  })
20
23
  const props = defineProps({
21
- modelValue: {
22
- type: Array,
23
- default: () => ([])
24
- }
24
+ idx: Number
25
25
  })
26
- const emits = defineEmits(['update:modelValue'])
27
- const area = computed({
28
- get(){
29
- return props.modelValue
30
- },
31
- set(val){
32
- console.log('val', val)
33
- emits('update:modelValue', Object.values(val))
34
- }
26
+
27
+ const emits = defineEmits(['update:modelValue', 'change'])
28
+ const modelValue = defineModel('modelValue')
29
+
30
+ const handleChange = (value) => {
31
+ emits('change', {index: props.idx, value})
32
+ }
33
+ defineExpose({
34
+ regionFlatData
35
35
  })
36
+
36
37
  </script>
37
38
 
38
39
  <style lang="less" scoped>
@@ -48,7 +48,7 @@ const props = defineProps({
48
48
  }
49
49
  })
50
50
 
51
- const modelValue = defineModel('modelValue', { type: String })
51
+ const modelValue = defineModel('modelValue', { type: [String, Array] })
52
52
  </script>
53
53
 
54
54
  <style lang="less" scoped>
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <el-form-item :label="label" :prop="propName">
2
+ <el-form-item :label="label" :prop="propName" :key="label">
3
3
  <slot/>
4
4
  </el-form-item>
5
5
  </template>
@@ -37,9 +37,10 @@ const props = defineProps({
37
37
  type: [String, Number],
38
38
  default: ''
39
39
  },
40
- disabled: Boolean
40
+ disabled: Boolean,
41
+ idx: Number
41
42
  })
42
- const emits = defineEmits(['update:modelValue'])
43
+ const emits = defineEmits(['update:modelValue', 'change'])
43
44
  const formData = defineModel('formData')
44
45
  const inputValue = computed({
45
46
  get () {
@@ -50,6 +51,7 @@ const inputValue = computed({
50
51
  value = value.trim()
51
52
  }
52
53
  if (formData.value?.loc) formData.value.loc = ''
54
+ emits('change', {index: props.idx || 0, keyWord: value})
53
55
  emits('update:modelValue', value)
54
56
  }
55
57
  })
@@ -19,5 +19,4 @@ const install = makeInstaller(Components)
19
19
 
20
20
  export { Message, MessageBox, install, install as default }
21
21
 
22
- console.info('%c====== Editing in local package ======', 'font-size:16px;color:pink;')
23
-
22
+ console.info('%c====== Editing in local package ======', 'font-size:16px;color:pink;')
package/package/index.js CHANGED
@@ -20,3 +20,5 @@ const install = makeInstaller(Components)
20
20
  export { Message, MessageBox, install, install as default }
21
21
 
22
22
  console.info('%c====== Editing in local package ======', 'font-size:16px;color:pink;')
23
+
24
+
@@ -52,4 +52,30 @@ export const dateFormat = (time, format) => {
52
52
  } else {
53
53
  return ''
54
54
  }
55
- }
55
+ }
56
+
57
+ // 将树形结构数组对象转换为二维数组
58
+ export const treeToArray = (treeArray) => {
59
+ const result = []
60
+
61
+ function flatten (node, level) {
62
+ result.push({
63
+ id: node.value,
64
+ name: node.label,
65
+ level: level
66
+ })
67
+
68
+ if (node.children && node.children.length > 0) {
69
+ node.children.forEach(child => {
70
+ flatten(child, level + 1)
71
+ })
72
+ }
73
+ }
74
+
75
+ treeArray.forEach(node => {
76
+ flatten(node, 0)
77
+ })
78
+
79
+ return result
80
+ }
81
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qtsk-vue3",
3
- "version": "0.0.18",
3
+ "version": "0.0.19",
4
4
  "description": "vue3版组件库",
5
5
  "main": "./package/index.js",
6
6
  "scripts": {