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

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

DCloud_JSON's avatar
DCloud_JSON 已提交
192
<style>
DCloud_JSON's avatar
DCloud_JSON 已提交
193 194
	@import url("../common/login-page.css");

195
	.content{
196
		padding-top: 36rpx;
芊里 已提交
197
	}
198
</style>