From 3fe4dbe47fbd9f7b10124c1027b22e5e5d965a71 Mon Sep 17 00:00:00 2001 From: FengHui Date: Fri, 10 Apr 2026 13:18:15 +0800 Subject: [PATCH] 11111 --- pages/login/sms-verify.vue | 49 +++++++++++++++++++++++++++++--------- pages/login/wx-login.vue | 37 +++++++++++++++++++--------- 2 files changed, 64 insertions(+), 22 deletions(-) diff --git a/pages/login/sms-verify.vue b/pages/login/sms-verify.vue index c03cadc..cd28ebc 100644 --- a/pages/login/sms-verify.vue +++ b/pages/login/sms-verify.vue @@ -194,13 +194,27 @@ const resendSms = async () => { uni.showLoading({ title: '发送中...' }); try { // 调用重新发送验证码接口 - await $api.createRequest('/app/sendSmsAgain', { phone: phone.value }, 'post'); - uni.hideLoading(); - uni.showToast({ title: '验证码已发送', icon: 'success' }); - startCountdown(); + const requestParams = { phone: phone.value }; + // 只有单位用户才传递机构类型 + if (userType.value === '0') { + 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) { uni.hideLoading(); - uni.showToast({ title: error.msg || '发送失败', icon: 'none' }); + uni.showToast({ title: error.msg || '发送失败,请重试', icon: 'none' }); } }; @@ -305,16 +319,29 @@ const submitVerification = async () => { try { // 调用接口 /app/appLoginPhone - const res = await $api.createRequest('/app/appLoginPhone', { + const requestParams = { smsCode: code, phone: phone.value, openid: openid.value, unionid: unionid.value, - userType: userType.value, - orgType: orgType.value - }, 'post'); + userType: userType.value + }; + // 只有单位用户才传递机构类型 + if (userType.value === '0') { + requestParams.orgType = orgType.value; + } + const res = await $api.createRequest('/app/appLoginPhone', requestParams, 'post'); - if (res.token) { + 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; + } + // 登录成功,存储token const userStore = useUserStore(); await userStore.loginSetToken(res.token); @@ -336,7 +363,7 @@ const submitVerification = async () => { uni.showToast({ title: res.msg || '验证失败', icon: 'none' }); } } catch (error) { - uni.showToast({ title: error.msg || '验证失败,请重试', icon: 'none' }); + uni.showToast({ title: error || '验证失败,请重试', icon: 'none' }); } finally { loading.value = false; } diff --git a/pages/login/wx-login.vue b/pages/login/wx-login.vue index 893d5fe..7f88026 100644 --- a/pages/login/wx-login.vue +++ b/pages/login/wx-login.vue @@ -260,13 +260,19 @@ const onWxGetPhoneNumber = async (e) => { // 调用接口 /app/appWxphoneSmsCode uni.showLoading({ title: '获取验证码中...' }); - $api.createRequest('/app/appWxphoneSmsCode', { + // 根据用户类型构建参数 + const requestParams = { code, encryptedData, iv, - userType: userType.value, - orgType: orgType.value - }, 'post').then((resData) => { + userType: userType.value + }; + // 只有单位用户才传递机构类型 + if (userType.value === 0) { + requestParams.orgType = orgType.value; + } + + $api.createRequest('/app/appWxphoneSmsCode', requestParams, 'post').then((resData) => { uni.hideLoading(); // 检查可能的手机号字段 const possiblePhoneFields = ['phone', 'mobile', 'phoneNumber', 'tel', 'mobilePhone']; @@ -285,9 +291,12 @@ const onWxGetPhoneNumber = async (e) => { phone: phoneValue || '', // 接口返回的手机号 openid: resData.openid || '', unionid: resData.unionid || '', - userType: userType.value, - orgType: orgType.value + userType: userType.value }; + // 只有单位用户才传递机构类型 + if (userType.value === 0) { + params.orgType = orgType.value; + } uni.navigateTo({ url: '/pages/login/sms-verify?' + Object.keys(params) @@ -351,12 +360,18 @@ const wxLogin = () => { success: (loginRes) => { console.log('微信登录成功:', loginRes); - // 调用后端接口进行登录 - $api.createRequest('/app/appLogin', { + // 根据用户类型构建参数 + const loginParams = { code: loginRes.code, - userType: userType.value, - orgType: orgType.value - }, 'post').then((resData) => { + userType: userType.value + }; + // 只有单位用户才传递机构类型 + if (userType.value === 0) { + loginParams.orgType = orgType.value; + } + + // 调用后端接口进行登录 + $api.createRequest('/app/appLogin', loginParams, 'post').then((resData) => { if (resData.token) { userStore.loginSetToken(resData.token).then((resume) => { // 更新用户类型到缓存