feat: 调整优化登录的逻辑

This commit is contained in:
2025-09-15 22:52:44 +08:00
parent 66c256cefd
commit fc63bbc994
15 changed files with 190 additions and 159 deletions

View File

@@ -1,27 +1,25 @@
import { loginAuth, checkPhone, bindPhone } from "@/manager/LoginManager";
import { loginAuth, bindPhone } from "@/manager/LoginManager";
// 跳转登录
export const goLogin = () => uni.reLaunch({ url: "/pages/login/index" });
export const goLogin = () => uni.navigateTo({ url: "/pages/login/index" });
// 登录成功后,返回上一页
export const goBack = () => uni.navigateBack({ delta: 1 });
// 登录逻辑
export const onLogin = (e) => {
const token = uni.getStorageSync("token");
export const onLogin = async (e) => {
return new Promise(async (resolve) => {
await loginAuth().then(async () => {
const { code } = e.detail;
console.info("onLogin code: ", code);
if (token) return;
const { code } = e.detail;
console.info("onLogin code: ", code);
loginAuth().then(async () => {
// 检测是否绑定手机号
const res = await checkPhone();
if (res.data) return;
const params = { wechatPhoneCode: code, clientId: "2" };
// 绑定手机号
bindPhone(params);
// 绑定手机号
const params = { wechatPhoneCode: code, clientId: "2" };
const res = await bindPhone(params);
if (res.data) {
resolve();
}
});
});
};
@@ -29,9 +27,13 @@ export const onLogin = (e) => {
export const checkToken = async () => {
return new Promise((resolve) => {
const token = uni.getStorageSync("token");
if (!token) return;
resolve(token);
if (!token) {
console.log("token不存在重新登录");
loginAuth().then(() => {
resolve();
});
return;
}
resolve();
});
};