perf: Optimize embedded page style layout

This commit is contained in:
fit2cloud-chenyw
2025-08-21 12:06:48 +08:00
parent 314b83cbb9
commit 54e2cdf953
8 changed files with 42 additions and 35 deletions
+2 -2
View File
@@ -95,7 +95,7 @@ def get_chat_with_records_with_data(session: SessionDep, chart_id: int, current_
current_assistant: CurrentAssistant) -> ChatInfo:
return get_chat_with_records(session, chart_id, current_user, current_assistant, True)
dynamic_ds_types = [1, 3]
def get_chat_with_records(session: SessionDep, chart_id: int, current_user: CurrentUser,
current_assistant: CurrentAssistant, with_data: bool = False) -> ChatInfo:
chat = session.get(Chat, chart_id)
@@ -104,7 +104,7 @@ def get_chat_with_records(session: SessionDep, chart_id: int, current_user: Curr
chat_info = ChatInfo(**chat.model_dump())
if current_assistant and current_assistant.type == 1:
if current_assistant and current_assistant.type in dynamic_ds_types:
out_ds_instance = AssistantOutDsFactory.get_instance(current_assistant)
ds = out_ds_instance.get_ds(chat.datasource)
else:
+6 -5
View File
@@ -42,6 +42,7 @@ base_message_count_limit = 5
executor = ThreadPoolExecutor(max_workers=200)
dynamic_ds_types = [1, 3]
class LLMService:
ds: CoreDatasource
@@ -79,7 +80,7 @@ class LLMService:
if chat.datasource:
# Get available datasource
# ds = self.session.query(CoreDatasource).filter(CoreDatasource.id == chat.datasource).first()
if current_assistant and current_assistant.type == 1:
if current_assistant and current_assistant.type in dynamic_ds_types:
self.out_ds_instance = AssistantOutDsFactory.get_instance(current_assistant)
ds = self.out_ds_instance.get_ds(chat.datasource)
if not ds:
@@ -355,7 +356,7 @@ class LLMService:
def select_datasource(self):
datasource_msg: List[Union[BaseMessage, dict[str, Any]]] = []
datasource_msg.append(SystemMessage(self.chat_question.datasource_sys_question()))
if self.current_assistant:
if self.current_assistant and self.current_assistant.type != 4:
_ds_list = get_assistant_ds(session=self.session, llm_service=self)
else:
oid: str = self.current_user.oid
@@ -426,7 +427,7 @@ class LLMService:
_datasource = data['id']
_chat = self.session.get(Chat, self.record.chat_id)
_chat.datasource = _datasource
if self.current_assistant and self.current_assistant.type == 1:
if self.current_assistant and self.current_assistant.type in dynamic_ds_types:
_ds = self.out_ds_instance.get_ds(data['id'])
self.ds = _ds
self.chat_question.engine = _ds.type
@@ -851,7 +852,7 @@ class LLMService:
# filter sql
SQLBotLogUtil.info(full_sql_text)
use_dynamic_ds: bool = self.current_assistant and self.current_assistant.type == 1
use_dynamic_ds: bool = self.current_assistant and self.current_assistant.type in dynamic_ds_types
# todo row permission
if (not self.current_assistant and is_normal_user(self.current_user)) or use_dynamic_ds:
@@ -1037,7 +1038,7 @@ class LLMService:
def validate_history_ds(self):
_ds = self.ds
if not self.current_assistant:
if not self.current_assistant or self.current_assistant.type == 4:
try:
current_ds = self.session.get(CoreDatasource, _ds.id)
if not current_ds:
+1 -1
View File
@@ -32,7 +32,7 @@ def get_assistant_user(*, id: int):
def get_assistant_ds(session: Session, llm_service) -> list[dict]:
assistant: AssistantHeader = llm_service.current_assistant
type = assistant.type
if type == 0:
if type == 0 or type == 2:
configuration = assistant.configuration
if configuration:
config: dict[any] = json.loads(configuration)
+3
View File
@@ -57,6 +57,9 @@ export const AssistantStore = defineStore('assistant', {
getOnline(): boolean {
return this.online
},
getEmbedded(): boolean {
return this.assistant && this.type === 4
},
},
actions: {
refreshCertificate<T>() {
@@ -43,7 +43,7 @@ const emits = defineEmits([
])
const assistantStore = useAssistantStore()
const isAssistant = computed(() => assistantStore.getAssistant)
const isCompletePage = computed(() => !assistantStore.getAssistant || assistantStore.getEmbedded)
const search = ref<string>()
@@ -145,7 +145,7 @@ const createNewChat = async () => {
}
async function doCreateNewChat() {
if (isAssistant.value) {
if (!isCompletePage.value) {
return
}
chatCreatorRef.value?.showDs()
@@ -252,7 +252,7 @@ function onChatRenamed(chat: Chat) {
/>
</el-main>
<ChatCreator v-if="!isAssistant" ref="chatCreatorRef" @on-chat-created="onChatCreated" />
<ChatCreator v-if="isCompletePage" ref="chatCreatorRef" @on-chat-created="onChatCreated" />
</el-container>
</template>
+2 -2
View File
@@ -10,7 +10,7 @@ const props = defineProps<{
const { t } = useI18n()
const assistantStore = useAssistantStore()
const isAssistant = computed(() => assistantStore.getAssistant)
const isCompletePage = computed(() => !assistantStore.getAssistant || assistantStore.getEmbedded)
const showBlock = computed(() => {
return props.error && props.error?.trim().length > 0
@@ -54,7 +54,7 @@ function showTraceBack() {
<el-drawer
v-model="show"
:size="isAssistant ? '100%' : '600px'"
:size="!isCompletePage ? '100%' : '600px'"
:title="t('chat.error')"
direction="rtl"
body-class="chart-sql-error-body"
@@ -61,7 +61,7 @@ const dataObject = computed<{
return {}
})
const assistantStore = useAssistantStore()
const isAssistant = computed(() => assistantStore.getAssistant)
const isCompletePage = computed(() => !assistantStore.getAssistant || assistantStore.getEmbedded)
const chartId = computed(() => props.message?.record?.id + (props.enlarge ? '-fullscreen' : ''))
@@ -409,7 +409,7 @@ watch(
<el-tooltip
effect="dark"
:offset="8"
:content="isAssistant ? $t('common.zoom_in') : t('chat.full_screen')"
:content="!isCompletePage ? $t('common.zoom_in') : t('chat.full_screen')"
placement="top"
>
<el-button class="tool-btn" text @click="openFullScreen">
@@ -423,7 +423,7 @@ watch(
<el-tooltip
effect="dark"
:offset="8"
:content="isAssistant ? $t('common.zoom_out') : t('chat.exit_full_screen')"
:content="!isCompletePage ? $t('common.zoom_out') : t('chat.exit_full_screen')"
placement="top"
>
<el-button class="tool-btn" text @click="closeFullScreen">
@@ -473,7 +473,7 @@ watch(
<el-drawer
v-model="sqlShow"
:size="isAssistant ? '100%' : '600px'"
:size="!isCompletePage ? '100%' : '600px'"
:title="t('chat.show_sql')"
direction="rtl"
body-class="chart-sql-drawer-body"
+21 -18
View File
@@ -1,6 +1,6 @@
<template>
<el-container class="chat-container no-padding">
<el-aside v-if="!isAssistant && chatListSideBarShow" class="chat-container-left">
<el-aside v-if="isCompletePage && chatListSideBarShow" class="chat-container-left">
<ChatListContainer
v-model:chat-list="chatList"
v-model:current-chat-id="currentChatId"
@@ -16,9 +16,9 @@
/>
</el-aside>
<div
v-if="isAssistant || !chatListSideBarShow"
v-if="!isCompletePage || !chatListSideBarShow"
class="hidden-sidebar-btn"
:class="{ 'assistant-popover-sidebar': isAssistant }"
:class="{ 'assistant-popover-sidebar': !isCompletePage }"
>
<el-popover
:width="280"
@@ -86,13 +86,13 @@
<el-main
class="chat-record-list"
:class="{
'hide-sidebar': !isAssistant && !chatListSideBarShow,
'assistant-chat-main': isAssistant,
'hide-sidebar': isCompletePage && !chatListSideBarShow,
'assistant-chat-main': !isCompletePage,
}"
>
<div v-if="computedMessages.length == 0 && !loading" class="welcome-content-block">
<div class="welcome-content">
<template v-if="!isAssistant">
<template v-if="isCompletePage">
<div class="greeting">
<el-icon size="32">
<logo_fold />
@@ -111,7 +111,7 @@
</div>
<el-button
v-if="!isAssistant && currentChatId === undefined"
v-if="isCompletePage && currentChatId === undefined"
size="large"
type="primary"
class="greeting-btn"
@@ -132,7 +132,10 @@
<el-scrollbar v-if="computedMessages.length > 0" ref="chatListRef" class="no-horizontal">
<div
class="chat-scroll"
:class="{ 'no-sidebar': !isAssistant && !chatListSideBarShow, pad16: isAssistant }"
:class="{
'no-sidebar': isCompletePage && !chatListSideBarShow,
pad16: !isCompletePage,
}"
>
<template v-for="(message, _index) in computedMessages" :key="_index">
<ChatRow :current-chat="currentChat" :msg="message" :hide-avatar="message.first_chat">
@@ -287,9 +290,9 @@
</div>
</el-scrollbar>
</el-main>
<el-footer v-if="computedMessages.length > 0 || isAssistant" class="chat-footer">
<el-footer v-if="computedMessages.length > 0 || !isCompletePage" class="chat-footer">
<div class="input-wrapper" @click="clickInput">
<div v-if="!isAssistant" class="datasource">
<div v-if="isCompletePage" class="datasource">
<template v-if="currentChat.datasource && currentChat.datasource_name">
{{ t('qa.selected_datasource') }}:
<img
@@ -311,7 +314,7 @@
:disabled="isTyping"
clearable
class="input-area"
:class="isAssistant && 'is-assistant'"
:class="!isCompletePage && 'is-assistant'"
type="textarea"
:autosize="{ minRows: 1, maxRows: 8.583 }"
:placeholder="t('qa.question_placeholder')"
@@ -334,7 +337,7 @@
</el-footer>
</el-container>
<ChatCreator v-if="!isAssistant" ref="chatCreatorRef" @on-chat-created="onChatCreatedQuick" />
<ChatCreator v-if="isCompletePage" ref="chatCreatorRef" @on-chat-created="onChatCreatedQuick" />
<ChatCreator ref="hiddenChatCreatorRef" hidden @on-chat-created="onChatCreatedQuick" />
</el-container>
</template>
@@ -384,7 +387,7 @@ const defaultFloatPopoverStyle = ref({
borderRadius: '6px',
})
const isAssistant = computed(() => assistantStore.getAssistant)
const isCompletePage = computed(() => !assistantStore.getAssistant || assistantStore.getEmbedded)
const { t } = useI18n()
@@ -479,7 +482,7 @@ const createNewChat = async () => {
return
}
goEmpty()
if (isAssistant.value) {
if (!isCompletePage.value) {
currentChat.value = new ChatInfo()
currentChatId.value = undefined
return
@@ -526,7 +529,7 @@ function onChatRenamed(chat: Chat) {
const chatListSideBarShow = ref<boolean>(true)
function hideSideBar() {
if (isAssistant.value) {
if (!isCompletePage.value) {
floatPopoverVisible.value = false
return
}
@@ -598,7 +601,7 @@ function onChatStop() {
}
const assistantPrepareSend = async () => {
if (
isAssistant.value &&
!isCompletePage.value &&
(currentChatId.value == null || typeof currentChatId.value == 'undefined')
) {
const assistantChat = await assistantStore.setChat()
@@ -821,12 +824,12 @@ function stop(func?: (...p: any[]) => void, ...param: any[]) {
}
}
const showFloatPopover = () => {
if (isAssistant.value && !floatPopoverVisible.value) {
if (!isCompletePage.value && !floatPopoverVisible.value) {
floatPopoverVisible.value = true
}
}
const assistantPrepareInit = () => {
if (!isAssistant.value) {
if (isCompletePage.value) {
return
}
Object.assign(defaultFloatPopoverStyle.value, {