@lcap/nasl 0.3.10-beta.oom4 → 0.3.12-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/out/service/app/api.js +17 -17
  2. package/out/service/app/api.js.map +1 -1
  3. package/out/service/create/errHandles.js +12 -0
  4. package/out/service/create/errHandles.js.map +1 -1
  5. package/out/service/create/index.js +5 -0
  6. package/out/service/create/index.js.map +1 -1
  7. package/out/service/logic/logic.d.ts +26 -17
  8. package/out/service/logic/logic.js +6 -0
  9. package/out/service/logic/logic.js.map +1 -1
  10. package/out/types/app/App.d.ts +9 -0
  11. package/out/types/app/App.js +25 -1
  12. package/out/types/app/App.js.map +1 -1
  13. package/out/types/app/History.js +3 -2
  14. package/out/types/app/History.js.map +1 -1
  15. package/out/types/app/Service.d.ts +3 -0
  16. package/out/types/app/Service.js +14 -6
  17. package/out/types/app/Service.js.map +1 -1
  18. package/out/types/cacheData.js.map +1 -1
  19. package/out/types/common/Vertex.js +2 -1
  20. package/out/types/common/Vertex.js.map +1 -1
  21. package/out/types/data/Entity.d.ts +4 -0
  22. package/out/types/data/Entity.js +8 -0
  23. package/out/types/data/Entity.js.map +1 -1
  24. package/out/types/data/EntityProperty.d.ts +5 -0
  25. package/out/types/data/EntityProperty.js +16 -0
  26. package/out/types/data/EntityProperty.js.map +1 -1
  27. package/out/types/data/GlobalLogicNode.js +8 -1
  28. package/out/types/data/GlobalLogicNode.js.map +1 -1
  29. package/out/types/data/dataTypes.js +1 -1
  30. package/out/types/data/dataTypes.js.map +1 -1
  31. package/out/types/data/genBlock/genCurdEditTableBlock.d.ts +3 -0
  32. package/out/types/data/genBlock/genCurdEditTableBlock.js +578 -0
  33. package/out/types/data/genBlock/genCurdEditTableBlock.js.map +1 -0
  34. package/out/types/data/genBlock/genEditTableBlock.d.ts +234 -0
  35. package/out/types/data/genBlock/genEditTableBlock.js +419 -0
  36. package/out/types/data/genBlock/genEditTableBlock.js.map +1 -0
  37. package/out/types/data/genBlock/genQueryComponent.d.ts +20 -0
  38. package/out/types/data/genBlock/genQueryComponent.js +57 -1
  39. package/out/types/data/genBlock/genQueryComponent.js.map +1 -1
  40. package/out/types/data/genBlock/genTableBlock.js +9 -5
  41. package/out/types/data/genBlock/genTableBlock.js.map +1 -1
  42. package/out/types/data/genBlock/index.d.ts +2 -0
  43. package/out/types/data/genBlock/index.js +2 -0
  44. package/out/types/data/genBlock/index.js.map +1 -1
  45. package/out/types/data/genBlock/utils.d.ts +7 -0
  46. package/out/types/data/genBlock/utils.js +38 -1
  47. package/out/types/data/genBlock/utils.js.map +1 -1
  48. package/out/types/logic/Logic.d.ts +4 -0
  49. package/out/types/logic/Logic.js +35 -10
  50. package/out/types/logic/Logic.js.map +1 -1
  51. package/out/types/logic/LogicItem.js +6 -8
  52. package/out/types/logic/LogicItem.js.map +1 -1
  53. package/out/types/logic/Param.js +5 -13
  54. package/out/types/logic/Param.js.map +1 -1
  55. package/out/types/logic/Return.js +3 -11
  56. package/out/types/logic/Return.js.map +1 -1
  57. package/out/types/logic/Variable.js +3 -6
  58. package/out/types/logic/Variable.js.map +1 -1
  59. package/out/types/logic/translator.js +39 -8
  60. package/out/types/logic/translator.js.map +1 -1
  61. package/out/types/page/Element.d.ts +21 -2
  62. package/out/types/page/Element.js +86 -5
  63. package/out/types/page/Element.js.map +1 -1
  64. package/out/types/page/Page.d.ts +4 -0
  65. package/out/types/page/Page.js +7 -0
  66. package/out/types/page/Page.js.map +1 -1
  67. package/out/types/page/View.d.ts +18 -0
  68. package/out/types/page/View.js +112 -7
  69. package/out/types/page/View.js.map +1 -1
  70. package/out/types/page/ViewVariable.js +0 -6
  71. package/out/types/page/ViewVariable.js.map +1 -1
  72. package/out/types/process/ProcessParam.js +3 -1
  73. package/out/types/process/ProcessParam.js.map +1 -1
  74. package/out/types/utils/index.d.ts +1 -0
  75. package/out/types/utils/index.js +16 -7
  76. package/out/types/utils/index.js.map +1 -1
  77. package/package.json +1 -1
  78. package/src/service/app/api.js +4 -4
  79. package/src/service/create/errHandles.js +12 -0
  80. package/src/service/create/index.js +6 -0
  81. package/src/service/logic/logic.js +6 -0
  82. package/src/types/app/App.ts +32 -9
  83. package/src/types/app/History.ts +3 -2
  84. package/src/types/app/Service.ts +18 -9
  85. package/src/types/cacheData.ts +7 -7
  86. package/src/types/common/Vertex.ts +2 -1
  87. package/src/types/data/Entity.ts +7 -0
  88. package/src/types/data/EntityProperty.ts +12 -0
  89. package/src/types/data/GlobalLogicNode.ts +8 -1
  90. package/src/types/data/dataTypes.ts +1 -1
  91. package/src/types/data/genBlock/genCurdEditTableBlock.ts +581 -0
  92. package/src/types/data/genBlock/genEditTableBlock.ts +470 -0
  93. package/src/types/data/genBlock/genQueryComponent.ts +56 -0
  94. package/src/types/data/genBlock/genTableBlock.ts +14 -10
  95. package/src/types/data/genBlock/index.ts +2 -0
  96. package/src/types/data/genBlock/utils.ts +38 -0
  97. package/src/types/logic/Logic.ts +45 -17
  98. package/src/types/logic/LogicItem.ts +8 -11
  99. package/src/types/logic/Param.ts +25 -35
  100. package/src/types/logic/Return.ts +18 -26
  101. package/src/types/logic/Variable.ts +18 -20
  102. package/src/types/logic/translator.js +41 -10
  103. package/src/types/page/Element.ts +157 -71
  104. package/src/types/page/Page.ts +7 -0
  105. package/src/types/page/View.ts +150 -41
  106. package/src/types/page/ViewVariable.ts +13 -19
  107. package/src/types/page/dist/View.js +727 -0
  108. package/src/types/process/ProcessParam.ts +4 -1
  109. package/src/types/utils/index.ts +16 -7
  110. package/out/service/debugger/debugger.d.ts +0 -3
  111. package/out/service/debugger/debugger.js +0 -95
  112. package/out/service/debugger/debugger.js.map +0 -1
  113. package/out/test/units/config.spec.d.ts +0 -1
  114. package/out/test/units/config.spec.js +0 -12
  115. package/out/test/units/config.spec.js.map +0 -1
  116. package/out/types/logic/BreakPoint.d.ts +0 -42
  117. package/out/types/logic/BreakPoint.js +0 -155
  118. package/out/types/logic/BreakPoint.js.map +0 -1
  119. package/out/types/logic/Debugger.d.ts +0 -156
  120. package/out/types/logic/Debugger.js +0 -912
  121. package/out/types/logic/Debugger.js.map +0 -1
