@lcap/nasl 0.3.10 → 0.3.11

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 (194) 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 +19 -2
  5. package/out/service/create/errHandles.js.map +1 -1
  6. package/out/service/create/index.js +5 -0
  7. package/out/service/create/index.js.map +1 -1
  8. package/out/service/logic/logic.d.ts +50 -14
  9. package/out/service/logic/logic.js +26 -0
  10. package/out/service/logic/logic.js.map +1 -1
  11. package/out/service/page/element.d.ts +9 -0
  12. package/out/service/page/element.js +6 -0
  13. package/out/service/page/element.js.map +1 -1
  14. package/out/service/permission/api.d.ts +57 -0
  15. package/out/service/permission/api.js +41 -0
  16. package/out/service/permission/api.js.map +1 -0
  17. package/out/service/permission/index.d.ts +2 -0
  18. package/out/service/permission/index.js +17 -0
  19. package/out/service/permission/index.js.map +1 -0
  20. package/out/service/webFile/index.js +5 -0
  21. package/out/service/webFile/index.js.map +1 -1
  22. package/out/types/app/App.d.ts +13 -0
  23. package/out/types/app/App.js +55 -1
  24. package/out/types/app/App.js.map +1 -1
  25. package/out/types/app/History.js +3 -2
  26. package/out/types/app/History.js.map +1 -1
  27. package/out/types/app/Service.d.ts +5 -2
  28. package/out/types/app/Service.js +42 -9
  29. package/out/types/app/Service.js.map +1 -1
  30. package/out/types/cache.d.ts +6 -0
  31. package/out/types/cache.js +54 -0
  32. package/out/types/cache.js.map +1 -0
  33. package/out/types/cacheData.js.map +1 -1
  34. package/out/types/common/Vertex.d.ts +25 -0
  35. package/out/types/common/Vertex.js +42 -1
  36. package/out/types/common/Vertex.js.map +1 -1
  37. package/out/types/data/Entity.d.ts +4 -0
  38. package/out/types/data/Entity.js +9 -0
  39. package/out/types/data/Entity.js.map +1 -1
  40. package/out/types/data/EntityProperty.d.ts +5 -0
  41. package/out/types/data/EntityProperty.js +16 -0
  42. package/out/types/data/EntityProperty.js.map +1 -1
  43. package/out/types/data/Enum.d.ts +5 -0
  44. package/out/types/data/Enum.js +5 -0
  45. package/out/types/data/Enum.js.map +1 -1
  46. package/out/types/data/GlobalLogicNode.js +8 -1
  47. package/out/types/data/GlobalLogicNode.js.map +1 -1
  48. package/out/types/data/Interface.js +5 -3
  49. package/out/types/data/Interface.js.map +1 -1
  50. package/out/types/data/dataTypes.js +1 -1
  51. package/out/types/data/dataTypes.js.map +1 -1
  52. package/out/types/data/genBlock/genCreateBlock.js +5 -5
  53. package/out/types/data/genBlock/genCreateBlock.js.map +1 -1
  54. package/out/types/data/genBlock/genCurdBlock.js +3 -3
  55. package/out/types/data/genBlock/genCurdBlock.js.map +1 -1
  56. package/out/types/data/genBlock/genCurdEditTableBlock.d.ts +3 -0
  57. package/out/types/data/genBlock/genCurdEditTableBlock.js +578 -0
  58. package/out/types/data/genBlock/genCurdEditTableBlock.js.map +1 -0
  59. package/out/types/data/genBlock/genEditTableBlock.d.ts +234 -0
  60. package/out/types/data/genBlock/genEditTableBlock.js +419 -0
  61. package/out/types/data/genBlock/genEditTableBlock.js.map +1 -0
  62. package/out/types/data/genBlock/genEnumSelectBlock.d.ts +1 -1
  63. package/out/types/data/genBlock/genEnumSelectBlock.js +2 -2
  64. package/out/types/data/genBlock/genEnumSelectBlock.js.map +1 -1
  65. package/out/types/data/genBlock/genGridViewBlock.js +12 -1
  66. package/out/types/data/genBlock/genGridViewBlock.js.map +1 -1
  67. package/out/types/data/genBlock/genListViewBlock.js +2 -2
  68. package/out/types/data/genBlock/genQueryComponent.d.ts +20 -0
  69. package/out/types/data/genBlock/genQueryComponent.js +57 -1
  70. package/out/types/data/genBlock/genQueryComponent.js.map +1 -1
  71. package/out/types/data/genBlock/genSelectBlock.js +2 -2
  72. package/out/types/data/genBlock/genTableBlock.js +23 -8
  73. package/out/types/data/genBlock/genTableBlock.js.map +1 -1
  74. package/out/types/data/genBlock/genUpdateBlock.js +5 -5
  75. package/out/types/data/genBlock/genUpdateBlock.js.map +1 -1
  76. package/out/types/data/genBlock/index.d.ts +2 -0
  77. package/out/types/data/genBlock/index.js +2 -0
  78. package/out/types/data/genBlock/index.js.map +1 -1
  79. package/out/types/data/genBlock/utils.d.ts +7 -0
  80. package/out/types/data/genBlock/utils.js +38 -1
  81. package/out/types/data/genBlock/utils.js.map +1 -1
  82. package/out/types/data/systemTypes.js +47 -0
  83. package/out/types/data/systemTypes.js.map +1 -1
  84. package/out/types/enum.d.ts +6 -0
  85. package/out/types/enum.js +11 -0
  86. package/out/types/enum.js.map +1 -0
  87. package/out/types/generator/hotReload.d.ts +2 -0
  88. package/out/types/generator/hotReload.js +12 -1
  89. package/out/types/generator/hotReload.js.map +1 -1
  90. package/out/types/index.d.ts +5 -1
  91. package/out/types/index.js +8 -2
  92. package/out/types/index.js.map +1 -1
  93. package/out/types/logic/Logic.d.ts +32 -0
  94. package/out/types/logic/Logic.js +151 -41
  95. package/out/types/logic/Logic.js.map +1 -1
  96. package/out/types/logic/LogicItem.d.ts +1 -0
  97. package/out/types/logic/LogicItem.js +49 -32
  98. package/out/types/logic/LogicItem.js.map +1 -1
  99. package/out/types/logic/Param.d.ts +1 -0
  100. package/out/types/logic/Param.js +43 -33
  101. package/out/types/logic/Param.js.map +1 -1
  102. package/out/types/logic/Return.js +17 -30
  103. package/out/types/logic/Return.js.map +1 -1
  104. package/out/types/logic/Variable.js +17 -25
  105. package/out/types/logic/Variable.js.map +1 -1
  106. package/out/types/logic/translator.js +39 -10
  107. package/out/types/logic/translator.js.map +1 -1
  108. package/out/types/nuims/Nuims.d.ts +1 -1
  109. package/out/types/nuims/Nuims.js +11 -4
  110. package/out/types/nuims/Nuims.js.map +1 -1
  111. package/out/types/page/Element.d.ts +24 -0
  112. package/out/types/page/Element.js +198 -134
  113. package/out/types/page/Element.js.map +1 -1
  114. package/out/types/page/Event.js.map +1 -1
  115. package/out/types/page/Page.d.ts +5 -0
  116. package/out/types/page/Page.js +66 -27
  117. package/out/types/page/Page.js.map +1 -1
  118. package/out/types/page/View.d.ts +19 -1
  119. package/out/types/page/View.js +150 -40
  120. package/out/types/page/View.js.map +1 -1
  121. package/out/types/page/ViewParam.d.ts +1 -0
  122. package/out/types/page/ViewParam.js +23 -4
  123. package/out/types/page/ViewParam.js.map +1 -1
  124. package/out/types/page/ViewVariable.js +13 -24
  125. package/out/types/page/ViewVariable.js.map +1 -1
  126. package/out/types/permission/Permission.d.ts +41 -0
  127. package/out/types/permission/Permission.js +122 -0
  128. package/out/types/permission/Permission.js.map +1 -0
  129. package/out/types/process/ProcessParam.js +3 -1
  130. package/out/types/process/ProcessParam.js.map +1 -1
  131. package/out/types/utils/index.d.ts +1 -0
  132. package/out/types/utils/index.js +16 -7
  133. package/out/types/utils/index.js.map +1 -1
  134. package/package.json +1 -2
  135. package/src/service/app/api.js +8 -17
  136. package/src/service/create/errHandles.js +18 -2
  137. package/src/service/create/index.js +6 -0
  138. package/src/service/developPermission/api.js +37 -0
  139. package/src/service/developPermission/index.js +13 -0
  140. package/src/service/logic/logic.js +26 -0
  141. package/src/service/page/element.js +6 -0
  142. package/src/service/permission/api.js +38 -0
  143. package/src/service/permission/index.js +13 -0
  144. package/src/service/webFile/index.js +6 -1
  145. package/src/types/app/App.ts +58 -2
  146. package/src/types/app/History.ts +3 -2
  147. package/src/types/app/Service.ts +48 -10
  148. package/src/types/cache.ts +50 -0
  149. package/src/types/cacheData.ts +7 -7
  150. package/src/types/common/Vertex.ts +32 -1
  151. package/src/types/data/Entity.ts +8 -0
  152. package/src/types/data/EntityProperty.ts +12 -0
  153. package/src/types/data/Enum.ts +5 -0
  154. package/src/types/data/GlobalLogicNode.ts +8 -1
  155. package/src/types/data/Interface.ts +4 -3
  156. package/src/types/data/dataTypes.ts +1 -1
  157. package/src/types/data/genBlock/genCreateBlock.ts +5 -5
  158. package/src/types/data/genBlock/genCurdBlock.ts +3 -3
  159. package/src/types/data/genBlock/genCurdEditTableBlock.ts +581 -0
  160. package/src/types/data/genBlock/genEditTableBlock.ts +470 -0
  161. package/src/types/data/genBlock/genEnumSelectBlock.ts +2 -2
  162. package/src/types/data/genBlock/genGridViewBlock.ts +12 -1
  163. package/src/types/data/genBlock/genListViewBlock.ts +2 -2
  164. package/src/types/data/genBlock/genQueryComponent.ts +56 -0
  165. package/src/types/data/genBlock/genSelectBlock.ts +2 -2
  166. package/src/types/data/genBlock/genTableBlock.ts +28 -13
  167. package/src/types/data/genBlock/genUpdateBlock.ts +5 -5
  168. package/src/types/data/genBlock/index.ts +2 -0
  169. package/src/types/data/genBlock/utils.ts +38 -0
  170. package/src/types/data/systemTypes.ts +47 -0
  171. package/src/types/enum.ts +6 -0
  172. package/src/types/generator/hotReload.ts +10 -0
  173. package/src/types/index.ts +5 -1
  174. package/src/types/logic/Logic.ts +148 -39
  175. package/src/types/logic/LogicItem.ts +55 -38
  176. package/src/types/logic/Param.ts +43 -35
  177. package/src/types/logic/Return.ts +21 -34
  178. package/src/types/logic/Variable.ts +21 -27
  179. package/src/types/logic/translator.js +41 -14
  180. package/src/types/logic/translator_backup.js +5 -16
  181. package/src/types/nuims/Nuims.ts +11 -5
  182. package/src/types/page/Element.ts +212 -138
  183. package/src/types/page/Event.ts +0 -3
  184. package/src/types/page/Page.ts +80 -40
  185. package/src/types/page/View.ts +154 -39
  186. package/src/types/page/ViewParam.ts +22 -3
  187. package/src/types/page/ViewVariable.ts +16 -26
  188. package/src/types/page/dist/View.js +727 -0
  189. package/src/types/permission/Permission.ts +112 -0
  190. package/src/types/process/ProcessParam.ts +4 -1
  191. package/src/types/utils/index.ts +16 -7
  192. package/out/test/units/config.spec.d.ts +0 -1
  193. package/out/test/units/config.spec.js +0 -12
  194. package/out/test/units/config.spec.js.map +0 -1
