@lcap/nasl 0.3.9 → 0.3.10-beta.nocache1

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.
Files changed (147) hide show
  1. package/out/service/create/errHandles.js +7 -2
  2. package/out/service/create/errHandles.js.map +1 -1
  3. package/out/service/logic/logic.d.ts +27 -0
  4. package/out/service/logic/logic.js +20 -0
  5. package/out/service/logic/logic.js.map +1 -1
  6. package/out/service/page/element.d.ts +9 -0
  7. package/out/service/page/element.js +6 -0
  8. package/out/service/page/element.js.map +1 -1
  9. package/out/service/permission/api.d.ts +57 -0
  10. package/out/service/permission/api.js +41 -0
  11. package/out/service/permission/api.js.map +1 -0
  12. package/out/service/permission/index.d.ts +2 -0
  13. package/out/service/permission/index.js +17 -0
  14. package/out/service/permission/index.js.map +1 -0
  15. package/out/service/webFile/index.js +5 -0
  16. package/out/service/webFile/index.js.map +1 -1
  17. package/out/types/app/App.d.ts +4 -0
  18. package/out/types/app/App.js +30 -0
  19. package/out/types/app/App.js.map +1 -1
  20. package/out/types/app/Service.d.ts +2 -2
  21. package/out/types/app/Service.js +28 -3
  22. package/out/types/app/Service.js.map +1 -1
  23. package/out/types/cache.d.ts +6 -0
  24. package/out/types/cache.js +54 -0
  25. package/out/types/cache.js.map +1 -0
  26. package/out/types/common/Vertex.d.ts +25 -0
  27. package/out/types/common/Vertex.js +40 -0
  28. package/out/types/common/Vertex.js.map +1 -1
  29. package/out/types/data/Entity.js +1 -0
  30. package/out/types/data/Entity.js.map +1 -1
  31. package/out/types/data/Enum.d.ts +5 -0
  32. package/out/types/data/Enum.js +5 -0
  33. package/out/types/data/Enum.js.map +1 -1
  34. package/out/types/data/Interface.js +5 -3
  35. package/out/types/data/Interface.js.map +1 -1
  36. package/out/types/data/dataTypes.js +1 -1
  37. package/out/types/data/dataTypes.js.map +1 -1
  38. package/out/types/data/genBlock/genCreateBlock.js +5 -5
  39. package/out/types/data/genBlock/genCreateBlock.js.map +1 -1
  40. package/out/types/data/genBlock/genCurdBlock.js +3 -3
  41. package/out/types/data/genBlock/genCurdBlock.js.map +1 -1
  42. package/out/types/data/genBlock/genEnumSelectBlock.d.ts +1 -1
  43. package/out/types/data/genBlock/genEnumSelectBlock.js +2 -2
  44. package/out/types/data/genBlock/genEnumSelectBlock.js.map +1 -1
  45. package/out/types/data/genBlock/genGridViewBlock.js +12 -1
  46. package/out/types/data/genBlock/genGridViewBlock.js.map +1 -1
  47. package/out/types/data/genBlock/genListViewBlock.js +2 -2
  48. package/out/types/data/genBlock/genSelectBlock.js +2 -2
  49. package/out/types/data/genBlock/genTableBlock.js +14 -3
  50. package/out/types/data/genBlock/genTableBlock.js.map +1 -1
  51. package/out/types/data/genBlock/genUpdateBlock.js +5 -5
  52. package/out/types/data/genBlock/genUpdateBlock.js.map +1 -1
  53. package/out/types/data/systemTypes.js +47 -0
  54. package/out/types/data/systemTypes.js.map +1 -1
  55. package/out/types/enum.d.ts +6 -0
  56. package/out/types/enum.js +11 -0
  57. package/out/types/enum.js.map +1 -0
  58. package/out/types/generator/hotReload.d.ts +2 -0
  59. package/out/types/generator/hotReload.js +12 -1
  60. package/out/types/generator/hotReload.js.map +1 -1
  61. package/out/types/index.d.ts +5 -1
  62. package/out/types/index.js +8 -2
  63. package/out/types/index.js.map +1 -1
  64. package/out/types/logic/Logic.d.ts +28 -0
  65. package/out/types/logic/Logic.js +116 -31
  66. package/out/types/logic/Logic.js.map +1 -1
  67. package/out/types/logic/LogicItem.d.ts +1 -0
  68. package/out/types/logic/LogicItem.js +43 -24
  69. package/out/types/logic/LogicItem.js.map +1 -1
  70. package/out/types/logic/Param.d.ts +1 -0
  71. package/out/types/logic/Param.js +38 -20
  72. package/out/types/logic/Param.js.map +1 -1
  73. package/out/types/logic/Return.js +14 -19
  74. package/out/types/logic/Return.js.map +1 -1
  75. package/out/types/logic/Variable.js +14 -19
  76. package/out/types/logic/Variable.js.map +1 -1
  77. package/out/types/logic/translator.js +0 -2
  78. package/out/types/logic/translator.js.map +1 -1
  79. package/out/types/nuims/Nuims.d.ts +1 -1
  80. package/out/types/nuims/Nuims.js +11 -4
  81. package/out/types/nuims/Nuims.js.map +1 -1
  82. package/out/types/page/Element.d.ts +5 -0
  83. package/out/types/page/Element.js +115 -132
  84. package/out/types/page/Element.js.map +1 -1
  85. package/out/types/page/Event.js.map +1 -1
  86. package/out/types/page/Page.d.ts +1 -0
  87. package/out/types/page/Page.js +59 -27
  88. package/out/types/page/Page.js.map +1 -1
  89. package/out/types/page/View.d.ts +1 -1
  90. package/out/types/page/View.js +38 -33
  91. package/out/types/page/View.js.map +1 -1
  92. package/out/types/page/ViewParam.d.ts +1 -0
  93. package/out/types/page/ViewParam.js +23 -4
  94. package/out/types/page/ViewParam.js.map +1 -1
  95. package/out/types/page/ViewVariable.js +13 -18
  96. package/out/types/page/ViewVariable.js.map +1 -1
  97. package/out/types/permission/Permission.d.ts +41 -0
  98. package/out/types/permission/Permission.js +122 -0
  99. package/out/types/permission/Permission.js.map +1 -0
  100. package/package.json +1 -2
  101. package/src/service/create/errHandles.js +6 -2
  102. package/src/service/developPermission/api.js +37 -0
  103. package/src/service/developPermission/index.js +13 -0
  104. package/src/service/logic/logic.js +20 -0
  105. package/src/service/page/element.js +6 -0
  106. package/src/service/permission/api.js +38 -0
  107. package/src/service/permission/index.js +13 -0
  108. package/src/service/webFile/index.js +6 -1
  109. package/src/types/app/App.ts +34 -1
  110. package/src/types/app/Service.ts +32 -3
  111. package/src/types/cache.ts +50 -0
  112. package/src/types/common/Vertex.ts +30 -0
  113. package/src/types/data/Entity.ts +1 -0
  114. package/src/types/data/Enum.ts +5 -0
  115. package/src/types/data/Interface.ts +4 -3
  116. package/src/types/data/dataTypes.ts +1 -1
  117. package/src/types/data/genBlock/genCreateBlock.ts +5 -5
  118. package/src/types/data/genBlock/genCurdBlock.ts +3 -3
  119. package/src/types/data/genBlock/genEnumSelectBlock.ts +2 -2
  120. package/src/types/data/genBlock/genGridViewBlock.ts +12 -1
  121. package/src/types/data/genBlock/genListViewBlock.ts +2 -2
  122. package/src/types/data/genBlock/genSelectBlock.ts +2 -2
  123. package/src/types/data/genBlock/genTableBlock.ts +14 -3
  124. package/src/types/data/genBlock/genUpdateBlock.ts +5 -5
  125. package/src/types/data/systemTypes.ts +47 -0
  126. package/src/types/enum.ts +6 -0
  127. package/src/types/generator/hotReload.ts +10 -0
  128. package/src/types/index.ts +5 -1
  129. package/src/types/logic/Logic.ts +109 -28
  130. package/src/types/logic/LogicItem.ts +48 -28
  131. package/src/types/logic/Param.ts +26 -8
  132. package/src/types/logic/Return.ts +4 -9
  133. package/src/types/logic/Variable.ts +4 -8
  134. package/src/types/logic/translator.js +0 -4
  135. package/src/types/logic/translator_backup.js +5 -16
  136. package/src/types/nuims/Nuims.ts +11 -5
  137. package/src/types/page/Element.ts +64 -77
  138. package/src/types/page/Event.ts +0 -3
  139. package/src/types/page/Page.ts +73 -40
  140. package/src/types/page/View.ts +18 -12
  141. package/src/types/page/ViewParam.ts +22 -3
  142. package/src/types/page/ViewVariable.ts +4 -8
  143. package/src/types/page/dist/View.js +727 -0
  144. package/src/types/permission/Permission.ts +112 -0
  145. package/out/test/units/config.spec.d.ts +0 -1
  146. package/out/test/units/config.spec.js +0 -12
  147. package/out/test/units/config.spec.js.map +0 -1
