ronds-metadata 1.3.3 → 1.3.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,36 +0,0 @@
1
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
- /*
3
- * @Author:wangxian
4
- * @Date: 2022-03-03 16:12:34
5
- * @LastEditTime: 2022-03-28 11:56:36
6
- */
7
- import { MetadataService } from './../../../framework/metadata/MetadataService';
8
- import React from 'react';
9
- export var useMetaType = function useMetaType(tag) {
10
- var isFresh = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
11
- var _React$useState = React.useState([]),
12
- _React$useState2 = _slicedToArray(_React$useState, 2),
13
- metaType = _React$useState2[0],
14
- setMetaType = _React$useState2[1];
15
- React.useEffect(function () {
16
- if (isFresh) {
17
- var service = new MetadataService();
18
- var _tag = tag ? [tag] : [];
19
- service.GetMetadataList(_tag).then(function (res) {
20
- var _metaType = [];
21
- // console.log('res', res);
22
- if (res) {
23
- for (var i = 0; i < res.length; i++) {
24
- var obj = {
25
- label: res[i].name,
26
- value: res[i].id
27
- };
28
- _metaType.push(obj);
29
- }
30
- }
31
- setMetaType([].concat(_metaType));
32
- });
33
- }
34
- }, [tag, isFresh]);
35
- return metaType;
36
- };
@@ -1,25 +0,0 @@
1
- import './index.less';
2
- interface IMetadataEditProps {
3
- /**
4
- * 默认元数据最外层的名称无法编辑
5
- */
6
- isNameDisabled?: boolean;
7
- /**
8
- * 元数据的标签,根据这个标签在元数据库里检索元数据
9
- */
10
- metadataTag?: string;
11
- /**
12
- * 初始化值
13
- */
14
- initialValues?: any;
15
- /**
16
- * 确定点击事件
17
- */
18
- onFinish: (data: string) => void;
19
- /**
20
- * 添加新的引用类型点击事件
21
- */
22
- onNewRefClick?: () => void;
23
- }
24
- declare const MetadataEditV2: (props: IMetadataEditProps) => JSX.Element;
25
- export default MetadataEditV2;
@@ -1,263 +0,0 @@
1
- import "antd/es/drawer/style";
2
- import _Drawer from "antd/es/drawer";
3
- import "antd/es/button/style";
4
- import _Button from "antd/es/button";
5
- import "antd/es/select/style";
6
- import _Select from "antd/es/select";
7
- import "antd/es/input/style";
8
- import _Input from "antd/es/input";
9
- import "antd/es/message/style";
10
- import _message from "antd/es/message";
11
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
12
- import "antd/es/form/style";
13
- import _Form from "antd/es/form";
14
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
15
- import React from 'react';
16
- import './index.less';
17
- import MetaFieldsEdit from './components/MetaFieldsEdit';
18
- import MetaPropsEdit from './components/MetaPropsEdit';
19
- import { OUTERMOST_TYPES_OPTIONS } from './constant';
20
- var MetadataEditV2 = function MetadataEditV2(props) {
21
- var initialValues = props.initialValues,
22
- isNameDisabled = props.isNameDisabled,
23
- metadataTag = props.metadataTag,
24
- onFinish = props.onFinish,
25
- onNewRefClick = props.onNewRefClick;
26
- var _Form$useForm = _Form.useForm(),
27
- _Form$useForm2 = _slicedToArray(_Form$useForm, 1),
28
- form = _Form$useForm2[0];
29
- var _React$useState = React.useState('object'),
30
- _React$useState2 = _slicedToArray(_React$useState, 2),
31
- outerType = _React$useState2[0],
32
- setOutType = _React$useState2[1];
33
- var _React$useState3 = React.useState({
34
- id: '',
35
- type: 'object'
36
- }),
37
- _React$useState4 = _slicedToArray(_React$useState3, 2),
38
- metaSchema = _React$useState4[0],
39
- setMetaSchema = _React$useState4[1];
40
- var metaSchemaRef = React.useRef({
41
- id: '',
42
- type: 'object'
43
- });
44
- var firstLoadRef = React.useRef(true);
45
- var _React$useState5 = React.useState(false),
46
- _React$useState6 = _slicedToArray(_React$useState5, 2),
47
- isFields = _React$useState6[0],
48
- setIsFields = _React$useState6[1];
49
- var _React$useState7 = React.useState({}),
50
- _React$useState8 = _slicedToArray(_React$useState7, 2),
51
- fields = _React$useState8[0],
52
- setFields = _React$useState8[1];
53
- var _React$useState9 = React.useState({}),
54
- _React$useState10 = _slicedToArray(_React$useState9, 2),
55
- curFields = _React$useState10[0],
56
- setCurFields = _React$useState10[1];
57
- React.useEffect(function () {
58
- form.setFieldsValue({
59
- id: 'Test'
60
- });
61
- form.setFieldsValue({
62
- type: 'object'
63
- });
64
- }, [form]);
65
- React.useEffect(function () {
66
- if (initialValues && firstLoadRef.current) {
67
- form.setFieldsValue(_objectSpread({}, initialValues));
68
- setMetaSchema(_objectSpread({}, initialValues));
69
- metaSchemaRef.current = initialValues;
70
- processFileds(initialValues);
71
- firstLoadRef.current = false;
72
- }
73
- }, [form, initialValues]);
74
- var onMyFinish = function onMyFinish(values) {
75
- // console.log('values:', values, JSON.stringify(values));
76
- // console.log('values:', values);
77
- var _metaSchema = metaSchemaRef.current;
78
- _metaSchema.id = values.id;
79
- _metaSchema.type = values.type;
80
- if (values === null || values === void 0 ? void 0 : values.properties) {
81
- _metaSchema.properties = values.properties;
82
- var _loop = function _loop() {
83
- var ele = _metaSchema.properties[i];
84
- var curFields = fields[_metaSchema.properties[i].id];
85
- if (curFields) {
86
- _metaSchema.properties[i].fields = curFields;
87
- }
88
- var propKeys = Object.keys(ele);
89
- var needOptKeys = ['name', 'code', 'desc'];
90
- if (ele.fields) {
91
- propKeys.forEach(function (propKey) {
92
- if (needOptKeys.indexOf(propKey) > -1) {
93
- ele.fields.forEach(function (field, index) {
94
- if (index === 0) {
95
- if (propKey === 'name') {
96
- field.value[propKey] = ele[propKey];
97
- field.value.label = ele[propKey];
98
- } else {
99
- field.value[propKey] = ele[propKey];
100
- }
101
- }
102
- });
103
- delete ele[propKey];
104
- }
105
- });
106
- } else {
107
- ele.fields = [{
108
- type: 'ref',
109
- refId: 'Rule.Form',
110
- id: 'Rule.Form',
111
- value: {
112
- label: '',
113
- name: '',
114
- code: '',
115
- desc: ''
116
- }
117
- }];
118
- propKeys.forEach(function (propKey) {
119
- if (needOptKeys.indexOf(propKey) > -1) {
120
- ele.fields.forEach(function (field, index) {
121
- if (index === 0) {
122
- if (propKey === 'name') {
123
- field.value[propKey] = ele[propKey];
124
- field.value.label = ele[propKey];
125
- } else {
126
- field.value[propKey] = ele[propKey];
127
- }
128
- }
129
- });
130
- delete ele[propKey];
131
- }
132
- });
133
- }
134
- };
135
- for (var i = 0; i < _metaSchema.properties.length; i++) {
136
- _loop();
137
- }
138
- }
139
- if (fields[values.id]) {
140
- _metaSchema.fields = fields[values.id];
141
- }
142
- setMetaSchema(_objectSpread({}, _metaSchema));
143
- metaSchemaRef.current = _metaSchema;
144
- onFinish && onFinish(JSON.stringify(_metaSchema));
145
- };
146
- var onAddFields = function onAddFields(index) {
147
- if (index === -1) {
148
- var _id = form.getFieldValue('id');
149
- if (_id) {
150
- setIsFields(true);
151
- setCurFields({
152
- id: _id
153
- });
154
- } else {
155
- _message.warn('请填写元数据名称');
156
- }
157
- return;
158
- }
159
- // console.log('========1========', form.getFieldValue('properties'));
160
- var _properties_from = form.getFieldValue('properties') || [];
161
- var _properties_ref = metaSchemaRef.current.properties || [];
162
- var _properties = _properties_from.length <= _properties_ref.length ? _properties_ref : _properties_from;
163
- // console.log('properties', _properties);
164
- var _curFields = _properties[index];
165
- if (_curFields && _curFields.id) {
166
- setIsFields(true);
167
- var idx = ((metaSchema === null || metaSchema === void 0 ? void 0 : metaSchema.fields) || []).findIndex(function (v) {
168
- return v.id === _curFields.id;
169
- });
170
- if ((metaSchema === null || metaSchema === void 0 ? void 0 : metaSchema.fields) && idx >= 0) {
171
- setCurFields(_objectSpread({}, metaSchema === null || metaSchema === void 0 ? void 0 : metaSchema.fields[idx]));
172
- } else {
173
- // console.log('_curFields', _curFields);
174
- setCurFields(_objectSpread({}, _curFields));
175
- }
176
- } else {
177
- _message.warn('请填写属性名称');
178
- }
179
- };
180
- var onFieldsChange = function onFieldsChange(values) {
181
- var _fields = fields;
182
- _fields[curFields.id] = values;
183
- setFields(_objectSpread({}, _fields));
184
- setIsFields(false);
185
- };
186
- var onOuterTypeChange = function onOuterTypeChange(value) {
187
- setOutType(value);
188
- };
189
- var processFileds = function processFileds(schema) {
190
- var _properties = schema.properties;
191
- var _fields = fields;
192
- if (_properties) {
193
- for (var i = 0; i < _properties.length; i++) {
194
- if (_properties[i].fields) {
195
- _fields[_properties[i].id] = _properties[i].fields;
196
- }
197
- }
198
- }
199
- if (schema.fields) {
200
- _fields[schema.id] = schema.fields;
201
- }
202
- setFields(_objectSpread({}, _fields));
203
- };
204
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_Form, {
205
- className: "metadata-edit",
206
- initialValues: initialValues,
207
- form: form,
208
- name: "control-hooks",
209
- onFinish: onMyFinish
210
- }, /*#__PURE__*/React.createElement(_Form.Item, {
211
- label: "\u540D\u79F0",
212
- name: "id",
213
- style: {
214
- marginBottom: '15px'
215
- },
216
- rules: [{
217
- required: true
218
- }]
219
- }, /*#__PURE__*/React.createElement(_Input, {
220
- disabled: isNameDisabled
221
- })), /*#__PURE__*/React.createElement(_Form.Item, {
222
- label: "\u7C7B\u578B",
223
- name: "type",
224
- style: {
225
- marginBottom: '15px'
226
- },
227
- rules: [{
228
- required: true
229
- }]
230
- }, /*#__PURE__*/React.createElement(_Select, {
231
- options: OUTERMOST_TYPES_OPTIONS,
232
- onChange: onOuterTypeChange
233
- })), outerType === 'object' && /*#__PURE__*/React.createElement(MetaPropsEdit, {
234
- form: form,
235
- metadataTag: metadataTag,
236
- name: "properties",
237
- onAddFields: onAddFields,
238
- onNewRefClick: onNewRefClick
239
- }), /*#__PURE__*/React.createElement(_Form.Item, null, /*#__PURE__*/React.createElement(_Button, {
240
- type: "primary",
241
- block: true,
242
- htmlType: "submit"
243
- }, "\u786E\u5B9A"))), /*#__PURE__*/React.createElement(_Drawer, {
244
- title: (curFields === null || curFields === void 0 ? void 0 : curFields.id) || 'fields',
245
- width: 450,
246
- bodyStyle: {
247
- padding: 0
248
- },
249
- placement: "right",
250
- onClose: function onClose() {
251
- setIsFields(false);
252
- },
253
- mask: false,
254
- push: false,
255
- visible: isFields,
256
- destroyOnClose: true
257
- }, /*#__PURE__*/React.createElement(MetaFieldsEdit, {
258
- key: curFields === null || curFields === void 0 ? void 0 : curFields.id,
259
- defaultValues: fields[curFields.id],
260
- onChange: onFieldsChange
261
- })));
262
- };
263
- export default MetadataEditV2;
@@ -1,11 +0,0 @@
1
- .metadata-edit {
2
- height: 100%;
3
- width: 100%;
4
- .ant-row {
5
- display: block;
6
- }
7
- .pr-10 {
8
- padding-right: 10px;
9
- width: 50%;
10
- }
11
- }
@@ -1,20 +0,0 @@
1
- export interface IMetaFileds {
2
- id: string;
3
- type: 'object';
4
- properties: any[];
5
- value: any;
6
- }
7
-
8
- export type ITypeStatus = 'object' | 'ref' | 'bool' | 'number' | 'text' | 'enum' | 'array';
9
-
10
- export type IMetaProperty = {
11
- /**
12
- * 属性的名称
13
- */
14
- id: string;
15
- /**
16
- * 类型
17
- */
18
- type: string;
19
- enum?: any[];
20
- };