@@ -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
  * 页面(入口页)类,后端路由控制
@@ -39,6 +56,13 @@ export class Page extends Vertex {
39
56
  */
40
57
  @immutable()
41
58
  public readonly isIndex: boolean = undefined;
59
+
60
+ /**
61
+ * 描述信息
62
+ */
63
+ @immutable()
64
+ public readonly description: string = undefined;
65
+
42
66
  /**
43
67
  * 根页面视图
44
68
  */
@@ -95,13 +119,12 @@ export class Page extends Vertex {
95
119
  }, { node: this.rootView });
96
120
  const rootView = new View(this.rootView);
97
121
  rootView.assign({ page: this });
98
-
122
+
99
123
  this.assign({ rootView });
100
124
  }
101
125
 
102
126
  addData(res: any) {
103
127
  const microService = this.service.app.firstMicroService;
104
-
105
128
 
106
129
  const enums = res.enums as Array<Enum>;
107
130
  if (enums && enums.length) {
@@ -153,8 +176,8 @@ export class Page extends Vertex {
153
176
  operationDesc: actionOptions?.actionDesc || `添加页面"${this.name}${this.title ? `(${this.title})` : ''}"`,
154
177
  },
155
178
  body,
156
- });
157
-
179
+ }).catch(catchFn());
180
+
158
181
  this.deepPick(result.page, ['id']);
