fix: 修复token和用户信息问题

This commit is contained in:
yuanshan 2025-09-11 11:24:48 +08:00
parent c2fcf9c0e2
commit a21420754c
2 changed files with 23 additions and 36 deletions

1
env/.env vendored
View File

@ -8,6 +8,7 @@ VITE_DEV_TOKEN= ""
VITE_APP_PUBLIC_BASE=/
VITE_SERVER_BASEURL = 'http://114.218.158.24:9020'
# VITE_SERVER_BASEURL = 'https://oa-b.szjixun.cn/api'
VITE_UPLOAD_BASEURL = 'http://114.218.158.24:9020'
# 有些同学可能需要在微信小程序里面根据 develop、trial、release 分别设置上传地址,参考代码如下。

View File

@ -11,7 +11,7 @@
<div class="flex flex-col h-screen bg-#ffffff tops">
<!-- Navigation Bar -->
<div
class="flex-none flex items-center justify-between px-5 pb-6 bg-white shadow-md h-20 pt-15 z-999 fixed top-0 w-full box-border"
class="flex-none flex items-center justify-between px-5 pb-2 bg-white shadow-md pt-2 z-999 fixed top-0 w-full box-border"
>
<image src="/static/aichat/black.png" class="w-3 h-4.5" @click="goBack" />
<div class="text-lg font-medium ml-12">小墨</div>
@ -21,7 +21,6 @@
<image src="/static/aichat/new.png" class="w-5 h-5" @click="newChat" />
</div>
</div>
<!-- 消息区 -->
<div
:class="[
@ -37,6 +36,12 @@
<image src="/static/aichat/logo.png" class="w-20 h-24 mb-4" @click="newChat" />
<view class="text-xl font-medium mb-1"> 我是小墨</view>
<view class="text-gray-400">开启新的聊天吧</view>
<view
class="text-gray-400"
style="max-width: 200px; overflow: auto; text-overflow: ellipsis; white-space: nowrap"
>
{{ chatUserInfo }}
</view>
</div>
<div
@ -514,7 +519,6 @@ import {
import 'dayjs/locale/zh-cn'
import { showToastErr, showToastOk, time_format3 } from '@/utils/tools'
import { uploadFileChunk } from './utils/api.js'
// import { TOKEN, AVATAR } from './utils/test'
import { deepClone } from 'wot-design-uni/components/common/util'
import VConsole from 'vconsole'
@ -627,7 +631,7 @@ async function createChatSession() {
gptModel: chatMode.value,
},
header: {
Authorization: token.value,
Authorization: chatToken.value,
},
})
// listUuid
@ -669,9 +673,7 @@ async function fetchHistoryList() {
page: state.page,
pageSize: state.pageSize,
},
header: {
// Authorization: token.value,
},
header: {},
})
if (resp.data.code == 0 && resp.data.data) {
if (rawList.value.length > 0) {
@ -731,9 +733,7 @@ async function fetchHistoryDiets(value) {
listUuid: value,
gptModel: chatMode.value,
},
header: {
// Authorization: token.value,
},
header: {},
})
if (resp.data.status === 0 && resp.data && resp.data.data) {
const rawList = resp?.data?.data?.detail //
@ -1004,35 +1004,29 @@ function tryParseMapFormat(str: string): ParsedPart[] | null {
return result.length > 0 ? result : null
}
const token = ref<string>()
const userInfo = ref<any>({})
const chatToken = ref<string>()
const chatUserInfo = ref<any>({})
const refreshToken = ref<string>('')
const statusBarHeight = ref<number>(0)
const mask = ref('')
// ---- ----
onMounted(async () => {
const { token } = await window.NativeBridge.getAccessToken()
const { user } = await window.NativeBridge.call('auth.getUser')
chatToken.value = token
chatUserInfo.value = user
// 1. init Extras
try {
const init = async () => {
const wv = plus.webview.currentWebview() // Webview
token.value =
wv.token ||
uni.getStorageSync('token') ||
store.userInfo.token ||
import.meta.env.VITE_DEV_TOKEN
userInfo.value = JSON.parse(wv.userInfo) || {}
refreshToken.value = wv.refreshToken || uni.getStorageSync('refreshToken')
statusBarHeight.value = wv.statusBarHeight || uni.getSystemInfoSync().statusBarHeight
userAvatar.value = userInfo.value.Avatar
mask.value = userInfo.value.ID
userAvatar.value = chatUserInfo.value.Avatar
mask.value = chatUserInfo.value.ID
store.setUserInfo({
token: token.value,
avatar: userInfo.value.Avatar,
refreshToken: refreshToken.value,
statusBarHeight: statusBarHeight.value,
token: chatToken.value,
avatar: chatUserInfo.value.Avatar,
})
if (userInfo.value.TelNum === '18639432358') {
if (chatUserInfo.value.TelNum === '18639432358') {
new VConsole()
}
await createChatSession()
@ -1041,12 +1035,7 @@ onMounted(async () => {
} catch (e) {
console.error('onMounted e: ', e)
} finally {
// store.userInfo.token = ''
// token.value = store.userInfo.token
}
// if (JSON.parse(uni.getStorageSync('userInfo'))?.NickName === '') {
// new VConsole()
// }
})
function scrollToBottom() {
@ -1908,12 +1897,11 @@ const send = async (body) => {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: token.value,
Authorization: chatToken.value,
},
body: JSON.stringify(body),
signal: signal,
})
// console.log(resp)
const reader = resp.body!.getReader()
const decoder = new TextDecoder()
@ -1922,8 +1910,6 @@ const send = async (body) => {
while (!done) {
if (stopStreamMsg) {
//
// reader.cancel();
controller.abort()
stopStreamMsg = false
}