@lcap/nasl 0.3.9-beta → 0.3.10-beta.oom2

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 (149) 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 -0
  21. package/out/types/app/App.js +29 -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 +5 -1
  63. package/out/types/index.js +8 -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 +28 -0
  72. package/out/types/logic/Logic.js +116 -31
  73. package/out/types/logic/Logic.js.map +1 -1
  74. package/out/types/logic/LogicItem.d.ts +1 -0
  75. package/out/types/logic/LogicItem.js +43 -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 +8 -0
  90. package/out/types/page/Element.js +145 -129
  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 +71 -37
  95. package/out/types/page/Page.js.map +1 -1
  96. package/out/types/page/View.d.ts +1 -1
  97. package/out/types/page/View.js +50 -42
  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 -3
  108. package/src/service/create/errHandles.js +6 -2
  109. package/src/service/developPermission/api.js +37 -0
  110. package/src/service/developPermission/index.js +13 -0
  111. package/src/service/logic/logic.js +20 -0
  112. package/src/service/page/element.js +6 -0
  113. package/src/service/permission/api.js +38 -0
  114. package/src/service/permission/index.js +13 -0
  115. package/src/service/webFile/index.js +6 -1
  116. package/src/types/app/App.ts +32 -1
  117. package/src/types/app/Service.ts +32 -3
  118. package/src/types/cache.ts +50 -0
  119. package/src/types/common/Vertex.ts +30 -0
  120. package/src/types/data/Entity.ts +1 -0
  121. package/src/types/data/Enum.ts +5 -0
  122. package/src/types/data/Interface.ts +4 -3
  123. package/src/types/data/genBlock/genCreateBlock.ts +5 -5
  124. package/src/types/data/genBlock/genCurdBlock.ts +3 -3
  125. package/src/types/data/genBlock/genEnumSelectBlock.ts +2 -2
  126. package/src/types/data/genBlock/genGridViewBlock.ts +12 -1
  127. package/src/types/data/genBlock/genListViewBlock.ts +2 -2
  128. package/src/types/data/genBlock/genSelectBlock.ts +2 -2
  129. package/src/types/data/genBlock/genTableBlock.ts +14 -3
  130. package/src/types/data/genBlock/genUpdateBlock.ts +5 -5
  131. package/src/types/data/systemTypes.ts +47 -0
  132. package/src/types/enum.ts +6 -0
  133. package/src/types/generator/hotReload.ts +10 -0
  134. package/src/types/index.ts +5 -1
  135. package/src/types/logic/Logic.ts +109 -28
  136. package/src/types/logic/LogicItem.ts +48 -28
  137. package/src/types/logic/Param.ts +26 -8
  138. package/src/types/logic/Return.ts +4 -9
  139. package/src/types/logic/Variable.ts +4 -8
  140. package/src/types/logic/translator.js +0 -4
  141. package/src/types/logic/translator_backup.js +5 -16
  142. package/src/types/nuims/Nuims.ts +11 -5
  143. package/src/types/page/Element.ts +101 -73
  144. package/src/types/page/Event.ts +0 -3
  145. package/src/types/page/Page.ts +86 -49
  146. package/src/types/page/View.ts +31 -22
  147. package/src/types/page/ViewParam.ts +22 -3
  148. package/src/types/page/ViewVariable.ts +4 -8
  149. package/src/types/permission/Permission.ts +112 -0
@@ -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,22 +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
- const interfaces = res.interfaces as Array<Interface>;
105
- if (interfaces && interfaces.length) {
106
- interfaces.forEach((item, index) => {
107
- const itface = interfaces[index] = Interface.from(item, microService);
108
- postServiceType(itface);
109
- });
110
- microService.interfaces.unshift(...interfaces);
111
- microService.globalLogic.globalLogics.unshift(...interfaces);
112
- microService.emit('interfacesChange');
113
- }
114
121
 
115
122
  const enums = res.enums as Array<Enum>;
