From 84c459dd776355c86be057be4891397d378b3b70 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Mon, 24 Nov 2025 16:07:42 +0800 Subject: [PATCH] feat(chat): add standalone chat component and integrate with config page for testing configurations --- dashboard/src/components/chat/ChatInput.vue | 5 +- .../src/components/chat/ConfigSelector.vue | 6 +- .../src/components/chat/StandaloneChat.vue | 305 ++++++++++++++++++ dashboard/src/views/ConfigPage.vue | 87 ++++- 4 files changed, 399 insertions(+), 4 deletions(-) create mode 100644 dashboard/src/components/chat/StandaloneChat.vue diff --git a/dashboard/src/components/chat/ChatInput.vue b/dashboard/src/components/chat/ChatInput.vue index cad1b720..79ce2765 100644 --- a/dashboard/src/components/chat/ChatInput.vue +++ b/dashboard/src/components/chat/ChatInput.vue @@ -15,6 +15,7 @@ :session-id="sessionId || null" :platform-id="sessionPlatformId" :is-group="sessionIsGroup" + :initial-config-id="props.configId" @config-changed="handleConfigChange" /> @@ -79,11 +80,13 @@ interface Props { isRecording: boolean; sessionId?: string | null; currentSession?: Session | null; + configId?: string | null; } const props = withDefaults(defineProps(), { sessionId: null, - currentSession: null + currentSession: null, + configId: null }); const emit = defineEmits<{ diff --git a/dashboard/src/components/chat/ConfigSelector.vue b/dashboard/src/components/chat/ConfigSelector.vue index 85b92d5e..9cb5eeaa 100644 --- a/dashboard/src/components/chat/ConfigSelector.vue +++ b/dashboard/src/components/chat/ConfigSelector.vue @@ -90,10 +90,12 @@ const props = withDefaults(defineProps<{ sessionId?: string | null; platformId?: string; isGroup?: boolean; + initialConfigId?: string | null; }>(), { sessionId: null, platformId: 'webchat', - isGroup: false + isGroup: false, + initialConfigId: null }); const emit = defineEmits<{ 'config-changed': [ConfigChangedPayload] }>(); @@ -291,7 +293,7 @@ watch( onMounted(async () => { await fetchConfigList(); - const stored = localStorage.getItem(STORAGE_KEY) || 'default'; + const stored = props.initialConfigId || localStorage.getItem(STORAGE_KEY) || 'default'; selectedConfigId.value = stored; await setSelection(stored); await syncSelectionForSession(); diff --git a/dashboard/src/components/chat/StandaloneChat.vue b/dashboard/src/components/chat/StandaloneChat.vue new file mode 100644 index 00000000..6e66c858 --- /dev/null +++ b/dashboard/src/components/chat/StandaloneChat.vue @@ -0,0 +1,305 @@ + + + + + + + + + + Hello, I'm + AstrBot ⭐ + + + 测试配置: {{ configId || 'default' }} + + + + + + + + + + + + + + + {{ t('core.common.imagePreview') }} + + + + + + + + + + + + diff --git a/dashboard/src/views/ConfigPage.vue b/dashboard/src/views/ConfigPage.vue index 133c5eeb..d052e9c5 100644 --- a/dashboard/src/views/ConfigPage.vue +++ b/dashboard/src/views/ConfigPage.vue @@ -45,6 +45,15 @@ @click="configToString(); codeEditorDialog = true"> + + + + + + + @@ -135,6 +144,34 @@ + + + + + + + 测试配置 + + {{ selectedConfigInfo.name }} ({{ testConfigId }}) + + + + mdi-close + + + + + + + + @@ -142,6 +179,7 @@ import axios from 'axios'; import AstrBotCoreConfigWrapper from '@/components/config/AstrBotCoreConfigWrapper.vue'; import WaitingForRestart from '@/components/shared/WaitingForRestart.vue'; +import StandaloneChat from '@/components/chat/StandaloneChat.vue'; import { VueMonacoEditor } from '@guolao/vue-monaco-editor' import { useI18n, useModuleI18n } from '@/i18n/composables'; @@ -150,7 +188,8 @@ export default { components: { AstrBotCoreConfigWrapper, VueMonacoEditor, - WaitingForRestart + WaitingForRestart, + StandaloneChat }, props: { initialConfigId: { @@ -238,6 +277,10 @@ export default { name: '', }, editingConfigId: null, + + // 测试聊天 + testChatDrawer: false, + testConfigId: null, } }, mounted() { @@ -506,6 +549,20 @@ export default { this.getConfigInfoList("default"); } } + }, + openTestChat() { + if (!this.selectedConfigID) { + this.save_message = "请先选择一个配置文件"; + this.save_message_snack = true; + this.save_message_success = "warning"; + return; + } + this.testConfigId = this.selectedConfigID; + this.testChatDrawer = true; + }, + closeTestChat() { + this.testChatDrawer = false; + this.testConfigId = null; } }, } @@ -565,4 +622,32 @@ export default { width: 100%; } } + +/* 测试聊天抽屉样式 */ +.test-chat-overlay { + align-items: stretch; + justify-content: flex-end; +} + +.test-chat-card { + width: clamp(320px, 50vw, 720px); + height: calc(100vh - 32px); + display: flex; + flex-direction: column; + margin: 16px; +} + +.test-chat-header { + display: flex; + align-items: center; + justify-content: space-between; + padding: 16px 20px 12px 20px; +} + +.test-chat-content { + flex: 1; + overflow: hidden; + padding: 0; + border-radius: 0 0 16px 16px; +} \ No newline at end of file
+ 测试配置: {{ configId || 'default' }} +