@lcap/nasl 0.3.9-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 (191) 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 +3 -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 +4 -0
  23. package/out/types/app/App.js +31 -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 +38 -5
  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 +40 -0
  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/Interface.js +5 -3
  47. package/out/types/data/Interface.js.map +1 -1
  48. package/out/types/data/dataTypes.js +1 -1
  49. package/out/types/data/dataTypes.js.map +1 -1
  50. package/out/types/data/genBlock/genCreateBlock.js +5 -5
  51. package/out/types/data/genBlock/genCreateBlock.js.map +1 -1
  52. package/out/types/data/genBlock/genCurdBlock.js +3 -3
  53. package/out/types/data/genBlock/genCurdBlock.js.map +1 -1
  54. package/out/types/data/genBlock/genCurdEditTableBlock.d.ts +3 -0
  55. package/out/types/data/genBlock/genCurdEditTableBlock.js +578 -0
  56. package/out/types/data/genBlock/genCurdEditTableBlock.js.map +1 -0
  57. package/out/types/data/genBlock/genEditTableBlock.d.ts +234 -0
  58. package/out/types/data/genBlock/genEditTableBlock.js +419 -0
  59. package/out/types/data/genBlock/genEditTableBlock.js.map +1 -0
  60. package/out/types/data/genBlock/genEnumSelectBlock.d.ts +1 -1
  61. package/out/types/data/genBlock/genEnumSelectBlock.js +2 -2
  62. package/out/types/data/genBlock/genEnumSelectBlock.js.map +1 -1
  63. package/out/types/data/genBlock/genGridViewBlock.js +12 -1
  64. package/out/types/data/genBlock/genGridViewBlock.js.map +1 -1
  65. package/out/types/data/genBlock/genListViewBlock.js +2 -2
  66. package/out/types/data/genBlock/genQueryComponent.d.ts +20 -0
  67. package/out/types/data/genBlock/genQueryComponent.js +57 -1
  68. package/out/types/data/genBlock/genQueryComponent.js.map +1 -1
  69. package/out/types/data/genBlock/genSelectBlock.js +2 -2
  70. package/out/types/data/genBlock/genTableBlock.js +23 -8
  71. package/out/types/data/genBlock/genTableBlock.js.map +1 -1
  72. package/out/types/data/genBlock/genUpdateBlock.js +5 -5
  73. package/out/types/data/genBlock/genUpdateBlock.js.map +1 -1
  74. package/out/types/data/genBlock/index.d.ts +2 -0
  75. package/out/types/data/genBlock/index.js +2 -0
  76. package/out/types/data/genBlock/index.js.map +1 -1
  77. package/out/types/data/genBlock/utils.d.ts +7 -0
  78. package/out/types/data/genBlock/utils.js +38 -1
  79. package/out/types/data/genBlock/utils.js.map +1 -1
  80. package/out/types/data/systemTypes.js +47 -0
  81. package/out/types/data/systemTypes.js.map +1 -1
  82. package/out/types/enum.d.ts +6 -0
  83. package/out/types/enum.js +11 -0
  84. package/out/types/enum.js.map +1 -0
  85. package/out/types/generator/hotReload.d.ts +2 -0
  86. package/out/types/generator/hotReload.js +12 -1
  87. package/out/types/generator/hotReload.js.map +1 -1
  88. package/out/types/index.d.ts +5 -1
  89. package/out/types/index.js +8 -2
  90. package/out/types/index.js.map +1 -1
  91. package/out/types/logic/Logic.d.ts +32 -0
  92. package/out/types/logic/Logic.js +151 -41
  93. package/out/types/logic/Logic.js.map +1 -1
  94. package/out/types/logic/LogicItem.d.ts +1 -0
  95. package/out/types/logic/LogicItem.js +48 -31
  96. package/out/types/logic/LogicItem.js.map +1 -1
  97. package/out/types/logic/Param.d.ts +1 -0
  98. package/out/types/logic/Param.js +43 -33
  99. package/out/types/logic/Param.js.map +1 -1
  100. package/out/types/logic/Return.js +17 -30
  101. package/out/types/logic/Return.js.map +1 -1
  102. package/out/types/logic/Variable.js +17 -25
  103. package/out/types/logic/Variable.js.map +1 -1
  104. package/out/types/logic/translator.js +39 -10
  105. package/out/types/logic/translator.js.map +1 -1
  106. package/out/types/nuims/Nuims.d.ts +1 -1
  107. package/out/types/nuims/Nuims.js +11 -4
  108. package/out/types/nuims/Nuims.js.map +1 -1
  109. package/out/types/page/Element.d.ts +27 -0
  110. package/out/types/page/Element.js +229 -131
  111. package/out/types/page/Element.js.map +1 -1
  112. package/out/types/page/Event.js.map +1 -1
  113. package/out/types/page/Page.d.ts +5 -0
  114. package/out/types/page/Page.js +78 -37
  115. package/out/types/page/Page.js.map +1 -1
  116. package/out/types/page/View.d.ts +18 -1
  117. package/out/types/page/View.js +119 -42
  118. package/out/types/page/View.js.map +1 -1
  119. package/out/types/page/ViewParam.d.ts +1 -0
  120. package/out/types/page/ViewParam.js +23 -4
  121. package/out/types/page/ViewParam.js.map +1 -1
  122. package/out/types/page/ViewVariable.js +13 -24
  123. package/out/types/page/ViewVariable.js.map +1 -1
  124. package/out/types/permission/Permission.d.ts +41 -0
  125. package/out/types/permission/Permission.js +122 -0
  126. package/out/types/permission/Permission.js.map +1 -0
  127. package/out/types/process/ProcessParam.js +3 -1
  128. package/out/types/process/ProcessParam.js.map +1 -1
  129. package/out/types/utils/index.d.ts +1 -0
  130. package/out/types/utils/index.js +16 -7
  131. package/out/types/utils/index.js.map +1 -1
  132. package/package.json +2 -3
  133. package/src/service/app/api.js +8 -17
  134. package/src/service/create/errHandles.js +18 -2
  135. package/src/service/create/index.js +4 -0
  136. package/src/service/developPermission/api.js +37 -0
  137. package/src/service/developPermission/index.js +13 -0
  138. package/src/service/logic/logic.js +26 -0
  139. package/src/service/page/element.js +6 -0
  140. package/src/service/permission/api.js +38 -0
  141. package/src/service/permission/index.js +13 -0
  142. package/src/service/webFile/index.js +6 -1
  143. package/src/types/app/App.ts +37 -2
  144. package/src/types/app/History.ts +3 -2
  145. package/src/types/app/Service.ts +44 -6
  146. package/src/types/cache.ts +50 -0
  147. package/src/types/cacheData.ts +7 -7
  148. package/src/types/common/Vertex.ts +30 -0
  149. package/src/types/data/Entity.ts +8 -0
  150. package/src/types/data/EntityProperty.ts +12 -0
  151. package/src/types/data/Enum.ts +5 -0
  152. package/src/types/data/Interface.ts +4 -3
  153. package/src/types/data/dataTypes.ts +1 -1
  154. package/src/types/data/genBlock/genCreateBlock.ts +5 -5
  155. package/src/types/data/genBlock/genCurdBlock.ts +3 -3
  156. package/src/types/data/genBlock/genCurdEditTableBlock.ts +581 -0
  157. package/src/types/data/genBlock/genEditTableBlock.ts +470 -0
  158. package/src/types/data/genBlock/genEnumSelectBlock.ts +2 -2
  159. package/src/types/data/genBlock/genGridViewBlock.ts +12 -1
  160. package/src/types/data/genBlock/genListViewBlock.ts +2 -2
  161. package/src/types/data/genBlock/genQueryComponent.ts +56 -0
  162. package/src/types/data/genBlock/genSelectBlock.ts +2 -2
  163. package/src/types/data/genBlock/genTableBlock.ts +28 -13
  164. package/src/types/data/genBlock/genUpdateBlock.ts +5 -5
  165. package/src/types/data/genBlock/index.ts +2 -0
  166. package/src/types/data/genBlock/utils.ts +38 -0
  167. package/src/types/data/systemTypes.ts +47 -0
  168. package/src/types/enum.ts +6 -0
  169. package/src/types/generator/hotReload.ts +10 -0
  170. package/src/types/index.ts +5 -1
  171. package/src/types/logic/Logic.ts +148 -39
  172. package/src/types/logic/LogicItem.ts +54 -37
  173. package/src/types/logic/Param.ts +43 -35
  174. package/src/types/logic/Return.ts +21 -34
  175. package/src/types/logic/Variable.ts +21 -27
  176. package/src/types/logic/translator.js +41 -14
  177. package/src/types/logic/translator_backup.js +5 -16
  178. package/src/types/nuims/Nuims.ts +11 -5
  179. package/src/types/page/Element.ts +250 -135
  180. package/src/types/page/Event.ts +0 -3
  181. package/src/types/page/Page.ts +93 -49
  182. package/src/types/page/View.ts +123 -42
  183. package/src/types/page/ViewParam.ts +22 -3
  184. package/src/types/page/ViewVariable.ts +16 -26
  185. package/src/types/page/dist/View.js +727 -0
  186. package/src/types/permission/Permission.ts +112 -0
  187. package/src/types/process/ProcessParam.ts +4 -1
  188. package/src/types/utils/index.ts +16 -7
  189. package/out/test/units/config.spec.d.ts +0 -1
  190. package/out/test/units/config.spec.js +0 -12
  191. package/out/test/units/config.spec.js.map +0 -1
