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

<script>
L
123  
linju 已提交
18 19
	import {isOn,setting} from './dc-push/push.js';
	import {mapMutations,mapGetters} from 'vuex';
芊里 已提交
20 21 22 23 24
	export default {
		data() {
			return {
				agreeList: [{
						title: '个人资料',
芊里 已提交
25
						event:'toEdit'
芊里 已提交
26 27
					},
					{
芊里 已提交
28 29
						title: '修改密码',
						event:'changePwd'
test  
芊里 已提交
30 31 32 33 34
					},
					// {
					// 	title: '注销用户',
					// 	event: ''
					// },
芊里 已提交
35 36 37 38 39 40 41 42
					//#ifdef APP-PLUS
					{
						title: '推送功能',
						name: 'push',
						event: 'openSetting',
						isChecked: false,
						showSwitch: true
					},
test  
芊里 已提交
43 44 45 46
					// {
					// 	title: '清理缓存',
					// 	event: ''
					// },
芊里 已提交
47 48 49 50
					//#endif

				]
			}
芊里 已提交
51 52 53 54 55
		},
		computed:{
			...mapGetters({
				'userInfo':'user/info'
			})
芊里 已提交
56 57 58 59 60 61 62 63 64 65 66
		},
		onLoad() {
			this.initSoterAuthentication();
		},
		onShow() {
			this.checkPush();
		},
		methods: {
			...mapMutations({
				logout: 'user/logout'
			}),
芊里 已提交
67 68
			toEdit(){
				uni.navigateTo({
L
123  
linju 已提交
69
					url: '/pages/ucenter/edit/edit'
芊里 已提交
70 71
				});
			},
芊里 已提交
72
			changePwd(){
L
123  
linju 已提交
73
				uni.navigateTo({
L
123  
linju 已提交
74
					url:'/uni_modules/uni-login-page/pages/index/pwd-retrieve?phoneNumber='+ (this.userInfo?this.userInfo.phone:'') +'&phoneArea=+86'
L
123  
linju 已提交
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
			checkPush(){
				// 手机端获取推送是否开启
				//#ifdef APP-PLUS
				let pushIsOn = isOn();
				this.agreeList.forEach(item => {
					item.name == 'push' ? (item.isChecked = pushIsOn) : '';
				})
				//#endif
			},
			/**
			 * 添加生物认证选项
			 */
			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 => {
							this.agreeList.push(checkAuthModeList.find(mode => mode.name == item));
						})
					},
					fail: (err) => {
						reject(err);
					}
				})
				// #endif
			},
			/**
			 * 开始生物认证
			 */
			startSoterAuthentication(item) {
				// 检查是否开启认证
				this.checkIsSoterEnrolledInDevice(item)
				.then(()=>{
					// 开始认证
					uni.startSoterAuthentication({
						requestAuthModes: [item.name],
						challenge: '123456',	// 微信端挑战因子
						authContent: `请用${item.title}`,
芊里 已提交
125
						success:(res)=> {
芊里 已提交
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
							if(res.errCode == 0){
								/**
								 * 验证成功后开启自己的业务逻辑
								 * 
								 * app端以此为依据 验证成功
								 * 
								 * 微信小程序需要再次通过后台验证resultJSON与resultJSONSignature获取最终结果
								 */
								return uni.showToast({
									title: `${item.title}成功`,
									icon: 'none'
								});
							}
							uni.showToast({
								title: '认证失败请重试',
								icon: 'none'
							});
						},
芊里 已提交
144
						fail:(err)=> {
芊里 已提交
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
							uni.showToast({
								title: `认证失败:${err.errCode}`,
								icon: 'none'
							});
						}
					})
				})
			},
			checkIsSoterEnrolledInDevice(mode){
				return new Promise((resolve, reject)=>{
					uni.checkIsSoterEnrolledInDevice({
						checkAuthMode:mode.name,
						success: (res) => {
							if(res.isEnrolled){
								return resolve(res);
							}
							uni.showToast({
芊里 已提交
162
								title: `设备未开启${mode.title}`,
芊里 已提交
163 164 165 166 167 168
								icon: 'none'
							});
							reject(res);
						},
						fail: (err) => {
							uni.showToast({
芊里 已提交
169
								title: `${mode.title}失败`,
芊里 已提交
170 171 172 173 174 175 176 177
								icon: 'none'
							});
							reject(err);
						}
					})
				})
			},
			clickLogout() {
L
123  
linju 已提交
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
				if(this.userInfo){
					uni.showModal({
						title: '提示',
						content: '是否退出登录',
						cancelText: '取消',
						confirmText: '确定',
						success: res => {
							if(res.confirm){
								this.logout();
								uni.navigateBack();
							}
						},
						fail: () => {},
						complete: () => {}
					});
				}else{
					uni.navigateTo({
						url: '/uni_modules/uni-login-page/pages/index/index'
					});
				}
芊里 已提交
198
			},
芊里 已提交
199
			itemClick(item) {
芊里 已提交
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
				if (!item.to && item.event) {
					this[item.event](item);
				}
			},
			/**
			 * 打开设置页面
			 */
			openSetting() {
				setting();
			}
		}
	}
</script>

<style>
	/* #ifndef APP-NVUE */
	page {
		flex: 1;
		width: 100%;
		height: 100%;
	}
	uni-button:after{
		border: none;
		border-radius: 0;
	}
	/* #endif */
	.content {
		/* #ifndef APP-NVUE */
		display: flex;
		width: 100%;
		height: 100%;
		/* #endif */
		flex-direction: column;
		flex: 1;
	}

	.bottom-back {
		width: 750rpx;
		height: 120rpx;
		/* #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
123  
linju 已提交
249 250
		border-radius: 0;
		background-color: #007AFF;
芊里 已提交
251 252 253 254
	}

	.bottom-back-text {
		font-size: 40rpx;
L
123  
linju 已提交
255
		color: #FFFFFF;
芊里 已提交
256 257
	}
</style>