@@ -1,8 +1,6 @@
1
1
  import generate from '@babel/generator';
2
2
  import * as babel from '@babel/core';
3
- import { TransforClientQuery as genQuery } from 'apollo-plugin-loader';
4
- import { Vertex, vertexesMap, utils } from '..';
5
- import { getQuerySchemaMap } from './tools';
3
+ import { Vertex, utils } from '..';
6
4
 
7
5
  function switchCase2If(cases) {
8
6
  const cas = cases.shift();
@@ -81,9 +79,7 @@ export default function (source) {
81
79
  } else if (node.type === 'MemberExpression') {
82
80
  return checkThis(node.object);
83
81
  } else if (node.type === 'CallExpression') {
84
- (node.arguments || []).forEach((arg) => {
85
- return checkThis(arg);
86
- });
82
+ (node.arguments || []).forEach((arg) => checkThis(arg));
87
83
  }
88
84
  }
89
85
  function safeGenerate(node) {
@@ -586,7 +582,7 @@ export default function (source) {
586
582
  const jsBlock_${index} = async () => {
587
583
  ${node.code}
588
584
  }
589
-
585
+
590
586
  await jsBlock_${index}();
591
587
  }`,
592
588
  {
@@ -600,16 +596,9 @@ export default function (source) {
600
596
  }
601
597
  });
602
598
 
603
- // console.info("JSON generate:", JSON.stringify(logic.body));
604
- // console.log(generate({ type: 'Program', body: logic.body }).code);
605
-
606
599
  return `methods['${logic.name}'] = async function (${logic.params.map((param) => param.name).join(', ')}) {
607
- ${logic.params.length ? logic.params.map((param) => {
608
- return `${param.name} = ${param.name} !== undefined ? ${param.name} : this.$genInitFromSchema(${JSON.stringify(param.schema)}, ${JSON.stringify(param.defaultValue)});`;
609
- }).join('\n') + '' : ''}
610
- ${logic.variables.length ? logic.variables.map((variable) => {
611
- return `let ${variable.name} = this.$genInitFromSchema(${JSON.stringify(variable.schema)}, ${JSON.stringify(variable.defaultValue)});`;
612
- }).join('\n') + '' : ''}
600
+ ${logic.params.length ? logic.params.map((param) => `${param.name} = ${param.name} !== undefined ? ${param.name} : this.$genInitFromSchema(${JSON.stringify(param.schema)}, ${JSON.stringify(param.defaultValue)});`).join('\n') + '' : ''}
601
+ ${logic.variables.length ? logic.variables.map((variable) => `let ${variable.name} = this.$genInitFromSchema(${JSON.stringify(variable.schema)}, ${JSON.stringify(variable.defaultValue)});`).join('\n') + '' : ''}
613
602
  let ${returnObj.name} = this.$genInitFromSchema(${JSON.stringify(returnObj.schema)}, ${JSON.stringify(returnObj.defaultValue)});
614
603
  ${generate({ type: 'Program', body: logic.body }).code}
615
604
  }`;
@@ -17,7 +17,7 @@ interface RoleItem extends Role {
17
17
  toggling?: Boolean,
18
18
  }
19
19
 
20
- interface Permission{
20
+ interface Permission {
21
21
  DomainName: string,
22
22
  PermissionId: string,
23
23
  PermissionValue: string,
@@ -79,7 +79,7 @@ export class Nuims {
79
79
  }
80
80
  }
81
81
 
82
- async getInitRoles() {
82
+ async getInitRoles(auto: unknown) {
83
83
  let isCreated = false;
84
84
  let resource = await this.getResource();
85
85
  if (!resource) {
@@ -99,9 +99,15 @@ export class Nuims {
99
99
  await this.bindRolesAndPermissions(role, permission);
100
100
  }
101
101
  roleName2Permission.set(role.RoleName, permission);
102
- // 创建 /dashboard 资源时自动关联 DEV-AdminRole 权限
103
- if (isCreated && (ResourceValue === '/dashboard' || ((ResourceValue === '/index' || ResourceValue === '/user') && config.scope === 'h5')) && role.RoleName === 'DEV-AdminRole') {
104
- await this.attachPermissionResourceAction();
102
+ if (auto) {
103
+ if ((ResourceValue === '/dashboard' || ((ResourceValue === '/index' || ResourceValue === '/user') && config.scope === 'h5')) && role.RoleName === 'DEV-AdminRole') {
104
+ await this.attachPermissionResourceAction();
105
+ }
106
+ } else {
107
+ // 创建 /dashboard 资源时自动关联 DEV-AdminRole 权限
108
+ if (isCreated && (ResourceValue === '/dashboard' || ((ResourceValue === '/index' || ResourceValue === '/user') && config.scope === 'h5')) && role.RoleName === 'DEV-AdminRole') {
109
+ await this.attachPermissionResourceAction();
110
+ }
105
111
  }
106
112
  roleItem.permission = permission;
107
113
  const resources = await this.getResourcesFromPermission(permission);
@@ -1,15 +1,14 @@
1
- // import stringify = require('json-stringify-safe');
2
1
  import { action, circular, excludedInJSON, immutable } from '../decorators';
3
- import { config, history, utils, LEVEL_ENUM, Vertex, PackageJSON, App, Page, DataNode, View, Attr, Directive, Event, ExpressionNode, Logic, dataTypesMap, Entity, LogicItem, ActionOptions, ACTION_MODE, Nuims, Structure } from '..';
2
+ import { config, utils, LEVEL_ENUM, Vertex, View, Attr, Directive, Event, ExpressionNode, dataTypesMap, LogicItem, ActionOptions, ACTION_MODE, Nuims, Structure } from '..';
4
3
  import * as compiler from 'vue-template-compiler';
5
4
  import * as json5 from 'json5';
6
- import { elementService, attributeService, eventService, directiveService } from '../../service/page';
5
+ import { elementService } from '../../service/page';
7
6
  import { vertexsMap } from '../cacheData';
8
7
  import Variable from '../logic/Variable';
9
8
  import * as babelParser from '@babel/parser';
10
- import { traverse } from '../utils';
11
9
  import { isPlainObject, cloneDeep, mapValues } from 'lodash';
12
- import * as utilsAll from '../../../src/types/utils/string';
10
+ import { refreshHtml } from '../cache';
11
+ import { BusinessCode } from '../enum';
13
12
 
14
13
  export interface ElementToVueOptions {
15
14
  indentStyle?: 'space' | 'tab';
@@ -29,6 +28,18 @@ export interface ParseContext {
29
28
  [key: string]: any;
30
29
  }
31
30
 
31
+ export function catchFn(view: View) {
32
+ return async (err: any) => {
33
+ if(err.code !== BusinessCode.HasReferenced) // 节点被引用,不用刷新数据
34
+ await refreshHtml(view);
35
+ else
36
+ config.defaultApp?.emit('saved', err);
37
+
38
+ config.defaultApp?.history.load();
39
+ throw err;
40
+ }
41
+ }
42
+
32
43
  /**
33
44
  * 前端页面元素
34
45
  * @example
@@ -150,9 +161,6 @@ export class Element extends Vertex {
150
161
  constructor(source?: Partial<Element>) {
151
162
  super();
152
163
  source && this.assign(source);
153
- // 为了给生成的节点使用
154
- // !this.id && this.assign({ id: uuidv4() });
155
- // this.assign({ id: 'temp-' + uuidv4() });
156
164
  }
157
165
  assign(source?: any) {
158
166
  ['attrList', 'eventList', 'directiveList', 'children'].forEach((key) => {
@@ -172,7 +180,6 @@ export class Element extends Vertex {
172
180
  }
173
181
 
174
182
  config.defaultApp?.emit('saving');
175
- try {
176
183
  if (actionOptions?.actionMode !== ACTION_MODE.undoRedo) {
177
184
  const body = this.toJSON();
178
185
  body.parentId = this.parent && this.parent.id;
@@ -185,15 +192,7 @@ export class Element extends Vertex {
185
192
  operationDesc: `添加组件"${this.getElementTitle()}"`,
186
193
  },
187
194
  body,
188
- });
189
-
190
- // Nuims createResource
191
- // Element 对应资源增删在 undo/redo 情况下可能存在权限丢失的情况
192
- // 暂时只增不减
193
- // new Nuims({
194
- // domainName: this.view.page.service.app.name,
195
- // element: this,
196
- // }).createResource();
195
+ }).catch(catchFn(this.view));
197
196
 
198
197
  this.deepPick(result, ['id', 'parentId', 'elementId']);
199
198
  // attr,directive,event的id,exprssion需要合并
@@ -220,14 +219,6 @@ export class Element extends Vertex {
220
219
  config.defaultApp?.emit('saved');
221
220
  }
222
221
  return this;
223
- } catch (err) {
224
- if (this.view) {
225
- await this.view.load();
226
- this.view.emit('change');
227
- config.defaultApp?.emit('saved');
228
- }
229
- throw err;
230
- }
231
222
  }
232
223
  /**
233
224
  * 删除元素
@@ -248,7 +239,6 @@ export class Element extends Vertex {
248
239
 
249
240
  if (actionOptions?.actionMode !== ACTION_MODE.undoRedo) {
250
241
  if (this.id) {
251
- try {
252
242
  await elementService.delete({
253
243
  headers: {
254
244
  appId: config.defaultApp?.id,
@@ -258,19 +248,7 @@ export class Element extends Vertex {
258
248
  query: {
259
249
  id: this.id,
260
250
  },
261
- });
262
- } catch (err) {
263
- await config.defaultApp?.history.load();
264
- throw err;
265
- }
266
-
267
- // Nuims deleteResource
268
- // Element 对应资源增删在 undo/redo 情况下可能存在权限丢失的情况
269
- // 暂时只增不减
270
- // new Nuims({
271
- // domainName: this.view.page.service.app.name,
272
- // element: this,
273
- // }).deleteResources();
251
+ }).catch(catchFn(this.view));
274
252
  }
275
253
  }
276
254
 
@@ -295,7 +273,6 @@ export class Element extends Vertex {
295
273
  config.defaultApp?.emit('saving');
296
274
 
297
275
  source && this.assign(source);
298
- try {
299
276
  if (actionOptions?.actionMode !== ACTION_MODE.undoRedo) {
300
277
  const body = this.toPlainJSON();
301
278
  utils.logger.debug('修改组件', body);
@@ -306,28 +283,41 @@ export class Element extends Vertex {
306
283
  operationDesc: actionOptions?.actionDesc || `修改组件"${this.getElementTitle()}"`,
307
284
  },
308
285
  body,
309
- });
286
+ }).catch(catchFn(this.view));
310
287
  }
311
288
 
312
289
  this.view && this.view.emit('change');
313
290
  await config.defaultApp?.history.load(actionOptions?.actionMode !== ACTION_MODE.undoRedo && {
314
291
  operationAction: 'Element.update',
315
- operationBeforeImage: null, // JSON.parse(JSON.stringify(this)),
292
+ operationBeforeImage: null,
316
293
  operationAfterImage: null,
317
294
  operationDesc: `修改组件"${this.getElementTitle()}"`,
318
295
  });
319
296
 
320
297
  config.defaultApp?.emit('saved');
321
298
  return this;
322
- } catch (err) {
323
- if (this.view) {
324
- await this.view.load();
325
- this.view.emit('change');
326
- config.defaultApp?.emit('saved');
327
- }
328
- throw err;
329
- }
330
299
  }
300
+
301
+ /**
302
+ * 按当前 id 加载逻辑数据
303
+ */
304
+ async load() {
305
+ if (!this.id)
306
+ return;
307
+
308
+ const result = await elementService.load({
309
+ headers: {
310
+ appId: config.defaultApp?.id,
311
+ },
312
+ query: {
313
+ id: this.id,
314
+ },
315
+ config: { noErrorTip: true },
316
+ });
317
+ const newElement = Element.from(result, this.parent, this.view);
318
+ this.assign(newElement);
319
+ }
320
+
331
321
  async move(options: {
332
322
  parentId?: string,
333
323
  _posIndex?: number,
@@ -365,11 +355,16 @@ export class Element extends Vertex {
365
355
  }
366
356
 
367
357
  config.defaultApp?.emit('element.moved');
358
+ config.defaultApp?.emit('saved');
368
359
  } catch (err) {
369
360
  if (this.view) {
370
361
  await this.view.load();
371
362
  this.view.emit('change');
372
363
  }
364
+ config.defaultApp?.emit('saved', {
365
+ action: 'move',
366
+ err,
367
+ });
373
368
  throw err;
374
369
  }
375
370
  }
@@ -383,7 +378,6 @@ export class Element extends Vertex {
383
378
 
384
379
  const index = this.parent.children.indexOf(this);
385
380
  const newNode = Element.fromHTML(code, this.parent, this.view);
386
-
387
381
 
388
382
  const mergeExpression = (originList: Array<Attr|Directive>, newList: Array<Attr|Directive>) => {
389
383
  newList.forEach((item) => {
@@ -437,11 +431,11 @@ export class Element extends Vertex {
437
431
  };
438
432
 
439
433
  const arrayComp = this.findElementsByTag('u-modal');
440
- const existingNames = Object.values(mapValues(arrayComp, function(o) { return o.name; }));
434
+ const existingNames = Object.values(mapValues(arrayComp, (o) => o.name));
441
435
  // 处理弹窗组件的命名问题
442
436
  if (newNode.tag === 'u-modal') {
443
437
  Object.assign(newNode, {
444
- name: utilsAll.unique('saveModal1', existingNames as any),
438
+ name: utils.unique('saveModal1', existingNames as any),
445
439
  });
446
440
  }
447
441
 
@@ -501,11 +495,14 @@ export class Element extends Vertex {
501
495
  await this.update(undefined, {
502
496
  actionDesc: `设置组件"${this.getElementTitle()}"的名称为"${name}"`,
503
497
  });
504
- // 同步权限
505
- new Nuims({
506
- domainName: this.view.page.service.app.name,
507
- element: this,
508
- }).editResourceFromResourceValue(oldName ? `${this.view.tempPath}/${oldName}` : null);
498
+
499
+ if (!(window as any).globalData.hasUserCenter) {
500
+ // 同步权限
501
+ new Nuims({
502
+ domainName: this.view.page.service.app.name,
503
+ element: this,
504
+ }).editResourceFromResourceValue(oldName ? `${this.view.tempPath}/${oldName}` : null);
505
+ }
509
506
 
510
507
  this.view && this.view.emit('change');
511
508
  if (this.view && this.view.page && this.view.page.service) {
@@ -554,9 +551,7 @@ export class Element extends Vertex {
554
551
  async setAttr(name: string, type: 'string' | 'static' | 'dynamic', value?: any) {
555
552
  let attr = this.getAttr(name);
556
553
  //
557
- if (value === undefined) {
558
-
559
- } else {
554
+ if (value !== undefined) {
560
555
  if (typeof value !== 'string')
561
556
  value = JSON.stringify(value);
562
557
 
@@ -567,7 +562,7 @@ export class Element extends Vertex {
567
562
  });
568
563
  await attr.update(undefined, {
569
564
  actionDesc: `设置组件"${this.getElementTitle()}"属性"${attr.name}"的值为"${attr.value}"`,
570
- });
565
+ }).catch(catchFn(this.view));
571
566
  } else {
572
567
  attr = Attr.from({
573
568
  name,
@@ -577,7 +572,7 @@ export class Element extends Vertex {
577
572
  }, this);
578
573
  await attr.create(undefined, {
579
574
  actionDesc: `设置组件"${this.getElementTitle()}"属性"${attr.name}"的值为"${attr.value}"`,
580
- });
575
+ }).catch(catchFn(this.view));
581
576
  this.attrList.push(attr);
582
577
  }
583
578
  }
@@ -594,7 +589,7 @@ export class Element extends Vertex {
594
589
 
595
590
  await event.create(undefined, Object.assign({
596
591
  actionDesc: `添加组件"${this.getElementTitle()}"事件"${event.name}"`,
597
- }, actionOptions));
592
+ }, actionOptions)).catch(catchFn(this.view));
598
593
  event = Event.from(event, this);
599
594
  this.eventList.push(event);
600
595
 
@@ -617,7 +612,7 @@ export class Element extends Vertex {
617
612
 
618
613
  await event.delete(undefined, Object.assign({
619
614
  actionDesc: `删除组件"${this.getElementTitle()}"事件"${event.name}"`,
620
- }, actionOptions));
615
+ }, actionOptions)).catch(catchFn(this.view));
621
616
  const index = this.eventList.indexOf(event);
622
617
  ~index && this.eventList.splice(index, 1);
623
618
 
@@ -635,7 +630,7 @@ export class Element extends Vertex {
635
630
  const directive = new Directive(data);
636
631
  await directive.create(undefined, Object.assign({
637
632
  actionDesc: `添加组件"${this.getElementTitle()}"指令"${directive.name}"`,
638
- }, actionOptions));
633
+ }, actionOptions)).catch(catchFn(this.view));
639
634
  this.directiveList.push(Directive.from(directive, this));
640
635
 
641
636
  this.view && this.view.emit('change');
@@ -652,7 +647,7 @@ export class Element extends Vertex {
652
647
 
653
648
  await directive.delete(undefined, Object.assign({
654
649
  actionDesc: `删除组件"${this.getElementTitle()}"属性"${directive.name}"`,
655
- }, actionOptions));
650
+ }, actionOptions)).catch(catchFn(this.view));
656
651
  const index = this.directiveList.indexOf(directive);
657
652
  ~index && this.directiveList.splice(index, 1);
658
653
 
@@ -839,7 +834,7 @@ export class Element extends Vertex {
839
834
  findElementsByTagInChildren(children: Array<any>, tag: string, existingNames: Array<any>) {
840
835
  for (const child of children) {
841
836
  const result = child.findElementByTag(tag);
842
-
837
+
843
838
  if (child.children) {
844
839
  this.findElementsByTagInChildren(child.children, tag, existingNames);
845
840
  }
@@ -892,8 +887,6 @@ export class Element extends Vertex {
892
887
  }
893
888
  }
894
889
 
895
- // if (astNode.tag === 'template')
896
- // astNode.tag = 'div';
897
890
  element = new Element({
898
891
  tag: astNode.tag,
899
892
  name: astNode.attrsMap.ref,
@@ -934,7 +927,6 @@ export class Element extends Vertex {
934
927
  }
935
928
  }
936
929
  element.attrList.push(attr);
937
- // element.attrMap[attr.name] = attr;
938
930
  });
939
931
 
940
932
  // compiler 处理:value.sync 时会加上update:value事件,需要过滤
@@ -946,10 +938,6 @@ export class Element extends Vertex {
946
938
  value,
947
939
  logicId: value[0] === '$' ? undefined : value,
948
940
  }, element));
949
- // element.eventMap[name] = new Event({
950
- // name,
951
- // value: oldEvent.value,
952
- // });
953
941
  });
954
942
 
955
943
  astNode.directives && astNode.directives.forEach((directive) => {
@@ -976,7 +964,6 @@ export class Element extends Vertex {
976
964
  arg: directive.arg,
977
965
  modifiers: directive.modifiers,
978
966
  }, element));
979
- // element.directiveMap[directive.name] = );
980
967
  }
981
968
  });
982
969
 
@@ -3,10 +3,7 @@ import { action, circular, excludedInJSON, immutable } from '../decorators';
3
3
  import { config, history, utils, LEVEL_ENUM, Vertex, PackageJSON, App, Page, DataNode, View, Element, ExpressionNode, Logic, genFinalCode, ActionOptions, ACTION_MODE } from '..';
4
4
  import { elementService, attributeService, eventService, directiveService } from '../../service/page';
5
5
  import * as babel from '@babel/core';
6
- import { traverse } from '../utils';
7
- import generate from '@babel/generator';
8
6
  import { vertexsMap } from '../cacheData';
9
- import Variable from '../logic/Variable';
10
7
 
11
8
  /**
12
9
  * 前端组件事件
@@ -3,6 +3,23 @@ import { config, history, LEVEL_ENUM, Vertex, Entity, Enum, PackageJSON, App, We
3
3
  import pageService from '../../service/page';
4
4
  import { traverse } from '../utils';
5
5
  import { postServiceType } from '../../service/common/preprocess';
6
+ import { refreshPages } from '../cache';
7
+ import { BusinessCode } from '../enum';
8
+
9
+ export function catchFn() {
10
+ return async (err: any) => {
11
+ const code = err?.code;
12
+ // 节点已存在; 节点不存在; 父节点不存在
13
+ if ([BusinessCode.ElementExist, BusinessCode.ElementNotExist, BusinessCode.ParentElementNotExist].includes(code)) {
14
+ await refreshPages();
15
+ } else
16
+ config.defaultApp?.emit('saved', err);
17
+
18
+ config.defaultApp?.history.load();
19
+
20
+ throw err;
21
+ };
22
+ }
6
23
 
7
24
  /**
8
25
  * 页面(入口页)类,后端路由控制
@@ -95,13 +112,12 @@ export class Page extends Vertex {
95
112
  }, { node: this.rootView });
96
113
  const rootView = new View(this.rootView);
97
114
  rootView.assign({ page: this });
98
-
115
+
99
116
  this.assign({ rootView });
100
117
  }
101
118
 
102
119
  addData(res: any) {
103
120
  const microService = this.service.app.firstMicroService;
104
-
105
121
 
106
122
  const enums = res.enums as Array<Enum>;
107
123
  if (enums && enums.length) {
@@ -153,8 +169,8 @@ export class Page extends Vertex {
153
169
  operationDesc: actionOptions?.actionDesc || `添加页面"${this.name}${this.title ? `(${this.title})` : ''}"`,
154
170
  },
155
171
  body,
156
- });
157
-
172
+ }).catch(catchFn());
173
+
158
174
  this.deepPick(result.page, ['id']);
159
175
  // 添加数据和接口
160
176
  this.addData(result);
@@ -170,8 +186,8 @@ export class Page extends Vertex {
170
186
  tempPath: `/${rootView.name}`,
171
187
  code: `/ID_${rootView.id}`,
172
188
  });
173
- this.rootView.attachNodePath();
174
- if(result.page.isIndex) {
189
+ this.rootView.attachNodePath();
190
+ if (result.page.isIndex) {
175
191
  const tasks = this.service.pages.filter((page) => page.isIndex && page.id !== result.page.id)
176
192
  .map((page) => {
177
193
  page.assign({ isIndex: false });
@@ -179,7 +195,7 @@ export class Page extends Vertex {
179
195
  });
180
196
  Promise.all(tasks);
181
197
  }
182
-
198
+
183
199
  await then?.();
184
200
  this.service.emit('pageTreeChange');
185
201
 
@@ -187,10 +203,10 @@ export class Page extends Vertex {
187
203
  microService.emit('dataTypesChange');
188
204
  microService.emit('enumsChange');
189
205
  microService.emit('vertexIdToNameChange');
190
-
206
+
191
207
  this.rootView.emit('change');
192
208
  // this.assign(Page.from(this, this.service));
193
-
209
+
194
210
  await config.defaultApp?.history.load();
195
211
  config.defaultApp?.emit('saved');
196
212
  return this;
@@ -215,7 +231,7 @@ export class Page extends Vertex {
215
231
  });
216
232
  this.deepPick(result, ['id']);
217
233
  this.rootView.attachNodePath();
218
- if(result.isIndex) {
234
+ if (result.isIndex) {
219
235
  const tasks = this.service.pages.filter((page) => page.isIndex && page.id !== result.id)
220
236
  .map((page) => {
221
237
  page.assign({ isIndex: false });
@@ -223,12 +239,12 @@ export class Page extends Vertex {
223
239
  });
224
240
  Promise.all(tasks);
225
241
  }
226
-
242
+
227
243
  await then?.();
228
244
  this.service.emit('pageTreeChange');
229
245
  this.rootView.emit('change');
230
246
  // this.assign(Page.from(this, this.service));
231
-
247
+
232
248
  await config.defaultApp?.history.load();
233
249
  config.defaultApp?.emit('saved');
234
250
  return this;
@@ -240,21 +256,16 @@ export class Page extends Vertex {
240
256
  async delete(none?: void, actionOptions?: ActionOptions) {
241
257
  config.defaultApp?.emit('saving');
242
258
 
243
- try {
244
- await pageService.removePage({
245
- headers: {
246
- appId: config.defaultApp?.id,
247
- operationAction: actionOptions?.actionName || 'Page.delete',
248
- operationDesc: actionOptions?.actionDesc || `删除页面"${this.name}${this.title ? `(${this.title})` : ''}"`,
249
- },
250
- path: {
251
- id: this.id,
252
- },
253
- });
254
- } catch(err) {
255
- await config.defaultApp?.history.load();
256
- throw err;
257
- }
259
+ await pageService.removePage({
260
+ headers: {
261
+ appId: config.defaultApp?.id,
262
+ operationAction: actionOptions?.actionName || 'Page.delete',
263
+ operationDesc: actionOptions?.actionDesc || `删除页面"${this.name}${this.title ? `(${this.title})` : ''}"`,
264
+ },
265
+ path: {
266
+ id: this.id,
267
+ },
268
+ }).catch(catchFn());
258
269
 
259
270
  const index = this.service.pages.indexOf(this);
260
271
  ~index && this.service.pages.splice(index, 1);
@@ -279,7 +290,7 @@ export class Page extends Vertex {
279
290
  operationDesc: actionOptions?.actionDesc || `修改页面"${this.name}${this.title ? `(${this.title})` : ''}"`,
280
291
  },
281
292
  body,
282
- });
293
+ }).catch(catchFn());
283
294
 
284
295
  await config.defaultApp?.history.load();
285
296
  config.defaultApp?.emit('saved');
@@ -292,19 +303,41 @@ export class Page extends Vertex {
292
303
  async setAsIndex() {
293
304
  config.defaultApp?.emit('saving');
294
305
 
295
- const tasks = this.service.pages.filter((page) => page.isIndex)
296
- .map((page) => {
297
- page.assign({ isIndex: false });
298
- return page.update();
306
+ const oldIndexPages: Array<Page> = this.service.pages.filter((page) => page.isIndex);
307
+ const rejectedPages: Array<Page> = [];
308
+ const tasks = oldIndexPages.map((page) => {
309
+ page.assign({ isIndex: false });
310
+ return page.update().catch((e) => {
311
+ rejectedPages.push(page);
312
+ return Promise.reject(e);
299
313
  });
300
- this.assign({ isIndex: true });
301
- tasks.push(this.update(undefined, {
302
- actionDesc: `设置页面"${this.name}"为首页`,
303
- }));
304
- await Promise.all(tasks);
314
+ });
305
315
 
306
- this.service.emit('pageTreeChange');
316
+ // 去掉旧首页
317
+ try {
318
+ await Promise.all(tasks);
319
+ } catch (e) {
320
+ // 恢复状态
321
+ rejectedPages.forEach((page) => page.assign({ isIndex: true }));
307
322
 
323
+ this.service.emit('pageTreeChange');
324
+ await config.defaultApp?.history.load();
325
+ config.defaultApp?.emit('saved');
326
+ return;
327
+ }
328
+
329
+ // 设置新首页
330
+ try {
331
+ this.assign({ isIndex: true });
332
+ await this.update(undefined, {
333
+ actionDesc: `设置页面"${this.name}"为首页`,
334
+ });
335
+ } catch (e) {
336
+ // 恢复状态
337
+ this.assign({ isIndex: false });
338
+ }
339
+
340
+ this.service.emit('pageTreeChange');
308
341
  await config.defaultApp?.history.load();
309
342
  config.defaultApp?.emit('saved');
310
343
  }
@@ -356,8 +389,8 @@ export class Page extends Vertex {
356
389
  page.assign({
357
390
  rootView: View.from(page.rootView, null, page),
358
391
  service,
359
- tempPath: page.rootView? `/${page.rootView.name}`: '',
360
- code: page.rootView?`/ID_${page.rootView.id}`: '',
392
+ tempPath: page.rootView ? `/${page.rootView.name}` : '',
393
+ code: page.rootView ? `/ID_${page.rootView.id}` : '',
361
394
  });
362
395
 
363
396
  return page;