@lcap/nasl 0.3.9 → 0.3.10-beta

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 (154) 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/debugger/debugger.d.ts +3 -0
  4. package/out/service/debugger/debugger.js +95 -0
  5. package/out/service/debugger/debugger.js.map +1 -0
  6. package/out/service/logic/logic.d.ts +27 -0
  7. package/out/service/logic/logic.js +20 -0
  8. package/out/service/logic/logic.js.map +1 -1
  9. package/out/service/page/element.d.ts +9 -0
  10. package/out/service/page/element.js +6 -0
  11. package/out/service/page/element.js.map +1 -1
  12. package/out/service/permission/api.d.ts +57 -0
  13. package/out/service/permission/api.js +41 -0
  14. package/out/service/permission/api.js.map +1 -0
  15. package/out/service/permission/index.d.ts +2 -0
  16. package/out/service/permission/index.js +17 -0
  17. package/out/service/permission/index.js.map +1 -0
  18. package/out/service/webFile/index.js +5 -0
  19. package/out/service/webFile/index.js.map +1 -1
  20. package/out/types/app/App.d.ts +4 -1
  21. package/out/types/app/App.js +24 -0
  22. package/out/types/app/App.js.map +1 -1
  23. package/out/types/app/Service.d.ts +2 -2
  24. package/out/types/app/Service.js +28 -3
  25. package/out/types/app/Service.js.map +1 -1
  26. package/out/types/cache.d.ts +6 -0
  27. package/out/types/cache.js +54 -0
  28. package/out/types/cache.js.map +1 -0
  29. package/out/types/common/Vertex.d.ts +25 -0
  30. package/out/types/common/Vertex.js +40 -0
  31. package/out/types/common/Vertex.js.map +1 -1
  32. package/out/types/data/Entity.js +1 -0
  33. package/out/types/data/Entity.js.map +1 -1
  34. package/out/types/data/Enum.d.ts +5 -0
  35. package/out/types/data/Enum.js +5 -0
  36. package/out/types/data/Enum.js.map +1 -1
  37. package/out/types/data/Interface.js +5 -3
  38. package/out/types/data/Interface.js.map +1 -1
  39. package/out/types/data/genBlock/genCreateBlock.js +5 -5
  40. package/out/types/data/genBlock/genCreateBlock.js.map +1 -1
  41. package/out/types/data/genBlock/genCurdBlock.js +3 -3
  42. package/out/types/data/genBlock/genCurdBlock.js.map +1 -1
  43. package/out/types/data/genBlock/genEnumSelectBlock.d.ts +1 -1
  44. package/out/types/data/genBlock/genEnumSelectBlock.js +2 -2
  45. package/out/types/data/genBlock/genEnumSelectBlock.js.map +1 -1
  46. package/out/types/data/genBlock/genGridViewBlock.js +12 -1
  47. package/out/types/data/genBlock/genGridViewBlock.js.map +1 -1
  48. package/out/types/data/genBlock/genListViewBlock.js +2 -2
  49. package/out/types/data/genBlock/genSelectBlock.js +2 -2
  50. package/out/types/data/genBlock/genTableBlock.js +14 -3
  51. package/out/types/data/genBlock/genTableBlock.js.map +1 -1
  52. package/out/types/data/genBlock/genUpdateBlock.js +5 -5
  53. package/out/types/data/genBlock/genUpdateBlock.js.map +1 -1
  54. package/out/types/data/systemTypes.js +47 -0
  55. package/out/types/data/systemTypes.js.map +1 -1
  56. package/out/types/enum.d.ts +6 -0
  57. package/out/types/enum.js +11 -0
  58. package/out/types/enum.js.map +1 -0
  59. package/out/types/generator/hotReload.d.ts +2 -0
  60. package/out/types/generator/hotReload.js +12 -1
  61. package/out/types/generator/hotReload.js.map +1 -1
  62. package/out/types/index.d.ts +7 -1
  63. package/out/types/index.js +11 -2
  64. package/out/types/index.js.map +1 -1
  65. package/out/types/logic/BreakPoint.d.ts +42 -0
  66. package/out/types/logic/BreakPoint.js +155 -0
  67. package/out/types/logic/BreakPoint.js.map +1 -0
  68. package/out/types/logic/Debugger.d.ts +156 -0
  69. package/out/types/logic/Debugger.js +912 -0
  70. package/out/types/logic/Debugger.js.map +1 -0
  71. package/out/types/logic/Logic.d.ts +40 -0
  72. package/out/types/logic/Logic.js +130 -31
  73. package/out/types/logic/Logic.js.map +1 -1
  74. package/out/types/logic/LogicItem.d.ts +21 -1
  75. package/out/types/logic/LogicItem.js +227 -24
  76. package/out/types/logic/LogicItem.js.map +1 -1
  77. package/out/types/logic/Param.d.ts +1 -0
  78. package/out/types/logic/Param.js +38 -20
  79. package/out/types/logic/Param.js.map +1 -1
  80. package/out/types/logic/Return.js +14 -19
  81. package/out/types/logic/Return.js.map +1 -1
  82. package/out/types/logic/Variable.js +14 -19
  83. package/out/types/logic/Variable.js.map +1 -1
  84. package/out/types/logic/translator.js +0 -2
  85. package/out/types/logic/translator.js.map +1 -1
  86. package/out/types/nuims/Nuims.d.ts +1 -1
  87. package/out/types/nuims/Nuims.js +11 -4
  88. package/out/types/nuims/Nuims.js.map +1 -1
  89. package/out/types/page/Element.d.ts +5 -0
  90. package/out/types/page/Element.js +114 -130
  91. package/out/types/page/Element.js.map +1 -1
  92. package/out/types/page/Event.js.map +1 -1
  93. package/out/types/page/Page.d.ts +1 -0
  94. package/out/types/page/Page.js +59 -27
  95. package/out/types/page/Page.js.map +1 -1
  96. package/out/types/page/View.d.ts +17 -3
  97. package/out/types/page/View.js +53 -37
  98. package/out/types/page/View.js.map +1 -1
  99. package/out/types/page/ViewParam.d.ts +1 -0
  100. package/out/types/page/ViewParam.js +23 -4
  101. package/out/types/page/ViewParam.js.map +1 -1
  102. package/out/types/page/ViewVariable.js +13 -18
  103. package/out/types/page/ViewVariable.js.map +1 -1
  104. package/out/types/permission/Permission.d.ts +41 -0
  105. package/out/types/permission/Permission.js +122 -0
  106. package/out/types/permission/Permission.js.map +1 -0
  107. package/package.json +2 -2
  108. package/src/service/create/errHandles.js +6 -2
  109. package/src/service/debugger/debugger.js +90 -0
  110. package/src/service/developPermission/api.js +37 -0
  111. package/src/service/developPermission/index.js +13 -0
  112. package/src/service/logic/logic.js +20 -0
  113. package/src/service/page/element.js +6 -0
  114. package/src/service/permission/api.js +38 -0
  115. package/src/service/permission/index.js +13 -0
  116. package/src/service/webFile/index.js +6 -1
  117. package/src/types/app/App.ts +27 -1
  118. package/src/types/app/Service.ts +32 -3
  119. package/src/types/cache.ts +50 -0
  120. package/src/types/common/Vertex.ts +30 -0
  121. package/src/types/data/Entity.ts +1 -0
  122. package/src/types/data/Enum.ts +5 -0
  123. package/src/types/data/Interface.ts +4 -3
  124. package/src/types/data/genBlock/genCreateBlock.ts +5 -5
  125. package/src/types/data/genBlock/genCurdBlock.ts +3 -3
  126. package/src/types/data/genBlock/genEnumSelectBlock.ts +2 -2
  127. package/src/types/data/genBlock/genGridViewBlock.ts +12 -1
  128. package/src/types/data/genBlock/genListViewBlock.ts +2 -2
  129. package/src/types/data/genBlock/genSelectBlock.ts +2 -2
  130. package/src/types/data/genBlock/genTableBlock.ts +14 -3
  131. package/src/types/data/genBlock/genUpdateBlock.ts +5 -5
  132. package/src/types/data/systemTypes.ts +47 -0
  133. package/src/types/enum.ts +6 -0
  134. package/src/types/generator/hotReload.ts +10 -0
  135. package/src/types/index.ts +7 -1
  136. package/src/types/logic/BreakPoint.ts +200 -0
  137. package/src/types/logic/Debugger.ts +1140 -0
  138. package/src/types/logic/Logic.ts +133 -28
  139. package/src/types/logic/LogicItem.ts +250 -28
  140. package/src/types/logic/Param.ts +26 -8
  141. package/src/types/logic/Return.ts +4 -9
  142. package/src/types/logic/Variable.ts +4 -8
  143. package/src/types/logic/translator.d.ts +16 -0
  144. package/src/types/logic/translator.js +144 -88
  145. package/src/types/logic/translator_backup.js +5 -16
  146. package/src/types/nuims/Nuims.ts +11 -5
  147. package/src/types/page/Element.ts +63 -75
  148. package/src/types/page/Event.ts +0 -3
  149. package/src/types/page/Page.ts +73 -40
  150. package/src/types/page/View.ts +45 -18
  151. package/src/types/page/ViewParam.ts +22 -3
  152. package/src/types/page/ViewVariable.ts +4 -8
  153. package/src/types/permission/Permission.ts +112 -0
  154. package/tsconfig.json +1 -1
