2020 </div >
2121 <div class =" sqlbot-chat-container" >
2222 <chat-component
23- v-if =" !loading && tokenReady "
23+ v-if =" !loading"
2424 ref =" chatRef"
2525 :welcome =" customSet.welcome"
2626 :welcome-desc =" customSet.welcome_desc"
@@ -42,7 +42,6 @@ import {
4242 watch ,
4343} from ' vue'
4444import ChatComponent from ' @/views/chat/index.vue'
45- import { request } from ' @/utils/request'
4645import LOGO from ' @/assets/svg/logo-custom_small.svg'
4746import icon_new_chat_outlined from ' @/assets/svg/icon_new_chat_outlined.svg'
4847import { useAppearanceStoreWithOut } from ' @/stores/appearance'
@@ -80,11 +79,10 @@ const openHistory = () => {
8079}) */
8180const appName = ref (' ' )
8281const loading = ref (true )
83- const tokenReady = ref (false )
8482const eventName = ' sqlbot_assistant_event'
8583
86- let resolveTokenReady: (() => void ) | null = null
87- const tokenReadyPromise = new Promise <void >((resolve ) => {
84+ let resolveTokenReady: ((data : any ) => any ) | null = null
85+ const tokenReadyPromise = new Promise <any >((resolve ) => {
8886 resolveTokenReady = resolve
8987})
9088const communicationCb = async (event : any ) => {
@@ -94,8 +92,8 @@ const communicationCb = async (event: any) => {
9492 }
9593 if (event .data [' sqlbot_embedded_token' ]) {
9694 assistantStore .setToken (event .data [' sqlbot_embedded_token' ])
97- resolveTokenReady ?.()
98- tokenReady . value = true
95+ const originData = event . data [ ' sqlbot_origin_data ' ]
96+ resolveTokenReady ?.( originData )
9997 }
10098 if (event .data ?.busi == ' certificate' ) {
10199 const certificate = event .data [' certificate' ]
@@ -220,8 +218,6 @@ onBeforeMount(async () => {
220218 validator.value = await assistantApi.validate(param)
221219 assistantStore.setToken(validator.value.token) */
222220 assistantStore .setAssistant (true )
223- loading .value = false
224-
225221 window .addEventListener (' message' , communicationCb )
226222 const readyData = {
227223 eventName: ' sqlbot_assistant_event' ,
@@ -231,46 +227,44 @@ onBeforeMount(async () => {
231227 }
232228 window .parent .postMessage (readyData , ' *' )
233229
234- await tokenReadyPromise
235-
236- request .get (` /system/assistant/${assistantId } ` ).then ((res ) => {
237- if (res .name ) {
238- appName .value = res .name
230+ const res = await tokenReadyPromise
231+ loading .value = false
232+ if (res ?.name ) {
233+ appName .value = res .name
234+ }
235+ if (res ?.configuration ) {
236+ const rawData = JSON .parse (res ?.configuration )
237+ assistantStore .setAutoDs (rawData ?.auto_ds )
238+ if (rawData .logo ) {
239+ logo .value = baseUrl + rawData .logo
239240 }
240- if (res ?.configuration ) {
241- const rawData = JSON .parse (res ?.configuration )
242- assistantStore .setAutoDs (rawData ?.auto_ds )
243- if (rawData .logo ) {
244- logo .value = baseUrl + rawData .logo
245- }
246241
247- for (const key in customSet ) {
248- if (
249- Object .prototype .hasOwnProperty .call (customSet , key ) &&
250- ! [null , undefined ].includes (rawData [key ])
251- ) {
252- customSet [key ] = rawData [key ]
253- configuredKeys .add (key )
254- }
255- }
256-
257- if (! rawData .theme ) {
258- const { customColor, themeColor } = appearanceStore
259- const currentColor =
260- themeColor === ' custom' && customColor
261- ? customColor
262- : themeColor === ' blue'
263- ? ' #3370ff'
264- : ' #1CBA90'
265- customSet .theme = currentColor || customSet .theme
242+ for (const key in customSet ) {
243+ if (
244+ Object .prototype .hasOwnProperty .call (customSet , key ) &&
245+ ! [null , undefined ].includes (rawData [key ])
246+ ) {
247+ customSet [key ] = rawData [key ]
248+ configuredKeys .add (key )
266249 }
250+ }
267251
268- nextTick (() => {
269- setPageCustomColor (customSet .theme )
270- setPageHeaderFontColor (customSet .header_font_color )
271- })
252+ if (! rawData .theme ) {
253+ const { customColor, themeColor } = appearanceStore
254+ const currentColor =
255+ themeColor === ' custom' && customColor
256+ ? customColor
257+ : themeColor === ' blue'
258+ ? ' #3370ff'
259+ : ' #1CBA90'
260+ customSet .theme = currentColor || customSet .theme
272261 }
273- })
262+
263+ nextTick (() => {
264+ setPageCustomColor (customSet .theme )
265+ setPageHeaderFontColor (customSet .header_font_color )
266+ })
267+ }
274268})
275269
276270onBeforeUnmount (() => {
0 commit comments