From 746e355df3ce7b588f40e96e4f20ba35266e7190 Mon Sep 17 00:00:00 2001
From: loulijun2021 <1694218219@qq.com>
Date: 星期二, 22 八月 2023 11:28:42 +0800
Subject: [PATCH] 1.人员管理开发完成

---
 src/views/basicSettings/roleList.vue |  100 ++++++++++++++++++++++++++++++-------------------
 1 files changed, 61 insertions(+), 39 deletions(-)

diff --git a/src/views/basicSettings/roleList.vue b/src/views/basicSettings/roleList.vue
index 816eb2b..3fe1ff7 100644
--- a/src/views/basicSettings/roleList.vue
+++ b/src/views/basicSettings/roleList.vue
@@ -42,7 +42,7 @@
               <input
                 v-if="data.isEdit"
                 :ref="data.code"
-                v-model="node.label"
+                v-model="data.name"
                 type="text"
                 @click.stop
                 @blur="roleSave(data)"
@@ -68,7 +68,7 @@
         </div>
 
         <div
-          style="margin-left: 15px;width:100%;position: relative"
+          style="margin-left: 10px;width:100%;position: relative"
         >
 
           <el-button
@@ -128,10 +128,10 @@
                   </el-checkbox>
 
                   <div v-if="treeCenter.length>0">
-                    <div v-for="item in treeCenter[0].children" :key="item.menucode">
+                    <div v-for="(item,index) in treeCenter[0].children" :key="item.menucode">
 
                       <div
-                        v-if="item.buttoncodelist ===null "
+                        v-if="!item.buttoncodelist"
                         style="margin-left: 40px;height:26px;display: flex;"
                       />
 
@@ -141,7 +141,7 @@
                         :key="it.menucode"
                         v-model="it.buttonChecked"
                         style="margin-left: 40px;height:26px;display: flex;"
-                        @change="val=>handleCheckedButtonChange(val,it.menucode,it.buttonChecked)"
+                        @change="val=>handleCheckedButtonChange(val,index,it.menucode,it.buttonChecked)"
                       >
 
                         <el-checkbox
@@ -179,7 +179,7 @@
                   <div v-if="treeCenter.length>0">
                     <div v-for="item in treeCenter[0].children" :key="item.menucode">
                       <div
-                        v-if="item.datacodelist ===null "
+                        v-if="!item.datacodelist"
                         style="margin-left: 40px;height:26px;display: flex;"
                       />
 
@@ -222,7 +222,7 @@
 <script>
 import waves from '@/directive/waves'
 import {
-  DataPermissions,
+  RoleAddUpdateSava, RoleDeleteSava,
   RolePermissionSava,
   RolePermissionSearchRole,
   RolePermissionSearchRoleMenu,
@@ -230,6 +230,7 @@
 } from '@/api/basicSettings'
 import arrayToTree from 'array-to-tree'
 import { throttle } from '@/utils/debounceAndThrottle'