@@ -25,8 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  return result;
26
26
  };
27
27
  Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.Element = void 0;
29
- // import stringify = require('json-stringify-safe');
28
+ exports.Element = exports.catchFn = void 0;
30
29
  const decorators_1 = require("../decorators");
31
30
  const __1 = require("..");
32
31
  const compiler = __importStar(require("vue-template-compiler"));
@@ -35,6 +34,19 @@ const page_1 = require("../../service/page");
35
34
  const cacheData_1 = require("../cacheData");
36
35
  const babelParser = __importStar(require("@babel/parser"));
37
36
  const lodash_1 = require("lodash");
37
+ const cache_1 = require("../cache");
38
+ const enum_1 = require("../enum");
39
+ function catchFn(view) {
40
+ return async (err) => {
41
+ if (err.code !== enum_1.BusinessCode.HasReferenced) // 节点被引用,不用刷新数据
42
+ await cache_1.refreshHtml(view);
43
+ else
44
+ __1.config.defaultApp?.emit('saved', err);
45
+ __1.config.defaultApp?.history.load();
46
+ throw err;
47
+ };
48
+ }
49
+ exports.catchFn = catchFn;
38
50
  /**
39
51
  * 前端页面元素
40
52
  * @example
@@ -69,6 +81,10 @@ class Element extends __1.Vertex {
69
81
  * Vue 中的 ref
70
82
  */
