crabatool 1.0.414 → 1.0.415

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/data.js CHANGED
@@ -162,7 +162,8 @@ class data {
162
162
  }
163
163
 
164
164
  async reverseData(req, pageName, body) {
165
- var oldEntity = await this._getDb(req).get(body.name, body.data.id);
165
+ var db = this._getDb(req);
166
+ var oldEntity = await db.get(body.name, body.data.id);
166
167
  if (!oldEntity) {
167
168
  crabatool.utils.end(res, {
168
169
  code: 404,
@@ -170,6 +171,8 @@ class data {
170
171
  });
171
172
  return;
172
173
  }
174
+
175
+ await this.fillData(body.name, [oldEntity], db, true);
173
176
  //退回联动老数据
174
177
  var rt = await this.pageSaveToDataLinkage(req, body.name, pageName, oldEntity, null, true);
175
178
  return {
@@ -297,7 +300,7 @@ class data {
297
300
  //从原始数据中获取对应字段的数据
298
301
  var targetRef = _this.findFormateItem(item.filter.refField)
299
302
  var targetRefField = _this.findFormateItem(`#[${item.ref}.${item.field}]`)
300
- var targetValue = _this.findItemMapData(name, crabatool.stringUtils.getFullPinyinCode(item.ref), data, new Set([...targetRef, ...targetRefField]));
303
+ var targetValue = _this.findItemMapData(name, crabatool.stringUtils.getFullPinyinCode(item.ref), data, new Set([...targetRef, ...targetRefField, `${item.ref}.id`]));
301
304
  var refFieldName = this.matchFields(item.filter.refField)[0];
302
305
  var refFieldNamePy = crabatool.stringUtils.getFullPinyinCode(refFieldName);
303
306
  var targetArray = refFieldNamePy.split('.')
@@ -325,7 +328,13 @@ class data {
325
328
  //传入了老数据,当前计算的值可以直接取老数据的对应值,因为它已经排除本单
326
329
  var oldDataTemp = oldData[name][refNamePy];
327
330
  if (oldDataTemp instanceof Array) {
328
- target[refNamePy][fieldNamePy] = oldDataTemp[0][fieldNamePy];//强制取第一行
331
+ target[refNamePy][fieldNamePy] = 0;
332
+ for(var m = 0 ; m < oldDataTemp.length; m++){
333
+ if(oldDataTemp[m].id == target[refNamePy].id){
334
+ target[refNamePy][fieldNamePy] = oldDataTemp[m][fieldNamePy];
335
+ break;
336
+ }
337
+ }
329
338
  } else {
330
339
  target[refNamePy][fieldNamePy] = oldDataTemp[fieldNamePy] ? oldDataTemp[fieldNamePy] : 0;
331
340
  }
package/lib/jsoncrud.js CHANGED
@@ -127,7 +127,7 @@ class JSONCRUD {
127
127
  const end = start + pageSize
128
128
 
129
129
  return {
130
- data: sorted.slice(start, end),
130
+ data: JSON.parse(JSON.stringify(sorted.slice(start, end))),
131
131
  pageData: {
132
132
  count: allData.length,
133
133
  page,
@@ -158,7 +158,7 @@ class JSONCRUD {
158
158
 
159
159
  const index = this.entities[entityName].data.findIndex(item => item.id === id)
160
160
  if (index === -1) return null
161
- return this.entities[entityName].data[index]
161
+ return JSON.parse(JSON.stringify(this.entities[entityName].data[index]))
162
162
  }
163
163
 
164
164
  async getByField(entityName, field, value) {
@@ -167,7 +167,7 @@ class JSONCRUD {
167
167
 
168
168
  const index = this.entities[entityName].data.findIndex(item => item[field] === value)
169
169
  if (index === -1) return null
170
- return this.entities[entityName].data[index]
170
+ return JSON.parse(JSON.stringify(this.entities[entityName].data[index]))
171
171
  }
172
172
 
173
173
  async update(entityName, id, updates) {
@@ -183,7 +183,7 @@ class JSONCRUD {
183
183
  updatedAt: new Date().toISOString()
184
184
  }
185
185
  await this.persist(entityName)
186
- return this.entities[entityName].data[index]
186
+ return JSON.parse(JSON.stringify(this.entities[entityName].data[index]))
187
187
  }
188
188
 
189
189
  async batchUpdate(entityName, items) {
package/lib/server.js CHANGED
@@ -92,6 +92,11 @@ function createServer(app, options) {
92
92
  app.use(utils.rewriteCrabaJs);
93
93
  }
94
94
 
95
+ // 统一拦截login.html
96
+ if (config.modName && !config.localLogin) {
97
+ app.use(utils.rewriteLoginHTML);
98
+ }
99
+
95
100
  // 指定静态文件目录
96
101
  var webPath = config.webPath;
97
102
  if (options) {
@@ -111,7 +116,7 @@ function createServer(app, options) {
111
116
  res.setHeader('Content-Type', 'text/html; charset=utf-8'); // 当做文本输出,才能显示到iframe中
112
117
  }
113
118
  var name = path.basename(pathname);
114
- if (name == 'index.html') {
119
+ if (name == 'index.html' || name == 'login.html') {
115
120
  res.setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate');
116
121
  res.setHeader('Pragma', 'no-cache');
117
122
  res.setHeader('Expires', '0');
package/lib/utils.js CHANGED
@@ -527,6 +527,43 @@ class Utils {
527
527
  res.end(content);
528
528
  }
529
529
 
530
+
531
+ rewriteLoginHTML(req, res, next) {
532
+ var url = req.originalUrl;
533
+ if (url.startsWith('/login.html')) {
534
+ var htmlPath = utils.join(__dirname, '../res/login.html');
535
+ var content = fs.readFileSync(htmlPath).toString();
536
+ content = content.replaceAll('${modName}', config.modName);
537
+
538
+ res.setHeader('Content-Type', 'text/html; charset=utf-8'); // 当做文本输出,才能显示到iframe中
539
+ res.setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate');
540
+ res.setHeader('Pragma', 'no-cache');
541
+ res.setHeader('Expires', '0');
542
+ res.end(content);
543
+ } else if (url.startsWith('/crabatool/Login.gspx')) {
544
+ var htmlPath = utils.join(__dirname, '../res/Login.gspx');
545
+ var content = fs.readFileSync(htmlPath).toString();
546
+ content = content.replaceAll('${modName}', config.modName);
547
+
548
+ res.setHeader('Content-Type', 'text/plain; charset=utf-8'); // 当做文本输出,才能显示到iframe中
549
+ res.setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate');
550
+ res.setHeader('Pragma', 'no-cache');
551
+ res.setHeader('Expires', '0');
552
+ res.end(content);
553
+ } else if (url.startsWith('/crabatool/Login.js')) {
554
+ var htmlPath = utils.join(__dirname, '../res/Login.js');
555
+ var content = fs.readFileSync(htmlPath).toString();
556
+ content = content.replaceAll('${modName}', config.modName);
557
+
558
+ res.setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate');
559
+ res.setHeader('Pragma', 'no-cache');
560
+ res.setHeader('Expires', '0');
561
+ res.end(content);
562
+ } else {
563
+ next();
564
+ }
565
+ }
566
+
530
567
  getFiles(options, fileList) {
531
568
  var exts = options.exts;
532
569
  var source = options.source;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crabatool",
3
- "version": "1.0.414",
3
+ "version": "1.0.415",
4
4
  "description": "crabatool",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -28,7 +28,10 @@
28
28
  "makeHash2": "node run.js -makeHash -webPath ./test/ -modName craba -files ./test/ -exts .js -outJson ./hash2.json -hashName sha384",
29
29
  "pageHash": "node run.js -pageHash /Test/TestMasterDetail.gspx",
30
30
  "addVersion": "node run.js -addVersion -file F:\\basicweb\\www\\index.html -exp AUTOVERSION",
31
- "gspxHash": "node run.js -gspxHash -webPath F:\\Beefun\\srcs\\Beefun"
31
+ "gspxHash": "node run.js -gspxHash -webPath F:\\Beefun\\srcs\\Beefun",
32
+ "runShell": "node run.js -run -webPath F:\\shell-gerrit\\web\\src\\main\\resources\\static\\shell\\ -port 10000 -modName shell",
33
+ "runShellLocal": "node run.js -run -webPath F:\\shell-gerrit\\web\\src\\main\\resources\\static\\shell\\ -port 10000 -modName shell -localLogin true",
34
+ "runJxc": "node run.js -run -webPath F:\\jxc\\jxc-web\\src\\main\\resources\\static\\jxc\\ -port 10001 -modName jxc"
32
35
  },
33
36
  "author": "wssf",
34
37
  "dependencies": {
package/res/Login.gspx ADDED
@@ -0,0 +1,34 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Page xmlns="Craba.UI" Title="NGP开发环境统一登录入口" ActionType="crabatool.LoginAction, crabatool/Login.js" DataSource='${formData}'>
3
+ <FlexColumn CssClass='FlexCenter MainBg'>
4
+ <FlowPanel Caption='Ngp模块登录' CssClass='VertItem' LayoutDirection='Vert' ItemLabelWidth='70' ItemCssClass='FlexAuto'>
5
+ <TextEdit Label='公司名称:' DataField='companyName' Required="true" />
6
+ <TextEdit Label='职员名称:' DataField='employeeName' Required="true" />
7
+ <DropDownEdit Label='指定产品:' DataField='productId' DataSource='${formData.products}' DataTextField='name' DataValueField='id' Required="true" OnChange="doChangeProduct" />
8
+ <HBlock Label='服务版本:'>
9
+ <TextEdit DataField='deploy' CssClass='FlexAuto' NullDisplayText='不填写则使用默认账套账本' />
10
+ <DropDownEdit DataField='productDeploy' DataSource="${formData.productDeploys}" DataTextField='deployName' DataValueField='deployName' />
11
+ </HBlock>
12
+ <TextEdit Label='本地端口:' DataField='localPort' Required="true" />
13
+
14
+ <Grid ID='grid' DataField="routes" AutoMaxRowCount="8" AllowConfig='false' ReadOnly='false'>
15
+ <TextColumn Caption="模块名称" DataField="serverName" AllowStretch='true' NullDisplayText='微服务名称' />
16
+ <TextColumn Caption="Ip" DataField="serverIp" AllowStretch='true' NullDisplayText='微服务IP地址' />
17
+ <TextColumn Caption="端口" DataField="serverPort" AllowStretch='true' NullDisplayText='微服务端口号' />
18
+ <RowDeleteColumn Caption="操作" />
19
+ </Grid>
20
+
21
+ <FlexBlock CssClass='BottomBlock FlexRight'>
22
+ <Button Text='添加路由' OnClick='addRoute' />
23
+ <Button Text='登录' CssClass='SpecialButton' OnClick="doLogin" />
24
+ </FlexBlock>
25
+ </FlowPanel>
26
+ </FlexColumn>
27
+
28
+ <Style>
29
+ .MainBg{background-color: #374979;}
30
+ .MainBg .FlowPanel{border-radius:8px;box-shadow:0 0 18px #111;width:600px;}
31
+ .MainBg .FlowPanel .FlowItem{padding:10px 20px;margin:0;}
32
+ .MainBg .GridBlock{margin:10px 20px}
33
+ </Style>
34
+ </Page>
package/res/Login.js ADDED
@@ -0,0 +1,155 @@
1
+ Type.registerNamespace('crabatool');
2
+ crabatool.LoginAction = function() {
3
+ crabatool.LoginAction.initializeBase(this);
4
+ };
5
+
6
+ crabatool.LoginAction.prototype = {
7
+ context: function(cb) {
8
+ this.initData(cb);
9
+ },
10
+
11
+ initialize: function LoginAction$initialize() {
12
+ crabatool.LoginAction.callBaseMethod(this, 'initialize');
13
+ },
14
+
15
+ initData: function(cb) {
16
+ var data = {
17
+ companyName: "",
18
+ employeeName: "",
19
+ productId: "0",
20
+ deploy: "",
21
+ localPort: "",
22
+ routes: [],
23
+ products: [],
24
+ deploys: {},
25
+ productDeploys: [],
26
+ productDeploy: ""
27
+ };
28
+ var formData = { formData: data }; // 窗体数据
29
+
30
+ var routes = localStorage.getItem("routes");
31
+ if (routes) {
32
+ routes = JSON.parse(routes);
33
+ data.routes = routes;
34
+ }
35
+
36
+ var user = localStorage.getItem("user");
37
+ if (user) {
38
+ user = JSON.parse(user);
39
+ data.companyName = user.companyName;
40
+ data.employeeName = user.employeeName;
41
+ data.productId = user.productId;
42
+ data.deploy = user.deploy;
43
+ data.localPort = user.port || user.localPort || "";
44
+ data.productDeploy = user.productDeploy || "";
45
+ }
46
+
47
+ var route = localStorage.getItem("route");
48
+ if (route) {
49
+ route = JSON.parse(route);
50
+ this.setRoute(route, data);
51
+ this.login();
52
+ this.end(); // 不继续处理Login.gspx
53
+ return;
54
+ }
55
+
56
+ var that = this;
57
+ $common.ajax({
58
+ url: 'http://172.17.0.237:56789/ngp/auth/init',
59
+ type: 'GET',
60
+ success: function(res) {
61
+ if (res.code != "200") {
62
+ $common.alertError("初始化信息失败");
63
+ that.end();
64
+ return;
65
+ }
66
+
67
+ data.deploys = res.data.deploys;
68
+ data.products = res.data.products;
69
+ console.log(data.productId);
70
+ data.productDeploys = res.data.deploys[data.productId];
71
+ cb(formData);
72
+ },
73
+ error: function() {
74
+ $common.alertError("网络请求失败");
75
+ that.end();
76
+ }
77
+ });
78
+ },
79
+
80
+ dispose: function() {
81
+ crabatool.LoginAction.callBaseMethod(this, 'dispose');
82
+ },
83
+
84
+ setRoute: function(route, data) {
85
+ route.deploy = data.deploy || (data.productDeploy || route.deploy);
86
+ route.productId = (data.productId == "0") ? route.productId : data.productId;
87
+ var debugMs = {};
88
+ for (var key in route) {
89
+ debugMs[key] = route[key];
90
+ }
91
+ debugMs.aloneDeploy = '${modName}';
92
+ debugMs.gateway = "http://eshop.gateway.ngp.wsgjp.com.cn";
93
+ debugMs.aloneServer = "http://" + location.hostname + ":" + data.localPort;
94
+ $ms.router = {//设置请求路由
95
+ debugMs: debugMs,
96
+ 'ngp-authorization': 'jwt',
97
+ 'ngp-router': 'ngprt'
98
+ };
99
+ if (data.routes.length > 0) {
100
+ var server = {};
101
+ for (var i = 0; i < data.routes.length; i++) {
102
+ var r = data.routes[i];
103
+ server[r.serverName] = r.serverIp + ":" + r.serverPort;
104
+ }
105
+ $ms.server = server;
106
+ }
107
+ var cookieStr = JSON.stringify(route);
108
+ $common.setCookieNoEscape("ngp-route", cookieStr);
109
+ localStorage.setItem("route", JSON.stringify(route));
110
+ },
111
+ login: function() {
112
+ $common.setCookieNoEscape('ngp-authorization', 'jwt');
113
+ $common.setCookieNoEscape('ngp-router', 'ngprt');
114
+ $common.setCookie('debugMs', JSON.stringify($ms.router.debugMs));
115
+
116
+ location.reload();
117
+ },
118
+ doLogin: function(sender) {
119
+ var user = this.get_form().saveData({clear:true});
120
+ var data = {
121
+ companyName: user.companyName,
122
+ userName: user.employeeName
123
+ };
124
+ localStorage.setItem("user", JSON.stringify(user));
125
+ localStorage.setItem("routes", JSON.stringify(user.routes));
126
+
127
+ var that = this;
128
+ $common.ajax({
129
+ url: "http://172.17.0.237:56789/ngp/auth/login",
130
+ data: data,
131
+ success: function(res) {
132
+ if (res.code != "200") {
133
+ $common.alertError("登录失败,请检查公司名称和职员名称是否正确");
134
+ } else {
135
+ that.setRoute(res.data, user);
136
+ that.login();
137
+ }
138
+ },
139
+ error: function() {
140
+ $common.alertError("网络请求失败");
141
+ }
142
+
143
+ });
144
+ },
145
+ addRoute: function(sender) {
146
+ this.get_form().grid.appendRowData({});
147
+ },
148
+ doChangeProduct: function(sender) {
149
+ var pid = sender.get_value();
150
+ var deploys = this.get_context('formData').deploys;
151
+ var pdeploys = deploys[pid];
152
+ sender.get_form().productDeploy.set_items(pdeploys);
153
+ }
154
+ };
155
+ crabatool.LoginAction.registerClass('crabatool.LoginAction', Sys.UI.PageAction);
package/res/login.html ADDED
@@ -0,0 +1,102 @@
1
+ <!DOCTYPE html>
2
+ <html lang="zh-cn" translate="no">
3
+
4
+ <head>
5
+ <title>NGP开发环境统一登录入口</title>
6
+ <meta http-equiv="Content-Type" content="text/html; charset=utf8" />
7
+ <meta http-equiv="X-UA-Compatible" content="IE=edge" />
8
+ <link rel="shortcut icon" type="image/x-icon" href="${modName}/favicon.ico" />
9
+ </head>
10
+
11
+ <body>
12
+ <script>
13
+ var modeName = '${modName}'; // 按各组的模块名称修改
14
+
15
+ function startPage() { // 供agency内部调用
16
+ var authorization = $common.getCookie('ngp-authorization');
17
+ var ngp_route = $common.getCookie('ngp-route');
18
+ if (authorization && ngp_route) {
19
+ $ms.router = {//设置请求路由
20
+ debugMs: JSON.parse($common.getCookie('debugMs')),
21
+ 'ngp-authorization': 'jwt',
22
+ 'ngp-router': 'ngprt'
23
+ };
24
+
25
+ var routes = localStorage.getItem("routes");
26
+ if (routes) {
27
+ routes = JSON.parse(routes);
28
+ if (routes.length > 0) {
29
+ var server = {};
30
+ for (var i = 0; i < routes.length; i++) {
31
+ var r = routes[i];
32
+ server[r.serverName] = r.serverIp + ":" + r.serverPort;
33
+ }
34
+ $ms.server = server;
35
+ }
36
+ }
37
+
38
+ var srcs = [];
39
+ srcs.push('shell/js/help.plug.js?rv=' + Math.random());
40
+ srcs.push('shell/js/init.js?rv=' + Math.random());
41
+ $common.loadScript(srcs, function() {
42
+ showMainPage();
43
+ });
44
+ return;
45
+ }
46
+ showLoginPage();
47
+ }
48
+
49
+ function showMainPage() {
50
+ $skin.loadCss(modeName + '/skins/craba.min.css,shell/skins/shell.css', 'login', function() {
51
+ $craba.run(modeName + '/Main.gspx', modeName);
52
+ createLoginBtn();
53
+ });
54
+ }
55
+
56
+ function showLoginPage() {
57
+ $skin.loadCss(modeName + '/skins/craba.min.css', 'login', function() {
58
+ $craba.run('crabatool/Login.gspx', modeName);
59
+ });
60
+ }
61
+
62
+ function createLoginBtn() {
63
+ var btn = $common.createClassDiv('Button');
64
+ btn.innerText = '重新登录';
65
+ btn.style.cssText = 'z-index: 9999;font-weight: bold;background-color:#03abf5;border:none;position:fixed;bottom:5px;right:5px;';
66
+ document.body.appendChild(btn);
67
+ $common.addClickHandler(btn, function() {
68
+ localStorage.removeItem("route");
69
+ $common.removeCookie('ngp-authorization');
70
+ location.reload();
71
+ });
72
+ }
73
+
74
+ function loadScript(src, cb) {
75
+ var script = document.createElement('script');
76
+ script.type = 'text/javascript';
77
+ script.onload = script.onreadystatechange = function() {
78
+ if (!this.readyState || this.readyState === "loaded" || this.readyState === "complete") {
79
+ script.onload = script.onreadystatechange = script.onerror = null;
80
+ cb();
81
+ }
82
+ };
83
+ script.onerror = function() {
84
+ script.onload = script.onreadystatechange = script.onerror = null;
85
+ cb();
86
+ };
87
+ script.src = src;
88
+ document.getElementsByTagName('HEAD')[0].appendChild(script);
89
+ }
90
+
91
+ var agencyUrl = 'js/agency.js?vc=' + (new Date()).getTime(); // 加时间戳防止浏览器缓存
92
+ loadScript(agencyUrl, function() {
93
+ $agency.load(['js/craba.min.js',
94
+ 'js/crabaEx.min.js',
95
+ 'js/math.min.js',
96
+ 'js/crabaNgp.js'
97
+ ], {}, startPage); // 这里写死首页脚本,agency内部使用。所有脚本由agency内部版本号防止浏览器缓存
98
+ });
99
+ </script>
100
+ </body>
101
+
102
+ </html>
package/tool/start.js CHANGED
@@ -87,6 +87,8 @@ class Start {
87
87
  { name: '-abortUrl', type: '' },
88
88
  { name: '-reportHost', type: '' },
89
89
  { name: '-aiHost', type: '' },
90
+ { name: '-defaultPage', type: '' },
91
+ { name: '-localLogin', type: 'boolean' },
90
92
 
91
93
  { name: '-ignoreCheck', type: 'array' },
92
94
  { name: '-childModList', type: 'array' },