From 41edd210f4f52ec3328da024f446216e01d8b23b Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期一, 03 三月 2025 15:29:42 +0800
Subject: [PATCH] 修改系统管理bug

---
 src/views/system/dept/index.vue |  106 +++++++++++++++++++---------------------------------
 1 files changed, 39 insertions(+), 67 deletions(-)

diff --git a/src/views/system/dept/index.vue b/src/views/system/dept/index.vue
index 2483a2b..fa71608 100644
--- a/src/views/system/dept/index.vue
+++ b/src/views/system/dept/index.vue
@@ -2,21 +2,12 @@
   <div class="app-container">
     <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
       <el-form-item label="閮ㄩ棬鍚嶇О" prop="deptName">
-        <el-input
-          v-model="queryParams.deptName"
-          placeholder="璇疯緭鍏ラ儴闂ㄥ悕绉�"
-          clearable
-          @keyup.enter.native="handleQuery"
-        />
+        <el-input v-model="queryParams.deptName" placeholder="璇疯緭鍏ラ儴闂ㄥ悕绉�" clearable @keyup.enter.native="handleQuery" />
       </el-form-item>
       <el-form-item label="鐘舵��" prop="status">
         <el-select v-model="queryParams.status" placeholder="閮ㄩ棬鐘舵��" clearable>
-          <el-option
-            v-for="dict in dict.type.sys_normal_disable"
-            :key="dict.value"
-            :label="dict.label"
-            :value="dict.value"
-          />
+          <el-option v-for="dict in dict.type.sys_normal_disable" :key="dict.value" :label="dict.label"
+            :value="dict.value" />
         </el-select>
       </el-form-item>
       <el-form-item>
@@ -27,40 +18,22 @@
 
     <el-row :gutter="10" class="mb8">
       <el-col :span="1.5">
-        <el-button
-          type="primary"
-          plain
-          icon="el-icon-plus"
-          size="mini"
-          @click="handleAdd"
-          v-hasPermi="['system:dept:add']"
-        >鏂板</el-button>
+        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
+          v-hasPermi="['system:dept:add']">鏂板</el-button>
       </el-col>
       <el-col :span="1.5">
-        <el-button
-          type="info"
-          plain
-          icon="el-icon-sort"
-          size="mini"
-          @click="toggleExpandAll"
-        >灞曞紑/鎶樺彔</el-button>
+        <el-button type="info" plain icon="el-icon-sort" size="mini" @click="toggleExpandAll">灞曞紑/鎶樺彔</el-button>
       </el-col>
       <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
     </el-row>
 
-    <el-table
-      v-if="refreshTable"
-      v-loading="loading"
-      :data="deptList"
-      row-key="deptId"
-      :default-expand-all="isExpandAll"
-      :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
-    >
+    <el-table v-if="refreshTable" v-loading="loading" :data="deptList" row-key="deptId"
+      :default-expand-all="isExpandAll" :tree-props="{ children: 'children', hasChildren: 'hasChildren' }">
       <el-table-column prop="deptName" label="閮ㄩ棬鍚嶇О" width="260"></el-table-column>
       <el-table-column prop="orderNum" label="鎺掑簭" width="200"></el-table-column>
       <el-table-column prop="status" label="鐘舵��" width="100">
         <template slot-scope="scope">
-          <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"/>
+          <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status" />
         </template>
       </el-table-column>
       <el-table-column label="鍒涘缓鏃堕棿" align="center" prop="createTime" width="200">
@@ -70,28 +43,12 @@
       </el-table-column>
       <el-table-column label="鎿嶄綔" align="center" class-name="small-padding fixed-width">
         <template slot-scope="scope">
-          <el-button
-            size="mini"
-            type="text"
-            icon="el-icon-edit"
-            @click="handleUpdate(scope.row)"
-            v-hasPermi="['system:dept:edit']"
-          >淇敼</el-button>
-          <el-button
-            size="mini"
-            type="text"
-            icon="el-icon-plus"
-            @click="handleAdd(scope.row)"
-            v-hasPermi="['system:dept:add']"
-          >鏂板</el-button>
-          <el-button
-            v-if="scope.row.parentId != 0"
-            size="mini"
-            type="text"
-            icon="el-icon-delete"
-            @click="handleDelete(scope.row)"
-            v-hasPermi="['system:dept:remove']"
-          >鍒犻櫎</el-button>
+          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
+            v-hasPermi="['system:dept:edit']">淇敼</el-button>
+          <el-button size="mini" type="text" icon="el-icon-plus" @click="handleAdd(scope.row)"
+            v-hasPermi="['system:dept:add']">鏂板</el-button>
+          <el-button v-if="scope.row.parentId != 0" size="mini" type="text" icon="el-icon-delete"
+            @click="handleDelete(scope.row)" v-hasPermi="['system:dept:remove']">鍒犻櫎</el-button>
         </template>
       </el-table-column>
     </el-table>
