@lcap/nasl 0.3.10 → 0.3.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +5 -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 +13 -0
- package/out/types/app/App.js +55 -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 +42 -9
- 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 +42 -1
- 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/GlobalLogicNode.js +8 -1
- package/out/types/data/GlobalLogicNode.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 +49 -32
- 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 +24 -0
- package/out/types/page/Element.js +198 -134
- 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 +66 -27
- package/out/types/page/Page.js.map +1 -1
- package/out/types/page/View.d.ts +19 -1
- package/out/types/page/View.js +150 -40
- 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 +1 -2
- package/src/service/app/api.js +8 -17
- package/src/service/create/errHandles.js +18 -2
- package/src/service/create/index.js +6 -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 +58 -2
- package/src/types/app/History.ts +3 -2
- package/src/types/app/Service.ts +48 -10
- package/src/types/cache.ts +50 -0
- package/src/types/cacheData.ts +7 -7
- package/src/types/common/Vertex.ts +32 -1
- 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/GlobalLogicNode.ts +8 -1
- 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 +55 -38
- 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 +212 -138
- package/src/types/page/Event.ts +0 -3
- package/src/types/page/Page.ts +80 -40
- package/src/types/page/View.ts +154 -39
- 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 { traverse, unique } from '../utils';
|
|
11
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,6 +160,16 @@ 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_PREFIX_REG?: RegExp = /^([lieu]|van)[-_]/;
|
|
168
|
+
/**
|
|
169
|
+
* 忽略命名的标签
|
|
170
|
+
*/
|
|
171
|
+
@immutable()
|
|
172
|
+
public static readonly ignoreTag?: Array<string> = ['div', 'span'];
|
|
145
173
|
|
|
146
174
|
/**
|
|
147
175
|
* @param source 需要合并的部分参数
|
|
@@ -149,9 +177,6 @@ export class Element extends Vertex {
|
|
|
149
177
|
constructor(source?: Partial<Element>) {
|
|
150
178
|
super();
|
|
151
179
|
source && this.assign(source);
|
|
152
|
-
// 为了给生成的节点使用
|
|
153
|
-
// !this.id && this.assign({ id: uuidv4() });
|
|
154
|
-
// this.assign({ id: 'temp-' + uuidv4() });
|
|
155
180
|
}
|
|
156
181
|
assign(source?: any) {
|
|
157
182
|
['attrList', 'eventList', 'directiveList', 'children'].forEach((key) => {
|
|
@@ -171,62 +196,45 @@ export class Element extends Vertex {
|
|
|
171
196
|
}
|
|
172
197
|
|
|
173
198
|
config.defaultApp?.emit('saving');
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
appId: config.defaultApp?.id,
|
|
183
|
-
operationAction: 'Element.create',
|
|
184
|
-
operationDesc: `添加组件"${this.getElementTitle()}"`,
|
|
185
|
-
},
|
|
186
|
-
body,
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
// Nuims createResource
|
|
190
|
-
// Element 对应资源增删在 undo/redo 情况下可能存在权限丢失的情况
|
|
191
|
-
// 暂时只增不减
|
|
192
|
-
// new Nuims({
|
|
193
|
-
// domainName: this.view.page.service.app.name,
|
|
194
|
-
// element: this,
|
|
195
|
-
// }).createResource();
|
|
196
|
-
|
|
197
|
-
this.deepPick(result, ['id', 'parentId', 'elementId']);
|
|
198
|
-
// attr,directive,event的id,exprssion需要合并
|
|
199
|
-
this.attrList.forEach((attr, index) => {
|
|
200
|
-
attr.deepPick(result.attrList[index], ['id', 'expression']);
|
|
201
|
-
});
|
|
202
|
-
this.directiveList.forEach((directive, index) => {
|
|
203
|
-
directive.deepPick(result.directiveList[index], ['id', 'expression']);
|
|
204
|
-
});
|
|
205
|
-
this.eventList.forEach((event, index) => {
|
|
206
|
-
event.deepPick(result.eventList[index], ['id']);
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
this.view && this.view.emit('change');
|
|
211
|
-
|
|
212
|
-
if (actionOptions?.loadHistory !== false) {
|
|
213
|
-
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,
|
|
214
207
|
operationAction: 'Element.create',
|
|
215
|
-
operationBeforeImage: null,
|
|
216
|
-
operationAfterImage: JSON.parse(JSON.stringify(this)),
|
|
217
208
|
operationDesc: `添加组件"${this.getElementTitle()}"`,
|
|
218
|
-
}
|
|
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
|
+
});
|
|
219
235
|
config.defaultApp?.emit('saved');
|
|
220
|
-
}
|
|
221
|
-
return this;
|
|
222
|
-
} catch (err) {
|
|
223
|
-
if (this.view) {
|
|
224
|
-
await this.view.load();
|
|
225
|
-
this.view.emit('change');
|
|
226
|
-
config.defaultApp?.emit('saved');
|
|
227
|
-
}
|
|
228
|
-
throw err;
|
|
229
236
|
}
|
|
237
|
+
return this;
|
|
230
238
|
}
|
|
231
239
|
/**
|
|
232
240
|
* 删除元素
|
|
@@ -236,6 +244,7 @@ export class Element extends Vertex {
|
|
|
236
244
|
if (actionOptions?.actionMode === ACTION_MODE.local) {
|
|
237
245
|
const index = this.parent.children.indexOf(this);
|
|
238
246
|
~index && this.parent.children.splice(index, 1);
|
|
247
|
+
this.deepRemoveElementsName();
|
|
239
248
|
this.view && this.view.emit('local-change');
|
|
240
249
|
return this;
|
|
241
250
|
}
|
|
@@ -247,34 +256,24 @@ export class Element extends Vertex {
|
|
|
247
256
|
|
|
248
257
|
if (actionOptions?.actionMode !== ACTION_MODE.undoRedo) {
|
|
249
258
|
if (this.id) {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
});
|
|
261
|
-
} catch (err) {
|
|
262
|
-
await config.defaultApp?.history.load();
|
|
263
|
-
throw err;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
// Nuims deleteResource
|
|
267
|
-
// Element 对应资源增删在 undo/redo 情况下可能存在权限丢失的情况
|
|
268
|
-
// 暂时只增不减
|
|
269
|
-
// new Nuims({
|
|
270
|
-
// domainName: this.view.page.service.app.name,
|
|
271
|
-
// element: this,
|
|
272
|
-
// }).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));
|
|
273
269
|
}
|
|
274
270
|
}
|
|
275
271
|
|
|
276
272
|
const index = this.parent.children.indexOf(this);
|
|
277
273
|
~index && this.parent.children.splice(index, 1);
|
|
274
|
+
|
|
275
|
+
// 递归删除组件名的缓存
|
|
276
|
+
this.deepRemoveElementsName();
|
|
278
277
|
this.destroy();
|
|
279
278
|
this.view && this.view.emit('change');
|
|
280
279
|
if (actionOptions?.loadHistory !== false) {
|
|
@@ -294,39 +293,51 @@ export class Element extends Vertex {
|
|
|
294
293
|
config.defaultApp?.emit('saving');
|
|
295
294
|
|
|
296
295
|
source && this.assign(source);
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
}
|
|
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
|
+
}
|
|
310
308
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
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
|
+
});
|
|
318
316
|
|
|
319
317
|
config.defaultApp?.emit('saved');
|
|
320
318
|
return this;
|
|
321
|
-
} catch (err) {
|
|
322
|
-
if (this.view) {
|
|
323
|
-
await this.view.load();
|
|
324
|
-
this.view.emit('change');
|
|
325
|
-
config.defaultApp?.emit('saved');
|
|
326
|
-
}
|
|
327
|
-
throw err;
|
|
328
|
-
}
|
|
329
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
|
+
|
|
330
341
|
async move(options: {
|
|
331
342
|
parentId?: string,
|
|
332
343
|
_posIndex?: number,
|
|
@@ -364,11 +375,16 @@ export class Element extends Vertex {
|
|
|
364
375
|
}
|
|
365
376
|
|
|
366
377
|
config.defaultApp?.emit('element.moved');
|
|
378
|
+
config.defaultApp?.emit('saved');
|
|
367
379
|
} catch (err) {
|
|
368
380
|
if (this.view) {
|
|
369
381
|
await this.view.load();
|
|
370
382
|
this.view.emit('change');
|
|
371
383
|
}
|
|
384
|
+
config.defaultApp?.emit('saved', {
|
|
385
|
+
action: 'move',
|
|
386
|
+
err,
|
|
387
|
+
});
|
|
372
388
|
throw err;
|
|
373
389
|
}
|
|
374
390
|
}
|
|
@@ -382,7 +398,8 @@ export class Element extends Vertex {
|
|
|
382
398
|
|
|
383
399
|
const index = this.parent.children.indexOf(this);
|
|
384
400
|
const newNode = Element.fromHTML(code, this.parent, this.view);
|
|
385
|
-
|
|
401
|
+
// 复制的元素需重新命名
|
|
402
|
+
newNode.deepRenameElements();
|
|
386
403
|
|
|
387
404
|
const mergeExpression = (originList: Array<Attr|Directive>, newList: Array<Attr|Directive>) => {
|
|
388
405
|
newList.forEach((item) => {
|
|
@@ -436,11 +453,11 @@ export class Element extends Vertex {
|
|
|
436
453
|
};
|
|
437
454
|
|
|
438
455
|
const arrayComp = this.findElementsByTag('u-modal');
|
|
439
|
-
const existingNames = Object.values(mapValues(arrayComp,
|
|
456
|
+
const existingNames = Object.values(mapValues(arrayComp, (o) => o.name));
|
|
440
457
|
// 处理弹窗组件的命名问题
|
|
441
458
|
if (newNode.tag === 'u-modal') {
|
|
442
459
|
Object.assign(newNode, {
|
|
443
|
-
name: unique('saveModal1', existingNames as any),
|
|
460
|
+
name: utils.unique('saveModal1', existingNames as any),
|
|
444
461
|
});
|
|
445
462
|
}
|
|
446
463
|
|
|
@@ -500,11 +517,30 @@ export class Element extends Vertex {
|
|
|
500
517
|
await this.update(undefined, {
|
|
501
518
|
actionDesc: `设置组件"${this.getElementTitle()}"的名称为"${name}"`,
|
|
502
519
|
});
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
520
|
+
|
|
521
|
+
if (!(window as any).globalData.hasUserCenter) {
|
|
522
|
+
// 同步权限
|
|
523
|
+
new Nuims({
|
|
524
|
+
domainName: this.view.page.service.app.name,
|
|
525
|
+
element: this,
|
|
526
|
+
}).editResourceFromResourceValue(oldName ? `${this.view.tempPath}/${oldName}` : null);
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
this.view && this.view.emit('change');
|
|
530
|
+
if (this.view && this.view.page && this.view.page.service) {
|
|
531
|
+
this.view.page.service.emit('vertexIdToNameChange', this.id, this.name);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* 更新描述信息
|
|
537
|
+
* @param description
|
|
538
|
+
*/
|
|
539
|
+
async setDescription(description: string) {
|
|
540
|
+
this.assign({ description });
|
|
541
|
+
await this.update(undefined, {
|
|
542
|
+
actionDesc: `设置组件"${this.getElementTitle()}"的描述为"${description}"`,
|
|
543
|
+
});
|
|
508
544
|
|
|
509
545
|
this.view && this.view.emit('change');
|
|
510
546
|
if (this.view && this.view.page && this.view.page.service) {
|
|
@@ -553,9 +589,7 @@ export class Element extends Vertex {
|
|
|
553
589
|
async setAttr(name: string, type: 'string' | 'static' | 'dynamic', value?: any) {
|
|
554
590
|
let attr = this.getAttr(name);
|
|
555
591
|
//
|
|
556
|
-
if (value
|
|
557
|
-
|
|
558
|
-
} else {
|
|
592
|
+
if (value !== undefined) {
|
|
559
593
|
if (typeof value !== 'string')
|
|
560
594
|
value = JSON.stringify(value);
|
|
561
595
|
|
|
@@ -566,7 +600,7 @@ export class Element extends Vertex {
|
|
|
566
600
|
});
|
|
567
601
|
await attr.update(undefined, {
|
|
568
602
|
actionDesc: `设置组件"${this.getElementTitle()}"属性"${attr.name}"的值为"${attr.value}"`,
|
|
569
|
-
});
|
|
603
|
+
}).catch(catchFn(this.view));
|
|
570
604
|
} else {
|
|
571
605
|
attr = Attr.from({
|
|
572
606
|
name,
|
|
@@ -576,7 +610,7 @@ export class Element extends Vertex {
|
|
|
576
610
|
}, this);
|
|
577
611
|
await attr.create(undefined, {
|
|
578
612
|
actionDesc: `设置组件"${this.getElementTitle()}"属性"${attr.name}"的值为"${attr.value}"`,
|
|
579
|
-
});
|
|
613
|
+
}).catch(catchFn(this.view));
|
|
580
614
|
this.attrList.push(attr);
|
|
581
615
|
}
|
|
582
616
|
}
|
|
@@ -593,7 +627,7 @@ export class Element extends Vertex {
|
|
|
593
627
|
|
|
594
628
|
await event.create(undefined, Object.assign({
|
|
595
629
|
actionDesc: `添加组件"${this.getElementTitle()}"事件"${event.name}"`,
|
|
596
|
-
}, actionOptions));
|
|
630
|
+
}, actionOptions)).catch(catchFn(this.view));
|
|
597
631
|
event = Event.from(event, this);
|
|
598
632
|
this.eventList.push(event);
|
|
599
633
|
|
|
@@ -616,7 +650,7 @@ export class Element extends Vertex {
|
|
|
616
650
|
|
|
617
651
|
await event.delete(undefined, Object.assign({
|
|
618
652
|
actionDesc: `删除组件"${this.getElementTitle()}"事件"${event.name}"`,
|
|
619
|
-
}, actionOptions));
|
|
653
|
+
}, actionOptions)).catch(catchFn(this.view));
|
|
620
654
|
const index = this.eventList.indexOf(event);
|
|
621
655
|
~index && this.eventList.splice(index, 1);
|
|
622
656
|
|
|
@@ -634,7 +668,7 @@ export class Element extends Vertex {
|
|
|
634
668
|
const directive = new Directive(data);
|
|
635
669
|
await directive.create(undefined, Object.assign({
|
|
636
670
|
actionDesc: `添加组件"${this.getElementTitle()}"指令"${directive.name}"`,
|
|
637
|
-
}, actionOptions));
|
|
671
|
+
}, actionOptions)).catch(catchFn(this.view));
|
|
638
672
|
this.directiveList.push(Directive.from(directive, this));
|
|
639
673
|
|
|
640
674
|
this.view && this.view.emit('change');
|
|
@@ -651,7 +685,7 @@ export class Element extends Vertex {
|
|
|
651
685
|
|
|
652
686
|
await directive.delete(undefined, Object.assign({
|
|
653
687
|
actionDesc: `删除组件"${this.getElementTitle()}"属性"${directive.name}"`,
|
|
654
|
-
}, actionOptions));
|
|
688
|
+
}, actionOptions)).catch(catchFn(this.view));
|
|
655
689
|
const index = this.directiveList.indexOf(directive);
|
|
656
690
|
~index && this.directiveList.splice(index, 1);
|
|
657
691
|
|
|
@@ -733,8 +767,11 @@ export class Element extends Vertex {
|
|
|
733
767
|
if (attr.level === LEVEL_ENUM.attr) {
|
|
734
768
|
const api = config.allNodesAPI[el.tag];
|
|
735
769
|
const apiOfAttr = api && api.attrs && api.attrs.find((_attr) => _attr.name === attr.name);
|
|
736
|
-
if (apiOfAttr && apiOfAttr['designer-value']) {
|
|
737
|
-
|
|
770
|
+
if (apiOfAttr && apiOfAttr['designer-value'] !== undefined) {
|
|
771
|
+
let designerValue = apiOfAttr['designer-value'];
|
|
772
|
+
if (typeof designerValue === 'string') {
|
|
773
|
+
designerValue = designerValue.replace(/"/g, '\'');
|
|
774
|
+
}
|
|
738
775
|
try {
|
|
739
776
|
json5.parse(designerValue);
|
|
740
777
|
return `:${attr.name}="${designerValue}"`;
|
|
@@ -838,7 +875,7 @@ export class Element extends Vertex {
|
|
|
838
875
|
findElementsByTagInChildren(children: Array<any>, tag: string, existingNames: Array<any>) {
|
|
839
876
|
for (const child of children) {
|
|
840
877
|
const result = child.findElementByTag(tag);
|
|
841
|
-
|
|
878
|
+
|
|
842
879
|
if (child.children) {
|
|
843
880
|
this.findElementsByTagInChildren(child.children, tag, existingNames);
|
|
844
881
|
}
|
|
@@ -847,6 +884,46 @@ export class Element extends Vertex {
|
|
|
847
884
|
}
|
|
848
885
|
}
|
|
849
886
|
}
|
|
887
|
+
|
|
888
|
+
// 初始化组件名
|
|
889
|
+
public initElementName() {
|
|
890
|
+
if (Element.ignoreTag.includes(this.tag)) {
|
|
891
|
+
return;
|
|
892
|
+
}
|
|
893
|
+
const name = this.genElementName();
|
|
894
|
+
this.assign({ name });
|
|
895
|
+
this.view.addElementName(name);
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
// 生成新的组件名
|
|
899
|
+
public genElementName(): string {
|
|
900
|
+
const compNameSet = this.view.elementNameSet;
|
|
901
|
+
const tagName = this.tag.replace(Element.TAG_NAME_PREFIX_REG, '').replace(/-/g, '_');
|
|
902
|
+
const componentName = utils.unique(tagName + '1', compNameSet);
|
|
903
|
+
return componentName;
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
// 递归生成组件名
|
|
907
|
+
public deepRenameElements(): void {
|
|
908
|
+
return this.traverseChildren((ele: Element) => {
|
|
909
|
+
ele.initElementName();
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
// 递归删除组件名的缓存
|
|
914
|
+
public deepRemoveElementsName(): void {
|
|
915
|
+
return this.traverseChildren((ele: Element) => {
|
|
916
|
+
this.view.removeElementName(ele.name);
|
|
917
|
+
});
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
// 递归遍历组件
|
|
921
|
+
public traverseChildren(cb: (ele: Element) => void): void {
|
|
922
|
+
utils.traverse((current) => {
|
|
923
|
+
cb(current.node);
|
|
924
|
+
}, { node: this });
|
|
925
|
+
}
|
|
926
|
+
|
|
850
927
|
/**
|
|
851
928
|
* 从 Vue 的 ASTNode 转换成 ASL 元素
|
|
852
929
|
* @param astNode Vue 的 ASTNode
|
|
@@ -891,8 +968,6 @@ export class Element extends Vertex {
|
|
|
891
968
|
}
|
|
892
969
|
}
|
|
893
970
|
|
|
894
|
-
// if (astNode.tag === 'template')
|
|
895
|
-
// astNode.tag = 'div';
|
|
896
971
|
element = new Element({
|
|
897
972
|
tag: astNode.tag,
|
|
898
973
|
name: astNode.attrsMap.ref,
|
|
@@ -933,7 +1008,6 @@ export class Element extends Vertex {
|
|
|
933
1008
|
}
|
|
934
1009
|
}
|
|
935
1010
|
element.attrList.push(attr);
|
|
936
|
-
// element.attrMap[attr.name] = attr;
|
|
937
1011
|
});
|
|
938
1012
|
|
|
939
1013
|
// compiler 处理:value.sync 时会加上update:value事件,需要过滤
|
|
@@ -945,10 +1019,6 @@ export class Element extends Vertex {
|
|
|
945
1019
|
value,
|
|
946
1020
|
logicId: value[0] === '$' ? undefined : value,
|
|
947
1021
|
}, element));
|
|
948
|
-
// element.eventMap[name] = new Event({
|
|
949
|
-
// name,
|
|
950
|
-
// value: oldEvent.value,
|
|
951
|
-
// });
|
|
952
1022
|
});
|
|
953
1023
|
|
|
954
1024
|
astNode.directives && astNode.directives.forEach((directive) => {
|
|
@@ -975,7 +1045,6 @@ export class Element extends Vertex {
|
|
|
975
1045
|
arg: directive.arg,
|
|
976
1046
|
modifiers: directive.modifiers,
|
|
977
1047
|
}, element));
|
|
978
|
-
// element.directiveMap[directive.name] = );
|
|
979
1048
|
}
|
|
980
1049
|
});
|
|
981
1050
|
|
|
@@ -1333,6 +1402,11 @@ export class Element extends Vertex {
|
|
|
1333
1402
|
const element = this.parse(html, context);
|
|
1334
1403
|
utils.traverse((current) => {
|
|
1335
1404
|
current.node.assign({ view, parent: current.parent });
|
|
1405
|
+
// 生成唯一组件名 依赖element.view
|
|
1406
|
+
|
|
1407
|
+
if (!current.node.name) {
|
|
1408
|
+
current.node.initElementName();
|
|
1409
|
+
}
|
|
1336
1410
|
}, { node: element, parent });
|
|
1337
1411
|
return element;
|
|
1338
1412
|
}
|
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
|
* 前端组件事件
|