@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.
Files changed (194) hide show
  1. package/out/service/app/api.d.ts +1 -15
  2. package/out/service/app/api.js +7 -17
  3. package/out/service/app/api.js.map +1 -1
  4. package/out/service/create/errHandles.js +19 -2
  5. package/out/service/create/errHandles.js.map +1 -1
  6. package/out/service/create/index.js +5 -0
  7. package/out/service/create/index.js.map +1 -1
  8. package/out/service/logic/logic.d.ts +50 -14
  9. package/out/service/logic/logic.js +26 -0
  10. package/out/service/logic/logic.js.map +1 -1
  11. package/out/service/page/element.d.ts +9 -0
  12. package/out/service/page/element.js +6 -0
  13. package/out/service/page/element.js.map +1 -1
  14. package/out/service/permission/api.d.ts +57 -0
  15. package/out/service/permission/api.js +41 -0
  16. package/out/service/permission/api.js.map +1 -0
  17. package/out/service/permission/index.d.ts +2 -0
  18. package/out/service/permission/index.js +17 -0
  19. package/out/service/permission/index.js.map +1 -0
  20. package/out/service/webFile/index.js +5 -0
  21. package/out/service/webFile/index.js.map +1 -1
  22. package/out/types/app/App.d.ts +13 -0
  23. package/out/types/app/App.js +55 -1
  24. package/out/types/app/App.js.map +1 -1
  25. package/out/types/app/History.js +3 -2
  26. package/out/types/app/History.js.map +1 -1
  27. package/out/types/app/Service.d.ts +5 -2
  28. package/out/types/app/Service.js +42 -9
  29. package/out/types/app/Service.js.map +1 -1
  30. package/out/types/cache.d.ts +6 -0
  31. package/out/types/cache.js +54 -0
  32. package/out/types/cache.js.map +1 -0
  33. package/out/types/cacheData.js.map +1 -1
  34. package/out/types/common/Vertex.d.ts +25 -0
  35. package/out/types/common/Vertex.js +42 -1
  36. package/out/types/common/Vertex.js.map +1 -1
  37. package/out/types/data/Entity.d.ts +4 -0
  38. package/out/types/data/Entity.js +9 -0
  39. package/out/types/data/Entity.js.map +1 -1
  40. package/out/types/data/EntityProperty.d.ts +5 -0
  41. package/out/types/data/EntityProperty.js +16 -0
  42. package/out/types/data/EntityProperty.js.map +1 -1
  43. package/out/types/data/Enum.d.ts +5 -0
  44. package/out/types/data/Enum.js +5 -0
  45. package/out/types/data/Enum.js.map +1 -1
  46. package/out/types/data/GlobalLogicNode.js +8 -1
  47. package/out/types/data/GlobalLogicNode.js.map +1 -1
  48. package/out/types/data/Interface.js +5 -3
  49. package/out/types/data/Interface.js.map +1 -1
  50. package/out/types/data/dataTypes.js +1 -1
  51. package/out/types/data/dataTypes.js.map +1 -1
  52. package/out/types/data/genBlock/genCreateBlock.js +5 -5
  53. package/out/types/data/genBlock/genCreateBlock.js.map +1 -1
  54. package/out/types/data/genBlock/genCurdBlock.js +3 -3
  55. package/out/types/data/genBlock/genCurdBlock.js.map +1 -1
  56. package/out/types/data/genBlock/genCurdEditTableBlock.d.ts +3 -0
  57. package/out/types/data/genBlock/genCurdEditTableBlock.js +578 -0
  58. package/out/types/data/genBlock/genCurdEditTableBlock.js.map +1 -0
  59. package/out/types/data/genBlock/genEditTableBlock.d.ts +234 -0
  60. package/out/types/data/genBlock/genEditTableBlock.js +419 -0
  61. package/out/types/data/genBlock/genEditTableBlock.js.map +1 -0
  62. package/out/types/data/genBlock/genEnumSelectBlock.d.ts +1 -1
  63. package/out/types/data/genBlock/genEnumSelectBlock.js +2 -2
  64. package/out/types/data/genBlock/genEnumSelectBlock.js.map +1 -1
  65. package/out/types/data/genBlock/genGridViewBlock.js +12 -1
  66. package/out/types/data/genBlock/genGridViewBlock.js.map +1 -1
  67. package/out/types/data/genBlock/genListViewBlock.js +2 -2
  68. package/out/types/data/genBlock/genQueryComponent.d.ts +20 -0
  69. package/out/types/data/genBlock/genQueryComponent.js +57 -1
  70. package/out/types/data/genBlock/genQueryComponent.js.map +1 -1
  71. package/out/types/data/genBlock/genSelectBlock.js +2 -2
  72. package/out/types/data/genBlock/genTableBlock.js +23 -8
  73. package/out/types/data/genBlock/genTableBlock.js.map +1 -1
  74. package/out/types/data/genBlock/genUpdateBlock.js +5 -5
  75. package/out/types/data/genBlock/genUpdateBlock.js.map +1 -1
  76. package/out/types/data/genBlock/index.d.ts +2 -0
  77. package/out/types/data/genBlock/index.js +2 -0
  78. package/out/types/data/genBlock/index.js.map +1 -1
  79. package/out/types/data/genBlock/utils.d.ts +7 -0
  80. package/out/types/data/genBlock/utils.js +38 -1
  81. package/out/types/data/genBlock/utils.js.map +1 -1
  82. package/out/types/data/systemTypes.js +47 -0
  83. package/out/types/data/systemTypes.js.map +1 -1
  84. package/out/types/enum.d.ts +6 -0
  85. package/out/types/enum.js +11 -0
  86. package/out/types/enum.js.map +1 -0
  87. package/out/types/generator/hotReload.d.ts +2 -0
  88. package/out/types/generator/hotReload.js +12 -1
  89. package/out/types/generator/hotReload.js.map +1 -1
  90. package/out/types/index.d.ts +5 -1
  91. package/out/types/index.js +8 -2
  92. package/out/types/index.js.map +1 -1
  93. package/out/types/logic/Logic.d.ts +32 -0
  94. package/out/types/logic/Logic.js +151 -41
  95. package/out/types/logic/Logic.js.map +1 -1
  96. package/out/types/logic/LogicItem.d.ts +1 -0
  97. package/out/types/logic/LogicItem.js +49 -32
  98. package/out/types/logic/LogicItem.js.map +1 -1
  99. package/out/types/logic/Param.d.ts +1 -0
  100. package/out/types/logic/Param.js +43 -33
  101. package/out/types/logic/Param.js.map +1 -1
  102. package/out/types/logic/Return.js +17 -30
  103. package/out/types/logic/Return.js.map +1 -1
  104. package/out/types/logic/Variable.js +17 -25
  105. package/out/types/logic/Variable.js.map +1 -1
  106. package/out/types/logic/translator.js +39 -10
  107. package/out/types/logic/translator.js.map +1 -1
  108. package/out/types/nuims/Nuims.d.ts +1 -1
  109. package/out/types/nuims/Nuims.js +11 -4
  110. package/out/types/nuims/Nuims.js.map +1 -1
  111. package/out/types/page/Element.d.ts +24 -0
  112. package/out/types/page/Element.js +198 -134
  113. package/out/types/page/Element.js.map +1 -1
  114. package/out/types/page/Event.js.map +1 -1
  115. package/out/types/page/Page.d.ts +5 -0
  116. package/out/types/page/Page.js +66 -27
  117. package/out/types/page/Page.js.map +1 -1
  118. package/out/types/page/View.d.ts +19 -1
  119. package/out/types/page/View.js +150 -40
  120. package/out/types/page/View.js.map +1 -1
  121. package/out/types/page/ViewParam.d.ts +1 -0
  122. package/out/types/page/ViewParam.js +23 -4
  123. package/out/types/page/ViewParam.js.map +1 -1
  124. package/out/types/page/ViewVariable.js +13 -24
  125. package/out/types/page/ViewVariable.js.map +1 -1
  126. package/out/types/permission/Permission.d.ts +41 -0
  127. package/out/types/permission/Permission.js +122 -0
  128. package/out/types/permission/Permission.js.map +1 -0
  129. package/out/types/process/ProcessParam.js +3 -1
  130. package/out/types/process/ProcessParam.js.map +1 -1
  131. package/out/types/utils/index.d.ts +1 -0
  132. package/out/types/utils/index.js +16 -7
  133. package/out/types/utils/index.js.map +1 -1
  134. package/package.json +1 -2
  135. package/src/service/app/api.js +8 -17
  136. package/src/service/create/errHandles.js +18 -2
  137. package/src/service/create/index.js +6 -0
  138. package/src/service/developPermission/api.js +37 -0
  139. package/src/service/developPermission/index.js +13 -0
  140. package/src/service/logic/logic.js +26 -0
  141. package/src/service/page/element.js +6 -0
  142. package/src/service/permission/api.js +38 -0
  143. package/src/service/permission/index.js +13 -0
  144. package/src/service/webFile/index.js +6 -1
  145. package/src/types/app/App.ts +58 -2
  146. package/src/types/app/History.ts +3 -2
  147. package/src/types/app/Service.ts +48 -10
  148. package/src/types/cache.ts +50 -0
  149. package/src/types/cacheData.ts +7 -7
  150. package/src/types/common/Vertex.ts +32 -1
  151. package/src/types/data/Entity.ts +8 -0
  152. package/src/types/data/EntityProperty.ts +12 -0
  153. package/src/types/data/Enum.ts +5 -0
  154. package/src/types/data/GlobalLogicNode.ts +8 -1
  155. package/src/types/data/Interface.ts +4 -3
  156. package/src/types/data/dataTypes.ts +1 -1
  157. package/src/types/data/genBlock/genCreateBlock.ts +5 -5
  158. package/src/types/data/genBlock/genCurdBlock.ts +3 -3
  159. package/src/types/data/genBlock/genCurdEditTableBlock.ts +581 -0
  160. package/src/types/data/genBlock/genEditTableBlock.ts +470 -0
  161. package/src/types/data/genBlock/genEnumSelectBlock.ts +2 -2
  162. package/src/types/data/genBlock/genGridViewBlock.ts +12 -1
  163. package/src/types/data/genBlock/genListViewBlock.ts +2 -2
  164. package/src/types/data/genBlock/genQueryComponent.ts +56 -0
  165. package/src/types/data/genBlock/genSelectBlock.ts +2 -2
  166. package/src/types/data/genBlock/genTableBlock.ts +28 -13
  167. package/src/types/data/genBlock/genUpdateBlock.ts +5 -5
  168. package/src/types/data/genBlock/index.ts +2 -0
  169. package/src/types/data/genBlock/utils.ts +38 -0
  170. package/src/types/data/systemTypes.ts +47 -0
  171. package/src/types/enum.ts +6 -0
  172. package/src/types/generator/hotReload.ts +10 -0
  173. package/src/types/index.ts +5 -1
  174. package/src/types/logic/Logic.ts +148 -39
  175. package/src/types/logic/LogicItem.ts +55 -38
  176. package/src/types/logic/Param.ts +43 -35
  177. package/src/types/logic/Return.ts +21 -34
  178. package/src/types/logic/Variable.ts +21 -27
  179. package/src/types/logic/translator.js +41 -14
  180. package/src/types/logic/translator_backup.js +5 -16
  181. package/src/types/nuims/Nuims.ts +11 -5
  182. package/src/types/page/Element.ts +212 -138
  183. package/src/types/page/Event.ts +0 -3
  184. package/src/types/page/Page.ts +80 -40
  185. package/src/types/page/View.ts +154 -39
  186. package/src/types/page/ViewParam.ts +22 -3
  187. package/src/types/page/ViewVariable.ts +16 -26
  188. package/src/types/page/dist/View.js +727 -0
  189. package/src/types/permission/Permission.ts +112 -0
  190. package/src/types/process/ProcessParam.ts +4 -1
  191. package/src/types/utils/index.ts +16 -7
  192. package/out/test/units/config.spec.d.ts +0 -1
  193. package/out/test/units/config.spec.js +0 -12
  194. package/out/test/units/config.spec.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;
