settings.vue 7.5 KB
Newer Older
芊里 已提交
1
<template>
L
23  
linju 已提交
2
	<view class="content">
芊里 已提交
3
		<!-- 功能列表 -->
4 5
		<uni-list :border="false" class="mt10" v-for="(sublist,index) in agreeList">
			<uni-list-item :border="false" class="list-item" v-for="(item,i) in sublist" :key="i" :title="item.title"
芊里 已提交
6
				:clickable="true" @click="itemClick(item)" :showSwitch="item.showSwitch" :switchChecked="item.isChecked"
7 8 9
				:link="!item.showSwitch"
				v-if="item.event!='changePwd'||hasLogin"
				></uni-list-item>
L
23  
linju 已提交
10 11 12
		</uni-list>
		<!-- 退出按钮 -->
		<view class="bottom-back" @click="clickLogout">
13
			<text class="bottom-back-text" v-if="hasLogin">退出登录</text>
L
23  
linju 已提交
14 15
			<text class="bottom-back-text" v-else>登录</text>
		</view>
芊里 已提交
16 17 18 19
	</view>
</template>

<script>
L
23  
linju 已提交
20 21 22 23 24 25 26 27
	import {
		isOn,
		setting
	} from './dc-push/push.js';
	import {
		mapMutations,
		mapGetters
	} from 'vuex';
芊里 已提交
28 29 30
	export default {
		data() {
			return {
L
23  
linju 已提交
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
				agreeList: [
					[{
							title: '个人资料',
							event: 'toEdit'
						},
						{
							title: '修改密码',
							event: 'changePwd'
						}
					],
					[
						//#ifdef APP-PLUS
						{
							title: '推送功能',
							name: 'push',
							event: 'openSetting',
							isChecked: false,
							showSwitch: true
						},
						{
							title: '清理缓存',
							event: 'clearTmp'
						},
						//#endif
					]
芊里 已提交
56 57
				]
			}
L
23  
linju 已提交
58 59 60
		},
		computed: {
			...mapGetters({
61 62
				'userInfo': 'user/info',
				'hasLogin': 'user/hasLogin',
L
23  
linju 已提交
63
			})
芊里 已提交
64 65 66 67 68 69 70 71 72 73
		},
		onLoad() {
			this.initSoterAuthentication();
		},
		onShow() {
			this.checkPush();
		},
		methods: {
			...mapMutations({
				logout: 'user/logout'
L
23  
linju 已提交
74 75 76
			}),
			toEdit() {
				uni.navigateTo({
77
					url: '/pages/ucenter/edit/edit'
L
23  
linju 已提交
78 79 80 81
				});
			},
			changePwd() {
				uni.navigateTo({
82 83 84
					url: '/pages/ucenter/login-page/pwd-retrieve/pwd-retrieve?phoneNumber='
						+ (this.userInfo && this.userInfo.phone ? this.userInfo.phone : '')
						+ '&phoneArea=+86',
L
23  
linju 已提交
85 86 87 88 89 90 91 92 93 94 95 96 97
					fail: err => {
						console.log(err);
					}
				});
			},
			checkPush() {
				// 手机端获取推送是否开启
				//#ifdef APP-PLUS
				let pushIsOn = isOn();
				this.agreeList.forEach(item => {
					item.name == 'push' ? (item.isChecked = pushIsOn) : '';
				})
				//#endif
芊里 已提交
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
			},
			/**
			 * 添加生物认证选项
			 */
			initSoterAuthentication() {
				// #ifdef APP-PLUS || MP-WEIXIN

				let checkAuthModeList = [{
					title: '指纹解锁',
					name: 'fingerPrint',
					event: 'startSoterAuthentication'
				}, {
					title: '人脸解锁',
					name: 'facial',
					event: 'startSoterAuthentication'
				}];
				uni.checkIsSupportSoterAuthentication({
					success: (res) => {
						res.supportMode.forEach(item => {
L
23  
linju 已提交
117
							this.agreeList.push([checkAuthModeList.find(mode => mode.name == item)]);
芊里 已提交
118 119 120 121 122 123 124
						})
					},
					fail: (err) => {
						reject(err);
					}
				})
				// #endif
L
23  
linju 已提交
125 126 127
			},
			/**
			 * 开始生物认证
芊里 已提交
128
			 */
L
23  
linju 已提交
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
			startSoterAuthentication(item) {
				// 检查是否开启认证
				this.checkIsSoterEnrolledInDevice(item)
					.then(() => {
						// 开始认证
						uni.startSoterAuthentication({
							requestAuthModes: [item.name],
							challenge: '123456', // 微信端挑战因子
							authContent: `请用${item.title}`,
							success: (res) => {
								if (res.errCode == 0) {
									/**
									 * 验证成功后开启自己的业务逻辑
									 * 
									 * app端以此为依据 验证成功
									 * 
									 * 微信小程序需要再次通过后台验证resultJSON与resultJSONSignature获取最终结果
									 */
									return uni.showToast({
										title: `${item.title}成功`,
										icon: 'none'
									});
								}
								uni.showToast({
									title: '认证失败请重试',
									icon: 'none'
								});
							},
							fail: (err) => {
								console.log(`认证失败:${err.errCode}`);
								uni.showToast({
									title: `认证失败`,
									icon: 'none'
								});
							}
						})
					})
			},
			checkIsSoterEnrolledInDevice(mode) {
				return new Promise((resolve, reject) => {
					uni.checkIsSoterEnrolledInDevice({
						checkAuthMode: mode.name,
						success: (res) => {
							if (res.isEnrolled) {
								return resolve(res);
							}
							uni.showToast({
								title: `设备未开启${mode.title}`,
								icon: 'none'
							});
							reject(res);
						},
						fail: (err) => {
							uni.showToast({
								title: `${mode.title}失败`,
								icon: 'none'
							});
							reject(err);
						}
					})
芊里 已提交
189 190
				})
			},
L
23  
linju 已提交
191
			clickLogout() {
192
				if (this.hasLogin) {
L
23  
linju 已提交
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
					uni.showModal({
						title: '提示',
						content: '是否退出登录',
						cancelText: '取消',
						confirmText: '确定',
						success: res => {
							if (res.confirm) {
								this.logout();
								uni.navigateBack();
							}
						},
						fail: () => {},
						complete: () => {}
					});
				} else {
					uni.navigateTo({
209
						url: '/pages/ucenter/login-page/index/index'
L
23  
linju 已提交
210 211
					});
				}
212 213 214
			},
			/**
			 * 每一项的点击事件
芊里 已提交
215
			 */
L
23  
linju 已提交
216 217
			itemClick(item) {
				if (item.event) {
芊里 已提交
218 219 220
					this[item.event](item);
				}
			},
L
23  
linju 已提交
221 222 223 224
			clearTmp() {
				uni.showLoading({
					title: '清除中',
					mask: true
225 226 227 228 229 230 231 232 233 234 235
				});
				/*
				任何临时存储或删除不直接影响程序运行逻辑(清除缓存必定造成业务逻辑的变化,如:打开页面的图片不从缓存中读取而从网络请求)的内容都可以视为缓存。主要有storage、和file写入。
				缓存分为三部分		
					原生层(如:webview、x5播放器的、第三方sdk的、地图组件等)
					前端框架(重启就会自动清除)
					开发者自己的逻辑(如:
						本示例的 检测更新功能下载了apk安装包,
						其他逻辑需要根据开发者自己的业务设计
						比如:有聊天功能的应用,聊天记录是否视为缓存,还是单独提供清除聊天记录的功能由开发者自己设计

L
linju 已提交
236
				*/
L
23  
linju 已提交
237 238 239 240 241 242
				uni.getSavedFileList({
					success:res=>{
						if (res.fileList.length > 0) {
							uni.removeSavedFile({
								filePath: res.fileList[0].filePath,
								complete:res=>{
243 244 245 246 247
									console.log(res);
									uni.hideLoading()
									uni.showToast({
										title: '清除成功',
										icon: 'none'
L
linju 已提交
248
									});
L
23  
linju 已提交
249 250
								}
							});
251 252 253 254 255 256
						}else{
							uni.hideLoading()
							uni.showToast({
								title: '清除成功',
								icon: 'none'
							});
L
23  
linju 已提交
257
						}
258 259 260
					},
					complete:e=>{
						console.log(e);
L
23  
linju 已提交
261 262 263
					}
				});
			},
芊里 已提交
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
			/**
			 * 打开设置页面
			 */
			openSetting() {
				setting();
			}
		}
	}
