@lcap/nasl 0.3.10-beta → 0.3.10-beta.10

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 (126) hide show
  1. package/out/service/app/api.d.ts +1 -15
  2. package/out/service/app/api.js +7 -17
  3. package/out/service/app/api.js.map +1 -1
  4. package/out/service/create/errHandles.js +12 -0
  5. package/out/service/create/errHandles.js.map +1 -1
  6. package/out/service/create/index.js +3 -0
  7. package/out/service/create/index.js.map +1 -1
  8. package/out/service/logic/logic.d.ts +26 -17
  9. package/out/service/logic/logic.js +6 -0
  10. package/out/service/logic/logic.js.map +1 -1
  11. package/out/types/app/App.d.ts +5 -4
  12. package/out/types/app/App.js +31 -25
  13. package/out/types/app/App.js.map +1 -1
  14. package/out/types/app/History.js +3 -2
  15. package/out/types/app/History.js.map +1 -1
  16. package/out/types/app/Service.d.ts +3 -0
  17. package/out/types/app/Service.js +10 -2
  18. package/out/types/app/Service.js.map +1 -1
  19. package/out/types/cacheData.js.map +1 -1
  20. package/out/types/data/Entity.d.ts +4 -0
  21. package/out/types/data/Entity.js +8 -0
  22. package/out/types/data/Entity.js.map +1 -1
  23. package/out/types/data/EntityProperty.d.ts +5 -0
  24. package/out/types/data/EntityProperty.js +16 -0
  25. package/out/types/data/EntityProperty.js.map +1 -1
  26. package/out/types/data/dataTypes.js +1 -1
  27. package/out/types/data/dataTypes.js.map +1 -1
  28. package/out/types/data/genBlock/genCurdEditTableBlock.d.ts +3 -0
  29. package/out/types/data/genBlock/genCurdEditTableBlock.js +578 -0
  30. package/out/types/data/genBlock/genCurdEditTableBlock.js.map +1 -0
  31. package/out/types/data/genBlock/genEditTableBlock.d.ts +234 -0
  32. package/out/types/data/genBlock/genEditTableBlock.js +419 -0
  33. package/out/types/data/genBlock/genEditTableBlock.js.map +1 -0
  34. package/out/types/data/genBlock/genQueryComponent.d.ts +20 -0
  35. package/out/types/data/genBlock/genQueryComponent.js +57 -1
  36. package/out/types/data/genBlock/genQueryComponent.js.map +1 -1
  37. package/out/types/data/genBlock/genTableBlock.js +9 -5
  38. package/out/types/data/genBlock/genTableBlock.js.map +1 -1
  39. package/out/types/data/genBlock/index.d.ts +2 -0
  40. package/out/types/data/genBlock/index.js +2 -0
  41. package/out/types/data/genBlock/index.js.map +1 -1
  42. package/out/types/data/genBlock/utils.d.ts +7 -0
  43. package/out/types/data/genBlock/utils.js +38 -1
  44. package/out/types/data/genBlock/utils.js.map +1 -1
  45. package/out/types/index.d.ts +2 -4
  46. package/out/types/index.js +3 -6
  47. package/out/types/index.js.map +1 -1
  48. package/out/types/logic/Logic.d.ts +4 -12
  49. package/out/types/logic/Logic.js +35 -24
  50. package/out/types/logic/Logic.js.map +1 -1
  51. package/out/types/logic/LogicItem.d.ts +1 -20
  52. package/out/types/logic/LogicItem.js +5 -191
  53. package/out/types/logic/LogicItem.js.map +1 -1
  54. package/out/types/logic/Param.js +5 -13
  55. package/out/types/logic/Param.js.map +1 -1
  56. package/out/types/logic/Return.js +3 -11
  57. package/out/types/logic/Return.js.map +1 -1
  58. package/out/types/logic/Variable.js +3 -6
  59. package/out/types/logic/Variable.js.map +1 -1
  60. package/out/types/logic/translator.js +39 -8
  61. package/out/types/logic/translator.js.map +1 -1
  62. package/out/types/page/Element.d.ts +21 -2
  63. package/out/types/page/Element.js +89 -7
  64. package/out/types/page/Element.js.map +1 -1
  65. package/out/types/page/Page.d.ts +4 -0
  66. package/out/types/page/Page.js +7 -0
  67. package/out/types/page/Page.js.map +1 -1
  68. package/out/types/page/View.d.ts +19 -16
  69. package/out/types/page/View.js +73 -15
  70. package/out/types/page/View.js.map +1 -1
  71. package/out/types/page/ViewVariable.js +0 -6
  72. package/out/types/page/ViewVariable.js.map +1 -1
  73. package/out/types/process/ProcessParam.js +3 -1
  74. package/out/types/process/ProcessParam.js.map +1 -1
  75. package/out/types/utils/index.d.ts +1 -0
  76. package/out/types/utils/index.js +16 -7
  77. package/out/types/utils/index.js.map +1 -1
  78. package/package.json +1 -2
  79. package/src/service/app/api.js +8 -17
  80. package/src/service/create/errHandles.js +12 -0
  81. package/src/service/create/index.js +4 -0
  82. package/src/service/logic/logic.js +6 -0
  83. package/src/types/app/App.ts +37 -28
  84. package/src/types/app/History.ts +3 -2
  85. package/src/types/app/Service.ts +14 -5
  86. package/src/types/cacheData.ts +7 -7
  87. package/src/types/data/Entity.ts +7 -0
  88. package/src/types/data/EntityProperty.ts +12 -0
  89. package/src/types/data/dataTypes.ts +1 -1
  90. package/src/types/data/genBlock/genCurdEditTableBlock.ts +581 -0
  91. package/src/types/data/genBlock/genEditTableBlock.ts +470 -0
  92. package/src/types/data/genBlock/genQueryComponent.ts +56 -0
  93. package/src/types/data/genBlock/genTableBlock.ts +14 -10
  94. package/src/types/data/genBlock/index.ts +2 -0
  95. package/src/types/data/genBlock/utils.ts +38 -0
  96. package/src/types/index.ts +2 -4
  97. package/src/types/logic/Logic.ts +45 -41
  98. package/src/types/logic/LogicItem.ts +12 -217
  99. package/src/types/logic/Param.ts +25 -35
  100. package/src/types/logic/Return.ts +18 -26
  101. package/src/types/logic/Variable.ts +18 -20
  102. package/src/types/logic/translator.js +125 -154
  103. package/src/types/page/Element.ts +160 -73
  104. package/src/types/page/Page.ts +7 -0
  105. package/src/types/page/View.ts +112 -61
  106. package/src/types/page/ViewVariable.ts +13 -19
  107. package/src/types/page/dist/View.js +727 -0
  108. package/src/types/process/ProcessParam.ts +4 -1
  109. package/src/types/utils/index.ts +16 -7
  110. package/tsconfig.json +1 -1
  111. package/out/service/debugger/debugger.d.ts +0 -3
  112. package/out/service/debugger/debugger.js +0 -95
  113. package/out/service/debugger/debugger.js.map +0 -1
  114. package/out/test/units/config.spec.d.ts +0 -1
  115. package/out/test/units/config.spec.js +0 -12
  116. package/out/test/units/config.spec.js.map +0 -1
  117. package/out/types/logic/BreakPoint.d.ts +0 -42
  118. package/out/types/logic/BreakPoint.js +0 -155
  119. package/out/types/logic/BreakPoint.js.map +0 -1
  120. package/out/types/logic/Debugger.d.ts +0 -156
  121. package/out/types/logic/Debugger.js +0 -912
  122. package/out/types/logic/Debugger.js.map +0 -1
  123. package/src/service/debugger/debugger.js +0 -90
  124. package/src/types/logic/BreakPoint.ts +0 -200
  125. package/src/types/logic/Debugger.ts +0 -1140
  126. package/src/types/logic/translator.d.ts +0 -16
