@cqsjjb/jjb-react-admin-component 3.1.3 → 3.2.0-beta.0
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 +57 -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 -213
- 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,69 +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
|
-
}
|
|
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, {
|
|
124
124
|
destroyOnClose: true,
|
|
125
125
|
title: "\u67E5\u770B\u6587\u4EF6",
|
|
126
126
|
open: open,
|
|
127
127
|
width: 1100,
|
|
128
|
-
footer:
|
|
128
|
+
footer: null,
|
|
129
129
|
onCancel: () => setOpen(false)
|
|
130
130
|
}, IS_PDF_REG.test(previewUrl) && /*#__PURE__*/React.createElement("embed", {
|
|
131
131
|
src: previewUrl,
|
|
@@ -135,90 +135,92 @@ function ItemRender(props) {
|
|
|
135
135
|
controls: true,
|
|
136
136
|
src: previewUrl,
|
|
137
137
|
width: "100%",
|
|
138
|
-
height:
|
|
138
|
+
height: 350
|
|
139
139
|
})));
|
|
140
140
|
}
|
|
141
|
-
function RenderText(
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const [
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}, [props.value]);
|
|
164
|
-
return Array.isArray(text) ? /*#__PURE__*/React.createElement("div", {
|
|
165
|
-
style: {
|
|
166
|
-
gap: 6,
|
|
167
|
-
width: '100%',
|
|
168
|
-
display: 'flex',
|
|
169
|
-
minHeight: 22,
|
|
170
|
-
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);
|
|
171
163
|
}
|
|
172
|
-
},
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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({
|
|
186
190
|
text,
|
|
187
|
-
name
|
|
191
|
+
name
|
|
188
192
|
}) : tools.textPlaceholder(text);
|
|
189
193
|
}
|
|
190
|
-
function RenderFileItem({
|
|
191
|
-
|
|
192
|
-
|
|
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
|
-
}
|
|
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
|
+
}));
|
|
220
222
|
}
|
|
221
|
-
function RenderImage({
|
|
223
|
+
export function RenderImage({
|
|
222
224
|
url,
|
|
223
225
|
imageWidth,
|
|
224
226
|
imageHeight,
|
|
@@ -237,48 +239,41 @@ function RenderImage({
|
|
|
237
239
|
height: imageHeight || 64,
|
|
238
240
|
preview: extraFileLink ? {
|
|
239
241
|
visible: false,
|
|
240
|
-
onVisibleChange: () =>
|
|
241
|
-
window.open(url);
|
|
242
|
-
}
|
|
242
|
+
onVisibleChange: () => window.open(url)
|
|
243
243
|
} : imagePreview
|
|
244
244
|
}));
|
|
245
245
|
}
|
|
246
|
-
function RenderValidFile({
|
|
246
|
+
export function RenderValidFile({
|
|
247
247
|
url,
|
|
248
248
|
name,
|
|
249
249
|
extraFileLink,
|
|
250
250
|
onPreview
|
|
251
251
|
}) {
|
|
252
|
+
const handleClick = () => extraFileLink ? window.open(url) : onPreview();
|
|
252
253
|
return /*#__PURE__*/React.createElement("a", {
|
|
253
254
|
style: {
|
|
254
255
|
gap: 4,
|
|
255
256
|
display: 'flex',
|
|
256
257
|
alignItems: 'center'
|
|
257
258
|
},
|
|
258
|
-
onClick:
|
|
259
|
-
if (extraFileLink) {
|
|
260
|
-
window.open(url);
|
|
261
|
-
} else {
|
|
262
|
-
onPreview();
|
|
263
|
-
}
|
|
264
|
-
}
|
|
259
|
+
onClick: handleClick
|
|
265
260
|
}, /*#__PURE__*/React.createElement(FileOutlined, null), name);
|
|
266
261
|
}
|
|
267
|
-
function RenderInvalidFile({
|
|
262
|
+
export function RenderInvalidFile({
|
|
268
263
|
url,
|
|
269
264
|
name
|
|
270
265
|
}) {
|
|
271
266
|
return /*#__PURE__*/React.createElement("a", {
|
|
272
267
|
href: url,
|
|
268
|
+
target: "_blank",
|
|
273
269
|
style: {
|
|
274
270
|
gap: 4,
|
|
275
271
|
display: 'flex',
|
|
276
272
|
alignItems: 'center'
|
|
277
|
-
}
|
|
278
|
-
target: "_blank"
|
|
273
|
+
}
|
|
279
274
|
}, /*#__PURE__*/React.createElement(LinkOutlined, null), name);
|
|
280
275
|
}
|
|
281
|
-
function RenderTable({
|
|
276
|
+
export function RenderTable({
|
|
282
277
|
columns,
|
|
283
278
|
dataSource,
|
|
284
279
|
imageWidth,
|
|
@@ -287,39 +282,33 @@ function RenderTable({
|
|
|
287
282
|
extraFileLink,
|
|
288
283
|
onPreview
|
|
289
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
|
+
};
|
|
290
309
|
return /*#__PURE__*/React.createElement(Table, {
|
|
291
310
|
rowKey: (record, index) => index,
|
|
292
|
-
columns: columns.map(
|
|
293
|
-
item.render = row => {
|
|
294
|
-
if (tools.isNumberArray(row) || tools.isStringArray(row)) {
|
|
295
|
-
return row?.join(',');
|
|
296
|
-
}
|
|
297
|
-
if (tools.isUploadFileListArray(row)) {
|
|
298
|
-
return /*#__PURE__*/React.createElement(Space, {
|
|
299
|
-
direction: "vertical"
|
|
300
|
-
}, tools.getDynamicUploadFileList(row).map((file, index) => {
|
|
301
|
-
return /*#__PURE__*/React.createElement(RenderFileItem, {
|
|
302
|
-
key: index,
|
|
303
|
-
url: file.url,
|
|
304
|
-
name: file.name,
|
|
305
|
-
isImage: file.isImage,
|
|
306
|
-
imageWidth: imageWidth,
|
|
307
|
-
imageHeight: imageHeight,
|
|
308
|
-
imagePreview: imagePreview,
|
|
309
|
-
extraFileLink: extraFileLink,
|
|
310
|
-
onPreview: () => {
|
|
311
|
-
onPreview(file.url);
|
|
312
|
-
}
|
|
313
|
-
});
|
|
314
|
-
}));
|
|
315
|
-
}
|
|
316
|
-
if (tools.isObject(row)) {
|
|
317
|
-
return '数据错误';
|
|
318
|
-
}
|
|
319
|
-
return row;
|
|
320
|
-
};
|
|
321
|
-
return item;
|
|
322
|
-
}),
|
|
311
|
+
columns: columns.map(renderColumn),
|
|
323
312
|
dataSource: dataSource
|
|
324
313
|
});
|
|
325
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;
|