From fbdc9fd53ce80d89b70184db67258f7b3b3a2ebb Mon Sep 17 00:00:00 2001
From: guoshilong <123456>
Date: Fri, 27 Oct 2023 14:51:58 +0800
Subject: [PATCH] 登录、切换角色

---
 subPackage/user/role/index.vue |  109 +++++++++++++++++++++++++++++++-----------------------
 1 files changed, 62 insertions(+), 47 deletions(-)

diff --git a/subPackage/user/role/index.vue b/subPackage/user/role/index.vue
index 0b59059..853c0ea 100644
--- a/subPackage/user/role/index.vue
+++ b/subPackage/user/role/index.vue
@@ -1,70 +1,85 @@
 <template>
 	<view class="container">
 		<view>
-			<role-list :roleData="roleData"></role-list>
+			<role-list :roleData="roleData" @select="select"></role-list>
 		</view>
-		
+
 		<view class="cur-btn">
-			<u-button type="primary" text="确定"></u-button>
+			<u-button @click="submit" type="primary" text="确定"></u-button>
 		</view>
+
+		<u-loading-page :loading="loading"></u-loading-page>
 	</view>
 </template>
 
 <script>
+	import store from "@/store/index.js"
 	import roleList from "@/subPackage/user/components/roleList.vue"
-	
+	import {
+		dynamicMenu,
+		getRoleListByIds,
+	} from "@/api/system/role.js"
 	export default {
 		components: {
 			roleList
 		},
-		
+
 		data() {
 			return {
-				cellGroupData: [
-					{
-						title: '我的家人',
-						icon: 'account-fill',
-						url: ''
-					},
-					{
-						title: '切换角色',
-						icon: 'account-fill',
-						url: ''
-					},
-					{
-						title: '修改密码',
-						icon: 'account-fill',
-						url: ''
-					},
-					{
-						title: '退出登录',
-						icon: 'account-fill',
-						url: ''
-					}
-				],
-				roleData: [
-					{
-						roleName: '居民',
-						iconName: 'account-fill'
-					},
-					{
-						roleName: '场所负责人',
-						iconName: 'account-fill'								
-					},
-					{
-						roleName: '网格员',
-						iconName: 'account-fill'
-					},
-					{
-						roleName: '系统管理员',
-						iconName: 'account-fill'
-					},
-				]
+				roleData: [],
+				selectRole: {},
+
+				loading: false,
 			}
+		},
+		created() {
+			this.getUserRole()
 		},
 
 		methods: {
-			
+			//获取当前角色的所有权限列表
+			async getUserRole() {
+				this.loading = !this.loading
+
+				const res = await getRoleListByIds({
+					roleIds: this.userInfo.role_id
+				})
+				this.roleData = []
+				let data = res.data
+				console.log(data)
+				data.forEach(e => {
+
+					this.roleData.push({
+						id: e.id,
+						iconName: 'account-fill',
+						roleName: e.roleName,
+						active: e.id == this.activeRoleId ? true : false
+					})
+				})
+
+				this.loading = !this.loading
+
+			},
+
+			select(item) {
+				this.selectRole = item
+			},
+
+			async submit() {
+				//保存当前激活的角色
+				store.commit("setActiveRoleId", this.selectRole.id)
+
+				//获取角色菜单
+				const res = await dynamicMenu(this.selectRole.id)
+
+				//把菜单存入store中
+				let data = res.data
+				const appMenu = data.filter(e => e.name == 'app')[0]
+				console.log("菜单:", appMenu)
+
+
+				this.$u.func.showToast("切换角色成功")
+			}
 		}
 	}
 </script>
@@ -77,7 +92,7 @@
 		display: flex;
 		flex-direction: column;
 		background: #F9F9FA;
-		
+
 		.cur-btn {
 			margin: 0 20rpx;
 			position: absolute;

--
Gitblit v1.9.3