diff --git a/hooks/useGoLogin.js b/hooks/useGoLogin.js index 0ca9a36..09a3928 100644 --- a/hooks/useGoLogin.js +++ b/hooks/useGoLogin.js @@ -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(); }); }; diff --git a/manager/LoginManager.js b/manager/LoginManager.js index de18336..0750345 100644 --- a/manager/LoginManager.js +++ b/manager/LoginManager.js @@ -20,9 +20,7 @@ const loginAuth = () => { if (response.access_token) { uni.setStorageSync("token", response.access_token); - const appStore = useAppStore(); - appStore.setHasToken(true); resolve(); } else { diff --git a/pages/chat/ChatInputArea.vue b/pages/chat/ChatInputArea.vue index 8aa5539..e71e0cd 100644 --- a/pages/chat/ChatInputArea.vue +++ b/pages/chat/ChatInputArea.vue @@ -9,8 +9,6 @@ - -