@@ -1,15 +1,15 @@
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
10
  import * as utilsAll from '../../../src/types/utils/string';
11
+ import { refreshHtml } from '../cache';
12
+ import { BusinessCode } from '../enum';
13
13
 
14
14
  export interface ElementToVueOptions {
15
15
  indentStyle?: 'space' | 'tab';
@@ -29,6 +29,18 @@ export interface ParseContext {
29
29
  [key: string]: any;
30
30
  }
31
31
 
32
+ export function catchFn(view: View) {
33
+ return async (err: any) => {
34
+ if(err.code !== BusinessCode.HasReferenced) // 节点被引用,不用刷新数据
35
+ await refreshHtml(view);
36
+ else
37
+ config.defaultApp?.emit('saved', err);
38
+
39
+ config.defaultApp?.history.load();
40
+ throw err;
41
+ }
42
+ }
43
+
32
44
  /**
33
45
  * 前端页面元素
34
46
  * @example
@@ -150,9 +162,6 @@ export class Element extends Vertex {
150
162
  constructor(source?: Partial<Element>) {
151
163
  super();
152
164
  source && this.assign(source);
153
- // 为了给生成的节点使用
154
- // !this.id && this.assign({ id: uuidv4() });
155
- // this.assign({ id: 'temp-' + uuidv4() });
156
165
  }
157
166
  assign(source?: any) {
158
167
  ['attrList', 'eventList', 'directiveList', 'children'].forEach((key) => {
@@ -172,7 +181,6 @@ export class Element extends Vertex {
172
181
  }
173
182
 
174
183
  config.defaultApp?.emit('saving');
175
- try {
176
184
  if (actionOptions?.actionMode !== ACTION_MODE.undoRedo) {
177
185
  const body = this.toJSON();
178
186
  body.parentId = this.parent && this.parent.id;
@@ -185,15 +193,7 @@ export class Element extends Vertex {
185
193
  operationDesc: `添加组件"${this.getElementTitle()}"`,
186
194
  },
187
195
  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();
196
+ }).catch(catchFn(this.view));
197
197
 
198
198
  this.deepPick(result, ['id', 'parentId', 'elementId']);
199
199
  // attr,directive,event的id,exprssion需要合并
@@ -220,14 +220,6 @@ export class Element extends Vertex {
220
220
  config.defaultApp?.emit('saved');
221
221
  }
222
222
  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
223
  }
232
224
  /**
233
225
  * 删除元素
@@ -248,7 +240,6 @@ export class Element extends Vertex {
248
240
 
249
241
  if (actionOptions?.actionMode !== ACTION_MODE.undoRedo) {
250
242
  if (this.id) {
251
- try {
252
243
  await elementService.delete({
253
244
  headers: {
254
245
  appId: config.defaultApp?.id,
@@ -258,19 +249,7 @@ export class Element extends Vertex {
258
249
  query: {
259
250
  id: this.id,
260
251
  },
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();
252
+ }).catch(catchFn(this.view));
274
253
  }
275
254
  }
276
255
 
@@ -295,7 +274,6 @@ export class Element extends Vertex {
295
274
  config.defaultApp?.emit('saving');
296
275
 
297
276
  source && this.assign(source);
298
- try {
299
277
  if (actionOptions?.actionMode !== ACTION_MODE.undoRedo) {
300
278
  const body = this.toPlainJSON();
301
279
  utils.logger.debug('修改组件', body);
@@ -306,28 +284,41 @@ export class Element extends Vertex {
306
284
  operationDesc: actionOptions?.actionDesc || `修改组件"${this.getElementTitle()}"`,
307
285
  },
308
286
  body,
309
- });
287
+ }).catch(catchFn(this.view));
310
288
  }
311
289
 
312
290
  this.view && this.view.emit('change');
313
291
  await config.defaultApp?.history.load(actionOptions?.actionMode !== ACTION_MODE.undoRedo && {
314
292
  operationAction: 'Element.update',
315
- operationBeforeImage: null, // JSON.parse(JSON.stringify(this)),
293
+ operationBeforeImage: null,
316
294
  operationAfterImage: null,
317
295
  operationDesc: `修改组件"${this.getElementTitle()}"`,
318
296
  });
319
297
 
320
298
  config.defaultApp?.emit('saved');
321
299
  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
300
  }
301
+
302
+ /**
303
+ * 按当前 id 加载逻辑数据
304
+ */
305
+ async load() {
306
+ if (!this.id)
307
+ return;
308
+
309
+ const result = await elementService.load({
310
+ headers: {
311
+ appId: config.defaultApp?.id,
312
+ },
313
+ query: {
314
+ id: this.id,
315
+ },
316
+ config: { noErrorTip: true },
317
+ });
318
+ const newElement = Element.from(result, this.parent, this.view);
319
+ this.assign(newElement);
320
+ }
321
+
331
322
  async move(options: {
332
323
  parentId?: string,
333
324
  _posIndex?: number,
@@ -365,11 +356,16 @@ export class Element extends Vertex {
365
356
  }
366
357
 
367
358
  config.defaultApp?.emit('element.moved');
359
+ config.defaultApp?.emit('saved');
368
360
  } catch (err) {
369
361
  if (this.view) {
370
362
  await this.view.load();
371
363
  this.view.emit('change');
372
364
  }
365
+ config.defaultApp?.emit('saved', {
366
+ action: 'move',
367
+ err,
368
+ });
373
369
  throw err;
374
370
  }
375
371
  }
@@ -383,7 +379,6 @@ export class Element extends Vertex {
383
379
 
384
380
  const index = this.parent.children.indexOf(this);
385
381
  const newNode = Element.fromHTML(code, this.parent, this.view);
386
-
387
382
 
388
383
  const mergeExpression = (originList: Array<Attr|Directive>, newList: Array<Attr|Directive>) => {
389
384
  newList.forEach((item) => {
@@ -437,7 +432,7 @@ export class Element extends Vertex {
437
432
  };
438
433
 
439
434
  const arrayComp = this.findElementsByTag('u-modal');
440
- const existingNames = Object.values(mapValues(arrayComp, function(o) { return o.name; }));
435
+ const existingNames = Object.values(mapValues(arrayComp, (o) => o.name));
441
436
  // 处理弹窗组件的命名问题
442
437
  if (newNode.tag === 'u-modal') {
443
438
  Object.assign(newNode, {
@@ -501,11 +496,14 @@ export class Element extends Vertex {
501
496
  await this.update(undefined, {
502
497
  actionDesc: `设置组件"${this.getElementTitle()}"的名称为"${name}"`,
503
498
  });
504
- // 同步权限
505
- new Nuims({
506
- domainName: this.view.page.service.app.name,
507
- element: this,
508
- }).editResourceFromResourceValue(oldName ? `${this.view.tempPath}/${oldName}` : null);
499
+
500
+ if (!(window as any).globalData.hasUserCenter) {
501
+ // 同步权限
502
+ new Nuims({
503
+ domainName: this.view.page.service.app.name,
504
+ element: this,
505
+ }).editResourceFromResourceValue(oldName ? `${this.view.tempPath}/${oldName}` : null);
506
+ }
509
507
 
510
508
  this.view && this.view.emit('change');
511
509
  if (this.view && this.view.page && this.view.page.service) {
@@ -554,9 +552,7 @@ export class Element extends Vertex {
554
552
  async setAttr(name: string, type: 'string' | 'static' | 'dynamic', value?: any) {
555
553
  let attr = this.getAttr(name);
556
554
  //
557
- if (value === undefined) {
558
-
559
- } else {
555
+ if (value !== undefined) {
560
556
  if (typeof value !== 'string')
561
557
  value = JSON.stringify(value);
562
558
 
@@ -567,7 +563,7 @@ export class Element extends Vertex {
567
563
  });
568
564
  await attr.update(undefined, {
569
565
  actionDesc: `设置组件"${this.getElementTitle()}"属性"${attr.name}"的值为"${attr.value}"`,
570
- });
566
+ }).catch(catchFn(this.view));
571
567
  } else {
572
568
  attr = Attr.from({
573
569
  name,
@@ -577,7 +573,7 @@ export class Element extends Vertex {
577
573
  }, this);
578
574
  await attr.create(undefined, {
579
575
  actionDesc: `设置组件"${this.getElementTitle()}"属性"${attr.name}"的值为"${attr.value}"`,
580
- });
576
+ }).catch(catchFn(this.view));
581
577
  this.attrList.push(attr);
582
578
  }
583
579
  }
@@ -594,7 +590,7 @@ export class Element extends Vertex {
594
590
 
595
591
  await event.create(undefined, Object.assign({
596
592
  actionDesc: `添加组件"${this.getElementTitle()}"事件"${event.name}"`,
597
- }, actionOptions));
593
+ }, actionOptions)).catch(catchFn(this.view));
598
594
  event = Event.from(event, this);
599
595
  this.eventList.push(event);
600
596
 
@@ -617,7 +613,7 @@ export class Element extends Vertex {
617
613
 
618
614
  await event.delete(undefined, Object.assign({
619
615
  actionDesc: `删除组件"${this.getElementTitle()}"事件"${event.name}"`,
620
- }, actionOptions));
616
+ }, actionOptions)).catch(catchFn(this.view));
621
617
  const index = this.eventList.indexOf(event);
622
618
  ~index && this.eventList.splice(index, 1);
623
619
 
@@ -635,7 +631,7 @@ export class Element extends Vertex {
635
631
  const directive = new Directive(data);
636
632
  await directive.create(undefined, Object.assign({
637
633
  actionDesc: `添加组件"${this.getElementTitle()}"指令"${directive.name}"`,
638
- }, actionOptions));
634
+ }, actionOptions)).catch(catchFn(this.view));
639
635
  this.directiveList.push(Directive.from(directive, this));
640
636
 
641
637
  this.view && this.view.emit('change');
@@ -652,7 +648,7 @@ export class Element extends Vertex {
652
648
 
653
649
  await directive.delete(undefined, Object.assign({
654
650
  actionDesc: `删除组件"${this.getElementTitle()}"属性"${directive.name}"`,
655
- }, actionOptions));
651
+ }, actionOptions)).catch(catchFn(this.view));
656
652
  const index = this.directiveList.indexOf(directive);
