@cniot/mdd-editor 0.2.0-beta.9 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.MD +308 -11
- package/build/index.cjs.js +27 -19
- package/build/index.es.js +3731 -446
- package/build/style.css +1 -1
- package/package.json +1 -1
- package/src/ai/LocalAIDrawer.jsx +217 -0
- package/src/ai/bridgeClient.js +168 -0
- package/src/ai/pageIR.js +148 -0
- package/src/components/address-select/formily.jsx +1 -1
- package/src/components/ajax-schema-form/formily-table-form-proxy.jsx +1 -1
- package/src/components/ajax-schema-form/formily.jsx +1 -1
- package/src/components/ajax-schema-form/table-form-proxy.jsx +1 -1
- package/src/components/ajax-schema-form/table-form.jsx +1 -1
- package/src/components/data-source-select/formily.jsx +1 -1
- package/src/components/dynamic-value/base/formily.jsx +1 -1
- package/src/components/dynamic-value/date/formily.jsx +1 -1
- package/src/components/formily-select/index.tsx +1 -1
- package/src/components/params-select/formily.jsx +1 -1
- package/src/components/time-range/formily.jsx +1 -1
- package/src/hooks/useSchema.jsx +5 -5
- package/src/hooks/useSwagger.jsx +2 -2
- package/src/schema/base-schema/AjaxSchema.js +1 -1
- package/src/schema/base-schema/AjaxSchemaQueue.js +1 -1
- package/src/schema/blocks/edit-table.js +57 -0
- package/src/schema/blocks/filter.js +49 -0
- package/src/schema/blocks/form.js +49 -0
- package/src/schema/blocks/index.js +32 -10
- package/src/schema/blocks/table.js +3 -4
- package/src/schema/detail/detail-item.js +5 -5
- package/src/schema/detail/index.js +26 -18
- package/src/schema/edit-table/header-toolbar.js +1 -1
- package/src/schema/edit-table/index.js +10 -5
- package/src/schema/edit-table/table.js +10 -2
- package/src/schema/formily-form/data-source.js +1 -1
- package/src/schema/formily-form/form-schema.js +1 -1
- package/src/schema/formily-form/index.js +8 -8
- package/src/schema/formily-form-v2/form-info.js +2 -2
- package/src/schema/formily-form-v2/form-items.js +1 -1
- package/src/schema/formily-form-v2/index.js +3 -3
- package/src/schema/ftp/data-source.js +1 -1
- package/src/schema/ftp/filter.js +2 -2
- package/src/schema/ftp/header-toolbar.js +1 -1
- package/src/schema/ftp/index.js +4 -4
- package/src/schema/ftp/middle-item.js +1 -1
- package/src/schema/ftp/table.js +9 -3
- package/src/schema/util.js +3 -3
- package/src/services/index.js +1 -1
- package/src/template/blocks/EditTable.jsx +62 -0
- package/src/template/blocks/Filter.jsx +137 -0
- package/src/template/blocks/Form.jsx +136 -0
- package/src/template/blocks/Table.jsx +4 -4
- package/src/template/const.js +18 -4
- package/src/template/detail/DetailItems.jsx +6 -1
- package/src/template/detail/components/Actions.jsx +1 -1
- package/src/template/detail/components/DetailCard.jsx +8 -5
- package/src/template/detail/components/DetailColumns.jsx +193 -113
- package/src/template/detail/components/DetailCustom.jsx +2 -2
- package/src/template/detail/components/DetailTable.jsx +13 -8
- package/src/template/detail/components/MultiAjaxSchemaForm.jsx +1 -1
- package/src/template/edit-table/HeaderToolbar.jsx +3 -2
- package/src/template/edit-table/Table.jsx +56 -3
- package/src/template/formily-form-v2/FormInfo.jsx +1 -1
- package/src/template/formily-form-v2/FormItems.jsx +4 -8
- package/src/template/formilyform/components/AsyncDataSourceSetter/index.tsx +1 -1
- package/src/template/formilyform/components/SubmitActionSetter/index.tsx +1 -1
- package/src/template/ftp/DataSource.jsx +1 -1
- package/src/template/ftp/Filter.jsx +14 -7
- package/src/template/ftp/HeaderToolbar.jsx +8 -4
- package/src/template/ftp/Middle.jsx +11 -7
- package/src/template/ftp/Table.jsx +143 -12
- package/src/template/simple-ftp/Table.jsx +2 -2
- package/src/toolbar.jsx +76 -14
- package/src/utils/buildFieldsToCompJson.js +3 -3
- package/src/utils/persistentStorage.js +1 -1
- package/src/utils/swagger/api2SchemaFromSwagger.js +7 -7
package/src/ai/pageIR.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
const pick = (obj, keys) => {
|
|
2
|
+
const res = {};
|
|
3
|
+
keys.forEach((key) => {
|
|
4
|
+
if (obj && obj[key] !== undefined) {
|
|
5
|
+
res[key] = obj[key];
|
|
6
|
+
}
|
|
7
|
+
});
|
|
8
|
+
return res;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const parseImports = (script = '') => {
|
|
12
|
+
const imports = [];
|
|
13
|
+
const reg = /^\s*import\s+(.+?)\s+from\s+['"](.+?)['"]/gm;
|
|
14
|
+
let match = reg.exec(script);
|
|
15
|
+
while (match) {
|
|
16
|
+
imports.push({
|
|
17
|
+
what: match[1].trim(),
|
|
18
|
+
from: match[2],
|
|
19
|
+
});
|
|
20
|
+
match = reg.exec(script);
|
|
21
|
+
}
|
|
22
|
+
return imports;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const parseFunctions = (script = '') => {
|
|
26
|
+
const functions = [];
|
|
27
|
+
const reg = /(?:function\s+([A-Za-z0-9_$]+)|const\s+([A-Za-z0-9_$]+)\s*=\s*(?:\([^)]*\)|[A-Za-z0-9_$]+)\s*=>)/g;
|
|
28
|
+
let match = reg.exec(script);
|
|
29
|
+
while (match) {
|
|
30
|
+
functions.push(match[1] || match[2]);
|
|
31
|
+
match = reg.exec(script);
|
|
32
|
+
}
|
|
33
|
+
return functions;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const getArray = (value) => (Array.isArray(value) ? value : []);
|
|
37
|
+
|
|
38
|
+
export function buildPageIR({ schemaJson = {}, script = '', style = '', pageMeta = {} }) {
|
|
39
|
+
const body = schemaJson.body || {};
|
|
40
|
+
const filterFields = getArray(body.filter?.fields);
|
|
41
|
+
const tableColumns = getArray(body.table?.columns);
|
|
42
|
+
const headerToolbar = getArray(body.headerToolbar);
|
|
43
|
+
const actionColumns = getArray(body.table?.actionColumns);
|
|
44
|
+
const bulkActions = getArray(body.table?.bulkActions);
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
meta: {
|
|
48
|
+
code: pageMeta.code,
|
|
49
|
+
name: pageMeta.name,
|
|
50
|
+
template: pageMeta.mddTemplateType || body.type,
|
|
51
|
+
editorVersion: schemaJson.editorVersion,
|
|
52
|
+
host: schemaJson.host,
|
|
53
|
+
pageType: schemaJson.type,
|
|
54
|
+
gmtModified: pageMeta.gmtModified,
|
|
55
|
+
modifierAccount: pageMeta.modifierAccount,
|
|
56
|
+
},
|
|
57
|
+
api: body.api
|
|
58
|
+
? {
|
|
59
|
+
...pick(body.api, ['type', 'host', 'method', 'url', 'content', 'value']),
|
|
60
|
+
watch: getArray(body.api.watch),
|
|
61
|
+
paramsKeys: Object.keys(body.api.params || {}),
|
|
62
|
+
formatResponseData: body.api.formatResponseData,
|
|
63
|
+
hasResponseHandleCode: !!body.api.responseHandleCode,
|
|
64
|
+
}
|
|
65
|
+
: null,
|
|
66
|
+
filter: {
|
|
67
|
+
count: filterFields.length,
|
|
68
|
+
fields: filterFields.map((field, index) => ({
|
|
69
|
+
index,
|
|
70
|
+
path: `body.filter.fields[${index}]`,
|
|
71
|
+
type: field.type,
|
|
72
|
+
name: field.name,
|
|
73
|
+
label: field.label,
|
|
74
|
+
colSpan: field.colSpan,
|
|
75
|
+
sourceUrl: field.source?.url,
|
|
76
|
+
sourceMethod: field.source?.method,
|
|
77
|
+
enumCode: field.source?.params?.code,
|
|
78
|
+
})),
|
|
79
|
+
},
|
|
80
|
+
headerToolbar: headerToolbar.map((item, index) => ({
|
|
81
|
+
index,
|
|
82
|
+
path: `body.headerToolbar[${index}]`,
|
|
83
|
+
type: item.type,
|
|
84
|
+
label: item.label,
|
|
85
|
+
name: item.name,
|
|
86
|
+
actionType: item.actionType,
|
|
87
|
+
action: item.action?.type,
|
|
88
|
+
value: item.action?.value,
|
|
89
|
+
title: item.action?.title,
|
|
90
|
+
shouldRender: item.action?.shouldRender || item.shouldRender,
|
|
91
|
+
})),
|
|
92
|
+
table: {
|
|
93
|
+
primaryKey: body.table?.primaryKey,
|
|
94
|
+
pagination: body.table?.pagination,
|
|
95
|
+
showSelect: body.table?.showSelect,
|
|
96
|
+
columnCount: tableColumns.length,
|
|
97
|
+
actionCount: actionColumns.length,
|
|
98
|
+
bulkActionCount: bulkActions.length,
|
|
99
|
+
columns: tableColumns.map((column, index) => ({
|
|
100
|
+
index,
|
|
101
|
+
path: `body.table.columns[${index}]`,
|
|
102
|
+
type: column.type,
|
|
103
|
+
name: column.name,
|
|
104
|
+
label: column.label,
|
|
105
|
+
lock: column.lock,
|
|
106
|
+
sortable: column.sortable,
|
|
107
|
+
filter: column.filter,
|
|
108
|
+
customType: column.customType,
|
|
109
|
+
value: column.value,
|
|
110
|
+
format: column.format,
|
|
111
|
+
})),
|
|
112
|
+
actionColumns: actionColumns.map((action, index) => ({
|
|
113
|
+
index,
|
|
114
|
+
path: `body.table.actionColumns[${index}]`,
|
|
115
|
+
type: action.type,
|
|
116
|
+
label: action.label,
|
|
117
|
+
name: action.name,
|
|
118
|
+
actionType: action.actionType,
|
|
119
|
+
action: action.action?.type,
|
|
120
|
+
value: action.action?.value,
|
|
121
|
+
title: action.action?.title,
|
|
122
|
+
shouldRender: action.action?.shouldRender || action.shouldRender,
|
|
123
|
+
})),
|
|
124
|
+
},
|
|
125
|
+
script: {
|
|
126
|
+
length: script.length,
|
|
127
|
+
imports: parseImports(script),
|
|
128
|
+
functions: parseFunctions(script),
|
|
129
|
+
hasSetModule: /\.setModule\s*\(/.test(script),
|
|
130
|
+
hasSetComponent: /\.setComponent\s*\(/.test(script),
|
|
131
|
+
hasMDDRenderEngine: script.indexOf('MDDRenderEngine') > -1,
|
|
132
|
+
},
|
|
133
|
+
style: {
|
|
134
|
+
length: style.length,
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function getPageCode(schemaJson = {}, pageMeta = {}) {
|
|
140
|
+
const searchParams = new URLSearchParams(window.location.search || '');
|
|
141
|
+
return (
|
|
142
|
+
pageMeta.code ||
|
|
143
|
+
searchParams.get('code') ||
|
|
144
|
+
schemaJson?.code ||
|
|
145
|
+
schemaJson?.body?.code ||
|
|
146
|
+
`local-${schemaJson?.body?.type || 'mdd'}`
|
|
147
|
+
);
|
|
148
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { formilyReact, formilyCore } from '@cainiaofe/cn-ui';
|
|
3
|
-
import { mapSize, mapStatus } from '
|
|
3
|
+
import { mapSize, mapStatus } from '$src/utils/formilyHook';
|
|
4
4
|
import AddressCompoent from './index';
|
|
5
5
|
|
|
6
6
|
const { connect, mapReadPretty, mapProps } = formilyReact;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { formilyReact, formilyCore } from '@cainiaofe/cn-ui';
|
|
3
|
-
import { mapSize, mapStatus } from '
|
|
3
|
+
import { mapSize, mapStatus } from '$src/utils/formilyHook';
|
|
4
4
|
import TableFormProxy from './table-form-proxy';
|
|
5
5
|
|
|
6
6
|
const { connect, mapReadPretty, mapProps } = formilyReact;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { formilyReact, formilyCore } from '@cainiaofe/cn-ui';
|
|
3
|
-
import { mapSize, mapStatus } from '
|
|
3
|
+
import { mapSize, mapStatus } from '$src/utils/formilyHook';
|
|
4
4
|
import AjaxSchemaFrom from './index';
|
|
5
5
|
|
|
6
6
|
const { connect, mapReadPretty, mapProps } = formilyReact;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import TableForm from './table-form';
|
|
3
|
-
import { object2Array, array2Object } from '
|
|
3
|
+
import { object2Array, array2Object } from '$src/schema/base-schema/AjaxSchema';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* <TableFromProxy value={{}} onChange={} />
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Table, Input, Button, Select } from '@cainiaofe/cn-ui';
|
|
3
|
-
import useSchema from '
|
|
3
|
+
import useSchema from '$src/hooks/useSchema';
|
|
4
4
|
import { GLOABL_DATA, splitValue, mergeValue, getFilterLabelList } from './const';
|
|
5
5
|
|
|
6
6
|
const FAST_LIST_DATA = [{ label: '当前操作行数据对象', value: 'RECORD_DATA' }];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { formilyReact, formilyCore } from '@cainiaofe/cn-ui';
|
|
3
|
-
import { mapSize, mapStatus } from '
|
|
3
|
+
import { mapSize, mapStatus } from '$src/utils/formilyHook';
|
|
4
4
|
import DataSourceSelect from './index';
|
|
5
5
|
|
|
6
6
|
const { connect, mapReadPretty, mapProps } = formilyReact;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { formilyReact, formilyCore } from '@cainiaofe/cn-ui';
|
|
3
|
-
import { mapSize, mapStatus } from '
|
|
3
|
+
import { mapSize, mapStatus } from '$src/utils/formilyHook';
|
|
4
4
|
import DynamicValueBase from './index';
|
|
5
5
|
|
|
6
6
|
const { connect, mapReadPretty, mapProps } = formilyReact;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { formilyReact, formilyCore } from '@cainiaofe/cn-ui';
|
|
3
|
-
import { mapSize, mapStatus } from '
|
|
3
|
+
import { mapSize, mapStatus } from '$src/utils/formilyHook';
|
|
4
4
|
import DynamicValueDate from './index';
|
|
5
5
|
|
|
6
6
|
const { connect, mapReadPretty, mapProps } = formilyReact;
|
|
@@ -86,7 +86,7 @@ const patchDataSource = (dataSource: any = []) => {
|
|
|
86
86
|
if (!result.children || result.children.length === 0) {
|
|
87
87
|
delete result.children;
|
|
88
88
|
} else {
|
|
89
|
-
result.children = result.children
|
|
89
|
+
result.children = result.children?.map?.(removeEmptyChildren);
|
|
90
90
|
}
|
|
91
91
|
return result;
|
|
92
92
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { formilyReact, formilyCore } from '@cainiaofe/cn-ui';
|
|
3
|
-
import { mapSize, mapStatus } from '
|
|
3
|
+
import { mapSize, mapStatus } from '$src/utils/formilyHook';
|
|
4
4
|
import DataSourceSelect from './index';
|
|
5
5
|
|
|
6
6
|
const { connect, mapReadPretty, mapProps } = formilyReact;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { formilyReact, formilyCore } from '@cainiaofe/cn-ui';
|
|
3
|
-
import { mapSize, mapStatus } from '
|
|
3
|
+
import { mapSize, mapStatus } from '$src/utils/formilyHook';
|
|
4
4
|
import TimeRange from './index';
|
|
5
5
|
|
|
6
6
|
const { connect, mapReadPretty, mapProps } = formilyReact;
|
package/src/hooks/useSchema.jsx
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
2
|
import { createModel } from 'hox';
|
|
3
|
-
import storage from '
|
|
4
|
-
import useSwagger from '
|
|
5
|
-
import { MDD_SCHEMA_LS_KEY } from '
|
|
6
|
-
import { Util } from '
|
|
7
|
-
import { IS_VSCODE } from '
|
|
3
|
+
import storage from '$src/utils/persistentStorage';
|
|
4
|
+
import useSwagger from '$src/hooks/useSwagger';
|
|
5
|
+
import { MDD_SCHEMA_LS_KEY } from '$src/common/const';
|
|
6
|
+
import { Util } from '$src/schema';
|
|
7
|
+
import { IS_VSCODE } from '$src/utils/vscode';
|
|
8
8
|
|
|
9
9
|
function useSchema() {
|
|
10
10
|
const { fetchSwaggerInfo } = useSwagger();
|
package/src/hooks/useSwagger.jsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
|
-
import { getSwaggerInfo } from '
|
|
2
|
+
import { getSwaggerInfo } from '$src/services';
|
|
3
3
|
import { createModel } from 'hox';
|
|
4
|
-
import { getSwaggerInfoFromJson, buildSwaggerApiJson, buildFieldsToCompJson } from '
|
|
4
|
+
import { getSwaggerInfoFromJson, buildSwaggerApiJson, buildFieldsToCompJson } from '$src/utils';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @returns 缓存swagger元数据信息, 方便后面匹配接口选择
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/* eslint-disable indent */
|
|
2
|
+
import JSONWatch from '$src/utils/JSONWatch';
|
|
3
|
+
|
|
4
|
+
export default class EditTableSchema extends JSONWatch {
|
|
5
|
+
constructor(props) {
|
|
6
|
+
super({
|
|
7
|
+
columns: props, // 与 BlockSchema 中的 toJSON toJSONKey 对应
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
setFieldsAll(columns, ignoreUpdate = false) {
|
|
12
|
+
// TODO 已有的schema结构,如何merge
|
|
13
|
+
this.set('columns', columns, ignoreUpdate);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// 更新
|
|
17
|
+
setItemAll(value, type = 'columns', ignoreUpdate = false) {
|
|
18
|
+
this.set(type, value, ignoreUpdate);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
add(field, key = 'columns', ignoreUpdate = false) {
|
|
22
|
+
this.data[key].push(field);
|
|
23
|
+
this.emit('$updated', null, ignoreUpdate);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
remove(index, key = 'columns', ignoreUpdate = false) {
|
|
27
|
+
this.data[key].splice(index, 1);
|
|
28
|
+
this.emit('$updated', null, ignoreUpdate);
|
|
29
|
+
}
|
|
30
|
+
update(index, data, key = 'columns', ignoreUpdate = false) {
|
|
31
|
+
/**
|
|
32
|
+
* key 的类型如下:
|
|
33
|
+
* {string} primaryKey 主键
|
|
34
|
+
* {array} bulkActions 批量操作
|
|
35
|
+
* {array} columns 列
|
|
36
|
+
* {array} actionColumns 操作列
|
|
37
|
+
* {object} pagination 分页
|
|
38
|
+
*/
|
|
39
|
+
if (['columns', 'actionColumns', 'bulkActions'].includes(key)) {
|
|
40
|
+
this.data[key].splice(index, 1, data);
|
|
41
|
+
} else {
|
|
42
|
+
this.data[key] = data;
|
|
43
|
+
}
|
|
44
|
+
this.emit('$updated', null, ignoreUpdate);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
updateAll(data) {
|
|
48
|
+
this.data = data;
|
|
49
|
+
this.emit('$updated');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
delete() {}
|
|
53
|
+
|
|
54
|
+
getJSON() {
|
|
55
|
+
return super.getJSON();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/* eslint-disable indent */
|
|
2
|
+
import JSONWatch from '$src/utils/JSONWatch';
|
|
3
|
+
import { getDefaultFomrLabelAlign } from '$src/utils';
|
|
4
|
+
|
|
5
|
+
export default class FilterSchema extends JSONWatch {
|
|
6
|
+
constructor(props) {
|
|
7
|
+
super({
|
|
8
|
+
fields: props, // 与 BlockSchema 中的 toJSON toJSONKey 对应
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
setFieldsAll(fields, ignoreUpdate = false) {
|
|
13
|
+
this.set('fields', fields, ignoreUpdate);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// 更新
|
|
17
|
+
setItemAll(value, type = 'fields', ignoreUpdate = false) {
|
|
18
|
+
this.set(type, value, ignoreUpdate);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
add(field, key = 'fields', ignoreUpdate = false) {
|
|
22
|
+
this.data[key].push(field);
|
|
23
|
+
this.emit('$updated', null, ignoreUpdate);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
remove(index, key = 'fields', ignoreUpdate = false) {
|
|
27
|
+
this.data[key].splice(index, 1);
|
|
28
|
+
this.emit('$updated', null, ignoreUpdate);
|
|
29
|
+
}
|
|
30
|
+
update(index, data, key = 'fields', ignoreUpdate = false) {
|
|
31
|
+
if (['fields'].includes(key)) {
|
|
32
|
+
this.data[key].splice(index, 1, data);
|
|
33
|
+
} else {
|
|
34
|
+
this.data[key] = data;
|
|
35
|
+
}
|
|
36
|
+
this.emit('$updated', null, ignoreUpdate);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
updateAll(data) {
|
|
40
|
+
this.data = data;
|
|
41
|
+
this.emit('$updated');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
delete() {}
|
|
45
|
+
|
|
46
|
+
getJSON() {
|
|
47
|
+
return super.getJSON();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/* eslint-disable indent */
|
|
2
|
+
import JSONWatch from '$src/utils/JSONWatch';
|
|
3
|
+
import { getDefaultFomrLabelAlign } from '$src/utils';
|
|
4
|
+
|
|
5
|
+
export default class FormSchema extends JSONWatch {
|
|
6
|
+
constructor(props) {
|
|
7
|
+
super({
|
|
8
|
+
fields: props, // 与 BlockSchema 中的 toJSON toJSONKey 对应
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
setFieldsAll(fields, ignoreUpdate = false) {
|
|
13
|
+
this.set('fields', fields, ignoreUpdate);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// 更新
|
|
17
|
+
setItemAll(value, type = 'fields', ignoreUpdate = false) {
|
|
18
|
+
this.set(type, value, ignoreUpdate);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
add(field, key = 'fields', ignoreUpdate = false) {
|
|
22
|
+
this.data[key].push(field);
|
|
23
|
+
this.emit('$updated', null, ignoreUpdate);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
remove(index, key = 'fields', ignoreUpdate = false) {
|
|
27
|
+
this.data[key].splice(index, 1);
|
|
28
|
+
this.emit('$updated', null, ignoreUpdate);
|
|
29
|
+
}
|
|
30
|
+
update(index, data, key = 'fields', ignoreUpdate = false) {
|
|
31
|
+
if (['fields'].includes(key)) {
|
|
32
|
+
this.data[key].splice(index, 1, data);
|
|
33
|
+
} else {
|
|
34
|
+
this.data[key] = data;
|
|
35
|
+
}
|
|
36
|
+
this.emit('$updated', null, ignoreUpdate);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
updateAll(data) {
|
|
40
|
+
this.data = data;
|
|
41
|
+
this.emit('$updated');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
delete() {}
|
|
45
|
+
|
|
46
|
+
getJSON() {
|
|
47
|
+
return super.getJSON();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -1,9 +1,31 @@
|
|
|
1
|
-
import { EVENT_KEY } from '
|
|
1
|
+
import { EVENT_KEY } from '$src/common/const';
|
|
2
2
|
import Schema from '../Schema';
|
|
3
3
|
import Table from './table';
|
|
4
|
+
import Filter from './filter';
|
|
5
|
+
import Form from './form';
|
|
6
|
+
import EditTable from './edit-table';
|
|
4
7
|
|
|
5
8
|
export default class BlocksSchema extends Schema {
|
|
6
|
-
static Table = Table;
|
|
9
|
+
// static Table = Table;
|
|
10
|
+
// static Filter = Filter;
|
|
11
|
+
static BlocksInfoMap = {
|
|
12
|
+
'blocks-table': {
|
|
13
|
+
schema: Table,
|
|
14
|
+
toJSONKey: 'columns',
|
|
15
|
+
},
|
|
16
|
+
'blocks-edit-table': {
|
|
17
|
+
schema: EditTable,
|
|
18
|
+
toJSONKey: 'columns',
|
|
19
|
+
},
|
|
20
|
+
'blocks-filter': {
|
|
21
|
+
schema: Filter,
|
|
22
|
+
toJSONKey: 'fields',
|
|
23
|
+
},
|
|
24
|
+
'blocks-form': {
|
|
25
|
+
schema: Form,
|
|
26
|
+
toJSONKey: 'fields',
|
|
27
|
+
},
|
|
28
|
+
};
|
|
7
29
|
|
|
8
30
|
/**
|
|
9
31
|
* @param {*} props
|
|
@@ -13,10 +35,11 @@ export default class BlocksSchema extends Schema {
|
|
|
13
35
|
* }
|
|
14
36
|
*/
|
|
15
37
|
constructor(props, isCompleteSchema = false) {
|
|
16
|
-
const { type, blocks, ...more } = isCompleteSchema ? props.body : props;
|
|
38
|
+
const { type, blocks = [], ...more } = isCompleteSchema ? props.body : props;
|
|
17
39
|
super(more);
|
|
18
40
|
this.type = type;
|
|
19
|
-
|
|
41
|
+
const RealSchema = BlocksSchema.BlocksInfoMap[type].schema;
|
|
42
|
+
this.blocks = new RealSchema(blocks);
|
|
20
43
|
|
|
21
44
|
this.willDetach = this.initChangeListener();
|
|
22
45
|
}
|
|
@@ -37,7 +60,7 @@ export default class BlocksSchema extends Schema {
|
|
|
37
60
|
// 根据schema初始化对象, 二次打开
|
|
38
61
|
initFromCache(schema) {
|
|
39
62
|
const { body, ...more } = schema;
|
|
40
|
-
const { blocks
|
|
63
|
+
const { blocks } = body;
|
|
41
64
|
// 先关闭storage的更新
|
|
42
65
|
if (this.willDetach) {
|
|
43
66
|
this.willDetach();
|
|
@@ -46,7 +69,6 @@ export default class BlocksSchema extends Schema {
|
|
|
46
69
|
this.init(more);
|
|
47
70
|
this.blocks.updateAll(blocks);
|
|
48
71
|
|
|
49
|
-
|
|
50
72
|
// 再开启change监听
|
|
51
73
|
this.willDetach = this.initChangeListener();
|
|
52
74
|
}
|
|
@@ -56,20 +78,20 @@ export default class BlocksSchema extends Schema {
|
|
|
56
78
|
return this.type;
|
|
57
79
|
}
|
|
58
80
|
|
|
59
|
-
|
|
60
|
-
getTablePanel() {
|
|
81
|
+
getPanel() {
|
|
61
82
|
return this.blocks;
|
|
62
83
|
}
|
|
63
84
|
|
|
64
85
|
getAllJSON() {
|
|
65
86
|
const res = super.getAllJSON();
|
|
66
|
-
return { ...res, type: 'blocks'
|
|
87
|
+
return { ...res, type: 'blocks' };
|
|
67
88
|
}
|
|
68
89
|
|
|
69
90
|
toJSON() {
|
|
91
|
+
const toJSONKey = BlocksSchema.BlocksInfoMap[this.type].toJSONKey;
|
|
70
92
|
return {
|
|
71
93
|
type: this.type,
|
|
72
|
-
blocks: this.blocks.getJSON()
|
|
94
|
+
blocks: this.blocks.getJSON()[toJSONKey], // 与 TableSchema constructor 中 的 key 对应
|
|
73
95
|
};
|
|
74
96
|
}
|
|
75
97
|
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/* eslint-disable indent */
|
|
2
|
-
import JSONWatch from '
|
|
2
|
+
import JSONWatch from '$src/utils/JSONWatch';
|
|
3
3
|
|
|
4
4
|
export default class TableSchema extends JSONWatch {
|
|
5
5
|
constructor(props) {
|
|
6
6
|
super({
|
|
7
|
-
columns: props, // 与 BlockSchema 中的 toJSON 对应
|
|
7
|
+
columns: props, // 与 BlockSchema 中的 toJSON toJSONKey 对应
|
|
8
8
|
});
|
|
9
|
-
|
|
10
9
|
}
|
|
11
10
|
|
|
12
11
|
setFieldsAll(columns, ignoreUpdate = false) {
|
|
@@ -50,7 +49,7 @@ export default class TableSchema extends JSONWatch {
|
|
|
50
49
|
this.emit('$updated');
|
|
51
50
|
}
|
|
52
51
|
|
|
53
|
-
delete() {
|
|
52
|
+
delete() {}
|
|
54
53
|
|
|
55
54
|
getJSON() {
|
|
56
55
|
return super.getJSON();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import JSONWatch from '
|
|
1
|
+
import JSONWatch from '$src/utils/JSONWatch';
|
|
2
2
|
|
|
3
3
|
export default class DetailItemSchema extends JSONWatch {
|
|
4
4
|
constructor(props) {
|
|
@@ -20,7 +20,7 @@ export default class DetailItemSchema extends JSONWatch {
|
|
|
20
20
|
current = 1, // 步骤条,当前步数
|
|
21
21
|
columnsDirection = 'row', // 分栏组件 方向,默认横向分栏
|
|
22
22
|
columnsBoxes = [],
|
|
23
|
-
|
|
23
|
+
height = 100,
|
|
24
24
|
...more
|
|
25
25
|
} = props || {};
|
|
26
26
|
super({
|
|
@@ -41,7 +41,7 @@ export default class DetailItemSchema extends JSONWatch {
|
|
|
41
41
|
current,
|
|
42
42
|
columnsDirection,
|
|
43
43
|
columnsBoxes,
|
|
44
|
-
|
|
44
|
+
height,
|
|
45
45
|
...more,
|
|
46
46
|
});
|
|
47
47
|
}
|
|
@@ -143,7 +143,7 @@ export default class DetailItemSchema extends JSONWatch {
|
|
|
143
143
|
* {array} actionColumns 操作列
|
|
144
144
|
* {object} pagination 分页
|
|
145
145
|
*/
|
|
146
|
-
if (['columnsBoxes','columns', 'actionColumns', 'bulkActions'].includes(key)) {
|
|
146
|
+
if (['columnsBoxes', 'columns', 'actionColumns', 'bulkActions'].includes(key)) {
|
|
147
147
|
this.data[key].splice(index, 1, record);
|
|
148
148
|
} else {
|
|
149
149
|
this.data[key] = record;
|
|
@@ -195,5 +195,5 @@ export default class DetailItemSchema extends JSONWatch {
|
|
|
195
195
|
this.emit('$updated');
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
-
delete() {
|
|
198
|
+
delete() {}
|
|
199
199
|
}
|