159
182
  // 添加数据和接口
160
183
  this.addData(result);
@@ -170,8 +193,8 @@ export class Page extends Vertex {
170
193
  tempPath: `/${rootView.name}`,
171
194
  code: `/ID_${rootView.id}`,
172
195
  });
173
- this.rootView.attachNodePath();
174
- if(result.page.isIndex) {
196
+ this.rootView.attachNodePath();
197
+ if (result.page.isIndex) {
175
198
  const tasks = this.service.pages.filter((page) => page.isIndex && page.id !== result.page.id)
176
199
  .map((page) => {
177
200
  page.assign({ isIndex: false });
@@ -179,7 +202,7 @@ export class Page extends Vertex {
179
202
  });
180
203
  Promise.all(tasks);
181
204
  }
182
-
205
+
183
206
  await then?.();
184
207
  this.service.emit('pageTreeChange');
185
208
 
@@ -187,10 +210,10 @@ export class Page extends Vertex {
187
210
  microService.emit('dataTypesChange');
188
211
  microService.emit('enumsChange');
189
212
  microService.emit('vertexIdToNameChange');
190
-
213
+
191
214
  this.rootView.emit('change');
192
215
  // this.assign(Page.from(this, this.service));
193
-
216
+
194
217
  await config.defaultApp?.history.load();
195
218
  config.defaultApp?.emit('saved');
196
219
  return this;
@@ -215,7 +238,7 @@ export class Page extends Vertex {
215
238
  });
216
239
  this.deepPick(result, ['id']);
217
240
  this.rootView.attachNodePath();
218
- if(result.isIndex) {
241
+ if (result.isIndex) {
219
242
  const tasks = this.service.pages.filter((page) => page.isIndex && page.id !== result.id)
220
243
  .map((page) => {
221
244
  page.assign({ isIndex: false });
@@ -223,12 +246,12 @@ export class Page extends Vertex {
223
246
  });
224
247
  Promise.all(tasks);
225
248
  }
226
-
249
+
227
250
  await then?.();
228
251
  this.service.emit('pageTreeChange');
229
252
  this.rootView.emit('change');
230
253
  // this.assign(Page.from(this, this.service));
231
-
254
+
232
255
  await config.defaultApp?.history.load();
233
256
  config.defaultApp?.emit('saved');
234
257
  return this;
@@ -240,21 +263,16 @@ export class Page extends Vertex {
240
263
  async delete(none?: void, actionOptions?: ActionOptions) {
241
264
  config.defaultApp?.emit('saving');
242
265
 
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
- }
266
+ await pageService.removePage({
267
+ headers: {
268
+ appId: config.defaultApp?.id,
269
+ operationAction: actionOptions?.actionName || 'Page.delete',
270
+ operationDesc: actionOptions?.actionDesc || `删除页面"${this.name}${this.title ? `(${this.title})` : ''}"`,
271
+ },
272
+ path: {
273
+ id: this.id,
274
+ },
275
+ }).catch(catchFn());
258
276
 
259
277
  const index = this.service.pages.indexOf(this);
260
278
  ~index && this.service.pages.splice(index, 1);
@@ -279,7 +297,7 @@ export class Page extends Vertex {
279
297
  operationDesc: actionOptions?.actionDesc || `修改页面"${this.name}${this.title ? `(${this.title})` : ''}"`,
280
298
  },
281
299
  body,
282
- });
300
+ }).catch(catchFn());
283
301
 
284
302
  await config.defaultApp?.history.load();
285
303
  config.defaultApp?.emit('saved');
@@ -292,19 +310,41 @@ export class Page extends Vertex {
292
310
  async setAsIndex() {
293
311
  config.defaultApp?.emit('saving');
294
312
 
295
- const tasks = this.service.pages.filter((page) => page.isIndex)
296
- .map((page) => {
297
- page.assign({ isIndex: false });
298
- return page.update();
313
+ const oldIndexPages: Array<Page> = this.service.pages.filter((page) => page.isIndex);
314
+ const rejectedPages: Array<Page> = [];
315
+ const tasks = oldIndexPages.map((page) => {
316
+ page.assign({ isIndex: false });
317
+ return page.update().catch((e) => {
318
+ rejectedPages.push(page);
319
+ return Promise.reject(e);
320
+ });
321
+ });
322
+
323
+ // 去掉旧首页
324
+ try {
325
+ await Promise.all(tasks);
326
+ } catch (e) {
327
+ // 恢复状态
328
+ rejectedPages.forEach((page) => page.assign({ isIndex: true }));
329
+
330
+ this.service.emit('pageTreeChange');
331
+ await config.defaultApp?.history.load();
332
+ config.defaultApp?.emit('saved');
333
+ return;
334
+ }
335
+
336
+ // 设置新首页
337
+ try {
338
+ this.assign({ isIndex: true });
339
+ await this.update(undefined, {
340
+ actionDesc: `设置页面"${this.name}"为首页`,
299
341
  });
300
- this.assign({ isIndex: true });
301
- tasks.push(this.update(undefined, {
302
- actionDesc: `设置页面"${this.name}"为首页`,
303
- }));
304
- await Promise.all(tasks);
342
+ } catch (e) {
343
+ // 恢复状态
344
+ this.assign({ isIndex: false });
345
+ }
305
346
 
306
347
  this.service.emit('pageTreeChange');
307
-
308
348
  await config.defaultApp?.history.load();
309
349
  config.defaultApp?.emit('saved');
310
350
  }
@@ -356,8 +396,8 @@ export class Page extends Vertex {
356
396
  page.assign({
357
397
  rootView: View.from(page.rootView, null, page),
358
398
  service,
359
- tempPath: page.rootView? `/${page.rootView.name}`: '',
360
- code: page.rootView?`/ID_${page.rootView.id}`: '',
399
+ tempPath: page.rootView ? `/${page.rootView.name}` : '',
400
+ code: page.rootView ? `/ID_${page.rootView.id}` : '',
361
401
  });
362
402
 
363
403
  return page;
@@ -16,6 +16,7 @@ import * as babel from '@babel/core';
16
16
  import view from '@/service/page/view';
17
17
  import Entity from '../data/Entity';
18
18
  import { postServiceType } from '../../service/common/preprocess';
19
+ import { catchFn } from './Page';
19
20
 
20
21
  /**
21
22
  * 子页面类,前端路由控制
@@ -58,6 +59,12 @@ export class View extends Block {
58
59
  */
59
60
  @immutable()
60
61
  public readonly title: string = undefined;
62
+
63
+ /**
64
+ * 标题
65
+ */
66
+ @immutable()
67
+ public readonly description: string = undefined;
61
68
  /**
62
69
  * 面包屑
63
70
  */
@@ -127,6 +134,12 @@ export class View extends Block {
127
134
  */
128
135
  @immutable()
129
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
+
130
143
  /**
131
144
  * @param source 需要合并的部分参数
132
145
  */
@@ -199,26 +212,40 @@ export class View extends Block {
199
212
  } catch (err) { }
200
213
  })().finally(() => this.contentPromise = undefined);
201
214
  }
202
- loadAll() {
215
+ loadAll(enableCache = true) {
216
+ const isGONGHANG = utils.getGlobalEnv() === 'gonghang';
217
+ if (isGONGHANG) {
218
+ enableCache = false;
219
+ }
203
220
  // 如果有正在进行的 Promise,则直接返回它
204
221
  if (this.contentPromise)
205
222
  return this.contentPromise;
206
223
 
207
224
  return this.contentPromise = (async () => {
208
- try {
209
- const result: View = await viewService.load({
210
- path: {
211
- id: this.id,
212
- },
213
- });
214
-
215
- const temp = View.from(result, this.parent, this.page, this);
216
- this.assign(temp);
217
- utils.traverse((current) => {
218
- current.node.attachNodePath(true);
219
- }, { node: this });
220
- return this;
221
- } catch (err) { }
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;
222
249
  })().finally(() => this.contentPromise = undefined);
223
250
  }
224
251
  isContentLoaded() {
@@ -325,7 +352,7 @@ export class View extends Block {
325
352
  operationDesc: actionOptions?.actionDesc || `添加子页面"${this.name}${this.title ? `(${this.title})` : ''}"`,
326
353
  },
327
354
  body,
328
- });
355
+ }).catch(catchFn());
329
356
  this.deepPick(result.view, ['id']);
330
357
  // 添加数据
331
358
  this.addData(result);
@@ -406,21 +433,16 @@ export class View extends Block {
406
433
  if (!this.parent)
407
434
  throw Error('该子页面为根节点!');
408
435
 
409
- try {
410
- await viewService.delete({
411
- headers: {
412
- appId: config.defaultApp?.id,
413
- operationAction: actionOptions?.actionName || 'View.delete',
414
- operationDesc: actionOptions?.actionDesc || `删除子页面"${this.name}${this.title ? `(${this.title})` : ''}"`,
415
- },
416
- path: {
417
- id: this.id,
418
- },
419
- });
420
- } catch (err) {
421
- await config.defaultApp?.history.load();
422
- throw err;
423
- }
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());
424
446
 
425
447
  const index = this.parent.children.indexOf(this);
426
448
  ~index && this.parent.children.splice(index, 1);
@@ -452,7 +474,7 @@ export class View extends Block {
452
474
  operationDesc: actionOptions?.actionDesc || `修改子页面"${this.name}${this.title ? `(${this.title})` : ''}"`,
453
475
  },
454
476
  body,
455
- });
477
+ }).catch(catchFn());
456
478
 