+import { DataPermissions } from '@/api/GeneralBasicData'
 
 export default {
   name: 'RoleList',
@@ -298,7 +299,7 @@
 
       this.treeLeft = res
 
-      if (res.length > 0) {
+      if (res && res.length > 0) {
         this.$nextTick(() => { // 榛樿閫変腑绗竴涓�
           this.$refs.treeLeftRef.setCurrentKey(res[0].roles[0].code) // 榛樿閫変腑鑺傜偣绗竴涓�
         })
@@ -319,7 +320,7 @@
     // 鑾峰彇鑿滃崟鏉冮檺瀵瑰簲鐨勬寜閽�
     async getRolePermissionSearchRoleMenuButton(rolecode) {
       const { data: res } = await RolePermissionSearchRoleMenuButton({ rolecode, type: this.activeName })
-      this.allButtonData = JSON.parse(res[0].jsondate)
+      this.allButtonData = res.length > 0 ? JSON.parse(res[0].jsondate) : []
     },
     // 鑾峰彇鑿滃崟鏉冮檺
     async getRolePermissionSearchRoleMenu(rolecode) {
@@ -339,21 +340,11 @@
       this.treeCenter[0].children.forEach(item => {
         if (item.children && item.children.length) {
           item.children.forEach(it => {
-            it.buttoncodelist = it.buttoncodelist !== null ? it.buttoncodelist.split(',') : []
+            it.buttoncodelist = it.buttoncodelist !== '' && it.buttoncodelist !== null ? it.buttoncodelist.split(',') : []
             if (it.buttoncodelist && it.buttoncodelist.length > 0) {
               it.buttoncodelist = this.$ButtonData.filter(j =>
                 it.buttoncodelist.includes(j.buttoncode)
               )
-
-              // let temp = this.allButtonData.filter(j => j.menucode === it.menucode).length > 0 ? this.allButtonData.filter(j => j.menucode === it.menucode)[0].buttoncode : []
-              // temp = temp.length > 0 ? temp.split(',') : []
-
-              // it.buttonChecked = [] // 鏁版嵁鍥炴樉
-              // it.buttoncodelist.forEach(j => {
-              //   if (temp.includes(j.buttoncode)) {
-              //     it.buttonChecked.push(j.buttonname)
-              //   }
-              // })
 
               it.buttoncodelist = it.buttoncodelist.map(j => j.buttonname)
             }
@@ -364,8 +355,6 @@
                 it.datacodelist.includes(j.datacode)
               ).map(j => j.dataname)
             }
-            // const datacode = this.allButtonData.filter(j => j.menucode === it.menucode).length > 0 ? this.allButtonData.filter(j => j.menucode === it.menucode)[0].datacode : ''
-            // it.dataChecked = datacode ? this.dataKeyValue.find(j => j.datacode === datacode).dataname : '' // 鏁版嵁鍥炴樉
           })
 
           item.expanded = true
@@ -399,7 +388,7 @@
         }
       })
 
-      this.handleCheckedButtonChange('', '', '', true)
+      this.handleCheckedButtonChange('', '', '', '', true)
       this.handleCheckedDataChange('', '', true)
       // this.$forceUpdate()
     },
@@ -462,14 +451,17 @@
       }
     },
     // 鍗曚釜鎸夐挳鏀瑰彉
