Forráskód Böngészése

完善忘记密码部分

littleblue55 6 napja
szülő
commit
388a72ae6e
2 módosított fájl, 80 hozzáadás és 55 törlés
  1. 12 0
      api/user.js
  2. 68 55
      pages/forget/forget.vue

+ 12 - 0
api/user.js

@@ -96,4 +96,16 @@ export function me() {
 		'method': 'get',
 		'data': null
 	})
+}
+
+// 重置密码
+export function resetPwd(data){
+	return request({
+		url: '/user/resetPassword',
+		headers: {
+			isToken: false
+		},
+		'method': 'post',
+		'data': data
+	})
 }

+ 68 - 55
pages/forget/forget.vue

@@ -28,9 +28,9 @@
 				<text class="popup-title">请输入验证码</text>
 				<view class="popup-content">
 					<u-input height="80" placeholder="请输入验证码" border-color="#d0d0d0"
-						v-model="shuzijiaoduimaForm.shuZiJiaoDuiMa" :border="true" class="form-item-input"
+						v-model="numberCaptchaForm.numberCaptcha" :border="true" class="form-item-input"
 						style="flex-grow: 1;" @confirm="submitCode" />
-					<image :src="shuzijiaoduimaSrc" mode="aspectFit"
+					<image :src="numberCaptchaSrc" mode="aspectFit" @click="loadImage"
 						style="height:40px;margin-left:20rpx;width: 180rpx;flex: 0 0 auto;"></image>
 				</view>
 				<view class="popup-btn">
@@ -44,13 +44,22 @@
 
 <script>
 	import {
-		msg
+		getCaptchaImage,
+		checknumberCaptcha,
+		smsSend,
+		resetPwd
+	} from "@/api/user.js"
+	import {
+		msg, msgSuccess
 	} from "@/utils/common.js"
+	import {
+		encryptAESCBC
+	} from "@/utils/crypto.js"
 	export default {
 		data() {
 			return {
 				// ----验证码 start -----
-				shuzijiaoduimaForm: {
+				numberCaptchaForm: {
 					numberCaptcha: '',
 					numberCaptchaUuid: ''
 				},
@@ -60,7 +69,7 @@
 				seconds: 60,
 				// ----验证码 end -----
 				forgetForm: {
-					phone: '', //手机号
+					phone: '18320082803', //手机号
 					captcha: "", //验证码
 					captchaUuid: "",
 					newPwd: '', // 新密码
@@ -92,10 +101,21 @@
 			submit() {
 				const that = this;
 				that.$refs.forgetForm.validate((valid) => {
-					console.log(valid, that.forgetForm, 456);
+					// console.log(valid, that.forgetForm, 456);
 					if (valid) {
-						msg("数据验证成功")
 						// 联调
+						const form = { ...that.forgetForm };
+						form.newPwd = encryptAESCBC(form.newPwd);
+						resetPwd(form).then(res=>{
+							if(res.code == 0){
+								msgSuccess("重置成功!");
+								setTimeout(()=>{
+									uni.reLaunch({
+										url: "/pages/login/login",
+									})
+								}, 1000)
+							}
+						})
 					}
 				})
 			},
@@ -122,75 +142,68 @@
 					msg('倒计时结束后再发送');
 				}
 			},
-			end() {
-				msg('倒计时结束');
-			},
-			start() {
-				msg('倒计时开始');
-			},
+			// end() {
+			// 	msg('倒计时结束');
+			// },
+			// start() {
+			// 	msg('倒计时开始');
+			// },
 			showPopup() {
-				// 模拟向后端请求验证码
-				// 1.获取数字校验码图片
-				// 2.显示弹窗
-				uni.showLoading({
-					title: '正在获取图片'
-				})
-				setTimeout(() => {
-					uni.hideLoading();
-					msg('获取成功')
-					this.show = true;
-				}, 1500);
-				// 联调
-				// this.loadImage()
-				// this.show = true;
+				this.loadImage()
+				this.show = true;
 			},
 			closePopup() {
 				this.show = false;
-				this.shuzijiaoduimaForm.shuZiJiaoDuiMa = ''; // 清空输入框
+				this.numberCaptchaForm.numberCaptcha = ''; // 清空输入框
 			},
 			async submitCode() {
-				let { shuZiJiaoDuiMa } = this.shuzijiaoduimaForm
-				if (!/^\d{4}$/.test(shuZiJiaoDuiMa)) {
+				let { numberCaptcha } = this.numberCaptchaForm
+				if (numberCaptcha.length!=4) {
 					uni.showToast({
 						title: '请输入4位验证码',
 						icon: 'none'
 					});
 					return;
 				}
-				// 联调 检验是否正确
-				// const checkRes = await checkShuzijiaoduima();
-				// if(!checkRes){
-				// 	uni.showToast({
-				// 		title: '验证码输入错误',
-				// 		icon: 'none'
-				// 	});
-				// 	return;
-				// }
-				// // 发送手机验证码
-				// const codeRes = await getCodeApi();
-				// if(codeRes && codeRes.captchaUuid){
-				// 	this.forgetForm.captchaUuid = codeRes.captchaUuid
-				// 	this.closePopup();
-				// 	this.$refs.uCode1.start()
-				// }
-
 				uni.showLoading({
 					title: '正在校验验证码'
 				})
-				setTimeout(() => {
-					uni.hideLoading();
-					msg('填写正确');
+				
+				const checkRes = await checknumberCaptcha(this.numberCaptchaForm);
+				if (!checkRes.data.valid) {
+					uni.showToast({
+						title: '验证码输入错误',
+						icon: 'none'
+					});
+					return;
+				}
+				
+				const codeRes = await smsSend({
+					phone: this.forgetForm.phone
+				});
+				
+				if (codeRes && codeRes.data.captchaUuid) {
+					this.getPhoneCapt++;
+					this.forgetForm.captchaUuid = codeRes.data.captchaUuid
 					this.closePopup();
 					this.$refs.uCode1.start()
-				}, 1500);
+				}
+				
+				uni.hideLoading();
 			},
 			// 加载验证码图片
 			async loadImage() {
 				// 联调
-				// const img = await loadShuzijiaoduima();
-				// this.shuzijiaoduimaForm.shuZiJiaoDuiMaUuid = img.shuZiJiaoDuiMaUuid
-				// this.shuzijiaoduimaSrc = img.shuzijiaoduimaSrc
-				console.log("加载图片")
+				uni.showLoading({
+					title: '正在获取图片'
+				})
+				const img = await getCaptchaImage();
+				if (!img.data.numberCaptchaSrc) {
+					return
+				}
+				this.numberCaptchaForm.numberCaptchaUuid = img.data.numberCaptchaUuid
+				this.numberCaptchaSrc = img.data.numberCaptchaSrc;
+				uni.hideLoading();
 			}
 			// --------验证码 end---------
 		},