From 988558aaa309068fd393cc654be537434b0a15ea Mon Sep 17 00:00:00 2001 From: Your Name <123456> Date: 星期四, 11 八月 2022 19:11:18 +0800 Subject: [PATCH] 修改 --- src/views/goalManagement/Goalsummary/index.vue | 20 +++++++++++++++++--- 1 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/views/goalManagement/Goalsummary/index.vue b/src/views/goalManagement/Goalsummary/index.vue index 4d241e4..4947ed0 100644 --- a/src/views/goalManagement/Goalsummary/index.vue +++ b/src/views/goalManagement/Goalsummary/index.vue @@ -24,10 +24,10 @@ <div class="btns"> <p>汇总日期:2022-07-04 23:00:07</p> <div> - <el-button type="primary" size="default" :icon="Download">导出</el-button> + <el-button type="primary" size="default" :icon="Download" @click="exportExcel('tab1', '会员明细.xlsx')">导出</el-button> </div> </div> - <el-table :data="tableData" style="width: 100%"> + <el-table :data="tableData" style="width: 100%" id="tab1"> <el-table-column label="责任部门" align="center"> <template #default="scope">{{ scope.row.departmentId }}</template> </el-table-column> @@ -68,6 +68,9 @@ import { ElMessageBox, ElMessage, ElButton, ElInput, TabsPaneContext, FormInstance } from 'element-plus'; import { Plus, Delete, Upload, Download, Refresh, View } from '@element-plus/icons-vue'; import { goalManagementApi } from '/@/api/goalManagement'; + +// import * as XLSX from 'xlsx'; + export default defineComponent({ components: { ElButton, ElInput }, setup() { @@ -162,6 +165,16 @@ ], }, ]; + + const exportExcel = (id:string,name:string) => { + let workbook = XLSX.utils.table_to_book(document.getElementById(id)); //需要在table上定义一个id + try { + XLSX.writeFile(workbook, name); + console.log('导出成功!'); + } catch (e) { + console.log('导出失败!'); + } + } return { ruleForm, tableData, @@ -179,6 +192,7 @@ Download, Refresh, View, + exportExcel }; }, }); @@ -210,4 +224,4 @@ display: flex; justify-content: right; } -</style> \ No newline at end of file +</style> -- Gitblit v1.9.2