pwd-retrieve.vue 4.4 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"
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
		data() {
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
				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) {
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 103
			}
		},
		computed: {
			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
			}
		},
DCloud_JSON's avatar
DCloud_JSON 已提交
128
		onReady() {
DCloud_JSON's avatar
DCloud_JSON 已提交
129
			if (this.formData.phone) {
DCloud_JSON's avatar
DCloud_JSON 已提交
130 131 132 133 134 135 136
				this.$refs.shortCode.start();
			}
		},
		methods: {
			/**
			 * 完成并提交
			 */
DCloud_JSON's avatar
DCloud_JSON 已提交
137
			submit() {
138
				this.$refs.form.validate()
DCloud_JSON's avatar
DCloud_JSON 已提交
139
					.then(res => {
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
						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 已提交
160
						})
161
					})
芊里 已提交
162 163 164 165 166
			}
		}
	}
</script>

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

170
	.content{
171
		padding-top: 36rpx;
芊里 已提交
172
	}
173
</style>