Skip to content

Commit b5a7159

Browse files
perf: Page Embedding Logic Optimization
1 parent 49288a3 commit b5a7159

File tree

3 files changed

+41
-12
lines changed

3 files changed

+41
-12
lines changed

frontend/src/stores/assistant.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ interface AssistantState {
1919
type: number
2020
certificate: string
2121
online: boolean
22+
pageEmbedded?: boolean
2223
requestPromiseMap: Map<string, PendingRequest>
2324
}
2425

@@ -32,6 +33,7 @@ export const AssistantStore = defineStore('assistant', {
3233
type: 0,
3334
certificate: '',
3435
online: false,
36+
pageEmbedded: false,
3537
requestPromiseMap: new Map<string, PendingRequest>(),
3638
}
3739
},
@@ -57,13 +59,16 @@ export const AssistantStore = defineStore('assistant', {
5759
getOnline(): boolean {
5860
return this.online
5961
},
62+
getPageEmbedded(): boolean {
63+
return this.pageEmbedded || false
64+
},
6065
getEmbedded(): boolean {
6166
return this.assistant && this.type === 4
6267
},
6368
},
6469
actions: {
6570
refreshCertificate<T>() {
66-
const timeout = 5000
71+
const timeout = 30000
6772
return new Promise((resolve, reject) => {
6873
const timeoutId = setTimeout(() => {
6974
this.requestPromiseMap.delete(this.id)
@@ -82,7 +87,7 @@ export const AssistantStore = defineStore('assistant', {
8287
},
8388
})
8489
const readyData = {
85-
eventName: 'sqlbot_assistant_event',
90+
eventName: this.pageEmbedded ? 'sqlbot_embedded_event' : 'sqlbot_assistant_event',
8691
busi: 'ready',
8792
ready: true,
8893
messageId: this.id,
@@ -119,6 +124,9 @@ export const AssistantStore = defineStore('assistant', {
119124
wsCache.set(flagKey, flag)
120125
}
121126
},
127+
setPageEmbedded(embedded?: boolean) {
128+
this.pageEmbedded = !!embedded
129+
},
122130
setOnline(online: boolean) {
123131
this.online = !!online
124132
},

frontend/src/views/chat/index.vue

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<template>
22
<el-container class="chat-container no-padding">
3-
<el-aside v-if="isCompletePage && chatListSideBarShow" class="chat-container-left">
3+
<el-aside
4+
v-if="(isCompletePage || pageEmbedded) && chatListSideBarShow"
5+
class="chat-container-left"
6+
>
47
<ChatListContainer
58
v-model:chat-list="chatList"
69
v-model:current-chat-id="currentChatId"
@@ -16,9 +19,9 @@
1619
/>
1720
</el-aside>
1821
<div
19-
v-if="!isCompletePage || !chatListSideBarShow"
22+
v-if="(!isCompletePage && !pageEmbedded) || !chatListSideBarShow"
2023
class="hidden-sidebar-btn"
21-
:class="{ 'assistant-popover-sidebar': !isCompletePage }"
24+
:class="{ 'assistant-popover-sidebar': !isCompletePage && !pageEmbedded }"
2225
>
2326
<el-popover
2427
:width="280"
@@ -86,8 +89,8 @@
8689
<el-main
8790
class="chat-record-list"
8891
:class="{
89-
'hide-sidebar': isCompletePage && !chatListSideBarShow,
90-
'assistant-chat-main': !isCompletePage,
92+
'hide-sidebar': (isCompletePage || pageEmbedded) && !chatListSideBarShow,
93+
'assistant-chat-main': !isCompletePage && !pageEmbedded,
9194
}"
9295
>
9396
<div v-if="computedMessages.length == 0 && !loading" class="welcome-content-block">
@@ -392,6 +395,7 @@ const props = defineProps<{
392395
welcomeDesc?: string
393396
logoAssistant?: string
394397
welcome?: string
398+
pageEmbedded?: boolean
395399
}>()
396400
const floatPopoverRef = ref()
397401
const floatPopoverVisible = ref(false)
@@ -588,7 +592,7 @@ function onChatRenamed(chat: Chat) {
588592
589593
const chatListSideBarShow = ref<boolean>(true)
590594
function hideSideBar() {
591-
if (!isCompletePage.value) {
595+
if (!isCompletePage.value && !props.pageEmbedded) {
592596
floatPopoverVisible.value = false
593597
return
594598
}
@@ -894,7 +898,7 @@ const showFloatPopover = () => {
894898
}
895899
}
896900
const assistantPrepareInit = () => {
897-
if (isCompletePage.value) {
901+
if (isCompletePage.value || props.pageEmbedded) {
898902
return
899903
}
900904
Object.assign(defaultFloatPopoverStyle.value, {

frontend/src/views/embedded/page.vue

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<template>
2-
<div class="sqlbot--embedded-page">
2+
<div :class="dynamicType === 4 ? 'sqlbot--embedded-page' : 'sqlbot-embedded-assistant-page'">
33
<chat-component
44
v-if="!loading"
55
ref="chatRef"
66
:welcome="customSet.welcome"
77
:welcome-desc="customSet.welcome_desc"
88
:logo-assistant="logo"
9+
:page-embedded="true"
910
/>
1011
</div>
1112
</template>
@@ -22,8 +23,10 @@ import { setCurrentColor } from '@/utils/utils'
2223
const { t } = useI18n()
2324
const chatRef = ref()
2425
const assistantStore = useAssistantStore()
26+
assistantStore.setPageEmbedded(true)
2527
const route = useRoute()
2628
const assistantName = ref('')
29+
const dynamicType = ref(0)
2730
const customSet = reactive({
2831
name: '',
2932
welcome: t('embedded.i_am_sqlbot'),
@@ -50,7 +53,7 @@ const communicationCb = async (event: any) => {
5053
if (event.data?.busi == 'certificate') {
5154
const type = parseInt(event.data['type'])
5255
const certificate = event.data['certificate']
53-
assistantStore.setType(type || 3)
56+
assistantStore.setType(type)
5457
if (type === 4) {
5558
assistantStore.setToken(certificate)
5659
assistantStore.setAssistant(true)
@@ -93,7 +96,9 @@ const registerReady = (assistantId: any) => {
9396
}
9497
9598
const setPageCustomColor = (val: any) => {
96-
const ele = document.querySelector('.sqlbot--embedded-page') as HTMLElement
99+
const selector =
100+
dynamicType.value === 4 ? '.sqlbot--embedded-page' : '.sqlbot-embedded-assistant-page'
101+
const ele = document.querySelector(selector) as HTMLElement
97102
setCurrentColor(val, ele)
98103
}
99104
@@ -109,6 +114,7 @@ onBeforeMount(async () => {
109114
assistantType = parseInt(typeParam.toString())
110115
assistantStore.setType(assistantType)
111116
}
117+
dynamicType.value = assistantType
112118
const online = route.query.online
113119
setFormatOnline(online)
114120
@@ -168,4 +174,15 @@ onBeforeUnmount(() => {
168174
position: relative;
169175
background: #f7f8fa;
170176
}
177+
.sqlbot-embedded-assistant-page {
178+
width: 100%;
179+
height: 100%;
180+
position: absolute;
181+
top: 0;
182+
left: 0;
183+
background: #f7f8fa;
184+
box-sizing: border-box;
185+
overflow: auto;
186+
padding-bottom: 48px;
187+
}
171188
</style>

0 commit comments

Comments
 (0)