@cqsjjb/jjb-react-admin-component 3.0.17 → 3.0.18

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.
@@ -42,12 +42,12 @@ interface FormilyDescriptionsProps extends ComponentProps {
42
42
  * @description 参考antd/description
43
43
  * @see https://ant.design/components/descriptions-cn#descriptions
44
44
  */
45
- labelStyle?: {};
45
+ labelStyle?: React.CSSProperties;
46
46
  /**
47
47
  * @description 参考antd/description
48
48
  * @see https://ant.design/components/descriptions-cn#descriptions
49
49
  */
50
- contentStyle?: {};
50
+ contentStyle?: React.CSSProperties;
51
51
  }
52
52
 
53
53
  interface FormilyDescriptionsFc extends React.FC<FormilyDescriptionsProps> {
@@ -1,8 +1,9 @@
1
1
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
2
  import React from 'react';
3
3
  import { tools } from '@cqsjjb/jjb-common-lib';
4
- import { LinkOutlined } from '@ant-design/icons';
5
- import { Descriptions, Empty, Image, Tooltip } from 'antd';
4
+ import { FilePdfOutlined, LinkOutlined } from '@ant-design/icons';
5
+ import { Modal, Descriptions, Empty, Image, Tooltip, Tag, Spin } from 'antd';
6
+ const formilyItemMargin = new Map([['small', 8], ['middle', 12], ['default', 16]]);
6
7
  export default function FormilyDescriptions(props) {
7
8
  const dataSource = tools.getDynamicFormilyFields(props.schema, props.values);
8
9
  return dataSource.length === 0 ? /*#__PURE__*/React.createElement(Empty, {
@@ -13,7 +14,7 @@ export default function FormilyDescriptions(props) {
13
14
  key: index,
14
15
  size: props.size,
15
16
  style: {
16
- marginBottom: isLast ? 0 : 16
17
+ marginBottom: isLast ? 0 : formilyItemMargin.get(props.size || 'default')
17
18
  },
18
19
  items: item.fromComponentEnum === 'GRID_FORM' ? item.children.map((child, childIndex) => {
19
20
  return {
@@ -41,13 +42,15 @@ export default function FormilyDescriptions(props) {
41
42
  }));
42
43
  }
43
44
  function ItemRender(props) {
45
+ const [open, setOpen] = React.useState(false);
46
+ const [previewUrl, setPreviewUrl] = React.useState('');
44
47
  const {
45
48
  data,
46
49
  imageWidth,
47
50
  imageHeight,
48
51
  imagePreview
49
52
  } = props;
50
- return tools.isArray(data.value) ? tools.isStringArray(data.value) || tools.isNumberArray(data.value) ? data.value.join('、') : tools.isObjectArray(data.value) ? /*#__PURE__*/React.createElement("div", null, data.value.map((next, nextIndex) => {
53
+ return /*#__PURE__*/React.createElement(React.Fragment, null, tools.isArray(data.value) ? tools.isStringArray(data.value) || tools.isNumberArray(data.value) ? data.value.join('、') : tools.isObjectArray(data.value) ? /*#__PURE__*/React.createElement("div", null, data.value.map((next, nextIndex) => {
51
54
  if (next.url) {
52
55
  if (next.isImage) {
53
56
  return /*#__PURE__*/React.createElement("span", {
@@ -66,7 +69,18 @@ function ItemRender(props) {
66
69
  } else {
67
70
  return /*#__PURE__*/React.createElement(Tooltip, {
68
71
  title: next.url
69
- }, /*#__PURE__*/React.createElement("a", {
72
+ }, /\.pdf$/.test(next.url) ? /*#__PURE__*/React.createElement("a", {
73
+ key: nextIndex,
74
+ style: {
75
+ gap: 4,
76
+ display: 'flex',
77
+ alignItems: 'center'
78
+ },
79
+ onClick: () => {
80
+ setOpen(true);
81
+ setPreviewUrl(next.url);
82
+ }
83
+ }, /*#__PURE__*/React.createElement(FilePdfOutlined, null), "\u70B9\u51FB\u67E5\u770B") : /*#__PURE__*/React.createElement("a", {
70
84
  key: nextIndex,
71
85
  href: next.url,
72
86
  style: {
@@ -80,5 +94,73 @@ function ItemRender(props) {
80
94
  } else {
81
95
  return tools.textPlaceholder(next.name);
82
96
  }
83
- })) : tools.textPlaceholder() : tools.textPlaceholder(data.value);
97
+ })) : tools.textPlaceholder() : /*#__PURE__*/React.createElement(RenderText, {
98
+ value: data.value
99
+ }) /*tools.textPlaceholder(data.value)*/, /*#__PURE__*/React.createElement(Modal, {
100
+ destroyOnClose: true,
101
+ title: "\u67E5\u770BPDF",
102
+ open: open,
103
+ width: 1100,
104
+ footer: false,
105
+ onCancel: () => setOpen(false)
106
+ }, /*#__PURE__*/React.createElement("embed", {
107
+ src: previewUrl,
108
+ width: "100%",
109
+ height: 600
110
+ })));
111
+ }
112
+ function generateValue(data, prefix = []) {
113
+ const result = [];
114
+ data.forEach(item => {
115
+ // 当前节点的完整 name
116
+ const currentName = prefix.concat(item.title);
117
+ result.push({
118
+ name: currentName,
119
+ key: item.key
120
+ });
121
+ if (item.children && item.children.length > 0) {
122
+ // 递归处理子节点
123
+ result.push(...generateValue(item.children, currentName));
124
+ }
125
+ });
126
+ return result;
127
+ }
128
+ function RenderText(props) {
129
+ const {
130
+ value
131
+ } = props;
132
+ const [text, setText] = React.useState();
133
+ const [loading, setLoading] = React.useState(false);
134
+ React.useEffect(() => {
135
+ if (value.load) {
136
+ setLoading(true);
137
+ value.load().then(res => res.json()).then(res => {
138
+ if (res.success) {
139
+ const data = generateValue(res.data);
140
+ setText(value.selected?.map(item => {
141
+ return data.find(i => i.key === item.key)?.name?.join('/');
142
+ })?.filter(i => i));
143
+ }
144
+ setLoading(false);
145
+ });
146
+ } else {
147
+ setText(value);
148
+ }
149
+ }, []);
150
+ return Array.isArray(text) ? /*#__PURE__*/React.createElement(Spin, {
151
+ spinning: loading
152
+ }, /*#__PURE__*/React.createElement("div", {
153
+ style: {
154
+ gap: 6,
155
+ display: 'flex',
156
+ minHeight: 22,
157
+ flexDirection: 'column'
158
+ }
159
+ }, text.map((item, index) => /*#__PURE__*/React.createElement(Tag, {
160
+ style: {
161
+ background: '#eee'
162
+ },
163
+ index: index,
164
+ bordered: false
165
+ }, item)))) : text;
84
166
  }
@@ -1,8 +1,14 @@
1
1
  import React from 'react';
2
2
 
3
3
  import { tools } from '@cqsjjb/jjb-common-lib';
4
- import { LinkOutlined } from '@ant-design/icons';
5
- import { Descriptions, Empty, Image, Tooltip } from 'antd';
4
+ import { FilePdfOutlined, LinkOutlined } from '@ant-design/icons';
5
+ import { Modal, Descriptions, Empty, Image, Tooltip, Tag, Spin } from 'antd';
6
+
7
+ const formilyItemMargin = new Map([
8
+ [ 'small', 8 ],
9
+ [ 'middle', 12 ],
10
+ [ 'default', 16 ]
11
+ ]);
6
12
 
7
13
  export default function FormilyDescriptions(props) {
8
14
  const dataSource = tools.getDynamicFormilyFields(props.schema, props.values);
@@ -20,7 +26,7 @@ export default function FormilyDescriptions(props) {
20
26
  style={{
21
27
  marginBottom: isLast
22
28
  ? 0
23
- : 16
29
+ : formilyItemMargin.get(props.size || 'default')
24
30
  }}
25
31
  items={item.fromComponentEnum === 'GRID_FORM'
26
32
  ? item.children.map((child, childIndex) => {
@@ -54,6 +60,9 @@ export default function FormilyDescriptions(props) {
54
60
  }
55
61
 
56
62
  function ItemRender(props) {
63
+ const [ open, setOpen ] = React.useState(false);
64
+ const [ previewUrl, setPreviewUrl ] = React.useState('');
65
+
57
66
  const {
58
67
  data,
59
68
  imageWidth,
@@ -61,57 +70,163 @@ function ItemRender(props) {
61
70
  imagePreview
62
71
  } = props;
63
72
 
64
- return tools.isArray(data.value)
65
- ? (tools.isStringArray(data.value) || tools.isNumberArray(data.value))
66
- ? data.value.join('、')
67
- : tools.isObjectArray(data.value)
68
- ? (
69
- <div>
70
- {data.value.map((next, nextIndex) => {
71
- if (next.url) {
72
- if (next.isImage) {
73
- return (
74
- <span
75
- key={nextIndex}
76
- style={{
77
- display: 'inline-block',
78
- marginRight: 4,
79
- marginBottom: 4
80
- }}
81
- >
82
- <Image
83
- src={next.url}
84
- width={imageWidth || 64}
85
- height={imageHeight || 64}
86
- preview={imagePreview}
87
- />
88
- </span>
89
- );
90
- } else {
91
- return (
92
- <Tooltip title={next.url}>
93
- <a
94
- key={nextIndex}
95
- href={next.url}
96
- style={{
97
- gap: 4,
98
- display: 'flex',
99
- alignItems: 'center'
100
- }}
101
- target="_blank"
102
- >
103
- <LinkOutlined />
104
- 点击下载
105
- </a>
106
- </Tooltip>
107
- );
108
- }
109
- } else {
110
- return tools.textPlaceholder(next.name);
111
- }
112
- })}
113
- </div>
114
- )
115
- : tools.textPlaceholder()
116
- : tools.textPlaceholder(data.value);
73
+ return (
74
+ <React.Fragment>
75
+ {tools.isArray(data.value)
76
+ ? (tools.isStringArray(data.value) || tools.isNumberArray(data.value))
77
+ ? data.value.join('、')
78
+ : tools.isObjectArray(data.value)
79
+ ? (
80
+ <div>
81
+ {data.value.map((next, nextIndex) => {
82
+ if (next.url) {
83
+ if (next.isImage) {
84
+ return (
85
+ <span
86
+ key={nextIndex}
87
+ style={{
88
+ display: 'inline-block',
89
+ marginRight: 4,
90
+ marginBottom: 4
91
+ }}
92
+ >
93
+ <Image
94
+ src={next.url}
95
+ width={imageWidth || 64}
96
+ height={imageHeight || 64}
97
+ preview={imagePreview}
98
+ />
99
+ </span>
100
+ );
101
+ } else {
102
+ return (
103
+ <Tooltip title={next.url}>
104
+ {/\.pdf$/.test(next.url)
105
+ ? (
106
+ <a
107
+ key={nextIndex}
108
+ style={{
109
+ gap: 4,
110
+ display: 'flex',
111
+ alignItems: 'center'
112
+ }}
113
+ onClick={() => {
114
+ setOpen(true);
115
+ setPreviewUrl(next.url);
116
+ }}
117
+ >
118
+ <FilePdfOutlined />
119
+ 点击查看
120
+ </a>
121
+ )
122
+ : (
123
+ <a
124
+ key={nextIndex}
125
+ href={next.url}
126
+ style={{
127
+ gap: 4,
128
+ display: 'flex',
129
+ alignItems: 'center'
130
+ }}
131
+ target="_blank"
132
+ >
133
+ <LinkOutlined />
134
+ 点击下载
135
+ </a>
136
+ )}
137
+ </Tooltip>
138
+ );
139
+ }
140
+ } else {
141
+ return tools.textPlaceholder(next.name);
142
+ }
143
+ })}
144
+ </div>
145
+ )
146
+ : tools.textPlaceholder()
147
+ : <RenderText value={data.value} />/*tools.textPlaceholder(data.value)*/}
148
+ <Modal
149
+ destroyOnClose
150
+ title="查看PDF"
151
+ open={open}
152
+ width={1100}
153
+ footer={false}
154
+ onCancel={() => setOpen(false)}
155
+ >
156
+ <embed
157
+ src={previewUrl}
158
+ width="100%"
159
+ height={600}
160
+ />
161
+ </Modal>
162
+ </React.Fragment>
163
+ );
164
+ }
165
+
166
+ function generateValue(data, prefix = []) {
167
+ const result = [];
168
+
169
+ data.forEach(item => {
170
+ // 当前节点的完整 name
171
+ const currentName = prefix.concat(item.title);
172
+ result.push({
173
+ name: currentName,
174
+ key: item.key
175
+ });
176
+
177
+ if (item.children && item.children.length > 0) {
178
+ // 递归处理子节点
179
+ result.push(...generateValue(item.children, currentName));
180
+ }
181
+ });
182
+
183
+ return result;
184
+ }
185
+
186
+ function RenderText(props) {
187
+ const { value } = props;
188
+ const [ text, setText ] = React.useState();
189
+ const [ loading, setLoading ] = React.useState(false);
190
+
191
+ React.useEffect(() => {
192
+ if (value.load) {
193
+ setLoading(true);
194
+ value.load().then(res => res.json()).then(res => {
195
+ if (res.success) {
196
+ const data = generateValue(res.data);
197
+ setText(value.selected?.map(item => {
198
+ return data.find(i => i.key === item.key)?.name?.join('/');
199
+ })?.filter(i => i));
200
+ }
201
+ setLoading(false);
202
+ });
203
+ } else {
204
+ setText(value);
205
+ }
206
+ }, []);
207
+
208
+ return Array.isArray(text)
209
+ ? (
210
+ <Spin spinning={loading}>
211
+ <div
212
+ style={{
213
+ gap: 6,
214
+ display: 'flex',
215
+ minHeight: 22,
216
+ flexDirection: 'column'
217
+ }}
218
+ >
219
+ {text.map((item, index) => (
220
+ <Tag
221
+ style={{ background: '#eee' }}
222
+ index={index}
223
+ bordered={false}
224
+ >
225
+ {item}
226
+ </Tag>
227
+ ))}
228
+ </div>
229
+ </Spin>
230
+ )
231
+ : text;
117
232
  }
@@ -28,7 +28,7 @@ interface FormilyRendererProps extends ComponentProps {
28
28
  * @description 样式
29
29
  * @see https://ant.design/components/image-cn#previewtype
30
30
  */
31
- style?: {}
31
+ style?: React.CSSProperties
32
32
  }
33
33
 
34
34
  interface FormilyRendererFc extends React.FC<FormilyRendererProps> {
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import Renderer from '@cqsjjb-formily/renderer';
3
3
  import { http, tools } from '@cqsjjb/jjb-common-lib';
4
- export default function FormilyRenderer(props) {
4
+ export default /*#__PURE__*/React.forwardRef((props, ref) => {
5
5
  const form = React.useRef();
6
6
  const [schema, setSchema] = React.useState({});
7
7
  React.useEffect(() => {
@@ -15,23 +15,24 @@ export default function FormilyRenderer(props) {
15
15
  });
16
16
  }, []);
17
17
  React.useEffect(() => {
18
- if (!tools.isEmptyObject(schema)) {
19
- form.current.setValues(props.initialValues);
20
- setTimeout(() => {
21
- for (const field of tools.toArray(props.disabledFields)) {
22
- if (form.current.fields[field]) {
23
- form.current.fields[field].required = false;
24
- form.current.fields[field].disabled = true;
25
- }
26
- }
27
- }, 1000);
28
- props.getRef && props.getRef(form);
18
+ if (ref) {
19
+ ref.current = form.current;
29
20
  }
21
+ form.current.setValues(props.initialValues);
22
+ setTimeout(() => {
23
+ for (const field of tools.toArray(props.disabledFields)) {
24
+ if (form.current.fields[field]) {
25
+ form.current.fields[field].required = false;
26
+ form.current.fields[field].disabled = true;
27
+ }
28
+ }
29
+ }, 1000);
30
+ props.getRef && props.getRef(form);
30
31
  }, [schema]);
31
32
  return /*#__PURE__*/React.createElement("div", {
32
33
  style: props.style
33
- }, !tools.isEmptyObject(schema) && /*#__PURE__*/React.createElement(Renderer, {
34
+ }, /*#__PURE__*/React.createElement(Renderer, {
34
35
  ref: form,
35
36
  schema: schema
36
37
  }));
37
- }
38
+ });
@@ -3,7 +3,7 @@ import Renderer from '@cqsjjb-formily/renderer';
3
3
 
4
4
  import { http, tools } from '@cqsjjb/jjb-common-lib';
5
5
 
6
- export default function FormilyRenderer (props) {
6
+ export default React.forwardRef((props, ref) => {
7
7
  const form = React.useRef();
8
8
  const [ schema, setSchema ] = React.useState({});
9
9
 
@@ -17,28 +17,30 @@ export default function FormilyRenderer (props) {
17
17
  }, []);
18
18
 
19
19
  React.useEffect(() => {
20
- if (!tools.isEmptyObject(schema)) {
21
- form.current.setValues(props.initialValues);
22
- setTimeout(() => {
23
- for (const field of tools.toArray(props.disabledFields)) {
24
- if (form.current.fields[ field ]) {
25
- form.current.fields[ field ].required = false;
26
- form.current.fields[ field ].disabled = true;
27
- }
28
- }
29
- }, 1000);
30
- props.getRef && props.getRef(form);
20
+ if (ref) {
21
+ ref.current = form.current;
31
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);
32
36
  }, [ schema ]);
33
37
 
34
38
  return (
35
39
  <div style={props.style}>
36
- {!tools.isEmptyObject(schema) && (
37
- <Renderer
38
- ref={form}
39
- schema={schema}
40
- />
41
- )}
40
+ <Renderer
41
+ ref={form}
42
+ schema={schema}
43
+ />
42
44
  </div>
43
45
  );
44
- }
46
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cqsjjb/jjb-react-admin-component",
3
- "version": "3.0.17",
3
+ "version": "3.0.18",
4
4
  "description": "jjb-react-admin-组件库@new",
5
5
  "main": "index.js",
6
6
  "author": "jjb-front-team",