userinfo.vue 6.7 KB
Newer Older
DCloud_JSON's avatar
DCloud_JSON 已提交
1
<!-- 用户资料页 -->
DCloud_JSON's avatar
DCloud_JSON 已提交
2 3 4 5 6 7 8 9
<template>
	<view class="uni-content">
		<view class="avatar">
			<uni-id-pages-avatar width="260rpx" height="260rpx"></uni-id-pages-avatar>
		</view>
		<uni-list>
			<uni-list-item class="item" @click="setNickname('')" title="昵称" :rightText="userInfo.nickname||'未设置'" link>
			</uni-list-item>
DCloud_JSON's avatar
DCloud_JSON 已提交
10 11
			<uni-list-item class="item" @click="bindMobile" title="手机号" :rightText="userInfo.mobile||'未绑定'" link>
			</uni-list-item>
12 13
			<uni-list-item v-if="userInfo.email" class="item" title="电子邮箱" :rightText="userInfo.email">
			</uni-list-item>
14 15 16 17 18
			<!-- #ifdef APP -->
      <!-- 如未开通实人认证服务,可以将实名认证入口注释 -->
			<uni-list-item class="item" @click="realNameVerify" title="实名认证" :rightText="realNameStatus !== 2 ? '未认证': '已认证'" link>
			</uni-list-item>
			<!-- #endif -->
DCloud_JSON's avatar
DCloud_JSON 已提交
19
			<uni-list-item v-if="hasPwd" class="item" @click="changePassword" title="修改密码" link>
DCloud_JSON's avatar
DCloud_JSON 已提交
20 21
			</uni-list-item>
		</uni-list>
22
		<!-- #ifndef MP -->
DCloud_JSON's avatar
DCloud_JSON 已提交
23 24 25
		<uni-list class="mt10">
			<uni-list-item @click="deactivate" title="注销账号" link="navigateTo"></uni-list-item>
		</uni-list>
26
		<!-- #endif -->
DCloud_JSON's avatar
DCloud_JSON 已提交
27
		<uni-popup ref="dialog" type="dialog">
C
chenruilong 已提交
28 29
			<uni-popup-dialog mode="input" :value="userInfo.nickname" @confirm="setNickname" :inputType="setNicknameIng?'nickname':'text'"
				title="设置昵称" placeholder="请输入要设置的昵称">
DCloud_JSON's avatar
DCloud_JSON 已提交
30 31
			</uni-popup-dialog>
		</uni-popup>
DCloud_JSON's avatar
1.0.20  
DCloud_JSON 已提交
32
		<uni-id-pages-bind-mobile ref="bind-mobile-by-sms" @success="bindMobileSuccess"></uni-id-pages-bind-mobile>
DCloud_JSON's avatar
1.0.12  
DCloud_JSON 已提交
33
		<template v-if="showLoginManage">
DCloud_JSON's avatar
1.0.20  
DCloud_JSON 已提交
34
			<button v-if="userInfo._id" @click="logout">退出登录</button>
DCloud_JSON's avatar
1.0.12  
DCloud_JSON 已提交
35 36
			<button v-else @click="login">去登录</button>
		</template>
DCloud_JSON's avatar
DCloud_JSON 已提交
37 38 39
	</view>
</template>
<script>
C
chenruilong 已提交
40 41 42 43 44
	const uniIdCo = uniCloud.importObject("uni-id-co")
	import {
		store,
		mutations
	} from '@/uni_modules/uni-id-pages/common/store.js'
