@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.
- package/out/service/app/api.d.ts +1 -15
- package/out/service/app/api.js +7 -17
- package/out/service/app/api.js.map +1 -1
- package/out/service/create/errHandles.js +19 -2
- package/out/service/create/errHandles.js.map +1 -1
- package/out/service/create/index.js +3 -0
- package/out/service/create/index.js.map +1 -1
- package/out/service/logic/logic.d.ts +50 -14
- package/out/service/logic/logic.js +26 -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/App.d.ts +4 -0
- package/out/types/app/App.js +31 -1
- package/out/types/app/App.js.map +1 -1
- package/out/types/app/History.js +3 -2
- package/out/types/app/History.js.map +1 -1
- package/out/types/app/Service.d.ts +5 -2
- package/out/types/app/Service.js +38 -5
- 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/cacheData.js.map +1 -1
- 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.d.ts +4 -0
- package/out/types/data/Entity.js +9 -0
- package/out/types/data/Entity.js.map +1 -1
- package/out/types/data/EntityProperty.d.ts +5 -0
- package/out/types/data/EntityProperty.js +16 -0
- package/out/types/data/EntityProperty.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/dataTypes.js +1 -1
- package/out/types/data/dataTypes.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/genCurdEditTableBlock.d.ts +3 -0
- package/out/types/data/genBlock/genCurdEditTableBlock.js +578 -0
- package/out/types/data/genBlock/genCurdEditTableBlock.js.map +1 -0
- package/out/types/data/genBlock/genEditTableBlock.d.ts +234 -0
- package/out/types/data/genBlock/genEditTableBlock.js +419 -0
- package/out/types/data/genBlock/genEditTableBlock.js.map +1 -0
- 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/genQueryComponent.d.ts +20 -0
- package/out/types/data/genBlock/genQueryComponent.js +57 -1
- package/out/types/data/genBlock/genQueryComponent.js.map +1 -1
- package/out/types/data/genBlock/genSelectBlock.js +2 -2
- package/out/types/data/genBlock/genTableBlock.js +23 -8
- 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/genBlock/index.d.ts +2 -0
- package/out/types/data/genBlock/index.js +2 -0
- package/out/types/data/genBlock/index.js.map +1 -1
- package/out/types/data/genBlock/utils.d.ts +7 -0
- package/out/types/data/genBlock/utils.js +38 -1
- package/out/types/data/genBlock/utils.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 +5 -1
- package/out/types/index.js +8 -2
- package/out/types/index.js.map +1 -1
- package/out/types/logic/Logic.d.ts +32 -0
- package/out/types/logic/Logic.js +151 -41
- package/out/types/logic/Logic.js.map +1 -1
- package/out/types/logic/LogicItem.d.ts +1 -0
- package/out/types/logic/LogicItem.js +48 -31
- package/out/types/logic/LogicItem.js.map +1 -1
- package/out/types/logic/Param.d.ts +1 -0
- package/out/types/logic/Param.js +43 -33
- package/out/types/logic/Param.js.map +1 -1
- package/out/types/logic/Return.js +17 -30
- package/out/types/logic/Return.js.map +1 -1
- package/out/types/logic/Variable.js +17 -25
- package/out/types/logic/Variable.js.map +1 -1
- package/out/types/logic/translator.js +39 -10
- 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 +27 -0
- package/out/types/page/Element.js +229 -131
- 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 +5 -0
- package/out/types/page/Page.js +78 -37
- package/out/types/page/Page.js.map +1 -1
- package/out/types/page/View.d.ts +18 -1
- package/out/types/page/View.js +119 -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 -24
- 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/out/types/process/ProcessParam.js +3 -1
- package/out/types/process/ProcessParam.js.map +1 -1
- package/out/types/utils/index.d.ts +1 -0
- package/out/types/utils/index.js +16 -7
- package/out/types/utils/index.js.map +1 -1
- package/package.json +2 -3
- package/src/service/app/api.js +8 -17
- package/src/service/create/errHandles.js +18 -2
- package/src/service/create/index.js +4 -0
- package/src/service/developPermission/api.js +37 -0
- package/src/service/developPermission/index.js +13 -0
- package/src/service/logic/logic.js +26 -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/App.ts +37 -2
- package/src/types/app/History.ts +3 -2
- package/src/types/app/Service.ts +44 -6
- package/src/types/cache.ts +50 -0
- package/src/types/cacheData.ts +7 -7
- package/src/types/common/Vertex.ts +30 -0
- package/src/types/data/Entity.ts +8 -0
- package/src/types/data/EntityProperty.ts +12 -0
- package/src/types/data/Enum.ts +5 -0
- package/src/types/data/Interface.ts +4 -3
- package/src/types/data/dataTypes.ts +1 -1
- package/src/types/data/genBlock/genCreateBlock.ts +5 -5
- package/src/types/data/genBlock/genCurdBlock.ts +3 -3
- package/src/types/data/genBlock/genCurdEditTableBlock.ts +581 -0
- package/src/types/data/genBlock/genEditTableBlock.ts +470 -0
- 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/genQueryComponent.ts +56 -0
- package/src/types/data/genBlock/genSelectBlock.ts +2 -2
- package/src/types/data/genBlock/genTableBlock.ts +28 -13
- package/src/types/data/genBlock/genUpdateBlock.ts +5 -5
- package/src/types/data/genBlock/index.ts +2 -0
- package/src/types/data/genBlock/utils.ts +38 -0
- 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 +5 -1
- package/src/types/logic/Logic.ts +148 -39
- package/src/types/logic/LogicItem.ts +54 -37
- package/src/types/logic/Param.ts +43 -35
- package/src/types/logic/Return.ts +21 -34
- package/src/types/logic/Variable.ts +21 -27
- package/src/types/logic/translator.js +41 -14
- package/src/types/logic/translator_backup.js +5 -16
- package/src/types/nuims/Nuims.ts +11 -5
- package/src/types/page/Element.ts +250 -135
- package/src/types/page/Event.ts +0 -3
- package/src/types/page/Page.ts +93 -49
- package/src/types/page/View.ts +123 -42
- package/src/types/page/ViewParam.ts +22 -3
- package/src/types/page/ViewVariable.ts +16 -26
- package/src/types/page/dist/View.js +727 -0
- package/src/types/permission/Permission.ts +112 -0
- package/src/types/process/ProcessParam.ts +4 -1
- package/src/types/utils/index.ts +16 -7
- 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,14 @@
|
|
|
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 { refreshHtml } from '../cache';
|
|
11
|
+
import { BusinessCode } from '../enum';
|
|
12
12
|
|
|
13
13
|
export interface ElementToVueOptions {
|
|
14
14
|
indentStyle?: 'space' | 'tab';
|
|
@@ -28,6 +28,18 @@ export interface ParseContext {
|
|
|
28
28
|
[key: string]: any;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
export function catchFn(view: View) {
|
|
32
|
+
return async (err: any) => {
|
|
33
|
+
if (err.code !== BusinessCode.HasReferenced) // 节点被引用,不用刷新数据
|
|
34
|
+
await refreshHtml(view);
|
|
35
|
+
else
|
|
36
|
+
config.defaultApp?.emit('saved', err);
|
|
37
|
+
|
|
38
|
+
config.defaultApp?.history.load();
|
|
39
|
+
throw err;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
31
43
|
/**
|
|
32
44
|
* 前端页面元素
|
|
33
45
|
* @example
|
|
@@ -63,6 +75,12 @@ export class Element extends Vertex {
|
|
|
63
75
|
*/
|
|
64
76
|
@immutable()
|
|
65
77
|
public readonly name: string = undefined;
|
|
78
|
+
|
|
79
|
+
/*
|
|
80
|
+
* 描述信息
|
|
81
|
+
*/
|
|
82
|
+
@immutable()
|
|
83
|
+
public readonly description: string = undefined;
|
|
66
84
|
/**
|
|
67
85
|
* 属性列表
|
|
68
86
|
* 和原来的 attrsList 不同,注意区分
|
|
@@ -142,15 +160,23 @@ export class Element extends Vertex {
|
|
|
142
160
|
*/
|
|
143
161
|
@immutable()
|
|
144
162
|
public readonly children?: Array<Element> = [];
|
|
163
|
+
/**
|
|
164
|
+
* 标签名前缀
|
|
165
|
+
*/
|
|
166
|
+
@immutable()
|
|
167
|
+
public static readonly TAG_NAME_REG?: RegExp = /^([lieu]|van)[-_]/;
|
|
168
|
+
/**
|
|
169
|
+
* 忽略命名的标签
|
|
170
|
+
*/
|
|
171
|
+
@immutable()
|
|
172
|
+
public static readonly ignoreTag?: Array<string> = ['div', 'span'];
|
|
173
|
+
|
|
145
174
|
/**
|
|
146
175
|
* @param source 需要合并的部分参数
|
|
147
176
|
*/
|
|
148
177
|
constructor(source?: Partial<Element>) {
|
|
149
178
|
super();
|
|
150
179
|
source && this.assign(source);
|
|
151
|
-
// 为了给生成的节点使用
|
|
152
|
-
// !this.id && this.assign({ id: uuidv4() });
|
|
153
|
-
// this.assign({ id: 'temp-' + uuidv4() });
|
|
154
180
|
}
|
|
155
181
|
assign(source?: any) {
|
|
156
182
|
['attrList', 'eventList', 'directiveList', 'children'].forEach((key) => {
|
|
@@ -170,62 +196,45 @@ export class Element extends Vertex {
|
|
|
170
196
|
}
|
|
171
197
|
|
|
172
198
|
config.defaultApp?.emit('saving');
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
appId: config.defaultApp?.id,
|
|
182
|
-
operationAction: 'Element.create',
|
|
183
|
-
operationDesc: `添加组件"${this.getElementTitle()}"`,
|
|
184
|
-
},
|
|
185
|
-
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();
|
|
195
|
-
|
|
196
|
-
this.deepPick(result, ['id', 'parentId', 'elementId']);
|
|
197
|
-
// attr,directive,event的id,exprssion需要合并
|
|
198
|
-
this.attrList.forEach((attr, index) => {
|
|
199
|
-
attr.deepPick(result.attrList[index], ['id', 'expression']);
|
|
200
|
-
});
|
|
201
|
-
this.directiveList.forEach((directive, index) => {
|
|
202
|
-
directive.deepPick(result.directiveList[index], ['id', 'expression']);
|
|
203
|
-
});
|
|
204
|
-
this.eventList.forEach((event, index) => {
|
|
205
|
-
event.deepPick(result.eventList[index], ['id']);
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
this.view && this.view.emit('change');
|
|
210
|
-
|
|
211
|
-
if (actionOptions?.loadHistory !== false) {
|
|
212
|
-
await config.defaultApp?.history.load(actionOptions?.actionMode !== ACTION_MODE.undoRedo && {
|
|
199
|
+
if (actionOptions?.actionMode !== ACTION_MODE.undoRedo) {
|
|
200
|
+
const body = this.toJSON();
|
|
201
|
+
body.parentId = this.parent && this.parent.id;
|
|
202
|
+
body._posIndex = this.parent && this.parent.children.indexOf(this);
|
|
203
|
+
utils.logger.debug('添加元素', body);
|
|
204
|
+
const result = await elementService.create({
|
|
205
|
+
headers: {
|
|
206
|
+
appId: config.defaultApp?.id,
|
|
213
207
|
operationAction: 'Element.create',
|
|
214
|
-
operationBeforeImage: null,
|
|
215
|
-
operationAfterImage: JSON.parse(JSON.stringify(this)),
|
|
216
208
|
operationDesc: `添加组件"${this.getElementTitle()}"`,
|
|
217
|
-
}
|
|
209
|
+
},
|
|
210
|
+
body,
|
|
211
|
+
}).catch(catchFn(this.view));
|
|
212
|
+
|
|
213
|
+
this.deepPick(result, ['id', 'parentId', 'elementId']);
|
|
214
|
+
// attr,directive,event的id,expression需要合并
|
|
215
|
+
this.attrList.forEach((attr, index) => {
|
|
216
|
+
attr.deepPick(result.attrList[index], ['id', 'expression']);
|
|
217
|
+
});
|
|
218
|
+
this.directiveList.forEach((directive, index) => {
|
|
219
|
+
directive.deepPick(result.directiveList[index], ['id', 'expression']);
|
|
220
|
+
});
|
|
221
|
+
this.eventList.forEach((event, index) => {
|
|
222
|
+
event.deepPick(result.eventList[index], ['id']);
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
this.view && this.view.emit('change');
|
|
227
|
+
|
|
228
|
+
if (actionOptions?.loadHistory !== false) {
|
|
229
|
+
await config.defaultApp?.history.load(actionOptions?.actionMode !== ACTION_MODE.undoRedo && {
|
|
230
|
+
operationAction: 'Element.create',
|
|
231
|
+
operationBeforeImage: null,
|
|
232
|
+
operationAfterImage: JSON.parse(JSON.stringify(this)),
|
|
233
|
+
operationDesc: `添加组件"${this.getElementTitle()}"`,
|
|
234
|
+
});
|
|
218
235
|
config.defaultApp?.emit('saved');
|
|
219
|
-
}
|
|
220
|
-
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
236
|
}
|
|
237
|
+
return this;
|
|
229
238
|
}
|
|
230
239
|
/**
|
|
231
240
|
* 删除元素
|
|
@@ -235,6 +244,7 @@ export class Element extends Vertex {
|
|
|
235
244
|
if (actionOptions?.actionMode === ACTION_MODE.local) {
|
|
236
245
|
const index = this.parent.children.indexOf(this);
|
|
237
246
|
~index && this.parent.children.splice(index, 1);
|
|
247
|
+
this.deepRemoveElementsName();
|
|
238
248
|
this.view && this.view.emit('local-change');
|
|
239
249
|
return this;
|
|
240
250
|
}
|
|
@@ -246,34 +256,24 @@ export class Element extends Vertex {
|
|
|
246
256
|
|
|
247
257
|
if (actionOptions?.actionMode !== ACTION_MODE.undoRedo) {
|
|
248
258
|
if (this.id) {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
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();
|
|
259
|
+
await elementService.delete({
|
|
260
|
+
headers: {
|
|
261
|
+
appId: config.defaultApp?.id,
|
|
262
|
+
operationAction: 'Element.delete',
|
|
263
|
+
operationDesc: `删除组件"${this.getElementTitle()}"`,
|
|
264
|
+
},
|
|
265
|
+
query: {
|
|
266
|
+
id: this.id,
|
|
267
|
+
},
|
|
268
|
+
}).catch(catchFn(this.view));
|
|
272
269
|
}
|
|
273
270
|
}
|
|
274
271
|
|
|
275
272
|
const index = this.parent.children.indexOf(this);
|
|
276
273
|
~index && this.parent.children.splice(index, 1);
|
|
274
|
+
|
|
275
|
+
// 递归删除组件名的缓存
|
|
276
|
+
this.deepRemoveElementsName();
|
|
277
277
|
this.destroy();
|
|
278
278
|
this.view && this.view.emit('change');
|
|
279
279
|
if (actionOptions?.loadHistory !== false) {
|
|
@@ -293,39 +293,51 @@ export class Element extends Vertex {
|
|
|
293
293
|
config.defaultApp?.emit('saving');
|
|
294
294
|
|
|
295
295
|
source && this.assign(source);
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
}
|
|
296
|
+
if (actionOptions?.actionMode !== ACTION_MODE.undoRedo) {
|
|
297
|
+
const body = this.toPlainJSON();
|
|
298
|
+
utils.logger.debug('修改组件', body);
|
|
299
|
+
await elementService.update({
|
|
300
|
+
headers: {
|
|
301
|
+
appId: config.defaultApp?.id,
|
|
302
|
+
operationAction: actionOptions?.actionName || 'Element.update',
|
|
303
|
+
operationDesc: actionOptions?.actionDesc || `修改组件"${this.getElementTitle()}"`,
|
|
304
|
+
},
|
|
305
|
+
body,
|
|
306
|
+
}).catch(catchFn(this.view));
|
|
307
|
+
}
|
|
309
308
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
309
|
+
this.view && this.view.emit('change');
|
|
310
|
+
await config.defaultApp?.history.load(actionOptions?.actionMode !== ACTION_MODE.undoRedo && {
|
|
311
|
+
operationAction: 'Element.update',
|
|
312
|
+
operationBeforeImage: null,
|
|
313
|
+
operationAfterImage: null,
|
|
314
|
+
operationDesc: `修改组件"${this.getElementTitle()}"`,
|
|
315
|
+
});
|
|
317
316
|
|
|
318
317
|
config.defaultApp?.emit('saved');
|
|
319
318
|
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
319
|
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* 按当前 id 加载逻辑数据
|
|
323
|
+
*/
|
|
324
|
+
async load() {
|
|
325
|
+
if (!this.id)
|
|
326
|
+
return;
|
|
327
|
+
|
|
328
|
+
const result = await elementService.load({
|
|
329
|
+
headers: {
|
|
330
|
+
appId: config.defaultApp?.id,
|
|
331
|
+
},
|
|
332
|
+
query: {
|
|
333
|
+
id: this.id,
|
|
334
|
+
},
|
|
335
|
+
config: { noErrorTip: true },
|
|
336
|
+
});
|
|
337
|
+
const newElement = Element.from(result, this.parent, this.view);
|
|
338
|
+
this.assign(newElement);
|
|
339
|
+
}
|
|
340
|
+
|
|
329
341
|
async move(options: {
|
|
330
342
|
parentId?: string,
|
|
331
343
|
_posIndex?: number,
|
|
@@ -363,11 +375,16 @@ export class Element extends Vertex {
|
|
|
363
375
|
}
|
|
364
376
|
|
|
365
377
|
config.defaultApp?.emit('element.moved');
|
|
378
|
+
config.defaultApp?.emit('saved');
|
|
366
379
|
} catch (err) {
|
|
367
380
|
if (this.view) {
|
|
368
381
|
await this.view.load();
|
|
369
382
|
this.view.emit('change');
|
|
370
383
|
}
|
|
384
|
+
config.defaultApp?.emit('saved', {
|
|
385
|
+
action: 'move',
|
|
386
|
+
err,
|
|
387
|
+
});
|
|
371
388
|
throw err;
|
|
372
389
|
}
|
|
373
390
|
}
|
|
@@ -381,6 +398,9 @@ export class Element extends Vertex {
|
|
|
381
398
|
|
|
382
399
|
const index = this.parent.children.indexOf(this);
|
|
383
400
|
const newNode = Element.fromHTML(code, this.parent, this.view);
|
|
401
|
+
// 复制的元素需重新命名
|
|
402
|
+
newNode.deepRenameElements();
|
|
403
|
+
|
|
384
404
|
const mergeExpression = (originList: Array<Attr|Directive>, newList: Array<Attr|Directive>) => {
|
|
385
405
|
newList.forEach((item) => {
|
|
386
406
|
const originItem = originList.find((originItem) => originItem.name === item.name);
|
|
@@ -432,6 +452,15 @@ export class Element extends Vertex {
|
|
|
432
452
|
}
|
|
433
453
|
};
|
|
434
454
|
|
|
455
|
+
const arrayComp = this.findElementsByTag('u-modal');
|
|
456
|
+
const existingNames = Object.values(mapValues(arrayComp, (o) => o.name));
|
|
457
|
+
// 处理弹窗组件的命名问题
|
|
458
|
+
if (newNode.tag === 'u-modal') {
|
|
459
|
+
Object.assign(newNode, {
|
|
460
|
+
name: utils.unique('saveModal1', existingNames as any),
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
|
|
435
464
|
traverseMergeNode(this, newNode);
|
|
436
465
|
~index && this.parent.children.splice(index + 1, 0, newNode);
|
|
437
466
|
this.parent.children.forEach((item, index) => {
|
|
@@ -457,6 +486,8 @@ export class Element extends Vertex {
|
|
|
457
486
|
}
|
|
458
487
|
if (isPlainObject(child)) {
|
|
459
488
|
child = Element.from(child, this, this.view);
|
|
489
|
+
child.initElementName();
|
|
490
|
+
child.deepRenameElements();
|
|
460
491
|
}
|
|
461
492
|
if (!this.children.includes(child)) {
|
|
462
493
|
const index = child._posIndex === undefined ? this.children.length : child._posIndex;
|
|
@@ -488,17 +519,36 @@ export class Element extends Vertex {
|
|
|
488
519
|
await this.update(undefined, {
|
|
489
520
|
actionDesc: `设置组件"${this.getElementTitle()}"的名称为"${name}"`,
|
|
490
521
|
});
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
522
|
+
|
|
523
|
+
if (!(window as any).globalData.hasUserCenter) {
|
|
524
|
+
// 同步权限
|
|
525
|
+
new Nuims({
|
|
526
|
+
domainName: this.view.page.service.app.name,
|
|
527
|
+
element: this,
|
|
528
|
+
}).editResourceFromResourceValue(oldName ? `${this.view.tempPath}/${oldName}` : null);
|
|
529
|
+
}
|
|
496
530
|
|
|
497
531
|
this.view && this.view.emit('change');
|
|
498
532
|
if (this.view && this.view.page && this.view.page.service) {
|
|
499
533
|
this.view.page.service.emit('vertexIdToNameChange', this.id, this.name);
|
|
500
534
|
}
|
|
501
535
|
}
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* 更新描述信息
|
|
539
|
+
* @param description
|
|
540
|
+
*/
|
|
541
|
+
async setDescription(description: string) {
|
|
542
|
+
this.assign({ description });
|
|
543
|
+
await this.update(undefined, {
|
|
544
|
+
actionDesc: `设置组件"${this.getElementTitle()}"的描述为"${description}"`,
|
|
545
|
+
});
|
|
546
|
+
|
|
547
|
+
this.view && this.view.emit('change');
|
|
548
|
+
if (this.view && this.view.page && this.view.page.service) {
|
|
549
|
+
this.view.page.service.emit('vertexIdToNameChange', this.id, this.name);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
502
552
|
/**
|
|
503
553
|
* 添加组件属性
|
|
504
554
|
*/
|
|
@@ -541,9 +591,7 @@ export class Element extends Vertex {
|
|
|
541
591
|
async setAttr(name: string, type: 'string' | 'static' | 'dynamic', value?: any) {
|
|
542
592
|
let attr = this.getAttr(name);
|
|
543
593
|
//
|
|
544
|
-
if (value
|
|
545
|
-
|
|
546
|
-
} else {
|
|
594
|
+
if (value !== undefined) {
|
|
547
595
|
if (typeof value !== 'string')
|
|
548
596
|
value = JSON.stringify(value);
|
|
549
597
|
|
|
@@ -554,7 +602,7 @@ export class Element extends Vertex {
|
|
|
554
602
|
});
|
|
555
603
|
await attr.update(undefined, {
|
|
556
604
|
actionDesc: `设置组件"${this.getElementTitle()}"属性"${attr.name}"的值为"${attr.value}"`,
|
|
557
|
-
});
|
|
605
|
+
}).catch(catchFn(this.view));
|
|
558
606
|
} else {
|
|
559
607
|
attr = Attr.from({
|
|
560
608
|
name,
|
|
@@ -564,7 +612,7 @@ export class Element extends Vertex {
|
|
|
564
612
|
}, this);
|
|
565
613
|
await attr.create(undefined, {
|
|
566
614
|
actionDesc: `设置组件"${this.getElementTitle()}"属性"${attr.name}"的值为"${attr.value}"`,
|
|
567
|
-
});
|
|
615
|
+
}).catch(catchFn(this.view));
|
|
568
616
|
this.attrList.push(attr);
|
|
569
617
|
}
|
|
570
618
|
}
|
|
@@ -581,7 +629,7 @@ export class Element extends Vertex {
|
|
|
581
629
|
|
|
582
630
|
await event.create(undefined, Object.assign({
|
|
583
631
|
actionDesc: `添加组件"${this.getElementTitle()}"事件"${event.name}"`,
|
|
584
|
-
}, actionOptions));
|
|
632
|
+
}, actionOptions)).catch(catchFn(this.view));
|
|
585
633
|
event = Event.from(event, this);
|
|
586
634
|
this.eventList.push(event);
|
|
587
635
|
|
|
@@ -604,7 +652,7 @@ export class Element extends Vertex {
|
|
|
604
652
|
|
|
605
653
|
await event.delete(undefined, Object.assign({
|
|
606
654
|
actionDesc: `删除组件"${this.getElementTitle()}"事件"${event.name}"`,
|
|
607
|
-
}, actionOptions));
|
|
655
|
+
}, actionOptions)).catch(catchFn(this.view));
|
|
608
656
|
const index = this.eventList.indexOf(event);
|
|
609
657
|
~index && this.eventList.splice(index, 1);
|
|
610
658
|
|
|
@@ -622,7 +670,7 @@ export class Element extends Vertex {
|
|
|
622
670
|
const directive = new Directive(data);
|
|
623
671
|
await directive.create(undefined, Object.assign({
|
|
624
672
|
actionDesc: `添加组件"${this.getElementTitle()}"指令"${directive.name}"`,
|
|
625
|
-
}, actionOptions));
|
|
673
|
+
}, actionOptions)).catch(catchFn(this.view));
|
|
626
674
|
this.directiveList.push(Directive.from(directive, this));
|
|
627
675
|
|
|
628
676
|
this.view && this.view.emit('change');
|
|
@@ -639,7 +687,7 @@ export class Element extends Vertex {
|
|
|
639
687
|
|
|
640
688
|
await directive.delete(undefined, Object.assign({
|
|
641
689
|
actionDesc: `删除组件"${this.getElementTitle()}"属性"${directive.name}"`,
|
|
642
|
-
}, actionOptions));
|
|
690
|
+
}, actionOptions)).catch(catchFn(this.view));
|
|
643
691
|
const index = this.directiveList.indexOf(directive);
|
|
644
692
|
~index && this.directiveList.splice(index, 1);
|
|
645
693
|
|
|
@@ -721,8 +769,11 @@ export class Element extends Vertex {
|
|
|
721
769
|
if (attr.level === LEVEL_ENUM.attr) {
|
|
722
770
|
const api = config.allNodesAPI[el.tag];
|
|
723
771
|
const apiOfAttr = api && api.attrs && api.attrs.find((_attr) => _attr.name === attr.name);
|
|
724
|
-
if (apiOfAttr && apiOfAttr['designer-value']) {
|
|
725
|
-
|
|
772
|
+
if (apiOfAttr && apiOfAttr['designer-value'] !== undefined) {
|
|
773
|
+
let designerValue = apiOfAttr['designer-value'];
|
|
774
|
+
if (typeof designerValue === 'string') {
|
|
775
|
+
designerValue = designerValue.replace(/"/g, '\'');
|
|
776
|
+
}
|
|
726
777
|
try {
|
|
727
778
|
json5.parse(designerValue);
|
|
728
779
|
return `:${attr.name}="${designerValue}"`;
|
|
@@ -808,6 +859,73 @@ export class Element extends Vertex {
|
|
|
808
859
|
}
|
|
809
860
|
}
|
|
810
861
|
}
|
|
862
|
+
|
|
863
|
+
findElementsByTag(tag: string): Array<any> {
|
|
864
|
+
let existingNames: Array<any> = [];
|
|
865
|
+
existingNames = this.findElementsByTagCurrent(tag, existingNames);
|
|
866
|
+
this.findElementsByTagInChildren(this.view.$html.children, tag, existingNames);
|
|
867
|
+
return existingNames;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
findElementsByTagCurrent(tag: string, existingNames: Array<any>) {
|
|
871
|
+
if (this.tag === tag) {
|
|
872
|
+
existingNames.push(this);
|
|
873
|
+
}
|
|
874
|
+
return existingNames;
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
findElementsByTagInChildren(children: Array<any>, tag: string, existingNames: Array<any>) {
|
|
878
|
+
for (const child of children) {
|
|
879
|
+
const result = child.findElementByTag(tag);
|
|
880
|
+
|
|
881
|
+
if (child.children) {
|
|
882
|
+
this.findElementsByTagInChildren(child.children, tag, existingNames);
|
|
883
|
+
}
|
|
884
|
+
if (result) {
|
|
885
|
+
existingNames.push(result);
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
// 初始化组件名
|
|
891
|
+
public initElementName() {
|
|
892
|
+
if (Element.ignoreTag.includes(this.tag)) {
|
|
893
|
+
return;
|
|
894
|
+
}
|
|
895
|
+
const name = this.genElementName();
|
|
896
|
+
this.assign({ name });
|
|
897
|
+
this.view.addElementName(name);
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
// 生成新的组件名
|
|
901
|
+
public genElementName(): string {
|
|
902
|
+
const compNameSet = this.view.elementNameSet;
|
|
903
|
+
const tagName = this.tag.replace(Element.TAG_NAME_REG, '').replace(/-/g, '_');
|
|
904
|
+
const componentName = utils.unique(tagName + '1', compNameSet);
|
|
905
|
+
return componentName;
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
// 递归生成组件名
|
|
909
|
+
public deepRenameElements(): void {
|
|
910
|
+
return this.traverseChildren((ele: Element) => {
|
|
911
|
+
ele.initElementName();
|
|
912
|
+
});
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
// 递归删除组件名的缓存
|
|
916
|
+
public deepRemoveElementsName(): void {
|
|
917
|
+
return this.traverseChildren((ele: Element) => {
|
|
918
|
+
this.view.removeElementName(ele.name);
|
|
919
|
+
});
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
// 递归遍历组件
|
|
923
|
+
public traverseChildren(cb: (ele: Element) => void): void {
|
|
924
|
+
utils.traverse((current) => {
|
|
925
|
+
cb(current.node);
|
|
926
|
+
}, { node: this });
|
|
927
|
+
}
|
|
928
|
+
|
|
811
929
|
/**
|
|
812
930
|
* 从 Vue 的 ASTNode 转换成 ASL 元素
|
|
813
931
|
* @param astNode Vue 的 ASTNode
|
|
@@ -852,8 +970,6 @@ export class Element extends Vertex {
|
|
|
852
970
|
}
|
|
853
971
|
}
|
|
854
972
|
|
|
855
|
-
// if (astNode.tag === 'template')
|
|
856
|
-
// astNode.tag = 'div';
|
|
857
973
|
element = new Element({
|
|
858
974
|
tag: astNode.tag,
|
|
859
975
|
name: astNode.attrsMap.ref,
|
|
@@ -894,7 +1010,6 @@ export class Element extends Vertex {
|
|
|
894
1010
|
}
|
|
895
1011
|
}
|
|
896
1012
|
element.attrList.push(attr);
|
|
897
|
-
// element.attrMap[attr.name] = attr;
|
|
898
1013
|
});
|
|
899
1014
|
|
|
900
1015
|
// compiler 处理:value.sync 时会加上update:value事件,需要过滤
|
|
@@ -906,10 +1021,6 @@ export class Element extends Vertex {
|
|
|
906
1021
|
value,
|
|
907
1022
|
logicId: value[0] === '$' ? undefined : value,
|
|
908
1023
|
}, element));
|
|
909
|
-
// element.eventMap[name] = new Event({
|
|
910
|
-
// name,
|
|
911
|
-
// value: oldEvent.value,
|
|
912
|
-
// });
|
|
913
1024
|
});
|
|
914
1025
|
|
|
915
1026
|
astNode.directives && astNode.directives.forEach((directive) => {
|
|
@@ -936,7 +1047,6 @@ export class Element extends Vertex {
|
|
|
936
1047
|
arg: directive.arg,
|
|
937
1048
|
modifiers: directive.modifiers,
|
|
938
1049
|
}, element));
|
|
939
|
-
// element.directiveMap[directive.name] = );
|
|
940
1050
|
}
|
|
941
1051
|
});
|
|
942
1052
|
|
|
@@ -1294,6 +1404,11 @@ export class Element extends Vertex {
|
|
|
1294
1404
|
const element = this.parse(html, context);
|
|
1295
1405
|
utils.traverse((current) => {
|
|
1296
1406
|
current.node.assign({ view, parent: current.parent });
|
|
1407
|
+
// 生成唯一组件名 依赖element.view
|
|
1408
|
+
|
|
1409
|
+
if (!current.node.name) {
|
|
1410
|
+
current.node.initElementName();
|
|
1411
|
+
}
|
|
1297
1412
|
}, { node: element, parent });
|
|
1298
1413
|
return element;
|
|
1299
1414
|
}
|
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
|
* 前端组件事件
|