</script>

<style>
	/* #ifndef APP-NVUE */
	page {
		flex: 1;
		width: 100%;
		height: 100%;
	}
L
23  
linju 已提交
281 282 283 284 285 286

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

芊里 已提交
287 288 289 290
	/* #endif */
	.content {
		/* #ifndef APP-NVUE */
		display: flex;
L
23  
linju 已提交
291 292
		width: 750rpx;
		height: 100vh;
芊里 已提交
293 294
		/* #endif */
		flex-direction: column;
L
23  
linju 已提交
295 296
		flex: 1;
		background-color: #F9F9F9;
芊里 已提交
297 298 299
	}

	.bottom-back {
L
23  
linju 已提交
300
		margin-top: 10px;
芊里 已提交
301
		width: 750rpx;
L
23  
linju 已提交
302
		height: 44px;
芊里 已提交
303 304 305 306 307 308 309 310 311 312
		/* #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 已提交
313 314
		border-radius: 0;
		background-color: #FFFFFF;
芊里 已提交
315 316 317
	}

	.bottom-back-text {
L
23  
linju 已提交
318 319 320
		font-size: 33rpx;
	}

321 322
	.mt10 {
		margin-top: 10px;
L
23  
linju 已提交
323 324 325 326 327 328
	}

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

329 330 331
	.list-item {
		height: 50px;
		margin-bottom: 1px;
芊里 已提交
332
	}
333
</style>