@@ -7,7 +7,6 @@ import { vertexsMap } from '../cacheData';
7
7
  import Variable from '../logic/Variable';
8
8
  import * as babelParser from '@babel/parser';
9
9
  import { isPlainObject, cloneDeep, mapValues } from 'lodash';
10
- import * as utilsAll from '../../../src/types/utils/string';
11
10
  import { refreshHtml } from '../cache';
12
11
  import { BusinessCode } from '../enum';
13
12
 
@@ -31,14 +30,14 @@ export interface ParseContext {
31
30
 
32
31
  export function catchFn(view: View) {
33
32
  return async (err: any) => {
34
- if(err.code !== BusinessCode.HasReferenced) // 节点被引用,不用刷新数据
33
+ if (err.code !== BusinessCode.HasReferenced) // 节点被引用,不用刷新数据
35
34
  await refreshHtml(view);
36
35
  else
37
36
  config.defaultApp?.emit('saved', err);
38
37
 
39
38
  config.defaultApp?.history.load();
40
39
  throw err;
41
- }
40
+ };
42
41
  }
43
42
 
44
43
  /**
@@ -76,6 +75,12 @@ export class Element extends Vertex {
76
75
  */
77
76
  @immutable()
78
77
  public readonly name: string = undefined;
78
+
79
+ /*
80
+ * 描述信息
81
+ */
82
+ @immutable()
83
+ public readonly description: string = undefined;
79
84
  /**
80
85
  * 属性列表
81
86
  * 和原来的 attrsList 不同,注意区分
@@ -155,6 +160,16 @@ export class Element extends Vertex {
155
160
  */
