pwd-retrieve.vue 5.6 KB
Newer Older
芊里 已提交
1
<template>
DCloud_JSON's avatar
DCloud_JSON 已提交
2 3 4
	<view class="content">
		<!-- 顶部文字 -->
		<!-- 登录框 (选择手机号所属国家和地区需要另行实现) -->
study夏羽's avatar
update  
study夏羽 已提交
5
		<uni-forms ref="form" :value="formData">
DCloud_JSON's avatar
DCloud_JSON 已提交
6 7
			<uni-forms-item name="phone">
				<!-- focus规则如果上一页携带来“手机号码”数据就focus验证码输入框,否则focus手机号码输入框 -->
study夏羽's avatar
update  
study夏羽 已提交
8 9 10
				<uni-easyinput :disabled="lock" :focus="formData.phone.length!=11" type="number" class="easyinput"
					:inputBorder="false" v-model="formData.phone" maxlength="11"
					:placeholder="$t('common.phonePlaceholder')"></uni-easyinput>
DCloud_JSON's avatar
DCloud_JSON 已提交
11 12
			</uni-forms-item>
			<uni-forms-item name="code">
DCloud_JSON's avatar
DCloud_JSON 已提交
13
				<uni-easyinput :focus="formData.phone.length==11" type="number" class="easyinput" :inputBorder="false"
14
					v-model="formData.code" maxlength="6" :placeholder="$t('common.verifyCodePlaceholder')">
15
					<template v-slot:right>
16
						<uni-send-sms-code ref="shortCode" :phone="formData.phone"></uni-send-sms-code>
DCloud_JSON's avatar
DCloud_JSON 已提交
17 18 19 20 21
					</template>
				</uni-easyinput>
			</uni-forms-item>
			<uni-forms-item name="pwd">
				<uni-easyinput type="password" class="easyinput" :inputBorder="false" v-model="formData.pwd"
22
					:placeholder="$t('common.newPasswordPlaceholder')"></uni-easyinput>
DCloud_JSON's avatar
DCloud_JSON 已提交
23 24 25
			</uni-forms-item>
			<uni-forms-item name="pwd2">
				<uni-easyinput type="password" class="easyinput" :inputBorder="false" v-model="formData.pwd2"
26
					:placeholder="$t('common.confirmNewPasswordPlaceholder')"></uni-easyinput>
DCloud_JSON's avatar
DCloud_JSON 已提交
27 28
			</uni-forms-item>
			<button class="send-btn-box" :disabled="!canSubmit" :type="canSubmit?'primary':'default'"
29
				@click="submit">{{$t('common.complete')}}</button>
DCloud_JSON's avatar
DCloud_JSON 已提交
30
		</uni-forms>
芊里 已提交
31 32 33
	</view>
</template>

DCloud_JSON's avatar
DCloud_JSON 已提交
34
<script>
DCloud_JSON's avatar
DCloud_JSON 已提交
35
	import mixin from '../common/login-page.mixin.js';