@@ -0,0 +1,470 @@
1
+ import {
2
+ dataTypesMap, vertexsMap, Entity, EntityProperty, View,
3
+ LEVEL_ENUM, utils,
4
+ Enum,
5
+ } from '../..';
6
+ import {
7
+ getExpression, filterProperty, NameGroup, genUniqueQueryNameGroup,
8
+ getFirstDisplayedProperty, getParamFromResolver,
9
+ genGenericTypeSchema, genVariable, genInterParam, genCallComponentLogic,
10
+ genCallInterface, genQueryInterface,
11
+ genCallInterfaceFromTempInterface,
12
+ genMemberExpression,
13
+ genEditQueryStructure,
14
+ } from '.';
15
+
16
+ /**
17
+ * 根据实体属性生成表格列模板
18
+ * @param property 实体属性
19
+ */
20
+ export function genEditTableColumnTemplate(entity: Entity, property: EntityProperty, nameGroup: NameGroup, selectNameGroupMap?: Map<string, NameGroup>) {
21
+ const lowerEntityName = utils.firstLowerCase(property.root.name);
22
+ const valueExpression = `scope.item.${lowerEntityName}.${property.name}`;
23
+ const title = property.label || property.name;
24
+
25
+ const expression = getExpression(property, `scope.item.${lowerEntityName}.${property.name}`);
26
+
27
+ const canEditable = (property: EntityProperty) => property.editable;
28
+
29
+ const getText = (property: EntityProperty) => {
30
+ if (property.typeKey === '#/basicTypes/Boolean') {
31
+ return `
32
+ <u-text v-if="${expression}" text="是"></u-text>
33
+ <u-text v-if="!${expression}" text="否"></u-text>
34
+ `;
35
+ } else {
36
+ return `<u-text :text="${expression}"></u-text>`;
37
+ }
38
+ };
39
+
40
+ const genEditComponent = (property: EntityProperty) => {
41
+ if (!property.editable)
42
+ return '';
43
+ const label = property.label || property.name;
44
+ let formItem = '';
45
+ if (property.$relationEntity && selectNameGroupMap) { // 有外键关联
46
+ const relationEntity = vertexsMap.get(property.$relationEntity) as Entity;
47
+ if (relationEntity) {
48
+ const relationProperty = vertexsMap.get(property.$relationProperty) as EntityProperty;
49
+ const displayedProperty = getFirstDisplayedProperty(relationEntity, 'inForm');
50
+ if (displayedProperty) {
51
+ const lowerEntityName = utils.firstLowerCase(relationEntity.name);
52
+ formItem += `
53
+ <u-select clearable placeholder="请选择${label}" :data-source="${selectNameGroupMap.get(relationEntity.id).load}"
54
+ :autofocus="true" :opened="true" append-to="body" @blur="${nameGroup.blurUpdate}" @select="${nameGroup.blurUpdate}"
55
+ text-field="${lowerEntityName}.${displayedProperty.name}" value-field="${lowerEntityName}.${relationProperty.name}" :pageable="true" :remote-paging="true" :value.sync="${valueExpression}">
56
+ </u-select>
57
+ `;
58
+ } else
59
+ return '';
60
+ } else
61
+ return '';
62
+ } else if (property.typeKey === '#/basicTypes/Boolean') {
63
+ formItem += `<u-select clearable :value.sync="${valueExpression}" placeholder="请输入${label}"
64
+ :autofocus="true" :opened="true" append-to="body" @blur="${nameGroup.blurUpdate}" @select="${nameGroup.blurUpdate}">
65
+ <u-select-item :value="true">是</u-select-item>
66
+ <u-select-item :value="false">否</u-select-item>
67
+ </u-select>`;
68
+ } else if (property.typeKey === '#/basicTypes/Integer' || property.typeKey === '#/basicTypes/Long') {
69
+ formItem = `<u-number-input :value.sync="${valueExpression}" placeholder="请输入${label}" :autofocus="true" @blur="${nameGroup.blurUpdate}"></u-number-input>`;
70
+ } else if (property.typeKey === '#/basicTypes/Decimal') {
71
+ formItem = `<u-number-input :value.sync="${valueExpression}" :precision="0" :step="0" placeholder="请输入${label}" :autofocus="true" @blur="${nameGroup.blurUpdate}"></u-number-input>`;
72
+ } else if (property.typeKey === '#/basicTypes/Text') {
73
+ formItem = `<u-validator placement="bottom" display="appear" @blur-valid="${nameGroup.blurUpdate}" style="width:100%">
74
+ <u-textarea :value.sync="${valueExpression}" placeholder="请输入${label}" :autofocus="true" size="full"></u-textarea>
75
+ </u-validator>`;
76
+ } else if (property.typeKey === '#/basicTypes/Date') {
77
+ formItem = `<u-date-picker clearable :date.sync="${valueExpression}" placeholder="请输入${label}" append-to="body" :autofocus="true" :opened="true" @blur="${nameGroup.blurUpdate}"></u-date-picker>`;
78
+ } else if (property.typeKey === '#/basicTypes/Time') {
79
+ formItem = `<u-time-picker :time.sync="${valueExpression}" placeholder="请输入${label}" append-to="body" :autofocus="true" @blur="${nameGroup.blurUpdate}"></u-time-picker>`;
80
+ } else if (property.typeKey === '#/basicTypes/DateTime') {
81
+ formItem = `<u-date-time-picker clearable :date.sync="${valueExpression}" placeholder="请输入${label}" append-to="body" :autofocus="true" :opened="true" @blur="${nameGroup.blurUpdate}"></u-date-time-picker>`;
82
+ } else if (dataTypesMap[property.typeKey].type === 'enum') {
83
+ formItem = `<u-select clearable :value.sync="${valueExpression}" placeholder="请选择${label}"
84
+ :autofocus="true" :opened="true" append-to="body" :data-source="ID_ENUM_LIST_${dataTypesMap[property.typeKey].id}"
85
+ @blur="${nameGroup.blurUpdate}" @select="${nameGroup.blurUpdate}">
86
+ </u-select>`;
87
+ } else {
88
+ formItem = `<u-validator placement="bottom" display="appear" @blur-valid="${nameGroup.blurUpdate}" style="width:100%" append-to="body">
89
+ <u-input :value.sync="${valueExpression}" placeholder="请输入${label}" :autofocus="true" size="full"></u-input>
90
+ </u-validator>`;
91
+ }
92
+ return `<template #editcell="scope">
93
+ <u-linear-layout gap="small">
94
+ ${formItem}
95
+ </u-linear-layout>
96
+ </template>`;
97
+ };
98
+
99
+ return `<u-table-view-column title="${title}" field="${utils.firstLowerCase(entity.name)}.${property.name}" ${canEditable(property) ? 'type="editable"' : ''}>
100
+ <template #cell="scope">
101
+ <u-linear-layout gap="small">
102
+ ${getText(property)}
103
+ </u-linear-layout>
104
+ </template>
105
+ ${genEditComponent(property)}
106
+ </u-table-view-column>`;
107
+ }
108
+
109
+ /**
110
+ * 生成表格模板
111
+ * @param entity 实体
112
+ * @param nameGroup 命名组
113
+ */
114
+ export function genEditTableTemplate(entity: Entity, nameGroup: NameGroup, selectNameGroupMap?: Map<string, NameGroup>) {
115
+ const propertyList = entity.propertyList
116
+ .filter(filterProperty('inTable'));
117
+
118
+ return `<u-table-view ref="tableView" :data-source="${nameGroup.load}" data-schema="${nameGroup.structure}"
119
+ value-field="${nameGroup.lowerEntity}.id"
120
+ :pageable="true" :remote-paging="true" :show-sizer="true" :default-column-width="300" editable>
121
+ <u-table-view-column type="index" width="60" title="序号"></u-table-view-column>
122
+
123
+ ${propertyList.map((property) => genEditTableColumnTemplate(entity, property, nameGroup, selectNameGroupMap) + '\n').join('')}
124
+
125
+ <u-table-view-column title="操作">
126
+ <template #cell="scope">
127
+ <u-linear-layout gap="small">
128
+ <u-link @click="${nameGroup.remove}($event, scope)">删除</u-link>
129
+ </u-linear-layout>
130
+ </template>
131
+ </u-table-view-column>
132
+ </u-table-view>
133
+ `;
134
+ }
135
+
136
+ /**
137
+ * 生成表格 load 逻辑
138
+ * @param entity 实体
139
+ */
140
+ export function genEditTableLoadLogic(entity: Entity, nameGroup: NameGroup,
141
+ newStructures: Array<any>, newInterfaces: Array<any>, supportFilter: boolean) {
142
+ const paramsSchema = {
143
+ $ref: '#/systemTypes/DataSourceParams',
144
+ };
145
+ const resultSchema = genGenericTypeSchema('PageOf', { T: { $ref: nameGroup.structure } });
146
+ const params = [
147
+ genInterParam(
148
+ `${newInterfaces[0].name}.${newInterfaces[0].logic.params[0].name}`,
149
+ 'params.page',
150
+ [undefined, undefined],
151
+ ),
152
+ genInterParam(
153
+ `${newInterfaces[0].name}.${newInterfaces[0].logic.params[1].name}`,
154
+ 'params.size',
155
+ [undefined, undefined],
156
+ ),
157
+ genInterParam(
158
+ `${newInterfaces[0].name}.${newInterfaces[0].logic.params[2].name}`,
159
+ 'params.sort',
160
+ [undefined, undefined],
161
+ ),
162
+ genInterParam(
163
+ `${newInterfaces[0].name}.${newInterfaces[0].logic.params[3].name}`,
164
+ 'params.order',
165
+ [undefined, undefined],
166
+ ),
167
+ ];
168
+
169
+ if (supportFilter)
170
+ params.push(
171
+ genInterParam(
172
+ `${newInterfaces[0].name}.${newInterfaces[0].logic.params[4].name}`,
173
+ 'filter',
174
+ [undefined],
175
+ ),
176
+ );
177
+
178
+ return {
179
+ level: 'logic',
180
+ name: nameGroup.load,
181
+ params: [{
182
+ level: 'param',
183
+ type: 'Identifier',
184
+ name: 'params',
185
+ schema: paramsSchema,
186
+ }],
187
+ returns: [
188
+ genVariable('result', resultSchema, LEVEL_ENUM.return),
189
+ ],
190
+ variables: [] as Array<any>,
191
+ body: [{
192
+ level: 'logicNode',
193
+ type: 'Start',
194
+ label: '开始',
195
+ }, {
196
+ level: 'logicNode',
197
+ type: 'AssignmentExpression',
198
+ label: '赋值',
199
+ operator: '=',
200
+ left: {
201
+ level: 'expressionNode',
202
+ type: 'Identifier',
203
+ name: 'result',
204
+ },
205
+ right: genCallInterfaceFromTempInterface(newInterfaces[0], params),
206
+ }, {
207
+ level: 'logicNode',
208
+ type: 'End',
209
+ label: '结束',
210
+ }],
211
+ };
212
+ }
213
+
214
+ /**
215
+ * 生成表格 remove 逻辑
216
+ * @param entity 实体
217
+ */
218
+ export function genEditTableRemoveLogic(entity: Entity, nameGroup: NameGroup) {
219
+ const scopeStructureSchema = genGenericTypeSchema('ScopeOf', { T: { $ref: nameGroup.structure } });
220
+ const deleteResolver = entity.resolvers.find((resolver) => resolver.name === 'delete');
221
+ const deleteInterface = deleteResolver.interface;
222
+ const idParam = getParamFromResolver(deleteResolver, 'id');
223
+ const idProperty = entity.propertyList.find((property) => property.primaryKey || property.name === 'id');
224
+
225
+ return {
226
+ level: 'logic',
227
+ name: nameGroup.remove,
228
+ params: [{
229
+ level: 'param',
230
+ type: 'Identifier',
231
+ name: 'event',
232
+ schema: { $ref: '#/basicTypes/String' },
233
+ }, {
234
+ level: 'param',
235
+ name: 'scope',
236
+ schema: scopeStructureSchema,
237
+ }],
238
+ returns: [] as Array<any>,
239
+ variables: [] as Array<any>,
240
+ body: [{
241
+ level: 'logicNode',
242
+ type: 'Start',
243
+ label: '开始',
244
+ },
245
+ genCallInterface(deleteInterface, [
246
+ genInterParam(
247
+ idParam.id,
248
+ `scope.item.${nameGroup.lowerEntity}.id`,
249
+ ['', '', `${nameGroup.structure}.${nameGroup.lowerEntity}`, idProperty.id],
250
+ ),
251
+ ]),
252
+ genCallComponentLogic('tableView', 'reload'),
253
+ {
254
+ level: 'logicNode',
255
+ label: '结束',
256
+ type: 'End',
257
+ }],
258
+ };
259
+ }
260
+
261
+ /**
262
+ * 生成表格 双击编辑 逻辑
263
+ * @param entity 实体
264
+ */
265
+ export function genEditTableDblclickLogic(property: EntityProperty, nameGroup: NameGroup, existingNameSets: {
266
+ viewLogic: Set<string>,
267
+ interface: Set<string>,
268
+ structure: Set<string>,
269
+ }) {
270
+ const scopeStructureSchema = genGenericTypeSchema('ScopeOf', { T: { $ref: nameGroup.structure } });
271
+ const logicName = utils.unique(`set${utils.firstUpperCase(property.name)}Edit`, existingNameSets.viewLogic);
272
+ return {
273
+ level: 'logic',
274
+ name: logicName,
275
+ params: [{
276
+ level: 'param',
277
+ type: 'Identifier',
278
+ name: 'event',
279
+ schema: { $ref: '#/basicTypes/String' },
280
+ }, {
281
+ level: 'param',
282
+ name: 'scope',
283
+ schema: scopeStructureSchema,
284
+ }],
285
+ returns: [] as Array<any>,
286
+ variables: [] as Array<any>,
287
+ body: [{
288
+ level: 'logicNode',
289
+ type: 'Start',
290
+ label: '开始',
291
+ },
292
+ {
293
+ level: 'logicNode',
294
+ type: 'AssignmentExpression',
295
+ label: '赋值',
296
+ operator: '=',
297
+ left: genMemberExpression(`scope.item.editing`, ['', '', `${nameGroup.structure}.editing`]),
298
+ right: {
299
+ level: 'expressionNode',
300
+ type: 'StringLiteral',
301
+ value: `${property.name}`,
302
+ },
303
+ },
304
+ {
305
+ level: 'logicNode',
306
+ label: '结束',
307
+ type: 'End',
308
+ }],
309
+ };
310
+ }
311
+
312
+ /**
313
+ * 生成表格区块
314
+ * @param entity 实体
315
+ * @param view 所插入的页面,用于生成逻辑名字,去重等
316
+ * @notice 目前 logic 名去重做成前置处理了,与 mergeBlock 的后置处理不冲突
317
+ * (页面 load 名) -产生-> (interface 名) -产生-> (structure 名)
318
+ * load -> load_someView_tableView
319
+ * load_select_student -> load_someView_select_student
320
+ */
321
+ export function genEditTableBlock(entity: Entity, view: View) {
322
+ const existingNameSets = {
323
+ viewLogic: new Set(view.$def.logics.map((logic) => logic.name)),
324
+ interface: new Set(entity.dataNode.service.interfaces.map((itface) => itface.name)),
325
+ structure: new Set(entity.dataNode.structures.map((structure) => structure.name)),
326
+ };
327
+
328
+ const nameGroup = genUniqueQueryNameGroup(existingNameSets, view.name, 'tableView');
329
+ nameGroup.remove = utils.unique('remove', existingNameSets.viewLogic);
330
+ nameGroup.blurUpdate = utils.unique('blurUpdate', existingNameSets.viewLogic);
331
+ nameGroup.lowerEntity = utils.firstLowerCase(entity.name);
332
+
333
+ // 收集所有和本实体关联的实体
334
+ const allEntities = [entity];
335
+ entity.propertyList.forEach((property) => {
336
+ if (property.$relationEntity) { // 有外键关联
337
+ const relationEntity = vertexsMap.get(property.$relationEntity) as Entity;
338
+ if (relationEntity) {
339
+ const displayedProperty = getFirstDisplayedProperty(relationEntity);
340
+ if (displayedProperty)
341
+ allEntities.push(relationEntity);
342
+ }
343
+ }
344
+ });
345
+
346
+ const newStructures: Array<any> = [genEditQueryStructure(allEntities, nameGroup)];
347
+ const newInterfaces: Array<any> = [genQueryInterface(allEntities, nameGroup, false, true)];
348
+
349
+ return `
350
+ <template>
351
+ ${genEditTableTemplate(entity, nameGroup)}
352
+ </template>
353
+ <definition>
354
+ {
355
+ "logics": [
356
+ ${JSON.stringify(genEditTableLoadLogic(entity, nameGroup, newStructures, newInterfaces, false))},
357
+ ${JSON.stringify(genEditTableRemoveLogic(entity, nameGroup))}
358
+ ],
359
+ "interfaces": ${JSON.stringify(newInterfaces)},
360
+ "structures": ${JSON.stringify(newStructures)}
361
+ }
362
+ </definition>
363
+ `;
364
+ }
365
+
366
+ export function genBlurUpdateLogic(entity: Entity, nameGroup: NameGroup) {
367
+ const scopeStructureSchema = genGenericTypeSchema('ScopeOf', { T: { $ref: nameGroup.structure } });
368
+ const updateResolver = entity.resolvers.find((item) => item.name === 'update');
369
+ const updateBodyParam = getParamFromResolver(updateResolver, 'body');
370
+
371
+ return {
372
+ level: 'logic',
373
+ name: nameGroup.blurUpdate,
374
+ params: [{
375
+ level: 'param',
376
+ type: 'Identifier',
377
+ name: 'event',
378
+ schema: { $ref: '#/basicTypes/String' },
379
+ }, {
380
+ level: 'param',
381
+ name: 'scope',
382
+ schema: scopeStructureSchema,
383
+ }],
384
+ returns: [] as Array<any>,
385
+ body: [
386
+ {
387
+ level: 'logicNode',
388
+ type: 'Start',
389
+ label: '开始',
390
+ },
391
+ {
392
+ level: 'logicNode',
393
+ type: 'AssignmentExpression',
394
+ label: '赋值',
395
+ operator: '=',
396
+ left: genMemberExpression(`scope.item.editing`, ['', '', `${nameGroup.structure}.editing`]),
397
+ right: {
398
+ level: 'expressionNode',
399
+ type: 'StringLiteral',
400
+ value: '',
401
+ },
402
+ },
403
+ genCallInterface(updateResolver.interface, [
404
+ genInterParam(
405
+ updateBodyParam.id,
406
+ `scope.item.${nameGroup.lowerEntity}`,
407
+ ['', '', `${nameGroup.structure}.${nameGroup.lowerEntity}`],
408
+ ),
409
+ ]),
410
+ {
411
+ level: 'logicNode',
412
+ type: 'End',
413
+ label: '结束',
414
+ },
415
+ ],
416
+ playground: [] as Array<any>,
417
+ expanded: false,
418
+ };
419
+ }
420
+
421
+ export function genEditTableColumnBlock(property: EntityProperty, view: View) {
422
+ const entity = property.root;
423
+
424
+ const existingNameSets = {
425
+ viewLogic: new Set(view.$def.logics.map((logic) => logic.name)),
426
+ interface: new Set(entity.dataNode.service.interfaces.map((itface) => itface.name)),
427
+ structure: new Set(entity.dataNode.structures.map((structure) => structure.name)),
428
+ };
429
+
430
+ const nameGroup = genUniqueQueryNameGroup(existingNameSets, view.name, 'tableView');
431
+ nameGroup.remove = utils.unique('remove', existingNameSets.viewLogic);
432
+ nameGroup.lowerEntity = utils.firstLowerCase(entity.name);
433
+
434
+ // 收集所有和本实体关联的实体
435
+ const allEntities = [entity];
436
+ const propertyList = [property];
437
+ propertyList.forEach((property) => {
438
+ if (property.$relationEntity) { // 有外键关联
439
+ const relationEntity = vertexsMap.get(property.$relationEntity) as Entity;
440
+ if (relationEntity) {
441
+ const displayedProperty = getFirstDisplayedProperty(relationEntity);
442
+ if (displayedProperty)
443
+ allEntities.push(relationEntity);
444
+ }
445
+ }
446
+ });
447
+
448
+ const newStructures: Array<any> = [genEditQueryStructure(allEntities, nameGroup)];
449
+ const newInterfaces: Array<any> = [genQueryInterface(allEntities, nameGroup, false, true)];
450
+
451
+ return `
452
+ <template>
453
+ <u-table-view ref="tableView" :data-source="${nameGroup.load}" :pageable="true" :remote-paging="true" :show-sizer="true" data-schema="${nameGroup.structure}">
454
+ ${propertyList.map((property) => genEditTableColumnTemplate(entity, property, nameGroup) + '\n').join('')}
455
+ </u-table-view>
456
+ </template>
457
+ <definition>
458
+ {
459
+ "logics": [
460
+ ${JSON.stringify(genEditTableLoadLogic(entity, nameGroup, newStructures, newInterfaces, false))},
461
+ ${JSON.stringify(genBlurUpdateLogic(entity, nameGroup))}
462
+ ],
463
+ "interfaces": ${JSON.stringify(newInterfaces)},
464
+ "structures": ${JSON.stringify(newStructures)}
465
+ }
466
+ </definition>
467
+ `;
468
+ }
469
+
470
+ export default genEditTableBlock;
@@ -490,3 +490,59 @@ export async function joinEntity(callQueryComponent: LogicItem, entity: Entity,
490
490
 
491
491
  export default genQueryAssignment;
492
492
 
493
+ export function genEditQueryStructure(allEntities: Array<Entity>, nameGroup: NameGroup) {
494
+ allEntities = Array.from(new Set(allEntities));
495
+ const propertyList = allEntities.map((entity, index) => ({
496
+ level: 'property',
497
+ ideVersion: '2.0',
498
+ editable: true,
499
+ name: utils.firstLowerCase(entity.name),
500
+ $ref: entity.schemaRef,
501
+ _posIndex: index,
502
+ typeKey: entity.schemaRef,
503
+ type: '',
504
+ format: '',
505
+ }));
506
+ // const tempPropertyList = propertyList.map((property) => {
507
+ // const tempProperty = Object.assign({}, property);
508
+ // tempProperty.name = `temp${utils.firstUpperCase(property.name)}`;
509
+ // return tempProperty;
510
+ // });
511
+ // tempPropertyList.push({
512
+ // level: 'property',
513
+ // ideVersion: '2.0',
514
+ // editable: true,
515
+ // name: 'editing',
516
+ // _posIndex: 0,
517
+ // $ref: '',
518
+ // type: 'string',
519
+ // format: '',
520
+ // typeKey: '#/basicTypes/String',
521
+ // });
522
+ // propertyList = propertyList.concat(tempPropertyList);
523
+ propertyList.push({
524
+ level: 'property',
525
+ ideVersion: '2.0',
526
+ editable: true,
527
+ name: 'editing',
528
+ _posIndex: 0,
529
+ $ref: '',
530
+ type: 'string',
531
+ format: '',
532
+ typeKey: '#/basicTypes/String',
533
+ });
534
+ propertyList.forEach((property, index) => {
535
+ property._posIndex = index;
536
+ });
537
+ return {
538
+ level: 'structure',
539
+ ideVersion: '2.0',
540
+ editable: true,
541
+ name: nameGroup.structure,
542
+ type: 'object',
543
+ propertyList,
544
+ serviceId: allEntities[0].serviceId,
545
+ serviceType: 'entity',
546
+ };
547
+ }
548
+
@@ -168,9 +168,7 @@ export function genTableRemoveLogic(entity: Entity, nameGroup: NameGroup) {
168
168
  const scopeStructureSchema = genGenericTypeSchema('ScopeOf', { T: { $ref: nameGroup.structure } });
169
169
  const deleteResolver = entity.resolvers.find((resolver) => resolver.name === 'delete');
170
170
  const deleteInterface = deleteResolver.interface;
171
- const idParam = getParamFromResolver(deleteResolver, 'id');
172
- const idProperty = entity.propertyList.find((property) => property.primaryKey || property.name === 'id');
173
-
171
+ const idPropertys = entity.propertyList.filter((property) => property.primaryKey);
174
172
  return {
175
173
  level: 'logic',
176
174
  name: nameGroup.remove,
@@ -191,13 +189,19 @@ export function genTableRemoveLogic(entity: Entity, nameGroup: NameGroup) {
191
189
  type: 'Start',
192
190
  label: '开始',
193
191
  },
194
- genCallInterface(deleteInterface, [
195
- genInterParam(
196
- idParam.id,
197
- `scope.item.${nameGroup.lowerEntity}.id`,
198
- ['', '', `${nameGroup.structure}.${nameGroup.lowerEntity}`, idProperty.id],
199
- ),
200
- ]),
192
+ genCallInterface(deleteInterface,
193
+ idPropertys.map((idProperty) => {
194
+ let paramFromResolver = getParamFromResolver(deleteResolver, idProperty.name);
195
+ // 如果旧逻辑,但是新导入表中,id的name 不是id 的话,就直接使用名称叫id的
196
+ if (!paramFromResolver) {
197
+ paramFromResolver = getParamFromResolver(deleteResolver, 'id');
198
+ }
199
+ return genInterParam(paramFromResolver.id,
200
+ `scope.item.${nameGroup.lowerEntity}.id`,
201
+ ['', '', `${nameGroup.structure}.${nameGroup.lowerEntity}`, idProperty.id],
202
+ )
203
+ }),
204
+ ),
201
205
  genCallComponentLogic('tableView', 'reload'),
202
206
  {
203
207
  level: 'logicNode',
@@ -13,6 +13,8 @@ export * from './genSelectBlock';
13
13
  export * from './genCurdBlock';
14
14
  export * from './genListViewBlock';
15
15
  export * from './genGridViewBlock';
16
+ export * from './genEditTableBlock';
17
+ export * from './genCurdEditTableBlock';
16
18
 
17
19
  // eslint-disable-next-line prefer-const
18
20
  export let dragSource: Entity | EntityProperty = null;
@@ -169,6 +169,44 @@ export function genInterParam(paramIdOrName: string, expression: string, schemaR
169
169
  };
170
170
  }
171
171
 
172
+ /**
173
+ * 生成接口 Param
174
+ * @param paramIdOrName 参数 id 或引用名称
175
+ * @param expression 表达式
176
+ * @param schemaChildren 数据结构
177
+ */
178
+ export function genMemberExpression(expression: string, schemaRefs: Array<string> = []) {
179
+ const arr = expression.split('.');
180
+
181
+ let expressionNode: any;
182
+ arr.forEach((name, index) => {
183
+ const currentNode = {
184
+ level: LEVEL_ENUM.expressionNode,
185
+ type: 'Identifier',
186
+ name,
187
+ schemaRef: schemaRefs[index],
188
+ };
189
+ if (expressionNode) {
190
+ expressionNode = {
191
+ level: LEVEL_ENUM.expressionNode,
192
+ type: 'MemberExpression',
193
+ object: expressionNode,
194
+ property: {
195
+ level: LEVEL_ENUM.expressionNode,
196
+ type: 'Identifier',
197
+ name,
198
+ schemaRef: schemaRefs[index],
199
+ code: schemaRefs[index] === '' ? '' : undefined,
200
+ },
201
+ };
202
+ } else {
203
+ expressionNode = currentNode;
204
+ }
205
+ });
206
+
207
+ return expressionNode;
208
+ }
209
+
172
210
  /**
173
211
  * 命名组,主要承载一次 mergeBlock 中的逻辑名称
174
212
  */