crabatool 1.0.390 → 1.0.393
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/apis/homeai.js +82 -12
- package/lib/utils.js +3 -1
- package/package.json +1 -1
- package/tool/install.js +10 -2
package/apis/homeai.js
CHANGED
|
@@ -20,6 +20,7 @@ var funcList = {
|
|
|
20
20
|
'修改菜单': '_modifyMenuItem',
|
|
21
21
|
'表生页': '_doExcel',
|
|
22
22
|
'文生页': '_createPage',
|
|
23
|
+
'AI报表': '_createPage',
|
|
23
24
|
'新建页面': '_createPage',
|
|
24
25
|
'新建弹窗': '_createPage',
|
|
25
26
|
'修改页面': '_createPage'
|
|
@@ -30,6 +31,7 @@ class homeai {
|
|
|
30
31
|
return path.join(req.app.webPath, 'data/menus.json');
|
|
31
32
|
}
|
|
32
33
|
|
|
34
|
+
|
|
33
35
|
async execute(req, res) {
|
|
34
36
|
var body = utils.getReqBody(req);
|
|
35
37
|
var text = body.text;
|
|
@@ -75,7 +77,7 @@ class homeai {
|
|
|
75
77
|
menus.push(item);
|
|
76
78
|
} else {
|
|
77
79
|
// a1之后新建a2,a3
|
|
78
|
-
var targetItem = menus.filter(function(item) {
|
|
80
|
+
var targetItem = menus.filter(function (item) {
|
|
79
81
|
return item.text == firstText;
|
|
80
82
|
})[0];
|
|
81
83
|
|
|
@@ -133,7 +135,7 @@ class homeai {
|
|
|
133
135
|
for (var i = 0; i < items.length; i++) {
|
|
134
136
|
var itext = items[i];
|
|
135
137
|
|
|
136
|
-
menus = menus.filter(function(item) {
|
|
138
|
+
menus = menus.filter(function (item) {
|
|
137
139
|
return item.text != itext;
|
|
138
140
|
});
|
|
139
141
|
// 先不管子菜单了
|
|
@@ -169,7 +171,7 @@ class homeai {
|
|
|
169
171
|
return;
|
|
170
172
|
}
|
|
171
173
|
|
|
172
|
-
menus.forEach(function(item) {
|
|
174
|
+
menus.forEach(function (item) {
|
|
173
175
|
if (item.text == items[0]) {
|
|
174
176
|
item.text = items[1];
|
|
175
177
|
}
|
|
@@ -205,7 +207,7 @@ class homeai {
|
|
|
205
207
|
}
|
|
206
208
|
|
|
207
209
|
var that = this;
|
|
208
|
-
this._postAI('excelToPage', data, function(resdata, error) {
|
|
210
|
+
this._postAI('excelToPage', data, function (resdata, error) {
|
|
209
211
|
if (resdata !== false && resdata.code == 200) {
|
|
210
212
|
that._saveExcelData(itemText, resdata.data, req, res);
|
|
211
213
|
} else {
|
|
@@ -235,7 +237,7 @@ class homeai {
|
|
|
235
237
|
var menus = this._getMenus(req);
|
|
236
238
|
|
|
237
239
|
// 找菜单
|
|
238
|
-
var item = menus.filter(function(item) {
|
|
240
|
+
var item = menus.filter(function (item) {
|
|
239
241
|
return item.text == itemText;
|
|
240
242
|
})[0];
|
|
241
243
|
|
|
@@ -284,7 +286,7 @@ class homeai {
|
|
|
284
286
|
menus.push(item);
|
|
285
287
|
} else {
|
|
286
288
|
// 找菜单
|
|
287
|
-
var item = menus.filter(function(item) {
|
|
289
|
+
var item = menus.filter(function (item) {
|
|
288
290
|
return item.text == itemText;
|
|
289
291
|
})[0];
|
|
290
292
|
|
|
@@ -306,7 +308,7 @@ class homeai {
|
|
|
306
308
|
this._buildPage(data, req);
|
|
307
309
|
|
|
308
310
|
// 输出
|
|
309
|
-
utils.end(res, {
|
|
311
|
+
res && utils.end(res, {
|
|
310
312
|
code: 200,
|
|
311
313
|
msg: '操作成功',
|
|
312
314
|
type: 'menu',
|
|
@@ -337,15 +339,23 @@ class homeai {
|
|
|
337
339
|
}
|
|
338
340
|
|
|
339
341
|
var type = '';
|
|
342
|
+
var method = 'expressToPage';
|
|
343
|
+
var cb = this.createPageSuccess;
|
|
340
344
|
if (name == '文生页') {
|
|
341
345
|
type = 'list'; // 基础资料,列表页面
|
|
346
|
+
} else if (name == 'AI报表') {
|
|
347
|
+
method = 'expressToReport'
|
|
348
|
+
cb = this.createReportSuccess;
|
|
349
|
+
type = "report";
|
|
350
|
+
name = '文生页';
|
|
342
351
|
}
|
|
343
352
|
|
|
344
353
|
var that = this;
|
|
345
354
|
var pageName = crabatool.stringUtils.getPinyinCode(itemName) + crabatool.cuid.newCuid(); // 防止同名菜单重复页面
|
|
346
|
-
this._postAI(
|
|
355
|
+
this._postAI(method, { express: express, name: itemName, enname: pageName, type: type }, function (resdata, error) {
|
|
347
356
|
if (resdata !== false && resdata.code == 200) {
|
|
348
|
-
|
|
357
|
+
resdata.data.enname = pageName;
|
|
358
|
+
cb.apply(that, [name, itemName, resdata, req, res])
|
|
349
359
|
} else {
|
|
350
360
|
utils.end(res, {
|
|
351
361
|
code: 500,
|
|
@@ -355,6 +365,66 @@ class homeai {
|
|
|
355
365
|
});
|
|
356
366
|
}
|
|
357
367
|
|
|
368
|
+
createPageSuccess(name, itemName, resdata, req, res) {
|
|
369
|
+
this._savePage(name, itemName, resdata.data, req, res);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
getReportProgress(obj, count) {
|
|
374
|
+
count = count ? count : 1;
|
|
375
|
+
if (count > 1000) {
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
var _this = this;
|
|
379
|
+
this._postAI('getReportProgress', { id: obj.id }, function (resdata, error) {
|
|
380
|
+
if (resdata !== false && resdata.data && resdata.data.status == 'fail') {
|
|
381
|
+
//明确失败了
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
if (resdata !== false && resdata.code == 200) {
|
|
385
|
+
var data = {
|
|
386
|
+
data: JSON.parse(JSON.stringify(resdata.data))
|
|
387
|
+
};
|
|
388
|
+
data.data.enname = obj.enname;
|
|
389
|
+
//成功后更新文件
|
|
390
|
+
_this.createReportSuccess(obj.name, obj.itemName, data, {
|
|
391
|
+
app: {
|
|
392
|
+
webPath: obj.webPath
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
} else {
|
|
396
|
+
//文件还没生成,继续请求
|
|
397
|
+
setTimeout(function () {
|
|
398
|
+
_this.getReportProgress(obj, count + 1);
|
|
399
|
+
}, 2000);
|
|
400
|
+
}
|
|
401
|
+
})
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
createReportSuccess(name, itemName, resdata, req, res) {
|
|
405
|
+
if (resdata.data.id) {
|
|
406
|
+
//存在id,说明生成的是临时页面,真正页面还没完全生成,需要循环去获取
|
|
407
|
+
this._savePage(name, itemName, resdata.data, req, res);
|
|
408
|
+
this.getReportProgress({
|
|
409
|
+
id: resdata.data.id,
|
|
410
|
+
enname: resdata.data.enname,
|
|
411
|
+
name: name,
|
|
412
|
+
itemName: itemName,
|
|
413
|
+
webPath: req.app.webPath
|
|
414
|
+
})
|
|
415
|
+
} else {
|
|
416
|
+
utils.mkdirsSync(utils.join(req.app.webPath, "../ai/jsCode/"), true)
|
|
417
|
+
var filePath = utils.join(req.app.webPath, `../ai/jsCode/${resdata.data.enname}.text`)
|
|
418
|
+
fs.writeFileSync(filePath, resdata.data.jsCode);
|
|
419
|
+
utils.mkdirsSync(utils.join(req.app.webPath, "../ai/reportConfig/"), true)
|
|
420
|
+
filePath = utils.join(req.app.webPath, `../ai/reportConfig/${resdata.data.enname}.text`)
|
|
421
|
+
fs.writeFileSync(filePath, resdata.data.reportConfig);
|
|
422
|
+
if (resdata.data.renderPage) {
|
|
423
|
+
this._savePage(name, itemName, resdata.data, req, res);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
358
428
|
_buildChildPage(pdata, req) {
|
|
359
429
|
var datas = pdata.childInfos;
|
|
360
430
|
if (!datas || datas.length == 0) {
|
|
@@ -362,7 +432,7 @@ class homeai {
|
|
|
362
432
|
}
|
|
363
433
|
|
|
364
434
|
var that = this;
|
|
365
|
-
datas.forEach(function(data) {
|
|
435
|
+
datas.forEach(function (data) {
|
|
366
436
|
that._buildPage(data, req);
|
|
367
437
|
});
|
|
368
438
|
}
|
|
@@ -404,11 +474,11 @@ class homeai {
|
|
|
404
474
|
url: aiHost + url,
|
|
405
475
|
data: data,
|
|
406
476
|
headers: { 'Content-Type': 'application/json' }
|
|
407
|
-
}).then(function(response) {
|
|
477
|
+
}).then(function (response) {
|
|
408
478
|
//console.log("执行成功", response.data);
|
|
409
479
|
|
|
410
480
|
cb(response.data);
|
|
411
|
-
}).catch(function(error) {
|
|
481
|
+
}).catch(function (error) {
|
|
412
482
|
console.log("执行失败:" + error);
|
|
413
483
|
cb(false, error);
|
|
414
484
|
});
|
package/lib/utils.js
CHANGED
|
@@ -92,7 +92,9 @@ class Utils {
|
|
|
92
92
|
var stat = fs.statSync(filePath);
|
|
93
93
|
if (stat.isDirectory()) {
|
|
94
94
|
var basename = path.basename(fileName);
|
|
95
|
-
if (basename.startsWith(name))
|
|
95
|
+
if (basename.startsWith(name)) {
|
|
96
|
+
return basename;
|
|
97
|
+
}
|
|
96
98
|
}
|
|
97
99
|
}
|
|
98
100
|
return "";
|
package/package.json
CHANGED
package/tool/install.js
CHANGED
|
@@ -17,6 +17,8 @@ class Install {
|
|
|
17
17
|
//return console.log('本机没有APPDATA目录,本功能暂不支持mac');
|
|
18
18
|
p1 = path.join(process.env.HOME, "/Library/Application Support"); // mac下面
|
|
19
19
|
}
|
|
20
|
+
console.log(p1);
|
|
21
|
+
|
|
20
22
|
var JetBrains = path.join(p1, "JetBrains");
|
|
21
23
|
if (fs.existsSync(JetBrains)) {
|
|
22
24
|
var folderName = utils.searchFolder("IntelliJIdea", JetBrains);
|
|
@@ -24,6 +26,12 @@ class Install {
|
|
|
24
26
|
this.doIDEA(path.join(JetBrains, folderName));
|
|
25
27
|
return;
|
|
26
28
|
}
|
|
29
|
+
|
|
30
|
+
var folderName = utils.searchFolder("Idea", JetBrains);
|
|
31
|
+
if (folderName != "") {
|
|
32
|
+
this.doIDEA(path.join(JetBrains, folderName));
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
27
35
|
}
|
|
28
36
|
|
|
29
37
|
|
|
@@ -115,7 +123,7 @@ class Install {
|
|
|
115
123
|
xml = xmljs.json2xml(xmldata, { compact: true, ignoreComment: true, spaces: 2 });
|
|
116
124
|
fs.writeFileSync(fileTypes, xml);
|
|
117
125
|
}
|
|
118
|
-
console.log("Idea
|
|
126
|
+
console.log("Idea环境安装/更新完成,请重启idea!");
|
|
119
127
|
}
|
|
120
128
|
|
|
121
129
|
installVscode() {
|
|
@@ -174,7 +182,7 @@ class Install {
|
|
|
174
182
|
// 第二步:下载xsd文件
|
|
175
183
|
utils.downloadFile(utils.joinPath(config.SourceHost, "/setup/Craba.UI.xsd"), path.join(extPath, "Craba.UI.xsd"));
|
|
176
184
|
|
|
177
|
-
console.log("vscode
|
|
185
|
+
console.log("vscode插件安装/更新完成,请重启vscode!");
|
|
178
186
|
}
|
|
179
187
|
}
|
|
180
188
|
|