Jelajahi Sumber

编辑时回显中文

lifanagju_citu 9 bulan lalu
induk
melakukan
9bbe32e16d

+ 2 - 3
src/components/FormUI/nestedListGroup/components/listGroup.vue

@@ -28,7 +28,6 @@
           :option="option"
           :selectValue="propsData.selectValue"
           :levelUI="propsData.levelUI + 1"
-          @labelUpdate="labelTxt => emit('labelUpdate', labelTxt)"
           @clickUpdate="child => clickUpdate(val, child)"
         ></listGroup>
       </v-list-group>
@@ -40,7 +39,7 @@
 // import listGroup from './listGroup'
 // import { ref } from 'vue'
 defineOptions({ name:'nestedListGroup-listGroup'})
-const emit = defineEmits(['clickUpdate', 'parentActUpdate', 'labelUpdate'])
+const emit = defineEmits(['clickUpdate', 'parentActUpdate'])
 const propsData = defineProps({
   list: Array,
   levelUI: {
@@ -78,7 +77,7 @@ const activeCalc = (val) => {
   else {
     const bool = (val[option.itemValue] - 0) === (propsData.selectValue -0)
     if (bool) {
-      emit('labelUpdate', val[option.itemText]) // 回显
+      // emit('labelUpdate', val[option.itemText]) // 回显
     }
     return bool
   }

+ 16 - 11
src/components/FormUI/nestedListGroup/index.vue

@@ -28,7 +28,7 @@
       @update:modelValue="modelValueUpDate"
     >
     </v-text-field>
-    <v-menu activator="#menu-activator" :close-on-content-click="closeOnContentClick" >
+    <v-menu activator="#menu-activator" :close-on-content-click="closeOnContentClick">
       <listGroup
         :list="item.items"
         :option="option"
@@ -64,22 +64,27 @@ const modelValueUpDate = () => {
 let static_selectLabel = ''; const model_selectLabel = ref('')
 const value = ref(propsData.modelValue) // selectValue // modelValue
 const clickUpdate = (val) => {
-  static_selectLabel = model_selectLabel.value = val[option.itemText]
-  value.value = val[option.itemValue]
+  static_selectLabel = model_selectLabel.value = val[option.itemText || 'label']
+  value.value = val[option.itemValue || 'value']
   emit('update:modelValue', value.value)
   emit('change', value.value)
 }
 const closeOnContentClick = ref(false) // multiple
 
-const labelUpdateDeal = (txt) => {
-  static_selectLabel = model_selectLabel.value = txt
+// 回显label
+const chosen = ref(null)
+const traverse = (nodes) => {
+  for (const node of nodes) {
+    if (node[option.itemValue || value] === value.value) {
+      chosen.value = node
+    }
+    if (node.children) {
+      traverse(node.children)
+    }
+  }
 }
-
-// // 回显label
-// if (item?.items?.length) {
-//   const options = item.items
-
-// }
+if (item?.items?.length && value.value) traverse(item.items)
+if (chosen.value) clickUpdate(chosen.value)
 </script>
 <style lang="scss" scoped>
 .showOnTop {