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 baseUrl = getEnvBaseUrl()
// const token = useUserStore().userInfo.token || import.meta.env.VITE_DEV_TOKEN || ''
const messages = reactive<IMessage[]>([])
//
const historyUserMsgs = reactive<any[]>([])
@ -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()