mirror of
https://gh-proxy.org/https://github.com/klinsmaya/SQLBot.git
synced 2026-11-09 09:46:55 +08:00
perf: Assistant switch online
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user