feat: 调整登录逻辑

This commit is contained in:
duanshuwen
2025-12-25 22:45:55 +08:00
parent b7fbe99cd0
commit f027685072
3 changed files with 28 additions and 23 deletions

View File

@@ -2,6 +2,7 @@
import { onLaunch, onShow, onHide } from "@dcloudio/uni-app"; import { onLaunch, onShow, onHide } from "@dcloudio/uni-app";
import { getEvnUrl } from "@/request/api/config"; import { getEvnUrl } from "@/request/api/config";
import { refreshToken } from "@/hooks/useGoLogin"; import { refreshToken } from "@/hooks/useGoLogin";
import { checkPhone } from "@/manager/LoginManager";
onLaunch(async () => { onLaunch(async () => {
await getEvnUrl({ versionValue: "1.0.3" }); await getEvnUrl({ versionValue: "1.0.3" });

View File

@@ -61,30 +61,34 @@ export const checkToken = () => {
}; };
// 刷新token // 刷新token
export const refreshToken = () => { export const refreshToken = async () => {
return new Promise((resolve) => { return new Promise((resolve) => {
uni.login({ checkPhone().then(async (checkRes) => {
provider: "weixin", //使用微信登录 if (!checkRes.data) {
success: async ({ code }) => { resolve(true);
console.log("refreshToken", code); return;
const params = { }
openIdCode: [code],
grant_type: "wechat",
scope: "server",
clientId: clientId,
};
console.log("获取到的微信授权params:", JSON.stringify(params));
const response = await wxLogin(params);
if (response.access_token) { uni.login({
setStorageSyncToken(response.access_token); provider: "weixin", //使用微信登录
// 登录成功后,触发登录成功事件 success: async ({ code }) => {
uni.$emit(NOTICE_EVENT_LOGIN_SUCCESS); console.log("refreshToken", code);
resolve(false) const params = {
} else { openIdCode: [code],
resolve(true) grant_type: "wechat",
} scope: "server",
}, clientId: clientId,
};
console.log("获取到的微信授权params:", JSON.stringify(params));
const response = await wxLogin(params);
if (response.access_token) {
setStorageSyncToken(response.access_token);
// 登录成功后,触发登录成功事件
uni.$emit(NOTICE_EVENT_LOGIN_SUCCESS);
}
},
});
}); });
}); });
}; };

View File

@@ -83,7 +83,7 @@ const logo = computed(() => getCurrentConfig().logo);
const handleAgreeAndGetPhone = () => { const handleAgreeAndGetPhone = () => {
// 如果需要微信登录,直接返回 // 如果需要微信登录,直接返回
if (needWxLogin.value) { if (needWxLogin.value) {
return return;
} }
if (!isAgree.value) { if (!isAgree.value) {