主包体积太大,相关代码迁移
This commit is contained in:
@@ -79,6 +79,7 @@
|
||||
<button
|
||||
class="auth-btn primary"
|
||||
open-type="getPhoneNumber"
|
||||
@tap="onPrepareWxAuth"
|
||||
@getphonenumber="getPhoneNumber"
|
||||
>
|
||||
<uni-icons type="phone" size="20" color="#FFFFFF"></uni-icons>
|
||||
@@ -126,7 +127,7 @@ import { ref, inject, onMounted } from 'vue';
|
||||
import useUserStore from '@/stores/useUserStore';
|
||||
import useDictStore from '@/stores/useDictStore';
|
||||
import { tabbarManager } from '@/utils/tabbarManager';
|
||||
import { refreshWxLoginCode, takeWxLoginCode } from '@/utils/loginHelper';
|
||||
import { prepareWxLoginCodeOnTap, consumeWxLoginCodeFromTap } from '@/utils/loginHelper';
|
||||
|
||||
const { $api } = inject('globalFunction');
|
||||
const { loginSetToken } = useUserStore();
|
||||
@@ -173,9 +174,6 @@ const open = () => {
|
||||
const agreed = uni.getStorageSync('agreedToUserAgreement');
|
||||
agreedToAgreement.value = !!agreed;
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
refreshWxLoginCode().catch(() => {});
|
||||
// #endif
|
||||
};
|
||||
|
||||
// 关闭弹窗
|
||||
@@ -217,6 +215,15 @@ const validateRole = () => {
|
||||
return true;
|
||||
};
|
||||
|
||||
const onPrepareWxAuth = () => {
|
||||
if (!validateRole()) {
|
||||
return;
|
||||
}
|
||||
prepareWxLoginCodeOnTap().catch((err) => {
|
||||
console.error('预取微信登录凭证失败:', err);
|
||||
});
|
||||
};
|
||||
|
||||
const getPhoneNumber = async (e) => {
|
||||
if (!validateRole()) {
|
||||
return;
|
||||
@@ -229,19 +236,17 @@ const getPhoneNumber = async (e) => {
|
||||
return;
|
||||
}
|
||||
|
||||
let loginCode = takeWxLoginCode();
|
||||
let loginCode = '';
|
||||
try {
|
||||
loginCode = await consumeWxLoginCodeFromTap();
|
||||
} catch (err) {
|
||||
console.error('获取微信登录凭证失败:', err);
|
||||
$api.msg('获取登录信息失败,请重试');
|
||||
return;
|
||||
}
|
||||
if (!loginCode) {
|
||||
if (encryptedData) {
|
||||
$api.msg('登录凭证未就绪,请关闭弹窗后重新打开再试');
|
||||
refreshWxLoginCode().catch(() => {});
|
||||
return;
|
||||
}
|
||||
try {
|
||||
loginCode = await refreshWxLoginCode();
|
||||
} catch {
|
||||
$api.msg('获取登录信息失败,请重试');
|
||||
return;
|
||||
}
|
||||
$api.msg('登录凭证未就绪,请重新点击授权');
|
||||
return;
|
||||
}
|
||||
|
||||
const requestParams = {
|
||||
@@ -291,10 +296,10 @@ const getPhoneNumber = async (e) => {
|
||||
$api.msg(resData.msg || '登录失败,请重试');
|
||||
}
|
||||
} catch (err) {
|
||||
$api.msg(err.msg || '登录失败,请重试');
|
||||
console.error('微信登录请求异常:', err);
|
||||
$api.msg(err.message || err.msg || '登录失败,请重试');
|
||||
} finally {
|
||||
uni.hideLoading();
|
||||
refreshWxLoginCode().catch(() => {});
|
||||
}
|
||||
} else if (e.detail.errMsg === 'getPhoneNumber:fail user deny') {
|
||||
$api.msg('您取消了授权');
|
||||
@@ -314,7 +319,7 @@ const wxLogin = () => {
|
||||
// H5端跳转到H5登录页面
|
||||
close();
|
||||
uni.navigateTo({
|
||||
url: '/pages/login/h5-login'
|
||||
url: '/packageA/pages/login/h5-login'
|
||||
});
|
||||
return;
|
||||
// #endif
|
||||
|
||||
Reference in New Issue
Block a user