From 195d6ddb7cb975cd60e61830812282d7017b7e20 Mon Sep 17 00:00:00 2001
From: Surpriseplus <845948745@qq.com>
Date: 星期五, 21 七月 2023 10:00:29 +0800
Subject: [PATCH] 角色资源授权

---
 src/api/api.js                                             |   21 +++
 src/views/AuthorizationManagement/roleResAuthorization.vue |  248 +++++++++++++++++++++++++++++++------------------
 2 files changed, 173 insertions(+), 96 deletions(-)

diff --git a/src/api/api.js b/src/api/api.js
index 79da168..ec23592 100644
--- a/src/api/api.js
+++ b/src/api/api.js
@@ -221,9 +221,24 @@
 export function res_updates(params) {
   return request.post('/res/updates', params);
 }
-//璧勬簮鍒楄〃-鏇存柊澶氭潯
-export function res_update(params) {
-  return request.post('/res/update', params);
+
+
+
+
+//瑙掕壊璧勬簮-鏍规嵁ID鏌ヨ
+export function roleRes_selectResByRole(params) {
+  return request.get('/roleRes/selectResByRole', { params: params });
+}
+
+
+
+//瑙掕壊璧勬簮-鎵归噺鏂板
+export function roleRes_inserts(params) {
+  return request.post('/roleRes/inserts', params);
+}
+//瑙掕壊璧勬簮-鍒犻櫎澶氭潯
+export function roleRes_deletes(params) {
+  return request.get('/roleRes/deletes', { params: params });
 }
 
 
diff --git a/src/views/AuthorizationManagement/roleResAuthorization.vue b/src/views/AuthorizationManagement/roleResAuthorization.vue
index 36bd1aa..447ceb2 100644
--- a/src/views/AuthorizationManagement/roleResAuthorization.vue
+++ b/src/views/AuthorizationManagement/roleResAuthorization.vue
@@ -123,50 +123,15 @@
           </div>
         </div>
         <el-divider class="divider" />
-
-        <el-table
-          :data="usertableData"
-          border
-          style="width: 100%"
-          height="calc(100% - 80px)"
-          @selection-change="handleSelectionChange"
+        <el-tree
+          ref="tree"
+          :props="defaultLayerrops"
+          node-key="resid"
+          :data="layerData"
+          show-checkbox
+          :default-expanded-keys="[1]"
         >
-          <el-table-column
-            type="selection"
-            width="55"
-          > </el-table-column>
-          <el-table-column
-            align="center"
-            type="index"
-            :label="$t('dataManage.styleObj.index')"
-          />
-          <el-table-column
-            prop="resName"
-            :label="$t('operatManage.UserRoleAuthorizationObj.name')"
-          >
-          </el-table-column>
-          <el-table-column
-            prop="server"
-            :label="$t('operatManage.UserRoleAuthorizationObj.server')"
-          >
-          </el-table-column>
-        </el-table>
-
-        <div
-          style="margin-top: 10px; text-align: center"
-          class="pagination_box"
-        >
-          <el-pagination
-            @size-change="userhandleSizeChange"
-            @current-change="userhandleCurrentChange"
-            :current-page="userlistData.pageIndex"
-            :page-sizes="[10, 20, 50, 100]"
-            :page-size="userlistData.pageSize"
-            layout="prev, pager, next"
-            :total="usercount"
-          >
-          </el-pagination>
-        </div>
+        </el-tree>
       </div>
     </div>
 
@@ -243,6 +208,10 @@
   roleResDeletes,
   resSelectCountForRole,
   roleResInserts,
+  res_selectAll,
+  roleRes_selectResByRole,
+  roleRes_inserts,
+  roleRes_deletes
 } from '../../api/api';
 export default {
   //import寮曞叆鐨勭粍浠堕渶瑕佹敞鍏ュ埌瀵硅薄涓墠鑳戒娇鐢�
@@ -275,7 +244,10 @@
       templateSelection: '',
       //   褰撳墠閫夋嫨鐨勮鐨勬暟鎹�
       checkList: [],
-
+      defaultLayerrops: {
+        children: "children",
+        label: "cnName",
+      },
       defaultProps: {
         children: 'children',
         label: 'name',
@@ -293,6 +265,9 @@
       debid: null,
       roleid: null,
       addmultipleSelection: [],
+      layerData: [],
+      layeroption: []
+
     };
   },
   methods: {
@@ -321,50 +296,91 @@
         })
         .catch(() => { });
     },
