From dcf9c9e0410fe1186239e3f8d6f7bdc789c08010 Mon Sep 17 00:00:00 2001
From: lzhe <lzhe@example.com>
Date: 星期三, 05 六月 2024 18:00:39 +0800
Subject: [PATCH] 1

---
 src/views/console/authority/role/index.vue |  148 +++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 130 insertions(+), 18 deletions(-)

diff --git a/src/views/console/authority/role/index.vue b/src/views/console/authority/role/index.vue
index 0ac23d9..557a1cc 100644
--- a/src/views/console/authority/role/index.vue
+++ b/src/views/console/authority/role/index.vue
@@ -27,12 +27,18 @@
 			<el-tabs tab-position="top">
 				<el-tab-pane label="鑿滃崟">
 					<div class="treeMain">
-						<el-tree ref="menu" node-key="name" :data="menu.list" :props="menu.props" show-checkbox></el-tree>
+						<el-tabs tab-position="left" class="demo-tabs" v-model="menuActiveName" @tab-click="menuHandleClick">
+							<el-tab-pane v-for="item in menuGrantList" :label="item.title" :name="item.title">
+								<el-tree ref="tree" v-if="showtree" :data="treeData" :props="{ label: 'title',children: 'children'}" node-key="id" show-checkbox @check-change="treeHandleCheckChange" :default-checked-keys="treeCheck" default-expand-all />
+							</el-tab-pane>
+						</el-tabs>
+						<div class="roleSubmit"><el-button type="primary" :loading="submitIsSaveing" @click="roleSubmit()">淇� 瀛�</el-button></div>
 					</div>
 				</el-tab-pane>
 				<el-tab-pane label="鍗$墖">
 					<div class="treeMain">
-						<el-tree ref="grid" node-key="key" :data="grid.list" :props="grid.props" :default-checked-keys="grid.checked" show-checkbox></el-tree>
+						<!-- <el-tree ref="grid" node-key="key" :data="grid.list" :props="grid.props" :default-checked-keys="grid.checked" show-checkbox></el-tree> -->
+						123
 					</div>
 				</el-tab-pane>
 			</el-tabs>
@@ -69,6 +75,11 @@
 		},
 		data() {
 			return {
+				showtree: true,
+				treeCheck: [],
+				menuActiveName: "",
+				treeData: [],
+				menuGrantList: [],
 				total: 0,
 				searchData: {
 					current: 1,
@@ -76,6 +87,7 @@
 				},
 				tableLiId: "", //褰撳墠瑙掕壊id
 				isSaveing: false,
+				submitIsSaveing: false,
 				userVisibleData: [],
 				userVisible: false,
 				roleHeaderList: [],
@@ -114,21 +126,111 @@
 			this.getUser();  //鑾峰彇鍏ㄩ儴璐﹀彿
 		},
 		methods: {
+			roleSubmit() {  //淇濆瓨
+				var obj = {
+					apiScopeIds: [],
+					dataScopeIds: [],
+					menuIds: this.$refs.tree[0].getCheckedKeys(),
+					roleIds: [this.tableLiId]
+				}
+				this.isSaveing = true;
+				this.$HTTP.post(`/api/blade-system/role/grant`,obj).then(res=> {
+					this.isSaveing = false;
+					if(res.code == 200) {
+						this.$message.success("鎿嶄綔鎴愬姛");
+					}
+				})
+			},
+			menuHandleClick(tab, event) {
+				this.setTreeList(this.menuGrantList,event.target.innerText);  //tree
+			},
+			treeHandleCheckChange() {
+
+			},
+			setTreeList(arr,name) {
+				this.treeData = [];
+				arr.forEach(item=> {
+					if(item.title == name) {
+						this.treeData = item.children;
+					}
+				})
+			},
+			extractLastLevelIds(array) {  //閫掑綊鑾峰彇children鏈�鍚庝竴绾х殑id鐨勬暟缁�
+				let ids = [];  
+				for (let i = 0; i < array.length; i++) {  
+					const obj = array[i];  
+					if (obj.children) {  
+						// 閫掑綊璋冪敤浠ユ彁鍙栨洿娣卞眰绾х殑children涓殑id  
+						ids = ids.concat(this.extractLastLevelIds(obj.children));  
+					} else {  
+						// 濡傛灉娌℃湁children灞炴�э紝鍒欏亣瀹氬綋鍓嶅璞℃槸鏈�鍚庝竴绾�  
+						if (obj.id) {  
+							ids.push(obj.id);  
+						}  
+					}  
+				}  
+				return ids; 
+			},
+			findOverlap(array1, array2) {   //鎵惧嚭涓や釜鏁扮粍閲嶅悎鐨勯儴鍒�
+				// 鍒涘缓涓�涓泦鍚堬紙Set锛夋潵瀛樺偍绗簩涓暟缁勪腑鐨勫厓绱狅紝浠ヤ究浜庡揩閫熸煡鎵�  
+				const set = new Set(array2);  
+				// 浣跨敤filter鏂规硶杩囨护鍑虹涓�涓暟缁勪腑鍦ㄩ泦鍚堜腑瀛樺湪鐨勫厓绱�  
+				const overlap = array1.filter(item => set.has(item));  
+				return overlap;  
+			},
+			getSelectTree(res,id,index) {//鑾峰彇宸查�夋暟鎹�
+				this.$HTTP.get(`/api/blade-system/menu/role-tree-keys?roleIds=${id}`).then(resp=> {
+					if(res.code == 200) {
+						this.tableData.forEach(item=> {
+							item.active = false;
+						})
+						this.tableData[index].active = true;  //閫変腑
+						this.showtree = false;
+						this.tableLiId = id;  //瑙掕壊id
+						this.$nextTick(()=> {
+							this.showtree = true;
+							this.menuGrantList = res.data.menu.filter(item=> { //杩囨护鎺夋病鏈塩hildren鐨�
+								return item.children;
+							});
+							this.menuActiveName = this.menuGrantList[0].title;//榛樿绗竴涓彍鍗�
+							this.setTreeList(this.menuGrantList,this.menuActiveName);//灞曠ず鏍戯紙宸︿晶鑿滃崟list锛屽乏渚ц彍鍗曞悕瀛楋級
+							var lastId = [],idarr = [];
+							var lastId = this.extractLastLevelIds(this.menuGrantList);  //鑾峰彇鏈�鍚庝竴绾d
+							var idarr = this.findOverlap(lastId,resp.data.menu); //鎵惧嚭涓や釜鏁扮粍閲嶅悎鐨勯儴鍒�
+							this.treeCheck = idarr;  //鑾峰彇閫変腑鏁版嵁
+						})
+					}
+				})
+			},
+			getMenuGrant(row,index) {
+				this.$HTTP.get(`/api/blade-system/menu/grant-tree`).then(res=> {
+					if(res.code == 200) {
+						//鑾峰彇宸查�夋暟鎹�  (鏍戠殑鏁版嵁锛岃鑹瞚d)
+						this.getSelectTree(res,row.id,index);
+					}
+				})
+			},
 			userSubmit() {
 				var ids = [];
 				this.userSelection.forEach(item=> {
 					ids.push(item.id);
 				})
+				this.isSaveing = true;
+
 				this.$HTTP.post(`/api/blade-user/${this.tableLiId}/save`,{ids}).then(res=> {
+					this.isSaveing = false;
 					if(res.code == 200) {
 						this.userVisible = false;
 						this.$message.success("鎿嶄綔鎴愬姛");
-						this.getBladeList(this.tableLiId);  //鑾峰彇浜哄憳鍒楄〃
+						this.$HTTP.get(`/api/blade-user/${this.tableLiId}/list`).then(res=> {
+							if(res.code == 200) {
+								this.roleHeaderList = res.data;
+							}
+						})
 					}
 				})
 			},
 			userVisibleChange(selection) {
-				console.log(selection);
 				this.userSelection = selection;
 			},
 			addUser() {  //娣诲姞璐﹀彿
@@ -142,10 +244,11 @@
 					}
 				})
 			},
