Skip to content

Commit 6ee4b04

Browse files
committed
pref: add loading data placeholder in chart
1 parent 82d94cb commit 6ee4b04

File tree

7 files changed

+48
-12
lines changed

7 files changed

+48
-12
lines changed

frontend/src/i18n/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@
635635
"error": "Error",
636636
"exec-sql-err": "Execute SQL failed",
637637
"no_data": "No Data",
638+
"loading_data": "Loading ...",
638639
"show_error_detail": "Show error info"
639640
},
640641
"about": {

frontend/src/i18n/ko-KR.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@
635635
"error": "오류",
636636
"exec-sql-err": "SQL 실행 실패",
637637
"no_data": "데이터가 없습니다",
638+
"loading_data": "로딩 중 ...",
638639
"show_error_detail": "구체적인 정보 보기"
639640
},
640641
"about": {
@@ -733,4 +734,4 @@
733734
"modelType": {
734735
"llm": "대형 언어 모델"
735736
}
736-
}
737+
}

frontend/src/i18n/zh-CN.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@
635635
"error": "错误",
636636
"exec-sql-err": "执行SQL失败",
637637
"no_data": "暂无数据",
638+
"loading_data": "加载中...",
638639
"show_error_detail": "查看具体信息"
639640
},
640641
"about": {
@@ -733,4 +734,4 @@
733734
"modelType": {
734735
"llm": "大语言模型"
735736
}
736-
}
737+
}

frontend/src/views/chat/answer/ChartAnswer.vue

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,10 @@ const sendMessage = async () => {
218218
}
219219
}
220220
221+
const loadingData = ref(false)
222+
221223
function getChatData(recordId?: number) {
224+
loadingData.value = true
222225
chatApi
223226
.get_chart_data(recordId)
224227
.then((response) => {
@@ -229,6 +232,7 @@ function getChatData(recordId?: number) {
229232
})
230233
})
231234
.finally(() => {
235+
loadingData.value = false
232236
emits('scrollBottom')
233237
})
234238
}
@@ -254,7 +258,12 @@ defineExpose({ sendMessage, index: () => index.value, stop })
254258

255259
<template>
256260
<BaseAnswer v-if="message" :message="message" :reasoning-name="reasoningName" :loading="_loading">
257-
<ChartBlock style="margin-top: 6px" :message="message" :record-id="recordId" />
261+
<ChartBlock
262+
style="margin-top: 6px"
263+
:message="message"
264+
:record-id="recordId"
265+
:loading-data="loadingData"
266+
/>
258267
<slot></slot>
259268
<template #tool>
260269
<slot name="tool"></slot>

frontend/src/views/chat/answer/PredictAnswer.vue

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,32 +204,49 @@ const sendMessage = async () => {
204204
205205
const chartBlockRef = ref()
206206
207+
const loadingData = ref(false)
208+
207209
function getChatPredictData(recordId?: number) {
208-
chatApi.get_chart_predict_data(recordId).then((response) => {
209-
_currentChat.value.records.forEach((record) => {
210-
if (record.id === recordId) {
211-
record.predict_data = response ?? []
210+
loadingData.value = true
211+
chatApi
212+
.get_chart_predict_data(recordId)
213+
.then((response) => {
214+
let has = false
215+
_currentChat.value.records.forEach((record) => {
216+
if (record.id === recordId) {
217+
has = true
218+
record.predict_data = response ?? []
212219
213-
if (record.predict_data.length > 1) {
214-
getChatData(recordId)
220+
if (record.predict_data.length > 1) {
221+
getChatData(recordId)
222+
} else {
223+
loadingData.value = false
224+
}
215225
}
226+
})
227+
if (!has) {
228+
_loading.value = false
216229
}
217230
})
218-
})
231+
.catch((e) => {
232+
loadingData.value = false
233+
console.error(e)
234+
})
219235
}
220236
221237
function getChatData(recordId?: number) {
238+
loadingData.value = true
222239
chatApi
223240
.get_chart_data(recordId)
224241
.then((response) => {
225242
_currentChat.value.records.forEach((record) => {
226243
if (record.id === recordId) {
227244
record.data = response
228-
console.log(record.data)
229245
}
230246
})
231247
})
232248
.finally(() => {
249+
loadingData.value = false
233250
emits('scrollBottom')
234251
})
235252
}
@@ -262,6 +279,7 @@ defineExpose({ sendMessage, index: () => index.value, chatList: () => _chatList,
262279
style="margin-top: 12px"
263280
:record-id="recordId"
264281
:message="message"
282+
:loading-data="loadingData"
265283
is-predict
266284
/>
267285
<slot></slot>

frontend/src/views/chat/chat-block/ChartBlock.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ const props = withDefaults(
3333
isPredict?: boolean
3434
chatType?: ChartTypes
3535
enlarge?: boolean
36+
loadingData?: boolean
3637
}>(),
3738
{
3839
recordId: undefined,
3940
isPredict: false,
4041
chatType: undefined,
4142
enlarge: false,
43+
loadingData: false,
4244
}
4345
)
4446
@@ -473,6 +475,7 @@ watch(
473475
:chart-type="chartType"
474476
:message="message"
475477
:data="data"
478+
:loading-data="loadingData"
476479
/>
477480
</div>
478481
<div v-if="dataObject.limit" class="over-limit-hint">
@@ -493,8 +496,10 @@ watch(
493496
<ChartBlock
494497
v-if="dialogVisible"
495498
:message="message"
499+
:record-id="recordId"
496500
:is-predict="isPredict"
497501
:chat-type="chartType"
502+
:loading-data="loadingData"
498503
enlarge
499504
@exit-full-screen="onExitFullScreen"
500505
/>

frontend/src/views/chat/component/DisplayChartBlock.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const props = defineProps<{
1010
chartType: ChartTypes
1111
message: ChatMessage
1212
data: Array<{ [key: string]: any }>
13+
loadingData?: boolean
1314
}>()
1415
1516
const { t } = useI18n()
@@ -94,7 +95,7 @@ defineExpose({
9495
:series="series"
9596
:data="data"
9697
/>
97-
<el-empty v-else :description="t('chat.no_data')" />
98+
<el-empty v-else :description="loadingData ? t('chat.loading_data') : t('chat.no_data')" />
9899
</div>
99100
</template>
100101

0 commit comments

Comments
 (0)