-    handleCheckedButtonChange(oldValue, code, newValue, flag) {
-      // console.log(oldValue, code, newValue, 2)
+    handleCheckedButtonChange(oldValue, index, code, newValue, flag) {
+      // console.log(oldValue, index, code, newValue, 2)
       // 鍒ゆ柇鏄惁鍖呭惈鍦ㄥ唴
       if (!flag) {
         if (!this.menuCheckedCodeArr.includes(code) && oldValue.length === 0 && newValue.length === 1) { // 鍚�
           this.menuCheckedCodeArr.push(code)
         } else if (this.menuCheckedCodeArr.includes(code) && oldValue.length === 1 && newValue.length === 0) { // 鏄�
-          this.menuCheckedCodeArr = this.menuCheckedCodeArr.filter(i => i !== code)
+          // 褰撴暟鎹潈闄愭湭鍕鹃�夋椂鍒欒繃婊ゆ帀鐩稿搴旂殑鑿滃崟
+          if (this.treeCenter[0].children[index].children.find(i => i.menucode === code).dataChecked.toString().length < 1) {
+            this.menuCheckedCodeArr = this.menuCheckedCodeArr.filter(i => i !== code)
+          }
         }
         this.$refs.treeCenterRef.setCheckedKeys(this.menuCheckedCodeArr)
       }
@@ -532,6 +524,7 @@
           this.menuCheckedCodeArr = this.menuCheckedCodeArr.filter(i => i !== obj.menucode)
         }
         if (selfChecked) { // 浠庝笉閫変腑鍒伴�変腑
+          obj.buttonCheckedCode = []
           this.treeCenter[0].children.forEach(item => {
             if (item.children && item.children.length) {
               item.children.forEach(it => {
@@ -542,6 +535,7 @@
             }
           })
         }
+
         this.$forceUpdate()
       }
     },
@@ -583,7 +577,7 @@
     },
     // 瑙掕壊鍚嶇О鏂板
     rolePlusClick() {
-      this.treeLeft[0].roles.push({ code: 1234, name: '', isEdit: true })
+      this.treeLeft[0].roles.push({ code: '', name: '', isEdit: true })
     },
     // 瑙掕壊鍚嶇О淇敼
     roleEditClick(self, node, data) {
@@ -596,16 +590,47 @@
     // 瑙掕壊鍚嶇О鍒犻櫎
     roleDeleteClick(self, node, data) {
       // console.log(self, node, data)
-      // this.treeLeft[0].roles.forEach((item, index) => {
-      //   if (item.code === data.code) {
-      //     this.treeLeft[0].roles.splice(index, 1) // 鏆傛椂鍏堝啓鎴愬墠绔垹闄わ紝鍚庢湡璋冪敤鎺ュ彛鍒犻櫎
-      //   }
-      // })
+      this.$confirm('鏄惁纭鍒犻櫎?', '鎻愮ず', {
+        confirmButtonText: '纭畾',
+        cancelButtonText: '鍙栨秷',
+        type: 'warning'
+      }).then(() => {
+        const D = {
+          rolecode: data.code,
+          rolename: data.name,
+          type: this.activeName
+        }
+        RoleDeleteSava(D).then(res => {
+          if (res.code === '200') {
+            this.$notify.success('瑙掕壊鍒犻櫎鎴愬姛锛�')
+          }
+          this.getRolePermissionSearchRole()
+        })
+      }).catch(() => {
+        this.$notify.info('宸插彇娑堝垹闄�')
+      })
     },
     // 瑙掕壊鍚嶇О淇濆瓨   閲囩敤闃叉姈褰㈠紡
-    roleSave: throttle(function(data) {
-      data.isEdit = false
-      console.log('鎵ц浜嗭紒')
+    roleSave: throttle(function(val) {
+      val.isEdit = false
+
+      if (val.name.trim().length === 0) {
+        this.getRolePermissionSearchRole()
+        return this.$notify.info('鏃犳晥淇濆瓨锛�')
+      }
+
+      const data = {
+        rolecode: val.code,
+        rolename: val.name,
+        type: val.code === '' ? 'Add' : 'Update'
+      }
+      console.log(data, '鎵ц浜嗭紒')
+      RoleAddUpdateSava(data).then(res => {
+        if (res.code === '200') {
+          this.$notify.success(val.code === '' ? '瑙掕壊鏂板鎴愬姛锛�' : '瑙掕壊淇敼鎴愬姛锛�')
+        }
+      })
+      this.getRolePermissionSearchRole()
     }, 1000, true),
 
     // 椤甸潰鍕鹃�夊ソ淇濆瓨浜嬩欢
@@ -635,16 +660,13 @@
         }
       })
 
-      console.log(arr, 'arr')
       const rolecode = this.$refs.treeLeftRef.getCurrentKey()
       const res = await RolePermissionSava(JSON.stringify(arr), rolecode, this.activeName)
       if (res.code === '200') {
         const rolename = this.treeLeft[0].roles.find(i => i.code === rolecode).name
         this.$notify.success(rolename + '鐨勮鑹叉潈闄愭彁浜ゆ垚鍔燂紒')
         await this.getRolePermissionSearchRoleMenuButton(rolecode)
-        // await this.getRolePermissionSearchRoleMenu(rolecode)
       }
-      // this.$forceUpdate()
     },
     // 鑾峰彇椤甸潰楂樺害
     getHeight() {
@@ -682,7 +704,7 @@
   width: 55px;
 }
 
-.el-icon-plus:hover,.el-icon-edit:hover,.el-icon-delete:hover{
+.el-icon-plus:hover, .el-icon-edit:hover, .el-icon-delete:hover {
   color: #000 !important;
 }
 </style>

--
Gitblit v1.9.3