|
1 | 1 | <template> |
2 | 2 | <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 | + /> |
4 | 10 | </div> |
5 | 11 | </template> |
6 | 12 | <script setup lang="ts"> |
7 | 13 | import ChatComponent from '@/views/chat/index.vue' |
8 | | -import { onBeforeMount, onBeforeUnmount, ref } from 'vue' |
| 14 | +import { nextTick, onBeforeMount, onBeforeUnmount, reactive, ref } from 'vue' |
9 | 15 | import { useRoute } from 'vue-router' |
10 | 16 | import { assistantApi } from '@/api/assistant' |
11 | 17 | import { useAssistantStore } from '@/stores/assistant' |
| 18 | +import { useI18n } from 'vue-i18n' |
| 19 | +import { request } from '@/utils/request' |
| 20 | +import { setCurrentColor } from '@/utils/utils' |
12 | 21 |
|
| 22 | +const { t } = useI18n() |
13 | 23 | const chatRef = ref() |
14 | 24 | const assistantStore = useAssistantStore() |
15 | 25 | const route = useRoute() |
16 | 26 | 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/' |
18 | 37 | const validator = ref({ |
19 | 38 | id: '', |
20 | 39 | valid: false, |
@@ -73,6 +92,11 @@ const registerReady = (assistantId: any) => { |
73 | 92 | window.parent.postMessage(readyData, '*') |
74 | 93 | } |
75 | 94 |
|
| 95 | +const setPageCustomColor = (val: any) => { |
| 96 | + const ele = document.querySelector('.sqlbot--embedded-page') as HTMLElement |
| 97 | + setCurrentColor(val, ele) |
| 98 | +} |
| 99 | +
|
76 | 100 | onBeforeMount(async () => { |
77 | 101 | const assistantId = route.query.id |
78 | 102 | if (!assistantId) { |
@@ -111,6 +135,25 @@ onBeforeMount(async () => { |
111 | 135 | loading.value = false |
112 | 136 |
|
113 | 137 | 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 | + }) |
114 | 157 | }) |
115 | 158 |
|
116 | 159 | onBeforeUnmount(() => { |
|
0 commit comments