This commit is contained in:
dataeaseShu
2025-08-29 13:52:47 +08:00
3 changed files with 56 additions and 29 deletions
-17
View File
@@ -1,17 +0,0 @@
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import './style.less'
import App from './App.vue'
import router from './router'
import { i18n } from './i18n'
import VueDOMPurifyHTML from 'vue-dompurify-html'
// import 'element-plus/dist/index.css'
const app = createApp(App)
const pinia = createPinia()
app.use(pinia)
app.use(router)
app.use(i18n)
app.use(VueDOMPurifyHTML)
app.mount('#app')
+10 -9
View File
@@ -11,8 +11,8 @@ import axios, {
import { useCache } from '@/utils/useCache'
import { getLocale } from './utils'
import { useAssistantStore } from '@/stores/assistant'
import { i18n } from '@/i18n'
const t = i18n.global.t
// import { i18n } from '@/i18n'
// const t = i18n.global.t
const assistantStore = useAssistantStore()
const { wsCache } = useCache()
// Response data structure
@@ -65,10 +65,10 @@ class HttpService {
this.setupInterceptors()
}
private cancelCurrentRequest(message: string) {
/* private cancelCurrentRequest(message: string) {
this.cancelTokenSource.cancel(message)
this.cancelTokenSource = axios.CancelToken.source()
}
} */
private setupInterceptors() {
// Request interceptor
@@ -112,7 +112,7 @@ class HttpService {
return config
}
try {
/* try {
const request_key = LicenseGenerator.generate()
config.headers['X-SQLBOT-KEY'] = request_key
} catch (e: any) {
@@ -120,7 +120,7 @@ class HttpService {
this.cancelCurrentRequest('license-key error detected')
showLicenseKeyError()
}
}
} */
// Request logging
// console.log(`[Request] ${config.method?.toUpperCase()} ${config.url}`)
@@ -293,7 +293,7 @@ class HttpService {
}
}
try {
/* try {
const request_key = LicenseGenerator.generate()
heads['X-SQLBOT-KEY'] = request_key
} catch (e: any) {
@@ -301,7 +301,7 @@ class HttpService {
controller?.abort('license-key error detected')
showLicenseKeyError()
}
}
} */
const real_url = import.meta.env.VITE_API_BASE_URL
return fetch(real_url + url, {
@@ -422,7 +422,7 @@ class HttpService {
export const request = new HttpService({
baseURL: import.meta.env.VITE_API_BASE_URL,
})
/*
const showLicenseKeyError = (msg?: string) => {
ElMessageBox.confirm(t('license.error_tips'), {
confirmButtonType: 'primary',
@@ -438,3 +438,4 @@ const showLicenseKeyError = (msg?: string) => {
},
})
}
*/
+46 -3
View File
@@ -1,20 +1,39 @@
<template>
<div class="sqlbot--embedded-page">
<chat-component v-if="!loading" ref="chatRef" />
<chat-component
v-if="!loading"
ref="chatRef"
:welcome="customSet.welcome"
:welcome-desc="customSet.welcome_desc"
:logo-assistant="logo"
/>
</div>
</template>
<script setup lang="ts">
import ChatComponent from '@/views/chat/index.vue'
import { onBeforeMount, onBeforeUnmount, ref } from 'vue'
import { nextTick, onBeforeMount, onBeforeUnmount, reactive, ref } from 'vue'
import { useRoute } from 'vue-router'
import { assistantApi } from '@/api/assistant'
import { useAssistantStore } from '@/stores/assistant'
import { useI18n } from 'vue-i18n'
import { request } from '@/utils/request'
import { setCurrentColor } from '@/utils/utils'
const { t } = useI18n()
const chatRef = ref()
const assistantStore = useAssistantStore()
const route = useRoute()
const assistantName = ref('')
const customSet = reactive({
name: '',
welcome: t('embedded.i_am_sqlbot'),
welcome_desc: t('embedded.data_analysis_now'),
theme: '#1CBA90',
header_font_color: '#1F2329',
}) as { [key: string]: any }
const logo = ref()
const basePath = import.meta.env.VITE_API_BASE_URL
const baseUrl = basePath + '/system/assistant/picture/'
const validator = ref({
id: '',
valid: false,
@@ -73,6 +92,11 @@ const registerReady = (assistantId: any) => {
window.parent.postMessage(readyData, '*')
}
const setPageCustomColor = (val: any) => {
const ele = document.querySelector('.sqlbot--embedded-page') as HTMLElement
setCurrentColor(val, ele)
}
onBeforeMount(async () => {
const assistantId = route.query.id
if (!assistantId) {
@@ -111,6 +135,25 @@ onBeforeMount(async () => {
loading.value = false
registerReady(assistantId)
request.get(`/system/assistant/${assistantId}`).then((res) => {
if (res?.configuration) {
const rawData = JSON.parse(res?.configuration)
if (rawData.logo) {
logo.value = baseUrl + rawData.logo
}
for (const key in customSet) {
if (Object.prototype.hasOwnProperty.call(customSet, key) && rawData[key]) {
customSet[key] = rawData[key]
}
}
nextTick(() => {
setPageCustomColor(customSet.theme)
})
}
})
})
onBeforeUnmount(() => {