-    adduser() {
-      this.dialogTableVisible = true;
-      this.getadduserList();
+    async adduser() {
+      var val = this.$refs.tree.getCheckedNodes(false, true); // 鍒╃敤杩欎釜鏂规硶灏卞彲浠ヨ幏鍙栧埌瀛愯妭鐐�+鐖惰妭鐐�)
+
+      var std = [];
+      for (var i in val) {
+        if (val[i].id == 0) {
+          val[i].roleid = this.roleid
+          std.push(val[i])
+        }
+      }
+      if (std.length == 0) {
+        return
+      }
+      const data = await roleRes_inserts(std)
+      if (data.code != 200) {
+        this.$message.error('鎺堟潈澶辫触');
+      } else {
+        this.$message({
+          type: 'success',
+          message: '鎺堟潈鎴愬姛!',
+        });
+      }
+      this.getuserList();
+      // this.dialogTableVisible = true;
+      // this.getadduserList();
     },
     //鐢ㄦ埛鍒犻櫎
     async deletesUser() {
-      let arr = [];
-      this.usermultipleSelection.forEach((e) => {
-        arr.push(e.id);
-      });
-      this.$confirm('姝ゆ搷浣滃皢姘镐箙鍒犻櫎璇ユ潈闄�, 鏄惁缁х画?', '鎻愮ず', {
-        confirmButtonText: '纭畾',
-        cancelButtonText: '鍙栨秷',
-        type: 'warning'
-      }).then(async () => {
-        const data = await roleResDeletes({ ids: arr.toString() });
-        if (data.code == 200) {
-          this.InsertFormdialog = false;
-          this.$message({
-            message: '鍒犻櫎鎴愬姛锛�',
-            type: 'success',
-          });
-          this.getuserList();
-        } else {
-          this.$message({
-            message: '鍒犻櫎澶辫触锛�',
-            type: 'warning',
-          });
+      var val = this.$refs.tree.getCheckedNodes(false, true); // 鍒╃敤杩欎釜鏂规硶灏卞彲浠ヨ幏鍙栧埌瀛愯妭鐐�+鐖惰妭鐐�)
+      var std = [];
+      for (var i in val) {
+        if (val[i].id > 0) {
+          std.push(val[i].id)
         }
-      }).catch(() => {
+      }
+      var res = this.layeroption;
+      var arr = [];
+      for (var i in res) {
+        if (res[i].id > 0 && std.indexOf(res[i].id) == -1) {
+          arr.push(res[i].id)
+        }
+      }
+      if (arr.length == 0) {
+        return
+      }
+      const data = await roleRes_deletes({ ids: arr.toString() });
+      if (data.code != 200) {
+        this.$message.error('鎺堟潈澶辫触');
+      } else {
         this.$message({
-          type: 'info',
-          message: '宸插彇娑堝垹闄�'
+          type: 'success',
+          message: '鎺堟潈鎴愬姛!',
         });
-      });
-      // const data = await roleResDeletes({ ids: arr.toString() });
-      // if (data.code !== 200) {
-      //   return this.$message.error('鍒犻櫎澶辫触');
-      // }
-      // this.$message({
-      //   message: '鍒犻櫎鎴愬姛',
-      //   type: 'success',
+      }
+      this.getuserList()
+      // let arr = [];
+      // this.usermultipleSelection.forEach((e) => {
+      //   arr.push(e.id);
       // });
-      // this.getuserList();
+      // this.$confirm('姝ゆ搷浣滃皢姘镐箙鍒犻櫎璇ユ潈闄�, 鏄惁缁х画?', '鎻愮ず', {
+      //   confirmButtonText: '纭畾',
+      //   cancelButtonText: '鍙栨秷',
+      //   type: 'warning'
+      // }).then(async () => {
+      //   const data = await roleResDeletes({ ids: arr.toString() });
+      //   if (data.code == 200) {
+      //     this.InsertFormdialog = false;
+      //     this.$message({
+      //       message: '鍒犻櫎鎴愬姛锛�',
+      //       type: 'success',
+      //     });
+      //     this.getuserList();
+      //   } else {
+      //     this.$message({
+      //       message: '鍒犻櫎澶辫触锛�',
+      //       type: 'warning',
+      //     });
+      //   }
+      // }).catch(() => {
+      //   this.$message({
+      //     type: 'info',
+      //     message: '宸插彇娑堝垹闄�'
+      //   });
+      // });
+
     },
     //鐢ㄦ埛琛ㄥ閫�
     handleSelectionChange(val) {
@@ -403,6 +419,35 @@
     handleCurrentChange(val) {
       this.listData.pageIndex = val;
       this.getRole();
+    },
+    //鑾峰彇璧勬簮鍒楄〃
+    async getlayerTree() {
+      this.layerData = []
+      const data = await res_selectAll();
+      if (data.code != 200) {
+        return this.$message.error("鍥惧眰鍒楄〃鏌ヨ澶辫触");
+      }
+      var val = this.setTreeData(data.result);
+      val.sort(function (a, b) {
+        return a.sort - b.sort
+      })
+      this.layerData = val
+    },
+    setTreeData(source) {
+      let cloneData = JSON.parse(JSON.stringify(source)); // 瀵规簮鏁版嵁娣卞害鍏嬮殕
+      return cloneData.filter((father) => {
+        // 寰幆鎵�鏈夐」
+        let branchArr = cloneData.filter((child) => father.resid == child.pid);
+        if (branchArr.length > 0) {
+          branchArr.sort(function (a, b) {
+            return a.sort - b.sort
+          })
+        }
+        branchArr.length > 0 ? (father.children = branchArr) : ""; // 缁欑埗绾ф坊鍔犱竴涓猚hildren灞炴�э紝骞惰祴鍊�
+        // 灞炰簬鍚屼竴瀵硅薄闂锛屼緥濡傦細浠� a=b銆乧=1 锛岀劧鍚庡啀浠� b.c=c 锛� 閭d箞 a.c=b.c=c=1 锛涘悓鐞嗭紝鍚庣画浠� c.d=2 ,閭d箞 a.c.d 涔熸槸=2锛�
+        // 鐢辨寰幆澶氭鍚庯紝灏辫兘褰㈡垚鐩稿簲鐨勬爲褰㈡暟鎹粨鏋�
+        return father.pid == 0; // 杩斿洖涓�绾ц彍鍗�
+      });
     },
     // 瑙掕壊鍗曢��
     singleElection(row) {
@@ -452,25 +497,41 @@
       }
     },
     async getadduserList() {
-      this.addlistData.roleid = this.roleid;
+      // this.addlistData.roleid = this.roleid;
 
-      // this.addlistData.debid = this.debid;
-      const data = await resSelectCountForRole(this.addlistData);
-      if (data.code !== 200) {
-        return this.$message.error('鏂板璧勬簮鍒楄〃璇锋眰閿欒');
-      }
+      // // this.addlistData.debid = this.debid;
+      // const data = await resSelectCountForRole(this.addlistData);
+      // if (data.code !== 200) {
+      //   return this.$message.error('鏂板璧勬簮鍒楄〃璇锋眰閿欒');
+      // }
 
-      this.gridData = data.result;
-      this.addcount = data.count;
+      // this.gridData = data.result;
+      // this.addcount = data.count;
+
+
     },
     // 鐢ㄦ埛琛ㄨ姹�
     async getuserList() {
-      const data = await roleReselectByPageAndCount(this.userlistData);
+      this.layerData = [];
+      this.layeroption = [];
+
+      const data = await roleRes_selectResByRole({ roleid: this.userlistData.roleid });
       if (data.code !== 200) {
-        return this.$message.error('鐢ㄦ埛璧勬簮鍒楄〃璇锋眰閿欒');
+        return this.$message.error('鏍规嵁ID鏌ヨ璧勬簮澶辫触');
       }
-      this.usertableData = data.result;
-      this.usercount = data.count;
+      var std = [];
+      this.layeroption = data.result;
+      for (var i in data.result) {
+        if (data.result[i].id > 0 && data.result[i].type != 1) {
+          std.push(data.result[i].resid)
+        }
+      }
+      var val = this.setTreeData(data.result);
+      val.sort(function (a, b) {
+        return a.sort - b.sort
+      })
+      this.layerData = val
+      this.$refs.tree.setCheckedKeys(std);
     },
     // 瑙掕壊琛ㄨ姹�
     async getRole() {
@@ -508,6 +569,7 @@
       }
     }
     this.getMenuTree();
+    // this.getlayerTree();
   },
 };
 </script>

--
Gitblit v1.9.3