perf: Assistant switch online

This commit is contained in:
fit2cloud-chenyw
2025-07-27 00:56:07 +08:00
parent 5502afcae2
commit 115016c262
6 changed files with 122 additions and 7 deletions
+8
View File
@@ -11,6 +11,7 @@ interface AssistantState {
flag: number
type: number
certificate: string
online: boolean
}
export const AssistantStore = defineStore('assistant', {
@@ -21,6 +22,7 @@ export const AssistantStore = defineStore('assistant', {
flag: 0,
type: 0,
certificate: '',
online: false,
}
},
getters: {
@@ -39,6 +41,9 @@ export const AssistantStore = defineStore('assistant', {
getType(): number {
return this.type
},
getOnline(): boolean {
return this.online
},
},
actions: {
setCertificate(certificate: string) {
@@ -61,6 +66,9 @@ export const AssistantStore = defineStore('assistant', {
wsCache.set(flagKey, flag)
}
},
setOnline(online: boolean) {
this.online = !!online
},
async setChat() {
if (!this.assistant) {
return null
+6
View File
@@ -80,6 +80,9 @@ class HttpService {
encodeURIComponent(assistantStore.getCertificate)
)
}
if (!assistantStore.getType) {
config.headers['X-SQLBOT-ASSISTANT-ONLINE'] = assistantStore.getOnline
}
}
const locale = getLocale()
if (locale) {
@@ -261,6 +264,9 @@ class HttpService {
encodeURIComponent(assistantStore.getCertificate)
)
}
if (!assistantStore.getType) {
heads['X-SQLBOT-ASSISTANT-ONLINE'] = assistantStore.getOnline
}
}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
+19 -2
View File
@@ -58,14 +58,31 @@ const communicationCb = async (event: any) => {
const certificate = event.data['certificate']
assistantStore.setType(1)
assistantStore.setCertificate(certificate)
// store certificate to pinia
}
if (event.data?.busi == 'setOnline') {
setFormatOnline(event.data.online)
}
}
}
const setFormatOnline = (text?: any) => {
if (text === null || typeof text === 'undefined') {
assistantStore.setOnline(false)
return
}
if (typeof text === 'boolean') {
assistantStore.setOnline(text)
return
}
if (typeof text === 'string') {
assistantStore.setOnline(text.toLowerCase() === 'true')
return
}
assistantStore.setOnline(false)
}
onBeforeMount(async () => {
const assistantId = route.query.id
const online = route.query.online
console.log(online)
setFormatOnline(online)
const now = Date.now()
assistantStore.setFlag(now)
const param = {