my-resetpassword.vue 9.0 KB
Newer Older
M
m0_74163447 已提交
1 2
<template>
	<view class="main">
M
m0_74163447 已提交
3
		<view class="top">
Y
yyt 已提交
4
			<image @click="goBack" class="back" src="/static/discover/back.png"></image>
M
m0_74163447 已提交
5 6
			<view class="title">重置密码</view>
			<span class="empty"></span>
M
m0_74163447 已提交
7 8
		</view>
		<view class="content">
M
m0_74163447 已提交
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
			<view class="text-area">
				<uni-forms :modelValue="formData" label-position="left" :labelWidth='90' :rules="confirmRules"
					ref="form" validate-trigger="bind" err-show-type="undertext">
					<uni-forms-item name="phone" required label="手机号">
						<uni-easyinput type="text" :inputBorder="true" v-model="formData.phone"
							placeholder="请输入注册使用的手机号"></uni-easyinput>
					</uni-forms-item>
					<view style="display: flex;flex-flow: row nowrap;">
						<uni-forms-item name="captcha" required label="验证码">
							<uni-easyinput type="number" :inputBorder="true" v-model="formData.captcha"
								placeholder="请输入六位验证码"></uni-easyinput>
						</uni-forms-item>
						<button size="mini" class="captchaButton" :disabled="btnDis" @tap="sendCaptcha">{{btnText}}</button>
						<!-- <button class="captchaButton" @click="sendCaptcha()">发送验证码</button> -->
					</view>
					<uni-forms-item name="newPassword" required label="新密码">
						<uni-easyinput type="password" :inputBorder="true" v-model="formData.newPassword"
							placeholder="请输入密码"></uni-easyinput>
					</uni-forms-item>
					<uni-forms-item name="confirmPassword" required label="确认密码">
						<uni-easyinput type="password" :inputBorder="true" v-model="formData.confirmPassword"
							placeholder="请确认新密码"></uni-easyinput>
					</uni-forms-item>
					<uni-forms-item>
						<button class="confirmButton" @click="confirm('form')">确认</button>
					</uni-forms-item>
				</uni-forms>
Y
yyt 已提交
36
			</view>
M
m0_74163447 已提交
37
		</view>
M
m0_74163447 已提交
38 39 40 41 42 43 44 45 46 47 48
		<uni-popup ref="popupDialog" type="center">
			<view class="mcaptcha">
				<view style="padding: 30px 20px;text-align: center;">
					<canvas canvas-id="canvas" @click="updateImageCode" class="canvas"></canvas>
					<input class="ginput" v-model="graphicVerifyCode" placeholder="请输入验证码" />
					<button style="margin-top: 10px;" :loading="loading" @tap="submitFcha" class="btn-big">验证</button>
					<view class="text" @click="updateImageCode">获取验证码</view>
				</view>
			</view>
		</uni-popup>
		
M
m0_74163447 已提交
49 50 51 52
		<uni-popup ref="alertDialog" type="dialog">
			<uni-popup-dialog cancelText="取消" confirmText="确定" title="提示" content="确定修改你的密码吗?"
				@confirm="dialogConfirm"></uni-popup-dialog>
		</uni-popup>
M
m0_74163447 已提交
53 54 55 56
	</view>
</template>

<script>
M
m0_74163447 已提交
57 58 59 60
	let code = 200;
	import {
		Fcaptcha
	} from "@/common/fcaptcha.js"
