From 30e858fa504b268b9b436afca0a1259cf6e8c488 Mon Sep 17 00:00:00 2001
From: MrShi <1878285526@qq.com>
Date: 星期二, 19 八月 2025 11:01:40 +0800
Subject: [PATCH] 优化

---
 admin/src/components/business/OperaCategoryWindow.vue |   45 +++++++++++++++++++++++++++++++++------------
 1 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/admin/src/components/business/OperaCategoryWindow.vue b/admin/src/components/business/OperaCategoryWindow.vue
index 829f064..e3f47e0 100644
--- a/admin/src/components/business/OperaCategoryWindow.vue
+++ b/admin/src/components/business/OperaCategoryWindow.vue
@@ -10,12 +10,21 @@
         <el-input v-model="form.name" placeholder="璇疯緭鍏ュ悕绉�" v-trim/>
       </el-form-item>
       <el-form-item label="閫夋嫨鐖剁骇" prop="parentId">
-        <el-cascader  v-model="form.categoryList" :options="categorys" @change="handleChangeCategory" :show-all-levels="false"
+<!--        <el-cascader  v-model="form.categoryList" :options="categorys" @change="handleChangeCategory" :show-all-levels="false"
                       clearable filterable :props="categoryprops"  >
           <template slot-scope="{ node, data }">
-            <span>{{ data.name }}</span> <!-- 鑷畾涔夋樉绀哄唴瀹� -->
+            <span>{{ data.name }}</span> &lt;!&ndash; 鑷畾涔夋樉绀哄唴瀹� &ndash;&gt;
           </template>
-        </el-cascader>
+        </el-cascader>-->
+        <treeselect
+            v-model="form.parentId"
+            placeholder="璇烽�夋嫨"
+            :options="categorys"
+            :normalizer="normalizeOptions"
+            :default-expand-level="1"
+            noChildrenText="娌℃湁瀛愰�夐」"
+            noOptionsText="娌℃湁鍙�夐」"
+            noResultsText="娌℃湁鍖归厤鐨勭粨鏋�" />
       </el-form-item>
       <el-form-item label="鎺掑簭鐮�" prop="sortnum">
         <el-input v-model="form.sortnum" type="number" placeholder="璇疯緭鍏ユ帓搴忕爜锛堝崌搴忥級" v-trim/>
@@ -66,6 +75,17 @@
     })
   },
   methods: {
+    normalizeOptions (node) {
+      if (node.childList && !node.childList.length) {
+        // 鍘绘帀children=[]鐨刢hildren灞炴��
+        delete node.childList
+      }
+      return {
+        id: node.id,
+        label: node.name,
+        children: node.childList
+      }
+    },
     handleChangeCategory (value) {
       this.form.parentId = null
       if (this.form.categoryList && this.form.categoryList.length >= 1) {
@@ -89,11 +109,11 @@
       }
       return data
     },
-    open (title, target, categorys, categoryType, parentIdPath) {
+    open (title, target, categorys, categoryType, parentId) {
       this.title = title
-      this.categorys = categorys || []
-      this.categorys = this.getTreeData(this.categorys)
-      console.log(this.categorys)
+      this.categorys = JSON.parse(JSON.stringify(categorys||[]));
+      // this.categorys = this.getTreeData(this.categorys)
+      console.log(parentId)
       this.visible = true
       this.form = {
         id: null,
@@ -102,7 +122,7 @@
         remark: '',
         categoryList: [],
         sortnum: null,
-        parentId: null
+        parentId: parentId || null
       }
       this.form.type = categoryType
       // 鏂板缓
@@ -110,9 +130,10 @@
       if (target == null) {
         this.$nextTick(() => {
           this.$refs.form.resetFields()
+          this.form.parentId = parentId
           this.form[this.configData['field.id']] = null
           this.form.categoryList = []
-          if (parentIdPath && parentIdPath != null) {
+          /* if (parentIdPath && parentIdPath != null) {
             var array = parentIdPath.split('/')
             array.forEach(item => {
               if (item && item != null && item !== '') {
@@ -120,7 +141,7 @@
               }
             })
             that.handleChangeCategory()
-          }
+          } */
         })
         return
       }
@@ -129,7 +150,7 @@
         for (const key in this.form) {
           this.form[key] = target[key]
         }
-        this.form.categoryList = []
+        /* this.form.categoryList = []
         if (target.parentId && target.idParentPath) {
           var array = target.idParentPath.split('/')
           array.forEach(item => {
@@ -137,7 +158,7 @@
               that.form.categoryList.push(parseInt(item))
             }
           })
-        }
+        } */
       })
     }
   }

--
Gitblit v1.9.3