@@ -7,14 +7,14 @@ import { config, Enum } from '../..';
7
7
  * @param size 尺寸属性的内容
8
8
  * @param placeholder 占位符的内容
9
9
  */
10
- export function genEnumSelectBlock(enumeration: Enum, vModel?: string, size?: string, placeholder?: string) {
10
+ export function genEnumSelectBlock(enumeration: Enum, vModel?: string, size?: string, placeholder?: string, hiddenAll?: boolean) {
11
11
  if (config.scope === 'h5')
12
12
  return `<van-cascader ${vModel ? ` v-model="${vModel}"` : ''}${placeholder ? ` title="${placeholder}" placeholder="${placeholder}"` : ''}
13
13
  :data-source="ID_ENUM_LIST_${enumeration.id}"></van-cascader>`;
14
14
 
15
15
  return `<u-select clearable${vModel ? ` v-model="${vModel}"` : ''}${size ? ` size="${size}"` : ''}${placeholder ? ` placeholder="${placeholder}"` : ''}
16
16
  :data-source="ID_ENUM_LIST_${enumeration.id}">
17
- <u-select-item text="全部"></u-select-item>
17
+ ${hiddenAll ? '' : '<u-select-item text="全部"></u-select-item>'}
18
18
  </u-select>`;
19
19
  }
20
20
 
@@ -31,8 +31,19 @@ export function genGridViewCardTemplate(property: EntityProperty) {
31
31
  } else
32
32
  expression = getExpression(property, `scope.item.${lowerEntityName}.${property.name}`);
33
33
 
34
+ const getText = (property: EntityProperty) => {
35
+ if (property.typeKey === '#/basicTypes/Boolean') {
36
+ return `
37
+ <u-text v-if="${expression}" text="是"></u-text>
38
+ <u-text v-if="!${expression}" text="否"></u-text>
39
+ `;
40
+ } else {
41
+ return `<u-text :text="${expression}"></u-text>`;
42
+ }
43
+ };
44
+
34
45
  return `<u-linear-layout gap="small">
35
- <u-text text="${title}:"></u-text><u-text :text="${expression}"></u-text>
46
+ <u-text text="${title}:"></u-text>${getText(property)}
36
47
  </u-linear-layout>`;
37
48
  }
