@cqsjjb/jjb-react-admin-component 3.0.29 → 3.1.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.
@@ -1,407 +0,0 @@
1
- import React from 'react';
2
-
3
- import { tools } from '@cqsjjb/jjb-common-lib';
4
- import { FileOutlined, LinkOutlined } from '@ant-design/icons';
5
- import { Modal, Descriptions, Empty, Image, Tooltip, Spin, Table, Space, TreeSelect } from 'antd';
6
-
7
- const formilyItemMargin = new Map([
8
- [ 'small', 8 ],
9
- [ 'middle', 12 ],
10
- [ 'default', 16 ]
11
- ]);
12
-
13
- const IS_PDF_REG = /\.pdf$/;
14
- const IS_VIDEO_REG = /\.(mp4|ogg|mkv|webm)$/;
15
-
16
- export default function FormilyDescriptions(props) {
17
- const [ regions, setRegions ] = React.useState([]);
18
-
19
- React.useEffect(() => {
20
- fetch(`${window.process.env.app.API_HOST}/system/operation/regions`, { headers: { token: sessionStorage.token } }).then(res => res.json()).then(res => {
21
- if (res.success) {
22
- setRegions(res.data);
23
- }
24
- });
25
- }, []);
26
-
27
- const dataSource = tools.getDynamicFormilyFields(props.schema, props.values, { regions });
28
-
29
- return dataSource.length === 0
30
- ? <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
31
- : (
32
- <DescriptionsRender dataSource={dataSource} {...props} />
33
- );
34
- }
35
-
36
- function DescriptionsRender(props) {
37
- return props.dataSource.map((item, index) => {
38
- const isLast = index === props.dataSource.length - 1;
39
-
40
- return (
41
- <Descriptions
42
- key={index}
43
- size={props.size}
44
- style={{
45
- marginBottom: isLast
46
- ? 0
47
- : formilyItemMargin.get(props.size || 'default')
48
- }}
49
- items={item.fromComponentEnum === 'GRID_FORM'
50
- ? item.children.map((child, childIndex) => {
51
- return {
52
- key: childIndex,
53
- span: child.formType === 'Table'
54
- ? props.column
55
- : 1,
56
- label: child.name,
57
- children: (
58
- <ItemRender data={child} {...props} />
59
- )
60
- };
61
- })
62
- : [
63
- {
64
- key: 1,
65
- label: item.name,
66
- children: <ItemRender data={item} {...props} />
67
- }
68
- ]}
69
- colon={props.colon}
70
- title={props.title}
71
- extra={props.extra}
72
- layout={props.layout || 'vertical'}
73
- column={props.column}
74
- labelStyle={props.labelStyle}
75
- contentStyle={props.contentStyle}
76
- />
77
- );
78
- });
79
- }
80
-
81
- function ItemRender(props) {
82
- const [ open, setOpen ] = React.useState(false);
83
- const [ previewUrl, setPreviewUrl ] = React.useState('');
84
-
85
- const {
86
- data,
87
- imageWidth,
88
- imageHeight,
89
- imagePreview,
90
- extraFileLink
91
- } = props;
92
-
93
- return (
94
- <React.Fragment>
95
- {/*如果数据是集合*/}
96
- {tools.isArray(data.value)
97
- // 如果数据是字符串集合 或 数字集合
98
- ? (tools.isStringArray(data.value) || tools.isNumberArray(data.value))
99
- // 直接字符串拼接
100
- ? data.value.join('、')
101
- // 如果是对象集合
102
- : tools.isObjectArray(data.value)
103
- // 如果数据表单类型是 数据表格
104
- ? data.formType === 'Table'
105
- // 处理数据表格
106
- ? (
107
- <div style={{ width: '100%' }}>
108
- <RenderTable
109
- columns={data.tableColumns}
110
- dataSource={data.value}
111
- imageWidth={imageWidth}
112
- imageHeight={imageHeight}
113
- imagePreview={imagePreview}
114
- extraFileLink={extraFileLink}
115
- onPreview={url => {
116
- setOpen(true);
117
- setPreviewUrl(url);
118
- }}
119
- />
120
- </div>
121
- )
122
- // 否则就是文件数据
123
- : (
124
- <div>
125
- {data.value.map((file, index) => (
126
- <RenderFileItem
127
- key={index}
128
- url={file.url}
129
- name={file.name}
130
- isImage={file.isImage}
131
- imageWidth={imageWidth}
132
- imageHeight={imageHeight}
133
- imagePreview={imagePreview}
134
- extraFileLink={extraFileLink}
135
- onPreview={() => {
136
- setOpen(true);
137
- setPreviewUrl(file.url);
138
- }}
139
- />
140
- ))}
141
- </div>
142
- )
143
- : tools.textPlaceholder()
144
- // 处理文本数据
145
- : (
146
- <RenderText
147
- name={data.name}
148
- value={data.value}
149
- renderItemText={props.renderItemText}
150
- />
151
- )}
152
- <Modal
153
- destroyOnClose
154
- title="查看文件"
155
- open={open}
156
- width={1100}
157
- footer={false}
158
- onCancel={() => setOpen(false)}
159
- >
160
- {IS_PDF_REG.test(previewUrl) && (
161
- <embed
162
- src={previewUrl}
163
- width="100%"
164
- height={600}
165
- />
166
- )}
167
- {IS_VIDEO_REG.test(previewUrl) && (
168
- <video
169
- controls
170
- src={previewUrl}
171
- width="100%"
172
- height="350"
173
- />
174
- )}
175
- </Modal>
176
- </React.Fragment>
177
- );
178
- }
179
-
180
- function RenderText(props) {
181
- const { value } = props;
182
- const [ text, setText ] = React.useState();
183
- const [ options, setOptions ] = React.useState([]);
184
- const [ loading, setLoading ] = React.useState(false);
185
-
186
- React.useEffect(() => {
187
- if (value) {
188
- if (value.load) {
189
- setLoading(true);
190
- value.load().then(res => res.json()).then(res => {
191
- if (res.success) {
192
- setOptions(res.data);
193
- setText(value.selected.map(i => `${i.key}&${i.label}`));
194
- }
195
- setLoading(false);
196
- });
197
- } else {
198
- setText(value);
199
- }
200
- }
201
- }, [ props.value ]);
202
-
203
- return Array.isArray(text)
204
- ? (
205
- <div
206
- style={{
207
- gap: 6,
208
- width: '100%',
209
- display: 'flex',
210
- minHeight: 22,
211
- flexDirection: 'column'
212
- }}
213
- >
214
- <Spin spinning={loading}>
215
- <TreeSelect
216
- treeCheckable
217
- treeDefaultExpandAll
218
- style={{ width: '100%' }}
219
- value={text}
220
- variant="borderless"
221
- treeData={options}
222
- showSearch={false}
223
- maxTagCount={1}
224
- />
225
- </Spin>
226
- </div>
227
- )
228
- : props.renderItemText
229
- ? props.renderItemText({
230
- text,
231
- name: props.name
232
- })
233
- : tools.textPlaceholder(text);
234
- }
235
-
236
- function RenderFileItem({
237
- url,
238
- name,
239
- isImage,
240
- imageWidth,
241
- imageHeight,
242
- imagePreview,
243
- extraFileLink,
244
- onPreview
245
- }) {
246
- if (isImage) {
247
- return (
248
- <RenderImage
249
- url={url}
250
- imageWidth={imageWidth}
251
- imageHeight={imageHeight}
252
- imagePreview={imagePreview}
253
- extraFileLink={extraFileLink}
254
- />
255
- );
256
- } else {
257
- return (
258
- <Tooltip title={url}>
259
- {IS_PDF_REG.test(url) || IS_VIDEO_REG.test(url)
260
- ? (
261
- <RenderValidFile
262
- url={url}
263
- name={name}
264
- onPreview={onPreview}
265
- />
266
- )
267
- : (
268
- <RenderInvalidFile
269
- url={url}
270
- name={name}
271
- />
272
- )}
273
- </Tooltip>
274
- );
275
- }
276
- }
277
-
278
- function RenderImage({
279
- url,
280
- imageWidth,
281
- imageHeight,
282
- imagePreview,
283
- extraFileLink
284
- }) {
285
- return (
286
- <span
287
- style={{
288
- display: 'inline-block',
289
- marginRight: 4,
290
- marginBottom: 4
291
- }}
292
- >
293
- <Image
294
- src={url}
295
- width={imageWidth || 64}
296
- height={imageHeight || 64}
297
- preview={extraFileLink
298
- ? {
299
- visible: false,
300
- onVisibleChange: () => {
301
- window.open(url);
302
- }
303
- }
304
- : imagePreview}
305
- />
306
- </span>
307
- );
308
- }
309
-
310
- function RenderValidFile({
311
- url,
312
- name,
313
- extraFileLink,
314
- onPreview
315
- }) {
316
- return (
317
- <a
318
- style={{
319
- gap: 4,
320
- display: 'flex',
321
- alignItems: 'center'
322
- }}
323
- onClick={() => {
324
- if (extraFileLink) {
325
- window.open(url);
326
- } else {
327
- onPreview();
328
- }
329
- }}
330
- >
331
- <FileOutlined />
332
- {name}
333
- </a>
334
- );
335
- }
336
-
337
- function RenderInvalidFile({
338
- url,
339
- name
340
- }) {
341
- return (
342
- <a
343
- href={url}
344
- style={{
345
- gap: 4,
346
- display: 'flex',
347
- alignItems: 'center'
348
- }}
349
- target="_blank"
350
- >
351
- <LinkOutlined />
352
- {name}
353
- </a>
354
- );
355
- }
356
-
357
- function RenderTable({
358
- columns,
359
- dataSource,
360
- imageWidth,
361
- imageHeight,
362
- imagePreview,
363
- extraFileLink,
364
- onPreview
365
- }) {
366
- return (
367
- <Table
368
- rowKey={(record, index) => index}
369
- columns={columns.map(item => {
370
- item.render = row => {
371
- if (tools.isNumberArray(row) || tools.isStringArray(row)) {
372
- return row?.join(',');
373
- }
374
- if (tools.isUploadFileListArray(row)) {
375
- return (
376
- <Space direction="vertical">
377
- {tools.getDynamicUploadFileList(row).map((file, index) => {
378
- return (
379
- <RenderFileItem
380
- key={index}
381
- url={file.url}
382
- name={file.name}
383
- isImage={file.isImage}
384
- imageWidth={imageWidth}
385
- imageHeight={imageHeight}
386
- imagePreview={imagePreview}
387
- extraFileLink={extraFileLink}
388
- onPreview={() => {
389
- onPreview(file.url);
390
- }}
391
- />
392
- );
393
- })}
394
- </Space>
395
- );
396
- }
397
- if (tools.isObject(row)) {
398
- return '数据错误';
399
- }
400
- return row;
401
- };
402
- return item;
403
- })}
404
- dataSource={dataSource}
405
- />
406
- );
407
- }
@@ -1,46 +0,0 @@
1
- import React from 'react';
2
- import Renderer from '@cqsjjb-formily/renderer';
3
-
4
- import { http, tools } from '@cqsjjb/jjb-common-lib';
5
-
6
- export default React.forwardRef((props, ref) => {
7
- const form = React.useRef();
8
- const [ schema, setSchema ] = React.useState({});
9
-
10
- React.useEffect(() => {
11
- http.Get(`/design/designs/${props.code}`).then(res => {
12
- if (res.success) {
13
- const { config } = res.data;
14
- setSchema(tools.parseObject(config));
15
- }
16
- });
17
- }, []);
18
-
19
- React.useEffect(() => {
20
- if (ref) {
21
- ref.current = form.current;
22
- }
23
-
24
- form.current.setValues(props.initialValues);
25
-
26
- setTimeout(() => {
27
- for (const field of tools.toArray(props.disabledFields)) {
28
- if (form.current.fields[ field ]) {
29
- form.current.fields[ field ].required = false;
30
- form.current.fields[ field ].disabled = true;
31
- }
32
- }
33
- }, 1000);
34
-
35
- props.getRef && props.getRef(form);
36
- }, [ schema ]);
37
-
38
- return (
39
- <div style={props.style}>
40
- <Renderer
41
- ref={form}
42
- schema={schema}
43
- />
44
- </div>
45
- );
46
- });
@@ -1,104 +0,0 @@
1
- import React from 'react';
2
-
3
- const MEDIA_QUERY_LIST = {
4
- MAX_WIDTH_479: '(max-width: 479px)',
5
- MIN_WIDTH_480_AND_MAX_WIDTH_599: '(min-width: 480px) and (max-width: 599px)',
6
- MIN_WIDTH_600_AND_MAX_WIDTH_899: '(min-width: 600px) and (max-width: 899px)',
7
- MIN_WIDTH_900_AND_MAX_WIDTH_1199: '(min-width: 900px) and (max-width: 1199px)',
8
- MIN_WIDTH_1200_AND_MAX_WIDTH_1439: '(min-width: 1200px) and (max-width: 1439px)',
9
- MIN_WIDTH_1440: '(min-width: 1440px)'
10
- };
11
-
12
- export default class MediaQuery extends React.Component {
13
- state = {
14
- media: undefined
15
- };
16
-
17
- componentDidMount () {
18
- const { disabled } = this.props;
19
-
20
- if (disabled) {
21
- return;
22
- }
23
-
24
- // 超小
25
- this.ultraSmall = window.matchMedia(MEDIA_QUERY_LIST.MAX_WIDTH_479);
26
- // 正常小
27
- this.normalSmall = window.matchMedia(MEDIA_QUERY_LIST.MIN_WIDTH_480_AND_MAX_WIDTH_599);
28
- // 中等
29
- this.normalMiddle = window.matchMedia(MEDIA_QUERY_LIST.MIN_WIDTH_600_AND_MAX_WIDTH_899);
30
- // 正常大
31
- this.normalLarge = window.matchMedia(MEDIA_QUERY_LIST.MIN_WIDTH_900_AND_MAX_WIDTH_1199);
32
- // 超大
33
- this.superLarge = window.matchMedia(MEDIA_QUERY_LIST.MIN_WIDTH_1200_AND_MAX_WIDTH_1439);
34
- // 超宽
35
- this.normalHuge = window.matchMedia(MEDIA_QUERY_LIST.MIN_WIDTH_1440);
36
-
37
- this.handleMediaQueryChange();
38
-
39
- this.ultraSmall.addEventListener('change', this.handleMediaQueryChange.bind(this));
40
- this.normalSmall.addEventListener('change', this.handleMediaQueryChange.bind(this));
41
- this.normalMiddle.addEventListener('change', this.handleMediaQueryChange.bind(this));
42
- this.normalLarge.addEventListener('change', this.handleMediaQueryChange.bind(this));
43
- this.superLarge.addEventListener('change', this.handleMediaQueryChange.bind(this));
44
- this.normalHuge.addEventListener('change', this.handleMediaQueryChange.bind(this));
45
- }
46
-
47
- componentWillUnmount () {
48
- this.ultraSmall.removeEventListener('change', this.handleMediaQueryChange.bind(this));
49
- this.normalSmall.removeEventListener('change', this.handleMediaQueryChange.bind(this));
50
- this.normalMiddle.removeEventListener('change', this.handleMediaQueryChange.bind(this));
51
- this.normalLarge.removeEventListener('change', this.handleMediaQueryChange.bind(this));
52
- this.superLarge.removeEventListener('change', this.handleMediaQueryChange.bind(this));
53
- this.normalHuge.removeEventListener('change', this.handleMediaQueryChange.bind(this));
54
- }
55
-
56
- handleMediaQueryChange () {
57
- const { disabled } = this.props;
58
-
59
- if (disabled) {
60
- return;
61
- }
62
-
63
- let media;
64
-
65
- if (this.ultraSmall.matches) {
66
- media = this.ultraSmall.media;
67
- } else if (this.normalSmall.matches) {
68
- media = this.normalSmall.media;
69
- } else if (this.normalMiddle.matches) {
70
- media = this.normalMiddle.media;
71
- } else if (this.normalLarge.matches) {
72
- media = this.normalLarge.media;
73
- } else if (this.superLarge.matches) {
74
- media = this.superLarge.media;
75
- } else if (this.normalHuge.matches) {
76
- media = this.normalHuge.media;
77
- }
78
-
79
- this.setState({ media: Object.keys(MEDIA_QUERY_LIST).find(key => media === MEDIA_QUERY_LIST[ key ]) });
80
- }
81
-
82
- get children () {
83
- return this.props.children;
84
- }
85
-
86
- render () {
87
- const { media } = this.state;
88
- const { children } = this.props;
89
-
90
- return (
91
- <>
92
- {(Array.isArray(children)
93
- ? children
94
- : [].concat(children)).map((item, key) => (
95
- React.createElement(item.type, {
96
- key,
97
- ...item.props,
98
- [ 'data-media-query' ]: media
99
- })
100
- ))}
101
- </>
102
- );
103
- }
104
- }
@@ -1,165 +0,0 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import { Form, Button, Space, Row, Col } from 'antd';
4
- import { SearchOutlined, DoubleRightOutlined, UndoOutlined } from '@ant-design/icons';
5
- import './index.less';
6
-
7
- class searchForm extends React.Component {
8
- form = React.createRef();
9
- state = {
10
- isOpen: false
11
- };
12
-
13
- getButtons () {
14
- const {
15
- form,
16
- expand,
17
- formLine,
18
- colSize,
19
- loading,
20
- onReset
21
- } = this.props;
22
- return (
23
- <Space>
24
- <Button
25
- type="primary"
26
- icon={<SearchOutlined />}
27
- htmlType="submit"
28
- loading={loading}
29
- >
30
- 查询
31
- </Button>
32
- <Button
33
- icon={<UndoOutlined />}
34
- loading={loading}
35
- onClick={() => {
36
- form
37
- ? form.current.resetFields()
38
- : this.form.current.resetFields();
39
- onReset(form
40
- ? form.current.getFieldsValue()
41
- : this.form.current.getFieldsValue());
42
- }}
43
- >
44
- 重置
45
- </Button>
46
- {expand && formLine.length / colSize > 1 && (
47
- <Button
48
- icon={(
49
- <DoubleRightOutlined
50
- style={{
51
- transform: this.state.isOpen
52
- ? 'rotate(-90deg)'
53
- : 'rotate(90deg)'
54
- }}
55
- />
56
- )}
57
- onClick={() => this.setState({ isOpen: !this.state.isOpen })}
58
- >
59
- {this.state.isOpen
60
- ? '收起'
61
- : '展开'}
62
- </Button>
63
- )}
64
- </Space>
65
- );
66
- }
67
-
68
- groupsList () {
69
- const arr = [];
70
- this.props.formLine.forEach(i => {
71
- arr.push({
72
- show: true,
73
- node: i
74
- });
75
- });
76
- if (this.props.expand && this.state.isOpen) {
77
- return arr;
78
- }
79
- if (!this.props.expand && arr.length > 3) {
80
- return arr;
81
- }
82
- arr.forEach((i, index) => {
83
- if (index > 2) {
84
- i.show = false;
85
- }
86
- });
87
- return arr;
88
- }
89
-
90
- componentDidMount () {
91
- if (this.props.onRef) {
92
- this.props.onRef(this.form);
93
- }
94
- }
95
-
96
- render () {
97
- const {
98
- form,
99
- style,
100
- colSize,
101
- initialValues,
102
- onFinish
103
- } = this.props;
104
- const formItemList = this.groupsList();
105
- return formItemList.length > 0
106
- ? (
107
- <Form
108
- ref={form || this.form}
109
- style={style}
110
- initialValues={initialValues}
111
- onFinish={values => onFinish(values)}
112
- >
113
- <Row gutter={[ 16, 16 ]}>
114
- {formItemList.map((item, index) => (
115
- <Col
116
- style={{
117
- display: item.show
118
- ? 'block'
119
- : 'none'
120
- }}
121
- key={index}
122
- span={24 / colSize}
123
- >
124
- {item.node}
125
- </Col>
126
- ))}
127
- <Col span={24 / colSize}>
128
- <Form.Item noStyle>
129
- {this.getButtons()}
130
- </Form.Item>
131
- </Col>
132
- </Row>
133
- </Form>
134
- )
135
- : <></>;
136
- }
137
- }
138
-
139
- searchForm.defaultProps = {
140
- style: {},
141
- expand: false,
142
- colSize: 3,
143
- loading: false,
144
- formLine: [],
145
- initialValues: {},
146
- onRef: () => {
147
- },
148
- onReset: () => {
149
- },
150
- onFinish: () => {
151
- }
152
- };
153
- searchForm.propTypes = {
154
- form: PropTypes.object,
155
- style: PropTypes.object,
156
- expand: PropTypes.bool,
157
- colSize: PropTypes.number,
158
- loading: PropTypes.bool,
159
- formLine: PropTypes.array,
160
- initialValues: PropTypes.object,
161
- onRef: PropTypes.func,
162
- onReset: PropTypes.func,
163
- onFinish: PropTypes.func
164
- };
165
- export default searchForm;