71
83
  this.name = undefined;
84
+ /*
85
+ * 描述信息
86
+ */
87
+ this.description = undefined;
72
88
  /**
73
89
  * 属性列表
74
90
  * 和原来的 attrsList 不同,注意区分
@@ -133,9 +149,6 @@ class Element extends __1.Vertex {
133
149
  */
134
150
  this.children = [];
135
151
  source && this.assign(source);
136
- // 为了给生成的节点使用
137
- // !this.id && this.assign({ id: uuidv4() });
138
- // this.assign({ id: 'temp-' + uuidv4() });
139
152
  }
140
153
  assign(source) {
141
154
  ['attrList', 'eventList', 'directiveList', 'children'].forEach((key) => {
@@ -153,59 +166,42 @@ class Element extends __1.Vertex {
153
166
  return this;
154
167
  }
155
168
  __1.config.defaultApp?.emit('saving');
156
- try {
157
- if (actionOptions?.actionMode !== __1.ACTION_MODE.undoRedo) {
158
- const body = this.toJSON();
159
- body.parentId = this.parent && this.parent.id;
160
- body._posIndex = this.parent && this.parent.children.indexOf(this);
161
- __1.utils.logger.debug('添加元素', body);
162
- const result = await page_1.elementService.create({
163
- headers: {
164
- appId: __1.config.defaultApp?.id,
165
- operationAction: 'Element.create',
166
- operationDesc: `添加组件"${this.getElementTitle()}"`,
167
- },
168
- body,
169
- });
170
- // Nuims createResource
171
- // Element 对应资源增删在 undo/redo 情况下可能存在权限丢失的情况
172
- // 暂时只增不减
173
- // new Nuims({
174
- // domainName: this.view.page.service.app.name,
175
- // element: this,
176
- // }).createResource();
177
- this.deepPick(result, ['id', 'parentId', 'elementId']);
178
- // attr,directive,event的id,exprssion需要合并
179
- this.attrList.forEach((attr, index) => {
180
- attr.deepPick(result.attrList[index], ['id', 'expression']);
181
- });
182
- this.directiveList.forEach((directive, index) => {
183
- directive.deepPick(result.directiveList[index], ['id', 'expression']);
184
- });
185
- this.eventList.forEach((event, index) => {
186
- event.deepPick(result.eventList[index], ['id']);
187
- });
188
- }
189
- this.view && this.view.emit('change');
190
- if (actionOptions?.loadHistory !== false) {
191
- await __1.config.defaultApp?.history.load(actionOptions?.actionMode !== __1.ACTION_MODE.undoRedo && {
169
+ if (actionOptions?.actionMode !== __1.ACTION_MODE.undoRedo) {
170
+ const body = this.toJSON();
171
+ body.parentId = this.parent && this.parent.id;
172
+ body._posIndex = this.parent && this.parent.children.indexOf(this);
173
+ __1.utils.logger.debug('添加元素', body);
174
+ const result = await page_1.elementService.create({
175
+ headers: {
176
+ appId: __1.config.defaultApp?.id,
192
177
  operationAction: 'Element.create',
193
- operationBeforeImage: null,
194
- operationAfterImage: JSON.parse(JSON.stringify(this)),
195
178
  operationDesc: `添加组件"${this.getElementTitle()}"`,
196
- });
197
- __1.config.defaultApp?.emit('saved');
198
- }
199
- return this;
179
+ },
180
+ body,
181
+ }).catch(catchFn(this.view));
182
+ this.deepPick(result, ['id', 'parentId', 'elementId']);
183
+ // attr,directive,event的id,expression需要合并
184
+ this.attrList.forEach((attr, index) => {
185
+ attr.deepPick(result.attrList[index], ['id', 'expression']);
186
+ });
187
+ this.directiveList.forEach((directive, index) => {
188
+ directive.deepPick(result.directiveList[index], ['id', 'expression']);
189
+ });
190
+ this.eventList.forEach((event, index) => {
191
+ event.deepPick(result.eventList[index], ['id']);
192
+ });
200
193
  }
201
- catch (err) {
202
- if (this.view) {
203
- await this.view.load();
204
- this.view.emit('change');
205
- __1.config.defaultApp?.emit('saved');
206
- }
207
- throw err;
194
+ this.view && this.view.emit('change');
195
+ if (actionOptions?.loadHistory !== false) {
196
+ await __1.config.defaultApp?.history.load(actionOptions?.actionMode !== __1.ACTION_MODE.undoRedo && {
197
+ operationAction: 'Element.create',
198
+ operationBeforeImage: null,
199
+ operationAfterImage: JSON.parse(JSON.stringify(this)),
200
+ operationDesc: `添加组件"${this.getElementTitle()}"`,
201
+ });
202
+ __1.config.defaultApp?.emit('saved');
208
203
  }
204
+ return this;
209
205
  }
210
206
  /**
211
207
  * 删除元素
@@ -214,6 +210,7 @@ class Element extends __1.Vertex {
214
210
  if (actionOptions?.actionMode === __1.ACTION_MODE.local) {
215
211
  const index = this.parent.children.indexOf(this);
216
212
  ~index && this.parent.children.splice(index, 1);
213
+ this.deepRemoveElementsName();
217
214
  this.view && this.view.emit('local-change');
218
215
  return this;
219
216
  }
@@ -222,33 +219,22 @@ class Element extends __1.Vertex {
222
219
  throw Error('该元素为根节点!');
223
220
  if (actionOptions?.actionMode !== __1.ACTION_MODE.undoRedo) {
224
221
  if (this.id) {
225
- try {
226
- await page_1.elementService.delete({
227
- headers: {
228
- appId: __1.config.defaultApp?.id,
229
- operationAction: 'Element.delete',
230
- operationDesc: `删除组件"${this.getElementTitle()}"`,
231
- },
232
- query: {
233
- id: this.id,
234
- },
235
- });
236
- }
237
- catch (err) {
238
- await __1.config.defaultApp?.history.load();
239
- throw err;
240
- }
241
- // Nuims deleteResource
242
- // Element 对应资源增删在 undo/redo 情况下可能存在权限丢失的情况
243
- // 暂时只增不减
244
- // new Nuims({
245
- // domainName: this.view.page.service.app.name,
246
- // element: this,
247
- // }).deleteResources();
222
+ await page_1.elementService.delete({
223
+ headers: {
224
+ appId: __1.config.defaultApp?.id,
225
+ operationAction: 'Element.delete',
226
+ operationDesc: `删除组件"${this.getElementTitle()}"`,
227
+ },
228
+ query: {
229
+ id: this.id,
230
+ },
231
+ }).catch(catchFn(this.view));
248
232
  }
249
233
  }
250
234
  const index = this.parent.children.indexOf(this);
251
235
  ~index && this.parent.children.splice(index, 1);
236
+ // 递归删除组件名的缓存
237
+ this.deepRemoveElementsName();
252
238
  this.destroy();
253
239
  this.view && this.view.emit('change');
254
240
  if (actionOptions?.loadHistory !== false) {
@@ -267,37 +253,45 @@ class Element extends __1.Vertex {
267
253
  async update(source, actionOptions) {
268
254
  __1.config.defaultApp?.emit('saving');
269
255
  source && this.assign(source);
270
- try {
271
- if (actionOptions?.actionMode !== __1.ACTION_MODE.undoRedo) {
272
- const body = this.toPlainJSON();
273
- __1.utils.logger.debug('修改组件', body);
274
- await page_1.elementService.update({
275
- headers: {
276
- appId: __1.config.defaultApp?.id,
277
- operationAction: actionOptions?.actionName || 'Element.update',
278
- operationDesc: actionOptions?.actionDesc || `修改组件"${this.getElementTitle()}"`,
279
- },
280
- body,
281
- });
282
- }
283
- this.view && this.view.emit('change');
284
- await __1.config.defaultApp?.history.load(actionOptions?.actionMode !== __1.ACTION_MODE.undoRedo && {
285
- operationAction: 'Element.update',
286
- operationBeforeImage: null,
287
- operationAfterImage: null,
288
- operationDesc: `修改组件"${this.getElementTitle()}"`,
289
- });
290
- __1.config.defaultApp?.emit('saved');
291
- return this;
292
- }
293
- catch (err) {
294
- if (this.view) {
295
- await this.view.load();
296
- this.view.emit('change');
297
- __1.config.defaultApp?.emit('saved');
298
- }
299
- throw err;
256
+ if (actionOptions?.actionMode !== __1.ACTION_MODE.undoRedo) {
257
+ const body = this.toPlainJSON();
258
+ __1.utils.logger.debug('修改组件', body);
259
+ await page_1.elementService.update({
260
+ headers: {
261
+ appId: __1.config.defaultApp?.id,
262
+ operationAction: actionOptions?.actionName || 'Element.update',
263
+ operationDesc: actionOptions?.actionDesc || `修改组件"${this.getElementTitle()}"`,
264
+ },
265
+ body,
266
+ }).catch(catchFn(this.view));
300
267
  }
268
+ this.view && this.view.emit('change');
269
+ await __1.config.defaultApp?.history.load(actionOptions?.actionMode !== __1.ACTION_MODE.undoRedo && {
270
+ operationAction: 'Element.update',
271
+ operationBeforeImage: null,
272
+ operationAfterImage: null,
273
+ operationDesc: `修改组件"${this.getElementTitle()}"`,
274
+ });
275
+ __1.config.defaultApp?.emit('saved');
276
+ return this;
277
+ }
278
+ /**
279
+ * 按当前 id 加载逻辑数据
280
+ */
281
+ async load() {
282
+ if (!this.id)
283
+ return;
284
+ const result = await page_1.elementService.load({
285
+ headers: {
286
+ appId: __1.config.defaultApp?.id,
287
+ },
288
+ query: {
289
+ id: this.id,
290
+ },
291
+ config: { noErrorTip: true },
292
+ });
293
+ const newElement = Element.from(result, this.parent, this.view);
294
+ this.assign(newElement);
301
295
  }
302
296
  async move(options, actionOptions) {
303
297
  try {
@@ -326,12 +320,17 @@ class Element extends __1.Vertex {
326
320
  await __1.config.defaultApp?.history.load();
327
321
  }
328
322
  __1.config.defaultApp?.emit('element.moved');
323
+ __1.config.defaultApp?.emit('saved');
329
324
  }
330
325
  catch (err) {
331
326
  if (this.view) {
332
327
  await this.view.load();
333
328
  this.view.emit('change');
334
329
  }
330
+ __1.config.defaultApp?.emit('saved', {
331
+ action: 'move',
332
+ err,
333
+ });
335
334
  throw err;
336
335
  }
337
336
  }
@@ -343,6 +342,8 @@ class Element extends __1.Vertex {
343
342
  const code = this.toVue();
344
343
  const index = this.parent.children.indexOf(this);
345
344
  const newNode = Element.fromHTML(code, this.parent, this.view);
345
+ // 复制的元素需重新命名
346
+ newNode.deepRenameElements();
346
347
  const mergeExpression = (originList, newList) => {
347
348
  newList.forEach((item) => {
348
349
  const originItem = originList.find((originItem) => originItem.name === item.name);
@@ -392,6 +393,14 @@ class Element extends __1.Vertex {
392
393
  }
393
394
  }
394
395
  };
396
+ const arrayComp = this.findElementsByTag('u-modal');
397
+ const existingNames = Object.values(lodash_1.mapValues(arrayComp, (o) => o.name));
398
+ // 处理弹窗组件的命名问题
399
+ if (newNode.tag === 'u-modal') {
400
+ Object.assign(newNode, {
401
+ name: __1.utils.unique('saveModal1', existingNames),
402
+ });
403
+ }
395
404
  traverseMergeNode(this, newNode);
396
405
  ~index && this.parent.children.splice(index + 1, 0, newNode);
397
406
  this.parent.children.forEach((item, index) => {
@@ -417,6 +426,8 @@ class Element extends __1.Vertex {
417
426
  }
418
427
  if (lodash_1.isPlainObject(child)) {
419
428
  child = Element.from(child, this, this.view);
429
+ child.initElementName();
430
+ child.deepRenameElements();
420
431
  }
421
432
  if (!this.children.includes(child)) {
422
433
  const index = child._posIndex === undefined ? this.children.length : child._posIndex;
@@ -447,11 +458,27 @@ class Element extends __1.Vertex {
447
458
  await this.update(undefined, {
448
459
  actionDesc: `设置组件"${this.getElementTitle()}"的名称为"${name}"`,
449
460
  });
450
- // 同步权限
451
- new __1.Nuims({
452
- domainName: this.view.page.service.app.name,
453
- element: this,
454
- }).editResourceFromResourceValue(oldName ? `${this.view.tempPath}/${oldName}` : null);
461
+ if (!window.globalData.hasUserCenter) {
462
+ // 同步权限
463
+ new __1.Nuims({
464
+ domainName: this.view.page.service.app.name,
465
+ element: this,
466
+ }).editResourceFromResourceValue(oldName ? `${this.view.tempPath}/${oldName}` : null);
467
+ }
468
+ this.view && this.view.emit('change');
469
+ if (this.view && this.view.page && this.view.page.service) {
470
+ this.view.page.service.emit('vertexIdToNameChange', this.id, this.name);
471
+ }
472
+ }
473
+ /**
474
+ * 更新描述信息
475
+ * @param description
476
+ */
477
+ async setDescription(description) {
478
+ this.assign({ description });
479
+ await this.update(undefined, {
480
+ actionDesc: `设置组件"${this.getElementTitle()}"的描述为"${description}"`,
481
+ });
455
482
  this.view && this.view.emit('change');
456
483
  if (this.view && this.view.page && this.view.page.service) {
457
484
  this.view.page.service.emit('vertexIdToNameChange', this.id, this.name);
@@ -494,9 +521,7 @@ class Element extends __1.Vertex {
494
521
  async setAttr(name, type, value) {
495
522
  let attr = this.getAttr(name);
496
523
  //
497
- if (value === undefined) {
498
- }
499
- else {
524
+ if (value !== undefined) {
500
525
  if (typeof value !== 'string')
501
526
  value = JSON.stringify(value);
502
527
  if (attr) {
@@ -506,7 +531,7 @@ class Element extends __1.Vertex {
506
531
  });
507
532
  await attr.update(undefined, {
508
533
  actionDesc: `设置组件"${this.getElementTitle()}"属性"${attr.name}"的值为"${attr.value}"`,
509
- });
534
+ }).catch(catchFn(this.view));
510
535
  }
511
536
  else {
512
537
  attr = __1.Attr.from({
@@ -517,7 +542,7 @@ class Element extends __1.Vertex {
517
542
  }, this);
518
543
  await attr.create(undefined, {
519
544
  actionDesc: `设置组件"${this.getElementTitle()}"属性"${attr.name}"的值为"${attr.value}"`,
520
- });
545
+ }).catch(catchFn(this.view));
521
546
  this.attrList.push(attr);
522
547
  }
523
548
  }
@@ -531,7 +556,7 @@ class Element extends __1.Vertex {
531
556
  let event = new __1.Event(data);
532
557
  await event.create(undefined, Object.assign({
533
558
  actionDesc: `添加组件"${this.getElementTitle()}"事件"${event.name}"`,
534
- }, actionOptions));
559
+ }, actionOptions)).catch(catchFn(this.view));
535
560
  event = __1.Event.from(event, this);
536
561
  this.eventList.push(event);
537
562
  this.view && this.view.emit('change');
@@ -549,7 +574,7 @@ class Element extends __1.Vertex {
549
574
  event = this.eventList.find((item) => item.id === event.id);
550
575
  await event.delete(undefined, Object.assign({
551
576
  actionDesc: `删除组件"${this.getElementTitle()}"事件"${event.name}"`,
552
- }, actionOptions));
577
+ }, actionOptions)).catch(catchFn(this.view));
553
578
  const index = this.eventList.indexOf(event);
554
579
  ~index && this.eventList.splice(index, 1);
555
580
  this.view && this.view.emit('change');
@@ -564,7 +589,7 @@ class Element extends __1.Vertex {
564
589
  const directive = new __1.Directive(data);
565
590
  await directive.create(undefined, Object.assign({
566
591
  actionDesc: `添加组件"${this.getElementTitle()}"指令"${directive.name}"`,
567
- }, actionOptions));
592
+ }, actionOptions)).catch(catchFn(this.view));
568
593
  this.directiveList.push(__1.Directive.from(directive, this));
569
594
  this.view && this.view.emit('change');
570
595
  }
@@ -578,7 +603,7 @@ class Element extends __1.Vertex {
578
603
  directive = this.directiveList.find((item) => item.id === directive.id);
579
604
  await directive.delete(undefined, Object.assign({
580
605
  actionDesc: `删除组件"${this.getElementTitle()}"属性"${directive.name}"`,
581
- }, actionOptions));
606
+ }, actionOptions)).catch(catchFn(this.view));
582
607
  const index = this.directiveList.indexOf(directive);
583
608
  ~index && this.directiveList.splice(index, 1);
584
609
  this.view && this.view.emit('change');
@@ -652,8 +677,11 @@ class Element extends __1.Vertex {
652
677
  if (attr.level === __1.LEVEL_ENUM.attr) {
653
678
  const api = __1.config.allNodesAPI[el.tag];
654
679
  const apiOfAttr = api && api.attrs && api.attrs.find((_attr) => _attr.name === attr.name);
655
- if (apiOfAttr && apiOfAttr['designer-value']) {
656
- const designerValue = apiOfAttr['designer-value'].replace(/"/g, '\'');
680
+ if (apiOfAttr && apiOfAttr['designer-value'] !== undefined) {
681
+ let designerValue = apiOfAttr['designer-value'];
682
+ if (typeof designerValue === 'string') {
683
+ designerValue = designerValue.replace(/"/g, '\'');
684
+ }
657
685
  try {
658
686
  json5.parse(designerValue);
659
687
  return `:${attr.name}="${designerValue}"`;
@@ -739,6 +767,63 @@ class Element extends __1.Vertex {
739
767
  }
740
768
  }
741
769
  }
770
+ findElementsByTag(tag) {
771
+ let existingNames = [];
772
+ existingNames = this.findElementsByTagCurrent(tag, existingNames);
773
+ this.findElementsByTagInChildren(this.view.$html.children, tag, existingNames);
774
+ return existingNames;
775
+ }
776
+ findElementsByTagCurrent(tag, existingNames) {
777
+ if (this.tag === tag) {
778
+ existingNames.push(this);
779
+ }
780
+ return existingNames;
781
+ }
782
+ findElementsByTagInChildren(children, tag, existingNames) {
783
+ for (const child of children) {
784
+ const result = child.findElementByTag(tag);
785
+ if (child.children) {
786
+ this.findElementsByTagInChildren(child.children, tag, existingNames);
787
+ }
788
+ if (result) {
789
+ existingNames.push(result);
790
+ }
791
+ }
792
+ }
793
+ // 初始化组件名
794
+ initElementName() {
795
+ if (Element.ignoreTag.includes(this.tag)) {
796
+ return;
797
+ }
798
+ const name = this.genElementName();
799
+ this.assign({ name });
800
+ this.view.addElementName(name);
801
+ }
802
+ // 生成新的组件名
803
+ genElementName() {
804
+ const compNameSet = this.view.elementNameSet;
805
+ const tagName = this.tag.replace(Element.TAG_NAME_REG, '').replace(/-/g, '_');
806
+ const componentName = __1.utils.unique(tagName + '1', compNameSet);
807
+ return componentName;
808
+ }
809
+ // 递归生成组件名
810
+ deepRenameElements() {
811
+ return this.traverseChildren((ele) => {
812
+ ele.initElementName();
813
+ });
814
+ }
815
+ // 递归删除组件名的缓存
816
+ deepRemoveElementsName() {
817
+ return this.traverseChildren((ele) => {
818
+ this.view.removeElementName(ele.name);
819
+ });
820
+ }
821
+ // 递归遍历组件
822
+ traverseChildren(cb) {
823
+ __1.utils.traverse((current) => {
824
+ cb(current.node);
825
+ }, { node: this });
826
+ }
742
827
  /**
743
828
  * 从 Vue 的 ASTNode 转换成 ASL 元素
744
829
  * @param astNode Vue 的 ASTNode
@@ -780,8 +865,6 @@ class Element extends __1.Vertex {
780
865
  astNode.tag = 'u-router-view';
781
866
  }
782
867
  }
783
- // if (astNode.tag === 'template')
784
- // astNode.tag = 'div';
785
868
  element = new Element({
786
869
  tag: astNode.tag,
787
870
  name: astNode.attrsMap.ref,
@@ -823,7 +906,6 @@ class Element extends __1.Vertex {
823
906
  }
824
907
  }
825
908
  element.attrList.push(attr);
826
- // element.attrMap[attr.name] = attr;
827
909
  });
828
910
  // compiler 处理:value.sync 时会加上update:value事件,需要过滤
829
911
  astNode.events && Object.keys(astNode.events).filter((name) => !name.startsWith('update:')).forEach((name) => {
@@ -834,10 +916,6 @@ class Element extends __1.Vertex {
834
916
  value,
835
917
  logicId: value[0] === '$' ? undefined : value,
836
918
  }, element));
837
- // element.eventMap[name] = new Event({
838
- // name,
839
- // value: oldEvent.value,
840
- // });
841
919
  });
842
920
  astNode.directives && astNode.directives.forEach((directive) => {
843
921
  if (directive.name === 'model') {
@@ -864,7 +942,6 @@ class Element extends __1.Vertex {
864
942
  arg: directive.arg,
865
943
  modifiers: directive.modifiers,
866
944
  }, element));
867
- // element.directiveMap[directive.name] = );
868
945
  }
869
946
  });
870
947
  if (astNode.if) {
@@ -1205,6 +1282,10 @@ class Element extends __1.Vertex {
1205
1282
  const element = this.parse(html, context);
1206
1283
  __1.utils.traverse((current) => {
1207
1284
  current.node.assign({ view, parent: current.parent });
1285
+ // 生成唯一组件名 依赖element.view
1286
+ if (!current.node.name) {
1287
+ current.node.initElementName();
1288
+ }
1208
1289
  }, { node: element, parent });
1209
1290
  return element;
1210
1291
  }
@@ -1225,6 +1306,14 @@ class Element extends __1.Vertex {
1225
1306
  return element;
1226
1307
  }
1227
1308
  }
1309
+ /**
1310
+ * 标签名前缀
1311
+ */
1312
+ Element.TAG_NAME_REG = /^([lieu]|van)[-_]/;
1313
+ /**
1314
+ * 忽略命名的标签
1315
+ */
1316
+ Element.ignoreTag = ['div', 'span'];
1228
1317
  __decorate([
1229
1318
  decorators_1.immutable()
1230
1319
  ], Element.prototype, "level", void 0);
@@ -1240,6 +1329,9 @@ __decorate([
1240
1329
  __decorate([
1241
1330
  decorators_1.immutable()
1242
1331
  ], Element.prototype, "name", void 0);
1332
+ __decorate([
1333
+ decorators_1.immutable()
1334
+ ], Element.prototype, "description", void 0);
1243
1335
  __decorate([
1244
1336
  decorators_1.immutable()
1245
1337
  ], Element.prototype, "attrList", void 0);
@@ -1317,6 +1409,12 @@ __decorate([
1317
1409
  __decorate([
1318
1410
  decorators_1.action('删除组件指令')
1319
1411
  ], Element.prototype, "deleteDirective", null);
1412
+ __decorate([
1413
+ decorators_1.immutable()
1414
+ ], Element, "TAG_NAME_REG", void 0);
1415
+ __decorate([
1416
+ decorators_1.immutable()
1417
+ ], Element, "ignoreTag", void 0);
1320
1418
  exports.Element = Element;
1321
1419
  exports.default = Element;
1322
1420
  //# sourceMappingURL=Element.js.map