Skip to content

Commit 66699ef

Browse files
authored
fix: Application embed (#3462)
1 parent ce17833 commit 66699ef

File tree

7 files changed

+19
-9
lines changed

7 files changed

+19
-9
lines changed

apps/chat/serializers/chat_embed_serializers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from application.models import ApplicationAccessToken
1919
from common.database_model_manage.database_model_manage import DatabaseModelManage
2020
from maxkb.conf import PROJECT_DIR
21+
from maxkb.const import CONFIG
2122

2223

2324
class ChatEmbedSerializer(serializers.Serializer):
@@ -38,7 +39,7 @@ def get_embed(self, with_valid=True, params=None):
3839
access_token=self.data.get('token')).first()
3940
is_draggable = 'false'
4041
show_guide = 'true'
41-
float_icon = f"{self.data.get('protocol')}://{self.data.get('host')}/ui/MaxKB.gif"
42+
float_icon = f"{self.data.get('protocol')}://{self.data.get('host')}{CONFIG.get_chat_path()}/MaxKB.gif"
4243
is_license_valid = DatabaseModelManage.get_model('license_is_valid')
4344
X_PACK_LICENSE_IS_VALID = is_license_valid if is_license_valid is not None else False
4445
# 获取接入的query参数

apps/maxkb/urls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ def page_not_found(request, exception):
130130
if not os.path.exists(index_path):
131131
return HttpResponse("页面不存在", status=404)
132132
content = get_index_html(index_path)
133-
content = content.replace("prefix: '/admin'", f"prefix: '{CONFIG.get_admin_path()}'")
133+
content = content.replace("prefix: '/admin'", f"prefix: '{CONFIG.get_admin_path()}'").replace(
134+
"chatPrefix: '/chat'", f"prefix: '{CONFIG.get_chat_path()}'")
134135
return HttpResponse(content, status=200)
135136
else:
136137
return HttpResponseRedirect(admin_ui_prefix + '/')

ui/admin.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
;((prefix) => {
1111
window.MaxKB = {
1212
prefix: '/admin',
13+
chatPrefix: '/chat',
1314
}
1415
})()
1516
</script>

ui/env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ interface Window {
44
sendMessage: ?((message: string, other_params_data: any) => void)
55
MaxKB: {
66
prefix: string
7+
chatPrefix: string
78
}
89
}

ui/src/stores/modules/application.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { getBrowserLang } from '@/locales/index'
66
import useUserStore from './user'
77
const useApplicationStore = defineStore('application', {
88
state: () => ({
9-
location: `${window.location.origin}/${window.MaxKB.prefix}/chat/`,
9+
location: `${window.location.origin}${window.MaxKB.chatPrefix}/`,
1010
}),
1111
actions: {
1212
async asyncGetAllApplication() {

ui/src/stores/modules/chat-user.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,14 @@ const useChatUserStore = defineStore('chat-user', {
3838
applicationProfile() {
3939
return ChatAPI.applicationProfile().then((ok) => {
4040
this.application = ok.data
41-
this.application['custom_theme']['theme_color'] =
42-
ok.data?.custom_theme.theme_color || '#3370FF'
41+
if (this.application.custom_theme) {
42+
this.application['custom_theme']['theme_color'] =
43+
ok.data?.custom_theme?.theme_color || '#3370FF'
44+
} else {
45+
this.application.custom_theme = {
46+
theme_color: ok.data?.custom_theme?.theme_color || '#3370FF',
47+
}
48+
}
4349
})
4450
},
4551
isAuthentication() {

ui/src/views/application-overview/component/EmbedDialog.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const { application } = useStore()
8989
9090
const props = defineProps({
9191
data: Object,
92-
apiInputParams: String
92+
apiInputParams: String,
9393
})
9494
9595
const emit = defineEmits(['addData'])
@@ -104,7 +104,7 @@ const source3 = ref('')
104104
const urlParams1 = computed(() => (props.apiInputParams ? '?' + props.apiInputParams : ''))
105105
const urlParams2 = computed(() => (props.apiInputParams ? '&' + props.apiInputParams : ''))
106106
const urlParams3 = computed(() =>
107-
props.apiInputParams ? '?mode=mobile&' + props.apiInputParams : '?mode=mobile'
107+
props.apiInputParams ? '?mode=mobile&' + props.apiInputParams : '?mode=mobile',
108108
)
109109
watch(dialogVisible, (bool) => {
110110
if (!bool) {
@@ -126,9 +126,9 @@ allow="microphone">
126126
source2.value = `<script
127127
async
128128
defer
129-
src="${window.location.origin}/api/application/embed?protocol=${window.location.protocol.replace(
129+
src="${application.location}api/embed?protocol=${window.location.protocol.replace(
130130
':',
131-
''
131+
'',
132132
)}&host=${window.location.host}&token=${val}${urlParams2.value}">
133133
<\/script>
134134
`

0 commit comments

Comments
 (0)