3131 </div >
3232</template >
3333<script setup lang="ts">
34- import { onBeforeMount , nextTick , onBeforeUnmount , ref , onMounted , reactive , computed } from ' vue'
34+ import {
35+ onBeforeMount ,
36+ nextTick ,
37+ onBeforeUnmount ,
38+ ref ,
39+ onMounted ,
40+ reactive ,
41+ computed ,
42+ watch ,
43+ } from ' vue'
3544import ChatComponent from ' @/views/chat/index.vue'
3645import { request } from ' @/utils/request'
3746import LOGO from ' @/assets/svg/logo-custom_small.svg'
@@ -42,6 +51,9 @@ import { assistantApi } from '@/api/assistant'
4251import { useAssistantStore } from ' @/stores/assistant'
4352import { setCurrentColor } from ' @/utils/utils'
4453import { useI18n } from ' vue-i18n'
54+ import { i18n } from ' @/i18n'
55+ import { useUserStore } from ' @/stores/user'
56+ const userStore = useUserStore ()
4557
4658const { t } = useI18n ()
4759const assistantStore = useAssistantStore ()
@@ -92,6 +104,9 @@ const communicationCb = async (event: any) => {
92104 if (event .data ?.busi == ' createConversation' ) {
93105 createChat ()
94106 }
107+ if (event .data ?.busi == ' setLang' ) {
108+ userStore .setLanguage (event .data .lang )
109+ }
95110 }
96111}
97112const setFormatOnline = (text ? : any ) => {
@@ -128,6 +143,24 @@ const customSet = reactive({
128143 theme: ' #1CBA90' ,
129144 header_font_color: ' #1F2329' ,
130145}) as { [key : string ]: any }
146+
147+ // 记录哪些字段被服务端 API 配置覆盖过,避免被 locale watcher 覆盖
148+ const configuredKeys = new Set <string >()
149+
150+ // 监听 locale 变化,动态更新未被子定义覆盖的翻译字段
151+ watch (
152+ () => i18n .global .locale .value ,
153+ () => {
154+ if (! configuredKeys .has (' welcome' )) {
155+ customSet .welcome = t (' embedded.i_am_sqlbot' )
156+ }
157+ if (! configuredKeys .has (' welcome_desc' )) {
158+ customSet .welcome_desc = t (' embedded.data_analysis_now' )
159+ }
160+ },
161+ { immediate: true }
162+ )
163+
131164const logo = ref ()
132165const basePath = import .meta .env .VITE_API_BASE_URL
133166const baseUrl = basePath + ' /system/assistant/picture/'
@@ -140,7 +173,14 @@ const setPageHeaderFontColor = (val: any) => {
140173 const ele = document .querySelector (' body' ) as HTMLElement
141174 ele .style .setProperty (' --ed-text-color-primary' , val )
142175}
176+ const setParamLanguage = () => {
177+ const lang = route .query .lang
178+ if (lang ) {
179+ userStore .setLanguage (lang as string )
180+ }
181+ }
143182onBeforeMount (async () => {
183+ setParamLanguage ()
144184 const assistantId = route .query .id
145185 if (! assistantId ) {
146186 ElMessage .error (' Miss assistant id, please check assistant url' )
@@ -197,6 +237,7 @@ onBeforeMount(async () => {
197237 ! [null , undefined ].includes (rawData [key ])
198238 ) {
199239 customSet [key ] = rawData [key ]
240+ configuredKeys .add (key )
200241 }
201242 }
202243
0 commit comments