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

<script>
	import mixin from '../common/login-page.mixin.js';
	export default {
		mixins: [mixin],
		data() {
雪洛's avatar
雪洛 已提交
38 39
			return {
				lock:false,
DCloud_JSON's avatar
DCloud_JSON 已提交
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 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
				formData: {
					"phone": "",
					'pwd': '',
					'pwd2': ''
				},
				rules: {
					phone: {
						rules: [{
								required: true,
								errorMessage: this.$t('common.phonePlaceholder'),
							},
							{
								pattern: /^1\d{10}$/,
								errorMessage: this.$t('common.formatErr'),
							}
						]
					},
					code: {
						rules: [{
								required: true,
								errorMessage: this.$t('common.verifyCodePlaceholder'),
							},
							{
								pattern: /^.{6}$/,
								errorMessage: this.$t('common.sixDigitCode'),
							}
						]
					},
					pwd: {
						rules: [{
								required: true,
								errorMessage:this.$t('common.newPasswordPlaceholder'),
							},
							{
								pattern: /^.{6,20}$/,
								errorMessage: this.$t('common.passwordDigits'),
							}
						]
					},
					pwd2: {
						rules: [{
								required: true,
								errorMessage:this.$t('common.confirmPassword'),
							},
							{
								pattern: /^.{6,20}$/,
								errorMessage: this.$t('common.passwordDigits'),
							},
							{
								validateFunction: function(rule, value, data, callback) {
									// console.log(value);
									if (value != data.pwd) {
										callback('两次输入密码不一致')
									};
									return true
								}
							}
						]
					}
				}
			}
		},
雪洛's avatar
雪洛 已提交
102
		computed: {
DCloud_JSON's avatar
DCloud_JSON 已提交
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
			canSubmit() {
				return this.isPhone && this.isPwd && this.isCode;
			},
			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;
			}
		},
		onLoad(event) {
			if (event && event.phoneNumber) {
雪洛's avatar
雪洛 已提交
124
				this.formData.phone = event.phoneNumber;
DCloud_JSON's avatar
DCloud_JSON 已提交
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
				this.lock = true
			}
			uni.setNavigationBarTitle({
				title: this.$t('common.resetNavTitle')
			})
		},
		onReady() {
			if (this.formData.phone) {
				this.$refs.shortCode.start();
			}
		},
		methods: {
			/**
			 * 完成并提交
			 */
			submit() {
				this.$refs.form.validate()
					.then(res => {
雪洛's avatar
雪洛 已提交
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
						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()
								}
							}
DCloud_JSON's avatar
DCloud_JSON 已提交
163
						})
雪洛's avatar
雪洛 已提交
164
					})
DCloud_JSON's avatar
DCloud_JSON 已提交
165 166 167 168 169 170 171 172 173 174 175 176
			}
		}
	}
</script>

<style>
	@import url("../common/login-page.css");

	.content{
		padding-top: 36rpx;
	}
</style>