This commit is contained in:
FengHui
2026-04-10 13:18:15 +08:00
parent c742a65aa0
commit 3fe4dbe47f
2 changed files with 64 additions and 22 deletions

View File

@@ -194,13 +194,27 @@ const resendSms = async () => {
uni.showLoading({ title: '发送中...' }); uni.showLoading({ title: '发送中...' });
try { try {
// 调用重新发送验证码接口 // 调用重新发送验证码接口
await $api.createRequest('/app/sendSmsAgain', { phone: phone.value }, 'post'); const requestParams = { phone: phone.value };
uni.hideLoading(); // 只有单位用户才传递机构类型
uni.showToast({ title: '验证码已发送', icon: 'success' }); if (userType.value === '0') {
startCountdown(); requestParams.orgType = orgType.value;
requestParams.userType = userType.value;
}
const res = await $api.createRequest('/app/sendSmsAgain', requestParams, 'post');
// 检查状态码
if (res.code === 200 ) {
uni.hideLoading();
uni.showToast({ title: '验证码已发送', icon: 'success' });
startCountdown();
} else {
uni.hideLoading();
uni.showToast({ title: res.msg || '发送失败', icon: 'none' });
}
} catch (error) { } catch (error) {
uni.hideLoading(); uni.hideLoading();
uni.showToast({ title: error.msg || '发送失败', icon: 'none' }); uni.showToast({ title: error.msg || '发送失败,请重试', icon: 'none' });
} }
}; };
@@ -305,16 +319,29 @@ const submitVerification = async () => {
try { try {
// 调用接口 /app/appLoginPhone // 调用接口 /app/appLoginPhone
const res = await $api.createRequest('/app/appLoginPhone', { const requestParams = {
smsCode: code, smsCode: code,
phone: phone.value, phone: phone.value,
openid: openid.value, openid: openid.value,
unionid: unionid.value, unionid: unionid.value,
userType: userType.value, userType: userType.value
orgType: orgType.value };
}, 'post'); // 只有单位用户才传递机构类型
if (userType.value === '0') {
requestParams.orgType = orgType.value;
}
const res = await $api.createRequest('/app/appLoginPhone', requestParams, 'post');
if (res.token && res.code === 200) {
// 检查idCard是否为null如果是则跳转到个人信息不全页面
if (res.idCard) {
uni.showToast({ title: '个人信息不全,请完善信息', icon: 'none' });
setTimeout(() => {
uni.navigateTo({ url: '/pages/personal-info/incomplete' });
}, 1500);
return;
}
if (res.token) {
// 登录成功存储token // 登录成功存储token
const userStore = useUserStore(); const userStore = useUserStore();
await userStore.loginSetToken(res.token); await userStore.loginSetToken(res.token);
@@ -336,7 +363,7 @@ const submitVerification = async () => {
uni.showToast({ title: res.msg || '验证失败', icon: 'none' }); uni.showToast({ title: res.msg || '验证失败', icon: 'none' });
} }
} catch (error) { } catch (error) {
uni.showToast({ title: error.msg || '验证失败,请重试', icon: 'none' }); uni.showToast({ title: error || '验证失败,请重试', icon: 'none' });
} finally { } finally {
loading.value = false; loading.value = false;
} }

View File

@@ -260,13 +260,19 @@ const onWxGetPhoneNumber = async (e) => {
// 调用接口 /app/appWxphoneSmsCode // 调用接口 /app/appWxphoneSmsCode
uni.showLoading({ title: '获取验证码中...' }); uni.showLoading({ title: '获取验证码中...' });
$api.createRequest('/app/appWxphoneSmsCode', { // 根据用户类型构建参数
const requestParams = {
code, code,
encryptedData, encryptedData,
iv, iv,
userType: userType.value, userType: userType.value
orgType: orgType.value };
}, 'post').then((resData) => { // 只有单位用户才传递机构类型
if (userType.value === 0) {
requestParams.orgType = orgType.value;
}
$api.createRequest('/app/appWxphoneSmsCode', requestParams, 'post').then((resData) => {
uni.hideLoading(); uni.hideLoading();
// 检查可能的手机号字段 // 检查可能的手机号字段
const possiblePhoneFields = ['phone', 'mobile', 'phoneNumber', 'tel', 'mobilePhone']; const possiblePhoneFields = ['phone', 'mobile', 'phoneNumber', 'tel', 'mobilePhone'];
@@ -285,9 +291,12 @@ const onWxGetPhoneNumber = async (e) => {
phone: phoneValue || '', // 接口返回的手机号 phone: phoneValue || '', // 接口返回的手机号
openid: resData.openid || '', openid: resData.openid || '',
unionid: resData.unionid || '', unionid: resData.unionid || '',
userType: userType.value, userType: userType.value
orgType: orgType.value
}; };
// 只有单位用户才传递机构类型
if (userType.value === 0) {
params.orgType = orgType.value;
}
uni.navigateTo({ uni.navigateTo({
url: '/pages/login/sms-verify?' + Object.keys(params) url: '/pages/login/sms-verify?' + Object.keys(params)
@@ -351,12 +360,18 @@ const wxLogin = () => {
success: (loginRes) => { success: (loginRes) => {
console.log('微信登录成功:', loginRes); console.log('微信登录成功:', loginRes);
// 调用后端接口进行登录 // 根据用户类型构建参数
$api.createRequest('/app/appLogin', { const loginParams = {
code: loginRes.code, code: loginRes.code,
userType: userType.value, userType: userType.value
orgType: orgType.value };
}, 'post').then((resData) => { // 只有单位用户才传递机构类型
if (userType.value === 0) {
loginParams.orgType = orgType.value;
}
// 调用后端接口进行登录
$api.createRequest('/app/appLogin', loginParams, 'post').then((resData) => {
if (resData.token) { if (resData.token) {
userStore.loginSetToken(resData.token).then((resume) => { userStore.loginSetToken(resData.token).then((resume) => {
// 更新用户类型到缓存 // 更新用户类型到缓存