@@ -102,7 +59,8 @@
         <el-row>
           <el-col :span="24" v-if="form.parentId !== 0">
             <el-form-item label="涓婄骇閮ㄩ棬" prop="parentId">
-              <treeselect v-model="form.parentId" :options="deptOptions" :normalizer="normalizer" placeholder="閫夋嫨涓婄骇閮ㄩ棬" />
+              <treeselect v-model="form.parentId" :options="deptOptions" :normalizer="normalizer"
+                placeholder="閫夋嫨涓婄骇閮ㄩ棬" />
             </el-form-item>
           </el-col>
         </el-row>
@@ -139,11 +97,9 @@
           <el-col :span="12">
             <el-form-item label="閮ㄩ棬鐘舵��">
               <el-radio-group v-model="form.status">
-                <el-radio
-                  v-for="dict in dict.type.sys_normal_disable"
-                  :key="dict.value"
-                  :label="dict.value"
-                >{{dict.label}}</el-radio>
+                <el-radio v-for="dict in dict.type.sys_normal_disable" :key="dict.value" :label="dict.value">{{
+                  dict.label
+                }}</el-radio>
               </el-radio-group>
             </el-form-item>
           </el-col>
@@ -280,6 +236,7 @@
       this.title = "娣诲姞閮ㄩ棬";
       listDept().then(response => {
         this.deptOptions = this.handleTree(response.data, "deptId");
+        this.deptOptions = this.limitTreeDepth(this.deptOptions, 2)
       });
     },
     /** 灞曞紑/鎶樺彔鎿嶄綔 */
@@ -303,11 +260,12 @@
             const noResultsOptions = { deptId: this.form.parentId, deptName: this.form.parentName, children: [] };
             this.deptOptions.push(noResultsOptions);
           }
+          this.deptOptions = this.limitTreeDepth(this.deptOptions, 2)
         });
       });
     },
     /** 鎻愪氦鎸夐挳 */
-    submitForm: function() {
+    submitForm: function () {
       this.$refs["form"].validate(valid => {
         if (valid) {
           if (this.form.deptId != undefined) {
@@ -328,12 +286,26 @@
     },
     /** 鍒犻櫎鎸夐挳鎿嶄綔 */
     handleDelete(row) {
-      this.$modal.confirm('鏄惁纭鍒犻櫎鍚嶇О涓�"' + row.deptName + '"鐨勬暟鎹」锛�').then(function() {
+      this.$modal.confirm('鏄惁纭鍒犻櫎鍚嶇О涓�"' + row.deptName + '"鐨勬暟鎹」锛�').then(function () {
         return delDept(row.deptId);
       }).then(() => {
         this.getList();
         this.$modal.msgSuccess("鍒犻櫎鎴愬姛");
-      }).catch(() => {});
+      }).catch(() => { });
+    },
+    // 閫掑綊鍑芥暟锛岀敤浜庨檺鍒舵爲鐨勬繁搴�
+    limitTreeDepth(options, maxDepth, currentDepth = 1) {
+      return options.map(option => {
+        const newOption = { ...option };
+        if (currentDepth < maxDepth && option.children) {
+          // 濡傛灉褰撳墠娣卞害灏忎簬鏈�澶ф繁搴︿笖瀛樺湪瀛愯妭鐐癸紝鍒欓�掑綊澶勭悊瀛愯妭鐐�
+          newOption.children = this.limitTreeDepth(option.children, maxDepth, currentDepth + 1);
+        } else {
+          // 鍚﹀垯绉婚櫎瀛愯妭鐐�
+          delete newOption.children;
+        }
+        return newOption;
+      });
     }
   }
 };

--
Gitblit v1.9.3