DCloud_JSON's avatar
DCloud_JSON 已提交
45
	export default {
C
chenruilong 已提交
46 47 48 49 50 51 52 53
		computed: {
			userInfo() {
				return store.userInfo
			},
      realNameStatus () {
        if (!this.userInfo.realNameAuth) {
          return 0
        }
54

C
chenruilong 已提交
55 56 57
        return this.userInfo.realNameAuth.authStatus
      }
		},
DCloud_JSON's avatar
DCloud_JSON 已提交
58 59 60 61 62 63 64 65 66 67
		data() {
			return {
				univerifyStyle: {
					authButton: {
						"title": "本机号码一键绑定", // 授权按钮文案
					},
					otherLoginButton: {
						"title": "其他号码绑定",
					}
				},
DCloud_JSON's avatar
1.0.20  
DCloud_JSON 已提交
68 69 70 71
				// userInfo: {
				// 	mobile:'',
				// 	nickname:''
				// },
C
chenruilong 已提交
72
				hasPwd: false,
DCloud_JSON's avatar
v1.1.1  
DCloud_JSON 已提交
73
				showLoginManage: false ,//通过页面传参隐藏登录&退出登录按钮
C
chenruilong 已提交
74
				setNicknameIng:false
DCloud_JSON's avatar
DCloud_JSON 已提交
75 76 77 78 79 80
			}
		},
		async onShow() {
			this.univerifyStyle.authButton.title = "本机号码一键绑定"
			this.univerifyStyle.otherLoginButton.title = "其他号码绑定"
		},
DCloud_JSON's avatar
1.0.12  
DCloud_JSON 已提交
81
		async onLoad(e) {
C
chenruilong 已提交
82 83
			if (e.showLoginManage) {
				this.showLoginManage = true //通过页面传参隐藏登录&退出登录按钮
DCloud_JSON's avatar
1.0.12  
DCloud_JSON 已提交
84
			}
DCloud_JSON's avatar
DCloud_JSON 已提交
85 86
			//判断当前用户是否有密码,否则就不显示密码修改功能
			let res = await uniIdCo.getAccountInfo()
DCloud_JSON's avatar
DCloud_JSON 已提交
87 88 89 90 91 92 93
			this.hasPwd = res.isPasswordSet
		},
		methods: {
			login() {
				uni.navigateTo({
					url: '/uni_modules/uni-id-pages/pages/login/login-withoutpwd',
					complete: (e) => {
study夏羽's avatar
1.0.37  
study夏羽 已提交
94
						// console.log(e);
DCloud_JSON's avatar
DCloud_JSON 已提交
95 96 97
					}
				})
			},
C
chenruilong 已提交
98 99 100 101 102 103 104
			logout() {
				mutations.logout()
			},
			bindMobileSuccess() {
				mutations.updateUserInfo()
			},
			changePassword() {
DCloud_JSON's avatar
DCloud_JSON 已提交
105
				uni.navigateTo({
DCloud_JSON's avatar
DCloud_JSON 已提交
106
					url: '/uni_modules/uni-id-pages/pages/userinfo/change_pwd/change_pwd',
DCloud_JSON's avatar
DCloud_JSON 已提交
107
					complete: (e) => {
study夏羽's avatar
1.0.37  
study夏羽 已提交
108
						// console.log(e);
DCloud_JSON's avatar
DCloud_JSON 已提交
109 110
					}
				})
DCloud_JSON's avatar
DCloud_JSON 已提交
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
			},
			bindMobile() {
				// #ifdef APP-PLUS
				uni.preLogin({
					provider: 'univerify',
					success: this.univerify(), //预登录成功
					fail: (res) => { // 预登录失败
						// 不显示一键登录选项(或置灰)
						console.log(res)
						this.bindMobileBySmsCode()
					}
				})
				// #endif

				// #ifdef MP-WEIXIN
126
				this.$refs['bind-mobile-by-sms'].open()
DCloud_JSON's avatar
DCloud_JSON 已提交
127 128 129 130 131 132 133 134 135 136 137 138 139
				// #endif

				// #ifdef H5
				//...去用验证码绑定
				this.bindMobileBySmsCode()
				// #endif
			},
			univerify() {
				uni.login({
					"provider": 'univerify',
					"univerifyStyle": this.univerifyStyle,
					success: async e => {
						uniIdCo.bindMobileByUniverify(e.authResult).then(res => {
study夏羽's avatar
1.0.37  
study夏羽 已提交
140
							mutations.updateUserInfo()
DCloud_JSON's avatar
DCloud_JSON 已提交
141 142
						}).catch(e => {
							console.log(e);
C
chenruilong 已提交
143
						}).finally(e => {
study夏羽's avatar
1.0.37  
study夏羽 已提交
144
							// console.log(e);
DCloud_JSON's avatar
DCloud_JSON 已提交
145 146 147 148 149 150 151 152 153 154 155 156
							uni.closeAuthView()
						})
					},
					fail: (err) => {
						console.log(err);
						if (err.code == '30002' || err.code == '30001') {
							this.bindMobileBySmsCode()
						}
					}
				})
			},
			bindMobileBySmsCode() {
study夏羽's avatar
1.0.37  
study夏羽 已提交
157 158 159
				uni.navigateTo({
					url: './bind-mobile/bind-mobile'
				})
DCloud_JSON's avatar
DCloud_JSON 已提交
160 161
			},
			setNickname(nickname) {
study夏羽's avatar
1.0.37  
study夏羽 已提交
162
				if (nickname) {
C
chenruilong 已提交
163 164
					mutations.updateUserInfo({
						nickname
study夏羽's avatar
1.0.37  
study夏羽 已提交
165
					})
C
chenruilong 已提交
166
					this.setNicknameIng = false
study夏羽's avatar
1.0.37  
study夏羽 已提交
167
					this.$refs.dialog.close()
DCloud_JSON's avatar
v1.1.1  
DCloud_JSON 已提交
168
				} else {
C
chenruilong 已提交
169
					this.setNicknameIng = true
study夏羽's avatar
1.0.37  
study夏羽 已提交
170 171
					this.$refs.dialog.open()
				}
DCloud_JSON's avatar
DCloud_JSON 已提交
172
			},
C
chenruilong 已提交
173
			deactivate() {
DCloud_JSON's avatar
DCloud_JSON 已提交
174
				uni.navigateTo({
C
chenruilong 已提交
175
					url: "/uni_modules/uni-id-pages/pages/userinfo/deactivate/deactivate"
DCloud_JSON's avatar
DCloud_JSON 已提交
176
				})
177
			},
study夏羽's avatar
1.0.37  
study夏羽 已提交
178 179 180 181 182 183 184
			async bindThirdAccount(provider) {
				const uniIdCo = uniCloud.importObject("uni-id-co")
				const bindField = {
					weixin: 'wx_openid',
					alipay: 'ali_openid',
					apple: 'apple_openid',
					qq: 'qq_openid'
C
chenruilong 已提交
185
				} [provider.toLowerCase()]
186

study夏羽's avatar
1.0.37  
study夏羽 已提交
187 188 189 190 191 192 193 194
				if (this.userInfo[bindField]) {
					await uniIdCo['unbind' + provider]()
					await mutations.updateUserInfo()
				} else {
					uni.login({
						provider: provider.toLowerCase(),
						onlyAuthorize: true,
						success: async e => {
C
chenruilong 已提交
195 196 197
							const res = await uniIdCo['bind' + provider]({
								code: e.code
							})
study夏羽's avatar
1.0.37  
study夏羽 已提交
198 199 200 201 202 203 204 205 206 207 208 209 210 211
							if (res.errCode) {
								uni.showToast({
									title: res.errMsg || '绑定失败',
									duration: 3000
								})
							}
							await mutations.updateUserInfo()
						},
						fail: async (err) => {
							console.log(err);
							uni.hideLoading()
						}
					})
				}
212 213 214 215 216
			},
			realNameVerify () {
				uni.navigateTo({
					url: "/uni_modules/uni-id-pages/pages/userinfo/realname-verify/realname-verify"
				})
study夏羽's avatar
1.0.37  
study夏羽 已提交
217
			}
DCloud_JSON's avatar
DCloud_JSON 已提交
218 219 220 221
		}
	}
