@cqsjjb/jjb-react-admin-component 3.1.4 → 3.2.0-beta.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/BMap/index.d.ts +40 -0
- package/BMap/index.js +185 -0
- package/BMap/index.less +36 -0
- package/ControlWrapper/index.d.ts +45 -59
- package/ControlWrapper/index.js +70 -245
- package/Editor/index.js +330 -0
- package/Editor/index.ts +59 -0
- package/ErrorBoundary/index.d.ts +3 -6
- package/ErrorBoundary/index.js +3 -9
- package/FileUploader/index.d.ts +56 -0
- package/FileUploader/index.js +385 -0
- package/FileUploader/index.less +198 -0
- package/FormilyDescriptions/index.d.ts +116 -59
- package/FormilyDescriptions/index.js +202 -215
- package/FormilyRenderer/index.d.ts +15 -32
- package/FormilyRenderer/index.js +45 -25
- package/ImageCropper/index.d.ts +55 -0
- package/ImageCropper/index.js +131 -0
- package/ImageUploader/index.d.ts +79 -0
- package/ImageUploader/index.js +362 -0
- package/ImageUploader/index.less +100 -0
- package/MediaQuery/index.d.ts +9 -6
- package/MediaQuery/index.js +32 -81
- package/PageLayout/index.d.ts +44 -0
- package/PageLayout/index.js +85 -0
- package/PageLayout/index.less +47 -0
- package/SearchForm/index.d.ts +26 -49
- package/SearchForm/index.js +93 -108
- package/Table/index.d.ts +2 -6
- package/Table/index.js +1 -1
- package/TableAction/index.d.ts +15 -10
- package/TableAction/index.js +23 -15
- package/package.json +3 -3
- package/tools/index.d.ts +10 -0
- package/tools/index.js +87 -0
- package/SearchForm/index.less +0 -0
- package/Upload/index.d.ts +0 -76
- package/Upload/index.js +0 -334
- package/types/index.ts +0 -7
|
@@ -1,58 +1,66 @@
|
|
|
1
|
-
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (
|
|
2
|
-
import React from 'react';
|
|
1
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
2
|
+
import React, { useState, useEffect, Fragment } from 'react';
|
|
3
3
|
import { tools } from '@cqsjjb/jjb-common-lib';
|
|
4
4
|
import { FileOutlined, LinkOutlined } from '@ant-design/icons';
|
|
5
5
|
import { Modal, Descriptions, Empty, Image, Tooltip, Spin, Table, Space, TreeSelect } from 'antd';
|
|
6
6
|
const formilyItemMargin = new Map([['small', 8], ['middle', 12], ['default', 16]]);
|
|
7
7
|
const IS_PDF_REG = /\.pdf$/;
|
|
8
8
|
const IS_VIDEO_REG = /\.(mp4|ogg|mkv|webm)$/;
|
|
9
|
-
export default function FormilyDescriptions(
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
export default function FormilyDescriptions({
|
|
10
|
+
schema,
|
|
11
|
+
values,
|
|
12
|
+
...props
|
|
13
|
+
}) {
|
|
14
|
+
const [regions, setRegions] = useState([]);
|
|
15
|
+
useEffect(() => {
|
|
12
16
|
fetch(`${window.process.env.app.API_HOST}/system/operation/regions`, {
|
|
13
17
|
headers: {
|
|
14
18
|
token: sessionStorage.token
|
|
15
19
|
}
|
|
16
20
|
}).then(res => res.json()).then(res => {
|
|
17
|
-
if (res.success)
|
|
18
|
-
setRegions(res.data);
|
|
19
|
-
}
|
|
21
|
+
if (res.success) setRegions(res.data);
|
|
20
22
|
});
|
|
21
23
|
}, []);
|
|
22
|
-
const dataSource = tools.getDynamicFormilyFields(
|
|
24
|
+
const dataSource = tools.getDynamicFormilyFields(schema, values, {
|
|
23
25
|
regions
|
|
24
26
|
});
|
|
25
|
-
|
|
27
|
+
console.log(schema, values);
|
|
28
|
+
if (!dataSource.length) return /*#__PURE__*/React.createElement(Empty, {
|
|
26
29
|
image: Empty.PRESENTED_IMAGE_SIMPLE
|
|
27
|
-
})
|
|
30
|
+
});
|
|
31
|
+
return /*#__PURE__*/React.createElement(DescriptionsRender, _extends({
|
|
28
32
|
dataSource: dataSource
|
|
29
33
|
}, props));
|
|
30
34
|
}
|
|
31
|
-
function DescriptionsRender(
|
|
32
|
-
|
|
33
|
-
|
|
35
|
+
export function DescriptionsRender({
|
|
36
|
+
dataSource,
|
|
37
|
+
size = 'default',
|
|
38
|
+
...props
|
|
39
|
+
}) {
|
|
40
|
+
return dataSource.map((item, index) => {
|
|
41
|
+
const isLast = index === dataSource.length - 1;
|
|
42
|
+
const marginBottom = isLast ? 0 : formilyItemMargin.get(size);
|
|
43
|
+
const items = item.fromComponentEnum === 'GRID_FORM' ? item.children.map((child, childIndex) => ({
|
|
44
|
+
key: childIndex,
|
|
45
|
+
span: child.formType === 'Table' ? props.column : 1,
|
|
46
|
+
label: child.name,
|
|
47
|
+
children: /*#__PURE__*/React.createElement(ItemRender, _extends({
|
|
48
|
+
data: child
|
|
49
|
+
}, props))
|
|
50
|
+
})) : [{
|
|
51
|
+
key: 1,
|
|
52
|
+
label: item.name,
|
|
53
|
+
children: /*#__PURE__*/React.createElement(ItemRender, _extends({
|
|
54
|
+
data: item
|
|
55
|
+
}, props))
|
|
56
|
+
}];
|
|
34
57
|
return /*#__PURE__*/React.createElement(Descriptions, {
|
|
35
58
|
key: index,
|
|
36
|
-
size:
|
|
59
|
+
size: size,
|
|
37
60
|
style: {
|
|
38
|
-
marginBottom
|
|
61
|
+
marginBottom
|
|
39
62
|
},
|
|
40
|
-
items:
|
|
41
|
-
return {
|
|
42
|
-
key: childIndex,
|
|
43
|
-
span: child.formType === 'Table' ? props.column : 1,
|
|
44
|
-
label: child.name,
|
|
45
|
-
children: /*#__PURE__*/React.createElement(ItemRender, _extends({
|
|
46
|
-
data: child
|
|
47
|
-
}, props))
|
|
48
|
-
};
|
|
49
|
-
}) : [{
|
|
50
|
-
key: 1,
|
|
51
|
-
label: item.name,
|
|
52
|
-
children: /*#__PURE__*/React.createElement(ItemRender, _extends({
|
|
53
|
-
data: item
|
|
54
|
-
}, props))
|
|
55
|
-
}],
|
|
63
|
+
items: items,
|
|
56
64
|
colon: props.colon,
|
|
57
65
|
title: props.title,
|
|
58
66
|
extra: props.extra,
|
|
@@ -63,70 +71,61 @@ function DescriptionsRender(props) {
|
|
|
63
71
|
});
|
|
64
72
|
});
|
|
65
73
|
}
|
|
66
|
-
function ItemRender(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
name: file.name,
|
|
108
|
-
isImage: file.isImage,
|
|
109
|
-
imageWidth: imageWidth,
|
|
110
|
-
imageHeight: imageHeight,
|
|
111
|
-
imagePreview: imagePreview,
|
|
112
|
-
extraFileLink: extraFileLink,
|
|
113
|
-
onPreview: () => {
|
|
114
|
-
setOpen(true);
|
|
115
|
-
setPreviewUrl(file.url);
|
|
74
|
+
export function ItemRender({
|
|
75
|
+
data,
|
|
76
|
+
imageWidth,
|
|
77
|
+
imageHeight,
|
|
78
|
+
imagePreview,
|
|
79
|
+
extraFileLink,
|
|
80
|
+
...props
|
|
81
|
+
}) {
|
|
82
|
+
const [open, setOpen] = useState(false);
|
|
83
|
+
const [previewUrl, setPreviewUrl] = useState('');
|
|
84
|
+
const handlePreview = url => {
|
|
85
|
+
setPreviewUrl(url);
|
|
86
|
+
setOpen(true);
|
|
87
|
+
};
|
|
88
|
+
const renderContent = () => {
|
|
89
|
+
if (tools.isArray(data.value)) {
|
|
90
|
+
if (tools.isStringArray(data.value) || tools.isNumberArray(data.value)) {
|
|
91
|
+
return data.value.join('、');
|
|
92
|
+
}
|
|
93
|
+
if (tools.isObjectArray(data.value)) {
|
|
94
|
+
return data.formType === 'Table' ? /*#__PURE__*/React.createElement(RenderTable, {
|
|
95
|
+
columns: data.tableColumns,
|
|
96
|
+
dataSource: data.value,
|
|
97
|
+
imageWidth: imageWidth,
|
|
98
|
+
imageHeight: imageHeight,
|
|
99
|
+
imagePreview: imagePreview,
|
|
100
|
+
extraFileLink: extraFileLink,
|
|
101
|
+
onPreview: handlePreview
|
|
102
|
+
}) : data.value.map((file, index) => /*#__PURE__*/React.createElement(RenderFileItem, {
|
|
103
|
+
key: index,
|
|
104
|
+
url: file.url,
|
|
105
|
+
name: file.name,
|
|
106
|
+
isImage: file.isImage,
|
|
107
|
+
imageWidth: imageWidth,
|
|
108
|
+
imageHeight: imageHeight,
|
|
109
|
+
imagePreview: imagePreview,
|
|
110
|
+
extraFileLink: extraFileLink,
|
|
111
|
+
onPreview: () => handlePreview(file.url)
|
|
112
|
+
}));
|
|
113
|
+
}
|
|
114
|
+
return tools.textPlaceholder();
|
|
116
115
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
116
|
+
return /*#__PURE__*/React.createElement(RenderText, {
|
|
117
|
+
name: data.name,
|
|
118
|
+
value: data.value,
|
|
119
|
+
maxTagCount: props.maxTagCount,
|
|
120
|
+
renderItemText: props.renderItemText
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
return /*#__PURE__*/React.createElement(Fragment, null, renderContent(), /*#__PURE__*/React.createElement(Modal, {
|
|
125
124
|
destroyOnClose: true,
|
|
126
125
|
title: "\u67E5\u770B\u6587\u4EF6",
|
|
127
126
|
open: open,
|
|
128
127
|
width: 1100,
|
|
129
|
-
footer:
|
|
128
|
+
footer: null,
|
|
130
129
|
onCancel: () => setOpen(false)
|
|
131
130
|
}, IS_PDF_REG.test(previewUrl) && /*#__PURE__*/React.createElement("embed", {
|
|
132
131
|
src: previewUrl,
|
|
@@ -136,91 +135,92 @@ function ItemRender(props) {
|
|
|
136
135
|
controls: true,
|
|
137
136
|
src: previewUrl,
|
|
138
137
|
width: "100%",
|
|
139
|
-
height:
|
|
138
|
+
height: 350
|
|
140
139
|
})));
|
|
141
140
|
}
|
|
142
|
-
function RenderText(
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const [
|
|
149
|
-
const [
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
}, [props.value]);
|
|
166
|
-
return Array.isArray(text) ? /*#__PURE__*/React.createElement("div", {
|
|
167
|
-
style: {
|
|
168
|
-
gap: 6,
|
|
169
|
-
width: '100%',
|
|
170
|
-
display: 'flex',
|
|
171
|
-
minHeight: 22,
|
|
172
|
-
flexDirection: 'column'
|
|
141
|
+
export function RenderText({
|
|
142
|
+
value,
|
|
143
|
+
name,
|
|
144
|
+
maxTagCount = 1,
|
|
145
|
+
renderItemText
|
|
146
|
+
}) {
|
|
147
|
+
const [text, setText] = useState();
|
|
148
|
+
const [options, setOptions] = useState([]);
|
|
149
|
+
const [loading, setLoading] = useState(false);
|
|
150
|
+
useEffect(() => {
|
|
151
|
+
if (!value) return;
|
|
152
|
+
if (value.load) {
|
|
153
|
+
setLoading(true);
|
|
154
|
+
value.load().then(res => res.json()).then(res => {
|
|
155
|
+
if (res.success) {
|
|
156
|
+
setOptions(res.data);
|
|
157
|
+
setText(value?.selected?.map(i => `${i.key}&${i.label}`));
|
|
158
|
+
}
|
|
159
|
+
setLoading(false);
|
|
160
|
+
});
|
|
161
|
+
} else {
|
|
162
|
+
setText(value);
|
|
173
163
|
}
|
|
174
|
-
},
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
164
|
+
}, [value]);
|
|
165
|
+
if (Array.isArray(text)) {
|
|
166
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
167
|
+
style: {
|
|
168
|
+
gap: 6,
|
|
169
|
+
width: '100%',
|
|
170
|
+
display: 'flex',
|
|
171
|
+
minHeight: 22,
|
|
172
|
+
flexDirection: 'column'
|
|
173
|
+
}
|
|
174
|
+
}, /*#__PURE__*/React.createElement(Spin, {
|
|
175
|
+
spinning: loading
|
|
176
|
+
}, /*#__PURE__*/React.createElement(TreeSelect, {
|
|
177
|
+
treeCheckable: true,
|
|
178
|
+
treeDefaultExpandAll: true,
|
|
179
|
+
style: {
|
|
180
|
+
width: '100%'
|
|
181
|
+
},
|
|
182
|
+
value: text,
|
|
183
|
+
variant: "borderless",
|
|
184
|
+
treeData: options,
|
|
185
|
+
showSearch: false,
|
|
186
|
+
maxTagCount: maxTagCount
|
|
187
|
+
})));
|
|
188
|
+
}
|
|
189
|
+
return renderItemText ? renderItemText({
|
|
188
190
|
text,
|
|
189
|
-
name
|
|
191
|
+
name
|
|
190
192
|
}) : tools.textPlaceholder(text);
|
|
191
193
|
}
|
|
192
|
-
function RenderFileItem({
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
}));
|
|
221
|
-
}
|
|
194
|
+
export function RenderFileItem(props) {
|
|
195
|
+
const {
|
|
196
|
+
isImage,
|
|
197
|
+
url,
|
|
198
|
+
name,
|
|
199
|
+
imageWidth,
|
|
200
|
+
imageHeight,
|
|
201
|
+
imagePreview,
|
|
202
|
+
extraFileLink,
|
|
203
|
+
onPreview
|
|
204
|
+
} = props;
|
|
205
|
+
return isImage ? /*#__PURE__*/React.createElement(RenderImage, {
|
|
206
|
+
url: url,
|
|
207
|
+
imageWidth: imageWidth,
|
|
208
|
+
imageHeight: imageHeight,
|
|
209
|
+
imagePreview: imagePreview,
|
|
210
|
+
extraFileLink: extraFileLink
|
|
211
|
+
}) : /*#__PURE__*/React.createElement(Tooltip, {
|
|
212
|
+
title: url
|
|
213
|
+
}, IS_PDF_REG.test(url) || IS_VIDEO_REG.test(url) ? /*#__PURE__*/React.createElement(RenderValidFile, {
|
|
214
|
+
url: url,
|
|
215
|
+
name: name,
|
|
216
|
+
onPreview: onPreview,
|
|
217
|
+
extraFileLink: extraFileLink
|
|
218
|
+
}) : /*#__PURE__*/React.createElement(RenderInvalidFile, {
|
|
219
|
+
url: url,
|
|
220
|
+
name: name
|
|
221
|
+
}));
|
|
222
222
|
}
|
|
223
|
-
function RenderImage({
|
|
223
|
+
export function RenderImage({
|
|
224
224
|
url,
|
|
225
225
|
imageWidth,
|
|
226
226
|
imageHeight,
|
|
@@ -239,48 +239,41 @@ function RenderImage({
|
|
|
239
239
|
height: imageHeight || 64,
|
|
240
240
|
preview: extraFileLink ? {
|
|
241
241
|
visible: false,
|
|
242
|
-
onVisibleChange: () =>
|
|
243
|
-
window.open(url);
|
|
244
|
-
}
|
|
242
|
+
onVisibleChange: () => window.open(url)
|
|
245
243
|
} : imagePreview
|
|
246
244
|
}));
|
|
247
245
|
}
|
|
248
|
-
function RenderValidFile({
|
|
246
|
+
export function RenderValidFile({
|
|
249
247
|
url,
|
|
250
248
|
name,
|
|
251
249
|
extraFileLink,
|
|
252
250
|
onPreview
|
|
253
251
|
}) {
|
|
252
|
+
const handleClick = () => extraFileLink ? window.open(url) : onPreview();
|
|
254
253
|
return /*#__PURE__*/React.createElement("a", {
|
|
255
254
|
style: {
|
|
256
255
|
gap: 4,
|
|
257
256
|
display: 'flex',
|
|
258
257
|
alignItems: 'center'
|
|
259
258
|
},
|
|
260
|
-
onClick:
|
|
261
|
-
if (extraFileLink) {
|
|
262
|
-
window.open(url);
|
|
263
|
-
} else {
|
|
264
|
-
onPreview();
|
|
265
|
-
}
|
|
266
|
-
}
|
|
259
|
+
onClick: handleClick
|
|
267
260
|
}, /*#__PURE__*/React.createElement(FileOutlined, null), name);
|
|
268
261
|
}
|
|
269
|
-
function RenderInvalidFile({
|
|
262
|
+
export function RenderInvalidFile({
|
|
270
263
|
url,
|
|
271
264
|
name
|
|
272
265
|
}) {
|
|
273
266
|
return /*#__PURE__*/React.createElement("a", {
|
|
274
267
|
href: url,
|
|
268
|
+
target: "_blank",
|
|
275
269
|
style: {
|
|
276
270
|
gap: 4,
|
|
277
271
|
display: 'flex',
|
|
278
272
|
alignItems: 'center'
|
|
279
|
-
}
|
|
280
|
-
target: "_blank"
|
|
273
|
+
}
|
|
281
274
|
}, /*#__PURE__*/React.createElement(LinkOutlined, null), name);
|
|
282
275
|
}
|
|
283
|
-
function RenderTable({
|
|
276
|
+
export function RenderTable({
|
|
284
277
|
columns,
|
|
285
278
|
dataSource,
|
|
286
279
|
imageWidth,
|
|
@@ -289,39 +282,33 @@ function RenderTable({
|
|
|
289
282
|
extraFileLink,
|
|
290
283
|
onPreview
|
|
291
284
|
}) {
|
|
285
|
+
const renderColumn = col => {
|
|
286
|
+
const originalRender = col.render;
|
|
287
|
+
col.render = row => {
|
|
288
|
+
if (tools.isNumberArray(row) || tools.isStringArray(row)) return row.join(',');
|
|
289
|
+
if (tools.isUploadFileListArray(row)) {
|
|
290
|
+
return /*#__PURE__*/React.createElement(Space, {
|
|
291
|
+
direction: "vertical"
|
|
292
|
+
}, tools.getDynamicUploadFileList(row).map((file, index) => /*#__PURE__*/React.createElement(RenderFileItem, {
|
|
293
|
+
key: index,
|
|
294
|
+
url: file.url,
|
|
295
|
+
name: file.name,
|
|
296
|
+
isImage: file.isImage,
|
|
297
|
+
imageWidth: imageWidth,
|
|
298
|
+
imageHeight: imageHeight,
|
|
299
|
+
imagePreview: imagePreview,
|
|
300
|
+
extraFileLink: extraFileLink,
|
|
301
|
+
onPreview: () => onPreview(file.url)
|
|
302
|
+
})));
|
|
303
|
+
}
|
|
304
|
+
if (tools.isObject(row)) return '数据错误';
|
|
305
|
+
return originalRender ? originalRender(row) : row;
|
|
306
|
+
};
|
|
307
|
+
return col;
|
|
308
|
+
};
|
|
292
309
|
return /*#__PURE__*/React.createElement(Table, {
|
|
293
310
|
rowKey: (record, index) => index,
|
|
294
|
-
columns: columns.map(
|
|
295
|
-
item.render = row => {
|
|
296
|
-
if (tools.isNumberArray(row) || tools.isStringArray(row)) {
|
|
297
|
-
return row?.join(',');
|
|
298
|
-
}
|
|
299
|
-
if (tools.isUploadFileListArray(row)) {
|
|
300
|
-
return /*#__PURE__*/React.createElement(Space, {
|
|
301
|
-
direction: "vertical"
|
|
302
|
-
}, tools.getDynamicUploadFileList(row).map((file, index) => {
|
|
303
|
-
return /*#__PURE__*/React.createElement(RenderFileItem, {
|
|
304
|
-
key: index,
|
|
305
|
-
url: file.url,
|
|
306
|
-
name: file.name,
|
|
307
|
-
isImage: file.isImage,
|
|
308
|
-
imageWidth: imageWidth,
|
|
309
|
-
imageHeight: imageHeight,
|
|
310
|
-
imagePreview: imagePreview,
|
|
311
|
-
extraFileLink: extraFileLink,
|
|
312
|
-
onPreview: () => {
|
|
313
|
-
onPreview(file.url);
|
|
314
|
-
}
|
|
315
|
-
});
|
|
316
|
-
}));
|
|
317
|
-
}
|
|
318
|
-
if (tools.isObject(row)) {
|
|
319
|
-
return '数据错误';
|
|
320
|
-
}
|
|
321
|
-
return row;
|
|
322
|
-
};
|
|
323
|
-
return item;
|
|
324
|
-
}),
|
|
311
|
+
columns: columns.map(renderColumn),
|
|
325
312
|
dataSource: dataSource
|
|
326
313
|
});
|
|
327
314
|
}
|
|
@@ -1,38 +1,21 @@
|
|
|
1
|
-
// @ts-ignore
|
|
2
1
|
import * as React from 'react';
|
|
3
|
-
import {
|
|
2
|
+
import { CSSProperties } from 'react';
|
|
4
3
|
|
|
5
|
-
interface FormilyRendererProps
|
|
6
|
-
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
|
|
16
|
-
*/
|
|
17
|
-
disabledFields?: string[];
|
|
18
|
-
/**
|
|
19
|
-
* @description 获取表单示例
|
|
20
|
-
* @see https://core.formilyjs.org/api/models/form#method
|
|
21
|
-
*/
|
|
22
|
-
getRef?: (form: object) => void;
|
|
23
|
-
/**
|
|
24
|
-
* @description 图片高度
|
|
25
|
-
*/
|
|
26
|
-
width?: number;
|
|
27
|
-
/**
|
|
28
|
-
* @description 样式
|
|
29
|
-
* @see https://ant.design/components/image-cn#previewtype
|
|
30
|
-
*/
|
|
31
|
-
style?: React.CSSProperties
|
|
4
|
+
export interface FormilyRendererProps {
|
|
5
|
+
/** 设计编码,用于请求后端配置 */
|
|
6
|
+
code: string;
|
|
7
|
+
/** 初始表单值 */
|
|
8
|
+
initialValues?: Record<string, any>;
|
|
9
|
+
/** 需要禁用的字段 */
|
|
10
|
+
disabledFields?: string[] | string;
|
|
11
|
+
/** 样式 */
|
|
12
|
+
style?: CSSProperties;
|
|
13
|
+
/** 获取内部 formRef 的回调 */
|
|
14
|
+
getRef?: (ref: React.RefObject<any>) => void;
|
|
32
15
|
}
|
|
33
16
|
|
|
34
|
-
|
|
35
|
-
|
|
17
|
+
declare const FormilyRenderer: React.ForwardRefExoticComponent<
|
|
18
|
+
FormilyRendererProps & React.RefAttributes<any>
|
|
19
|
+
>;
|
|
36
20
|
|
|
37
|
-
declare const FormilyRenderer: FormilyRendererFc;
|
|
38
21
|
export default FormilyRenderer;
|
package/FormilyRenderer/index.js
CHANGED
|
@@ -1,38 +1,58 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useEffect, useRef, useState, forwardRef, useImperativeHandle } from 'react';
|
|
2
2
|
import Renderer from '@cqsjjb-formily/renderer';
|
|
3
3
|
import { http, tools } from '@cqsjjb/jjb-common-lib';
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
const FormilyRenderer = /*#__PURE__*/forwardRef((props, ref) => {
|
|
5
|
+
const {
|
|
6
|
+
code,
|
|
7
|
+
style,
|
|
8
|
+
initialValues = {},
|
|
9
|
+
disabledFields = [],
|
|
10
|
+
getRef
|
|
11
|
+
} = props;
|
|
12
|
+
const formRef = useRef(null);
|
|
13
|
+
const [schema, setSchema] = useState({});
|
|
14
|
+
|
|
15
|
+
// 暴露 formRef 给父组件
|
|
16
|
+
useImperativeHandle(ref, () => formRef.current);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
let isMounted = true;
|
|
19
|
+
|
|
20
|
+
// 获取设计配置
|
|
21
|
+
http.Get(`/design/designs/${code}`).then(res => {
|
|
22
|
+
if (isMounted && res.success) {
|
|
10
23
|
const {
|
|
11
24
|
config
|
|
12
25
|
} = res.data;
|
|
13
26
|
setSchema(tools.parseObject(config));
|
|
14
27
|
}
|
|
15
28
|
});
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
return () => {
|
|
30
|
+
isMounted = false;
|
|
31
|
+
};
|
|
32
|
+
}, [code]);
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (!formRef.current || !Object.keys(schema).length) return;
|
|
35
|
+
|
|
36
|
+
// 设置初始值
|
|
37
|
+
formRef.current.setValues(initialValues);
|
|
38
|
+
|
|
39
|
+
// 禁用字段
|
|
40
|
+
tools.toArray(disabledFields).forEach(field => {
|
|
41
|
+
const f = formRef.current.fields[field];
|
|
42
|
+
if (f) {
|
|
43
|
+
f.required = false;
|
|
44
|
+
f.disabled = true;
|
|
28
45
|
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// 返回 formRef 给父组件
|
|
49
|
+
getRef && getRef(formRef);
|
|
50
|
+
}, [schema, initialValues, disabledFields, getRef]);
|
|
32
51
|
return /*#__PURE__*/React.createElement("div", {
|
|
33
|
-
style:
|
|
52
|
+
style: style
|
|
34
53
|
}, /*#__PURE__*/React.createElement(Renderer, {
|
|
35
|
-
ref:
|
|
54
|
+
ref: formRef,
|
|
36
55
|
schema: schema
|
|
37
56
|
}));
|
|
38
|
-
});
|
|
57
|
+
});
|
|
58
|
+
export default FormilyRenderer;
|