@yoooloo42/joker 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js ADDED
@@ -0,0 +1,6 @@
1
+ import libs from './src/libs/index.js';
2
+
3
+ const bean = {
4
+ libs
5
+ }
6
+ export default bean
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@yoooloo42/joker",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/13993193075/joker.git"
12
+ },
13
+ "author": "",
14
+ "license": "ISC",
15
+ "bugs": {
16
+ "url": "https://github.com/13993193075/joker/issues"
17
+ },
18
+ "homepage": "https://github.com/13993193075/joker#readme"
19
+ }
@@ -0,0 +1,49 @@
1
+ import * as XLSX from 'xlsx';
2
+ import FileSaver from 'file-saver';
3
+
4
+ /**
5
+ * 将 JSON 数组数据导出为 Excel 文件
6
+ * @param {Array<Object>} json - 要导出的数据数组 (el-table 的 :data 绑定的数据)
7
+ * @param {Array<string>} header - 表格的表头(中文名)
8
+ * @param {Array<string>} keys - 对应表头的数据字段名(英文键名)
9
+ * @param {string} filename - 导出的文件名
10
+ */
11
+ function jsonToExcel({
12
+ json,
13
+ header,
14
+ keys,
15
+ filename = 'excel-file',
16
+ }) {
17
+ // 1. 转换数据格式
18
+ const data = json.map(item => keys.map(key => item[key]));
19
+
20
+ // 2. 将表头和数据组合
21
+ const aoa = [header, ...data];
22
+
23
+ // 3. 创建工作簿和工作表
24
+ const ws = XLSX.utils.aoa_to_sheet(aoa);
25
+ const wb = XLSX.utils.book_new();
26
+ XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
27
+
28
+ // 4. 生成 Excel 文件
29
+ const wbout = XLSX.write(wb, {
30
+ bookType: 'xlsx',
31
+ bookSST: true,
32
+ type: 'array'
33
+ });
34
+
35
+ // 5. 保存文件
36
+ try {
37
+ FileSaver.saveAs(
38
+ new Blob([wbout], { type: 'application/octet-stream' }),
39
+ `${filename}.xlsx`
40
+ );
41
+ } catch (e) {
42
+ if (typeof console !== 'undefined') console.log(e, wbout);
43
+ }
44
+ }
45
+
46
+ const bean = {
47
+ jsonToExcel
48
+ }
49
+ export default bean
@@ -0,0 +1,6 @@
1
+ import FileSaver from "./FileSaver.js";
2
+
3
+ const bean = {
4
+ FileSaver
5
+ }
6
+ export default bean