116
123
  if (enums && enums.length) {
@@ -132,6 +139,19 @@ export class Page extends Vertex {
132
139
  microService.data.structures.unshift(...structures);
133
140
  updateDataTypeList();
134
141
  }
142
+
143
+ const interfaces = res.interfaces as Array<Interface>;
144
+ if (interfaces && interfaces.length) {
145
+ interfaces.forEach((item, index) => {
146
+ const itface = interfaces[index] = Interface.from(item, microService);
147
+ postServiceType(itface);
148
+ });
149
+ microService.interfaces.unshift(...interfaces);
150
+ microService.globalLogic.globalLogics.unshift(...interfaces);
151
+ microService.mountResolverOnEntity();
152
+ microService.mountResolverOnInterface();
153
+ microService.emit('interfacesChange');
154
+ }
135
155
  }
136
156
 
137
157
  /**
@@ -149,8 +169,8 @@ export class Page extends Vertex {
149
169
  operationDesc: actionOptions?.actionDesc || `添加页面"${this.name}${this.title ? `(${this.title})` : ''}"`,
150
170
  },
151
171
  body,
152
- });
153
-
172
+ }).catch(catchFn());
173
+
154
174
  this.deepPick(result.page, ['id']);
155
175
  // 添加数据和接口
156
176
  this.addData(result);
@@ -166,8 +186,8 @@ export class Page extends Vertex {
166
186
  tempPath: `/${rootView.name}`,
167
187
  code: `/ID_${rootView.id}`,
168
188
  });
169
- this.rootView.attachNodePath();
170
- if(result.page.isIndex) {
189
+ this.rootView.attachNodePath();
190
+ if (result.page.isIndex) {
171
191
  const tasks = this.service.pages.filter((page) => page.isIndex && page.id !== result.page.id)
172
192
  .map((page) => {
173
193
  page.assign({ isIndex: false });
@@ -175,7 +195,7 @@ export class Page extends Vertex {
175
195
  });
176
196
  Promise.all(tasks);
177
197
  }
178
-
198
+
179
199
  await then?.();
180
200
  this.service.emit('pageTreeChange');
181
201
 
@@ -183,10 +203,10 @@ export class Page extends Vertex {
183
203
  microService.emit('dataTypesChange');
184
204
  microService.emit('enumsChange');
185
205
  microService.emit('vertexIdToNameChange');
186
-
206
+
187
207
  this.rootView.emit('change');
188
208
  // this.assign(Page.from(this, this.service));
189
-
209
+
190
210
  await config.defaultApp?.history.load();
191
211
  config.defaultApp?.emit('saved');
192
212
  return this;
@@ -211,7 +231,7 @@ export class Page extends Vertex {
211
231
  });
212
232
  this.deepPick(result, ['id']);
213
233
  this.rootView.attachNodePath();
214
- if(result.isIndex) {
234
+ if (result.isIndex) {
215
235
  const tasks = this.service.pages.filter((page) => page.isIndex && page.id !== result.id)
216
236
  .map((page) => {
217
237
  page.assign({ isIndex: false });
@@ -219,12 +239,12 @@ export class Page extends Vertex {
219
239
  });
220
240
  Promise.all(tasks);
221
241
  }
222
-
242
+
223
243
  await then?.();
224
244
  this.service.emit('pageTreeChange');
225
245
  this.rootView.emit('change');
226
246
  // this.assign(Page.from(this, this.service));
227
-
247
+
228
248
  await config.defaultApp?.history.load();
229
249
  config.defaultApp?.emit('saved');
230
250
  return this;
@@ -236,21 +256,16 @@ export class Page extends Vertex {
236
256
  async delete(none?: void, actionOptions?: ActionOptions) {
237
257
  config.defaultApp?.emit('saving');
238
258
 
239
- try {
240
- await pageService.removePage({
241
- headers: {
242
- appId: config.defaultApp?.id,
243
- operationAction: actionOptions?.actionName || 'Page.delete',
244
- operationDesc: actionOptions?.actionDesc || `删除页面"${this.name}${this.title ? `(${this.title})` : ''}"`,
245
- },
246
- path: {
247
- id: this.id,
248
- },
249
- });
250
- } catch(err) {
251
- await config.defaultApp?.history.load();
252
- throw err;
253
- }
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());
254
269
 
255
270
  const index = this.service.pages.indexOf(this);
256
271
  ~index && this.service.pages.splice(index, 1);
@@ -275,7 +290,7 @@ export class Page extends Vertex {
275
290
  operationDesc: actionOptions?.actionDesc || `修改页面"${this.name}${this.title ? `(${this.title})` : ''}"`,
276
291
  },
277
292
  body,
278
- });
293
+ }).catch(catchFn());
279
294
 
280
295
  await config.defaultApp?.history.load();
281
296
  config.defaultApp?.emit('saved');
@@ -288,19 +303,41 @@ export class Page extends Vertex {
288
303
  async setAsIndex() {
289
304
  config.defaultApp?.emit('saving');
290
305
 
291
- const tasks = this.service.pages.filter((page) => page.isIndex)
292
- .map((page) => {
293
- page.assign({ isIndex: false });
294
- 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);
295
313
  });
296
- this.assign({ isIndex: true });
297
- tasks.push(this.update(undefined, {
298
- actionDesc: `设置页面"${this.name}"为首页`,
299
- }));
300
- await Promise.all(tasks);
314
+ });
301
315
 
302
- this.service.emit('pageTreeChange');
316
+ // 去掉旧首页
317
+ try {
318
+ await Promise.all(tasks);
319
+ } catch (e) {
320
+ // 恢复状态
321
+ rejectedPages.forEach((page) => page.assign({ isIndex: true }));
322
+
323
+ this.service.emit('pageTreeChange');
324
+ await config.defaultApp?.history.load();
325
+ config.defaultApp?.emit('saved');
326
+ return;
327
+ }
303
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');
304
341
  await config.defaultApp?.history.load();
305
342
  config.defaultApp?.emit('saved');
306
343
  }
@@ -352,8 +389,8 @@ export class Page extends Vertex {
352
389
  page.assign({
353
390
  rootView: View.from(page.rootView, null, page),
354
391
  service,
355
- tempPath: page.rootView? `/${page.rootView.name}`: '',
356
- code: page.rootView?`/ID_${page.rootView.id}`: '',
392
+ tempPath: page.rootView ? `/${page.rootView.name}` : '',
393
+ code: page.rootView ? `/ID_${page.rootView.id}` : '',
357
394
  });
358
395
 
359
396
  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
  * 子页面类,前端路由控制
@@ -199,26 +200,36 @@ export class View extends Block {
199
200
  } catch (err) { }
200
201
  })().finally(() => this.contentPromise = undefined);
201
202
  }
202
- loadAll() {
203
+ loadAll(enableCache = true) {
203
204
  // 如果有正在进行的 Promise,则直接返回它
204
205
  if (this.contentPromise)
205
206
  return this.contentPromise;
206
207
 
207
208
  return this.contentPromise = (async () => {
208
- try {
209
209
  const result: View = await viewService.load({
210
210
  path: {
211
211
  id: this.id,
212
212
  },
213
+ query: {
214
+ enableCache,
215
+ },
216
+ config: { noErrorTip: true },
213
217
  });
214
-
218
+ const oldLogics = this.$def.logics;
219
+ Object.assign(result, {
220
+ children: this.children,
221
+ })
215
222
  const temp = View.from(result, this.parent, this.page, this);
223
+ const newLogics = temp.$def.logics;
224
+ oldLogics.forEach((logic) => {
225
+ if(!newLogics.find((item) => item.id === logic.id))
226
+ logic.destroy();
227
+ });
216
228
  this.assign(temp);
217
229
  utils.traverse((current) => {
218
230
  current.node.attachNodePath(true);
219
231
  }, { node: this });
220
232
  return this;
221
- } catch (err) { }
222
233
  })().finally(() => this.contentPromise = undefined);
223
234
  }
224
235
  isContentLoaded() {
@@ -277,16 +288,6 @@ export class View extends Block {
277
288
  /* 绑定数据结构和接口 */