DCloud_JSON's avatar
DCloud_JSON 已提交
36
	export default {
DCloud_JSON's avatar
DCloud_JSON 已提交
37
		mixins: [mixin],
芊里 已提交
38
		data() {
DCloud_JSON's avatar
DCloud_JSON 已提交
39
			return {
study夏羽's avatar
update  
study夏羽 已提交
40
				lock: false,
DCloud_JSON's avatar
DCloud_JSON 已提交
41 42
				formData: {
					"phone": "",
study夏羽's avatar
update  
study夏羽 已提交
43
					"code": "",
DCloud_JSON's avatar
DCloud_JSON 已提交
44 45 46 47 48 49 50
					'pwd': '',
					'pwd2': ''
				},
				rules: {
					phone: {
						rules: [{
								required: true,
51
								errorMessage: this.$t('common.phonePlaceholder'),
DCloud_JSON's avatar
DCloud_JSON 已提交
52 53 54
							},
							{
								pattern: /^1\d{10}$/,
55
								errorMessage: this.$t('common.formatErr'),
DCloud_JSON's avatar
DCloud_JSON 已提交
56 57 58 59 60 61
							}
						]
					},
					code: {
						rules: [{
								required: true,
62
								errorMessage: this.$t('common.verifyCodePlaceholder'),
DCloud_JSON's avatar
DCloud_JSON 已提交
63 64 65
							},
							{
								pattern: /^.{6}$/,
66
								errorMessage: this.$t('common.sixDigitCode'),
DCloud_JSON's avatar
DCloud_JSON 已提交
67 68 69 70 71 72
							}
						]
					},
					pwd: {
						rules: [{
								required: true,
study夏羽's avatar
update  
study夏羽 已提交
73
								errorMessage: this.$t('common.newPasswordPlaceholder'),
DCloud_JSON's avatar
DCloud_JSON 已提交
74 75 76
							},
							{
								pattern: /^.{6,20}$/,
77
								errorMessage: this.$t('common.passwordDigits'),
DCloud_JSON's avatar
DCloud_JSON 已提交
78 79 80 81 82 83
							}
						]
					},
					pwd2: {
						rules: [{
								required: true,
study夏羽's avatar
update  
study夏羽 已提交
84
								errorMessage: this.$t('common.confirmPassword'),
DCloud_JSON's avatar
DCloud_JSON 已提交
85 86 87
							},
							{
								pattern: /^.{6,20}$/,
88
								errorMessage: this.$t('common.passwordDigits'),
DCloud_JSON's avatar
DCloud_JSON 已提交
89 90 91
							},
							{
								validateFunction: function(rule, value, data, callback) {
92
									// console.log(value);
DCloud_JSON's avatar
DCloud_JSON 已提交
93 94 95 96 97 98 99 100
									if (value != data.pwd) {
										callback('两次输入密码不一致')
									};
									return true
								}
							}
						]
					}
101
				}
芊里 已提交
102 103
			}
		},
DCloud_JSON's avatar
DCloud_JSON 已提交
104
		computed: {
芊里 已提交
105
			canSubmit() {
106
				return this.isPhone && this.isPwd && this.isCode;
DCloud_JSON's avatar
DCloud_JSON 已提交
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
			},
			isPhone() {
				let reg_phone = /^1\d{10}$/;
				let isPhone = reg_phone.test(this.formData.phone);
				return isPhone;
			},
			isPwd() {
				let reg_pwd = /^.{6,20}$/;
				let isPwd = reg_pwd.test(this.formData.pwd);
				return isPwd;
			},
			isCode() {
				let reg_code = /^\d{6}$/;
				let isCode = reg_code.test(this.formData.code);
				return isCode;
芊里 已提交
122 123 124
			}
		},
		onLoad(event) {
芊里 已提交
125
			if (event && event.phoneNumber) {
DCloud_JSON's avatar
DCloud_JSON 已提交
126
				this.formData.phone = event.phoneNumber;
127
				this.lock = true
芊里 已提交
128
			}
129 130 131
			uni.setNavigationBarTitle({
				title: this.$t('common.resetNavTitle')
			})
芊里 已提交
132
		},
DCloud_JSON's avatar
DCloud_JSON 已提交
133
		onReady() {
DCloud_JSON's avatar
DCloud_JSON 已提交
134
			if (this.formData.phone) {
DCloud_JSON's avatar
DCloud_JSON 已提交
135 136
				this.$refs.shortCode.start();
			}
study夏羽's avatar
update  
study夏羽 已提交
137
			this.$refs.form.setRules(this.rules)
DCloud_JSON's avatar
DCloud_JSON 已提交
138 139 140 141 142
		},
		methods: {
			/**
			 * 完成并提交
			 */
study夏羽's avatar
update  
study夏羽 已提交
143 144 145
			submit() {
				console.log("formData", this.formData);
				console.log('rules', this.rules);
study夏羽's avatar
study夏羽 已提交
146
				return this.$refs.form.validate()
study夏羽's avatar
update  
study夏羽 已提交
147
					.then(async res => {
study夏羽's avatar
study夏羽 已提交
148
						return await uniCloud.callFunction({
study夏羽's avatar
update  
study夏羽 已提交
149 150 151 152
							name: 'uni-id-cf',
							data: {
								action: 'resetPwdBySmsCode',
								params: {
study夏羽's avatar
study夏羽 已提交
153 154 155 156 157
									"mobile": this.formData.phone,
									"code": this.formData.code,
									"password": this.formData.pwd
								},
							}
study夏羽's avatar
update  
study夏羽 已提交
158 159 160
						}).then(({
							result
						}) => {
study夏羽's avatar
study夏羽 已提交
161
							console.log("resetPwdBySmsCode------------",result);
162
							uni.showToast({
study夏羽's avatar
update  
study夏羽 已提交
163
								title: result.msg || '更新成功',
164 165
								icon: 'none'
							});
study夏羽's avatar
study夏羽 已提交
166
							return result
study夏羽's avatar
study夏羽 已提交
167
							if (result.code === 0) {
study夏羽's avatar
study夏羽 已提交
168
								
study夏羽's avatar
study夏羽 已提交
169 170
								uni.navigateBack()
							}
study夏羽's avatar
study夏羽 已提交
171 172
							
							
study夏羽's avatar
update  
study夏羽 已提交
173 174 175
						}).catch((reason) => {
							console.log(reason, 'reason----');
							return reason
DCloud_JSON's avatar
DCloud_JSON 已提交
176
						})
study夏羽's avatar
study夏羽 已提交
177
						
DCloud_JSON's avatar
DCloud_JSON 已提交
178 179 180 181 182 183 184 185 186 187 188 189 190
						// uniCloud.callFunction({
						// 	name:'uni-id-cf',
						// 	data:{
						// 		action:'resetPwdBySmsCode',
						// 		params:{
						// 			"mobile": this.formData.phone,
						// 			"code": this.formData.code,
						// 			"password": this.formData.pwd
						// 		},
						// 	},
						// 	success: ({result}) => {
						// 		console.log(result);
						// 		uni.showToast({
study夏羽's avatar
update  
study夏羽 已提交
191
						// 			title: result.msg||'更新成功',
DCloud_JSON's avatar
DCloud_JSON 已提交
192 193 194 195 196 197
						// 			icon: 'none'
						// 		});
						// 		if (result.code === 0) {
						// 			uni.navigateBack()
						// 		}
						// 	}
study夏羽's avatar
study夏羽 已提交
198
						// })
DCloud_JSON's avatar
DCloud_JSON 已提交
199
					})
芊里 已提交
200 201 202 203 204
			}
		}
	}
</script>

DCloud_JSON's avatar
DCloud_JSON 已提交
205
<style>
DCloud_JSON's avatar
DCloud_JSON 已提交
206
	@import url("../common/login-page.css");
study夏羽's avatar
update  
study夏羽 已提交
207 208

	.content {
209
		padding-top: 36rpx;
芊里 已提交
210
	}
study夏羽's avatar
update  
study夏羽 已提交
211
</style>