feat: 登录逻辑的调整

This commit is contained in:
2025-09-20 16:13:07 +08:00
parent 67474d73a4
commit 4cdff7a594
6 changed files with 25 additions and 61 deletions

View File

@@ -1,7 +1,7 @@
import { loginAuth, bindPhone } from "@/manager/LoginManager";
// 引入base.js中的clientId
import { clientId } from "@/constant/base";
import { clientId } from "@/constant/base";
import { useAppStore } from "@/store";
// 跳转登录
export const goLogin = () => uni.navigateTo({ url: "/pages/login/index" });
@@ -14,7 +14,7 @@ export const onLogin = async (e) => {
await loginAuth().then(async () => {
const { code } = e.detail;
console.info("onLogin code: ", code);
// 绑定手机号
const params = { wechatPhoneCode: code, clientId: clientId };
const res = await bindPhone(params);
@@ -26,14 +26,13 @@ export const onLogin = async (e) => {
};
// 检测token
export const checkToken = async () => {
export const checkToken = () => {
return new Promise((resolve) => {
const token = uni.getStorageSync("token");
if (!token) {
console.log("token不存在重新登录");
loginAuth().then(() => {
resolve();
});
const appStore = useAppStore();
console.log("appStore.hasToken: ", appStore.hasToken);
if (!appStore.hasToken) {
console.log("没有token跳转到登录页");
goLogin();
return;
}
resolve();