38
49
 
@@ -11,7 +11,7 @@ export function genListViewTemplate(property: EntityProperty, nameGroup: NameGro
11
11
 
12
12
  return `<u-list-view ref="listView" :data-source="${nameGroup.load}" data-schema="${nameGroup.structure}"
13
13
  text-field="${nameGroup.lowerEntity}.${property.name}"
14
- value-field="${nameGroup.lowerEntity}.id" pageable remote-paging>
14
+ value-field="${nameGroup.lowerEntity}.id" :pageable="true" :remote-paging="true">
15
15
  <template #item="scope">
16
16
  <u-linear-layout>
17
17
  <u-text :text="${expression}"></u-text>
@@ -25,7 +25,7 @@ export function genH5ListViewTemplate(property: EntityProperty, nameGroup: NameG
25
25
 
26
26
  return `<van-list-view ref="listView" :data-source="${nameGroup.load}" data-schema="${nameGroup.structure}"
27
27
  text-field="${nameGroup.lowerEntity}.${property.name}"
28
- value-field="${nameGroup.lowerEntity}.id" pageable="auto-more" remote-paging>
28
+ value-field="${nameGroup.lowerEntity}.id" pageable="auto-more" :remote-paging="true">
29
29
  <template #item="scope">
30
30
  <van-cell :value="${expression}" isLink></van-cell>
31
31
  </template>
@@ -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
+
@@ -8,14 +8,14 @@ import {
8
8
  export function genSelectTemplate(property: EntityProperty, nameGroup: NameGroup) {
9
9
  return `<u-select clearable placeholder="请选择" ref="select" :data-source="${nameGroup.load}" data-schema="${nameGroup.structure}"
10
10
  text-field="${nameGroup.lowerEntity}.${property.name}"
11
- value-field="${nameGroup.lowerEntity}.id" pageable remote-paging>
11
+ value-field="${nameGroup.lowerEntity}.id" :pageable="true" :remote-paging="true">
12
12
  </u-select>`;
13
13
  }
14
14
 
15
15
  export function genH5SelectTemplate(property: EntityProperty, nameGroup: NameGroup) {
16
16
  return `<van-cascader title="请选择" placeholder="请选择" ref="select" :data-source="${nameGroup.load}" data-schema="${nameGroup.structure}"
17
17
  text-field="${nameGroup.lowerEntity}.${property.name}"
18
- value-field="${nameGroup.lowerEntity}.id" pageable remote-paging>
18
+ value-field="${nameGroup.lowerEntity}.id" :pageable="true" :remote-paging="true">
19
19
  </van-cascader>`;
20
20
  }
21
21