278
289
  addData(res: any) {
279
290
  const microService = this.parent.page.service.app.firstMicroService;
280
- const interfaces = res.interfaces as Array<Interface>;
281
- if (interfaces && interfaces.length) {
282
- interfaces.forEach((item, index) => {
283
- const itface = interfaces[index] = Interface.from(item, microService);
284
- postServiceType(itface);
285
- });
286
- microService.interfaces.unshift(...interfaces);
287
- microService.emit('interfacesChange');
288
- }
289
-
290
291
  const enums = res.enums as Array<Enum>;
291
292
  if (enums && enums.length) {
292
293
  enums.forEach((item, index) => enums[index] = Enum.from(item, microService));
@@ -307,6 +308,19 @@ export class View extends Block {
307
308
  microService.data.structures.unshift(...structures);
308
309
  updateDataTypeList();
309
310
  }
311
+
312
+ const interfaces = res.interfaces as Array<Interface>;
313
+ if (interfaces && interfaces.length) {
314
+ interfaces.forEach((item, index) => {
315
+ const itface = interfaces[index] = Interface.from(item, microService);
316
+ postServiceType(itface);
317
+ });
318
+ microService.interfaces.unshift(...interfaces);
319
+ microService.globalLogic.globalLogics.unshift(...interfaces);
320
+ microService.mountResolverOnEntity();
321
+ microService.mountResolverOnInterface();
322
+ microService.emit('interfacesChange');
323
+ }
310
324
  }
311
325
 
312
326
  @action('添加子页面')
@@ -322,7 +336,7 @@ export class View extends Block {
322
336
  operationDesc: actionOptions?.actionDesc || `添加子页面"${this.name}${this.title ? `(${this.title})` : ''}"`,
323
337
  },
324
338
  body,
325
- });
339
+ }).catch(catchFn());
326
340
  this.deepPick(result.view, ['id']);
