fix: Application embed (#3462)

This commit is contained in:
shaohuzhang1 2025-07-03 12:26:20 +08:00 committed by GitHub
parent ce17833b0a
commit 66699ef497
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 19 additions and 9 deletions

View File

@ -18,6 +18,7 @@ from rest_framework import serializers
from application.models import ApplicationAccessToken from application.models import ApplicationAccessToken
from common.database_model_manage.database_model_manage import DatabaseModelManage from common.database_model_manage.database_model_manage import DatabaseModelManage
from maxkb.conf import PROJECT_DIR from maxkb.conf import PROJECT_DIR
from maxkb.const import CONFIG
class ChatEmbedSerializer(serializers.Serializer): class ChatEmbedSerializer(serializers.Serializer):
@ -38,7 +39,7 @@ class ChatEmbedSerializer(serializers.Serializer):
access_token=self.data.get('token')).first() access_token=self.data.get('token')).first()
is_draggable = 'false' is_draggable = 'false'
show_guide = 'true' 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') 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 X_PACK_LICENSE_IS_VALID = is_license_valid if is_license_valid is not None else False
# 获取接入的query参数 # 获取接入的query参数

View File

@ -130,7 +130,8 @@ def page_not_found(request, exception):
if not os.path.exists(index_path): if not os.path.exists(index_path):
return HttpResponse("页面不存在", status=404) return HttpResponse("页面不存在", status=404)
content = get_index_html(index_path) 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) return HttpResponse(content, status=200)
else: else:
return HttpResponseRedirect(admin_ui_prefix + '/') return HttpResponseRedirect(admin_ui_prefix + '/')

View File

@ -10,6 +10,7 @@
;((prefix) => { ;((prefix) => {
window.MaxKB = { window.MaxKB = {
prefix: '/admin', prefix: '/admin',
chatPrefix: '/chat',
} }
})() })()
</script> </script>

1
ui/env.d.ts vendored
View File

@ -4,5 +4,6 @@ interface Window {
sendMessage: ?((message: string, other_params_data: any) => void) sendMessage: ?((message: string, other_params_data: any) => void)
MaxKB: { MaxKB: {
prefix: string prefix: string
chatPrefix: string
} }
} }

View File

@ -6,7 +6,7 @@ import { getBrowserLang } from '@/locales/index'
import useUserStore from './user' import useUserStore from './user'
const useApplicationStore = defineStore('application', { const useApplicationStore = defineStore('application', {
state: () => ({ state: () => ({
location: `${window.location.origin}/${window.MaxKB.prefix}/chat/`, location: `${window.location.origin}${window.MaxKB.chatPrefix}/`,
}), }),
actions: { actions: {
async asyncGetAllApplication() { async asyncGetAllApplication() {

View File

@ -38,8 +38,14 @@ const useChatUserStore = defineStore('chat-user', {
applicationProfile() { applicationProfile() {
return ChatAPI.applicationProfile().then((ok) => { return ChatAPI.applicationProfile().then((ok) => {
this.application = ok.data this.application = ok.data
this.application['custom_theme']['theme_color'] = if (this.application.custom_theme) {
ok.data?.custom_theme.theme_color || '#3370FF' 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() { isAuthentication() {

View File

@ -89,7 +89,7 @@ const { application } = useStore()
const props = defineProps({ const props = defineProps({
data: Object, data: Object,
apiInputParams: String apiInputParams: String,
}) })
const emit = defineEmits(['addData']) const emit = defineEmits(['addData'])
@ -104,7 +104,7 @@ const source3 = ref('')
const urlParams1 = computed(() => (props.apiInputParams ? '?' + props.apiInputParams : '')) const urlParams1 = computed(() => (props.apiInputParams ? '?' + props.apiInputParams : ''))
const urlParams2 = computed(() => (props.apiInputParams ? '&' + props.apiInputParams : '')) const urlParams2 = computed(() => (props.apiInputParams ? '&' + props.apiInputParams : ''))
const urlParams3 = computed(() => const urlParams3 = computed(() =>
props.apiInputParams ? '?mode=mobile&' + props.apiInputParams : '?mode=mobile' props.apiInputParams ? '?mode=mobile&' + props.apiInputParams : '?mode=mobile',
) )
watch(dialogVisible, (bool) => { watch(dialogVisible, (bool) => {
if (!bool) { if (!bool) {
@ -126,9 +126,9 @@ allow="microphone">
source2.value = `<script source2.value = `<script
async async
defer defer
src="${window.location.origin}/api/application/embed?protocol=${window.location.protocol.replace( src="${application.location}api/embed?protocol=${window.location.protocol.replace(
':', ':',
'' '',
)}&host=${window.location.host}&token=${val}${urlParams2.value}"> )}&host=${window.location.host}&token=${val}${urlParams2.value}">
<\/script> <\/script>
` `