M
m0_74163447 已提交
61
	export default {
M
m0_74163447 已提交
62 63
		name: 'login',
		components: {},
M
m0_74163447 已提交
64 65
		data() {
			return {
M
m0_74163447 已提交
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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
				btnDis: false,// 发送验证码按钮不禁用
				btnText: "发送验证码",// 提示
				loading: false,
				graphicVerifyCode: "",
				formData: {
					phone: '',
					password: '',
					captcha: '',
					newPassword: ''
				},
				confirmRules: {
					phone: {
						rules: [{
							required: true,
							errorMessage: '请输入手机号'
						}, {
							validateFunction: function(rule, value, data, callback) {
								if (value === '') {
									callback(new Error('手机号不能为空'))
								} else {
									const reg = /^(13[0-9]|14[0-9]|15[0-9]|166|17[0-9]|18[0-9]|19[8|9])\d{8}$/
									if (reg.test(value)) {
										this.yzmshow = true
										callback()
									} else {
										callback('请输入正确的手机号')
									}
								}
							}
						}]
					},
					captcha: {
						rules: [{
							required: true,
							errorMessage: '请输入六位验证码'
						}, {
							validateFunction: function(rule, value, data, callback) {
								if (value.length != 6) {
									callback('验证码为六位!')
								} else {
									callback();
								}
							}
						}]
					},
					newPassword: {
						rules: [{
							required: true,
							errorMessage: '请输入密码'
						}, {
							validateFunction: function(rule, value, data, callback) {
								if (value.length > 20 || value.length < 8) {
									callback('密码长度在8-20位!')
								} else {
									callback();
								}
							}
						}]
					},
					confirmPassword: {
						rules: [{
							required: true,
							errorMessage: '请确认密码'
						}, {
							validateFunction: function(rule, value, data, callback) {
								if (value.length > 20 || value.length < 8) {
									callback('密码长度在8-20位!')
								} else if (value != data.newPassword) {
									callback('密码不一致')
								} else {
									callback();
								}
							}
						}]
					}
				}
M
m0_74163447 已提交
142 143 144
			}
		},
		methods: {
M
m0_74163447 已提交
145 146 147 148
			async sendCaptcha() {
				await this.$refs['popupDialog'].open()
				await this.fcaptcha.refresh()
				
M
m0_74163447 已提交
149
			},
M
m0_74163447 已提交
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
			countDown() {
			  	// 初始化定时器
				let t = null;
				// 倒计时1分钟
				let timer = 300;
				// 按钮禁用
				this.btnDis = true;
				// 计时器清零
				clearInterval(t);
				// 按钮显示时间
				this.btnText = `${timer}s`;
				t = setInterval(() => {
				// 当倒计时完时,显示重新发送,按钮开启
					if (timer == 0) {
						clearInterval(t);
						this.btnText = "重新发送";
						this.btnDis = false;
						return;
					}
					// 实现倒计时效果
					timer--;
					this.btnText = `${timer}s`;
				}, 1000)
Y
yyt 已提交
173
			},
M
m0_74163447 已提交
174 175 176
			confirm(validateForm) {
				this.$refs.alertDialog.open();
				
Y
yyt 已提交
177
			},
M
m0_74163447 已提交
178
			dialogConfirm() {
M
m0_74163447 已提交
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
				this.$refs[validateForm].validate(valid => {
					if (!valid) {
						
						this.calluniCloud()
					}
				})
			},
			async calluniCloud() {
				await uniCloud.callFunction({
						name: 'fe-retrievePassword',
						data: {
							phone: this.formData.phone,
							password: this.formData.newPassword,
							code: this.formData.captcha
						}
					})
					.then(res => {
						this.code = res.result.code
						console.log(res)
					})
				await this.showTorM()
			},
			showTorM() {
				if (this.code == 200) {
					console.log(this.code, 'this.code1')
M
m0_74163447 已提交
204
					uni.showToast({
M
m0_74163447 已提交
205
						title: '修改成功',
M
m0_74163447 已提交
206 207
						duration: 2000
					});
M
m0_74163447 已提交
208
				} else if (this.code == 400) {
M
m0_74163447 已提交
209
					uni.showToast({
M
m0_74163447 已提交
210 211
						title: '验证码错误或超时',
						icon: "error",
M
m0_74163447 已提交
212 213
						duration: 2000
					});
M
m0_74163447 已提交
214
				} else {
Y
结束  
yyt 已提交
215
					uni.showToast({
M
m0_74163447 已提交
216 217
						title: '错误',
						icon: "error",
Y
结束  
yyt 已提交
218 219
						duration: 2000
					});
M
m0_74163447 已提交
220
				}
M
m0_74163447 已提交
221 222 223 224 225
			},
			goBack() {
				uni.navigateBack({
					delta: 1, //返回层数,2则上上页
				})
M
m0_74163447 已提交
226 227 228 229
			},
			dialogClose() {
				this.$refsalertDialog.close();
			},
M
m0_74163447 已提交
230 231 232 233
			
			// 刷新验证码
			updateImageCode() {
				this.fcaptcha.refresh()
M
m0_74163447 已提交
234
			},
M
m0_74163447 已提交
235 236 237 238 239 240 241
			// 提交前校验图形验证码
			submitFcha() {
				if (!this.graphicVerifyCode) {
					return uni.showToast({
						title: '请输入图形验证码',
						icon: 'error'
					})
Y
yyt 已提交
242
				}
M
m0_74163447 已提交
243 244 245 246 247 248 249 250 251
				let validate = this.fcaptcha.validate(this.graphicVerifyCode)
				if (!validate) {
					this.updateImageCode();
					this.graphicVerifyCode = ''
					uni.showToast({
						title: '图形验证码错误',
						icon: 'error'
					})
					this.fcaptcha.refresh()
Y
yyt 已提交
252
				} else {
M
m0_74163447 已提交
253 254
					uni.showToast({
						title: '图形验证码通过'
Y
布局  
yyt 已提交
255
					})
M
m0_74163447 已提交
256 257 258 259 260 261 262 263 264 265 266 267 268
					this.$refs['popupDialog'].close();
					uniCloud.callFunction({
							name: 'fe-auth-code',
							data: {
								phone: this.formData.phone
							}
						})
						.then(res => {
							this.code = res.result.code
							console.log(this.userId)
						})
					this.countDown();
				}
M
m0_74163447 已提交
269
			}
M
m0_74163447 已提交
270 271 272 273 274 275 276 277 278
		},
		onReady() {
			this.fcaptcha = new Fcaptcha({
				el: 'canvas',
				width: 80,
				height: 35,
				createCodeImg: ""
			});
		},
M
m0_74163447 已提交
279
	}
