Skip to content

Commit e91e408

Browse files
committed
feat(embedded): Helper embedded display settings
1 parent c15e693 commit e91e408

File tree

3 files changed

+95
-22
lines changed

3 files changed

+95
-22
lines changed

frontend/src/views/chat/index.vue

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,24 @@
9292
>
9393
<div v-if="computedMessages.length == 0 && !loading" class="welcome-content-block">
9494
<div class="welcome-content">
95-
<div class="greeting">
96-
<el-icon size="32">
97-
<logo_fold />
98-
</el-icon>
99-
{{ isAssistant ? t('embedded.i_am_sqlbot') : t('qa.greeting') }}
100-
</div>
101-
<div class="sub">
102-
{{ isAssistant ? t('embedded.predict_data_etc') : t('qa.hint_description') }}
103-
</div>
104-
<div v-if="isAssistant" class="sub assistant-sub">
105-
{{ t('embedded.intelligent_data_query') }}
95+
<template v-if="!isAssistant">
96+
<div class="greeting">
97+
<el-icon size="32">
98+
<logo_fold />
99+
</el-icon>
100+
{{ t('qa.greeting') }}
101+
</div>
102+
<div class="sub">
103+
{{ t('qa.hint_description') }}
104+
</div>
105+
</template>
106+
107+
<div v-else class="assistant-desc">
108+
<img :src="logoAssistant" class="logo" width="30px" height="30px" alt="" />
109+
<div class="i-am">{{ welcome }}</div>
110+
<div class="i-can">{{ welcomeDesc }}</div>
106111
</div>
112+
107113
<el-button
108114
v-if="!isAssistant && currentChatId === undefined"
109115
size="large"
@@ -364,6 +370,9 @@ import router from '@/router'
364370
const userStore = useUserStore()
365371
const props = defineProps<{
366372
startChatDsId?: number
373+
welcomeDesc?: string
374+
logoAssistant?: string
375+
welcome?: string
367376
}>()
368377
const floatPopoverRef = ref()
369378
const floatPopoverVisible = ref(false)
@@ -1090,6 +1099,30 @@ onMounted(() => {
10901099
align-items: center;
10911100
flex-direction: column;
10921101
1102+
.assistant-desc {
1103+
width: 100%;
1104+
display: flex;
1105+
align-items: center;
1106+
flex-direction: column;
1107+
1108+
.i-am {
1109+
font-weight: 600;
1110+
font-size: 24px;
1111+
line-height: 32px;
1112+
margin: 16px 0;
1113+
}
1114+
1115+
.i-can {
1116+
margin-bottom: 4px;
1117+
max-width: 350px;
1118+
text-align: center;
1119+
font-weight: 400;
1120+
font-size: 14px;
1121+
line-height: 24px;
1122+
color: #646a73;
1123+
}
1124+
}
1125+
10931126
.greeting {
10941127
display: flex;
10951128
align-items: center;

frontend/src/views/embedded/index.vue

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<el-icon size="20" @click="openHistory">
55
<icon_sidebar_outlined></icon_sidebar_outlined>
66
</el-icon>
7-
<img :src="LOGO" class="logo" width="30px" height="30px" alt="" />
8-
<span class="tite">{{ assistantName || $t('embedded.intelligent_customer_service') }}</span>
7+
<img :src="logo || LOGO" class="logo" width="30px" height="30px" alt="" />
8+
<span class="title">{{ customSet.name || $t('embedded.intelligent_customer_service') }}</span>
99

1010
<el-tooltip effect="dark" :content="$t('embedded.new_conversation')" placement="top">
1111
<el-icon class="new-chat" size="20" @click="createChat">
@@ -14,24 +14,31 @@
1414
</el-tooltip>
1515
</div>
1616
<div class="sqlbot-chat-container">
17-
<chat-component v-if="!loading" ref="chatRef" />
17+
<chat-component
18+
v-if="!loading"
19+
ref="chatRef"
20+
:welcome="customSet.welcome"
21+
:welcome-desc="customSet.welcome_desc"
22+
:logo-assistant="logo"
23+
/>
1824
</div>
1925
<div class="drawer-assistant" @click="openHistory"></div>
2026
</div>
2127
</template>
2228
<script setup lang="ts">
23-
import { onBeforeMount, onBeforeUnmount, ref, onMounted } from 'vue'
29+
import { onBeforeMount, nextTick, onBeforeUnmount, ref, onMounted, reactive } from 'vue'
2430
import ChatComponent from '@/views/chat/index.vue'
31+
import { request } from '@/utils/request'
2532
import LOGO from '@/assets/embedded/LOGO.png'
2633
import icon_sidebar_outlined from '@/assets/embedded/icon_sidebar_outlined.svg'
2734
import icon_new_chat_outlined from '@/assets/svg/icon_new_chat_outlined.svg'
2835
import { useRoute } from 'vue-router'
2936
import { assistantApi } from '@/api/assistant'
3037
import { useAssistantStore } from '@/stores/assistant'
38+
import { setCurrentColor } from '@/utils/utils'
3139
3240
const assistantStore = useAssistantStore()
3341
const route = useRoute()
34-
const assistantName = ref('')
3542
const chatRef = ref()
3643
3744
const createChat = () => {
@@ -92,19 +99,51 @@ onMounted(() => {
9299
}`
93100
document.querySelector('head')?.appendChild(style)
94101
})
102+
const customSet = reactive({
103+
name: '',
104+
welcome: '',
105+
welcome_desc: '',
106+
theme: '#1CBA90',
107+
header_font_color: '#1F2329',
108+
}) as { [key: string]: any }
109+
const logo = ref()
110+
const basePath = import.meta.env.VITE_API_BASE_URL
111+
const baseUrl = basePath + '/system/assistant/picture/'
112+
const setPageCustomColor = (val: any) => {
113+
const ele = document.querySelector('.sqlbot-assistant-container') as HTMLElement
114+
setCurrentColor(val, ele)
115+
}
116+
117+
const setPageHeaderFontColor = (val: any) => {
118+
const ele = document.querySelector('.sqlbot-assistant-container') as HTMLElement
119+
ele.style.setProperty('--ed-text-color-primary', val)
120+
}
95121
onBeforeMount(async () => {
96122
const assistantId = route.query.id
97123
if (!assistantId) {
98124
ElMessage.error('Miss assistant id, please check assistant url')
99125
return
100126
}
127+
request.get(`/system/assistant/info/${assistantId}`).then((res) => {
128+
if (res?.configuration) {
129+
const rawData = JSON.parse(res?.configuration)
130+
logo.value = baseUrl + rawData.logo
131+
132+
for (const key in customSet) {
133+
if (Object.prototype.hasOwnProperty.call(customSet, key) && rawData[key]) {
134+
customSet[key] = rawData[key]
135+
}
136+
}
137+
138+
nextTick(() => {
139+
setPageCustomColor(customSet.theme)
140+
setPageHeaderFontColor(customSet.header_font_color)
141+
})
142+
}
143+
})
101144
const online = route.query.online
102145
setFormatOnline(online)
103146
104-
let name = route.query.name
105-
if (name) {
106-
assistantName.value = decodeURIComponent(name.toString())
107-
}
108147
const now = Date.now()
109148
assistantStore.setFlag(now)
110149
assistantStore.setId(assistantId?.toString() || '')
@@ -145,7 +184,7 @@ onBeforeUnmount(() => {
145184
z-index: 100;
146185
height: 56px;
147186
line-height: 56px;
148-
background: var(--ed-color-primary-14, #1cba9014);
187+
background: var(--ed-color-primary-1a, #1cba901a);
149188
height: 56px;
150189
padding: 0 16px;
151190
display: flex;
@@ -159,6 +198,7 @@ onBeforeUnmount(() => {
159198
font-weight: 500;
160199
font-size: 16px;
161200
line-height: 24px;
201+
color: var(--ed-text-color-primary);
162202
}
163203
164204
.ed-icon {

frontend/src/views/system/embedded/Test.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
width="400"
44
height="700"
55
style="position: fixed; left: 16px; bottom: 16px"
6-
src="/embedded.html/#/assistant?id=1"
6+
src="/embedded.html/#/assistant?id=7355522562870218752"
77
frameborder="0"
88
></iframe>
99
</template>

0 commit comments

Comments
 (0)