修复了验证码bug

This commit is contained in:
2025-08-09 22:30:47 +08:00
parent f871831cbc
commit 8a085da7dc
4 changed files with 12 additions and 6 deletions

View File

@ -68,7 +68,7 @@ Page({
// 获取验证码(仅校验手机号) // 获取验证码(仅校验手机号)
getSmsCode() { getSmsCode() {
const { phone } = this.data; const { phone, role } = this.data;
// 1. 非空校验 // 1. 非空校验
if (!validate(this.data, { phone: '请输入手机号' })) { if (!validate(this.data, { phone: '请输入手机号' })) {
@ -83,7 +83,10 @@ Page({
wx.request({ wx.request({
url: baseUrl + '/userInfo/code/pwd', url: baseUrl + '/userInfo/code/pwd',
method: 'POST', method: 'POST',
data: { templateString: phone }, data: {
phoneNumber: phone,
userRole: role
},
success: (res) => { success: (res) => {
console.log('验证码发送--->',res.data); console.log('验证码发送--->',res.data);
if (res.data.code === 1) { if (res.data.code === 1) {
@ -176,7 +179,7 @@ Page({
const token = res.data.data.token || res.data.data; const token = res.data.data.token || res.data.data;
// ← 新增:将 token 存到本地缓存 // ← 新增:将 token 存到本地缓存
wx.setStorageSync('token', token); wx.setStorageSync('token', token);
wx.setStorageSync('role', role)
wx.showToast({ wx.showToast({
title: '登录成功', title: '登录成功',
icon: 'success', icon: 'success',

View File

@ -54,7 +54,7 @@ Page({
}, },
sendSmsCode() { sendSmsCode() {
const { phone } = this.data; const { phone, role } = this.data;
if (!phone.trim()) { if (!phone.trim()) {
wx.showToast({ title: '请输入手机号', icon: 'none' }); wx.showToast({ title: '请输入手机号', icon: 'none' });
return; return;
@ -68,7 +68,8 @@ Page({
method: 'POST', method: 'POST',
header: { 'content-type': 'application/json' }, header: { 'content-type': 'application/json' },
data: { data: {
templateString: phone phoneNumber: phone,
userRole: role
}, },
success: res => { success: res => {
// 假设后端返回 { success: true, ... } // 假设后端返回 { success: true, ... }

View File

@ -33,6 +33,7 @@ Page({
icon: 'success' icon: 'success'
}) })
wx.removeStorageSync('token') wx.removeStorageSync('token')
wx.removeStorageSync('role')
setTimeout(() => { setTimeout(() => {
wx.reLaunch({ wx.reLaunch({
url: '/pages/welcome/homePage/homePage', url: '/pages/welcome/homePage/homePage',

View File

@ -67,7 +67,8 @@ Page({
Authorization: wx.getStorageSync('token') Authorization: wx.getStorageSync('token')
}, },
data: { data: {
templateString: phone phoneNumber: phone,
userRole: wx.getStorageSync('role')
}, },
success: res => { success: res => {
if (res.data.code === 1) { if (res.data.code === 1) {