From a669939c58b97861e3448bce36eb0bccd80ee20a Mon Sep 17 00:00:00 2001
From: guoshilong <123456>
Date: Mon, 30 Oct 2023 10:40:04 +0800
Subject: [PATCH] 角色切换

---
 components/curMenu/index.vue   |   38 +++---
 pages/home/index.vue           |  194 ++++++++++++++++++++++----------------
 utils/func.js                  |    4 
 subPackage/user/role/index.vue |    5 
 components/tabBar/tabBar.vue   |   11 --
 5 files changed, 137 insertions(+), 115 deletions(-)

diff --git a/components/curMenu/index.vue b/components/curMenu/index.vue
index f212f45..80c6bd1 100644
--- a/components/curMenu/index.vue
+++ b/components/curMenu/index.vue
@@ -1,15 +1,16 @@
 <template>
-		<view class="menu-box" @click="curMenuClick(curMenu)">
-			<view v-if="imgShow">
-				<u--image :src="curMenu.imgUrl" :width='curMenu.imgWidth || 54' :height='curMenu.imgHeight || 54' shape="circle"></u--image>
-			</view>
-			<view v-if="textShow" :style="{height: curMenu.numHeight ? curMenu.numHeight + 'px' : '56rpx'}">
-				{{curMenu.num}}
-			</view>
-			<view :style="{height: curMenu.titleHeight ? curMenu.titleHeight + 'px' : '56rpx'}">
-				{{curMenu.title}}
-			</view>
+	<view class="menu-box" @click="curMenuClick(curMenu)">
+		<view v-if="imgShow">
+			<u--image :src="curMenu.imgUrl" :width='curMenu.imgWidth || 40' :height='curMenu.imgHeight || 40'
+				shape="circle"></u--image>
 		</view>
+		<view v-if="textShow" :style="{height: curMenu.numHeight ? curMenu.numHeight + 'px' : '56rpx'}">
+			{{curMenu.num}}
+		</view>
+		<view :style="{height: curMenu.titleHeight ? curMenu.titleHeight + 'px' : '56rpx'}">
+			{{curMenu.title}}
+		</view>
+	</view>
 </template>
 
 <script>
@@ -21,22 +22,22 @@
 					return {}
 				}
 			},
-				
+
 			imgShow: {
 				type: Boolean,
 				default: true
 			},
-			
+
 			textShow: {
 				type: Boolean,
 				default: false
 			},
 		},