327
341
  // 添加数据
328
342
  this.addData(result);
@@ -403,7 +417,6 @@ export class View extends Block {
403
417
  if (!this.parent)
404
418
  throw Error('该子页面为根节点!');
405
419
 
406
- try {
407
420
  await viewService.delete({
408
421
  headers: {
409
422
  appId: config.defaultApp?.id,
@@ -413,11 +426,7 @@ export class View extends Block {
413
426
  path: {
414
427
  id: this.id,
415
428
  },
416
- });
417
- } catch (err) {
418
- await config.defaultApp?.history.load();
419
- throw err;
420
- }
429
+ }).catch(catchFn());
421
430
 
422
431
  const index = this.parent.children.indexOf(this);
423
432
  ~index && this.parent.children.splice(index, 1);
@@ -449,7 +458,7 @@ export class View extends Block {
449
458
  operationDesc: actionOptions?.actionDesc || `修改子页面"${this.name}${this.title ? `(${this.title})` : ''}"`,
450
459
  },
451
460
  body,
452
- });
461
+ }).catch(catchFn());
453
462
 
454
463
  await then?.();
455
464
  await config.defaultApp?.history.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
 
@@ -5,6 +5,7 @@ import { viewService } from '../../service/page';
5
5
  import { convert2RefType, convert2SchemaType } from '../data/dataTypeUtils';
6
6
  import { getBasicTypeDefaultValue } from '../data/basicTypes';
7
7
  import { schemaService } from '../../service/common';
8
+ import { catchFn } from './ViewParam';
8
9
 
