@cicctencent/low-code-simulate-base 0.0.0-stage → 1.1.9-beta.5

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 (82) hide show
  1. package/README.md +1 -3
  2. package/__tests__/plugin.spec.ts +40 -0
  3. package/__tests__/utils.transform.test.ts +37 -0
  4. package/api-extractor.json +36 -0
  5. package/build/md.js +25 -0
  6. package/dist/VCComponent.d.ts +5 -0
  7. package/dist/VCComponent.js +91 -0
  8. package/dist/domain/BaseProjectDomain.d.ts +349 -0
  9. package/dist/domain/BaseProjectDomain.js +1305 -0
  10. package/dist/domain/ComponentManager.d.ts +78 -0
  11. package/dist/domain/ComponentManager.js +293 -0
  12. package/dist/domain/DataHistoryDomain.d.ts +53 -0
  13. package/dist/domain/DataHistoryDomain.js +110 -0
  14. package/dist/domain/PreviewDomain.d.ts +208 -0
  15. package/dist/domain/PreviewDomain.js +492 -0
  16. package/dist/domain/ProjectDomain.d.ts +209 -0
  17. package/dist/domain/ProjectDomain.js +138 -0
  18. package/dist/event/generateEventHandler.d.ts +21 -0
  19. package/dist/event/generateEventHandler.js +218 -0
  20. package/dist/event/generateEventSchema.d.ts +123 -0
  21. package/dist/event/generateEventSchema.js +342 -0
  22. package/dist/event/register.d.ts +56 -0
  23. package/dist/event/register.js +207 -0
  24. package/dist/index.d.ts +1330 -0
  25. package/dist/index.js +28 -0
  26. package/dist/plugin/onH5PageValidate.d.ts +7 -0
  27. package/dist/plugin/onH5PageValidate.js +178 -0
  28. package/dist/plugin/onPlaceholder.d.ts +6 -0
  29. package/dist/plugin/onPlaceholder.js +68 -0
  30. package/dist/plugin/subscribeInsertUploadList.d.ts +6 -0
  31. package/dist/plugin/subscribeInsertUploadList.js +49 -0
  32. package/dist/plugin/subscribeSetTitle.d.ts +6 -0
  33. package/dist/plugin/subscribeSetTitle.js +16 -0
  34. package/dist/plugin/subscribeTransformComponentMeta.d.ts +14 -0
  35. package/dist/plugin/subscribeTransformComponentMeta.js +31 -0
  36. package/dist/plugin/subscribeValidateField.d.ts +7 -0
  37. package/dist/plugin/subscribeValidateField.js +57 -0
  38. package/dist/plugin/subscribeValidateUpload.d.ts +6 -0
  39. package/dist/plugin/subscribeValidateUpload.js +92 -0
  40. package/dist/utils/base64.d.ts +14 -0
  41. package/dist/utils/base64.js +14 -0
  42. package/dist/utils/buildInVariable.d.ts +61 -0
  43. package/dist/utils/buildInVariable.js +216 -0
  44. package/dist/utils/dom.d.ts +14 -0
  45. package/dist/utils/dom.js +19 -0
  46. package/dist/utils/index.d.ts +55 -0
  47. package/dist/utils/index.js +201 -0
  48. package/dist/utils/transform.d.ts +39 -0
  49. package/dist/utils/transform.js +191 -0
  50. package/dist/utils/validate.d.ts +7 -0
  51. package/dist/utils/validate.js +18 -0
  52. package/docs/.api/low-code-simulate-base.api.json +8450 -0
  53. package/jest.config.ts +20 -0
  54. package/package.json +44 -4
  55. package/src/VCComponent.ts +118 -0
  56. package/src/domain/BaseProjectDomain.ts +1341 -0
  57. package/src/domain/ComponentManager.ts +241 -0
  58. package/src/domain/DataHistoryDomain.ts +102 -0
  59. package/src/domain/PreviewDomain.ts +424 -0
  60. package/src/domain/ProjectDomain.ts +244 -0
  61. package/src/event/generateEventHandler.ts +162 -0
  62. package/src/event/generateEventSchema.ts +371 -0
  63. package/src/event/register.ts +181 -0
  64. package/src/index.ts +61 -0
  65. package/src/plugin/onH5PageValidate.ts +179 -0
  66. package/src/plugin/onPlaceholder.ts +71 -0
  67. package/src/plugin/subscribeInsertUploadList.ts +51 -0
  68. package/src/plugin/subscribeSetTitle.ts +18 -0
  69. package/src/plugin/subscribeTransformComponentMeta.ts +38 -0
  70. package/src/plugin/subscribeValidateField.ts +65 -0
  71. package/src/plugin/subscribeValidateUpload.ts +116 -0
  72. package/src/utils/base64.ts +17 -0
  73. package/src/utils/buildInVariable.ts +157 -0
  74. package/src/utils/dom.ts +30 -0
  75. package/src/utils/index.ts +194 -0
  76. package/src/utils/transform.ts +171 -0
  77. package/src/utils/validate.ts +19 -0
  78. package/temp/low-code-simulate-base.api.md +597 -0
  79. package/test/plugin.test.ts +4 -0
  80. package/tsconfig.build.json +9 -0
  81. package/tsconfig.json +9 -0
  82. package/tsconfig.test.json +14 -0
