Skip to content

Commit a9a9e7c

Browse files
committed
Merge branch 'main' of https://github.com/dataease/SQLBot
2 parents 0af80c2 + 814dbc3 commit a9a9e7c

File tree

3 files changed

+56
-29
lines changed

3 files changed

+56
-29
lines changed

frontend/src/embedded.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

frontend/src/utils/request.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import axios, {
1111
import { useCache } from '@/utils/useCache'
1212
import { getLocale } from './utils'
1313
import { useAssistantStore } from '@/stores/assistant'
14-
import { i18n } from '@/i18n'
15-
const t = i18n.global.t
14+
// import { i18n } from '@/i18n'
15+
// const t = i18n.global.t
1616
const assistantStore = useAssistantStore()
1717
const { wsCache } = useCache()
1818
// Response data structure
@@ -65,10 +65,10 @@ class HttpService {
6565
this.setupInterceptors()
6666
}
6767

68-
private cancelCurrentRequest(message: string) {
68+
/* private cancelCurrentRequest(message: string) {
6969
this.cancelTokenSource.cancel(message)
7070
this.cancelTokenSource = axios.CancelToken.source()
71-
}
71+
} */
7272

7373
private setupInterceptors() {
7474
// Request interceptor
@@ -112,15 +112,15 @@ class HttpService {
112112
return config
113113
}
114114

115-
try {
115+
/* try {
116116
const request_key = LicenseGenerator.generate()
117117
config.headers['X-SQLBOT-KEY'] = request_key
118118
} catch (e: any) {
119119
if (e?.message?.includes('offline')) {
120120
this.cancelCurrentRequest('license-key error detected')
121121
showLicenseKeyError()
122122
}
123-
}
123+
} */
124124

125125
// Request logging
126126
// console.log(`[Request] ${config.method?.toUpperCase()} ${config.url}`)
@@ -293,15 +293,15 @@ class HttpService {
293293
}
294294
}
295295

296-
try {
296+
/* try {
297297
const request_key = LicenseGenerator.generate()
298298
heads['X-SQLBOT-KEY'] = request_key
299299
} catch (e: any) {
300300
if (e?.message?.includes('offline')) {
301301
controller?.abort('license-key error detected')
302302
showLicenseKeyError()
303303
}
304-
}
304+
} */
305305

306306
const real_url = import.meta.env.VITE_API_BASE_URL
307307
return fetch(real_url + url, {
@@ -422,7 +422,7 @@ class HttpService {
422422
export const request = new HttpService({
423423
baseURL: import.meta.env.VITE_API_BASE_URL,
424424
})
425-
425+
/*
426426
const showLicenseKeyError = (msg?: string) => {
427427
ElMessageBox.confirm(t('license.error_tips'), {
428428
confirmButtonType: 'primary',
@@ -438,3 +438,4 @@ const showLicenseKeyError = (msg?: string) => {
438438
},
439439
})
440440
}
441+
*/

frontend/src/views/embedded/page.vue

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,39 @@
11
<template>
22
<div class="sqlbot--embedded-page">
3-
<chat-component v-if="!loading" ref="chatRef" />
3+
<chat-component
4+
v-if="!loading"
5+
ref="chatRef"
6+
:welcome="customSet.welcome"
7+
:welcome-desc="customSet.welcome_desc"
8+
:logo-assistant="logo"
9+
/>
410
</div>
511
</template>
612
<script setup lang="ts">
713
import ChatComponent from '@/views/chat/index.vue'
8-
import { onBeforeMount, onBeforeUnmount, ref } from 'vue'
14+
import { nextTick, onBeforeMount, onBeforeUnmount, reactive, ref } from 'vue'
915
import { useRoute } from 'vue-router'
1016
import { assistantApi } from '@/api/assistant'
1117
import { useAssistantStore } from '@/stores/assistant'
18+
import { useI18n } from 'vue-i18n'
19+
import { request } from '@/utils/request'
20+
import { setCurrentColor } from '@/utils/utils'
1221
22+
const { t } = useI18n()
1323
const chatRef = ref()
1424
const assistantStore = useAssistantStore()
1525
const route = useRoute()
1626
const assistantName = ref('')
17-
27+
const customSet = reactive({
28+
name: '',
29+
welcome: t('embedded.i_am_sqlbot'),
30+
welcome_desc: t('embedded.data_analysis_now'),
31+
theme: '#1CBA90',
32+
header_font_color: '#1F2329',
33+
}) as { [key: string]: any }
34+
const logo = ref()
35+
const basePath = import.meta.env.VITE_API_BASE_URL
36+
const baseUrl = basePath + '/system/assistant/picture/'
1837
const validator = ref({
1938
id: '',
2039
valid: false,
@@ -73,6 +92,11 @@ const registerReady = (assistantId: any) => {
7392
window.parent.postMessage(readyData, '*')
7493
}
7594
95+
const setPageCustomColor = (val: any) => {
96+
const ele = document.querySelector('.sqlbot--embedded-page') as HTMLElement
97+
setCurrentColor(val, ele)
98+
}
99+
76100
onBeforeMount(async () => {
77101
const assistantId = route.query.id
78102
if (!assistantId) {
@@ -111,6 +135,25 @@ onBeforeMount(async () => {
111135
loading.value = false
112136
113137
registerReady(assistantId)
138+
139+
request.get(`/system/assistant/${assistantId}`).then((res) => {
140+
if (res?.configuration) {
141+
const rawData = JSON.parse(res?.configuration)
142+
if (rawData.logo) {
143+
logo.value = baseUrl + rawData.logo
144+
}
145+
146+
for (const key in customSet) {
147+
if (Object.prototype.hasOwnProperty.call(customSet, key) && rawData[key]) {
148+
customSet[key] = rawData[key]
149+
}
150+
}
151+
152+
nextTick(() => {
153+
setPageCustomColor(customSet.theme)
154+
})
155+
}
156+
})
114157
})
115158
116159
onBeforeUnmount(() => {

0 commit comments

Comments
 (0)