doomiwork 4.0.6 → 4.0.8
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/core/controller.js +3 -3
- package/package.json +1 -1
- package/utilities/excelutility.js +15 -21
- package/utilities/requestparser.js +2 -1
package/core/controller.js
CHANGED
|
@@ -219,7 +219,7 @@ class controller {
|
|
|
219
219
|
*/
|
|
220
220
|
async getDataById(req, dataKey, sqlCommand) {
|
|
221
221
|
if (this.logger) this.logger.trace("准备获取dataconfig文件中对应的 %s 详细数据",dataKey)
|
|
222
|
-
const detailinfo = getDetailInfo(dataKey);
|
|
222
|
+
const detailinfo = getDetailInfo(req, dataKey);
|
|
223
223
|
if (!detailinfo) return { successed: false, errcode: -10, errmsg: `缺失${dataKey}对应的详情配置` };
|
|
224
224
|
let beforeData = await this.beforeAccessDB(req, sqlCommand || this._daoModel.getByIdSql(), req.params.id, "detail", this);
|
|
225
225
|
////如果返回Null,则表示不加载数据了
|
|
@@ -255,7 +255,7 @@ class controller {
|
|
|
255
255
|
let detailinfo, resultItem = { successed: true, data: req.body };
|
|
256
256
|
///是否需要将data中的key-value值到配置文件中进行转换
|
|
257
257
|
if (mapping == true) {
|
|
258
|
-
detailinfo = getDetailInfo(dataKey);
|
|
258
|
+
detailinfo = getDetailInfo(req, dataKey);
|
|
259
259
|
if (!detailinfo) return { successed: false, errcode: -10, errmsg: `缺失${dataKey}对应的详情配置` };
|
|
260
260
|
resultItem = View2Data(req, detailinfo.fields, "create");
|
|
261
261
|
///如果转换的验证过程中出现错误,则返回
|
|
@@ -307,7 +307,7 @@ class controller {
|
|
|
307
307
|
let detailinfo, resultItem = { successed: true, data: req.body };
|
|
308
308
|
///是否需要将data中的key-value值到配置文件中进行转换
|
|
309
309
|
if (mapping == true) {
|
|
310
|
-
detailinfo = getDetailInfo(dataKey);
|
|
310
|
+
detailinfo = getDetailInfo(req, dataKey);
|
|
311
311
|
if (!detailinfo) return { successed: false, errcode: -10, errmsg: `缺失${dataKey}对应的详情配置` };
|
|
312
312
|
///从Request中获取到用户提交的数据
|
|
313
313
|
resultItem = View2Data(req, detailinfo.fields, "update");
|
package/package.json
CHANGED
|
@@ -35,7 +35,7 @@ class ExcelUtility {
|
|
|
35
35
|
});
|
|
36
36
|
fReadStream = fs.createReadStream(buffer);
|
|
37
37
|
fReadStream.on("data", (chunk) => res.write(chunk, "binary"));
|
|
38
|
-
fReadStream.on("end",
|
|
38
|
+
fReadStream.on("end", () => {
|
|
39
39
|
res.end();
|
|
40
40
|
});
|
|
41
41
|
}
|
|
@@ -43,23 +43,17 @@ class ExcelUtility {
|
|
|
43
43
|
async writeExcel(data, workSheetName) {
|
|
44
44
|
let sheetName = 'sheet1';
|
|
45
45
|
if (workSheetName == null) sheetName = workSheetName;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
fs.writeFileSync(fileName, buffer, { 'flag': 'w' });
|
|
58
|
-
return { successed: true, fileName: randomFile };
|
|
59
|
-
}
|
|
60
|
-
catch (err) {
|
|
61
|
-
return { successed: false, errorcode: 1, errmessage: err };
|
|
62
|
-
}
|
|
46
|
+
let randomFile = uuid.v4() + '.xlsx';
|
|
47
|
+
let fileName = path.resolve(this.exportFolder, randomFile);
|
|
48
|
+
let _saveDir = path.dirname(fileName);
|
|
49
|
+
///创建本地文件夹
|
|
50
|
+
if (!this.mkdirsSync(_saveDir)) return { success: false, errorcode: 1, errmessage: 'create folder failed!' };
|
|
51
|
+
const buffer = xlsx.build([{ name: workSheetName, data: data }]);
|
|
52
|
+
return new Promise(reslove => {
|
|
53
|
+
return fs.writeFile(fileName, buffer, (err) => {
|
|
54
|
+
return reslove({ successed: !err, errmessage: err, fileName:randomFile })
|
|
55
|
+
})
|
|
56
|
+
})
|
|
63
57
|
}
|
|
64
58
|
///导出记录集到Excel,写入
|
|
65
59
|
///dataRow :记录集
|
|
@@ -69,7 +63,7 @@ class ExcelUtility {
|
|
|
69
63
|
let _instance = this;
|
|
70
64
|
//var setting = exportConfig ? excelConfig[exportConfig] : null;
|
|
71
65
|
let setting = exportConfig ? _instance.excelConfig[exportConfig] : null;
|
|
72
|
-
let dataBuffer = [],worksheetName = "sheet1", fieldKey = [], titleRow = [];
|
|
66
|
+
let dataBuffer = [], worksheetName = "sheet1", fieldKey = [], titleRow = [];
|
|
73
67
|
if (setting != null) {
|
|
74
68
|
worksheetName = setting.worksheet == null ? "sheet1" : setting.worksheet;
|
|
75
69
|
////第一行导出标题行
|
|
@@ -116,8 +110,8 @@ class ExcelUtility {
|
|
|
116
110
|
*/
|
|
117
111
|
mkdirsSync(dirpath, mode) {
|
|
118
112
|
if (!fs.existsSync(dirpath)) {
|
|
119
|
-
|
|
120
|
-
|
|
113
|
+
let pathtmp;
|
|
114
|
+
const splitPath = dirpath.split(path.sep);
|
|
121
115
|
for (var nLoop = 0; nLoop < splitPath.length; nLoop++) {
|
|
122
116
|
var dirname = splitPath[nLoop];
|
|
123
117
|
if (dirname.length == 0) {
|
|
@@ -149,10 +149,11 @@ module.exports.getListInfo = (req, dataKey, cfgType = 0, dao) => {
|
|
|
149
149
|
* 详细页面请求上下文中获取需要的信息
|
|
150
150
|
* 如Page ,PageSize , Sort 等等
|
|
151
151
|
*/
|
|
152
|
-
module.exports.getDetailInfo = (dataKey) => {
|
|
152
|
+
module.exports.getDetailInfo = (req,dataKey) => {
|
|
153
153
|
if (dataKey) {
|
|
154
154
|
const dataConfig = dataconfig.getConfig(dataKey);
|
|
155
155
|
if (dataConfig && dataConfig.detail) {
|
|
156
|
+
req.dataConfig = dataConfig;
|
|
156
157
|
const { primary, field: fields, primaryIsAutoIncrease } = dataConfig.detail;
|
|
157
158
|
return { primary, fields, autoincrease: primaryIsAutoIncrease }
|
|
158
159
|
}
|