</script>
<style lang="scss" scoped>
DCloud_JSON's avatar
1.0.20  
DCloud_JSON 已提交
222
	@import "@/uni_modules/uni-id-pages/common/login-page.scss";
DCloud_JSON's avatar
DCloud_JSON 已提交
223 224 225 226 227 228 229 230 231 232 233

	.uni-content {
		padding: 0;
	}

	/* #ifndef APP-NVUE */
	view {
		display: flex;
		box-sizing: border-box;
		flex-direction: column;
	}
C
chenruilong 已提交
234

DCloud_JSON's avatar
1.0.12  
DCloud_JSON 已提交
235 236 237 238 239 240 241 242 243 244 245
	@media screen and (min-width: 690px) {
		.uni-content {
			padding: 0;
			max-width: 690px;
			margin-left: calc(50% - 345px);
			border: none;
			max-height: none;
			border-radius: 0;
			box-shadow: none;
		}
	}
C
chenruilong 已提交
246

DCloud_JSON's avatar
DCloud_JSON 已提交
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
	/* #endif */
	.avatar {
		align-items: center;
		justify-content: center;
		margin: 22px 0;
		width: 100%;
	}

	.item {
		flex: 1;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
	}

	button {
		margin: 10%;
		margin-top: 40px;
		border-radius: 0;
		background-color: #FFFFFF;
		width: 80%;
	}
269

C
chenruilong 已提交
270
	.mt10 {
DCloud_JSON's avatar
DCloud_JSON 已提交
271 272 273
		margin-top: 10px;
	}
</style>