linwe
2024-08-08 3c738f4fe2762bba8087e5a22fc0dc06560eab0e
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<template>
    <view class="container">
 
        <view class="row bgc-ff mt-20 flex f-d-c a-i-c  j-c-c">
 
 
            <!-- <u-row customStyle="margin-bottom: 10px">
                <u-col span="6">
                    <view class="demo-layout bg-purple-light">
                        离线/在线:
                    </view>
                </u-col>
                <u-col span="6">
                    <u-switch v-model="onLine" asyncChange @change="asyncChange"></u-switch>
                </u-col>
            </u-row> -->
 
            <view class="f-32 mb-20">
                当前状态 {{onLine?"在线 ":"离线"}}
            </view>
            <view class="round" :class="onLine?'bgc-main':' bgc-gray '" @click="asyncChange(!onLine)">
                {{onLine?"在线 ":"离线"}}
            </view>
 
 
        </view>
        <!-- <view> -->
        <!-- <role-list :roleData="roleData" :current-id="selectRole.id" @select="select"></role-list> -->
        <!-- <u-switch v-model="value13" asyncChange @change="asyncChange"></u-switch> -->
        <!-- </view> -->
 
        <!-- <footer-btn v-if="roleData.length" text="确定" @click="submit" /> -->
 
        <u-loading-page :loading="loading"></u-loading-page>
    </view>
</template>
 
<script>
    import {
        getUser,
        updateUserInfo
    } from "@/api/user.js"
    // import roleList from "@/subPackage/user/components/roleList.vue"
    // import {
    //     dynamicMenu,
    //     getRoleListByIds,
    // } from "@/api/system/role.js"
    export default {
        components: {
            // roleList
        },
 
        data() {
            return {
                onLine: false,
                userInfo: {},
                loading: false,
            }
        },
        created() {
            // this.selectRole = uni.getStorageSync("activeRole")
 
        },
        onShow() {
            this.getUserInfo()
        },
 
        methods: {
 
            asyncChange(e) {
                uni.showModal({
                    content: e ? '确定是否上线?' : '确定是否下线?',
                    success: (res) => {
                        if (res.confirm) {
                            this.onLine = e
                            if (e) {
                                this.userInfo.status = 2
                            } else {
                                this.userInfo.status = 1
                            }
                            updateUserInfo(this.userInfo).then(res => {
                                console.log("**********userInfo*************", res)
                                let userInfo = uni.getStorageSync("userInfo")
                                userInfo.status = this.userInfo.status
                                uni.setStorageSync("userInfo", userInfo)
                            })
                        }
                    }
                })
            },
            //获取当前角色的所有权限列表
            getUserInfo() {
                this.loading = !this.loading
                getUser(
                    uni.getStorageSync("userInfo").user_id
                ).then(res => {
                    this.userInfo = res.data
                    if (res.data.status && res.data.status == 2) {
                        this.onLine = true
                    } else {
                        this.onLine = false
                    }
                });
                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")
                            }, 500)
                        }
                    })
                });
 
            }
        }
    }
</script>
 
<style lang="scss">
    page {
        backgrond-color: #f5f5f5;
    }
 
    .row {
        // padding: 20rpx;
        // margin: 0 20rpx;
        // border-radius: 4rpx;
        padding-top: 200rpx;
    }
 
    .container {
        position: relative;
        width: 100%;
        height: 100%;
        display: flex;
        flex-direction: column;
        // background-color: #fff;
        // background: #F9F9FA;
 
 
    }
 
    .cur-btn {
        width: 100%;
        padding: 20rpx;
        position: fixed;
        bottom: 0;
        left: 0;
        box-sizing: border-box;
        z-index: 10;
 
    }
 
    .round {
        width: 200rpx;
        height: 200rpx;
        line-height: 200rpx;
        border-radius: 50%;
 
        text-align: center;
        color: #fff;
        font-weight: bold;
 
    }
 
    .bgc-gray {
        background: #949494;
    }
</style>