@@ -0,0 +1,1305 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ var __assign = (this && this.__assign) || function () {
17
+ __assign = Object.assign || function(t) {
18
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
19
+ s = arguments[i];
20
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
21
+ t[p] = s[p];
22
+ }
23
+ return t;
24
+ };
25
+ return __assign.apply(this, arguments);
26
+ };
27
+ var __read = (this && this.__read) || function (o, n) {
28
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
29
+ if (!m) return o;
30
+ var i = m.call(o), r, ar = [], e;
31
+ try {
32
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
33
+ }
34
+ catch (error) { e = { error: error }; }
35
+ finally {
36
+ try {
37
+ if (r && !r.done && (m = i["return"])) m.call(i);
38
+ }
39
+ finally { if (e) throw e.error; }
40
+ }
41
+ return ar;
42
+ };
43
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
44
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
45
+ if (ar || !(i in from)) {
46
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
47
+ ar[i] = from[i];
48
+ }
49
+ }
50
+ return to.concat(ar || Array.prototype.slice.call(from));
51
+ };
52
+ import { getImageUrls, getSchemaConfigByValue } from '../utils';
53
+ import { getObjectPath } from '../utils/transform';
54
+ import { ComponentType } from '@jt/low-code-core';
55
+ import { navTreeKey, componentTreeKey } from '../domain/ProjectDomain';
56
+ import { cloneDeep, get, isEqual, set, toPlainObject, merge, isEmpty, log, } from '@jt/ark-util';
57
+ import { decodeContent } from 'jm-jsruntime';
58
+ import { getSchemaObjectAttribute } from '../utils';
59
+ import { tipIcon } from '../utils/base64';
60
+ import { transform } from '../utils/transform';
61
+ import ComponentManager from './ComponentManager';
62
+ var logTag = '[low-code-preview BaseProjectDomain]';
63
+ var logInfo = log(logTag);
64
+ import ProjectDomain from '../domain/ProjectDomain';
65
+ var statusOptions = {
66
+ 0: '编辑中',
67
+ 1: '已发布',
68
+ 2: '已下线',
69
+ 3: '审核中',
70
+ 4: '发布失败',
71
+ };
72
+ /**
73
+ * @public
74
+ */
75
+ var BaseProjectDomain = /** @class */ (function (_super) {
76
+ __extends(BaseProjectDomain, _super);
77
+ /**
78
+ * @public
79
+ */
80
+ function BaseProjectDomain(state) {
81
+ var _this = _super.call(this) || this;
82
+ /**
83
+ * @public
84
+ */
85
+ _this.staticPath = 'components.0.list';
86
+ /**
87
+ * @public
88
+ */
89
+ _this.currentPageIndex = 0; // 当前编辑页面索引
90
+ /**
91
+ * @public
92
+ */
93
+ _this.currentComponentPath = ''; // 当前编辑组件索引路径
94
+ // generateComponentPath(id: number): string {
95
+ // const index = this.components.findIndex(item=>item.componentId === id);
96
+ // const paths = index !== -1 ? `0.components.0.list.${index}` : ''
97
+ // return paths;
98
+ // }
99
+ /**
100
+ * @public
101
+ */
102
+ _this.Id2ComponentPathMap = {};
103
+ _this.state = state;
104
+ // this.basePath = state.basePath || this.basePath;
105
+ _this.cManager = ComponentManager.getInstance(state.componentConfigs);
106
+ _this.setProject(state.project);
107
+ return _this;
108
+ }
109
+ Object.defineProperty(BaseProjectDomain.prototype, "config", {
110
+ /**
111
+ * @public
112
+ * 获取配置
113
+ */
114
+ get: function () {
115
+ var _a = this, navTreeData = _a.navTreeData, componentTreeData = _a.componentTreeData, schemaData = _a.schemaData, functionData = _a.functionData;
116
+ return {
117
+ navTreeData: {
118
+ key: navTreeKey,
119
+ value: navTreeData,
120
+ },
121
+ componentTreeData: {
122
+ key: componentTreeKey,
123
+ value: componentTreeData,
124
+ },
125
+ functionData: functionData,
126
+ schemaData: schemaData,
127
+ };
128
+ },
129
+ enumerable: false,
130
+ configurable: true
131
+ });
132
+ Object.defineProperty(BaseProjectDomain.prototype, "basePath", {
133
+ /**
134
+ * @public
135
+ */
136
+ get: function () {
137
+ return "".concat(this.currentPageIndex, ".").concat(this.staticPath);
138
+ },
139
+ enumerable: false,
140
+ configurable: true
141
+ });
142
+ /**
143
+ * 根据id在pages中找到组件 生成componentPath
144
+ * @param id - 组件ID
145
+ * @returns 组件路径
146
+ * @example
147
+ * const pages = [{components:[{list:[{componentId:1}]}]}];
148
+ * const componentId = 1;
149
+ * generateComponentPath(componentId)
150
+ * // => 0.components.0.list.0
151
+ */
152
+ /**
153
+ * @public
154
+ */
155
+ BaseProjectDomain.prototype.generateComponentPath = function (id, pageIndex) {
156
+ var componentPath = this.Id2ComponentPathMap[id];
157
+ if (componentPath) {
158
+ // 由于组件位置可能变化,所以这里要确认一下
159
+ var component = this.pathToData(componentPath);
160
+ if (component && component.componentId === id) {
161
+ return componentPath;
162
+ }
163
+ }
164
+ var paths = pageIndex !== undefined ? [pageIndex, this.staticPath] : [this.basePath];
165
+ var findComponent = function (list) {
166
+ for (var i in list) {
167
+ var item = list[i];
168
+ if (item.componentId === id) {
169
+ paths.push(i);
170
+ return true;
171
+ }
172
+ else if (item.children && item.children.length) {
173
+ paths.push(i, 'children');
174
+ if (findComponent(item.children)) {
175
+ return true;
176
+ }
177
+ // 未找到 删除最后两个
178
+ paths.splice(-2, 2);
179
+ }
180
+ // else if (item.slot) {
181
+ // const keys = Object.keys(item.slot);
182
+ // if(keys.length){
183
+ // for(let key of keys){
184
+ // if (item.slot[key]?.componentId === id) {
185
+ // paths.push(i, 'slot', key);
186
+ // return true;
187
+ // }
188
+ // }
189
+ // }
190
+ // }
191
+ }
192
+ };
193
+ if (findComponent(this.components)) {
194
+ componentPath = paths.join('.');
195
+ this.Id2ComponentPathMap[id] = componentPath;
196
+ return componentPath;
197
+ }
198
+ return '';
199
+ };
200
+ /**
201
+ * @public
202
+ * 获取父组件数据
203
+ * @param childPath - 子组件路径
204
+ * @returns 父组件数据
205
+ */
206
+ BaseProjectDomain.prototype.getParent = function (childPath) {
207
+ childPath = childPath || this.currentComponentPath;
208
+ if (childPath) {
209
+ var parentComponentPath = this.getIndexByKey(childPath).parentComponentPath;
210
+ if (parentComponentPath) {
211
+ return this.pathToData(parentComponentPath);
212
+ }
213
+ }
214
+ return null;
215
+ };
216
+ /**
217
+ * @public
218
+ * 更新数据
219
+ * @param oldProject - 旧Project
220
+ * @returns true 新增记录 false 更新记录
221
+ */
222
+ BaseProjectDomain.prototype.needUpdateHistory = function (oldProject) {
223
+ var _a, _b;
224
+ var projectData = oldProject.projectData;
225
+ var currentComponentPath = oldProject.currentComponentPath;
226
+ if (!projectData || !currentComponentPath) {
227
+ return false;
228
+ }
229
+ if (!currentComponentPath.includes('.')) {
230
+ // 如果,当前导航在页面上
231
+ // 新增页面兼容处理,页面配置formData初始为空,新增页面会设置默认值
232
+ var pageMeta = (_a = projectData === null || projectData === void 0 ? void 0 : projectData.pages[0]) === null || _a === void 0 ? void 0 : _a.pageMeta;
233
+ if (isEmpty(pageMeta)) {
234
+ Object.assign(pageMeta, this.pageMeta);
235
+ return true;
236
+ }
237
+ }
238
+ if ((_b = this === null || this === void 0 ? void 0 : this.currentComponent) === null || _b === void 0 ? void 0 : _b.immobile) {
239
+ var parentComponentPath = this.getIndexByKey(this.currentComponentPath).parentComponentPath;
240
+ currentComponentPath = parentComponentPath;
241
+ }
242
+ var oldComponentData = this.pathToData(currentComponentPath, projectData.pages);
243
+ if (!(oldComponentData)) {
244
+ return false;
245
+ }
246
+ var newComponentData = this.pathToData(currentComponentPath);
247
+ // 点击新增组件先click新增历史记录,后form表单更新set新增历史记录
248
+ // 如果新组件的formData路径比旧的多于1个(1个可能是修改了值)则表示点击新增组件还没有到表单更新默认值
249
+ // 同时currentComponent有值,表示是表单更新设置值
250
+ if (isEqual(oldComponentData, newComponentData) || getObjectPath(oldComponentData.formData).length < getObjectPath(newComponentData === null || newComponentData === void 0 ? void 0 : newComponentData.formData).length - 1) {
251
+ Object.assign(oldComponentData, newComponentData);
252
+ return true;
253
+ }
254
+ return false;
255
+ };
256
+ /**
257
+ * @public
258
+ * 根据组件路径获取组件位置、组件所在列表路径、组件父组件路径以及组件数据
259
+ * @param path - 组件路径
260
+ * @returns
261
+ * @example
262
+ */
263
+ BaseProjectDomain.prototype.getIndexByKey = function (path) {
264
+ var paths = path ? path.split('.') : [];
265
+ var hasContainer = path.includes('children');
266
+ return {
267
+ index: path ? +paths.slice(-1) : -1,
268
+ pageIndex: path ? +paths.slice(0, 1) : -1,
269
+ componentListPath: hasContainer
270
+ ? paths.slice(0, -1).join('.')
271
+ : this.basePath,
272
+ parentComponentPath: hasContainer ? paths.slice(0, -2).join('.') : null,
273
+ component: this.pathToData(path),
274
+ };
275
+ };
276
+ /**
277
+ * @public
278
+ * 判断是否符合插入容器组件的条件
279
+ * @param child - 子容器组件配置
280
+ * @param container - 容器组件数据
281
+ * @returns
282
+ * @example
283
+ */
284
+ BaseProjectDomain.prototype.canInsertContainer = function (child, container) {
285
+ var _a, _b;
286
+ var insertConfig = container.insertConfig || this.cManager.get(container.name).insertConfig;
287
+ var errorMessage = '';
288
+ var context = { componentName: child.title };
289
+ if (!(insertConfig === null || insertConfig === void 0 ? void 0 : insertConfig.allowList)) {
290
+ return true;
291
+ }
292
+ // 判断该组件是否在允许拖入容器的组件范围
293
+ if (!((_a = insertConfig === null || insertConfig === void 0 ? void 0 : insertConfig.allowList) === null || _a === void 0 ? void 0 : _a.includes(child.name))) {
294
+ errorMessage = decodeContent(insertConfig === null || insertConfig === void 0 ? void 0 : insertConfig.allowErrorMessage, {
295
+ params: context,
296
+ });
297
+ }
298
+ // 判断该组件是否在单独占据容器的组件范围
299
+ if (insertConfig === null || insertConfig === void 0 ? void 0 : insertConfig.aloneList.includes(child.name)) {
300
+ // 判断容器内是否存在组件
301
+ if ((_b = container === null || container === void 0 ? void 0 : container.children) === null || _b === void 0 ? void 0 : _b.length) {
302
+ errorMessage = decodeContent(insertConfig.aloneErrorMessage, {
303
+ params: context,
304
+ });
305
+ }
306
+ }
307
+ else {
308
+ // 判断容器内是否存在单独占据容器的组件
309
+ var aloneComponent = container.children.find(function (c) {
310
+ return insertConfig === null || insertConfig === void 0 ? void 0 : insertConfig.aloneList.includes(c.name);
311
+ });
312
+ if (aloneComponent) {
313
+ errorMessage = decodeContent(insertConfig === null || insertConfig === void 0 ? void 0 : insertConfig.aloneErrorMessage, {
314
+ params: { componentName: aloneComponent.title },
315
+ });
316
+ }
317
+ }
318
+ if (errorMessage) {
319
+ this.publishEditor('action', toPlainObject({
320
+ key: 'error',
321
+ value: errorMessage,
322
+ }));
323
+ return false;
324
+ }
325
+ return true;
326
+ };
327
+ /**
328
+ * @public
329
+ * @param name - 组件名
330
+ * @param data - 数据
331
+ */
332
+ BaseProjectDomain.prototype.action = function (name, data) {
333
+ try {
334
+ console.log('action:', name, data);
335
+ if ('componentListSplice' === name) {
336
+ this.componentListSplice(data.insertIndex, data.deleteNum,
337
+ // 不需要this.cManager.copy, 管理端复制的时候已经设置
338
+ data.component, data.componentListPath);
339
+ // 因为maxId不一样了,需要重新init
340
+ this.cManager.initComponens(this.components);
341
+ }
342
+ }
343
+ catch (error) {
344
+ console.log('action error:', error);
345
+ }
346
+ };
347
+ Object.defineProperty(BaseProjectDomain.prototype, "title", {
348
+ /**
349
+ * @public
350
+ */
351
+ get: function () {
352
+ var _a = this.state.project || {}, categoryName = _a.categoryName, projectName = _a.projectName;
353
+ return (categoryName ? "".concat(categoryName, "/") : '') + projectName || '';
354
+ },
355
+ enumerable: false,
356
+ configurable: true
357
+ });
358
+ Object.defineProperty(BaseProjectDomain.prototype, "isNoLogin", {
359
+ /**
360
+ * @public
361
+ */
362
+ get: function () {
363
+ var _a, _b;
364
+ return (_b = (_a = this.state.project) === null || _a === void 0 ? void 0 : _a.isNoLogin) !== null && _b !== void 0 ? _b : false;
365
+ },
366
+ enumerable: false,
367
+ configurable: true
368
+ });
369
+ Object.defineProperty(BaseProjectDomain.prototype, "pages", {
370
+ /**
371
+ * @public
372
+ */
373
+ get: function () {
374
+ var _a, _b;
375
+ return (_b = (_a = this.state.project) === null || _a === void 0 ? void 0 : _a.pages) !== null && _b !== void 0 ? _b : [];
376
+ },
377
+ enumerable: false,
378
+ configurable: true
379
+ });
380
+ Object.defineProperty(BaseProjectDomain.prototype, "components", {
381
+ /**
382
+ * @public
383
+ */
384
+ get: function () {
385
+ var _a, _b, _c, _d, _e;
386
+ return (_e = (_d = (_c = (_b = (_a = this.pages) === null || _a === void 0 ? void 0 : _a[this.currentPageIndex]) === null || _b === void 0 ? void 0 : _b.components) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.list) !== null && _e !== void 0 ? _e : [];
387
+ },
388
+ enumerable: false,
389
+ configurable: true
390
+ });
391
+ Object.defineProperty(BaseProjectDomain.prototype, "componentsWithConfig", {
392
+ /**
393
+ * @public
394
+ * 含包含config的数据
395
+ */
396
+ get: function () {
397
+ var _this = this;
398
+ var joinConfig = function (c) {
399
+ var _a;
400
+ var comp = cloneDeep(__assign(__assign({}, _this.cManager.get(c.name)), c));
401
+ if ((_a = comp.children) === null || _a === void 0 ? void 0 : _a.length) {
402
+ comp.children = comp.children.map(joinConfig);
403
+ }
404
+ return comp;
405
+ };
406
+ return this.components.map(joinConfig);
407
+ },
408
+ enumerable: false,
409
+ configurable: true
410
+ });
411
+ Object.defineProperty(BaseProjectDomain.prototype, "pageMeta", {
412
+ /**
413
+ * @public
414
+ */
415
+ get: function () {
416
+ var _a, _b, _c, _d;
417
+ return (_d = (_c = (_b = (_a = this.state.project) === null || _a === void 0 ? void 0 : _a.pages) === null || _b === void 0 ? void 0 : _b[this.currentPageIndex]) === null || _c === void 0 ? void 0 : _c.pageMeta) !== null && _d !== void 0 ? _d : {};
418
+ },
419
+ enumerable: false,
420
+ configurable: true
421
+ });
422
+ Object.defineProperty(BaseProjectDomain.prototype, "currentComponent", {
423
+ //ComponentItem
424
+ /**
425
+ * @public
426
+ */
427
+ get: function () {
428
+ return this.currentComponentPath
429
+ ? this.pathToData(this.currentComponentPath)
430
+ : null;
431
+ },
432
+ enumerable: false,
433
+ configurable: true
434
+ });
435
+ Object.defineProperty(BaseProjectDomain.prototype, "navTreeData", {
436
+ /**
437
+ * @public
438
+ * 获取导航树数据
439
+ */
440
+ get: function () {
441
+ var _this = this;
442
+ var _a;
443
+ var navTreeData = [];
444
+ // 根据path确定激活的组件
445
+ var activatedComponentId = (_a = this.currentComponent) === null || _a === void 0 ? void 0 : _a.componentId;
446
+ var buildOptions = function (list) {
447
+ var treeData = [];
448
+ list.forEach(function (c, index) {
449
+ var name = c.name;
450
+ var schema = _this.cManager.get(name);
451
+ var path = _this.generateComponentPath(c.componentId);
452
+ var title = c.title || schema.title;
453
+ if (schema.immobile) {
454
+ title = schema.title + (index + 1);
455
+ }
456
+ var tree = {
457
+ title: title,
458
+ // path是对应组件数据的路径 可以用dot-object包映射到对应的组件数据
459
+ key: {
460
+ module: 'navTree',
461
+ action: 'activate',
462
+ component: name,
463
+ path: path,
464
+ },
465
+ type: c.type,
466
+ icon: c.icon || schema.icon,
467
+ immobile: schema.immobile,
468
+ // 当前激活的组件activity为true
469
+ activity: c.componentId === activatedComponentId ? true : false,
470
+ componentId: c.componentId, // 导航树需要显示组件ID
471
+ };
472
+ if (!schema.immobile) {
473
+ tree.rightIcon = {
474
+ icon: 'Delete',
475
+ key: {
476
+ module: 'menu',
477
+ action: 'componentDeleteWithConfirm',
478
+ component: name,
479
+ path: path,
480
+ },
481
+ };
482
+ }
483
+ // 如果组件数据有children
484
+ if (c.children && c.children.length) {
485
+ tree.children = buildOptions(c.children);
486
+ }
487
+ treeData.push(tree);
488
+ });
489
+ return treeData;
490
+ };
491
+ // 没有添加组件时 默认返回空树 有组件时生成组件树
492
+ if (this.state.project.pages) {
493
+ this.state.project.pages.forEach(function (page, idx) {
494
+ var path = idx + '';
495
+ var tree = {
496
+ title: page.title || '页面内容',
497
+ key: { module: 'navTree', action: 'activate', path: path },
498
+ icon: '', // TODO:
499
+ activity: _this.currentComponentPath === path && _this.currentPageIndex === idx
500
+ ? true
501
+ : false,
502
+ };
503
+ tree.children = buildOptions(page.components[0].list);
504
+ navTreeData.push(tree);
505
+ });
506
+ }
507
+ return navTreeData;
508
+ },
509
+ enumerable: false,
510
+ configurable: true
511
+ });
512
+ Object.defineProperty(BaseProjectDomain.prototype, "schemaData", {
513
+ /**
514
+ * @public
515
+ * 获取当前配置表单数据
516
+ */
517
+ get: function () {
518
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
519
+ if (!this.state.project.pages) {
520
+ // 未初始化
521
+ return {};
522
+ }
523
+ // 若为免登录 过滤事件和中间件
524
+ var filterEvents = function (eventConfig) {
525
+ Object.keys(eventConfig !== null && eventConfig !== void 0 ? eventConfig : {}).forEach(function (key) {
526
+ // 过滤掉isNoLogin为false的情况 如果事件和中间件没增加免登录配置 则isNoLogin默认为false!!
527
+ try {
528
+ if (key === 'handler' && eventConfig[key]) {
529
+ eventConfig[key].properties.name.enum = eventConfig[key].properties.name.enum.filter(function (item) { return item.isNoLogin; });
530
+ }
531
+ else if (key === 'middlewares' && eventConfig[key]) {
532
+ eventConfig[key].items.properties.name.enum = eventConfig[key].items.properties.name.enum.filter(function (it) { return it.isNoLogin; });
533
+ }
534
+ }
535
+ catch (error) {
536
+ console.log('schemaData', error);
537
+ }
538
+ });
539
+ };
540
+ // 没有选中组件或选中组件不存在 默认返回页面表单数据
541
+ if (!((_a = this.pathToData(this.currentComponentPath)) === null || _a === void 0 ? void 0 : _a.componentId)) {
542
+ var schemaConfig_1 = cloneDeep(this.state.pageConfig);
543
+ if (this.isNoLogin) {
544
+ var eventConfig = getSchemaObjectAttribute(schemaConfig_1, 'event');
545
+ if (eventConfig)
546
+ filterEvents(eventConfig === null || eventConfig === void 0 ? void 0 : eventConfig.properties);
547
+ }
548
+ return {
549
+ key: {
550
+ module: 'schema',
551
+ action: 'setPathDataWithValidate',
552
+ path: this.currentPageIndex + '.pageMeta',
553
+ },
554
+ title: '页面信息',
555
+ schema: schemaConfig_1,
556
+ data: cloneDeep(this.pageMeta),
557
+ };
558
+ }
559
+ // 选中组件 返回对应组件表单数据 -> 根据path找到组件
560
+ var component = this.currentComponent;
561
+ //为自创建组件,则用父组件的配置项
562
+ if (component.immobile) {
563
+ var parentComponent = this.getParent();
564
+ if (parentComponent) {
565
+ component = parentComponent;
566
+ }
567
+ }
568
+ var componentSchema = this.cManager.get(component === null || component === void 0 ? void 0 : component.name);
569
+ if (!componentSchema)
570
+ return {};
571
+ var schemaConfig = cloneDeep(componentSchema.config);
572
+ if (this.isNoLogin) {
573
+ var eventConfig = getSchemaObjectAttribute(schemaConfig, 'event');
574
+ if (eventConfig) {
575
+ filterEvents((_d = (_c = (_b = eventConfig === null || eventConfig === void 0 ? void 0 : eventConfig.properties) === null || _b === void 0 ? void 0 : _b.list) === null || _c === void 0 ? void 0 : _c.items) === null || _d === void 0 ? void 0 : _d.properties);
576
+ }
577
+ // 热区
578
+ var hotAreaConfig = getSchemaObjectAttribute(schemaConfig, 'hotArea');
579
+ if (hotAreaConfig) {
580
+ filterEvents((_j = (_h = (_g = (_f = (_e = hotAreaConfig === null || hotAreaConfig === void 0 ? void 0 : hotAreaConfig['ui:options']) === null || _e === void 0 ? void 0 : _e.event) === null || _f === void 0 ? void 0 : _f.properties) === null || _g === void 0 ? void 0 : _g.list) === null || _h === void 0 ? void 0 : _h.items) === null || _j === void 0 ? void 0 : _j.properties);
581
+ }
582
+ // 如果当前非免登录组件被隐藏了 右侧区域的配置为空
583
+ // if (!component.isNoLogin) return {};
584
+ }
585
+ // 替换配置中的占位词
586
+ schemaConfig = transform(schemaConfig, this.getFlagWordMap());
587
+ return {
588
+ key: {
589
+ module: 'schema',
590
+ action: 'setPathDataWithValidate',
591
+ component: component.name,
592
+ path: this.generateComponentPath(component.componentId) + '.formData',
593
+ },
594
+ title: '基础配置',
595
+ schema: schemaConfig,
596
+ data: cloneDeep(component === null || component === void 0 ? void 0 : component.formData),
597
+ componentId: component === null || component === void 0 ? void 0 : component.componentId,
598
+ };
599
+ },
600
+ enumerable: false,
601
+ configurable: true
602
+ });
603
+ Object.defineProperty(BaseProjectDomain.prototype, "componentTreeData", {
604
+ /**
605
+ * @public
606
+ * 获取组件树数据
607
+ */
608
+ get: function () {
609
+ var _this = this;
610
+ var componentTree = [];
611
+ var buildTree = function (groupList, trees) {
612
+ groupList.forEach(function (v, i) {
613
+ trees.push({
614
+ title: v.name,
615
+ list: [],
616
+ });
617
+ if (v.children) {
618
+ buildTree(v.children, trees[i].list);
619
+ }
620
+ else {
621
+ trees[i].list = __spreadArray([], __read(_this.state.componentConfigs
622
+ .filter(function (c) {
623
+ return c.group === v.name &&
624
+ (!_this.isNoLogin || (_this.isNoLogin && c.isNoLogin)) &&
625
+ !c.invalid;
626
+ })
627
+ .map(function (c) { return ({
628
+ title: c.title,
629
+ icon: c.icon,
630
+ name: c.name,
631
+ type: c.type,
632
+ isNoLogin: c.isNoLogin,
633
+ guideConfig: (c === null || c === void 0 ? void 0 : c.guideConfig) || {},
634
+ key: {
635
+ module: 'componentTree',
636
+ action: 'componentInsert',
637
+ component: c.name,
638
+ },
639
+ }); })), false);
640
+ }
641
+ });
642
+ };
643
+ buildTree(this.state.groupConfig, componentTree);
644
+ return componentTree;
645
+ },
646
+ enumerable: false,
647
+ configurable: true
648
+ });
649
+ Object.defineProperty(BaseProjectDomain.prototype, "menuData", {
650
+ /**
651
+ * @public
652
+ * 获取右键菜单数据 没有考虑有容器组件的情况
653
+ */
654
+ get: function () {
655
+ var _this = this;
656
+ if (!this.currentComponentPath) {
657
+ return [];
658
+ }
659
+ var component = this.currentComponent;
660
+ //为自创建组件,不展示右键菜单
661
+ if (component.immobile) {
662
+ return [];
663
+ }
664
+ var key = function (action) { return ({
665
+ module: 'menu',
666
+ action: action,
667
+ component: component === null || component === void 0 ? void 0 : component.name,
668
+ path: _this.currentComponentPath,
669
+ }); };
670
+ var menus = [
671
+ {
672
+ key: key('setPathData'),
673
+ title: '重命名',
674
+ color: '#666666',
675
+ },
676
+ {
677
+ key: key('componentCopy'),
678
+ title: '复制组件',
679
+ color: '#666666',
680
+ },
681
+ {
682
+ key: key('componentDeleteWithConfirm'),
683
+ title: '删除组件',
684
+ color: '#c16e6c',
685
+ },
686
+ ];
687
+ var _a = this.getIndexByKey(this.currentComponentPath), index = _a.index, componentListPath = _a.componentListPath;
688
+ var length = get(this.pages, componentListPath).length;
689
+ if (length > 1) {
690
+ if (index != 0) {
691
+ menus.push({
692
+ key: key('componentMoveUp'),
693
+ title: '组件上移',
694
+ color: '#666666',
695
+ });
696
+ }
697
+ if (index != length - 1) {
698
+ menus.push({
699
+ key: key('componentMoveDown'),
700
+ title: '组件下移',
701
+ color: '#666666',
702
+ });
703
+ }
704
+ }
705
+ // 单图片组件添加一个上传图片的icon菜单放在第一位
706
+ if (component.name === 'ComponentImage') {
707
+ menus.unshift({
708
+ key: key('componentImageOpen'),
709
+ title: '上传图片',
710
+ color: '#666666',
711
+ });
712
+ }
713
+ return menus;
714
+ },
715
+ enumerable: false,
716
+ configurable: true
717
+ });
718
+ /**
719
+ * @public
720
+ * 生成占位词对应的真实数据
721
+ * @param index - 校验时需要传入的组件位置
722
+ * @returns
723
+ */
724
+ // 所有组件的选择器选项(不包括当前组件)
725
+ BaseProjectDomain.prototype.getComponentSelectors = function (index) {
726
+ var _this = this;
727
+ return this.components
728
+ .filter(function (cc, i) {
729
+ var _a, _b;
730
+ return (index !== undefined
731
+ ? index !== i
732
+ : cc.componentId !== ((_a = _this.currentComponent) === null || _a === void 0 ? void 0 : _a.componentId)) ||
733
+ !((_b = _this.cManager.get(cc.name)) === null || _b === void 0 ? void 0 : _b.unlinkable);
734
+ })
735
+ .map(function (c) { return ({ label: c.title, value: "".concat(c.name, "-").concat(c.componentId) }); });
736
+ };
737
+ /**
738
+ * @public
739
+ * 当前组件之后的选择器选项(不包括当前组件)
740
+ * @param index - 下标
741
+ * @returns
742
+ */
743
+ BaseProjectDomain.prototype.getAfterComponentSelectors = function (index) {
744
+ var _this = this;
745
+ var currentIndex = index !== undefined
746
+ ? index
747
+ : this.components.findIndex(function (c) { var _a; return c.componentId === ((_a = _this.currentComponent) === null || _a === void 0 ? void 0 : _a.componentId); });
748
+ // 若未找到当前组件或者当前组件是最后一个组件 则返回空数组
749
+ if (currentIndex === -1 || currentIndex === this.components.length - 1)
750
+ return [];
751
+ var availableComponents = this.components.slice(currentIndex + 1);
752
+ return availableComponents
753
+ .filter(function (cc) { var _a; return !((_a = _this.cManager.get(cc.name)) === null || _a === void 0 ? void 0 : _a.unlinkable); })
754
+ .map(function (c) { return ({ label: c.title, value: "".concat(c.name, "-").concat(c.componentId) }); });
755
+ };
756
+ /**
757
+ * @public
758
+ * 占位词映射表
759
+ * @param index - 下标
760
+ * @returns
761
+ */
762
+ BaseProjectDomain.prototype.getFlagWordMap = function (index) {
763
+ var _a, _b, _c, _d;
764
+ return {
765
+ $componentSelectors: this.getComponentSelectors(index),
766
+ $afterComponentSelectors: this.getAfterComponentSelectors(index),
767
+ $componentId: ((_a = this.currentComponent) === null || _a === void 0 ? void 0 : _a.componentId) || ((_b = this.components[index]) === null || _b === void 0 ? void 0 : _b.componentId),
768
+ $componentName: ((_c = this.currentComponent) === null || _c === void 0 ? void 0 : _c.name) || ((_d = this.components[index]) === null || _d === void 0 ? void 0 : _d.name),
769
+ $components: this.components
770
+ };
771
+ };
772
+ /**
773
+ * @public
774
+ * 激活导航树
775
+ * @param key - 组件LowCodeKey
776
+ */
777
+ BaseProjectDomain.prototype.activate = function (key) {
778
+ // 设置索引
779
+ this.currentComponentPath = key.path;
780
+ };
781
+ /**
782
+ * @public
783
+ * 生成编辑器删除操作二次确认弹出框所需的数据
784
+ * @param key - 组件LowCodeKey
785
+ * @returns
786
+ */
787
+ BaseProjectDomain.prototype.componentDeleteWithConfirm = function (key) {
788
+ if (!key.path) {
789
+ return;
790
+ }
791
+ var component = this.pathToData(key.path);
792
+ var value = {
793
+ type: 'warning',
794
+ title: '提示',
795
+ schema: {
796
+ type: 'object',
797
+ properties: {
798
+ text: {
799
+ type: 'string',
800
+ 'x-decorator': 'FormItem',
801
+ 'x-component': 'PreviewText.Input',
802
+ default: "\u662F\u5426\u5220\u9664\u7EC4\u4EF6: ".concat(component.title),
803
+ },
804
+ },
805
+ },
806
+ confirmButton: {
807
+ text: '确认',
808
+ key: {
809
+ module: 'menu',
810
+ component: component.name,
811
+ action: 'componentDelete',
812
+ path: key.path,
813
+ },
814
+ },
815
+ cancelButton: {
816
+ text: '取消',
817
+ },
818
+ };
819
+ this.publishEditor('action', toPlainObject({ key: 'confirm', value: value }));
820
+ };
821
+ /**
822
+ * @public
823
+ * 组件列表元素处理
824
+ * @param start - 组件插入的位置
825
+ * @param deleteNum - 删除的组件个数
826
+ * @param item - 组件数据
827
+ * @param componentListPath - 组件所在列表的路径
828
+ * @returns
829
+ * @example
830
+ */
831
+ BaseProjectDomain.prototype.componentListSplice = function (start, deleteNum, item, componentListPath) {
832
+ var components = componentListPath
833
+ ? get(this.pages, componentListPath)
834
+ : this.components;
835
+ // 插入操作
836
+ if (deleteNum === 0 && componentListPath && /\.children$/.test(componentListPath)) {
837
+ // 容器组件
838
+ if (!this.canInsertContainer(item, this.pathToData(componentListPath.replace(/\.children$/, ''))))
839
+ return;
840
+ }
841
+ var deleteList = [];
842
+ if (item) {
843
+ deleteList = components.splice(start, deleteNum, this.cManager.buildItemData(item));
844
+ this.currentComponentPath = componentListPath
845
+ ? "".concat(componentListPath, ".").concat(start)
846
+ : "".concat(this.basePath, ".").concat(start);
847
+ }
848
+ else {
849
+ deleteList = components.splice(start, deleteNum);
850
+ }
851
+ return deleteList;
852
+ };
853
+ /**
854
+ * @public
855
+ * 移动组件到某个位置
856
+ * @param originPath - 原路径
857
+ * @param newPath - 目标路径
858
+ * @example
859
+ * moveTo('0.components.0.list.0', '0.components.0.list.1')
860
+ **/
861
+ BaseProjectDomain.prototype.moveTo = function (originPath, newPath) {
862
+ var _a;
863
+ console.log('moveTo', originPath, newPath);
864
+ var originPathMap = this.getIndexByKey(originPath);
865
+ var newPathhMap = this.getIndexByKey(newPath);
866
+ if (newPathhMap.component && ((_a = newPathhMap.component) === null || _a === void 0 ? void 0 : _a.immobile)) {
867
+ // newPath = '0.components.0.list.0.children.0' 的场景
868
+ // 避免插在tab容器中间
869
+ if (newPathhMap.component.type === ComponentType.Container) {
870
+ newPathhMap = this.getIndexByKey(newPath + '.children.0');
871
+ }
872
+ else {
873
+ newPathhMap = this.getIndexByKey(newPath.replace('\.children.\d+$', ''));
874
+ }
875
+ }
876
+ var targetParentPath = newPathhMap.parentComponentPath;
877
+ var component = originPathMap.component;
878
+ var container;
879
+ console.log('newPath', newPath, targetParentPath);
880
+ if (targetParentPath) {
881
+ container = this.getIndexByKey(targetParentPath).component;
882
+ if (container && !this.canInsertContainer(component, container)) {
883
+ this.publishEditor('action', toPlainObject({ key: 'forceUpdate' }));
884
+ return;
885
+ }
886
+ }
887
+ // 删除被移动的组件(必须是先删除再插入,不然可能导致混乱。)
888
+ this.componentListSplice(originPathMap.index, 1, undefined, originPathMap.componentListPath);
889
+ var afterMoveComponentListPath = newPathhMap.componentListPath;
890
+ // 删除后可能导致路径发生变化,需重新计算目标路径
891
+ // 重新获取组件路径
892
+ if (container) {
893
+ // 插入到容器中
894
+ var afterMoveComponentPath = this.generateComponentPath(container.componentId);
895
+ afterMoveComponentListPath = "".concat(afterMoveComponentPath, ".children");
896
+ }
897
+ // 在新组件列表中插入被移动的组件
898
+ this.componentListSplice(newPathhMap.index, 0, component, afterMoveComponentListPath);
899
+ console.log(this.components);
900
+ };
901
+ /**
902
+ * @public
903
+ * 删除组件
904
+ * @param key - 组件LowCodeKey
905
+ * @returns
906
+ */
907
+ BaseProjectDomain.prototype.componentDelete = function (key) {
908
+ var _this = this;
909
+ if (!(key === null || key === void 0 ? void 0 : key.path)) {
910
+ return;
911
+ }
912
+ var _a = this.getIndexByKey(key.path), index = _a.index, componentListPath = _a.componentListPath, component = _a.component;
913
+ if (index === -1)
914
+ return;
915
+ // 清除当前索引
916
+ this.currentComponentPath = '';
917
+ this.componentListSplice(index, 1, undefined, componentListPath);
918
+ // 若计数为0则重新计数 只针对有单独配置的对象
919
+ var recount = function (component) {
920
+ _this.cManager.delete(component.name);
921
+ (component.children || []).forEach(function (c) { return recount(c); });
922
+ };
923
+ recount(component);
924
+ };
925
+ /**
926
+ * @public
927
+ * 复制组件
928
+ * @param key - 组件LowCodeKey
929
+ * @returns
930
+ */
931
+ BaseProjectDomain.prototype.componentCopy = function (key) {
932
+ if (!(key === null || key === void 0 ? void 0 : key.path)) {
933
+ return;
934
+ }
935
+ var _a = this.getIndexByKey(key.path), index = _a.index, componentListPath = _a.componentListPath, component = _a.component;
936
+ if (index === -1)
937
+ return;
938
+ var componentConfig = this.cManager.get(component.name);
939
+ // 是否走自定义拷贝
940
+ if (componentConfig === null || componentConfig === void 0 ? void 0 : componentConfig.customCopy) {
941
+ this.publishEditor('message', {
942
+ type: 'copy',
943
+ data: {
944
+ component: component,
945
+ newId: this.cManager.getImxId() + 1,
946
+ componentListPath: componentListPath,
947
+ insertIndex: index + 1,
948
+ deleteCount: 0,
949
+ },
950
+ });
951
+ }
952
+ else {
953
+ this.componentListSplice(index + 1, 0, this.cManager.copy(component), componentListPath);
954
+ }
955
+ };
956
+ /**
957
+ * @public
958
+ * 拖动组件
959
+ * @param key - 组件LowCodeKey
960
+ * @param value - 数据
961
+ */
962
+ BaseProjectDomain.prototype.componentDrag = function (key, value) {
963
+ var _a;
964
+ var elements = document.elementsFromPoint(value.x, value.y);
965
+ // 找到坐标落在里面的最近的那个组件
966
+ var element = elements.find(
967
+ // @ts-ignore
968
+ function (el) { var _a; return el.dataset.id && ((_a = el.dataset) === null || _a === void 0 ? void 0 : _a.component); });
969
+ var component = this.cManager.get(value.name);
970
+ var start = 0;
971
+ var componentListPath = '';
972
+ if (element) {
973
+ var targetComponentId = +(((_a = element === null || element === void 0 ? void 0 : element.dataset) === null || _a === void 0 ? void 0 : _a.id) || 0);
974
+ var targetComponentPath = this.generateComponentPath(targetComponentId);
975
+ var targetComponent = this.pathToData(targetComponentPath);
976
+ // 容器组件
977
+ if (targetComponent.type === ComponentType.Container) {
978
+ componentListPath = "".concat(targetComponentPath, ".children");
979
+ }
980
+ // 非容器组件
981
+ else {
982
+ var rect = element.getBoundingClientRect();
983
+ var _b = this.getIndexByKey(targetComponentPath), path = _b.componentListPath, index = _b.index;
984
+ componentListPath = path;
985
+ // 判断坐标在该组件的上半部分还是下半部分
986
+ start = value.y < rect.top + rect.height / 2 ? index : index + 1;
987
+ }
988
+ }
989
+ else {
990
+ // 页面
991
+ start = this.components.length;
992
+ }
993
+ this.componentListSplice(start, 0, component, componentListPath);
994
+ };
995
+ /**
996
+ * @public
997
+ * 点击时插入组件 直接插到模拟器最后
998
+ * @param key - 组件LowCodeKey
999
+ * @returns
1000
+ */
1001
+ BaseProjectDomain.prototype.componentInsert = function (key) {
1002
+ var _a;
1003
+ if (!key.component) {
1004
+ return;
1005
+ }
1006
+ var length = this.components.length;
1007
+ var listPath = undefined;
1008
+ var component = this.cManager.get(key.component);
1009
+ if (this.currentComponent) {
1010
+ var currentComponentConfig = this.cManager.get(this.currentComponent.name);
1011
+ if (currentComponentConfig.immobile) {
1012
+ if (currentComponentConfig.type === ComponentType.Container) {
1013
+ listPath = this.currentComponentPath + '.children';
1014
+ // 选择了容器,则插在容器内部
1015
+ length = (_a = this.pathToData(listPath)) === null || _a === void 0 ? void 0 : _a.length;
1016
+ }
1017
+ }
1018
+ else {
1019
+ listPath = this.currentComponentPath.replace(/\.\d+$/, '');
1020
+ // 插在当前选择的组件后面
1021
+ length = (parseInt(this.currentComponentPath.substring(listPath.length + 1)) || 0) + 1;
1022
+ }
1023
+ }
1024
+ this.componentListSplice(length, 0, component, listPath);
1025
+ };
1026
+ /**
1027
+ * @public
1028
+ * 组件上移
1029
+ * @param key - 组件LowCodeKey
1030
+ * @returns
1031
+ */
1032
+ BaseProjectDomain.prototype.componentMoveUp = function (key) {
1033
+ if (!key.path) {
1034
+ return;
1035
+ }
1036
+ var _a = this.getIndexByKey(key.path), index = _a.index, componentListPath = _a.componentListPath;
1037
+ this.moveTo(key.path, componentListPath + '.' + Math.max(index - 1, 0));
1038
+ };
1039
+ /**
1040
+ * @public
1041
+ * 组件下移
1042
+ * @param key - 组件LowCodeKey
1043
+ * @returns
1044
+ */
1045
+ BaseProjectDomain.prototype.componentMoveDown = function (key) {
1046
+ if (!key.path) {
1047
+ return;
1048
+ }
1049
+ var _a = this.getIndexByKey(key.path), index = _a.index, componentListPath = _a.componentListPath;
1050
+ var afterMoveIndex = Math.min(index + 1, get(this.pages, componentListPath).length - 1);
1051
+ this.moveTo(key.path, componentListPath + '.' + afterMoveIndex);
1052
+ };
1053
+ /**
1054
+ * @public
1055
+ * 打开图片上传
1056
+ * @param key - 组件LowCodeKey
1057
+ * @returns
1058
+ */
1059
+ BaseProjectDomain.prototype.componentImageOpen = function (key) {
1060
+ if (!key.path) {
1061
+ return;
1062
+ }
1063
+ var _a = this.getIndexByKey(key.path), index = _a.index, componentListPath = _a.componentListPath, component = _a.component;
1064
+ console.log('打开图片组件:', component);
1065
+ if (index === -1)
1066
+ return;
1067
+ // 打开云组件进行上传图片
1068
+ this.publishEditor('message', {
1069
+ type: 'openUpload',
1070
+ data: {
1071
+ field: {}
1072
+ },
1073
+ });
1074
+ };
1075
+ /**
1076
+ * @public
1077
+ * 修改表单更新项目数据
1078
+ * @param path - 路径
1079
+ * @param value - 值
1080
+ */
1081
+ BaseProjectDomain.prototype.setPathDataWithValidate = function (path, value) {
1082
+ var _this = this;
1083
+ var _a, _b;
1084
+ var data = this.setPathData(path, value);
1085
+ console.log('setPathDataWithValidate', data);
1086
+ // TODO 挪走
1087
+ // 先更新模拟器
1088
+ this.publishPreview('updateProject', this);
1089
+ // 校验图片
1090
+ var imgUrls = [];
1091
+ getImageUrls({
1092
+ // TODO 这里没考虑到页面配置的情况
1093
+ data: (_b = (_a = this.currentComponent) === null || _a === void 0 ? void 0 : _a.formData) === null || _b === void 0 ? void 0 : _b.props,
1094
+ path: [],
1095
+ result: imgUrls,
1096
+ });
1097
+ imgUrls.forEach(function (imgItem) {
1098
+ var _a, _b, _c, _d;
1099
+ // 通过某个值获取对应属性的配置
1100
+ var config = getSchemaConfigByValue((_a = _this.cManager.get(_this.currentComponent.name)) === null || _a === void 0 ? void 0 : _a.config, (_b = _this.currentComponent) === null || _b === void 0 ? void 0 : _b.formData, imgItem === null || imgItem === void 0 ? void 0 : imgItem.url);
1101
+ if (config && ((_d = (_c = config['x-validator']) === null || _c === void 0 ? void 0 : _c.upload) === null || _d === void 0 ? void 0 : _d.expectWidth)) {
1102
+ //不存在expectWidth 不需要模拟器校验
1103
+ return;
1104
+ }
1105
+ _this.publishPreview('validateImage', imgItem === null || imgItem === void 0 ? void 0 : imgItem.url, function (result) {
1106
+ var res = _this.validateImage(result, imgItem === null || imgItem === void 0 ? void 0 : imgItem.path, imgItem === null || imgItem === void 0 ? void 0 : imgItem.url);
1107
+ if (res) {
1108
+ _this.publishEditor('action', toPlainObject({ key: 'doubleImage', value: res }));
1109
+ _this.publishPreview('updateProject', _this);
1110
+ _this.publishEditor('update', true);
1111
+ }
1112
+ });
1113
+ });
1114
+ };
1115
+ /**
1116
+ * @public
1117
+ * 设置project数据 构造函数里和init时调用
1118
+ * @param project - 项目数据
1119
+ */
1120
+ BaseProjectDomain.prototype.setProject = function (project) {
1121
+ this.state.project = merge({
1122
+ categoryName: '',
1123
+ projectName: '无题',
1124
+ status: 0,
1125
+ isNoLogin: false,
1126
+ meta: { width: 414, height: 736 },
1127
+ pages: [
1128
+ {
1129
+ components: [
1130
+ {
1131
+ list: [],
1132
+ strategy: '',
1133
+ },
1134
+ ],
1135
+ pageMeta: {},
1136
+ },
1137
+ ],
1138
+ }, project);
1139
+ this.cManager.initComponens(this.components);
1140
+ };
1141
+ /**
1142
+ * @public
1143
+ * 替换project数据 undo,redo
1144
+ * @param project - project数据
1145
+ */
1146
+ BaseProjectDomain.prototype.replaceProject = function (project) {
1147
+ var currentComponentPath = project.currentComponentPath, projectData = project.projectData;
1148
+ var _a = this.state.project, categoryName = _a.categoryName, projectName = _a.projectName, isNoLogin = _a.isNoLogin, status = _a.status;
1149
+ this.state.project = __assign(__assign({}, projectData), { projectName: projectName, categoryName: categoryName, isNoLogin: isNoLogin, status: status });
1150
+ this.activate({
1151
+ path: currentComponentPath,
1152
+ });
1153
+ };
1154
+ /**
1155
+ * @public
1156
+ * @param result - 模拟器校验二倍图的结果
1157
+ * @param path - 图片地址的路径
1158
+ * @returns
1159
+ */
1160
+ BaseProjectDomain.prototype.validateImage = function (result, path, imgUrl) {
1161
+ var _a, _b;
1162
+ if (!result) {
1163
+ // 清空图片 // todo 撤销恢复原来的图片
1164
+ set((_b = (_a = this.currentComponent) === null || _a === void 0 ? void 0 : _a.formData) === null || _b === void 0 ? void 0 : _b.props, path, '');
1165
+ // 返回错误结果
1166
+ return this.validateImageFail(imgUrl);
1167
+ }
1168
+ // 校验通过返回null
1169
+ return null;
1170
+ };
1171
+ /**
1172
+ * @public
1173
+ * todo: 挪走
1174
+ * 二倍图校验失败需要返回的弹窗配置
1175
+ * @returns
1176
+ */
1177
+ BaseProjectDomain.prototype.validateImageFail = function (imgUrl) {
1178
+ var _a, _b, _c;
1179
+ try {
1180
+ if (!imgUrl) {
1181
+ return {};
1182
+ }
1183
+ // 通过某个值获取对应属性的配置
1184
+ var config = getSchemaConfigByValue((_a = this.cManager.get(this.currentComponent.name)) === null || _a === void 0 ? void 0 : _a.config, (_b = this.currentComponent) === null || _b === void 0 ? void 0 : _b.formData, imgUrl);
1185
+ var upload = ((_c = config === null || config === void 0 ? void 0 : config['x-validator']) !== null && _c !== void 0 ? _c : { upload: {} }).upload;
1186
+ return {
1187
+ text: (upload === null || upload === void 0 ? void 0 : upload.doubleImageTip) || '图片清晰度过低,请使用上传2倍图',
1188
+ icon: tipIcon,
1189
+ guide: upload === null || upload === void 0 ? void 0 : upload.guide,
1190
+ };
1191
+ }
1192
+ catch (e) {
1193
+ console.log('validateImageFail catch', e);
1194
+ }
1195
+ };
1196
+ Object.defineProperty(BaseProjectDomain.prototype, "functionData", {
1197
+ /**
1198
+ * @public
1199
+ * 获取功能数据
1200
+ */
1201
+ get: function () {
1202
+ var _this = this;
1203
+ if (!this.state.functionConfig) {
1204
+ // @ts-ignore
1205
+ return null;
1206
+ }
1207
+ // key规则: module:function, action是功能按钮的key 如undo或redo
1208
+ var data = {};
1209
+ var _a = this.state.project, status = _a.status, meta = _a.meta;
1210
+ var createFunctionData = function (key, value) { return ({
1211
+ key: {
1212
+ module: 'function',
1213
+ action: key,
1214
+ },
1215
+ value: value,
1216
+ clickable: undefined,
1217
+ }); };
1218
+ Object.entries(this.state.functionConfig).forEach(function (_a) {
1219
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
1220
+ // 如果布尔值为false 表示关闭这个功能 所以不添加这个字段
1221
+ if (typeof value === 'boolean') {
1222
+ if (value) {
1223
+ data[key] = createFunctionData(key, value);
1224
+ if (key === 'undo') {
1225
+ // 配套
1226
+ data['redo'] = createFunctionData('redo', value);
1227
+ }
1228
+ }
1229
+ }
1230
+ else {
1231
+ var val = value;
1232
+ if (key === 'title') {
1233
+ val = _this.title;
1234
+ }
1235
+ else if (key === 'status') {
1236
+ val = statusOptions[status !== null && status !== void 0 ? status : value];
1237
+ }
1238
+ else if (key === 'simulatorSizeList') {
1239
+ val = __assign(__assign({}, val), { data: __assign(__assign({}, val.data), meta) });
1240
+ }
1241
+ data[key] = createFunctionData(key, val);
1242
+ }
1243
+ });
1244
+ return data;
1245
+ },
1246
+ enumerable: false,
1247
+ configurable: true
1248
+ });
1249
+ /**
1250
+ * @public
1251
+ * @param componentId - 组件id
1252
+ * @param newValue - 新的值
1253
+ * @param oldValue - 旧的值
1254
+ */
1255
+ BaseProjectDomain.prototype.syncChildren = function (componentId, newValue, oldValue) {
1256
+ var componentPath = this.generateComponentPath(componentId);
1257
+ var component = this.pathToData(componentPath);
1258
+ console.log('syncChildren', componentId, component);
1259
+ if (component === null || component === void 0 ? void 0 : component.name) {
1260
+ var config = this.cManager.get(component.name);
1261
+ var _a = (config === null || config === void 0 ? void 0 : config.insertConfig) || {}, syncChildrenProp = _a.syncChildrenProp, syncChildrenName = _a.syncChildrenName;
1262
+ if (syncChildrenProp && syncChildrenName) {
1263
+ // 如果syncChildren.tabs比syncChildren.children长,则往children中插入差额的syncChildrenName组件,并把componentId更新到syncChildren.tabs中没有componentId属性的元素上;如果syncChildren.tabs比syncChildren.children短,则删除syncChildren.children中componentId不在syncChildren.tabs中的组件再同步一次。
1264
+ // 最后,如果currentComponentPath路径为不存在的路径,则把currentComponentPath路径更新为最后一个syncChildren.children的componentId对应的路径
1265
+ var childPath = componentPath + '.children';
1266
+ var children_1 = component.children = component.children || [];
1267
+ var childSetting = get(component.formData, syncChildrenProp) || [];
1268
+ console.log('syncChildren2', children_1, childSetting);
1269
+ var childLen = children_1.length;
1270
+ var childrenComponent = this.cManager.get(syncChildrenName);
1271
+ if (childLen < childSetting.length) {
1272
+ // 添加的情况
1273
+ for (var i = childLen; i < (childSetting === null || childSetting === void 0 ? void 0 : childSetting.length); i++) {
1274
+ this.componentListSplice(i, 0, childrenComponent, childPath);
1275
+ }
1276
+ console.log('syncChildren3', childLen, childSetting === null || childSetting === void 0 ? void 0 : childSetting.length, this.pathToData(childPath));
1277
+ // 对于初始化的情况
1278
+ if (childLen === 0) {
1279
+ this.activate({ path: childPath + '.0' });
1280
+ }
1281
+ }
1282
+ else if (childLen > childSetting.length) {
1283
+ // 删除的情况
1284
+ if (newValue && oldValue) {
1285
+ var newChildren_1 = [];
1286
+ var hasIn_1 = {};
1287
+ newValue.forEach(function (item, index) {
1288
+ var oldIndex = oldValue.findIndex(function (o, oldIdx) { return isEqual(item, o) && !hasIn_1[oldIdx]; });
1289
+ hasIn_1[oldIndex] = true;
1290
+ newChildren_1[index] = children_1[oldIndex];
1291
+ });
1292
+ component.children = newChildren_1;
1293
+ }
1294
+ else {
1295
+ component.children = component.children.slice(0, childSetting.length);
1296
+ }
1297
+ this.activate({ path: componentPath });
1298
+ }
1299
+ this.emit('updateHistory');
1300
+ }
1301
+ }
1302
+ };
1303
+ return BaseProjectDomain;
1304
+ }(ProjectDomain));
1305
+ export default BaseProjectDomain;