chore: 移除 xlsx 依赖, 重构 table 导出

This commit is contained in:
就眠儀式 2022-04-16 14:01:55 +08:00
parent 4333ee1c9e
commit 7f03d84e25
4 changed files with 29 additions and 102 deletions

View File

@ -38,8 +38,7 @@
"dayjs": "^1.11.0", "dayjs": "^1.11.0",
"evtd": "^0.2.3", "evtd": "^0.2.3",
"uuid": "^8.3.2", "uuid": "^8.3.2",
"vue-i18n": "^9.2.0-beta.34", "vue-i18n": "^9.2.0-beta.34"
"xlsx": "^0.18.4"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.15.8", "@babel/core": "^7.15.8",

View File

@ -5,7 +5,6 @@ export default {
</script> </script>
<script setup lang="ts"> <script setup lang="ts">
import * as XLSX from "xlsx";
import { ref, watch, useSlots, withDefaults, onMounted } from "vue"; import { ref, watch, useSlots, withDefaults, onMounted } from "vue";
import { v4 as uuidv4 } from "../../utils/guidUtil"; import { v4 as uuidv4 } from "../../utils/guidUtil";
import { Recordable } from "../../types"; import { Recordable } from "../../types";
@ -120,29 +119,43 @@ const print = function () {
// table // table
const exportData = () => { const exportData = () => {
const wb = XLSX.utils.book_new(); const head = [];
let arr: any[] = []; const body = [];
props.dataSource.forEach((item) => { tableColumns.value.forEach(item => {
let obj = {}; head.push(item.title);
})
tableDataSource.value.forEach((item) => {
let obj = [];
tableColumns.value.forEach((tableColumn) => { tableColumns.value.forEach((tableColumn) => {
// @ts-ignore // @ts-ignore
Object.keys(item).forEach((name) => { Object.keys(item).forEach((name) => {
if (tableColumn.key === name) { if (tableColumn.key === name) {
// @ts-ignore // @ts-ignore
obj[tableColumn.title] = item[name]; obj.push(item[name]);
} }
}); });
}); });
arr.push(obj); body.push(obj);
});
const ws = XLSX.utils.json_to_sheet(arr);
XLSX.utils.book_append_sheet(wb, ws, "sheet");
XLSX.writeFile(wb, "export.xls", {
bookType: "xls",
}); });
exportToExcel(head, body)
return; return;
}; };
function exportToExcel(headerList, bodyList){
let excelList = [];
excelList.push(headerList.join("\t,"));
excelList.push("\n");
bodyList.forEach(item=>{
excelList.push(item.join("\t,"));
excelList.push("\n");
})
var merged = excelList .join("");
let link = document.createElement("a");
link.href = "data:text/xls;charset=utf-8,\ufeff" + encodeURIComponent(merged);
link.download = `table.xls`;
link.click();
}
const sortTable = (e: any, key: string, sort: string) => { const sortTable = (e: any, key: string, sort: string) => {
// //
let currentSort = e.target.parentNode.getAttribute("lay-sort"); let currentSort = e.target.parentNode.getAttribute("lay-sort");

View File

@ -63,7 +63,6 @@ importers:
uuid: ^8.3.2 uuid: ^8.3.2
vite: 2.9.1 vite: 2.9.1
vue-i18n: ^9.2.0-beta.34 vue-i18n: ^9.2.0-beta.34
xlsx: ^0.18.4
dependencies: dependencies:
'@vueuse/core': 7.7.1_vue@3.2.31 '@vueuse/core': 7.7.1_vue@3.2.31
animate.css: 4.1.1 animate.css: 4.1.1
@ -74,7 +73,6 @@ importers:
evtd: 0.2.3 evtd: 0.2.3
uuid: 8.3.2 uuid: 8.3.2
vue-i18n: 9.2.0-beta.34_vue@3.2.31 vue-i18n: 9.2.0-beta.34_vue@3.2.31
xlsx: 0.18.5
devDependencies: devDependencies:
'@babel/core': 7.17.8 '@babel/core': 7.17.8
'@babel/preset-env': 7.16.11_@babel+core@7.17.8 '@babel/preset-env': 7.16.11_@babel+core@7.17.8
@ -2025,11 +2023,6 @@ packages:
hasBin: true hasBin: true
dev: true dev: true
/adler-32/1.3.1:
resolution: {integrity: sha512-ynZ4w/nUUv5rrsR8UUGoe1VC9hZj6V5hU9Qw1HlMDJGEJw5S7TfTErWTjMys6M7vr0YWcPqs3qAr4ss0nDfP+A==}
engines: {node: '>=0.8'}
dev: false
/ajv/6.12.6: /ajv/6.12.6:
resolution: {integrity: sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==} resolution: {integrity: sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==}
dependencies: dependencies:
@ -2216,15 +2209,6 @@ packages:
resolution: {integrity: sha512-sB1bZHjseSjDtijV1Hb7PB2Zd58Kyx+n/9EotvZ4Qcz2K3d0lWB8dB4nb8wN/TsOGFq3UuAm0zQZNQ4SoR7TrQ==} resolution: {integrity: sha512-sB1bZHjseSjDtijV1Hb7PB2Zd58Kyx+n/9EotvZ4Qcz2K3d0lWB8dB4nb8wN/TsOGFq3UuAm0zQZNQ4SoR7TrQ==}
dev: true dev: true
/cfb/1.2.1:
resolution: {integrity: sha512-wT2ScPAFGSVy7CY+aauMezZBnNrfnaLSrxHUHdea+Td/86vrk6ZquggV+ssBR88zNs0OnBkL2+lf9q0K+zVGzQ==}
engines: {node: '>=0.8'}
dependencies:
adler-32: 1.3.1
crc-32: 1.2.1
printj: 1.3.1
dev: false
/chalk/2.4.2: /chalk/2.4.2:
resolution: {integrity: sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==} resolution: {integrity: sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==}
engines: {node: '>=4'} engines: {node: '>=4'}
@ -2265,11 +2249,6 @@ packages:
wrap-ansi: 7.0.0 wrap-ansi: 7.0.0
dev: true dev: true
/codepage/1.15.0:
resolution: {integrity: sha512-3g6NUTPd/YtuuGrhMnOMRjFc+LJw/bnMp3+0r/Wcz3IXUuCosKRJvMphm5+Q+bvTVGcJJuRvVLuYba+WojaFaA==}
engines: {node: '>=0.8'}
dev: false
/color-convert/1.9.3: /color-convert/1.9.3:
resolution: {integrity: sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==} resolution: {integrity: sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==}
dependencies: dependencies:
@ -2406,15 +2385,6 @@ packages:
yaml: 1.10.2 yaml: 1.10.2
dev: true dev: true
/crc-32/1.2.1:
resolution: {integrity: sha512-Dn/xm/1vFFgs3nfrpEVScHoIslO9NZRITWGz/1E/St6u4xw99vfZzVkW0OSnzx2h9egej9xwMCEut6sqwokM/w==}
engines: {node: '>=0.8'}
hasBin: true
dependencies:
exit-on-epipe: 1.0.1
printj: 1.3.1
dev: false
/create-require/1.1.1: /create-require/1.1.1:
resolution: {integrity: sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==} resolution: {integrity: sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==}
dev: true dev: true
@ -3011,11 +2981,6 @@ packages:
strip-final-newline: 2.0.0 strip-final-newline: 2.0.0
dev: true dev: true
/exit-on-epipe/1.0.1:
resolution: {integrity: sha512-h2z5mrROTxce56S+pnvAV890uu7ls7f1kEvVGJbw1OlFH3/mlJ5bkXu0KRyW94v37zzHPiUd55iLn3DA7TjWpw==}
engines: {node: '>=0.8'}
dev: false
/expand-tilde/2.0.2: /expand-tilde/2.0.2:
resolution: {integrity: sha1-l+gBqgUt8CRU3kawK/YhZCzchQI=} resolution: {integrity: sha1-l+gBqgUt8CRU3kawK/YhZCzchQI=}
engines: {node: '>=0.10.0'} engines: {node: '>=0.10.0'}
@ -3142,11 +3107,6 @@ packages:
resolution: {integrity: sha512-WIWGi2L3DyTUvUrwRKgGi9TwxQMUEqPOPQBVi71R96jZXJdFskXEmf54BoZaS1kknGODoIGASGEzBUYdyMCBJg==} resolution: {integrity: sha512-WIWGi2L3DyTUvUrwRKgGi9TwxQMUEqPOPQBVi71R96jZXJdFskXEmf54BoZaS1kknGODoIGASGEzBUYdyMCBJg==}
dev: true dev: true
/frac/1.1.2:
resolution: {integrity: sha512-w/XBfkibaTl3YDqASwfDUqkna4Z2p9cFSr1aHDt0WoMTECnRfBOv2WArlZILlqgWlmdIlALXGpM2AOhEk5W3IA==}
engines: {node: '>=0.8'}
dev: false
/fs-extra/10.0.1: /fs-extra/10.0.1:
resolution: {integrity: sha512-NbdoVMZso2Lsrn/QwLXOy6rm0ufY2zEOKCDzJR/0kBsb0E6qed0P3iYK+Ath3BfvXEeu4JhEtXLgILx5psUfag==} resolution: {integrity: sha512-NbdoVMZso2Lsrn/QwLXOy6rm0ufY2zEOKCDzJR/0kBsb0E6qed0P3iYK+Ath3BfvXEeu4JhEtXLgILx5psUfag==}
engines: {node: '>=12'} engines: {node: '>=12'}
@ -3582,7 +3542,7 @@ packages:
/jsonfile/4.0.0: /jsonfile/4.0.0:
resolution: {integrity: sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=} resolution: {integrity: sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=}
optionalDependencies: optionalDependencies:
graceful-fs: registry.npmmirror.com/graceful-fs/4.2.9 graceful-fs: 4.2.9
dev: true dev: true
/jsonfile/6.1.0: /jsonfile/6.1.0:
@ -3590,7 +3550,7 @@ packages:
dependencies: dependencies:
universalify: 2.0.0 universalify: 2.0.0
optionalDependencies: optionalDependencies:
graceful-fs: registry.npmmirror.com/graceful-fs/4.2.9 graceful-fs: 4.2.9
dev: true dev: true
/jsonparse/1.3.1: /jsonparse/1.3.1:
@ -4077,12 +4037,6 @@ packages:
hasBin: true hasBin: true
dev: true dev: true
/printj/1.3.1:
resolution: {integrity: sha512-GA3TdL8szPK4AQ2YnOe/b+Y1jUFwmmGMMK/qbY7VcE3Z7FU8JstbKiKRzO6CIiAKPhTO8m01NoQ0V5f3jc4OGg==}
engines: {node: '>=0.8'}
hasBin: true
dev: false
/prismjs/1.27.0: /prismjs/1.27.0:
resolution: {integrity: sha512-t13BGPUlFDR7wRB5kQDG4jjl7XeuH6jbJGt11JHPL96qwsEHNX2+68tFXqc1/k+/jALsbSWJKUOT/hcYAZ5LkA==} resolution: {integrity: sha512-t13BGPUlFDR7wRB5kQDG4jjl7XeuH6jbJGt11JHPL96qwsEHNX2+68tFXqc1/k+/jALsbSWJKUOT/hcYAZ5LkA==}
engines: {node: '>=6'} engines: {node: '>=6'}
@ -4399,13 +4353,6 @@ packages:
resolution: {integrity: sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=} resolution: {integrity: sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=}
dev: true dev: true
/ssf/0.11.2:
resolution: {integrity: sha512-+idbmIXoYET47hH+d7dfm2epdOMUDjqcB4648sTZ+t2JwoyBFL/insLfB/racrDmsKB3diwsDA696pZMieAC5g==}
engines: {node: '>=0.8'}
dependencies:
frac: 1.1.2
dev: false
/string-width/2.1.1: /string-width/2.1.1:
resolution: {integrity: sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==} resolution: {integrity: sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==}
engines: {node: '>=4'} engines: {node: '>=4'}
@ -4811,21 +4758,11 @@ packages:
isexe: 2.0.0 isexe: 2.0.0
dev: true dev: true
/wmf/1.0.2:
resolution: {integrity: sha512-/p9K7bEh0Dj6WbXg4JG0xvLQmIadrner1bi45VMJTfnbVHsc7yIajZyoSoK60/dtVBs12Fm6WkUI5/3WAVsNMw==}
engines: {node: '>=0.8'}
dev: false
/word-wrap/1.2.3: /word-wrap/1.2.3:
resolution: {integrity: sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==} resolution: {integrity: sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==}
engines: {node: '>=0.10.0'} engines: {node: '>=0.10.0'}
dev: true dev: true
/word/0.3.0:
resolution: {integrity: sha512-OELeY0Q61OXpdUfTp+oweA/vtLVg5VDOXh+3he3PNzLGG/y0oylSOC1xRVj0+l4vQ3tj/bB1HVHv1ocXkQceFA==}
engines: {node: '>=0.8'}
dev: false
/wrap-ansi/7.0.0: /wrap-ansi/7.0.0:
resolution: {integrity: sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==} resolution: {integrity: sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==}
engines: {node: '>=10'} engines: {node: '>=10'}
@ -4839,20 +4776,6 @@ packages:
resolution: {integrity: sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=} resolution: {integrity: sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=}
dev: true dev: true
/xlsx/0.18.5:
resolution: {integrity: sha512-dmg3LCjBPHZnQp5/F/+nnTa+miPJxUXB6vtk42YjBBKayDNagxGEeIdWApkYPOf3Z3pm3k62Knjzp7lMeTEtFQ==}
engines: {node: '>=0.8'}
hasBin: true
dependencies:
adler-32: 1.3.1
cfb: 1.2.1
codepage: 1.15.0
crc-32: 1.2.1
ssf: 0.11.2
wmf: 1.0.2
word: 0.3.0
dev: false
/y18n/5.0.8: /y18n/5.0.8:
resolution: {integrity: sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==} resolution: {integrity: sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==}
engines: {node: '>=10'} engines: {node: '>=10'}
@ -4905,11 +4828,3 @@ packages:
name: '@types/prettier' name: '@types/prettier'
version: 2.6.0 version: 2.6.0
dev: true dev: true
registry.npmmirror.com/graceful-fs/4.2.9:
resolution: {integrity: sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/graceful-fs/-/graceful-fs-4.2.9.tgz}
name: graceful-fs
version: 4.2.9
requiresBuild: true
dev: true
optional: true