af-mobile-client-vue3 1.0.71 → 1.0.72

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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "af-mobile-client-vue3",
3
3
  "type": "module",
4
- "version": "1.0.71",
4
+ "version": "1.0.72",
5
5
  "description": "Vue + Vite component lib",
6
6
  "license": "MIT",
7
7
  "engines": {
@@ -4,7 +4,7 @@ import {
4
4
  Picker as VanPicker,
5
5
  Popup as VanPopup,
6
6
  } from 'vant'
7
- import { computed, defineEmits, defineModel, defineProps, ref, watch } from 'vue'
7
+ import { computed, defineEmits, defineModel, defineProps, onBeforeMount, ref, watch } from 'vue'
8
8
 
9
9
  const props = defineProps({
10
10
  columns: {
@@ -36,13 +36,34 @@ const emits = defineEmits(['confirm', 'change', 'cancel', 'input'])
36
36
  const show = ref(false)
37
37
  const searchVal = ref('')
38
38
  const resultValue = defineModel()
39
- const columnsData = ref([])
39
+ let columnsData = ref([])
40
+ const selectedOption = ref([])
41
+
42
+ // 转换空children为空字符串
43
+ function transformColumns(data) {
44
+ return data.map(item => {
45
+ if (item.children && item.children.length === 0) {
46
+ return {
47
+ ...item,
48
+ children: ''
49
+ }
50
+ } else if (item.children && item.children.length !== 0) {
51
+ return { ...item, children:transformColumns(item.children) }
52
+ } else {
53
+ return { ...item }
54
+ }
55
+ })
56
+ }
57
+
58
+ onBeforeMount(() => {
59
+ columnsData.value = transformColumns(props.columns)
60
+ })
40
61
 
41
62
  const resultLabel = computed({
42
63
  get() {
43
64
  const res = props.columns.filter((item) => {
44
65
  const data = props.offOption ? item : item[props.option.value]
45
- return data === resultValue.value
66
+ return data === resultValue.value[0]
46
67
  })
47
68
  return res.length ? (props.offOption ? res[0] : res[0][props.option.text]) : ''
48
69
  },
@@ -50,44 +71,45 @@ const resultLabel = computed({
50
71
 
51
72
  },
52
73
  })
74
+
53
75
  function search(val) {
54
76
  if (val) {
55
- columnsData.value = columnsData.value.filter((item) => {
77
+ columnsData.value = transformColumns(columnsData.value).filter((item) => {
56
78
  const data = props.offOption ? item : item[props.option.text]
57
-
58
79
  return data.includes(val)
59
80
  })
60
- }
61
- else {
62
- columnsData.value = JSON.parse(JSON.stringify(props.columns))
81
+ } else {
82
+ columnsData.value = transformColumns(props.columns)
63
83
  }
64
84
  }
85
+
65
86
  function onConfirm(value, _index) {
66
- resultValue.value = props.offOption ? value.selectedValues : value.selectedValues[0]
87
+ // resultValue.value = props.offOption ? value.selectedValues : value.selectedValues[0]
88
+ resultValue.value = value.selectedValues
89
+ selectedOption.value = value.selectedOptions
67
90
  show.value = !show.value
68
91
  emits('confirm', value.selectedValues[0], value.selectedOptions)
69
92
  }
93
+
70
94
  function change(val, index) {
71
95
  emits('change', val, index, resultValue.value)
72
96
  }
97
+
73
98
  function cancel(val, index) {
74
99
  show.value = !show.value
75
100
  emits('cancel', val, index, resultValue.value)
76
101
  }
102
+
77
103
  function showPopu(disabled) {
78
- // resultValue.value = `${selectValue}`
79
104
  if (disabled !== undefined && disabled !== false)
80
105
  return false
81
- columnsData.value = JSON.parse(JSON.stringify(props.columns))
106
+ columnsData.value = transformColumns(props.columns)
82
107
  show.value = !show.value
83
108
  }
84
109
 
85
- // watch(() => selectValue, (newVal, _oldVal) => {
86
- // resultValue.value = `${newVal}`
87
- // })
88
110
  watch(() => resultValue, (newVal, _oldVal) => {
89
111
  searchVal.value = ''
90
- columnsData.value = JSON.parse(JSON.stringify(props.columns))
112
+ columnsData.value = transformColumns(props.columns)
91
113
  emits('input', newVal)
92
114
  })
93
115
  </script>
@@ -118,5 +140,5 @@ watch(() => resultValue, (newVal, _oldVal) => {
118
140
  </template>
119
141
 
120
142
  <style lang="scss" scoped>
121
-
122
- </style>
143
+ /* 样式定义 */
144
+ </style>