settings.vue 8.8 KB
Newer Older
芊里 已提交
1
<template>
L
23  
linju 已提交
2
	<view class="content">
3
		<!-- 功能列表 -->
4 5
		<uni-list class="mt10" :border="false">
			<uni-list-item :title="$t('settings.userInfo')" to="/uni_modules/uni-id-pages/pages/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
		
DCloud_JSON's avatar
DCloud_JSON 已提交
21
		<!-- 退出/登录 按钮 -->
DCloud_JSON's avatar
DCloud_JSON 已提交
22
		<view class="bottom-back" @click="changeLoginState">
23 24
			<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 已提交
25
		</view>
芊里 已提交
26 27 28 29
	</view>
</template>

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

L
linju 已提交
183
				*/
L
23  
linju 已提交
184 185 186 187 188 189
				uni.getSavedFileList({
					success:res=>{
						if (res.fileList.length > 0) {
							uni.removeSavedFile({
								filePath: res.fileList[0].filePath,
								complete:res=>{
190 191 192
									console.log(res);
									uni.hideLoading()
									uni.showToast({
193
										title: this.$t('settings.clearedSuccessed'),
194
										icon: 'none'
L
linju 已提交
195
									});
L
23  
linju 已提交
196 197
								}
							});
198 199 200
						}else{
							uni.hideLoading()
							uni.showToast({
201
								title: this.$t('settings.clearedSuccessed'),
202 203
								icon: 'none'
							});
L
23  
linju 已提交
204
						}
205 206 207
					},
					complete:e=>{
						console.log(e);
L
23  
linju 已提交
208 209
					}
				});
210 211 212 213 214 215 216 217 218 219 220
			},
			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
update  
study夏羽 已提交
221
							const globalData = getApp().globalData
222 223 224 225 226 227
							if (language === 'en') {
								language = globalData.locale = 'zh-Hans'
							} else {
								language = globalData.locale = 'en'
							}
							uni.setStorageSync('CURRENT_LANG', language)
228 229 230 231
							getApp().globalData.$i18n.locale = language
							this.currentLanguage = res.tapIndex?'简体中文':'English'
							if(uni.setLocale){
								uni.setLocale(language)
232
							}
233 234 235 236 237 238 239 240 241 242 243
							uni.reLaunch({
								url: '/pages/list/list',
								complete: () => {
									uni.$emit("changeLanguage",language)
								}
							})
						}
					},
					fail: () => {},
					complete: () => {}
				});
芊里 已提交
244 245 246 247 248 249 250 251 252 253 254 255
			}
		}
	}
</script>

<style>
	/* #ifndef APP-NVUE */
	page {
		flex: 1;
		width: 100%;
		height: 100%;
	}
L
23  
linju 已提交
256 257 258 259 260

	uni-button:after {
		border: none;
		border-radius: 0;
	}
芊里 已提交
261 262 263 264
	/* #endif */
	.content {
		/* #ifndef APP-NVUE */
		display: flex;
L
23  
linju 已提交
265 266
		width: 750rpx;
		height: 100vh;
芊里 已提交
267 268
		/* #endif */
		flex-direction: column;
L
23  
linju 已提交
269 270
		flex: 1;
		background-color: #F9F9F9;
芊里 已提交
271 272 273
	}

	.bottom-back {
L
23  
linju 已提交
274
		margin-top: 10px;
芊里 已提交
275
		width: 750rpx;
L
23  
linju 已提交
276
		height: 44px;
芊里 已提交
277 278 279 280 281 282 283 284 285 286
		/* #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 已提交
287 288
		border-radius: 0;
		background-color: #FFFFFF;
芊里 已提交
289 290 291
	}

	.bottom-back-text {
L
23  
linju 已提交
292 293 294
		font-size: 33rpx;
	}

295 296
	.mt10 {
		margin-top: 10px;
L
23  
linju 已提交
297
	}
298
	/* #ifndef APP-NVUE  || VUE3 */
299
	.content ::v-deep .uni-list {
L
23  
linju 已提交
300
		background-color: #F9F9F9;
301
	}
302
	.content ::v-deep .uni-list-item--disabled,.list-item {
303 304 305
		height: 50px;
		margin-bottom: 1px;
	}
DCloud_JSON's avatar
DCloud_JSON 已提交
306
	/* #endif */
L
23  
linju 已提交
307

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