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
192
193
194
195
196
197
198
199
200
201
<template>
<view class="container"
style="background-image: url('https://life.cloud.hjxbc.cn/sys/common/static/scott/pic/bg_me1_1692254734871.png');">
<view class="page">
<view class="user">
<template v-if="isLogin && userAvatar">
<image :src="userAvatar" class="icon"></image>
</template>
<view class="icon" @click="toLogin" v-else>
<uni-icons type="person" size="50px" color="#6A59F2"></uni-icons>
</view>
<template v-if="isLogin">
<view class="name" v-if="userName">{{userName}}</view>
<view class="phone" v-if="userPhone">{{userPhone}}</view>
<div class="information" @click="employeeEntry(1)">修改个人资料 ></div>
</template>
<teleport v-else>
<view class="name" @click="toLogin" style="margin-bottom: 36rpx;">请登录</view>
</teleport>
</view>
<view class="LogOut" v-if="isLogin" @click="logout">退出登录</view>
</view>
<authorization-modal ref="authorization" @loginEnd="onLoginEnd" @refuse="onRefuse" />
</view>
</template>
<script>
import authorizationModal from '@/components/authorization.vue'
let timer = null
export default {
components: {
authorizationModal
},
data() {
return {
isLogin: false,
userName: '',
userAvatar: '',
userPhone: '',
}
},
methods: {
toLogin() {
if (!this.isLogin) {
uni.hideTabBar()
this.$nextTick(() => {
this.$refs.authorization.onOpenLogin()
});
}
},
logout() {
let _this = this
uni.showModal({
title: '警告',
content: '确定退出登录!',
showCancel: true,
success: function(res) {
if (res.confirm) {
wx.clearStorage()
_this.onLoginEnd()
}
}
});
},
employeeEntry(type) {
if (this.isLogin) {
if (type == 1) {
uni.navigateTo({
url: '/pages/myInformation/index',
});
}
} else {
uni.hideTabBar()
this.$nextTick(() => {
this.$refs.authorization.onOpenLogin()
});
}
},
onLoginEnd() {
uni.showTabBar()
uni.reLaunch({
url: '/pages/home/index'
})
},
onRefuse() {
uni.showTabBar()
},
},
onLoad() {
const token = uni.getStorageSync('token');
if (token) {
this.isLogin = true
this.userName = uni.getStorageSync('user_name')
this.userAvatar = uni.getStorageSync('user_avatar')
this.userPhone = uni.getStorageSync('user_phone')
} else {
this.isLogin = false
}
},
onShow() {
const token = uni.getStorageSync('token');
if (token) {
this.isLogin = true
this.userName = uni.getStorageSync('user_name')
this.userAvatar = uni.getStorageSync('user_avatar')
this.userPhone = uni.getStorageSync('user_phone')
} else {
this.isLogin = false
}
},
onHide() {
if (timer) clearTimeout(timer)
timer = null
}
}
</script>
<style>
page {
background-color: #F8F6F9;
}
</style>
<style lang="scss" scoped>
.container {
width: 100%;
height: 100vh;
background-position: top center;
background-repeat: no-repeat;
background-color: #F8F8FA;
background-size: cover;
display: flex;
align-items: center;
}
.page {
width: 100%;
box-sizing: border-box;
padding: 0 85rpx;
}
.LogOut {
background-color: #6A59F2;
width: 100%;
height: 80rpx;
line-height: 80rpx;
border-radius: 40rpx;
border: 1px solid #B5B8ED;
box-sizing: border-box;
font-size: 28rpx;
color: #FFFFFF;
font-weight: bold;
text-align: center;
margin-top: 60rpx;
}
.user {
background-color: #ffffff;
border-radius: 20rpx;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 70rpx 30rpx;
.icon {
width: 160rpx;
height: 160rpx;
border-radius: 160rpx;
border: 1px solid #6A59F2;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
}
.name {
font-size: 36rpx;
color: #373737;
margin: 20rpx 0 10rpx;
}
.phone {
font-size: 28rpx;
color: #373737;
margin-bottom: 36rpx;
opacity: 0.55;
}
.information {
width: 300rpx;
height: 60rpx;
line-height: 60rpx;
border-radius: 30rpx;
border: 1px solid #B5B8ED;
font-size: 28rpx;
color: #6A59F2;
text-align: center;
}
}
</style>