457
479
  await then?.();
458
480
  await config.defaultApp?.history.load();
@@ -468,15 +490,13 @@ export class View extends Block {
468
490
  async setName(name: string) {
469
491
  const oldName = this.name;
470
492
  const oldTempPath = this.tempPath;
471
- this.assign({ name });
472
- this.assign({
473
- tempPath: this.parent ? `${this.parent.tempPath}/${name}` : `/${name}`,
474
- });
493
+ const newTempPath = this.parent ? `${this.parent.tempPath}/${name}` : `/${name}`;
494
+ this.assign({ name, tempPath: newTempPath });
475
495
  await this.update(undefined, {
476
496
  actionDesc: `设置页面"${oldName}"的名称为"${name}"`,
477
497
  });
478
498
  if (this.page.rootView === this) {
479
- this.page.assign({ name });
499
+ this.page.assign({ name, tempPath: newTempPath });
480
500
  await this.page.update();
481
501
  }
482
502
  // 同步权限
@@ -484,6 +504,12 @@ export class View extends Block {
484
504
  domainName: this.page.service.app.name,
485
505
  view: this,
486
506
  }).editResourceFromResourceValue(oldTempPath);
507
+ // 批量调整子页面的 tempPath 和权限
508
+ if (this.children.length) {
509
+ this.children.forEach(async (child: View) => {
510
+ await this.updateTempPath(child);
511
+ });
512
+ }
487
513
  this.page.service.emit('pageTreeChange');
488
514
  this.emit('change');
489
515
  }
