Browse Source

前端导出

drew 5 years ago
parent
commit
c8f92e4bcd
1 changed files with 10 additions and 4 deletions
  1. 10 4
      src/main/vue/src/plugins/dataExport.js

+ 10 - 4
src/main/vue/src/plugins/dataExport.js

@@ -34,12 +34,18 @@ export default {
                 throw new Error('filename cannot be empty');
             }
             filename = filename.replace(/.xlsx$/i, '');
-            const columns = ref.columns.filter(i => !!i.property);
+            const columns = ref.columns.filter(column => !!column.property);
             let workbook = XLSX.utils.book_new();
             let sheet = XLSX.utils.aoa_to_sheet([
-                columns.map(c => c.label),
-                ...ref.tableData.map(i => {
-                    return columns.map(c => getPropByPath(i, c.property).v);
+                columns.map(column => column.label),
+                ...ref.tableData.map(row => {
+                    return columns.map((column, index) => {
+                        const value = getPropByPath(row, column.property).v;
+                        if (column.formatter) {
+                            return column.formatter(row, column, value, index);
+                        }
+                        return value;
+                    });
                 })
             ]);
             XLSX.utils.book_append_sheet(workbook, sheet, filename);