Skip to content

Commit 2426649

Browse files
committed
feat: add export excel loading
1 parent f199b36 commit 2426649

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

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

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const props = withDefaults(
3939
}
4040
)
4141
42+
const loading = ref<boolean>(false)
4243
const { t } = useI18n()
4344
const addViewRef = ref(null)
4445
const emits = defineEmits(['exitFullScreen'])
@@ -231,20 +232,26 @@ function copy() {
231232
const exportRef = ref()
232233
233234
function exportToExcel() {
234-
chatApi
235-
.export2Excel({ ...chartRef.value?.getExcelData(), name: chartObject.value.title })
236-
.then((res) => {
237-
const blob = new Blob([res], {
238-
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
235+
if (chartRef.value) {
236+
loading.value = true
237+
chatApi
238+
.export2Excel({ ...chartRef.value?.getExcelData(), name: chartObject.value.title })
239+
.then((res) => {
240+
const blob = new Blob([res], {
241+
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
242+
})
243+
const link = document.createElement('a')
244+
link.href = URL.createObjectURL(blob)
245+
link.download = `${chartObject.value.title ?? 'Excel'}.xlsx`
246+
document.body.appendChild(link)
247+
link.click()
248+
document.body.removeChild(link)
239249
})
240-
const link = document.createElement('a')
241-
link.href = URL.createObjectURL(blob)
242-
link.download = `${chartObject.value.title ?? 'Excel'}.xlsx`
243-
document.body.appendChild(link)
244-
link.click()
245-
document.body.removeChild(link)
246-
})
247-
exportRef.value?.hide()
250+
.finally(() => {
251+
loading.value = false
252+
})
253+
exportRef.value?.hide()
254+
}
248255
}
249256
250257
function exportToImage() {
@@ -284,6 +291,7 @@ watch(
284291
((!isPredict && (message?.record?.sql || message?.record?.chart)) ||
285292
(isPredict && message?.record?.chart && data.length > 0))
286293
"
294+
v-loading.fullscreen.lock="loading"
287295
class="chart-component-container"
288296
:class="{ 'full-screen': enlarge }"
289297
>

0 commit comments

Comments
 (0)