@@ -522,6 +548,27 @@ export class View extends Block {
522
548
  this.page.service.emit('pageTreeChange');
523
549
  this.emit('change');
524
550
  }
551
+
552
+ /**
553
+ * 描述信息
554
+ * @param description 描述信息
555
+ */
556
+ @action('设置子页面面包屑')
557
+ async setDescription(description: string) {
558
+ const oldDescription = this.description;
559
+ this.assign({ description });
560
+ await this.update(undefined, {
561
+ actionDesc: `设置页面"${oldDescription}"的描述为"${description}"`,
562
+ });
563
+
564
+ if (this.page.rootView === this) {
565
+ this.page.assign({ description });
566
+ await this.page.update();
567
+ }
568
+
569
+ this.page.service.emit('pageTreeChange');
570
+ this.emit('change');
571
+ }
525
572
  /**
526
573
  * 设置该子页面为默认跳转页
527
574
  */
@@ -814,9 +861,23 @@ export class View extends Block {
814
861
  body.$html._posIndex = +posIndex;
815
862
  }
816
863
 
864
+ // 生成组件名字
817
865
  traverse((current) => {
818
- if (current.node.level === 'element' && current.node.name)
819
- setNewNameIfNotUnique(current.node, 'name', 'elements');
866
+ const ele = current.node;
867
+ if (ele.level !== 'element') {
868
+ return;
869
+ }
870
+ // 自带ref名的组件
871
+ if (ele.name) {
872
+ setNewNameIfNotUnique(ele, 'name', 'elements');
873
+ } else {
874
+ if (Element.ignoreTag.includes(ele.tag)) {
875
+ return;
876
+ }
877
+ const tagName = ele.tag.replace(Element.TAG_NAME_PREFIX_REG, '').replace(/-/g, '_');
878
+ ele.name = utils.unique(tagName + '1', this.elementNameSet);
879
+ }
880
+ this.addElementName(ele.name);
820
881
  }, { node: body.$html });
