settings.vue 7.5 KB
Newer Older
芊里 已提交
1
<template>
L
23  
linju 已提交
2
	<view class="content">
3
		<!-- 功能列表 -->
DCloud_JSON's avatar
DCloud_JSON 已提交
4
		<uni-list class="mt10" :border="false">
5
			<uni-list-item title="个人资料" to="/pages/ucenter/userinfo/userinfo" link="navigateTo"></uni-list-item>
6
			<uni-list-item v-if="userInfo.mobile" title="修改密码" :to="'/pages/ucenter/login-page/pwd-retrieve/pwd-retrieve?phoneNumber='+ userInfo.mobile" link="navigateTo"></uni-list-item>
DCloud_JSON's avatar
DCloud_JSON 已提交
7 8
		</uni-list>
		<!-- #ifndef H5 -->
DCloud_JSON's avatar
DCloud_JSON 已提交
9
		<uni-list class="mt10" :border="false">
10 11
			<!-- #ifdef APP-PLUS -->
			<!-- 检查push过程未结束不显示,push设置项 -->
DCloud_JSON's avatar
DCloud_JSON 已提交
12
			<uni-list-item title="清理缓存" @click="clearTmp" link></uni-list-item>
13
			<uni-list-item v-if="pushIsOn != 'wait'" @click.native="pushIsOn?pushServer.off():pushServer.on()" title="推送功能" showSwitch :switchChecked="pushIsOn"></uni-list-item>
14
			<!-- #endif -->
15
			<uni-list-item v-if="supportMode.includes('fingerPrint')" title="指纹解锁" @click.native="startSoterAuthentication('fingerPrint')" link></uni-list-item>
16
			<uni-list-item v-if="supportMode.includes('facial')" title="人脸解锁" @click="startSoterAuthentication('facial')" link></uni-list-item>
DCloud_JSON's avatar
DCloud_JSON 已提交
17
		</uni-list>
18
		<!-- #endif -->
DCloud_JSON's avatar
重构  
DCloud_JSON 已提交
19
		
DCloud_JSON's avatar
DCloud_JSON 已提交
20
		<!-- 退出/登录 按钮 -->
L
23  
linju 已提交
21
		<view class="bottom-back" @click="clickLogout">
22
			<text class="bottom-back-text" v-if="hasLogin">退出登录</text>
L
23  
linju 已提交
23 24
			<text class="bottom-back-text" v-else>登录</text>
		</view>
芊里 已提交
25 26 27 28
	</view>
</template>

<script>
29
	import pushServer from './dc-push/push.js';
L
23  
linju 已提交
30 31 32 33
	import {
		mapMutations,
		mapGetters
	} from 'vuex';