-			getBladeList(id) {  //浜哄憳鍒楄〃
-				this.$HTTP.get(`/api/blade-user/${this.tableLiId}/list`).then(res=> {
+			getBladeList(row,index) {  //浜哄憳鍒楄〃
+				this.$HTTP.get(`/api/blade-user/${row.id}/list`).then(res=> {
 					if(res.code == 200) {
 						this.roleHeaderList = res.data;
+						this.getMenuGrant(row,index);   //鑾峰彇tree
 					}
 				})
 			},
@@ -156,20 +259,14 @@
 				this.roleHeaderList[index].active = true;
 			},
 			changeTabaleLi(row,index) {
-				this.tableData.forEach(item=> {
-					item.active = false;
-				})
-				this.tableData[index].active = true;
-				this.tableLiId = row.id;
-				this.getBladeList(row.id);  //鑾峰彇浜哄憳鍒楄〃
+				this.getBladeList(row,index);  //鑾峰彇浜哄憳鍒楄〃
 			},
 			getRoleList() {
 				this.$HTTP.get("/api/blade-system/role/list?current=1&size=1000").then(res=> {
 					if(res.code == 200) {
 						res.data[0].active = true;
 						this.tableData = res.data;
-						this.tableLiId = this.tableData[0].id;
-						this.getBladeList(this.tableData[0].id);  //鑾峰彇浜哄憳鍒楄〃
+						this.getBladeList(this.tableData[0],0);  //榛樿绗竴涓鑹茶幏
 					}
 				})
 			},
@@ -272,7 +369,7 @@
 	line-height: 41px;
 	font-size: 14px;
 	text-align: center;
-	background-color: #3b8e8e;
+	background-color: #409eff;
 	color: #fff;
 }
 .rolePage .roleContainer ul {
@@ -292,7 +389,7 @@
 }
 .rolePage .roleContainer ul li .active {
 	font-weight: bold;
-	color: #3b8e8e;
+	color: #409eff;
 }
 .rolePage .roleContainer ul li:hover {
 	background-color: #f5f7fa;
@@ -314,7 +411,7 @@
 .role-main-title {
 	padding: 6px 10px;
     font-size: 14px;
-    background-color: #d8e8d8;
+    background-color: #9dc7f2;
     margin-bottom: 8px;
     border-radius: 2px;
 }
@@ -334,10 +431,25 @@
     text-overflow: ellipsis;
 }
 .role-main-header ul li.titleActive {
-	border: 1px solid #3b8e8e;
+	border: 1px solid #409eff;
 }
 .role-main-header ul li.role-header-add {
 	display: inline-block;
 	border: 1px dashed #e5e5e5;
 }
+.treeMain {
+	position: relative;
+	margin-bottom: 60px;
+}
+.roleSubmit {
+	bottom: 0;
+    position: fixed;
+    width: 100%;
+    text-align: right;
+    right: 0;
+    padding-right: 20px;
+    padding-bottom: 12px;
+    background: #fff;
+    z-index: 11;
+}
 </style>

--
Gitblit v1.9.3