156
161
  @immutable()
157
162
  public readonly children?: Array<Element> = [];
163
+ /**
164
+ * 标签名前缀
165
+ */
166
+ @immutable()
167
+ public static readonly TAG_NAME_REG?: RegExp = /^([lieu]|van)[-_]/;
168
+ /**
169
+ * 忽略命名的标签
170
+ */
171
+ @immutable()
172
+ public static readonly ignoreTag?: Array<string> = ['div', 'span'];
158
173
 
159
174
  /**
160
175
  * @param source 需要合并的部分参数
@@ -181,45 +196,45 @@ export class Element extends Vertex {
181
196
  }
182
197
 
183
198
  config.defaultApp?.emit('saving');
184
- if (actionOptions?.actionMode !== ACTION_MODE.undoRedo) {
185
- const body = this.toJSON();
186
- body.parentId = this.parent && this.parent.id;
187
- body._posIndex = this.parent && this.parent.children.indexOf(this);
188
- utils.logger.debug('添加元素', body);
189
- const result = await elementService.create({
190
- headers: {
191
- appId: config.defaultApp?.id,
192
- operationAction: 'Element.create',
193
- operationDesc: `添加组件"${this.getElementTitle()}"`,
194
- },
195
- body,
196
- }).catch(catchFn(this.view));
197
-
198
- this.deepPick(result, ['id', 'parentId', 'elementId']);
199
- // attr,directive,event的id,exprssion需要合并
200
- this.attrList.forEach((attr, index) => {
201
- attr.deepPick(result.attrList[index], ['id', 'expression']);
202
- });
203
- this.directiveList.forEach((directive, index) => {
204
- directive.deepPick(result.directiveList[index], ['id', 'expression']);
205
- });
206
- this.eventList.forEach((event, index) => {
207
- event.deepPick(result.eventList[index], ['id']);
208
- });
209
- }
210
-
211
- this.view && this.view.emit('change');
212
-
213
- if (actionOptions?.loadHistory !== false) {
214
- await config.defaultApp?.history.load(actionOptions?.actionMode !== ACTION_MODE.undoRedo && {
199
+ if (actionOptions?.actionMode !== ACTION_MODE.undoRedo) {
200
+ const body = this.toJSON();
201
+ body.parentId = this.parent && this.parent.id;
202
+ body._posIndex = this.parent && this.parent.children.indexOf(this);
203
+ utils.logger.debug('添加元素', body);
204
+ const result = await elementService.create({
205
+ headers: {
206
+ appId: config.defaultApp?.id,
215
207
  operationAction: 'Element.create',
216
- operationBeforeImage: null,
217
- operationAfterImage: JSON.parse(JSON.stringify(this)),
218
208
  operationDesc: `添加组件"${this.getElementTitle()}"`,
219
- });
209
+ },
210
+ body,
211
+ }).catch(catchFn(this.view));
212
+
213
+ this.deepPick(result, ['id', 'parentId', 'elementId']);
214
+ // attr,directive,event的id,expression需要合并
215
+ this.attrList.forEach((attr, index) => {
216
+ attr.deepPick(result.attrList[index], ['id', 'expression']);
217
+ });
218
+ this.directiveList.forEach((directive, index) => {
219
+ directive.deepPick(result.directiveList[index], ['id', 'expression']);
220
+ });
221
+ this.eventList.forEach((event, index) => {
222
+ event.deepPick(result.eventList[index], ['id']);
223
+ });
224
+ }
225
+
226
+ this.view && this.view.emit('change');
227
+
228
+ if (actionOptions?.loadHistory !== false) {
229
+ await config.defaultApp?.history.load(actionOptions?.actionMode !== ACTION_MODE.undoRedo && {
230
+ operationAction: 'Element.create',
231
+ operationBeforeImage: null,
232
+ operationAfterImage: JSON.parse(JSON.stringify(this)),
233
+ operationDesc: `添加组件"${this.getElementTitle()}"`,
234
+ });
220
235
  config.defaultApp?.emit('saved');
221
- }
222
- return this;
236
+ }
237
+ return this;
223
238
  }
224
239
  /**
225
240
  * 删除元素
@@ -229,6 +244,7 @@ export class Element extends Vertex {
229
244
  if (actionOptions?.actionMode === ACTION_MODE.local) {
230
245
  const index = this.parent.children.indexOf(this);
231
246
  ~index && this.parent.children.splice(index, 1);
247
+ this.deepRemoveElementsName();
232
248
  this.view && this.view.emit('local-change');
233
249
  return this;
234
250
  }
@@ -240,21 +256,24 @@ export class Element extends Vertex {
240
256
 
241
257
  if (actionOptions?.actionMode !== ACTION_MODE.undoRedo) {
242
258
  if (this.id) {
243
- await elementService.delete({
244
- headers: {
245
- appId: config.defaultApp?.id,
246
- operationAction: 'Element.delete',
247
- operationDesc: `删除组件"${this.getElementTitle()}"`,
248
- },
249
- query: {
250
- id: this.id,
251
- },
252
- }).catch(catchFn(this.view));
259
+ await elementService.delete({
260
+ headers: {
261
+ appId: config.defaultApp?.id,
262
+ operationAction: 'Element.delete',
263
+ operationDesc: `删除组件"${this.getElementTitle()}"`,
264
+ },
265
+ query: {
266
+ id: this.id,
267
+ },
268
+ }).catch(catchFn(this.view));
253
269
  }
254
270
  }
255
271
 
256
272
  const index = this.parent.children.indexOf(this);
257
273
  ~index && this.parent.children.splice(index, 1);
274
+
275
+ // 递归删除组件名的缓存
276
+ this.deepRemoveElementsName();
258
277
  this.destroy();
259
278
  this.view && this.view.emit('change');
260
279
  if (actionOptions?.loadHistory !== false) {
@@ -274,32 +293,32 @@ export class Element extends Vertex {
274
293
  config.defaultApp?.emit('saving');
275
294
 
276
295
  source && this.assign(source);
277
- if (actionOptions?.actionMode !== ACTION_MODE.undoRedo) {
278
- const body = this.toPlainJSON();
279
- utils.logger.debug('修改组件', body);
280
- await elementService.update({
281
- headers: {
282
- appId: config.defaultApp?.id,
283
- operationAction: actionOptions?.actionName || 'Element.update',
284
- operationDesc: actionOptions?.actionDesc || `修改组件"${this.getElementTitle()}"`,
285
- },
286
- body,
287
- }).catch(catchFn(this.view));
288
- }
296
+ if (actionOptions?.actionMode !== ACTION_MODE.undoRedo) {
297
+ const body = this.toPlainJSON();
298
+ utils.logger.debug('修改组件', body);
299
+ await elementService.update({
300
+ headers: {
301
+ appId: config.defaultApp?.id,
302
+ operationAction: actionOptions?.actionName || 'Element.update',
303
+ operationDesc: actionOptions?.actionDesc || `修改组件"${this.getElementTitle()}"`,
304
+ },
305
+ body,
306
+ }).catch(catchFn(this.view));
307
+ }
289
308
 
290
- this.view && this.view.emit('change');
291
- await config.defaultApp?.history.load(actionOptions?.actionMode !== ACTION_MODE.undoRedo && {
292
- operationAction: 'Element.update',
293
- operationBeforeImage: null,
294
- operationAfterImage: null,
295
- operationDesc: `修改组件"${this.getElementTitle()}"`,
296
- });
309
+ this.view && this.view.emit('change');
310
+ await config.defaultApp?.history.load(actionOptions?.actionMode !== ACTION_MODE.undoRedo && {
311
+ operationAction: 'Element.update',
312
+ operationBeforeImage: null,
313
+ operationAfterImage: null,
314
+ operationDesc: `修改组件"${this.getElementTitle()}"`,
315
+ });
297
316
 
298
317
  config.defaultApp?.emit('saved');
299
318
  return this;
300
319
  }
301
320
 
302
- /**
321
+ /**
303
322
  * 按当前 id 加载逻辑数据
304
323
  */