-		
+
 		methods: {
 			curMenuClick(e) {
 				console.log('当前点击处')
-				
+
 				if (e.event) {
 					e.event(e)
 				}
@@ -50,16 +51,15 @@
 		display: flex;
 		flex-direction: column;
 		font-size: 28rpx;
-		
-		& > view {
+
+		&>view {
 			display: flex;
 			justify-content: center;
 			align-items: center;
 		}
-		
-		& > view:first-child {
+
+		&>view:first-child {
 			flex: 1;
 		}
 	}
-	
 </style>
\ No newline at end of file
diff --git a/components/tabBar/tabBar.vue b/components/tabBar/tabBar.vue
index 0c23be8..e047ef0 100644
--- a/components/tabBar/tabBar.vue
+++ b/components/tabBar/tabBar.vue
@@ -9,9 +9,6 @@
 </template>
 
 <script>
-	import {
-		messageCount,
-	} from "@/api/system/message.js"
 	export default {
 		props: {
 			currentTab: {},
@@ -65,15 +62,7 @@
 		},
 		methods: {
 			change(e) {
-				this.$store.commit("SET_TABBAT_INDEX", e)
 				this.$emit("change", this.curTabList[e].url)
-				let params = {
-					recipient: this.userInfo.user_id,
-					status: 0
-				}
-				messageCount(params).then(res => {
-					this.$u.func.updateTabbar(res.data)
-				})
 			},
 
 		}
diff --git a/pages/home/index.vue b/pages/home/index.vue
index 5352c35..430afc7 100644
--- a/pages/home/index.vue
+++ b/pages/home/index.vue
@@ -26,11 +26,11 @@
 			</view>
 
 			<view class="main-phone-house">
-				<view class="phone-box">
+				<view v-if="gridDataList.length>0" class="phone-box">
 					<grid-menu :gridData='item' v-for="(item, index) in gridDataList" :key='index'></grid-menu>
 				</view>
 
-				<view class="house-box">
+				<view v-if="hasMenu('楼盘表').length>0" class="house-box">
 					<box-title :title="'楼盘表'"></box-title>
 					<view class="content">
 						<grid-menu :gridData='item' v-for="(item, index) in houseDataList" :key='index'></grid-menu>
@@ -39,7 +39,7 @@
 			</view>
 
 			<view class="main-bt pb-40">
-				<view class="mt-20">
+				<view v-if="liveList.length>0" class="mt-20">
 					<box-title :title="'生活'"></box-title>
 
 					<view class="mt-20 b-c-w">
@@ -47,7 +47,7 @@
 					</view>
 				</view>
 
-				<view class="mt-20">
+				<view v-if="jobList.length>0" class="mt-20">
 					<box-title :title="'工作台'"></box-title>
 
 					<view class="mt-20 b-c-w">
@@ -97,6 +97,7 @@
 
 		data() {
 			return {
+				menuList: uni.getStorageSync("menu") || [],
 				tabList: uni.getStorageSync("tabBarList") || [],
 				selectBoxShow: false,
 				columns: [
@@ -105,32 +106,20 @@
 				columnData: [],
 				btnList: [{
 						imgUrl: '/static/img/sys.png',
-						title: '扫一扫'
+						title: '扫一扫',
+						imgWidth: 54,
+						imgHeight: 54
 					},
 					{
 						imgUrl: '/static/img/bs.png',
-						title: '报事'
+						title: '报事',
+						imgWidth: 54,
+						imgHeight: 54
 					}
 				],
-				gridDataList: [{
-						title: '物业',
-						data: '无数据',
-						phone: '无'
-					},
-					{
-						title: '综治网格',
-						data: '无数据',
-						phone: '无'
-					},
-					{
-						title: '公安网格',
-						data: '无数据',
-						phone: '无'
-					}
-				],
+				gridDataList: [],
 
-				houseDataList: [
-					{
+				houseDataList: [{
 						title: '万达广场',
 						useSlot: true
 					},
@@ -148,63 +137,9 @@
 					}
 				],
 
-				liveList: [{
-						imgUrl: '/static/img/ggbs.png',
-						title: '公共报事',
-						imgWidth: 40,
-						imgHeight: 40
-					},
-					{
-						imgUrl: '/static/img/bmrx.png',
-						title: '便民热线',
-						imgWidth: 40,
-						imgHeight: 40
-					},
-					{
-						imgUrl: '/static/img/zhsb.png',
-						title: '租户上报',
-						imgWidth: 40,
-						imgHeight: 40
-					}
-				],
+				liveList: [],
 
-				jobList: [{
-						imgUrl: '/static/img/ggbs.png',
-						title: '场所记录',
-						imgWidth: 40,
-						imgHeight: 40
-					},
-					{
-						imgUrl: '/static/img/bmrx.png',
-						title: '场所采集',
-						imgWidth: 40,
-						imgHeight: 40
-					},
-					{
-						imgUrl: '/static/img/zhsb.png',
-						title: '出租房管理',
-						imgWidth: 40,
-						imgHeight: 40
-					},
-					{
-						imgUrl: '/static/img/zhsb.png',
-						title: '标签事件',
-						imgWidth: 40,
-						imgHeight: 40
-					},
-					{
-						imgUrl: '/static/img/zhsb.png',
-						title: '场所维护',
-						imgWidth: 40,
-						imgHeight: 40
-					},
-					{
-						imgUrl: '/static/img/zhsb.png',
-						title: '报事审核',
-						imgWidth: 40,
-						imgHeight: 40
-					}
-				],
+				jobList: [],
 
 				taskTypeList: [{
 						title: '一次性',
@@ -233,10 +168,107 @@
 		},
 
 		onShow() {
+			this.getMenuList()
 			uni.hideTabBar()
 		},
 
+		computed: {
+			hasMenu() {
+				return (name) => {
+					let resultArr = []
+					resultArr = this.getMenu(name, this.menuList, resultArr)
+					if (resultArr.length > 0) {
+						return resultArr
+					} else {
+						return []
+					}
+
+				}
+			}
+		},
+
 		methods: {
+			//获取首页菜单
+			getMenuList() {
+				console.log("当前角色菜单", this.menuList)
+				this.getPhoneList()
+				this.getLiveList()
+				this.getWorkbenchList()
+			},
+			getPhoneList() {
+				this.gridDataList = []
+				const resultArr = this.hasMenu('快捷拨号')
+				if (resultArr.length == 0) {
+					return
+				}
+
+				const topMenu = resultArr[0]
+
+				topMenu.children.forEach(menu => {
+					this.gridDataList.push({
+						title: menu.name,
+						data: "无数据",
+						phone: "无"
+					})
+				})
+			},
+
+			//获取生活菜单
+			getLiveList() {
+				this.liveList = []
+				const resultArr = this.hasMenu('生活')
+				if (resultArr.length == 0) {
+					return
+				}
+
+				const topMenu = resultArr[0]
+
+				topMenu.children.forEach(menu => {
+					this.liveList.push({
+						imgUrl: menu.source,
+						title: menu.name,
+					})
+				})
+			},
+
+			//获取工作台菜单
+			getWorkbenchList() {
+				this.jobList = []
+				const resultArr = this.hasMenu('工作台')
+				if (resultArr.length == 0) {
+					return
+				}
+
+				const topMenu = resultArr[0]
+
+				topMenu.children.forEach(menu => {
+					this.jobList.push({
+						imgUrl: menu.source,
+						title: menu.name,
+					})
+				})
+			},
+
+
+
+
+
+			getMenu(menuName, menuList, resultArr) {
+				// console.log(menuList, menuName)
+				for (var i = 0; i < menuList.length; i++) {
+					if (menuList[i].name == menuName) {
+						resultArr.push(menuList[i])
+					} else {
+						if (menuList[i].children && menuList[i].children.length) {
+							this.getMenu(menuName, menuList[i].children, resultArr);
+						}
+					}
+				}
+
+				return resultArr
+
+			},
+
 			change(index) {
 				let url = index
 				this.$u.func.globalNavigator(url, "switchTab")
@@ -326,7 +358,7 @@
 					.content {
 						display: flex;
 						flex-wrap: wrap;
-						
+
 						&>view {
 							margin: 0 16rpx;
 							margin-top: 20rpx;
diff --git a/subPackage/user/role/index.vue b/subPackage/user/role/index.vue
index 837cb40..fb1a7fe 100644
--- a/subPackage/user/role/index.vue
+++ b/subPackage/user/role/index.vue
@@ -63,6 +63,7 @@
 
 			select(item) {
 				this.selectRole = item
+				console.log("当前选中角色", this.selectRole)
 			},
 
 			async submit() {
@@ -73,10 +74,10 @@
 
 				//获取角色菜单
 				const res = await dynamicMenu(this.selectRole.id)
-
+				console.log(res, "*/*/*/*/*/*")
 				//把菜单存入store中
 				let data = res.data
-				const appMenu = data.filter(e => e.name == 'app')[0]
+				const appMenu = data.filter(e => e.name == 'app')[0].children
 				console.log("菜单:", appMenu)
 				store.commit("SET_MENU", appMenu)
 
diff --git a/utils/func.js b/utils/func.js
index b9ef044..b3bcb9c 100644
--- a/utils/func.js
+++ b/utils/func.js
@@ -25,9 +25,9 @@
 		//获取角色菜单
 		dynamicMenu(activeRoleId).then(res => {
 			let data = res.data
-			let appMenu = data.filter(e => e.name == 'app')[0]
+			let appMenu = data.filter(e => e.name == 'app')[0].children
 			console.log("当前角色菜单:", appMenu)
-			vm.$u.vuex('menu', appMenu)
+			store.commit('SET_MENU', appMenu)
 
 			//跳转到首页
 			uni.switchTab({

--
Gitblit v1.9.3