M
m0_74163447 已提交
280 281 282
</script>

<style>
M
m0_74163447 已提交
283 284 285 286
	.bg {
		background-color: #edeef0;
	}

M
m0_74163447 已提交
287 288 289 290
	.main {
		position: absolute;
		width: 100%;
		height: 100%;
M
m0_74163447 已提交
291
	}
M
m0_74163447 已提交
292 293 294 295 296 297 298 299 300 301 302
	
	.content {
		/* background-color: #edeef0; */
		display: flex;
		align-items: center;
		flex-direction: column;
		justify-content: center;
		position: absolute;
		width: 100%;
		height: 100%;
	}
M
m0_74163447 已提交
303 304 305 306

	.top {
		width: 100%;
		height: 50px;
M
m0_74163447 已提交
307
		background-color: #EDEEF0;
M
m0_74163447 已提交
308
		text-align: center;
M
m0_74163447 已提交
309
	}
M
m0_74163447 已提交
310
	
M
m0_74163447 已提交
311 312 313 314 315 316 317 318
	.back {
		width: 40px;
		height: 30px;
		margin-top: 10px;
		margin-bottom: 10px;
		float: left;
		margin-left: 10px;
	}
M
m0_74163447 已提交
319
	
M
m0_74163447 已提交
320 321 322 323 324 325 326 327
	.empty {
		width: 40px;
		height: 30px;
		margin-top: 10px;
		margin-bottom: 10px;
		float: right;
		margin-right: 10px;
	}
M
m0_74163447 已提交
328
	
M
m0_74163447 已提交
329 330
	.title {
		font-size: 20px;
Y
yyt 已提交
331
		margin-top: 15px;
M
m0_74163447 已提交
332 333 334
		font-weight: bold;
		color: #f1992d;
		display: inline-block;
M
m0_74163447 已提交
335
	}
M
m0_74163447 已提交
336

M
m0_74163447 已提交
337 338 339 340 341
	.returnBack {
		height: 55rpx;
		width: 55rpx;
		margin-top: 60rpx;
		margin-left: 20rpx;
M
m0_74163447 已提交
342 343
		margin-right: auto;
	}
M
m0_74163447 已提交
344

M
m0_74163447 已提交
345 346 347 348 349 350
	.confirmButton {
		background-color: #f1992d;
		color: #fff;
		border: 0;
		border-radius: 20px;
	}
M
m0_74163447 已提交
351

M
m0_74163447 已提交
352 353 354
	.confirmButton::after {
		border: 0;
	}
M
m0_74163447 已提交
355

M
m0_74163447 已提交
356 357 358 359 360 361 362 363
	.captchaButton {
		background-color: #f1992d;
		color: #fff;
		width: 90px;
		height: 35px;
		font-size: 0.7em;
		border: 0;
		border-radius: 18px;
M
m0_74163447 已提交
364
	}
M
m0_74163447 已提交
365

M
m0_74163447 已提交
366 367
	.captchaButton::after {
		border: 0;
M
m0_74163447 已提交
368
	}
M
m0_74163447 已提交
369

M
m0_74163447 已提交
370 371 372 373 374 375 376
	.mcaptcha {
		display: flex;
		flex-direction: column;
		background-color: #fff;
		width: 270px;
		height: 200px;
		border-radius: 10px;
M
m0_74163447 已提交
377
	}
M
m0_74163447 已提交
378

M
m0_74163447 已提交
379 380 381 382
	.canvas {
		margin: auto;
		width: 200rpx;
		height: 100rpx;
M
m0_74163447 已提交
383
	}
M
m0_74163447 已提交
384

M
m0_74163447 已提交
385 386 387 388 389 390 391 392 393 394 395
	.btn-big {
		background-color: #f1992d;
		color: #fff;
		border: 0;
		border-radius: 20px;
	}
	
	.text{
		margin-top: 12px;
		font-size: 10px;
		color: #f1992d;
M
m0_74163447 已提交
396
	}
M
m0_74163447 已提交
397
	
M
m0_74163447 已提交
398
</style>