fix: 修复token赋值
This commit is contained in:
parent
70625f6ea1
commit
29bdcc1914
@ -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()
|
||||||
|
Loading…
Reference in New Issue
Block a user