From 66699ef49732aab5c8d82616ad01a7ed26b12244 Mon Sep 17 00:00:00 2001 From: shaohuzhang1 <80892890+shaohuzhang1@users.noreply.github.com> Date: Thu, 3 Jul 2025 12:26:20 +0800 Subject: [PATCH] fix: Application embed (#3462) --- apps/chat/serializers/chat_embed_serializers.py | 3 ++- apps/maxkb/urls.py | 3 ++- ui/admin.html | 1 + ui/env.d.ts | 1 + ui/src/stores/modules/application.ts | 2 +- ui/src/stores/modules/chat-user.ts | 10 ++++++++-- .../application-overview/component/EmbedDialog.vue | 8 ++++---- 7 files changed, 19 insertions(+), 9 deletions(-) diff --git a/apps/chat/serializers/chat_embed_serializers.py b/apps/chat/serializers/chat_embed_serializers.py index 3b35325af..565e8fd89 100644 --- a/apps/chat/serializers/chat_embed_serializers.py +++ b/apps/chat/serializers/chat_embed_serializers.py @@ -18,6 +18,7 @@ from rest_framework import serializers from application.models import ApplicationAccessToken from common.database_model_manage.database_model_manage import DatabaseModelManage from maxkb.conf import PROJECT_DIR +from maxkb.const import CONFIG class ChatEmbedSerializer(serializers.Serializer): @@ -38,7 +39,7 @@ class ChatEmbedSerializer(serializers.Serializer): access_token=self.data.get('token')).first() is_draggable = 'false' show_guide = 'true' - float_icon = f"{self.data.get('protocol')}://{self.data.get('host')}/ui/MaxKB.gif" + float_icon = f"{self.data.get('protocol')}://{self.data.get('host')}{CONFIG.get_chat_path()}/MaxKB.gif" is_license_valid = DatabaseModelManage.get_model('license_is_valid') X_PACK_LICENSE_IS_VALID = is_license_valid if is_license_valid is not None else False # 获取接入的query参数 diff --git a/apps/maxkb/urls.py b/apps/maxkb/urls.py index 6f7d505ec..ec8ae989d 100644 --- a/apps/maxkb/urls.py +++ b/apps/maxkb/urls.py @@ -130,7 +130,8 @@ def page_not_found(request, exception): if not os.path.exists(index_path): return HttpResponse("页面不存在", status=404) content = get_index_html(index_path) - content = content.replace("prefix: '/admin'", f"prefix: '{CONFIG.get_admin_path()}'") + content = content.replace("prefix: '/admin'", f"prefix: '{CONFIG.get_admin_path()}'").replace( + "chatPrefix: '/chat'", f"prefix: '{CONFIG.get_chat_path()}'") return HttpResponse(content, status=200) else: return HttpResponseRedirect(admin_ui_prefix + '/') diff --git a/ui/admin.html b/ui/admin.html index 52b43c40a..4bcf14fea 100644 --- a/ui/admin.html +++ b/ui/admin.html @@ -10,6 +10,7 @@ ;((prefix) => { window.MaxKB = { prefix: '/admin', + chatPrefix: '/chat', } })() diff --git a/ui/env.d.ts b/ui/env.d.ts index 401e8d4fd..97c603abd 100644 --- a/ui/env.d.ts +++ b/ui/env.d.ts @@ -4,5 +4,6 @@ interface Window { sendMessage: ?((message: string, other_params_data: any) => void) MaxKB: { prefix: string + chatPrefix: string } } diff --git a/ui/src/stores/modules/application.ts b/ui/src/stores/modules/application.ts index 702161603..ad5513057 100644 --- a/ui/src/stores/modules/application.ts +++ b/ui/src/stores/modules/application.ts @@ -6,7 +6,7 @@ import { getBrowserLang } from '@/locales/index' import useUserStore from './user' const useApplicationStore = defineStore('application', { state: () => ({ - location: `${window.location.origin}/${window.MaxKB.prefix}/chat/`, + location: `${window.location.origin}${window.MaxKB.chatPrefix}/`, }), actions: { async asyncGetAllApplication() { diff --git a/ui/src/stores/modules/chat-user.ts b/ui/src/stores/modules/chat-user.ts index 81e7f1dd5..4bd0375d3 100644 --- a/ui/src/stores/modules/chat-user.ts +++ b/ui/src/stores/modules/chat-user.ts @@ -38,8 +38,14 @@ const useChatUserStore = defineStore('chat-user', { applicationProfile() { return ChatAPI.applicationProfile().then((ok) => { this.application = ok.data - this.application['custom_theme']['theme_color'] = - ok.data?.custom_theme.theme_color || '#3370FF' + if (this.application.custom_theme) { + this.application['custom_theme']['theme_color'] = + ok.data?.custom_theme?.theme_color || '#3370FF' + } else { + this.application.custom_theme = { + theme_color: ok.data?.custom_theme?.theme_color || '#3370FF', + } + } }) }, isAuthentication() { diff --git a/ui/src/views/application-overview/component/EmbedDialog.vue b/ui/src/views/application-overview/component/EmbedDialog.vue index 65fdce9e5..5368df5c2 100644 --- a/ui/src/views/application-overview/component/EmbedDialog.vue +++ b/ui/src/views/application-overview/component/EmbedDialog.vue @@ -89,7 +89,7 @@ const { application } = useStore() const props = defineProps({ data: Object, - apiInputParams: String + apiInputParams: String, }) const emit = defineEmits(['addData']) @@ -104,7 +104,7 @@ const source3 = ref('') const urlParams1 = computed(() => (props.apiInputParams ? '?' + props.apiInputParams : '')) const urlParams2 = computed(() => (props.apiInputParams ? '&' + props.apiInputParams : '')) const urlParams3 = computed(() => - props.apiInputParams ? '?mode=mobile&' + props.apiInputParams : '?mode=mobile' + props.apiInputParams ? '?mode=mobile&' + props.apiInputParams : '?mode=mobile', ) watch(dialogVisible, (bool) => { if (!bool) { @@ -126,9 +126,9 @@ allow="microphone"> source2.value = `