From 70894a1fa40bbbdbe4581727627e541804c08ade Mon Sep 17 00:00:00 2001
From: guoshilong <123456>
Date: Mon, 30 Oct 2023 14:25:21 +0800
Subject: [PATCH] 场所切换

---
 api/system/role.js                       |    2 
 api/doorplateAddress/doorplateAddress.js |   13 ++++
 pages/home/index.vue                     |   62 +++++++++++++++++---
 subPackage/user/components/roleList.vue  |    4 
 utils/func.js                            |   32 ++++++----
 subPackage/user/role/index.vue           |    8 +-
 store/index.js                           |    8 +-
 7 files changed, 94 insertions(+), 35 deletions(-)

diff --git a/api/doorplateAddress/doorplateAddress.js b/api/doorplateAddress/doorplateAddress.js
new file mode 100644
index 0000000..a8c9cf3
--- /dev/null
+++ b/api/doorplateAddress/doorplateAddress.js
@@ -0,0 +1,13 @@
+import http from '@/http/api.js'
+
+//保存
+export const getFuncList = (type, roleName) => {
+	return http.request({
+		url: 'blade-doorplateAddress/doorplateAddress/getFuncList',
+		method: 'GET',
+		params: {
+			type,
+			roleName
+		}
+	})
+}
\ No newline at end of file
diff --git a/api/system/role.js b/api/system/role.js
index 1fd4a6f..430ee83 100644
--- a/api/system/role.js
+++ b/api/system/role.js
@@ -55,7 +55,7 @@
 
 export const getDetail = (params) => {
 	return http.request({
-		url: '/api/blade-system/role/detail',
+		url: '/blade-system/role/detail',
 		method: 'GET',
 		params
 	})
diff --git a/pages/home/index.vue b/pages/home/index.vue
index 8a8a70c..14c76d4 100644
--- a/pages/home/index.vue
+++ b/pages/home/index.vue
@@ -14,11 +14,11 @@
 			<view class="main-select" @click="selectBoxShow = !selectBoxShow">
 				<u-icon name="map" color="#fff"></u-icon>
 				<view>
-					当前场所:暂无绑定场所信息
+					当前场所:{{curSelectSite.name?curSelectSite.name:'暂无绑定场所信息'}}
 				</view>
 
-				<u-picker title="场所" :show="selectBoxShow" ref="uPicker" :columns="columns" @confirm="confirm"
-					@change="changeHandler"></u-picker>
+				<u-picker title="场所" :show="selectBoxShow" keyName="name" ref="uPicker" :columns="siteColumns"
+					@confirm="confirm" @change="changeHandler"></u-picker>
 			</view>
 
 			<view class="main-btn">
@@ -91,6 +91,9 @@
 	import curMenu from "@/components/curMenu/index.vue";
 	import menuList from "@/components/menuList/index.vue";
 	import gridMenu from "@/components/gridMenu/index.vue";
+	import {
+		getFuncList
+	} from "@/api/doorplateAddress/doorplateAddress";
 
 	export default {
 		components: {
@@ -103,10 +106,10 @@
 		data() {
 			return {
 				menuList: [],
+				selectRole: {},
 				selectBoxShow: false,
-				columns: [
-					['中国', '美国']
-				],
+				siteColumns: [],
+				curSelectSite: {},
 				columnData: [],
 				btnList: [{
 						imgUrl: '/static/img/sys.png',
@@ -172,9 +175,7 @@
 		},
 
 		onShow() {
-			this.menuList = uni.getStorageSync("menu")
-			this.getMenuList()
-			uni.hideTabBar()
+			this.init()
 		},
 
 		computed: {
@@ -193,6 +194,48 @@
 		},
 
 		methods: {
+			//初始化
+			init() {
+				this.curSelectSite = {}
+				this.menuList = uni.getStorageSync("menu")
+				this.selectRole = uni.getStorageSync("activeRole")
+				this.getMenuList()
+				this.getSiteList()
+				uni.hideTabBar()
+			},
+			//获取场所列表
+			async getSiteList() {
+				console.log(this.selectRole)
+				let type = null
+				let roleName = this.selectRole.roleName
+				console.log("roleName", roleName)
+				if (roleName == '网格员' || roleName == '系统管理员') {
+					type = 1
+				} else if (roleName == '场所负责人') {
+					type = 2
+				} else if (roleName == '居民') {
+					type = 3
+				}
+
+				const res = await getFuncList(type, roleName)
+				console.log(res, "-----------")
+				let data = res.data
+				this.siteColumns = []
+
+				this.buildSiteColumn(data, 0)
+				console.log(this.siteColumns)
+
+			},
+
+			buildSiteColumn(dataList, index) {
+				if (dataList.length > 0) {
+					this.siteColumns[index] = dataList
+					if (dataList[0].children && dataList[0].children.length > 0) {
+						this.buildSiteColumn(dataList[0].children, index + 1)
+					}
+				}
+			},
+
 			//获取首页菜单
 			getMenuList() {
 				console.log("当前角色菜单", this.menuList)
@@ -296,6 +339,7 @@
 			// 回调参数为包含columnIndex、value、values
 			confirm(e) {
 				console.log('confirm', e)
+				this.curSelectSite = e.value[e.value.length - 1]
 				this.selectBoxShow = false
 			}
 		}
diff --git a/store/index.js b/store/index.js
index 7b99d17..c0230a6 100644
--- a/store/index.js
+++ b/store/index.js
@@ -47,7 +47,7 @@
 		isLogin: lifeData.isLogin ? lifeData.isLogin : false,
 		// 如果version无需保存到本地永久存储,无需lifeData.version方式
 		version: '1.0.0',
-		activeRoleId: "",
+		activeRole: {},
 		// tabBarList: [],
 		adCodeBase: {},
 		// tabbarIndex: uni.getStorageSync("tabbarIndex") || 0,
@@ -93,9 +93,9 @@
 		// 	// console.log(uni.getStorageSync('tabBarList'))
 		// },
 		//设置当前激活的角色
-		setActiveRoleId(state, roleId) {
-			state.activeRoleId = roleId
-			uni.setStorageSync('activeRoleId', roleId)
+		setActiveRole(state, role) {
+			state.activeRole = role
+			uni.setStorageSync('activeRole', role)
 		},
 
 		SET_MENU(state, menuList) {
diff --git a/subPackage/user/components/roleList.vue b/subPackage/user/components/roleList.vue
index 18d35fa..cedcfe7 100644
--- a/subPackage/user/components/roleList.vue
+++ b/subPackage/user/components/roleList.vue
@@ -1,6 +1,6 @@
 <template>
 	<view class="role-container">
-		<view @click="activeRole(item)" v-for="(item, index) in roleData" :key="index" :class="item.active?'active':''">
+		<view @click="enableRole(item)" v-for="(item, index) in roleData" :key="index" :class="item.active?'active':''">
 			<view class="l">
 				<u-icon :name="item.iconName"></u-icon>
 				<view class="role-name">
@@ -30,7 +30,7 @@
 		methods: {
 
 			//启用角色
-			activeRole(item) {
+			enableRole(item) {
 				this.roleData.forEach(role => {
 					if (role.id == item.id) {
 						role.active = true
diff --git a/subPackage/user/role/index.vue b/subPackage/user/role/index.vue
index e7409ea..e6ee920 100644
--- a/subPackage/user/role/index.vue
+++ b/subPackage/user/role/index.vue
@@ -33,6 +33,7 @@
 			}
 		},
 		created() {
+			this.selectRole = uni.getStorageSync("activeRole")
 			this.getUserRole()
 		},
 
@@ -52,11 +53,10 @@
 						id: e.id,
 						iconName: 'account-fill',
 						roleName: e.roleName,
-						active: e.id == this.activeRoleId ? true : false
+						active: e.id == this.selectRole.id ? true : false
 					})
 				})
 
-				this.selectRole = this.roleData.filter(e => e.id == this.activeRoleId)[0]
 				this.loading = !this.loading
 
 			},
@@ -70,17 +70,15 @@
 				const that = this
 
 				//保存当前激活的角色
-				store.commit("setActiveRoleId", this.selectRole.id)
+				store.commit("setActiveRole", this.selectRole)
 
 				//获取角色菜单
 				const res = await dynamicMenu(this.selectRole.id)
-				console.log(res, "*/*/*/*/*/*")
 				//把菜单存入store中
 				let data = res.data
 				const appMenu = data.filter(e => e.name == 'app')[0].children
 				console.log("菜单:", appMenu)
 				store.commit("SET_MENU", appMenu)
-
 
 
 				uni.showToast({
diff --git a/utils/func.js b/utils/func.js
index b3bcb9c..3362a2b 100644
--- a/utils/func.js
+++ b/utils/func.js
@@ -1,6 +1,7 @@
 import store from "@/store/index.js"
 import {
-	dynamicMenu
+	dynamicMenu,
+	getDetail
 } from "@/api/system/role.js"
 import {
 	logAdd
@@ -10,30 +11,33 @@
 const install = (Vue, vm) => {
 
 	// 登录操作 1
-	const login = (userInfo) => {
+	const login = async (userInfo) => {
 
 		vm.$u.vuex('userInfo', userInfo)
 		vm.$u.vuex('accessToken', userInfo.access_token)
 		vm.$u.vuex('isLogin', true)
 
 		let activeRoleId = userInfo.role_id.split(",")[0]
-		console.log("当前激活角色的id:", activeRoleId)
 
-		//添加当前激活的roleId(默认取第一个)
-		vm.$u.vuex('activeRoleId', activeRoleId)
+		const resDetail = await getDetail({
+			id: activeRoleId
+		})
+		console.log("当前激活角色的id:", resDetail.data)
+		//添加当前激活的角色(默认取第一个)
+		store.commit('setActiveRole', resDetail.data)
 
 		//获取角色菜单
-		dynamicMenu(activeRoleId).then(res => {
-			let data = res.data
-			let appMenu = data.filter(e => e.name == 'app')[0].children
-			console.log("当前角色菜单:", appMenu)
-			store.commit('SET_MENU', appMenu)
+		const {
+			data
+		} = await dynamicMenu(activeRoleId)
 
-			//跳转到首页
-			uni.switchTab({
-				url: '/pages/home/index'
-			})
+		let appMenu = data.filter(e => e.name == 'app')[0].children
+		console.log("当前角色菜单:", appMenu)
+		store.commit('SET_MENU', appMenu)
 
+		//跳转到首页
+		uni.switchTab({
+			url: '/pages/home/index'
 		})
 	}
 

--
Gitblit v1.9.3