Lou
2023-11-17 eed35c26883b4dedddcbe4a8d3dedafdd4e5daf7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<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>
 
        <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 => {
                    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"
                    } 
                    // 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.$emit("refresh")
                            setTimeout(() => {
                                this.$u.func.globalNavigator("/pages/home/index", "switchTab")
                            }, 1000)
                        }
                    })
                });
                
            }
        }
    }
</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>