fix: Application embed (#3462)
This commit is contained in:
parent
ce17833b0a
commit
66699ef497
@ -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参数
|
||||||
|
|||||||
@ -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 + '/')
|
||||||
|
|||||||
@ -10,6 +10,7 @@
|
|||||||
;((prefix) => {
|
;((prefix) => {
|
||||||
window.MaxKB = {
|
window.MaxKB = {
|
||||||
prefix: '/admin',
|
prefix: '/admin',
|
||||||
|
chatPrefix: '/chat',
|
||||||
}
|
}
|
||||||
})()
|
})()
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
1
ui/env.d.ts
vendored
1
ui/env.d.ts
vendored
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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() {
|
||||||
|
|||||||
@ -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
|
||||||
|
if (this.application.custom_theme) {
|
||||||
this.application['custom_theme']['theme_color'] =
|
this.application['custom_theme']['theme_color'] =
|
||||||
ok.data?.custom_theme.theme_color || '#3370FF'
|
ok.data?.custom_theme?.theme_color || '#3370FF'
|
||||||
|
} else {
|
||||||
|
this.application.custom_theme = {
|
||||||
|
theme_color: ok.data?.custom_theme?.theme_color || '#3370FF',
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
isAuthentication() {
|
isAuthentication() {
|
||||||
|
|||||||
@ -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>
|
||||||
`
|
`
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user