<template>
|
<view class="container">
|
<view>
|
<role-list :roleData="roleData" :current-id="selectRole.id" @select="select"></role-list>
|
</view>
|
|
<!-- <view class="cur-btn" v-if="roleData.length">
|
<u-button @click="submit" type="primary" text="确定"></u-button>
|
</view> -->
|
|
<footer-btn v-if="roleData.length" text="确定" @click="submit" />
|
|
|
<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 {
|
roleData: [],
|
selectRole: {},
|
loading: false,
|
}
|
},
|
created() {
|
this.selectRole = uni.getStorageSync("activeRole")
|
this.getUserRole()
|
},
|
|
methods: {
|
//获取当前角色的所有权限列表
|
async getUserRole() {
|
this.loading = !this.loading
|
|
const res = await getRoleListByIds({
|
roleIds: this.userInfo.role_id
|
})
|
let data = res.data
|
console.log(data)
|
data.forEach((item, index) => {
|
if (item.roleName == "居民") {
|
item.icon = "/static/icon/user-01.png"
|
} else if (item.roleName == "场所负责人") {
|
item.icon = "/static/icon/user-02.png"
|
} else {
|
item.icon = "/static/icon/user-03.png"
|
}
|
|
if (item.roleName == "物业管理员") {
|
data.splice(index, 1);
|
}
|
// this.roleData.push({
|
// id: e.id,
|
// iconName: 'account-fill',
|
// roleName: e.roleName,
|
// active: e.id == this.selectRole.id ? true : false
|
// })
|
})
|
|
this.roleData = data;
|
this.loading = !this.loading
|
},
|
|
select(item) {
|
this.selectRole = item
|
console.log("当前选中角色", this.selectRole)
|
},
|
|
async submit() {
|
//保存当前激活的角色
|
this.$store.commit("setActiveRole", this.selectRole)
|
// const res = await dynamicMenu(this.selectRole.id)
|
// let data = res.data
|
// const appMenu = data.filter(e => e.name == 'app')[0].children
|
// console.log("菜单:", appMenu)
|
// store.commit("SET_MENU", appMenu)
|
this.$store.dispatch("getMenuList").then(res => {
|
uni.showToast({
|
title: "切换身份成功",
|
icon: "success",
|
duration: 1500,
|
success: () => {
|
uni.removeStorageSync("siteInfo")
|
uni.$emit("refresh")
|
setTimeout(() => {
|
this.$u.func.globalNavigator("/pages/home/index",
|
"switchTab")
|
}, 500)
|
}
|
})
|
});
|
|
}
|
}
|
}
|
</script>
|
|
<style lang="scss" scoped>
|
.container {
|
position: relative;
|
width: 100%;
|
height: 100%;
|
display: flex;
|
flex-direction: column;
|
// background: #F9F9FA;
|
|
|
}
|
|
.cur-btn {
|
width: 100%;
|
padding: 20rpx;
|
position: fixed;
|
bottom: 0;
|
left: 0;
|
box-sizing: border-box;
|
z-index: 10;
|
|
}
|
</style>
|