@gingkoo/base-server 0.0.4-alpha.17 → 0.0.4-alpha.18
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.
|
@@ -22,6 +22,9 @@ router.get('/:fileFolder/*', async function (req, res) {
|
|
|
22
22
|
let filename = '';
|
|
23
23
|
if (fileFolder === 'share') {
|
|
24
24
|
filename = req.path.split('/').slice(-1)[0];
|
|
25
|
+
}
|
|
26
|
+
if (fileFolder === 'system') {
|
|
27
|
+
filename = req.params[0];
|
|
25
28
|
} else {
|
|
26
29
|
filename = req.path.substr();
|
|
27
30
|
}
|
|
@@ -28,6 +28,9 @@ function resourcePath(userid = '', fileFolder, filePath = '') {
|
|
|
28
28
|
} else if (fileFolder == 'avatar') {
|
|
29
29
|
} else if (fileFolder == 'upload') {
|
|
30
30
|
fileRealPath = path.join(config.app.home, filePath);
|
|
31
|
+
} else if (fileFolder == 'system') {
|
|
32
|
+
// 系统内部文件
|
|
33
|
+
fileRealPath = path.resolve(filePath);
|
|
31
34
|
} else {
|
|
32
35
|
return null;
|
|
33
36
|
}
|
package/backend/utils/excel.js
CHANGED
|
@@ -17,6 +17,23 @@ const borderHeader = {
|
|
|
17
17
|
right: { style: 'thin' },
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
+
const numberToColumn = (number) => {
|
|
21
|
+
let column = '';
|
|
22
|
+
while (number >= 0) {
|
|
23
|
+
column = String.fromCharCode((number % 26) + 65) + column;
|
|
24
|
+
number = Math.floor(number / 26) - 1;
|
|
25
|
+
}
|
|
26
|
+
return column;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const columnToNumber = (column) => {
|
|
30
|
+
let number = 0;
|
|
31
|
+
for (let i = 0; i < column.length; i++) {
|
|
32
|
+
number = number * 26 + (column.charCodeAt(i) - 64);
|
|
33
|
+
}
|
|
34
|
+
return number - 1;
|
|
35
|
+
};
|
|
36
|
+
|
|
20
37
|
/**
|
|
21
38
|
* 解析excel
|
|
22
39
|
* @param {string} filePath 本地文件路径
|
|
@@ -137,7 +154,6 @@ async function _excelExport(
|
|
|
137
154
|
const mappingsheet = workbook.addWorksheet(dictSheetName);
|
|
138
155
|
let titles = []; // 表头
|
|
139
156
|
let columns = []; // 表 列信息
|
|
140
|
-
let mappingTitles = [];
|
|
141
157
|
let mappingColumns = []; // 字典 列信息
|
|
142
158
|
|
|
143
159
|
let mapColIndex = {};
|
|
@@ -377,12 +393,11 @@ const _excelExportMultisheet = async (
|
|
|
377
393
|
return mo;
|
|
378
394
|
}, 0);
|
|
379
395
|
|
|
380
|
-
//
|
|
381
|
-
mappings.
|
|
396
|
+
// 设置数据字典的一些配置
|
|
397
|
+
mappings.forEach((it) => {
|
|
382
398
|
mappingMap[it.key] = it;
|
|
383
399
|
mapColIndex[it.key] = {};
|
|
384
400
|
if (it.blankSheet) return false;
|
|
385
|
-
const mappingsheet = workbook.addWorksheet(it.sheetName);
|
|
386
401
|
let mappingColumns = []; // 字典 列信息
|
|
387
402
|
|
|
388
403
|
//处理头
|
|
@@ -396,27 +411,8 @@ const _excelExportMultisheet = async (
|
|
|
396
411
|
mappingColumns.push(colinfo);
|
|
397
412
|
}
|
|
398
413
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
//字典处理
|
|
402
|
-
for (let k in mappingData) {
|
|
403
|
-
let excelCol = mappingsheet.getColumn(k);
|
|
404
|
-
let mapList = [];
|
|
405
|
-
mapList.push(mappingData[k].label);
|
|
406
|
-
for (let x in mappingData[k].data) {
|
|
407
|
-
mapList.push(mappingData[k].data[x]);
|
|
408
|
-
}
|
|
409
|
-
excelCol.values = mapList;
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
let firstRow = mappingsheet.getRow(1);
|
|
413
|
-
firstRow.eachCell((cell, colNumber) => {
|
|
414
|
-
cell.font = fontHeader;
|
|
415
|
-
cell.fill = fillHeader;
|
|
416
|
-
cell.border = borderHeader;
|
|
417
|
-
let colObj = mappingsheet.getColumn(cell.col);
|
|
418
|
-
let colId = cell.address.match(/[a-zA-Z]+/g)[0];
|
|
419
|
-
mapColIndex[it.key][colObj.key] = colId;
|
|
414
|
+
mappingColumns.forEach((v, i) => {
|
|
415
|
+
mapColIndex[it.key][v.key] = numberToColumn(i); // 0 -> A
|
|
420
416
|
});
|
|
421
417
|
});
|
|
422
418
|
|
|
@@ -506,6 +502,44 @@ const _excelExportMultisheet = async (
|
|
|
506
502
|
}
|
|
507
503
|
});
|
|
508
504
|
|
|
505
|
+
// 处理数据字典
|
|
506
|
+
mappings.forEach((it) => {
|
|
507
|
+
if (it.blankSheet) return false;
|
|
508
|
+
const mappingsheet = workbook.addWorksheet(it.sheetName);
|
|
509
|
+
let mappingColumns = []; // 字典 列信息
|
|
510
|
+
|
|
511
|
+
//处理头
|
|
512
|
+
let mappingData = it.mappingData;
|
|
513
|
+
for (let k in mappingData) {
|
|
514
|
+
let colinfo = {
|
|
515
|
+
header: mappingData[k].label,
|
|
516
|
+
key: k,
|
|
517
|
+
width: mappingData[k].width || 20,
|
|
518
|
+
};
|
|
519
|
+
mappingColumns.push(colinfo);
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
mappingsheet.columns = mappingColumns;
|
|
523
|
+
|
|
524
|
+
//字典处理
|
|
525
|
+
for (let k in mappingData) {
|
|
526
|
+
let excelCol = mappingsheet.getColumn(k);
|
|
527
|
+
let mapList = [];
|
|
528
|
+
mapList.push(mappingData[k].label);
|
|
529
|
+
for (let x in mappingData[k].data) {
|
|
530
|
+
mapList.push(mappingData[k].data[x]);
|
|
531
|
+
}
|
|
532
|
+
excelCol.values = mapList;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
let firstRow = mappingsheet.getRow(1);
|
|
536
|
+
firstRow.eachCell((cell, colNumber) => {
|
|
537
|
+
cell.font = fontHeader;
|
|
538
|
+
cell.fill = fillHeader;
|
|
539
|
+
cell.border = borderHeader;
|
|
540
|
+
});
|
|
541
|
+
});
|
|
542
|
+
|
|
509
543
|
let ret = await workbook.xlsx.writeFile(filePath);
|
|
510
544
|
return ret;
|
|
511
545
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gingkoo/base-server",
|
|
3
|
-
"version": "0.0.4-alpha.
|
|
3
|
+
"version": "0.0.4-alpha.18",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "app.js",
|
|
6
6
|
"scripts": {
|
|
@@ -8,8 +8,7 @@
|
|
|
8
8
|
"build": "npm run clean && vite build --mode production",
|
|
9
9
|
"serve": "nodemon serve -p 1000",
|
|
10
10
|
"check": "node scripts/check_publish.js",
|
|
11
|
-
"clean": "rimraf dist"
|
|
12
|
-
"prepublishOnly": "npm run check && npm run build"
|
|
11
|
+
"clean": "rimraf dist"
|
|
13
12
|
},
|
|
14
13
|
"files": [
|
|
15
14
|
"dist",
|