9
10
  /**
10
11
  * 页面局部变量
@@ -51,7 +52,7 @@ export class ViewVariable extends Variable {
51
52
  operationDesc: actionOptions?.actionDesc || `添加页面"${this.view.name}"局部变量"${this.name}"`,
52
53
  },
53
54
  body,
54
- });
55
+ }).catch(catchFn(this.view));
55
56
  // convert2RefType(result.schema);
56
57
  this.deepPick(result, ['id']);
57
58
  this.assign({ code: this.genCode() });
@@ -73,7 +74,6 @@ export class ViewVariable extends Variable {
73
74
  config.defaultApp?.emit('saving');
74
75
 
75
76
  if (this.id) {
76
- try {
77
77
  await viewService.deleteViewVariable({
78
78
  headers: {
79
79
  appId: config.defaultApp?.id,
@@ -83,11 +83,7 @@ export class ViewVariable extends Variable {
83
83
  query: {
84
84
  id: this.id,
85
85
  },
86
- });
87
- } catch (err) {
88
- await config.defaultApp?.history.load();
89
- throw err;
90
- }
86
+ }).catch(catchFn(this.view));
91
87
  }
92
88
 
93
89
  const { variables } = this.view.$def;
@@ -122,7 +118,7 @@ export class ViewVariable extends Variable {
122
118
  operationDesc: actionOptions?.actionDesc || `修改页面"${this.view.name}"局部变量"${this.name}"`,
123
119
  },
124
120
  body,
125
- });
121
+ }).catch(catchFn(this.view));
126
122
  // convert2RefType(result.schema);
127
123
  // this.plainAssign(result);
128
124
 
@@ -0,0 +1,112 @@
1
+ import { immutable } from '../decorators';
2
+ import { View, Element } from '..';
3
+ import permissionService from '../../service/permission';
4
+
5
+
6
+ export class Permission {
7
+ /**
8
+ * App Name
9
+ */
10
+ @immutable()
11
+ public readonly domainName: string = undefined;
12
+ /**
13
+ * 上报权限后的资源id
14
+ */
15
+ @immutable()
16
+ public readonly resourceId: string = undefined;
17
+
18
+ /**
19
+ * 应用 id
20
+ */
21
+ @immutable()
22
+ public readonly serviceId: string = undefined;
23
+
24
+ /**
25
+ * view
26
+ */
27
+ @immutable()
28
+ public readonly view: View = undefined;
29
+
30
+ /**
31
+ * element
32
+ */
33
+ @immutable()
34
+ public readonly element: Element = undefined;
35
+
36
+ /**
37
+ * @param source 需要合并的部分参数
38
+ */
39
+ constructor(source?: Partial<Permission>) {
40
+ const { domainName } = source;
41
+ Object.assign(this, source);
42
+ if (!domainName) {
43
+ throw new Error('Permission need domainName!');
44
+ }
45
+ }
46
+
47
+ async createDefaultRoleFromRoleName(roleName: string) {
48
+ if (!roleName)
49
+ return;
50
+ return await permissionService.createRole({
51
+ body: {
52
+ name: roleName,
53
+ serviceId: this.serviceId,
54
+ },
55
+ });
56
+ }
57
+
58
+ async updateRoleName(roleId: string, roleName: string) {
59
+ return await permissionService.updateRole({
60
+ body: {
61
+ id: roleId,
62
+ name: roleName,
63
+ serviceId: this.serviceId,
64
+ }
65
+ })
66
+ }
67
+
68
+ /**
69
+ *
70
+ * @param query {
71
+ * resourceId
72
+ * roleId
73
+ * }
74
+ */
75
+ async attachPermissionResource(query: Object) {
76
+ return await permissionService.attachPermissionResourceAction({ query });
77
+ }
78
+
79
+ async detachPermissionResource(query: Object) {
80
+ return await permissionService.detachPermissionResourceAction({ query });
81
+ }
82
+
83
+ async getInitRoles(resourceId: string) {
84
+ return await permissionService.getRoles({
85
+ query: {
86
+ serviceId: this.serviceId,
87
+ resourceId,
88
+ }
89
+ });
90
+ }
91
+
92
+ async attachDevRole(resourceId: string) {
93
+ const data: any = await this.getInitRoles(resourceId)|| [];
94
+ let roleId;
95
+ data.forEach((item: any) => {
96
+ if (item.name === 'DEV-AdminRole') {
97
+ roleId = item.id;
98
+ }
99
+ })
100
+ // 获取权限树资源Id
101
+ if (roleId) {
102
+ // 默认角色开启
103
+ await this.attachPermissionResource({
104
+ resourceId,
105
+ roleId,
106
+ });
107
+ await this.getInitRoles(resourceId);
108
+ }
109
+ }
110
+ }
111
+
112
+ export default Permission;