821
882
  }
822
883
 
@@ -901,6 +962,40 @@ export class View extends Block {
901
962
  // config.defaultApp?.emit('saved');
902
963
  }
903
964
 
965
+ // 遍历页面缓存所有组件名
966
+ traverseAllElementName(): void {
967
+ this.elementNameSet.clear();
968
+ utils.traverse(({ node }) => {
969
+ node && this.elementNameSet.add(node.name);
970
+ }, { node: this.$html });
971
+ }
972
+
973
+ // 组件名是否有效
974
+ isValidElementName(name: string): boolean {
975
+ if (name) {
976
+ return !this.elementNameSet.has(name);
977
+ }
978
+ return false;
979
+ }
980
+
981
+ // 保存组件名至缓存
982
+ addElementName(nameOrElement: string | Element) {
983
+ let name: string = nameOrElement as string;
984
+ if (nameOrElement instanceof Element) {
985
+ name = nameOrElement.name;
986
+ }
987
+ return this.elementNameSet.add(name);
988
+ }
989
+
990
+ // 在缓存中移除组件名
991
+ removeElementName(nameOrElement: string | Element): void {
992
+ let name: string = nameOrElement as string;
993
+ if (nameOrElement instanceof Element) {
994
+ name = nameOrElement.name;
995
+ }
996
+ this.elementNameSet.delete(name);
997
+ }
998
+
904
999
  _removeDef($def: View['$def']) {
905
1000
  const removedParams = this.$def.params.filter((param) => $def.params?.find((item) => param.id === item.id));
906
1001
  this.$def.params = this.$def.params.filter((param) => !$def.params?.find((item) => param.id === item.id));
@@ -1032,6 +1127,26 @@ export class View extends Block {
1032
1127
  this.$def.logics.push(Logic.from(logic, this));
1033
1128
  });
