ronds-metadata 1.2.25 → 1.2.26
Sign up to get free protection for your applications and to get access to all the features.
- package/es/comps/FormGenerator/index.js +16 -1
- package/es/comps/FormGenerator/transformer.d.ts +1 -1
- package/es/comps/FormGenerator/transformer.js +17 -5
- package/es/comps/MetadataForm/DataCell/layout/TableArray.js +34 -4
- package/es/framework/fg/index.d.ts +120 -0
- package/es/framework/fg/index.js +301 -0
- package/es/framework/fg/utils.d.ts +14 -0
- package/es/framework/fg/utils.js +44 -0
- package/es/utils.d.ts +7 -0
- package/es/utils.js +43 -1
- package/package.json +1 -1
@@ -4,7 +4,7 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
4
4
|
/*
|
5
5
|
* @Author: wangxian
|
6
6
|
* @Date: 2023-02-04 13:45:31
|
7
|
-
* @LastEditTime: 2023-
|
7
|
+
* @LastEditTime: 2023-03-23 13:53:13
|
8
8
|
*/
|
9
9
|
import React from 'react';
|
10
10
|
import { DndProvider } from 'react-dnd';
|
@@ -18,6 +18,7 @@ import useMemoSubject from '../../framework/rxjs-hooks/useMemoSubject';
|
|
18
18
|
import useObservable from '../../framework/rxjs-hooks/useObservable';
|
19
19
|
import { streamEventType } from './settings';
|
20
20
|
import { transSchema2FG } from './transformer';
|
21
|
+
import { FormRobot } from '../../framework/fg/index';
|
21
22
|
|
22
23
|
var FormGenerator = function FormGenerator(props) {
|
23
24
|
var defaultSchema = props.defaultSchema;
|
@@ -29,6 +30,20 @@ var FormGenerator = function FormGenerator(props) {
|
|
29
30
|
setTypes = _React$useState2[1];
|
30
31
|
|
31
32
|
var typesRef = React.useRef({});
|
33
|
+
React.useEffect(function () {
|
34
|
+
var robot = new FormRobot();
|
35
|
+
|
36
|
+
var name = robot.input('name').label('名称').require().placeholder('请输入名称').valueOf();
|
37
|
+
|
38
|
+
var age = robot.input('age').label('年龄').defaultValue(1).valueOf();
|
39
|
+
var address = robot.textarea('address').label('地址').help('详细地址').valueOf();
|
40
|
+
var sex = robot.select('sex').label('性别').valueOf();
|
41
|
+
|
42
|
+
var birthday = robot.date('birthday').label('出身年月').require().valueOf();
|
43
|
+
|
44
|
+
var detail = robot.object([name, age], 'detail').valueOf();
|
45
|
+
var arr = robot.create([name, age, address, sex, birthday, detail]);
|
46
|
+
}, []);
|
32
47
|
React.useEffect(function () {
|
33
48
|
if (defaultSchema) {
|
34
49
|
var defaultValue = transSchema2FG(defaultSchema);
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { FG } from '../../comps/FormGenerator/index.d';
|
2
|
-
export declare const transFG2Schema: (nodes: FG.Node[], settings
|
2
|
+
export declare const transFG2Schema: (nodes: FG.Node[], settings?: any, _types?: any, schemaId?: string) => any;
|
3
3
|
export declare const transSchema2FG: (schema: any) => {
|
4
4
|
nodes: any[];
|
5
5
|
settings: {};
|
@@ -4,7 +4,7 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
4
4
|
/*
|
5
5
|
* @Author: wangxian
|
6
6
|
* @Date: 2023-02-08 14:45:46
|
7
|
-
* @LastEditTime: 2023-03-
|
7
|
+
* @LastEditTime: 2023-03-22 11:28:46
|
8
8
|
*/
|
9
9
|
import { deepClone } from '../../utils';
|
10
10
|
import { basicComps, complexComps, layoutComps } from './settings';
|
@@ -70,11 +70,22 @@ export var transFG2Schema = function transFG2Schema(nodes, settings, _types, sch
|
|
70
70
|
schema[0].id = schemaId;
|
71
71
|
}
|
72
72
|
|
73
|
+
var __types__ = _types || {};
|
74
|
+
|
73
75
|
var props = [];
|
74
76
|
var types = [];
|
75
77
|
|
76
78
|
for (var i = 0; i < nodes.length; i++) {
|
77
|
-
var
|
79
|
+
var _nodes$i, _nodes$i$param;
|
80
|
+
|
81
|
+
if ((_nodes$i = nodes[i]) === null || _nodes$i === void 0 ? void 0 : (_nodes$i$param = _nodes$i.param) === null || _nodes$i$param === void 0 ? void 0 : _nodes$i$param.types) {
|
82
|
+
__types__[nodes[i].id] = {
|
83
|
+
id: nodes[i].id,
|
84
|
+
nodes: nodes[i].param.types
|
85
|
+
};
|
86
|
+
}
|
87
|
+
|
88
|
+
var _prop = renderProp(nodes[i], settings ? settings[nodes[i].id] : nodes[i].param.setting);
|
78
89
|
|
79
90
|
props.push(_prop);
|
80
91
|
}
|
@@ -87,11 +98,12 @@ export var transFG2Schema = function transFG2Schema(nodes, settings, _types, sch
|
|
87
98
|
delete schema[0].fields;
|
88
99
|
}
|
89
100
|
|
90
|
-
if (
|
91
|
-
var typeKeys = Object.keys(
|
101
|
+
if (__types__) {
|
102
|
+
var typeKeys = Object.keys(__types__);
|
92
103
|
|
93
104
|
for (var _i = 0; _i < typeKeys.length; _i++) {
|
94
|
-
var _type = transFG2Schema(
|
105
|
+
var _type = transFG2Schema(__types__[typeKeys[_i]].nodes, // 没有传入内部类的情况 不需要传
|
106
|
+
_types && settings["".concat(typeKeys[_i], "_ref")], undefined, "".concat(__types__[typeKeys[_i]].id, "_ref"));
|
95
107
|
|
96
108
|
types.push(_type[0]);
|
97
109
|
}
|
@@ -1,5 +1,7 @@
|
|
1
1
|
import "antd/es/form/style";
|
2
2
|
import _Form from "antd/es/form";
|
3
|
+
import "antd/es/tag/style";
|
4
|
+
import _Tag from "antd/es/tag";
|
3
5
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
4
6
|
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
5
7
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
@@ -13,7 +15,7 @@ import Editable from '../../../../comps/Editable';
|
|
13
15
|
import useObservable from '../../../../framework/rxjs-hooks/useObservable';
|
14
16
|
import { MetadataFormContext } from '../../interface';
|
15
17
|
import { assign, getLabelByProps } from '../../utils';
|
16
|
-
import { deepClone } from '../../../../utils';
|
18
|
+
import { deepClone, getConstantValue } from '../../../../utils';
|
17
19
|
import { STREAM_EVENT_TYPE } from '../../constants';
|
18
20
|
|
19
21
|
var TableArray = function TableArray(props) {
|
@@ -56,6 +58,13 @@ var TableArray = function TableArray(props) {
|
|
56
58
|
setList = _React$useState10[1];
|
57
59
|
|
58
60
|
var listRef = React.useRef([]);
|
61
|
+
|
62
|
+
var _React$useState11 = React.useState({}),
|
63
|
+
_React$useState12 = _slicedToArray(_React$useState11, 2),
|
64
|
+
enumOptions = _React$useState12[0],
|
65
|
+
setEnumOptions = _React$useState12[1];
|
66
|
+
|
67
|
+
var enumOptionsRef = React.useRef({});
|
59
68
|
useObservable(function (p) {
|
60
69
|
if ((p === null || p === void 0 ? void 0 : p.type) === 'setFieldsValue') {
|
61
70
|
if (typeof name === 'string' && p.payload[name]) {
|
@@ -285,6 +294,8 @@ var TableArray = function TableArray(props) {
|
|
285
294
|
_options.push(obj);
|
286
295
|
});
|
287
296
|
|
297
|
+
enumOptionsRef.current[data.id] = _options;
|
298
|
+
setEnumOptions(_objectSpread({}, enumOptionsRef.current));
|
288
299
|
return _options;
|
289
300
|
}, []);
|
290
301
|
var processColumnType = React.useCallback(function (data, _extraInfo) {
|
@@ -301,7 +312,7 @@ var TableArray = function TableArray(props) {
|
|
301
312
|
var processSchemaToColumns = React.useCallback(function (_properties) {
|
302
313
|
var _columns = [];
|
303
314
|
|
304
|
-
|
315
|
+
var _loop = function _loop(i) {
|
305
316
|
var _extraInfo$common, _extraInfo$enum5;
|
306
317
|
|
307
318
|
var it = _properties[i];
|
@@ -314,14 +325,33 @@ var TableArray = function TableArray(props) {
|
|
314
325
|
editable: !(extraInfo === null || extraInfo === void 0 ? void 0 : (_extraInfo$common = extraInfo.common) === null || _extraInfo$common === void 0 ? void 0 : _extraInfo$common.disabled),
|
315
326
|
type: processColumnType(it, extraInfo),
|
316
327
|
enum: it.type === 'enum' ? processEnumData(it, extraInfo) : undefined,
|
317
|
-
mode: (extraInfo === null || extraInfo === void 0 ? void 0 : (_extraInfo$enum5 = extraInfo.enum) === null || _extraInfo$enum5 === void 0 ? void 0 : _extraInfo$enum5.isMutiple) ? 'multiple' : undefined
|
328
|
+
mode: (extraInfo === null || extraInfo === void 0 ? void 0 : (_extraInfo$enum5 = extraInfo.enum) === null || _extraInfo$enum5 === void 0 ? void 0 : _extraInfo$enum5.isMutiple) ? 'multiple' : undefined,
|
329
|
+
render: function render(val) {
|
330
|
+
if (it.type = 'enum') {
|
331
|
+
if (Array.isArray(val)) {
|
332
|
+
return val.map(function (v) {
|
333
|
+
return /*#__PURE__*/React.createElement(_Tag, {
|
334
|
+
color: "geekblue"
|
335
|
+
}, getConstantValue(enumOptionsRef.current[it.id], v, 'value', 'label'));
|
336
|
+
});
|
337
|
+
}
|
338
|
+
|
339
|
+
return getConstantValue(enumOptionsRef.current[it.id], val, 'value', 'label');
|
340
|
+
}
|
341
|
+
|
342
|
+
return val;
|
343
|
+
}
|
318
344
|
};
|
319
345
|
|
320
346
|
_columns.push(obj);
|
347
|
+
};
|
348
|
+
|
349
|
+
for (var i = 0; i < _properties.length; i++) {
|
350
|
+
_loop(i);
|
321
351
|
}
|
322
352
|
|
323
353
|
return _columns;
|
324
|
-
}, []);
|
354
|
+
}, [enumOptions]);
|
325
355
|
var columns = React.useMemo(function () {
|
326
356
|
var _columns = [];
|
327
357
|
|
@@ -0,0 +1,120 @@
|
|
1
|
+
import { FG } from '../../comps/FormGenerator/index.d';
|
2
|
+
interface ICreate {
|
3
|
+
create(data: any): ILayoutSetting & IReturnMethod;
|
4
|
+
}
|
5
|
+
interface ILayoutSetting {
|
6
|
+
grid<T>(this: T, _value: 1 | 2 | 3 | 4): Omit<T, 'grid'> & IReturnMethod;
|
7
|
+
labelSpan<T>(this: T, _value: number): Omit<T, 'labelSpan'> & IReturnMethod;
|
8
|
+
}
|
9
|
+
interface IComps {
|
10
|
+
object(data: FG.Node[] | any, _id: string): ICommonSetting & IReturnMethod;
|
11
|
+
input(_id: string): ICommonSetting;
|
12
|
+
textarea(_id: string): ICommonSetting;
|
13
|
+
date(_id: string): ICommonSetting;
|
14
|
+
number(_id: string): ICommonSetting;
|
15
|
+
switch(_id: string): ICommonSetting;
|
16
|
+
select(_id: string): ICommonSetting;
|
17
|
+
mutiSelect(_id: string): ICommonSetting;
|
18
|
+
}
|
19
|
+
interface ICommonSetting {
|
20
|
+
label<T>(this: T, _label: string): Omit<T, 'label'> & IReturnMethod;
|
21
|
+
require<T>(this: T): Omit<T, 'require'> & IReturnMethod;
|
22
|
+
disabled<T>(this: T): Omit<T, 'disabled'> & IReturnMethod;
|
23
|
+
hidden<T>(this: T): Omit<T, 'hidden'> & IReturnMethod;
|
24
|
+
br<T>(this: T): Omit<T, 'br'> & IReturnMethod;
|
25
|
+
color<T>(this: T, _color: string): Omit<T, 'color'> & IReturnMethod;
|
26
|
+
colSpan<T>(this: T, _colSpan: number): Omit<T, 'colSpan'> & IReturnMethod;
|
27
|
+
defaultValue<T>(this: T, _defaultValue: any): Omit<T, 'defaultValue'> & IReturnMethod;
|
28
|
+
help<T>(this: T, _help: string): Omit<T, 'help'> & IReturnMethod;
|
29
|
+
tooltip<T>(this: T, _tooltip: string): Omit<T, 'tooltip'> & IReturnMethod;
|
30
|
+
placeholder<T>(this: T, _placeholder: string): Omit<T, 'placeholder'> & IReturnMethod;
|
31
|
+
}
|
32
|
+
interface IReturnMethod {
|
33
|
+
valueOf(): void;
|
34
|
+
toString(): void;
|
35
|
+
}
|
36
|
+
export declare type IFormRobot = ICreate & IComps;
|
37
|
+
/**
|
38
|
+
* 链式调用 组件元数据表单的机器人
|
39
|
+
*/
|
40
|
+
export declare class FormRobot implements IFormRobot {
|
41
|
+
/**
|
42
|
+
* 构建每个字段的值
|
43
|
+
*/
|
44
|
+
_data: FG.Node | FG.Node[];
|
45
|
+
/**
|
46
|
+
* 用来判断是否已经初始化过数据
|
47
|
+
*/
|
48
|
+
_hasInitData: boolean;
|
49
|
+
constructor(data?: FG.Node | FG.Node[]);
|
50
|
+
/**
|
51
|
+
* 创建表单的入口
|
52
|
+
* @param arr
|
53
|
+
* @returns
|
54
|
+
*/
|
55
|
+
create(arr: FG.Node[]): ILayoutSetting & IReturnMethod;
|
56
|
+
/**
|
57
|
+
* 对象类型 创建表单的入口
|
58
|
+
* @param _id 属性名
|
59
|
+
* @returns
|
60
|
+
*/
|
61
|
+
object(arr: FG.Node[], _id: string): ICommonSetting & IReturnMethod;
|
62
|
+
/**
|
63
|
+
* 输入框
|
64
|
+
* @param _id 属性名
|
65
|
+
* @returns
|
66
|
+
*/
|
67
|
+
input(_id: string): ICommonSetting;
|
68
|
+
/**
|
69
|
+
* 文本框
|
70
|
+
* @param _id
|
71
|
+
* @returns
|
72
|
+
*/
|
73
|
+
textarea(_id: string): ICommonSetting;
|
74
|
+
/**
|
75
|
+
* 日期选择
|
76
|
+
* @param _id
|
77
|
+
* @returns
|
78
|
+
*/
|
79
|
+
date(_id: string): ICommonSetting;
|
80
|
+
/**
|
81
|
+
* 数字框
|
82
|
+
* @param _id
|
83
|
+
* @returns
|
84
|
+
*/
|
85
|
+
number(_id: string): ICommonSetting;
|
86
|
+
/**
|
87
|
+
* 开关
|
88
|
+
* @param _id
|
89
|
+
* @returns
|
90
|
+
*/
|
91
|
+
switch(_id: string): ICommonSetting;
|
92
|
+
/**
|
93
|
+
* 下拉单选
|
94
|
+
* @param _id
|
95
|
+
* @returns
|
96
|
+
*/
|
97
|
+
select(_id: string): ICommonSetting;
|
98
|
+
/**
|
99
|
+
* 下拉多选
|
100
|
+
* @param _id
|
101
|
+
* @returns
|
102
|
+
*/
|
103
|
+
mutiSelect(_id: string): ICommonSetting;
|
104
|
+
label<T>(this: T, _vaule: string): Omit<T, 'label'> & IReturnMethod;
|
105
|
+
require<T>(this: T): Omit<T, 'require'> & IReturnMethod;
|
106
|
+
color<T>(this: T, _vaule: string): Omit<T, 'color'> & IReturnMethod;
|
107
|
+
colSpan<T>(this: T, _vaule: number): Omit<T, 'colSpan'> & IReturnMethod;
|
108
|
+
defaultValue<T>(this: T, _vaule: number | string): Omit<T, 'defaultValue'> & IReturnMethod;
|
109
|
+
help<T>(this: T, _vaule: string): Omit<T, 'help'> & IReturnMethod;
|
110
|
+
tooltip<T>(this: T, _vaule: string): Omit<T, 'tooltip'> & IReturnMethod;
|
111
|
+
placeholder<T>(this: T, _vaule: string): Omit<T, 'placeholder'> & IReturnMethod;
|
112
|
+
disabled<T>(this: T): Omit<T, 'disabled'> & IReturnMethod;
|
113
|
+
br<T>(this: T): Omit<T, 'br'> & IReturnMethod;
|
114
|
+
hidden<T>(this: T): Omit<T, 'hidden'> & IReturnMethod;
|
115
|
+
grid<T>(this: T, _vaule: 1 | 2 | 3 | 4): Omit<T, 'grid'> & IReturnMethod;
|
116
|
+
valueOf(): any;
|
117
|
+
toString(): string;
|
118
|
+
}
|
119
|
+
declare const _default: FormRobot;
|
120
|
+
export default _default;
|
@@ -0,0 +1,301 @@
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
3
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
4
|
+
|
5
|
+
/* eslint-disable */
|
6
|
+
import { transFG2Schema } from '@/comps/FormGenerator/transformer';
|
7
|
+
import { renderBasicFormProps, renderLayoutFormProps, renderSetting } from './utils';
|
8
|
+
/**
|
9
|
+
* 链式调用 组件元数据表单的机器人
|
10
|
+
*/
|
11
|
+
|
12
|
+
export var FormRobot = /*#__PURE__*/function () {
|
13
|
+
/**
|
14
|
+
* 构建每个字段的值
|
15
|
+
*/
|
16
|
+
|
17
|
+
/**
|
18
|
+
* 用来判断是否已经初始化过数据
|
19
|
+
*/
|
20
|
+
function FormRobot(data) {
|
21
|
+
_classCallCheck(this, FormRobot);
|
22
|
+
|
23
|
+
this._data = void 0;
|
24
|
+
this._hasInitData = void 0;
|
25
|
+
|
26
|
+
/**
|
27
|
+
* 构造函数 正式判断是够已经初始化数据
|
28
|
+
* data -> 如果存在,则作为初始化数据
|
29
|
+
*/
|
30
|
+
this._hasInitData = true;
|
31
|
+
|
32
|
+
if (data === undefined) {
|
33
|
+
this._data = null;
|
34
|
+
this._hasInitData = false;
|
35
|
+
} else {
|
36
|
+
this._data = data;
|
37
|
+
}
|
38
|
+
}
|
39
|
+
/**
|
40
|
+
* 创建表单的入口
|
41
|
+
* @param arr
|
42
|
+
* @returns
|
43
|
+
*/
|
44
|
+
|
45
|
+
|
46
|
+
_createClass(FormRobot, [{
|
47
|
+
key: "create",
|
48
|
+
value: function create(arr) {
|
49
|
+
var _init = this._hasInitData ? this._data : [];
|
50
|
+
|
51
|
+
var _data = [].concat(_toConsumableArray(_init), _toConsumableArray(arr));
|
52
|
+
|
53
|
+
return new FormRobot(_data);
|
54
|
+
} //*********************************表单基本类型__START************************************//
|
55
|
+
|
56
|
+
/**
|
57
|
+
* 对象类型 创建表单的入口
|
58
|
+
* @param _id 属性名
|
59
|
+
* @returns
|
60
|
+
*/
|
61
|
+
|
62
|
+
}, {
|
63
|
+
key: "object",
|
64
|
+
value: function object(arr, _id) {
|
65
|
+
var _data = renderLayoutFormProps(arr, _id, 'obj');
|
66
|
+
|
67
|
+
return new FormRobot(_data);
|
68
|
+
}
|
69
|
+
/**
|
70
|
+
* 输入框
|
71
|
+
* @param _id 属性名
|
72
|
+
* @returns
|
73
|
+
*/
|
74
|
+
|
75
|
+
}, {
|
76
|
+
key: "input",
|
77
|
+
value: function input(_id) {
|
78
|
+
var _data = renderBasicFormProps(_id, 'input');
|
79
|
+
|
80
|
+
return new FormRobot(_data);
|
81
|
+
}
|
82
|
+
/**
|
83
|
+
* 文本框
|
84
|
+
* @param _id
|
85
|
+
* @returns
|
86
|
+
*/
|
87
|
+
|
88
|
+
}, {
|
89
|
+
key: "textarea",
|
90
|
+
value: function textarea(_id) {
|
91
|
+
var _data = renderBasicFormProps(_id, 'textarea');
|
92
|
+
|
93
|
+
return new FormRobot(_data);
|
94
|
+
}
|
95
|
+
/**
|
96
|
+
* 日期选择
|
97
|
+
* @param _id
|
98
|
+
* @returns
|
99
|
+
*/
|
100
|
+
|
101
|
+
}, {
|
102
|
+
key: "date",
|
103
|
+
value: function date(_id) {
|
104
|
+
var _data = renderBasicFormProps(_id, 'date');
|
105
|
+
|
106
|
+
return new FormRobot(_data);
|
107
|
+
}
|
108
|
+
/**
|
109
|
+
* 数字框
|
110
|
+
* @param _id
|
111
|
+
* @returns
|
112
|
+
*/
|
113
|
+
|
114
|
+
}, {
|
115
|
+
key: "number",
|
116
|
+
value: function number(_id) {
|
117
|
+
var _data = renderBasicFormProps(_id, 'number');
|
118
|
+
|
119
|
+
return new FormRobot(_data);
|
120
|
+
}
|
121
|
+
/**
|
122
|
+
* 开关
|
123
|
+
* @param _id
|
124
|
+
* @returns
|
125
|
+
*/
|
126
|
+
|
127
|
+
}, {
|
128
|
+
key: "switch",
|
129
|
+
value: function _switch(_id) {
|
130
|
+
var _data = renderBasicFormProps(_id, 'switch');
|
131
|
+
|
132
|
+
return new FormRobot(_data);
|
133
|
+
}
|
134
|
+
/**
|
135
|
+
* 下拉单选
|
136
|
+
* @param _id
|
137
|
+
* @returns
|
138
|
+
*/
|
139
|
+
|
140
|
+
}, {
|
141
|
+
key: "select",
|
142
|
+
value: function select(_id) {
|
143
|
+
var _data = renderBasicFormProps(_id, 'select');
|
144
|
+
|
145
|
+
return new FormRobot(_data);
|
146
|
+
}
|
147
|
+
/**
|
148
|
+
* 下拉多选
|
149
|
+
* @param _id
|
150
|
+
* @returns
|
151
|
+
*/
|
152
|
+
|
153
|
+
}, {
|
154
|
+
key: "mutiSelect",
|
155
|
+
value: function mutiSelect(_id) {
|
156
|
+
var _data = renderBasicFormProps(_id, 'mutiSelect');
|
157
|
+
|
158
|
+
return new FormRobot(_data);
|
159
|
+
} //*********************************表单基本类型__END************************************//
|
160
|
+
//*********************************提供的扩展规则完善表单__START************************************//
|
161
|
+
// 标签显示文本
|
162
|
+
|
163
|
+
}, {
|
164
|
+
key: "label",
|
165
|
+
value: function label(_vaule) {
|
166
|
+
var _init = this._hasInitData ? this._data : {};
|
167
|
+
|
168
|
+
var _data = renderSetting(_init, 'label', _vaule);
|
169
|
+
|
170
|
+
return new FormRobot(_data);
|
171
|
+
}
|
172
|
+
}, {
|
173
|
+
key: "require",
|
174
|
+
value: function require() {
|
175
|
+
var _init = this._hasInitData ? this._data : {};
|
176
|
+
|
177
|
+
var _data = renderSetting(_init, 'require', true);
|
178
|
+
|
179
|
+
return new FormRobot(_data);
|
180
|
+
}
|
181
|
+
}, {
|
182
|
+
key: "color",
|
183
|
+
value: function color(_vaule) {
|
184
|
+
var _init = this._hasInitData ? this._data : {};
|
185
|
+
|
186
|
+
var _data = renderSetting(_init, 'color', _vaule);
|
187
|
+
|
188
|
+
return new FormRobot(_data);
|
189
|
+
}
|
190
|
+
}, {
|
191
|
+
key: "colSpan",
|
192
|
+
value: function colSpan(_vaule) {
|
193
|
+
var _init = this._hasInitData ? this._data : {};
|
194
|
+
|
195
|
+
var _data = renderSetting(_init, 'colSpan', _vaule);
|
196
|
+
|
197
|
+
return new FormRobot(_data);
|
198
|
+
}
|
199
|
+
}, {
|
200
|
+
key: "defaultValue",
|
201
|
+
value: function defaultValue(_vaule) {
|
202
|
+
var _init = this._hasInitData ? this._data : {};
|
203
|
+
|
204
|
+
var _data = renderSetting(_init, 'defaultValue', _vaule);
|
205
|
+
|
206
|
+
return new FormRobot(_data);
|
207
|
+
}
|
208
|
+
}, {
|
209
|
+
key: "help",
|
210
|
+
value: function help(_vaule) {
|
211
|
+
var _init = this._hasInitData ? this._data : {};
|
212
|
+
|
213
|
+
var _data = renderSetting(_init, 'help', _vaule);
|
214
|
+
|
215
|
+
return new FormRobot(_data);
|
216
|
+
}
|
217
|
+
}, {
|
218
|
+
key: "tooltip",
|
219
|
+
value: function tooltip(_vaule) {
|
220
|
+
var _init = this._hasInitData ? this._data : {};
|
221
|
+
|
222
|
+
var _data = renderSetting(_init, 'tooltip', _vaule);
|
223
|
+
|
224
|
+
return new FormRobot(_data);
|
225
|
+
}
|
226
|
+
}, {
|
227
|
+
key: "placeholder",
|
228
|
+
value: function placeholder(_vaule) {
|
229
|
+
var _init = this._hasInitData ? this._data : {};
|
230
|
+
|
231
|
+
var _data = renderSetting(_init, 'placeholder', _vaule);
|
232
|
+
|
233
|
+
return new FormRobot(_data);
|
234
|
+
}
|
235
|
+
}, {
|
236
|
+
key: "disabled",
|
237
|
+
value: function disabled() {
|
238
|
+
var _init = this._hasInitData ? this._data : {};
|
239
|
+
|
240
|
+
var _data = renderSetting(_init, 'disabled', true);
|
241
|
+
|
242
|
+
return new FormRobot(_data);
|
243
|
+
}
|
244
|
+
}, {
|
245
|
+
key: "br",
|
246
|
+
value: function br() {
|
247
|
+
var _init = this._hasInitData ? this._data : {};
|
248
|
+
|
249
|
+
var _data = renderSetting(_init, 'br', true);
|
250
|
+
|
251
|
+
return new FormRobot(_data);
|
252
|
+
}
|
253
|
+
}, {
|
254
|
+
key: "hidden",
|
255
|
+
value: function hidden() {
|
256
|
+
var _init = this._hasInitData ? this._data : {};
|
257
|
+
|
258
|
+
var _data = renderSetting(_init, 'hidden', true);
|
259
|
+
|
260
|
+
return new FormRobot(_data);
|
261
|
+
} //*********************************提供的扩展规则完善表单__END************************************//
|
262
|
+
//*********************************表单布局的扩展规则__START************************************//
|
263
|
+
|
264
|
+
}, {
|
265
|
+
key: "grid",
|
266
|
+
value: function grid(_vaule) {
|
267
|
+
var _init = this._hasInitData ? this._data : {};
|
268
|
+
|
269
|
+
var _data = renderSetting(_init, 'colSpan', _vaule);
|
270
|
+
|
271
|
+
return new FormRobot(_data);
|
272
|
+
} //*********************************表单布局的扩展规则__END************************************//
|
273
|
+
//*********************************拿到最终的数据方法__START************************************//
|
274
|
+
|
275
|
+
}, {
|
276
|
+
key: "valueOf",
|
277
|
+
value: function valueOf() {
|
278
|
+
if (Array.isArray(this._data)) {
|
279
|
+
//是数组,说明是create方法,需要转换成元数据
|
280
|
+
return transFG2Schema(this._data);
|
281
|
+
} else {
|
282
|
+
return this._data;
|
283
|
+
}
|
284
|
+
}
|
285
|
+
}, {
|
286
|
+
key: "toString",
|
287
|
+
value: function toString() {
|
288
|
+
return JSON.stringify(this.valueOf());
|
289
|
+
}
|
290
|
+
}]);
|
291
|
+
|
292
|
+
return FormRobot;
|
293
|
+
}();
|
294
|
+
export default new FormRobot();
|
295
|
+
var fr = new FormRobot();
|
296
|
+
/* fr.object([
|
297
|
+
* fr.input('name').label('名称').valueOf(),
|
298
|
+
* fr.object([
|
299
|
+
* fr.input('id').label('主键').valueOf()
|
300
|
+
* ], 'detail')]);
|
301
|
+
*/
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { FG } from '../../comps/FormGenerator/index.d';
|
2
|
+
export declare const renderBasicFormProps: (_id: string, _type: string) => {
|
3
|
+
id: string;
|
4
|
+
name: string;
|
5
|
+
type: string;
|
6
|
+
param: FG.NodeParam;
|
7
|
+
};
|
8
|
+
export declare const renderLayoutFormProps: (_arr: FG.Node[], _id: string, _type: string) => {
|
9
|
+
id: string;
|
10
|
+
name: string;
|
11
|
+
type: string;
|
12
|
+
param: FG.NodeParam;
|
13
|
+
};
|
14
|
+
export declare const renderSetting: (_init: FG.Node, _type: string, _value: string | number | boolean) => FG.Node;
|
@@ -0,0 +1,44 @@
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
2
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
3
|
+
|
4
|
+
/*
|
5
|
+
* @Author: wangxian
|
6
|
+
* @Date: 2023-03-21 15:44:45
|
7
|
+
* @LastEditTime: 2023-03-22 09:20:34
|
8
|
+
*/
|
9
|
+
import { deepClone } from '../../utils';
|
10
|
+
import { basicComps, layoutComps } from './../../comps/FormGenerator/settings/index';
|
11
|
+
export var renderBasicFormProps = function renderBasicFormProps(_id, _type) {
|
12
|
+
var _basicComps = deepClone(basicComps);
|
13
|
+
|
14
|
+
var _ = _basicComps.find(function (it) {
|
15
|
+
return it.type === _type;
|
16
|
+
}) || {};
|
17
|
+
|
18
|
+
delete _.param.schema;
|
19
|
+
return _objectSpread(_objectSpread({}, _), {}, {
|
20
|
+
id: _id
|
21
|
+
});
|
22
|
+
};
|
23
|
+
export var renderLayoutFormProps = function renderLayoutFormProps(_arr, _id, _type) {
|
24
|
+
var _layoutComps = deepClone(layoutComps);
|
25
|
+
|
26
|
+
var _ = _layoutComps.find(function (it) {
|
27
|
+
return it.type === _type;
|
28
|
+
}) || {};
|
29
|
+
|
30
|
+
delete _.param.schema;
|
31
|
+
_.param.types = _arr;
|
32
|
+
return _objectSpread(_objectSpread({}, _), {}, {
|
33
|
+
id: _id
|
34
|
+
});
|
35
|
+
};
|
36
|
+
export var renderSetting = function renderSetting(_init, _type, _value) {
|
37
|
+
var _ = _objectSpread(_objectSpread({}, _init), {}, {
|
38
|
+
param: _objectSpread(_objectSpread({}, _init === null || _init === void 0 ? void 0 : _init.param), {}, {
|
39
|
+
setting: _objectSpread(_objectSpread({}, _init.param.setting), {}, _defineProperty({}, _type, _value))
|
40
|
+
})
|
41
|
+
});
|
42
|
+
|
43
|
+
return _;
|
44
|
+
};
|
package/es/utils.d.ts
CHANGED
@@ -17,3 +17,10 @@ export declare const md5: (data: string, digest?: string) => any;
|
|
17
17
|
export declare function arrayMoveMutable(array: any[], fromIndex: number, toIndex: number): void;
|
18
18
|
export declare function arrayMoveImmutable(array: any[], fromIndex: number, toIndex: number): any[];
|
19
19
|
export declare function arrayInsert(array: any[], index: number, item: any): any[];
|
20
|
+
/**
|
21
|
+
* 调用时不用把参数补全; getValue(array, key) 一样可以调用
|
22
|
+
* @param array 数组
|
23
|
+
* @param key 指定的数值
|
24
|
+
* @returns {string|string|string}
|
25
|
+
*/
|
26
|
+
export declare function getConstantValue(array: any[], key: string | number, strKey?: string, strValue?: string): string;
|
package/es/utils.js
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
+
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
1
2
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
2
3
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
3
4
|
|
4
5
|
/*
|
5
6
|
* @Author: wangxian
|
6
7
|
* @Date: 2021-09-18 14:15:04
|
7
|
-
* @LastEditTime: 2023-
|
8
|
+
* @LastEditTime: 2023-03-24 09:49:51
|
8
9
|
*/
|
9
10
|
import { useCallback, useEffect, useRef } from 'react';
|
10
11
|
/** 防抖 */
|
@@ -135,4 +136,45 @@ export function arrayMoveImmutable(array, fromIndex, toIndex) {
|
|
135
136
|
export function arrayInsert(array, index, item) {
|
136
137
|
array.splice(index, 0, item);
|
137
138
|
return array;
|
139
|
+
}
|
140
|
+
/**
|
141
|
+
* 调用时不用把参数补全; getValue(array, key) 一样可以调用
|
142
|
+
* @param array 数组
|
143
|
+
* @param key 指定的数值
|
144
|
+
* @returns {string|string|string}
|
145
|
+
*/
|
146
|
+
|
147
|
+
export function getConstantValue(array, key, strKey, strValue) {
|
148
|
+
var result = '';
|
149
|
+
var _strKey = 'id';
|
150
|
+
var _strValue = 'value';
|
151
|
+
|
152
|
+
if (strKey) {
|
153
|
+
_strKey = strKey;
|
154
|
+
}
|
155
|
+
|
156
|
+
if (strValue) {
|
157
|
+
_strValue = strValue;
|
158
|
+
}
|
159
|
+
|
160
|
+
if (array) {
|
161
|
+
var _iterator = _createForOfIteratorHelper(array),
|
162
|
+
_step;
|
163
|
+
|
164
|
+
try {
|
165
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
166
|
+
var item = _step.value;
|
167
|
+
|
168
|
+
if (key === item[_strKey]) {
|
169
|
+
result = item[_strValue];
|
170
|
+
}
|
171
|
+
}
|
172
|
+
} catch (err) {
|
173
|
+
_iterator.e(err);
|
174
|
+
} finally {
|
175
|
+
_iterator.f();
|
176
|
+
}
|
177
|
+
}
|
178
|
+
|
179
|
+
return result;
|
138
180
|
}
|