芊里 已提交
34 35
	export default {
		data() {
DCloud_JSON's avatar
DCloud_JSON 已提交
36
			return {
37
				pushServer:pushServer,
38 39
				supportMode:[],
				pushIsOn:"wait"
芊里 已提交
40
			}
L
23  
linju 已提交
41 42 43
		},
		computed: {
			...mapGetters({
44
				'userInfo': 'user/info',
45
				'hasLogin': 'user/hasLogin',
L
23  
linju 已提交
46
			})
芊里 已提交
47 48
		},
		onLoad() {
49 50 51 52 53 54 55
			// #ifdef APP-PLUS || MP-WEIXIN
			uni.checkIsSupportSoterAuthentication({
				success: (res) => {
					console.log(res);
					this.supportMode = res.supportMode
				},
				fail: (err) => {
56
					console.log(err);
57 58 59
				}
			})
			// #endif
芊里 已提交
60
		},
61 62 63 64
		onShow() {
			// 检查手机端获取推送是否开启
			//#ifdef APP-PLUS
			setTimeout(()=>{
65 66
				this.pushIsOn = pushServer.isOn();
			},300)
DCloud_JSON's avatar
重构  
DCloud_JSON 已提交
67
			//#endif
芊里 已提交
68 69 70 71
		},
		methods: {
			...mapMutations({
				logout: 'user/logout'
L
23  
linju 已提交
72 73 74
			}),
			toEdit() {
				uni.navigateTo({
75
					url: '/pages/ucenter/userinfo/userinfo'
L
23  
linju 已提交
76 77 78 79
				});
			},
			changePwd() {
				uni.navigateTo({
80
					url: '/pages/ucenter/login-page/pwd-retrieve/pwd-retrieve?phoneNumber='
81
						+ (this.userInfo && this.userInfo.mobile ? this.userInfo.mobile : ''),
L
23  
linju 已提交
82 83 84 85 86 87 88
					fail: err => {
						console.log(err);
					}
				});
			},
			/**
			 * 开始生物认证
芊里 已提交
89
			 */
DCloud_JSON's avatar
DCloud_JSON 已提交
90
			startSoterAuthentication(checkAuthMode) {
91
				console.log(checkAuthMode);
92
				let title = {"fingerPrint":"指纹解锁","facial":"人脸解锁"}[checkAuthMode]
L
23  
linju 已提交
93
				// 检查是否开启认证
94
				this.checkIsSoterEnrolledInDevice({checkAuthMode,title})
DCloud_JSON's avatar
DCloud_JSON 已提交
95
					.then(() => {
96
						console.log(checkAuthMode,title);
L
23  
linju 已提交
97 98
						// 开始认证
						uni.startSoterAuthentication({
99
							requestAuthModes: [checkAuthMode],
L
23  
linju 已提交
100
							challenge: '123456', // 微信端挑战因子
DCloud_JSON's avatar
DCloud_JSON 已提交
101 102 103
							authContent: `请用${title}`,
							complete: (res) => {
								console.log(res);
104
							},
DCloud_JSON's avatar
DCloud_JSON 已提交
105
							success: (res) => {
106
								console.log(res);
L
23  
linju 已提交
107 108 109 110 111 112 113 114 115
								if (res.errCode == 0) {
									/**
									 * 验证成功后开启自己的业务逻辑
									 * 
									 * app端以此为依据 验证成功
									 * 
									 * 微信小程序需要再次通过后台验证resultJSON与resultJSONSignature获取最终结果
									 */
									return uni.showToast({
DCloud_JSON's avatar
DCloud_JSON 已提交
116
										title: `${title}成功`,
L
23  
linju 已提交
117 118 119 120 121 122 123 124
										icon: 'none'
									});
								}
								uni.showToast({
									title: '认证失败请重试',
									icon: 'none'
								});
							},
DCloud_JSON's avatar
DCloud_JSON 已提交
125
							fail: (err) => {
126
								console.log(err);
L
23  
linju 已提交
127 128 129 130 131 132 133 134 135
								console.log(`认证失败:${err.errCode}`);
								uni.showToast({
									title: `认证失败`,
									icon: 'none'
								});
							}
						})
					})
			},
136
			checkIsSoterEnrolledInDevice({checkAuthMode,title}) {
L
23  
linju 已提交
137 138
				return new Promise((resolve, reject) => {
					uni.checkIsSoterEnrolledInDevice({
139
						checkAuthMode,
DCloud_JSON's avatar
DCloud_JSON 已提交
140
						success: (res) => {
141
							console.log(res);
L
23  
linju 已提交
142 143 144 145
							if (res.isEnrolled) {
								return resolve(res);
							}
							uni.showToast({
146
								title: `设备未开启${title}`,
L
23  
linju 已提交
147 148 149 150
								icon: 'none'
							});
							reject(res);
						},
DCloud_JSON's avatar
DCloud_JSON 已提交
151
						fail: (err) => {
152
							console.log(err);
L
23  
linju 已提交
153
							uni.showToast({
154
								title: `${title}失败`,
L
23  
linju 已提交
155 156 157 158 159
								icon: 'none'
							});
							reject(err);
						}
					})
芊里 已提交
160 161
				})
			},
L
23  
linju 已提交
162
			clickLogout() {
163
				if (this.hasLogin) {
L
23  
linju 已提交
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
					uni.showModal({
						title: '提示',
						content: '是否退出登录',
						cancelText: '取消',
						confirmText: '确定',
						success: res => {
							if (res.confirm) {
								this.logout();
								uni.navigateBack();
							}
						},
						fail: () => {},
						complete: () => {}
					});
				} else {
					uni.navigateTo({
180
						url: '/pages/ucenter/login-page/index/index'
L
23  
linju 已提交
181 182
					});
				}
183
			},
L
23  
linju 已提交
184 185 186 187
			clearTmp() {
				uni.showLoading({
					title: '清除中',
					mask: true
188 189 190 191 192 193 194 195 196 197 198
				});
				/*
				任何临时存储或删除不直接影响程序运行逻辑(清除缓存必定造成业务逻辑的变化,如:打开页面的图片不从缓存中读取而从网络请求)的内容都可以视为缓存。主要有storage、和file写入。
				缓存分为三部分		
					原生层(如:webview、x5播放器的、第三方sdk的、地图组件等)
					前端框架(重启就会自动清除)
					开发者自己的逻辑(如:
						本示例的 检测更新功能下载了apk安装包,
						其他逻辑需要根据开发者自己的业务设计
						比如:有聊天功能的应用,聊天记录是否视为缓存,还是单独提供清除聊天记录的功能由开发者自己设计

L
linju 已提交
199
				*/
L
23  
linju 已提交
200 201 202 203 204 205
				uni.getSavedFileList({
					success:res=>{
						if (res.fileList.length > 0) {
							uni.removeSavedFile({
								filePath: res.fileList[0].filePath,
								complete:res=>{
206 207 208 209 210
									console.log(res);
									uni.hideLoading()
									uni.showToast({
										title: '清除成功',
										icon: 'none'
L
linju 已提交
211
									});
L
23  
linju 已提交
212 213
								}
							});
214 215 216 217 218 219
						}else{
							uni.hideLoading()
							uni.showToast({
								title: '清除成功',
								icon: 'none'
							});
L
23  
linju 已提交
220
						}
221 222 223
					},
					complete:e=>{
						console.log(e);
L
23  
linju 已提交
224 225
					}
				});
芊里 已提交
226 227 228 229 230 231 232 233 234 235 236 237
			}
		}
	}