1034
1129
  }
1130
+
1131
+ // 批量调整子页面的 tempPath 和权限
1132
+ async updateTempPath(view: View) {
1133
+ const oldTempPath = view.tempPath;
1134
+ view.assign({
1135
+ tempPath: view.parent ? `${view.parent.tempPath}/${view.name}` : `/${view.name}`,
1136
+ });
1137
+ await view.update();
1138
+ // 同步权限
1139
+ new Nuims({
1140
+ domainName: view.page.service.app.name,
1141
+ view,
1142
+ }).editResourceFromResourceValue(oldTempPath);
1143
+ if (view.children.length) {
1144
+ view.children.forEach(async (childView: View) => {
1145
+ await view.updateTempPath(childView);
1146
+ });
1147
+ }
1148
+ }
1149
+
1035
1150
  /**
1036
1151
  * 从后端 JSON 生成规范的 View 对象
1037
1152
  * @param currentView 方便构建子对象时关联,主要在 load 中使用
@@ -5,6 +5,25 @@ import { getBasicTypeDefaultValue } from '../data/basicTypes';
5
5
  import { viewService } from '../../service/page';
6
6
  import { View } from './View';
7
7
  import { schemaService } from '../../service/common';
8
+ import { refreshPages, refreshView } from '../cache';
9
+ import { BusinessCode } from '../enum';
10
+
11
+ export function catchFn(view: View) {
12
+ return async (err: any) => {
13
+ const code = err?.code;
14
+ // 节点已存在; 节点不存在
15
+ if([BusinessCode.ElementExist, BusinessCode.ElementNotExist].includes(code)) {
16
+ await refreshView(view);
17
+ } else if(code === BusinessCode.ParentElementNotExist) { // 父节点不存在。视图添加变量,发现视图不存在
18
+ await refreshPages();
19
+ } else
20
+ config.defaultApp?.emit('saved', err);
21
+
22
+ config.defaultApp?.history.load();
23
+
24
+ throw err;
25
+ }
26
+ }
8
27
 
9
28
  /**
10
29
  * 页面输入参数
@@ -56,7 +75,7 @@ export class ViewParam extends Param {
56
75
  operationDesc: actionOptions?.actionDesc || `添加页面"${this.view.name}"输入参数"${this.name}"`,
57
76
  },
58
77
  body,
59
- });
78
+ }).catch(catchFn(this.view));
60
79
  // convert2RefType(result.schema);
61
80
  this.deepPick(result, ['id']);
62
81
  this.assign({ code: this.genCode() });
@@ -88,7 +107,7 @@ export class ViewParam extends Param {
88
107
  query: {
89
108
  id: this.id,
90
109
  },
91
- });
110
+ }).catch(catchFn(this.view));
92
111
  } catch(err) {
93
112
  await config.defaultApp?.history.load();
94
113
  throw err;
@@ -129,7 +148,7 @@ export class ViewParam extends Param {
129
148
  operationDesc: actionOptions?.actionDesc || `修改页面"${this.view.name}"输入参数"${this.name}"`,
130
149
  },
131
150
  body,
132
- });
151
+ }).catch(catchFn(this.view));
133
152
  // convert2RefType(result.schema);
134
153
  // this.plainAssign(result);
135
154
 
@@ -1,10 +1,10 @@
1
1
  import { immutable, excludedInJSON, action } from '../decorators';
2
- import { config, history, utils, LEVEL_ENUM, Vertex, Logic, Variable, View, Schema, ActionOptions } from '..';
3
- import { paramService } from '../../service/logic';
2
+ import { config, utils, Logic, Variable, View, Schema, ActionOptions } from '..';
4
3
  import { viewService } from '../../service/page';
5
- import { convert2RefType, convert2SchemaType } from '../data/dataTypeUtils';
4
+ import { convert2RefType } from '../data/dataTypeUtils';
6
5
  import { getBasicTypeDefaultValue } from '../data/basicTypes';
7
6
  import { schemaService } from '../../service/common';
7
+ import { catchFn } from './ViewParam';
8
8
 
9
9
  /**
10
10
  * 页面局部变量
@@ -42,7 +42,7 @@ export class ViewVariable extends Variable {
42
42
 
43
43
  const body = this.toJSON('', ['ideVersion', 'editable']);
44
44
  body.viewId = this.view.id;
45
- // convert2SchemaType(body.schema);
45
+
46
46
  utils.logger.debug('添加页面局部变量', body);
47
47
  const result: ViewVariable = await viewService.createViewVariable({
48
48
  headers: {
@@ -51,8 +51,7 @@ export class ViewVariable extends Variable {
51
51
  operationDesc: actionOptions?.actionDesc || `添加页面"${this.view.name}"局部变量"${this.name}"`,
52
52
  },
53
53
  body,
54
- });
55
- // convert2RefType(result.schema);
54
+ }).catch(catchFn(this.view));
56
55
  this.deepPick(result, ['id']);
57
56
  this.assign({ code: this.genCode() });
58
57
 
@@ -73,21 +72,16 @@ export class ViewVariable extends Variable {
73
72
  config.defaultApp?.emit('saving');
74
73
 
75
74
  if (this.id) {
76
- try {
77
- await viewService.deleteViewVariable({
78
- headers: {
79
- appId: config.defaultApp?.id,
80
- operationAction: actionOptions?.actionName || 'ViewVariable.delete',
81
- operationDesc: actionOptions?.actionDesc || `删除页面"${this.view.name}"局部变量"${this.name}"`,
82
- },
83
- query: {
84
- id: this.id,
85
- },
86
- });
87
- } catch (err) {
88
- await config.defaultApp?.history.load();
89
- throw err;
90
- }
75
+ await viewService.deleteViewVariable({
76
+ headers: {
77
+ appId: config.defaultApp?.id,
78
+ operationAction: actionOptions?.actionName || 'ViewVariable.delete',
79
+ operationDesc: actionOptions?.actionDesc || `删除页面"${this.view.name}"局部变量"${this.name}"`,
80
+ },
81
+ query: {
82
+ id: this.id,
83
+ },
84
+ }).catch(catchFn(this.view));
91
85
  }
92
86
 
93
87
  const { variables } = this.view.$def;
@@ -113,7 +107,6 @@ export class ViewVariable extends Variable {
113
107
  delete body.ideVersion;
114
108
  delete body.editable;
115
109
  body.viewId = this.view.id;
116
- // convert2SchemaType(body.schema);
117
110
  utils.logger.debug('修改页面局部变量', body);
118
111
  const result = await viewService.updateViewVariable({
119
112
  headers: {
@@ -122,9 +115,7 @@ export class ViewVariable extends Variable {
122
115
  operationDesc: actionOptions?.actionDesc || `修改页面"${this.view.name}"局部变量"${this.name}"`,
123
116
  },
124
117
  body,
125
- });
126
- // convert2RefType(result.schema);
127
- // this.plainAssign(result);
118
+ }).catch(catchFn(this.view));
128
119
 
129
120
  await config.defaultApp?.history.load();
130
121
  config.defaultApp?.emit('saved');
@@ -190,7 +181,6 @@ export class ViewVariable extends Variable {
190
181
  typeInstantiation: undefined,
191
182
  });
192
183
  Object.assign(this.schema, schema);
193
- // if (this.defaultValue)
194
184
  this.assign({ defaultValue: getBasicTypeDefaultValue() });
195
185
  try {
196
186
  await this.update(undefined, {