305
324
  async load() {
@@ -379,6 +398,8 @@ export class Element extends Vertex {
379
398
 
380
399
  const index = this.parent.children.indexOf(this);
381
400
  const newNode = Element.fromHTML(code, this.parent, this.view);
401
+ // 复制的元素需重新命名
402
+ newNode.deepRenameElements();
382
403
 
383
404
  const mergeExpression = (originList: Array<Attr|Directive>, newList: Array<Attr|Directive>) => {
384
405
  newList.forEach((item) => {
@@ -436,7 +457,7 @@ export class Element extends Vertex {
436
457
  // 处理弹窗组件的命名问题
437
458
  if (newNode.tag === 'u-modal') {
438
459
  Object.assign(newNode, {
439
- name: utilsAll.unique('saveModal1', existingNames as any),
460
+ name: utils.unique('saveModal1', existingNames as any),
440
461
  });
441
462
  }
442
463
 
@@ -465,6 +486,8 @@ export class Element extends Vertex {
465
486
  }
466
487
  if (isPlainObject(child)) {
467
488
  child = Element.from(child, this, this.view);
489
+ child.initElementName();
490
+ child.deepRenameElements();
468
491
  }
469
492
  if (!this.children.includes(child)) {
470
493
  const index = child._posIndex === undefined ? this.children.length : child._posIndex;
@@ -496,7 +519,7 @@ export class Element extends Vertex {
496
519
  await this.update(undefined, {
497
520
  actionDesc: `设置组件"${this.getElementTitle()}"的名称为"${name}"`,
498
521
  });
499
-
522
+
500
523
  if (!(window as any).globalData.hasUserCenter) {
501
524
  // 同步权限
502
525
  new Nuims({
@@ -510,6 +533,22 @@ export class Element extends Vertex {
510
533
  this.view.page.service.emit('vertexIdToNameChange', this.id, this.name);
511
534
  }
512
535
  }
536
+
537
+ /**
538
+ * 更新描述信息
539
+ * @param description
540
+ */
541
+ async setDescription(description: string) {
542
+ this.assign({ description });
543
+ await this.update(undefined, {
544
+ actionDesc: `设置组件"${this.getElementTitle()}"的描述为"${description}"`,
545
+ });
546
+
547
+ this.view && this.view.emit('change');
548
+ if (this.view && this.view.page && this.view.page.service) {
549
+ this.view.page.service.emit('vertexIdToNameChange', this.id, this.name);
550
+ }
551
+ }
513
552
  /**
514
553
  * 添加组件属性
515
554
  */
@@ -730,8 +769,11 @@ export class Element extends Vertex {
730
769
  if (attr.level === LEVEL_ENUM.attr) {
731
770
  const api = config.allNodesAPI[el.tag];
732
771
  const apiOfAttr = api && api.attrs && api.attrs.find((_attr) => _attr.name === attr.name);
733
- if (apiOfAttr && apiOfAttr['designer-value']) {
734
- const designerValue = apiOfAttr['designer-value'].replace(/"/g, '\'');
772
+ if (apiOfAttr && apiOfAttr['designer-value'] !== undefined) {
773
+ let designerValue = apiOfAttr['designer-value'];
774
+ if (typeof designerValue === 'string') {
775
+ designerValue = designerValue.replace(/"/g, '\'');
776
+ }
735
777
  try {
736
778
  json5.parse(designerValue);
737
779
  return `:${attr.name}="${designerValue}"`;
@@ -844,6 +886,46 @@ export class Element extends Vertex {
844
886
  }
845
887
  }
846
888
  }
889
+
890
+ // 初始化组件名
891
+ public initElementName() {
892
+ if (Element.ignoreTag.includes(this.tag)) {
893
+ return;
894
+ }
895
+ const name = this.genElementName();
896
+ this.assign({ name });
897
+ this.view.addElementName(name);
898
+ }
899
+
900
+ // 生成新的组件名
901
+ public genElementName(): string {
902
+ const compNameSet = this.view.elementNameSet;
903
+ const tagName = this.tag.replace(Element.TAG_NAME_REG, '').replace(/-/g, '_');
904
+ const componentName = utils.unique(tagName + '1', compNameSet);
905
+ return componentName;
906
+ }
907
+
908
+ // 递归生成组件名
909
+ public deepRenameElements(): void {
910
+ return this.traverseChildren((ele: Element) => {
911
+ ele.initElementName();
912
+ });
913
+ }
914
+
915
+ // 递归删除组件名的缓存
916
+ public deepRemoveElementsName(): void {
917
+ return this.traverseChildren((ele: Element) => {
918
+ this.view.removeElementName(ele.name);
919
+ });
920
+ }
921
+
922
+ // 递归遍历组件
923
+ public traverseChildren(cb: (ele: Element) => void): void {
924
+ utils.traverse((current) => {
925
+ cb(current.node);
926
+ }, { node: this });
927
+ }
928
+
847
929
  /**
848
930
  * 从 Vue 的 ASTNode 转换成 ASL 元素
849
931
  * @param astNode Vue 的 ASTNode
@@ -1322,6 +1404,11 @@ export class Element extends Vertex {
1322
1404
  const element = this.parse(html, context);
1323
1405
  utils.traverse((current) => {
1324
1406
  current.node.assign({ view, parent: current.parent });
1407
+ // 生成唯一组件名 依赖element.view
1408
+
1409
+ if (!current.node.name) {
1410
+ current.node.initElementName();
1411
+ }
1325
1412
  }, { node: element, parent });
1326
1413
  return element;
1327
1414
  }
@@ -56,6 +56,13 @@ export class Page extends Vertex {
56
56
  */
57
57
  @immutable()
58
58
  public readonly isIndex: boolean = undefined;
59
+
60
+ /**
61
+ * 描述信息
62
+ */
63
+ @immutable()
64
+ public readonly description: string = undefined;
65
+
59
66
  /**
60
67
  * 根页面视图
61
68
  */
@@ -1,6 +1,5 @@
1
-
2
1
  import { immutable, circular, action, excludedInJSON } from '../decorators';
3
- import { config, history, LEVEL_ENUM, Vertex, PackageJSON, App, Enum, Service, WebService, Structure, Page, Element, utils, ViewParam, ViewVariable, Lifecycle, genFinalCode, generator, Nuims, ActionOptions, ACTION_MODE, vertexsMap, updateDataTypeList, Interface, LogicItem } from '..';
2
+ import { config, history, LEVEL_ENUM, Vertex, PackageJSON, App, Enum, Service, WebService, Structure, Page, Element, utils, ViewParam, ViewVariable, Lifecycle, genFinalCode, generator, Nuims, ActionOptions, ACTION_MODE, vertexsMap, updateDataTypeList, Interface } from '..';
4
3
  import Block from './Block';
5
4
  import { viewService } from '../../service/page';
6
5
  import { Param } from '../logic/Param';
@@ -17,14 +16,6 @@ import * as babel from '@babel/core';
17
16
  import view from '@/service/page/view';
18
17
  import Entity from '../data/Entity';
19
18
  import { postServiceType } from '../../service/common/preprocess';
20
- export interface FrontEndsourceMap {
21
- [id: string]: {
22
- isLogic: boolean,
23
- node: LogicItem,
24
- from: number,
25
- to: number,
26
- }
27
- }
28
19
  import { catchFn } from './Page';
29
20
 
30
21
  /**
@@ -68,6 +59,12 @@ export class View extends Block {
68
59
  */
69
60
  @immutable()
70
61
  public readonly title: string = undefined;
62
+
63
+ /**
64
+ * 标题
65
+ */
66
+ @immutable()
67
+ public readonly description: string = undefined;
71
68
  /**
72
69
  * 面包屑
73
70
  */
@@ -121,9 +118,6 @@ export class View extends Block {
121
118
  */
122
119
  @excludedInJSON()
123
120
  public contentPromise: Promise<any> = undefined;
124
-
125
- @excludedInJSON()
126
- public sourceMap: FrontEndsourceMap = {};
127
121
  /**
128
122
  * 输入参数
129
123
  */
@@ -140,6 +134,12 @@ export class View extends Block {
140
134
  */
141
135
  @immutable()
142
136
  public readonly moreChildrenFields: Array<string> = ['$def.params', '$def.variables', '$def.logics'];
137
+ /**
138
+ * 当前View中所有组件名的缓存
139
+ */
140
+ @immutable()
141
+ public readonly elementNameSet: Set<string> = new Set();
142
+
143
143
  /**
144
144
  * @param source 需要合并的部分参数
145
145
  */
@@ -208,41 +208,44 @@ export class View extends Block {
208
208
  // def 情况比较特殊,需要单独处理,防止逻辑重新加载
209
209
  this._syncDef($def);
210
210
  this.attachNodePath(true);
211
- this.toVueOptions();
212
211
  return this;
213
212
  } catch (err) { }
214
213
  })().finally(() => this.contentPromise = undefined);
215
214
  }
216
215
  loadAll(enableCache = true) {
216
+ const isGONGHANG = utils.getGlobalEnv() === 'gonghang';
217
+ if (isGONGHANG) {
218
+ enableCache = false;
219
+ }
217
220
  // 如果有正在进行的 Promise,则直接返回它
218
221
  if (this.contentPromise)
219
222
  return this.contentPromise;
220
223
 
221
224
  return this.contentPromise = (async () => {
222
- const result: View = await viewService.load({
223
- path: {
224
- id: this.id,
225
- },
226
- query: {
227
- enableCache,
228
- },
229
- config: { noErrorTip: true },
230
- });
231
- const oldLogics = this.$def.logics;
232
- Object.assign(result, {
233
- children: this.children,
234
- })
235
- const temp = View.from(result, this.parent, this.page, this);
236
- const newLogics = temp.$def.logics;
237
- oldLogics.forEach((logic) => {
238
- if(!newLogics.find((item) => item.id === logic.id))
239
- logic.destroy();
240
- });
241
- this.assign(temp);
242
- utils.traverse((current) => {
243
- current.node.attachNodePath(true);
244
- }, { node: this });
245
- return this;
225
+ const result: View = await viewService.load({
226
+ path: {
227
+ id: this.id,
228
+ },
229
+ query: {
230
+ enableCache,
231
+ },
232
+ config: { noErrorTip: true },
233
+ });
234
+ const oldLogics = this.$def.logics;
235
+ Object.assign(result, {
236
+ children: this.children,
237
+ });
238
+ const temp = View.from(result, this.parent, this.page, this);
239
+ const newLogics = temp.$def.logics;
240
+ oldLogics.forEach((logic) => {
241
+ if (!newLogics.find((item) => item.id === logic.id))
242
+ logic.destroy();
243
+ });
244
+ this.assign(temp);
245
+ utils.traverse((current) => {
246
+ current.node.attachNodePath(true);
247
+ }, { node: this });
248
+ return this;
246
249
  })().finally(() => this.contentPromise = undefined);
247
250
  }
248
251
  isContentLoaded() {
@@ -430,16 +433,16 @@ export class View extends Block {
430
433
  if (!this.parent)
431
434
  throw Error('该子页面为根节点!');
432
435
 
433
- await viewService.delete({
434
- headers: {
435
- appId: config.defaultApp?.id,
436
- operationAction: actionOptions?.actionName || 'View.delete',
437
- operationDesc: actionOptions?.actionDesc || `删除子页面"${this.name}${this.title ? `(${this.title})` : ''}"`,
438
- },
439
- path: {
440
- id: this.id,
441
- },
442
- }).catch(catchFn());
436
+ await viewService.delete({
437
+ headers: {
438
+ appId: config.defaultApp?.id,
439
+ operationAction: actionOptions?.actionName || 'View.delete',
440
+ operationDesc: actionOptions?.actionDesc || `删除子页面"${this.name}${this.title ? `(${this.title})` : ''}"`,
441
+ },
442
+ path: {
443
+ id: this.id,
444
+ },
445
+ }).catch(catchFn());
443
446
 
444
447
  const index = this.parent.children.indexOf(this);
445
448
  ~index && this.parent.children.splice(index, 1);
@@ -541,6 +544,28 @@ export class View extends Block {
541
544
  this.page.service.emit('pageTreeChange');
542
545
  this.emit('change');
543
546
  }
547
+
548
+ /**
549
+ * 描述信息
550
+ * @param description 描述信息
551
+ */
552
+ @action('设置子页面面包屑')
553
+ async setDescription(description: string) {
554
+ const oldDescription = this.description;
555
+ this.assign({ description });
556
+ console.info('description abc', description);
557
+ await this.update(undefined, {
558
+ actionDesc: `设置页面"${oldDescription}"的描述为"${description}"`,
559
+ });
560
+
561
+ if (this.page.rootView === this) {
562
+ this.page.assign({ description });
563
+ await this.page.update();
564
+ }
565
+
566
+ this.page.service.emit('pageTreeChange');
567
+ this.emit('change');
568
+ }
544
569
  /**
545
570
  * 设置该子页面为默认跳转页
546
571
  */
@@ -681,6 +706,7 @@ export class View extends Block {
681
706
  let componentOptions = 'const componentOptions = {};';
682
707
  if (this.script)
683
708
  componentOptions = this.script.trim().replace(/export default |module\.exports +=/, 'const componentOptions = ');
709
+
684
710
  const $def = JSON.parse(JSON.stringify(this.$def));
685
711
  $def.title = this.title;
686
712
  $def.crumb = this.crumb;
@@ -706,16 +732,10 @@ export class View extends Block {
706
732
  // );
707
733
  // }
708
734
  // }, { node: $def }, { mode: 'anyObject' });
709
- const {
710
- output,
711
- sourceMap,
712
- } = translator($def, this.script);
713
- return {
714
- script: `${componentOptions}${genFinalCode(output, options && options.finalCode)}
735
+ return `${componentOptions}
736
+ ${genFinalCode(translator($def), options && options.finalCode)}
715
737
  export default componentOptions;
716
- `,
717
- sourceMap,
718
- };
738
+ `;
719
739
  }
720
740
  /**
721
741
  * 转换成 Vue 文件
@@ -749,12 +769,9 @@ export class View extends Block {
749
769
  * @TODO 后面 template 可以优化成 render 函数
750
770
  */
751
771
  toVueOptions(options?: ElementToVueOptions) {
752
- const { script, sourceMap } = this.toScript(options);
753
- this.sourceMap = sourceMap;
754
772
  return {
755
773
  template: this.$html.toVue(options),
756
- script,
757
- sourceMap,
774
+ script: this.toScript(options),
758
775
  // definition: JSON.stringify(this.$def),
759
776
  };
760
777
  }
@@ -928,6 +945,40 @@ export class View extends Block {
928
945
  // config.defaultApp?.emit('saved');
929
946
  }
930
947
 
948
+ // 遍历页面缓存所有组件名
949
+ traverseAllElementName(): void {
950
+ this.elementNameSet.clear();
951
+ utils.traverse(({ node }) => {
952
+ node && this.elementNameSet.add(node.name);
953
+ }, { node: this.$html });
954
+ }
955
+
956
+ // 组件名是否有效
957
+ isValidElementName(name: string): boolean {
958
+ if (name) {
959
+ return !this.elementNameSet.has(name);
960
+ }
961
+ return false;
962
+ }
963
+
964
+ // 保存组件名至缓存
965
+ addElementName(nameOrElement: string | Element) {
966
+ let name: string = nameOrElement as string;
967
+ if (nameOrElement instanceof Element) {
968
+ name = nameOrElement.name;
969
+ }
970
+ return this.elementNameSet.add(name);
971
+ }
972
+
973
+ // 在缓存中移除组件名
974
+ removeElementName(nameOrElement: string | Element): void {
975
+ let name: string = nameOrElement as string;
976
+ if (nameOrElement instanceof Element) {
977
+ name = nameOrElement.name;
978
+ }
979
+ this.elementNameSet.delete(name);
980
+ }
981
+
931
982
  _removeDef($def: View['$def']) {
932
983
  const removedParams = this.$def.params.filter((param) => $def.params?.find((item) => param.id === item.id));
933
984
  this.$def.params = this.$def.params.filter((param) => !$def.params?.find((item) => param.id === item.id));