fix: 修复token赋值

This commit is contained in:
韩庆伟 2025-05-19 09:25:35 +08:00
parent 70625f6ea1
commit 29bdcc1914

View File

@ -353,7 +353,6 @@ interface IMessage {
const userAvatar = ref('') const userAvatar = ref('')
const baseUrl = getEnvBaseUrl() const baseUrl = getEnvBaseUrl()
// const token = useUserStore().userInfo.token || import.meta.env.VITE_DEV_TOKEN || ''
const messages = reactive<IMessage[]>([]) const messages = reactive<IMessage[]>([])
// //
const historyUserMsgs = reactive<any[]>([]) const historyUserMsgs = reactive<any[]>([])
@ -430,6 +429,7 @@ async function goChat(listUuid: string) {
const listUuid = ref('') const listUuid = ref('')
async function createChatSession() { async function createChatSession() {
console.log(token.value, 'wwww')
try { try {
const createResp: any = await uni.request({ const createResp: any = await uni.request({
url: `${baseUrl}/chat/create`, url: `${baseUrl}/chat/create`,
@ -438,7 +438,7 @@ async function createChatSession() {
gptModel: 'gpt-3.5-turbo', gptModel: 'gpt-3.5-turbo',
}, },
header: { header: {
Authorization: token, Authorization: token.value,
}, },
}) })
// listUuid // listUuid
@ -463,7 +463,7 @@ async function fetchHistoryList() {
pageSize: 30, pageSize: 30,
}, },
header: { header: {
Authorization: token, Authorization: token.value,
}, },
}) })
if (resp.data && resp.data.data) { if (resp.data && resp.data.data) {
@ -486,7 +486,7 @@ async function fetchHistoryDiets(value) {
gptModel: 'gpt-3.5-turbo', gptModel: 'gpt-3.5-turbo',
}, },
header: { header: {
Authorization: token, Authorization: token.value,
}, },
}) })
if (resp.data) { if (resp.data) {
@ -506,9 +506,9 @@ const mask = ref('')
onMounted(() => { onMounted(() => {
// 1. init Extras // 1. init Extras
const init = async () => { const init = async () => {
// plusready plus.webview
const wv = plus.webview.currentWebview() 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) || {} userInfo.value = JSON.parse(wv.userInfo) || {}
refreshToken.value = wv.refreshToken || uni.getStorageSync('refreshToken') refreshToken.value = wv.refreshToken || uni.getStorageSync('refreshToken')
statusBarHeight.value = wv.statusBarHeight || uni.getSystemInfoSync().statusBarHeight statusBarHeight.value = wv.statusBarHeight || uni.getSystemInfoSync().statusBarHeight
@ -528,7 +528,7 @@ onMounted(() => {
} }
// 3. H5 storage/SystemInfo // 3. H5 storage/SystemInfo
else { else {
token.value = uni.getStorageSync('token') token.value = import.meta.env.VITE_DEV_TOKEN || uni.getStorageSync('token') || wv.token
userInfo.value = uni.getStorageSync('userInfo') userInfo.value = uni.getStorageSync('userInfo')
refreshToken.value = uni.getStorageSync('refreshToken') refreshToken.value = uni.getStorageSync('refreshToken')
statusBarHeight.value = uni.getSystemInfoSync().statusBarHeight statusBarHeight.value = uni.getSystemInfoSync().statusBarHeight
@ -944,7 +944,7 @@ async function sendText(msg) {
const resp = await fetch(baseUrl + '/chat/completion', { const resp = await fetch(baseUrl + '/chat/completion', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json', Authorization: token }, headers: { 'Content-Type': 'application/json', Authorization: token.value },
body: JSON.stringify(body), body: JSON.stringify(body),
}) })
const reader = resp.body!.getReader() const reader = resp.body!.getReader()