pwd-retrieve.vue 4.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手机号码输入框 -->
DCloud_JSON's avatar
DCloud_JSON 已提交
8
				<uni-easyinput :focus="formData.phone.length!=11" type="number" class="easyinput" :inputBorder="false"
DCloud_JSON's avatar
DCloud_JSON 已提交
9 10 11
					v-model="formData.phone" maxlength="11" placeholder="请输入手机号"></uni-easyinput>
			</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"
DCloud_JSON's avatar
DCloud_JSON 已提交
13 14
					v-model="formData.code" maxlength="6" placeholder="请输入验证码">
					<template 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 21 22 23 24 25 26 27 28 29
					</template>
				</uni-easyinput>
			</uni-forms-item>
			<uni-forms-item name="pwd">
				<uni-easyinput type="password" class="easyinput" :inputBorder="false" v-model="formData.pwd"
					placeholder="请输入新密码"></uni-easyinput>
			</uni-forms-item>
			<uni-forms-item name="pwd2">
				<uni-easyinput type="password" class="easyinput" :inputBorder="false" v-model="formData.pwd2"
					placeholder="请确认新密码"></uni-easyinput>
			</uni-forms-item>
			<button class="send-btn-box" :disabled="!canSubmit" :type="canSubmit?'primary':'default'"
				@click="submit">完成</button>
		</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 38
		data() {
			return {
DCloud_JSON's avatar
DCloud_JSON 已提交
39 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
				formData: {
					"phone": "",
					'pwd': '',
					'pwd2': ''
				},
				rules: {
					phone: {
						rules: [{
								required: true,
								errorMessage: '请输入手机号',
							},
							{
								pattern: /^1\d{10}$/,
								errorMessage: '手机号格式不正确',
							}
						]
					},
					code: {
						rules: [{
								required: true,
								errorMessage: '请输入验证码',
							},
							{
								pattern: /^.{6}$/,
								errorMessage: '请输入6位验证码',
							}
						]
					},
					pwd: {
						rules: [{
								required: true,
								errorMessage: '请输入密码',
							},
							{
								pattern: /^.{6,20}$/,
								errorMessage: '密码应为6到20位',
							}
						]
					},
					pwd2: {
						rules: [{
								required: true,
								errorMessage: '请确认密码',
							},
							{
								pattern: /^.{6,20}$/,
								errorMessage: '密码应为6到20位',
							},
							{
								validateFunction: function(rule, value, data, callback) {
									console.log(value);
									if (value != data.pwd) {
										callback('两次输入密码不一致')
									};
									return true
								}
							}
						]
					}
98
				}
芊里 已提交
99 100 101 102
			}
		},
		computed: {
			canSubmit() {
103
				return this.isPhone && this.isPwd && this.isCode;
DCloud_JSON's avatar
DCloud_JSON 已提交
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
			},
			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;
芊里 已提交
119 120 121
			}
		},
		onLoad(event) {
芊里 已提交
122
			if (event && event.phoneNumber) {
123
				this.formData.phone = event.phoneNumber;
芊里 已提交
124 125
			}
		},
DCloud_JSON's avatar
DCloud_JSON 已提交
126
		onReady() {
DCloud_JSON's avatar
DCloud_JSON 已提交
127
			if (this.formData.phone) {
DCloud_JSON's avatar
DCloud_JSON 已提交
128 129 130 131 132 133 134
				this.$refs.shortCode.start();
			}
		},
		methods: {
			/**
			 * 完成并提交
			 */
DCloud_JSON's avatar
DCloud_JSON 已提交
135
			submit() {
DCloud_JSON's avatar
DCloud_JSON 已提交
136
				this.$refs.form.submit()
DCloud_JSON's avatar
DCloud_JSON 已提交
137
					.then(res => {
138
						this.request('uni-id-cf/resetPwdBySmsCode', {
DCloud_JSON's avatar
DCloud_JSON 已提交
139 140 141 142 143 144 145 146 147 148 149 150 151
							"mobile": this.formData.phone,
							"code": this.formData.code,
							"password": this.formData.pwd
						}, result => {
							console.log(result);
							uni.showToast({
								title: result.msg,
								icon: 'none'
							});
							if (result.code === 0) {
								uni.navigateBack()
							}
						})
DCloud_JSON's avatar
DCloud_JSON 已提交
152
					})
芊里 已提交
153 154 155 156 157
			}
		}
	}
</script>

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

161
	.content{
162
		padding-top: 36rpx;
芊里 已提交
163
	}
164
</style>