From 4cdff7a594a803aa9c3a34c93679f03a39b82bd2 Mon Sep 17 00:00:00 2001 From: zoujing Date: Sat, 20 Sep 2025 16:13:07 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=99=BB=E5=BD=95=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E7=9A=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Interceptor/index.vue | 18 ---------------- hooks/useGoLogin.js | 21 +++++++++---------- pages/chat/ChatMainList.vue | 19 ++++++----------- pages/chat/ChatTopNavBar.vue | 12 +++-------- .../booking/QuickBookingContentList.vue | 7 +++++-- request/base/request.js | 9 +------- 6 files changed, 25 insertions(+), 61 deletions(-) delete mode 100644 components/Interceptor/index.vue diff --git a/components/Interceptor/index.vue b/components/Interceptor/index.vue deleted file mode 100644 index bfea59a..0000000 --- a/components/Interceptor/index.vue +++ /dev/null @@ -1,18 +0,0 @@ - - - diff --git a/hooks/useGoLogin.js b/hooks/useGoLogin.js index 31268d3..f4f9c56 100644 --- a/hooks/useGoLogin.js +++ b/hooks/useGoLogin.js @@ -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(); diff --git a/pages/chat/ChatMainList.vue b/pages/chat/ChatMainList.vue index 7b514d8..39b501d 100644 --- a/pages/chat/ChatMainList.vue +++ b/pages/chat/ChatMainList.vue @@ -181,7 +181,7 @@ import { import WebSocketManager from "@/utils/WebSocketManager"; import TypewriterManager from "@/utils/TypewriterManager"; import { IdUtils } from "@/utils"; -import { goLogin } from "@/hooks/useGoLogin"; +import { goLogin, checkToken } from "@/hooks/useGoLogin"; import { useAppStore } from "@/store"; const appStore = useAppStore(); @@ -297,12 +297,9 @@ const handleReply = (text) => { }; // 是发送指令 -const handleReplyInstruct = (item) => { - if (!appStore.hasToken) { - console.log("没有token,跳转到登录页"); - goLogin(); - return; - } +const handleReplyInstruct = async (item) => { + await checkToken(); + if (item.type === "MyOrder") { // 订单 uni.navigateTo({ @@ -632,14 +629,10 @@ const initData = () => { }; // 发送消息的参数拼接 -const sendMessage = (message, isInstruct = false) => { +const sendMessage = async (message, isInstruct = false) => { console.log("发送的消息:", message); - if (!appStore.hasToken) { - console.log("没有token,跳转到登录页"); - goLogin(); - return; - } + await checkToken(); if (!webSocketConnectStatus) { uni.showToast({ diff --git a/pages/chat/ChatTopNavBar.vue b/pages/chat/ChatTopNavBar.vue index a68bed0..3e2804a 100644 --- a/pages/chat/ChatTopNavBar.vue +++ b/pages/chat/ChatTopNavBar.vue @@ -13,18 +13,12 @@ diff --git a/request/base/request.js b/request/base/request.js index fd2fd1c..b99223c 100644 --- a/request/base/request.js +++ b/request/base/request.js @@ -1,6 +1,5 @@ import { goLogin } from "../../hooks/useGoLogin"; import { BASE_URL } from "./baseUrl"; -import { loginAuth, checkPhone } from "@/manager/LoginManager"; const defaultConfig = { header: { @@ -53,13 +52,7 @@ function request(url, args = {}, method = "POST", customConfig = {}) { resolve(res.data); if (res.statusCode && res.statusCode === 424) { console.log("424错误,重新登录"); - loginAuth().then(async () => { - // 检测是否绑定手机号 - const res = await checkPhone(); - if (!res.data) { - goLogin(); - } - }); + goLogin(); } }, fail: (err) => {