</script>

<style>
	/* #ifndef APP-NVUE */
	page {
		flex: 1;
		width: 100%;
		height: 100%;
	}
L
23  
linju 已提交
238 239 240 241 242 243

	uni-button:after {
		border: none;
		border-radius: 0;
	}

芊里 已提交
244 245 246 247
	/* #endif */
	.content {
		/* #ifndef APP-NVUE */
		display: flex;
L
23  
linju 已提交
248 249
		width: 750rpx;
		height: 100vh;
芊里 已提交
250 251
		/* #endif */
		flex-direction: column;
L
23  
linju 已提交
252 253
		flex: 1;
		background-color: #F9F9F9;
芊里 已提交
254 255 256
	}

	.bottom-back {
L
23  
linju 已提交
257
		margin-top: 10px;
芊里 已提交
258
		width: 750rpx;
L
23  
linju 已提交
259
		height: 44px;
芊里 已提交
260 261 262 263 264 265 266 267 268 269
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		justify-content: center;
		align-items: center;
		/* #ifndef APP-NVUE */
		border: none;
		/* #endif */
		border-width: 0;
L
23  
linju 已提交
270 271
		border-radius: 0;
		background-color: #FFFFFF;
芊里 已提交
272 273 274
	}

	.bottom-back-text {
L
23  
linju 已提交
275 276 277
		font-size: 33rpx;
	}

278 279
	.mt10 {
		margin-top: 10px;
L
23  
linju 已提交
280 281 282 283 284 285
	}

	.content /deep/ .uni-list {
		background-color: #F9F9F9;
	}

286
	.content /deep/ .uni-list-item--disabled,.list-item {
287
		height: 50px;
288
		margin-bottom: 1px;
芊里 已提交
289
	}
DCloud_JSON's avatar
重构  
DCloud_JSON 已提交
290
</style>