From 29bdcc191446a509fc81d0271d39a49f6a740f92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E5=BA=86=E4=BC=9F?= <1208669287@qq.com> Date: Mon, 19 May 2025 09:25:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dtoken=E8=B5=8B?= =?UTF-8?q?=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/index/index.vue | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue index fd4e8fd..abb802d 100644 --- a/src/pages/index/index.vue +++ b/src/pages/index/index.vue @@ -353,7 +353,6 @@ interface IMessage { const userAvatar = ref('') const baseUrl = getEnvBaseUrl() -// const token = useUserStore().userInfo.token || import.meta.env.VITE_DEV_TOKEN || '' const messages = reactive([]) //获取用户上下文 const historyUserMsgs = reactive([]) @@ -430,6 +429,7 @@ async function goChat(listUuid: string) { const listUuid = ref('') async function createChatSession() { + console.log(token.value, 'wwww') try { const createResp: any = await uni.request({ url: `${baseUrl}/chat/create`, @@ -438,7 +438,7 @@ async function createChatSession() { gptModel: 'gpt-3.5-turbo', }, header: { - Authorization: token, + Authorization: token.value, }, }) // 如果后台返回新的会话信息,可以在这里处理,比如拿到 listUuid 等 @@ -463,7 +463,7 @@ async function fetchHistoryList() { pageSize: 30, }, header: { - Authorization: token, + Authorization: token.value, }, }) if (resp.data && resp.data.data) { @@ -486,7 +486,7 @@ async function fetchHistoryDiets(value) { gptModel: 'gpt-3.5-turbo', }, header: { - Authorization: token, + Authorization: token.value, }, }) if (resp.data) { @@ -506,9 +506,9 @@ const mask = ref('') onMounted(() => { // 1. 定义一个 init 函数,拿 Extras 并依次调用接口 const init = async () => { - // plusready 后才能用 plus.webview const wv = plus.webview.currentWebview() - token.value = wv.token || uni.getStorageSync('token') + + token.value = uni.getStorageSync('token') || import.meta.env.VITE_DEV_TOKEN || wv.token userInfo.value = JSON.parse(wv.userInfo) || {} refreshToken.value = wv.refreshToken || uni.getStorageSync('refreshToken') statusBarHeight.value = wv.statusBarHeight || uni.getSystemInfoSync().statusBarHeight @@ -528,7 +528,7 @@ onMounted(() => { } // 3. 普通 H5 调试,直接从 storage/SystemInfo 拿 else { - token.value = uni.getStorageSync('token') + token.value = import.meta.env.VITE_DEV_TOKEN || uni.getStorageSync('token') || wv.token userInfo.value = uni.getStorageSync('userInfo') refreshToken.value = uni.getStorageSync('refreshToken') statusBarHeight.value = uni.getSystemInfoSync().statusBarHeight @@ -944,7 +944,7 @@ async function sendText(msg) { const resp = await fetch(baseUrl + '/chat/completion', { method: 'POST', - headers: { 'Content-Type': 'application/json', Authorization: token }, + headers: { 'Content-Type': 'application/json', Authorization: token.value }, body: JSON.stringify(body), }) const reader = resp.body!.getReader()