From 40e466b1464e505a44d5f01b29a785794dcb8363 Mon Sep 17 00:00:00 2001 From: tyro880 <你的GitHub绑定邮箱> Date: Sat, 18 Apr 2026 12:45:29 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E8=A1=A8=E6=A0=BC):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=92=8C=E5=AF=BC=E5=87=BA=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=B9=B6=E4=BC=98=E5=8C=96=E6=80=BB=E6=95=B0=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复删除操作后总数未更新的问题 - 合并导出功能代码并添加错误处理 - 为导出文件添加时间戳后缀 - 移除重复的formatJsonForSelected方法 --- src/views/table/complex-table.vue | 88 +++++++++++++++++++++---------- 1 file changed, 60 insertions(+), 28 deletions(-) diff --git a/src/views/table/complex-table.vue b/src/views/table/complex-table.vue index 4845b730..de037172 100644 --- a/src/views/table/complex-table.vue +++ b/src/views/table/complex-table.vue @@ -366,6 +366,7 @@ export default { duration: 2000 }) this.list.splice(index, 1) + this.total = Math.max(0, this.total - 1) }, handleFetchPv(pv) { fetchPv(pv).then(response => { @@ -376,19 +377,39 @@ export default { handleDownload() { this.downloadLoading = true import('@/vendor/Export2Excel').then(excel => { - const tHeader = ['timestamp', 'title', 'type', 'importance', 'status'] - const filterVal = ['timestamp', 'title', 'type', 'importance', 'status'] - const data = this.formatJson(filterVal) - excel.export_json_to_excel({ - header: tHeader, - data, - filename: 'table-list' - }) + try { + const tHeader = ['timestamp', 'title', 'type', 'importance', 'status'] + const filterVal = ['timestamp', 'title', 'type', 'importance', 'status'] + const data = this.formatJson(filterVal) + const timestamp = parseTime(new Date(), '{y}{m}{d}-{h}{i}{s}') + excel.export_json_to_excel({ + header: tHeader, + data, + filename: `article-list-${timestamp}` + }) + this.$message({ + message: '导出成功', + type: 'success' + }) + } catch (error) { + this.$message({ + message: '导出失败', + type: 'error' + }) + } finally { + this.downloadLoading = false + } + }).catch(() => { this.downloadLoading = false + this.$message({ + message: '导出失败', + type: 'error' + }) }) }, - formatJson(filterVal) { - return this.list.map(v => filterVal.map(j => { + formatJson(filterVal, dataSource) { + const data = dataSource || this.list + return data.map(v => filterVal.map(j => { if (j === 'timestamp') { return parseTime(v[j]) } else { @@ -421,6 +442,7 @@ export default { const ids = this.selectedList.map(item => item.id) const newList = this.list.filter(item => !ids.includes(item.id)) this.list = newList + this.total = Math.max(0, this.total - ids.length) this.selectedList = [] this.$notify({ title: 'Success', @@ -443,25 +465,35 @@ export default { this.batchExportLoading = true import('@/vendor/Export2Excel').then(excel => { - const tHeader = ['timestamp', 'title', 'type', 'importance', 'status'] - const filterVal = ['timestamp', 'title', 'type', 'importance', 'status'] - const data = this.formatJsonForSelected(filterVal) - excel.export_json_to_excel({ - header: tHeader, - data, - filename: 'selected-table-list' - }) - this.batchExportLoading = false - }) - }, - formatJsonForSelected(filterVal) { - return this.selectedList.map(v => filterVal.map(j => { - if (j === 'timestamp') { - return parseTime(v[j]) - } else { - return v[j] + try { + const tHeader = ['timestamp', 'title', 'type', 'importance', 'status'] + const filterVal = ['timestamp', 'title', 'type', 'importance', 'status'] + const data = this.formatJson(filterVal, this.selectedList) + const timestamp = parseTime(new Date(), '{y}{m}{d}-{h}{i}{s}') + excel.export_json_to_excel({ + header: tHeader, + data, + filename: `article-list-${timestamp}` + }) + this.$message({ + message: '导出成功', + type: 'success' + }) + } catch (error) { + this.$message({ + message: '导出失败', + type: 'error' + }) + } finally { + this.batchExportLoading = false } - })) + }).catch(() => { + this.batchExportLoading = false + this.$message({ + message: '导出失败', + type: 'error' + }) + }) } } }