@lcap/nasl 0.3.9-beta → 0.3.10-beta.nocache
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.
- package/out/service/create/errHandles.js +7 -2
- package/out/service/create/errHandles.js.map +1 -1
- package/out/service/logic/logic.d.ts +27 -0
- package/out/service/logic/logic.js +20 -0
- package/out/service/logic/logic.js.map +1 -1
- package/out/service/page/element.d.ts +9 -0
- package/out/service/page/element.js +6 -0
- package/out/service/page/element.js.map +1 -1
- package/out/service/permission/api.d.ts +57 -0
- package/out/service/permission/api.js +41 -0
- package/out/service/permission/api.js.map +1 -0
- package/out/service/permission/index.d.ts +2 -0
- package/out/service/permission/index.js +17 -0
- package/out/service/permission/index.js.map +1 -0
- package/out/service/webFile/index.js +5 -0
- package/out/service/webFile/index.js.map +1 -1
- package/out/types/app/Service.d.ts +2 -2
- package/out/types/app/Service.js +28 -3
- package/out/types/app/Service.js.map +1 -1
- package/out/types/cache.d.ts +6 -0
- package/out/types/cache.js +54 -0
- package/out/types/cache.js.map +1 -0
- package/out/types/common/Vertex.d.ts +25 -0
- package/out/types/common/Vertex.js +40 -0
- package/out/types/common/Vertex.js.map +1 -1
- package/out/types/data/Entity.js +1 -0
- package/out/types/data/Entity.js.map +1 -1
- package/out/types/data/Enum.d.ts +5 -0
- package/out/types/data/Enum.js +5 -0
- package/out/types/data/Enum.js.map +1 -1
- package/out/types/data/Interface.js +5 -3
- package/out/types/data/Interface.js.map +1 -1
- package/out/types/data/genBlock/genCreateBlock.js +5 -5
- package/out/types/data/genBlock/genCreateBlock.js.map +1 -1
- package/out/types/data/genBlock/genCurdBlock.js +3 -3
- package/out/types/data/genBlock/genCurdBlock.js.map +1 -1
- package/out/types/data/genBlock/genEnumSelectBlock.d.ts +1 -1
- package/out/types/data/genBlock/genEnumSelectBlock.js +2 -2
- package/out/types/data/genBlock/genEnumSelectBlock.js.map +1 -1
- package/out/types/data/genBlock/genGridViewBlock.js +12 -1
- package/out/types/data/genBlock/genGridViewBlock.js.map +1 -1
- package/out/types/data/genBlock/genListViewBlock.js +2 -2
- package/out/types/data/genBlock/genSelectBlock.js +2 -2
- package/out/types/data/genBlock/genTableBlock.js +14 -3
- package/out/types/data/genBlock/genTableBlock.js.map +1 -1
- package/out/types/data/genBlock/genUpdateBlock.js +5 -5
- package/out/types/data/genBlock/genUpdateBlock.js.map +1 -1
- package/out/types/data/systemTypes.js +47 -0
- package/out/types/data/systemTypes.js.map +1 -1
- package/out/types/enum.d.ts +6 -0
- package/out/types/enum.js +11 -0
- package/out/types/enum.js.map +1 -0
- package/out/types/generator/hotReload.d.ts +2 -0
- package/out/types/generator/hotReload.js +12 -1
- package/out/types/generator/hotReload.js.map +1 -1
- package/out/types/index.d.ts +4 -0
- package/out/types/index.js +6 -1
- package/out/types/index.js.map +1 -1
- package/out/types/logic/Logic.d.ts +28 -0
- package/out/types/logic/Logic.js +116 -31
- package/out/types/logic/Logic.js.map +1 -1
- package/out/types/logic/LogicItem.d.ts +1 -0
- package/out/types/logic/LogicItem.js +43 -24
- package/out/types/logic/LogicItem.js.map +1 -1
- package/out/types/logic/Param.d.ts +1 -0
- package/out/types/logic/Param.js +38 -20
- package/out/types/logic/Param.js.map +1 -1
- package/out/types/logic/Return.js +14 -19
- package/out/types/logic/Return.js.map +1 -1
- package/out/types/logic/Variable.js +14 -19
- package/out/types/logic/Variable.js.map +1 -1
- package/out/types/logic/translator.js +0 -2
- package/out/types/logic/translator.js.map +1 -1
- package/out/types/nuims/Nuims.d.ts +1 -1
- package/out/types/nuims/Nuims.js +11 -4
- package/out/types/nuims/Nuims.js.map +1 -1
- package/out/types/page/Element.d.ts +8 -0
- package/out/types/page/Element.js +145 -129
- package/out/types/page/Element.js.map +1 -1
- package/out/types/page/Event.js.map +1 -1
- package/out/types/page/Page.d.ts +1 -0
- package/out/types/page/Page.js +71 -37
- package/out/types/page/Page.js.map +1 -1
- package/out/types/page/View.d.ts +1 -1
- package/out/types/page/View.js +50 -42
- package/out/types/page/View.js.map +1 -1
- package/out/types/page/ViewParam.d.ts +1 -0
- package/out/types/page/ViewParam.js +23 -4
- package/out/types/page/ViewParam.js.map +1 -1
- package/out/types/page/ViewVariable.js +13 -18
- package/out/types/page/ViewVariable.js.map +1 -1
- package/out/types/permission/Permission.d.ts +41 -0
- package/out/types/permission/Permission.js +122 -0
- package/out/types/permission/Permission.js.map +1 -0
- package/package.json +2 -3
- package/src/service/create/errHandles.js +6 -2
- package/src/service/developPermission/api.js +37 -0
- package/src/service/developPermission/index.js +13 -0
- package/src/service/logic/logic.js +20 -0
- package/src/service/page/element.js +6 -0
- package/src/service/permission/api.js +38 -0
- package/src/service/permission/index.js +13 -0
- package/src/service/webFile/index.js +6 -1
- package/src/types/app/Service.ts +32 -3
- package/src/types/cache.ts +50 -0
- package/src/types/common/Vertex.ts +30 -0
- package/src/types/data/Entity.ts +1 -0
- package/src/types/data/Enum.ts +5 -0
- package/src/types/data/Interface.ts +4 -3
- package/src/types/data/genBlock/genCreateBlock.ts +5 -5
- package/src/types/data/genBlock/genCurdBlock.ts +3 -3
- package/src/types/data/genBlock/genEnumSelectBlock.ts +2 -2
- package/src/types/data/genBlock/genGridViewBlock.ts +12 -1
- package/src/types/data/genBlock/genListViewBlock.ts +2 -2
- package/src/types/data/genBlock/genSelectBlock.ts +2 -2
- package/src/types/data/genBlock/genTableBlock.ts +14 -3
- package/src/types/data/genBlock/genUpdateBlock.ts +5 -5
- package/src/types/data/systemTypes.ts +47 -0
- package/src/types/enum.ts +6 -0
- package/src/types/generator/hotReload.ts +10 -0
- package/src/types/index.ts +4 -0
- package/src/types/logic/Logic.ts +109 -28
- package/src/types/logic/LogicItem.ts +48 -28
- package/src/types/logic/Param.ts +26 -8
- package/src/types/logic/Return.ts +4 -9
- package/src/types/logic/Variable.ts +4 -8
- package/src/types/logic/translator.js +0 -4
- package/src/types/logic/translator_backup.js +5 -16
- package/src/types/nuims/Nuims.ts +11 -5
- package/src/types/page/Element.ts +101 -73
- package/src/types/page/Event.ts +0 -3
- package/src/types/page/Page.ts +86 -49
- package/src/types/page/View.ts +31 -22
- package/src/types/page/ViewParam.ts +22 -3
- package/src/types/page/ViewVariable.ts +4 -8
- package/src/types/page/dist/View.js +727 -0
- package/src/types/permission/Permission.ts +112 -0
- package/out/test/units/config.spec.d.ts +0 -1
- package/out/test/units/config.spec.js +0 -12
- package/out/test/units/config.spec.js.map +0 -1
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
// import stringify = require('json-stringify-safe');
|
|
2
1
|
import { action, circular, excludedInJSON, immutable } from '../decorators';
|
|
3
|
-
import { config,
|
|
2
|
+
import { config, utils, LEVEL_ENUM, Vertex, View, Attr, Directive, Event, ExpressionNode, dataTypesMap, LogicItem, ActionOptions, ACTION_MODE, Nuims, Structure } from '..';
|
|
4
3
|
import * as compiler from 'vue-template-compiler';
|
|
5
4
|
import * as json5 from 'json5';
|
|
6
|
-
import { elementService
|
|
5
|
+
import { elementService } from '../../service/page';
|
|
7
6
|
import { vertexsMap } from '../cacheData';
|
|
8
7
|
import Variable from '../logic/Variable';
|
|
9
8
|
import * as babelParser from '@babel/parser';
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
9
|
+
import { isPlainObject, cloneDeep, mapValues } from 'lodash';
|
|
10
|
+
import * as utilsAll from '../../../src/types/utils/string';
|
|
11
|
+
import { refreshHtml } from '../cache';
|
|
12
|
+
import { BusinessCode } from '../enum';
|
|
12
13
|
|
|
13
14
|
export interface ElementToVueOptions {
|
|
14
15
|
indentStyle?: 'space' | 'tab';
|
|
@@ -28,6 +29,18 @@ export interface ParseContext {
|
|
|
28
29
|
[key: string]: any;
|
|
29
30
|
}
|
|
30
31
|
|
|
32
|
+
export function catchFn(view: View) {
|
|
33
|
+
return async (err: any) => {
|
|
34
|
+
if(err.code !== BusinessCode.HasReferenced) // 节点被引用,不用刷新数据
|
|
35
|
+
await refreshHtml(view);
|
|
36
|
+
else
|
|
37
|
+
config.defaultApp?.emit('saved', err);
|
|
38
|
+
|
|
39
|
+
config.defaultApp?.history.load();
|
|
40
|
+
throw err;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
31
44
|
/**
|
|
32
45
|
* 前端页面元素
|
|
33
46
|
* @example
|
|
@@ -142,15 +155,13 @@ export class Element extends Vertex {
|
|
|
142
155
|
*/
|
|
143
156
|
@immutable()
|
|
144
157
|
public readonly children?: Array<Element> = [];
|
|
158
|
+
|
|
145
159
|
/**
|
|
146
160
|
* @param source 需要合并的部分参数
|
|
147
161
|
*/
|
|
148
162
|
constructor(source?: Partial<Element>) {
|
|
149
163
|
super();
|
|
150
164
|
source && this.assign(source);
|
|
151
|
-
// 为了给生成的节点使用
|
|
152
|
-
// !this.id && this.assign({ id: uuidv4() });
|
|
153
|
-
// this.assign({ id: 'temp-' + uuidv4() });
|
|
154
165
|
}
|
|
155
166
|
assign(source?: any) {
|
|
156
167
|
['attrList', 'eventList', 'directiveList', 'children'].forEach((key) => {
|
|
@@ -170,7 +181,6 @@ export class Element extends Vertex {
|
|
|
170
181
|
}
|
|
171
182
|
|
|
172
183
|
config.defaultApp?.emit('saving');
|
|
173
|
-
try {
|
|
174
184
|
if (actionOptions?.actionMode !== ACTION_MODE.undoRedo) {
|
|
175
185
|
const body = this.toJSON();
|
|
176
186
|
body.parentId = this.parent && this.parent.id;
|
|
@@ -183,15 +193,7 @@ export class Element extends Vertex {
|
|
|
183
193
|
operationDesc: `添加组件"${this.getElementTitle()}"`,
|
|
184
194
|
},
|
|
185
195
|
body,
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
// Nuims createResource
|
|
189
|
-
// Element 对应资源增删在 undo/redo 情况下可能存在权限丢失的情况
|
|
190
|
-
// 暂时只增不减
|
|
191
|
-
// new Nuims({
|
|
192
|
-
// domainName: this.view.page.service.app.name,
|
|
193
|
-
// element: this,
|
|
194
|
-
// }).createResource();
|
|
196
|
+
}).catch(catchFn(this.view));
|
|
195
197
|
|
|
196
198
|
this.deepPick(result, ['id', 'parentId', 'elementId']);
|
|
197
199
|
// attr,directive,event的id,exprssion需要合并
|
|
@@ -218,14 +220,6 @@ export class Element extends Vertex {
|
|
|
218
220
|
config.defaultApp?.emit('saved');
|
|
219
221
|
}
|
|
220
222
|
return this;
|
|
221
|
-
} catch (err) {
|
|
222
|
-
if (this.view) {
|
|
223
|
-
await this.view.load();
|
|
224
|
-
this.view.emit('change');
|
|
225
|
-
config.defaultApp?.emit('saved');
|
|
226
|
-
}
|
|
227
|
-
throw err;
|
|
228
|
-
}
|
|
229
223
|
}
|
|
230
224
|
/**
|
|
231
225
|
* 删除元素
|
|
@@ -246,7 +240,6 @@ export class Element extends Vertex {
|
|
|
246
240
|
|
|
247
241
|
if (actionOptions?.actionMode !== ACTION_MODE.undoRedo) {
|
|
248
242
|
if (this.id) {
|
|
249
|
-
try {
|
|
250
243
|
await elementService.delete({
|
|
251
244
|
headers: {
|
|
252
245
|
appId: config.defaultApp?.id,
|
|
@@ -256,19 +249,7 @@ export class Element extends Vertex {
|
|
|
256
249
|
query: {
|
|
257
250
|
id: this.id,
|
|
258
251
|
},
|
|
259
|
-
});
|
|
260
|
-
} catch (err) {
|
|
261
|
-
await config.defaultApp?.history.load();
|
|
262
|
-
throw err;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
// Nuims deleteResource
|
|
266
|
-
// Element 对应资源增删在 undo/redo 情况下可能存在权限丢失的情况
|
|
267
|
-
// 暂时只增不减
|
|
268
|
-
// new Nuims({
|
|
269
|
-
// domainName: this.view.page.service.app.name,
|
|
270
|
-
// element: this,
|
|
271
|
-
// }).deleteResources();
|
|
252
|
+
}).catch(catchFn(this.view));
|
|
272
253
|
}
|
|
273
254
|
}
|
|
274
255
|
|
|
@@ -293,7 +274,6 @@ export class Element extends Vertex {
|
|
|
293
274
|
config.defaultApp?.emit('saving');
|
|
294
275
|
|
|
295
276
|
source && this.assign(source);
|
|
296
|
-
try {
|
|
297
277
|
if (actionOptions?.actionMode !== ACTION_MODE.undoRedo) {
|
|
298
278
|
const body = this.toPlainJSON();
|
|
299
279
|
utils.logger.debug('修改组件', body);
|
|
@@ -304,28 +284,41 @@ export class Element extends Vertex {
|
|
|
304
284
|
operationDesc: actionOptions?.actionDesc || `修改组件"${this.getElementTitle()}"`,
|
|
305
285
|
},
|
|
306
286
|
body,
|
|
307
|
-
});
|
|
287
|
+
}).catch(catchFn(this.view));
|
|
308
288
|
}
|
|
309
289
|
|
|
310
290
|
this.view && this.view.emit('change');
|
|
311
291
|
await config.defaultApp?.history.load(actionOptions?.actionMode !== ACTION_MODE.undoRedo && {
|
|
312
292
|
operationAction: 'Element.update',
|
|
313
|
-
operationBeforeImage: null,
|
|
293
|
+
operationBeforeImage: null,
|
|
314
294
|
operationAfterImage: null,
|
|
315
295
|
operationDesc: `修改组件"${this.getElementTitle()}"`,
|
|
316
296
|
});
|
|
317
297
|
|
|
318
298
|
config.defaultApp?.emit('saved');
|
|
319
299
|
return this;
|
|
320
|
-
} catch (err) {
|
|
321
|
-
if (this.view) {
|
|
322
|
-
await this.view.load();
|
|
323
|
-
this.view.emit('change');
|
|
324
|
-
config.defaultApp?.emit('saved');
|
|
325
|
-
}
|
|
326
|
-
throw err;
|
|
327
|
-
}
|
|
328
300
|
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* 按当前 id 加载逻辑数据
|
|
304
|
+
*/
|
|
305
|
+
async load() {
|
|
306
|
+
if (!this.id)
|
|
307
|
+
return;
|
|
308
|
+
|
|
309
|
+
const result = await elementService.load({
|
|
310
|
+
headers: {
|
|
311
|
+
appId: config.defaultApp?.id,
|
|
312
|
+
},
|
|
313
|
+
query: {
|
|
314
|
+
id: this.id,
|
|
315
|
+
},
|
|
316
|
+
config: { noErrorTip: true },
|
|
317
|
+
});
|
|
318
|
+
const newElement = Element.from(result, this.parent, this.view);
|
|
319
|
+
this.assign(newElement);
|
|
320
|
+
}
|
|
321
|
+
|
|
329
322
|
async move(options: {
|
|
330
323
|
parentId?: string,
|
|
331
324
|
_posIndex?: number,
|
|
@@ -363,11 +356,16 @@ export class Element extends Vertex {
|
|
|
363
356
|
}
|
|
364
357
|
|
|
365
358
|
config.defaultApp?.emit('element.moved');
|
|
359
|
+
config.defaultApp?.emit('saved');
|
|
366
360
|
} catch (err) {
|
|
367
361
|
if (this.view) {
|
|
368
362
|
await this.view.load();
|
|
369
363
|
this.view.emit('change');
|
|
370
364
|
}
|
|
365
|
+
config.defaultApp?.emit('saved', {
|
|
366
|
+
action: 'move',
|
|
367
|
+
err,
|
|
368
|
+
});
|
|
371
369
|
throw err;
|
|
372
370
|
}
|
|
373
371
|
}
|
|
@@ -381,6 +379,7 @@ export class Element extends Vertex {
|
|
|
381
379
|
|
|
382
380
|
const index = this.parent.children.indexOf(this);
|
|
383
381
|
const newNode = Element.fromHTML(code, this.parent, this.view);
|
|
382
|
+
|
|
384
383
|
const mergeExpression = (originList: Array<Attr|Directive>, newList: Array<Attr|Directive>) => {
|
|
385
384
|
newList.forEach((item) => {
|
|
386
385
|
const originItem = originList.find((originItem) => originItem.name === item.name);
|
|
@@ -432,6 +431,15 @@ export class Element extends Vertex {
|
|
|
432
431
|
}
|
|
433
432
|
};
|
|
434
433
|
|
|
434
|
+
const arrayComp = this.findElementsByTag('u-modal');
|
|
435
|
+
const existingNames = Object.values(mapValues(arrayComp, (o) => o.name));
|
|
436
|
+
// 处理弹窗组件的命名问题
|
|
437
|
+
if (newNode.tag === 'u-modal') {
|
|
438
|
+
Object.assign(newNode, {
|
|
439
|
+
name: utilsAll.unique('saveModal1', existingNames as any),
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
|
|
435
443
|
traverseMergeNode(this, newNode);
|
|
436
444
|
~index && this.parent.children.splice(index + 1, 0, newNode);
|
|
437
445
|
this.parent.children.forEach((item, index) => {
|
|
@@ -488,11 +496,14 @@ export class Element extends Vertex {
|
|
|
488
496
|
await this.update(undefined, {
|
|
489
497
|
actionDesc: `设置组件"${this.getElementTitle()}"的名称为"${name}"`,
|
|
490
498
|
});
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
499
|
+
|
|
500
|
+
if (!(window as any).globalData.hasUserCenter) {
|
|
501
|
+
// 同步权限
|
|
502
|
+
new Nuims({
|
|
503
|
+
domainName: this.view.page.service.app.name,
|
|
504
|
+
element: this,
|
|
505
|
+
}).editResourceFromResourceValue(oldName ? `${this.view.tempPath}/${oldName}` : null);
|
|
506
|
+
}
|
|
496
507
|
|
|
497
508
|
this.view && this.view.emit('change');
|
|
498
509
|
if (this.view && this.view.page && this.view.page.service) {
|
|
@@ -541,9 +552,7 @@ export class Element extends Vertex {
|
|
|
541
552
|
async setAttr(name: string, type: 'string' | 'static' | 'dynamic', value?: any) {
|
|
542
553
|
let attr = this.getAttr(name);
|
|
543
554
|
//
|
|
544
|
-
if (value
|
|
545
|
-
|
|
546
|
-
} else {
|
|
555
|
+
if (value !== undefined) {
|
|
547
556
|
if (typeof value !== 'string')
|
|
548
557
|
value = JSON.stringify(value);
|
|
549
558
|
|
|
@@ -554,7 +563,7 @@ export class Element extends Vertex {
|
|
|
554
563
|
});
|
|
555
564
|
await attr.update(undefined, {
|
|
556
565
|
actionDesc: `设置组件"${this.getElementTitle()}"属性"${attr.name}"的值为"${attr.value}"`,
|
|
557
|
-
});
|
|
566
|
+
}).catch(catchFn(this.view));
|
|
558
567
|
} else {
|
|
559
568
|
attr = Attr.from({
|
|
560
569
|
name,
|
|
@@ -564,7 +573,7 @@ export class Element extends Vertex {
|
|
|
564
573
|
}, this);
|
|
565
574
|
await attr.create(undefined, {
|
|
566
575
|
actionDesc: `设置组件"${this.getElementTitle()}"属性"${attr.name}"的值为"${attr.value}"`,
|
|
567
|
-
});
|
|
576
|
+
}).catch(catchFn(this.view));
|
|
568
577
|
this.attrList.push(attr);
|
|
569
578
|
}
|
|
570
579
|
}
|
|
@@ -581,7 +590,7 @@ export class Element extends Vertex {
|
|
|
581
590
|
|
|
582
591
|
await event.create(undefined, Object.assign({
|
|
583
592
|
actionDesc: `添加组件"${this.getElementTitle()}"事件"${event.name}"`,
|
|
584
|
-
}, actionOptions));
|
|
593
|
+
}, actionOptions)).catch(catchFn(this.view));
|
|
585
594
|
event = Event.from(event, this);
|
|
586
595
|
this.eventList.push(event);
|
|
587
596
|
|
|
@@ -604,7 +613,7 @@ export class Element extends Vertex {
|
|
|
604
613
|
|
|
605
614
|
await event.delete(undefined, Object.assign({
|
|
606
615
|
actionDesc: `删除组件"${this.getElementTitle()}"事件"${event.name}"`,
|
|
607
|
-
}, actionOptions));
|
|
616
|
+
}, actionOptions)).catch(catchFn(this.view));
|
|
608
617
|
const index = this.eventList.indexOf(event);
|
|
609
618
|
~index && this.eventList.splice(index, 1);
|
|
610
619
|
|
|
@@ -622,7 +631,7 @@ export class Element extends Vertex {
|
|
|
622
631
|
const directive = new Directive(data);
|
|
623
632
|
await directive.create(undefined, Object.assign({
|
|
624
633
|
actionDesc: `添加组件"${this.getElementTitle()}"指令"${directive.name}"`,
|
|
625
|
-
}, actionOptions));
|
|
634
|
+
}, actionOptions)).catch(catchFn(this.view));
|
|
626
635
|
this.directiveList.push(Directive.from(directive, this));
|
|
627
636
|
|
|
628
637
|
this.view && this.view.emit('change');
|
|
@@ -639,7 +648,7 @@ export class Element extends Vertex {
|
|
|
639
648
|
|
|
640
649
|
await directive.delete(undefined, Object.assign({
|
|
641
650
|
actionDesc: `删除组件"${this.getElementTitle()}"属性"${directive.name}"`,
|
|
642
|
-
}, actionOptions));
|
|
651
|
+
}, actionOptions)).catch(catchFn(this.view));
|
|
643
652
|
const index = this.directiveList.indexOf(directive);
|
|
644
653
|
~index && this.directiveList.splice(index, 1);
|
|
645
654
|
|
|
@@ -808,6 +817,33 @@ export class Element extends Vertex {
|
|
|
808
817
|
}
|
|
809
818
|
}
|
|
810
819
|
}
|
|
820
|
+
|
|
821
|
+
findElementsByTag(tag: string): Array<any> {
|
|
822
|
+
let existingNames: Array<any> = [];
|
|
823
|
+
existingNames = this.findElementsByTagCurrent(tag, existingNames);
|
|
824
|
+
this.findElementsByTagInChildren(this.view.$html.children, tag, existingNames);
|
|
825
|
+
return existingNames;
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
findElementsByTagCurrent(tag: string, existingNames: Array<any>) {
|
|
829
|
+
if (this.tag === tag) {
|
|
830
|
+
existingNames.push(this);
|
|
831
|
+
}
|
|
832
|
+
return existingNames;
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
findElementsByTagInChildren(children: Array<any>, tag: string, existingNames: Array<any>) {
|
|
836
|
+
for (const child of children) {
|
|
837
|
+
const result = child.findElementByTag(tag);
|
|
838
|
+
|
|
839
|
+
if (child.children) {
|
|
840
|
+
this.findElementsByTagInChildren(child.children, tag, existingNames);
|
|
841
|
+
}
|
|
842
|
+
if (result) {
|
|
843
|
+
existingNames.push(result);
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
}
|
|
811
847
|
/**
|
|
812
848
|
* 从 Vue 的 ASTNode 转换成 ASL 元素
|
|
813
849
|
* @param astNode Vue 的 ASTNode
|
|
@@ -852,8 +888,6 @@ export class Element extends Vertex {
|
|
|
852
888
|
}
|
|
853
889
|
}
|
|
854
890
|
|
|
855
|
-
// if (astNode.tag === 'template')
|
|
856
|
-
// astNode.tag = 'div';
|
|
857
891
|
element = new Element({
|
|
858
892
|
tag: astNode.tag,
|
|
859
893
|
name: astNode.attrsMap.ref,
|
|
@@ -894,7 +928,6 @@ export class Element extends Vertex {
|
|
|
894
928
|
}
|
|
895
929
|
}
|
|
896
930
|
element.attrList.push(attr);
|
|
897
|
-
// element.attrMap[attr.name] = attr;
|
|
898
931
|
});
|
|
899
932
|
|
|
900
933
|
// compiler 处理:value.sync 时会加上update:value事件,需要过滤
|
|
@@ -906,10 +939,6 @@ export class Element extends Vertex {
|
|
|
906
939
|
value,
|
|
907
940
|
logicId: value[0] === '$' ? undefined : value,
|
|
908
941
|
}, element));
|
|
909
|
-
// element.eventMap[name] = new Event({
|
|
910
|
-
// name,
|
|
911
|
-
// value: oldEvent.value,
|
|
912
|
-
// });
|
|
913
942
|
});
|
|
914
943
|
|
|
915
944
|
astNode.directives && astNode.directives.forEach((directive) => {
|
|
@@ -936,7 +965,6 @@ export class Element extends Vertex {
|
|
|
936
965
|
arg: directive.arg,
|
|
937
966
|
modifiers: directive.modifiers,
|
|
938
967
|
}, element));
|
|
939
|
-
// element.directiveMap[directive.name] = );
|
|
940
968
|
}
|
|
941
969
|
});
|
|
942
970
|
|
package/src/types/page/Event.ts
CHANGED
|
@@ -3,10 +3,7 @@ import { action, circular, excludedInJSON, immutable } from '../decorators';
|
|
|
3
3
|
import { config, history, utils, LEVEL_ENUM, Vertex, PackageJSON, App, Page, DataNode, View, Element, ExpressionNode, Logic, genFinalCode, ActionOptions, ACTION_MODE } from '..';
|
|
4
4
|
import { elementService, attributeService, eventService, directiveService } from '../../service/page';
|
|
5
5
|
import * as babel from '@babel/core';
|
|
6
|
-
import { traverse } from '../utils';
|
|
7
|
-
import generate from '@babel/generator';
|
|
8
6
|
import { vertexsMap } from '../cacheData';
|
|
9
|
-
import Variable from '../logic/Variable';
|
|
10
7
|
|
|
11
8
|
/**
|
|
12
9
|
* 前端组件事件
|
package/src/types/page/Page.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
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
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
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
|
-
|
|
297
|
-
tasks.push(this.update(undefined, {
|
|
298
|
-
actionDesc: `设置页面"${this.name}"为首页`,
|
|
299
|
-
}));
|
|
300
|
-
await Promise.all(tasks);
|
|
314
|
+
});
|
|
301
315
|
|
|
302
|
-
|
|
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
|
|
392
|
+
tempPath: page.rootView ? `/${page.rootView.name}` : '',
|
|
393
|
+
code: page.rootView ? `/ID_${page.rootView.id}` : '',
|
|
357
394
|
});
|
|
358
395
|
|
|
359
396
|
return page;
|