657
653
  ~index && this.directiveList.splice(index, 1);
658
654
 
@@ -839,7 +835,7 @@ export class Element extends Vertex {
839
835
  findElementsByTagInChildren(children: Array<any>, tag: string, existingNames: Array<any>) {
840
836
  for (const child of children) {
841
837
  const result = child.findElementByTag(tag);
842
-
838
+
843
839
  if (child.children) {
844
840
  this.findElementsByTagInChildren(child.children, tag, existingNames);
845
841
  }
@@ -892,8 +888,6 @@ export class Element extends Vertex {
892
888
  }
893
889
  }
894
890
 
895
- // if (astNode.tag === 'template')
896
- // astNode.tag = 'div';
897
891
  element = new Element({
898
892
  tag: astNode.tag,
899
893
  name: astNode.attrsMap.ref,
@@ -934,7 +928,6 @@ export class Element extends Vertex {
934
928
  }
935
929
  }
936
930
  element.attrList.push(attr);
937
- // element.attrMap[attr.name] = attr;
938
931
  });
939
932
 
940
933
  // compiler 处理:value.sync 时会加上update:value事件,需要过滤
@@ -946,10 +939,6 @@ export class Element extends Vertex {
946
939
  value,
947
940
  logicId: value[0] === '$' ? undefined : value,
948
941
  }, element));
949
- // element.eventMap[name] = new Event({
950
- // name,
951
- // value: oldEvent.value,
952
- // });
953
942
  });
954
943
 
955
944
  astNode.directives && astNode.directives.forEach((directive) => {
@@ -976,7 +965,6 @@ export class Element extends Vertex {
976
965
  arg: directive.arg,
977
966
  modifiers: directive.modifiers,
978
967
  }, element));
979
- // element.directiveMap[directive.name] = );
980
968
  }
981
969
  });
982
970
 
@@ -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;