settings.vue 10.1 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="$t('settings.userInfo')" to="/pages/ucenter/userinfo/userinfo" link="navigateTo"></uni-list-item>
6
			<uni-list-item v-if="userInfo.mobile" :title="$t('settings.changePassword')" :to="'/pages/ucenter/login-page/pwd-retrieve/pwd-retrieve?phoneNumber='+ userInfo.mobile" link="navigateTo"></uni-list-item>
DCloud_JSON's avatar
DCloud_JSON 已提交
7
		</uni-list>
8
		<uni-list class="mt10" :border="false">
DCloud_JSON's avatar
DCloud_JSON 已提交
9
		<!-- #ifndef H5 -->
10 11
			<!-- #ifdef APP-PLUS -->
			<!-- 检查push过程未结束不显示,push设置项 -->
12
			<uni-list-item :title="$t('settings.clearTmp')" @click="clearTmp" link></uni-list-item>
13
			<uni-list-item v-show="pushIsOn != 'wait'" :title="$t('settings.pushServer')" @click.native="pushIsOn?pushServer.off():pushServer.on()"  showSwitch :switchChecked="pushIsOn"></uni-list-item>
14
			<!-- #endif -->
15 16
			<uni-list-item v-if="supportMode.includes('fingerPrint')" :title="$t('settings.fingerPrint')" @click.native="startSoterAuthentication('fingerPrint')" link></uni-list-item>
			<uni-list-item v-if="supportMode.includes('facial')" :title="$t('settings.facial')" @click="startSoterAuthentication('facial')" link></uni-list-item>
17
		<!-- #endif -->
18
			<uni-list-item v-if="i18nEnable" :title="$t('settings.changeLanguage')" @click="changeLanguage" :rightText="currentLanguage" link></uni-list-item>
DCloud_JSON's avatar
DCloud_JSON 已提交
19
		</uni-list>
20 21 22 23
		
		<uni-list class="mt10" :border="false">
			<uni-list-item @click="deactivate" :title="$t('settings.deactivate')" link="navigateTo"></uni-list-item>
		</uni-list>
DCloud_JSON's avatar
重构  
DCloud_JSON 已提交
24
		
DCloud_JSON's avatar
DCloud_JSON 已提交
25
		<!-- 退出/登录 按钮 -->
L
23  
linju 已提交
26
		<view class="bottom-back" @click="clickLogout">
27 28
			<text class="bottom-back-text" v-if="hasLogin">{{$t('settings.logOut')}}</text>
			<text class="bottom-back-text" v-else>{{$t('settings.login')}}</text>
L
23  
linju 已提交
29
		</view>
芊里 已提交
30 31 32 33
	</view>
</template>

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

L
linju 已提交
230
				*/
L
23  
linju 已提交
231 232 233 234 235 236
				uni.getSavedFileList({
					success:res=>{
						if (res.fileList.length > 0) {
							uni.removeSavedFile({
								filePath: res.fileList[0].filePath,
								complete:res=>{
237 238 239
									console.log(res);
									uni.hideLoading()
									uni.showToast({
240
										title: this.$t('settings.clearedSuccessed'),
241
										icon: 'none'
L
linju 已提交
242
									});
L
23  
linju 已提交
243 244
								}
							});
245 246 247
						}else{
							uni.hideLoading()
							uni.showToast({
248
								title: this.$t('settings.clearedSuccessed'),
249 250
								icon: 'none'
							});
L
23  
linju 已提交
251
						}
252 253 254
					},
					complete:e=>{
						console.log(e);
L
23  
linju 已提交
255 256
					}
				});
257 258 259 260 261 262 263 264 265 266 267
			},
			changeLanguage(){
				console.log('语言切换')
				uni.showActionSheet({
					itemList: ["English","简体中文"],
					success: res => {
						console.log(res.tapIndex); 
						let language = uni.getStorageSync('CURRENT_LANG')
						if(
							!res.tapIndex && language=='zh-Hans' || res.tapIndex && language=='en'
						){
study夏羽's avatar
study夏羽 已提交
268
							const globalData = getApp({allowDefault: true}).globalData
269 270 271 272 273 274
							if (language === 'en') {
								language = globalData.locale = 'zh-Hans'
							} else {
								language = globalData.locale = 'en'
							}
							uni.setStorageSync('CURRENT_LANG', language)
study夏羽's avatar
study夏羽 已提交
275
							getApp({allowDefault: true}).globalData.$i18n.locale = language
276 277 278
							this.currentLanguage = res.tapIndex?'简体中文':'English'
							if(uni.setLocale){
								uni.setLocale(language)
279
							}
280 281 282 283 284 285 286 287 288 289 290
							uni.reLaunch({
								url: '/pages/list/list',
								complete: () => {
									uni.$emit("changeLanguage",language)
								}
							})
						}
					},
					fail: () => {},
					complete: () => {}
				});
芊里 已提交
291 292 293 294 295 296 297 298 299 300 301 302
			}
		}
	}
</script>

<style>
	/* #ifndef APP-NVUE */
	page {
		flex: 1;
		width: 100%;
		height: 100%;
	}
L
23  
linju 已提交
303 304 305 306 307

	uni-button:after {
		border: none;
		border-radius: 0;
	}
芊里 已提交
308 309 310 311
	/* #endif */
	.content {
		/* #ifndef APP-NVUE */
		display: flex;
L
23  
linju 已提交
312 313
		width: 750rpx;
		height: 100vh;
芊里 已提交
314 315
		/* #endif */
		flex-direction: column;
L
23  
linju 已提交
316 317
		flex: 1;
		background-color: #F9F9F9;
芊里 已提交
318 319 320
	}

	.bottom-back {
L
23  
linju 已提交
321
		margin-top: 10px;
芊里 已提交
322
		width: 750rpx;
L
23  
linju 已提交
323
		height: 44px;
芊里 已提交
324 325 326 327 328 329 330 331 332 333
		/* #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 已提交
334 335
		border-radius: 0;
		background-color: #FFFFFF;
芊里 已提交
336 337 338
	}

	.bottom-back-text {
L
23  
linju 已提交
339 340 341
		font-size: 33rpx;
	}

342 343
	.mt10 {
		margin-top: 10px;
L
23  
linju 已提交
344
	}
345
	/* #ifndef APP-NVUE  || VUE3 */
L
23  
linju 已提交
346 347
	.content /deep/ .uni-list {
		background-color: #F9F9F9;
348 349 350 351 352
	}
	.content /deep/ .uni-list-item--disabled,.list-item {
		height: 50px;
		margin-bottom: 1px;
	}
DCloud_JSON's avatar
DCloud_JSON 已提交
353
	/* #endif */
L
23  
linju 已提交
354

DCloud_JSON's avatar
重构  
DCloud_JSON 已提交
355
</style>