From e39d4219cfe41c1024c1b9a2575c4314008d30f3 Mon Sep 17 00:00:00 2001
From: loulijun2021 <1694218219@qq.com>
Date: 星期五, 28 七月 2023 17:21:26 +0800
Subject: [PATCH] 1.递交

---
 package.json                               |    1 +
 src/views/basicSettings/rolePermission.vue |   51 +++++++++++++++++++++++++++++++++++++++++++--------
 2 files changed, 44 insertions(+), 8 deletions(-)

diff --git a/package.json b/package.json
index 3e0a585..13f5c8b 100644
--- a/package.json
+++ b/package.json
@@ -15,6 +15,7 @@
   },
   "dependencies": {
     "@microsoft/signalr": "^7.0.9",
+    "array-to-tree": "^3.3.2",
     "axios": "0.18.1",
     "core-js": "3.6.5",
     "cronstrue": "^2.28.0",
diff --git a/src/views/basicSettings/rolePermission.vue b/src/views/basicSettings/rolePermission.vue
index 5a3242e..2e76889 100644
--- a/src/views/basicSettings/rolePermission.vue
+++ b/src/views/basicSettings/rolePermission.vue
@@ -70,6 +70,7 @@
       <div
         class="elTableDiv"
       >
+
         <div style="width: 300px;">
           <el-tree
             ref="treeLeftRef"
@@ -78,7 +79,7 @@
             :data="treeLeft"
             node-key="code"
             highlight-current
-            :props="defaultProps"
+            :props="defaultPropsLeft"
             :default-expand-all="true"
           />
         </div>
@@ -107,7 +108,7 @@
                     style="padding-top: 10px;width: 199px;"
                     :data="treeCenter"
                     highlight-current
-                    :props="defaultProps"
+                    :props="defaultPropsCenter"
                     show-checkbox
                     node-key="code"
                     :default-expand-all="true"
@@ -182,6 +183,8 @@
 import ImportPicker from '@/components/ImportPicker'
 import elDragDialog from '@/directive/el-drag-dialog'
 import waves from '@/directive/waves'
+import { RolePermissionSearchRole, RolePermissionSearchRoleMenu } from '@/api/basicSettings'
+import arrayToTree from 'array-to-tree'
 
 export default {
   name: 'Zzjg',
@@ -246,7 +249,11 @@
           }]
         }
       ],
-      defaultProps: {
+      defaultPropsLeft: {
+        children: 'roles',
+        label: 'name'
+      },
+      defaultPropsCenter: {
         children: 'children',
         label: 'label'
       },
@@ -265,15 +272,11 @@
   },
 
   created() {
-
+    this.getRolePermissionSearchRole()
   },
   mounted() {
     window.addEventListener('resize', this.getHeight)
     this.getHeight()
-
-    this.$nextTick(() => {
-      this.$refs.treeLeftRef.setCurrentKey('2001') // 榛樿閫変腑鑺傜偣绗竴涓�
-    })
 
     this.treeCenter[0].children.forEach(item => {
       if (item.children && item.children.length) {
@@ -290,6 +293,38 @@
     console.log(JSON.parse(JSON.stringify(this.treeCenter)))
   },
   methods: {
+
+    // 鑾峰彇瑙掕壊鏉冮檺鏌ヨ瑙掕壊
+    async getRolePermissionSearchRole() {
+      const { data: res } = await RolePermissionSearchRole()
+      this.treeLeft = res
+      if (res.length > 0) {
+        this.$nextTick(() => { // 榛樿閫変腑绗竴涓�
+          this.$refs.treeLeftRef.setCurrentKey(res[0].roles[0].code) // 榛樿閫変腑鑺傜偣绗竴涓�
+        })
+        await this.getRolePermissionSearchRoleMenu(res[0].roles[0].code)
+      } else {
+        this.$notify.error('璇峰厛寤虹浉瀵瑰簲鐨勮鑹诧紒')
+      }
+    },
+    async getRolePermissionSearchRoleMenu(rolecode) {
+      const { data: res } = await RolePermissionSearchRoleMenu({ rolecode, type: 'PC' })
+
+      // 鎷垮埌鏁扮粍list杞崲鎴愭爲褰ree
+      const result = arrayToTree(res, {
+        parentProperty: 'parentid',
+        customID: 'code',
+        childrenProperty: 'children'
+      })
+
+      const aaa = [
+        { code: '-1', name: '鍏ㄩ儴', flag: result.every(i => i.flag === 'Y') ? 'Y' : 'N', children: result }
+      ]
+
+      console.log(JSON.parse(JSON.stringify(aaa)))
+      // aaa鏁扮粍缁欒彍鍗曟爲褰�   鐒跺悗鍐嶅仛鎸夐挳绫荤殑
+    },
+
     // 宸﹁竟婊氬姩鏉℃粦鍔ㄦ椂
     scrollLeftScroll() {
       if (!this.isScroll) {

--
Gitblit v1.9.3