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

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.
@@ -0,0 +1,57 @@
1
+ // @ts-ignore
2
+ import * as React from 'react';
3
+ import { ComponentProps } from '../types';
4
+
5
+ interface FormilyDescriptionsProps extends ComponentProps {
6
+ /**
7
+ * @description 表单配置
8
+ */
9
+ schema: any,
10
+ /**
11
+ * @description 表单数据
12
+ */
13
+ values: any,
14
+ /**
15
+ * @description 尺寸
16
+ */
17
+ size?: 'default' | 'middle' | 'small';
18
+ /**
19
+ * @description 图片宽度
20
+ */
21
+ imageWidth?: number;
22
+ /**
23
+ * @description 图片高度
24
+ */
25
+ imageHeight?: number;
26
+ /**
27
+ * @description 图片预览配置
28
+ * @see https://ant.design/components/image-cn#previewtype
29
+ */
30
+ imagePreview?: boolean | {}
31
+ /**
32
+ * @description 是否显示冒号
33
+ * @see https://ant.design/components/descriptions-cn#descriptions
34
+ */
35
+ colon?: boolean;
36
+ /**
37
+ * @description 显示布局
38
+ * @see https://ant.design/components/descriptions-cn#descriptions
39
+ */
40
+ layout?: 'vertical' | 'horizontal';
41
+ /**
42
+ * @description 参考antd/description
43
+ * @see https://ant.design/components/descriptions-cn#descriptions
44
+ */
45
+ labelStyle?: {};
46
+ /**
47
+ * @description 参考antd/description
48
+ * @see https://ant.design/components/descriptions-cn#descriptions
49
+ */
50
+ contentStyle?: {};
51
+ }
52
+
53
+ interface FormilyDescriptionsFc extends React.FC<FormilyDescriptionsProps> {
54
+ }
55
+
56
+ declare const FormilyDescriptions: FormilyDescriptionsFc;
57
+ export default FormilyDescriptions;
@@ -0,0 +1,84 @@
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
+ import React from 'react';
3
+ import { tools } from '@cqsjjb/jjb-common-lib';
4
+ import { LinkOutlined } from '@ant-design/icons';
5
+ import { Descriptions, Empty, Image, Tooltip } from 'antd';
6
+ export default function FormilyDescriptions(props) {
7
+ const dataSource = tools.getDynamicFormilyFields(props.schema, props.values);
8
+ return dataSource.length === 0 ? /*#__PURE__*/React.createElement(Empty, {
9
+ image: Empty.PRESENTED_IMAGE_SIMPLE
10
+ }) : /*#__PURE__*/React.createElement(React.Fragment, null, dataSource.map((item, index) => {
11
+ const isLast = index === dataSource.length - 1;
12
+ return /*#__PURE__*/React.createElement(Descriptions, {
13
+ key: index,
14
+ size: props.size,
15
+ style: {
16
+ marginBottom: isLast ? 0 : 16
17
+ },
18
+ items: item.fromComponentEnum === 'GRID_FORM' ? item.children.map((child, childIndex) => {
19
+ return {
20
+ key: childIndex,
21
+ label: child.name,
22
+ children: /*#__PURE__*/React.createElement(ItemRender, _extends({
23
+ data: child
24
+ }, props))
25
+ };
26
+ }) : [{
27
+ key: 1,
28
+ label: item.name,
29
+ children: /*#__PURE__*/React.createElement(ItemRender, _extends({
30
+ data: item
31
+ }, props))
32
+ }],
33
+ colon: props.colon,
34
+ title: props.title,
35
+ extra: props.extra,
36
+ layout: props.layout || 'vertical',
37
+ column: 3,
38
+ labelStyle: props.labelStyle,
39
+ contentStyle: props.contentStyle
40
+ });
41
+ }));
42
+ }
43
+ function ItemRender(props) {
44
+ const {
45
+ data,
46
+ imageWidth,
47
+ imageHeight,
48
+ imagePreview
49
+ } = 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) => {
51
+ if (next.url) {
52
+ if (next.isImage) {
53
+ return /*#__PURE__*/React.createElement("span", {
54
+ key: nextIndex,
55
+ style: {
56
+ display: 'inline-block',
57
+ marginRight: 4,
58
+ marginBottom: 4
59
+ }
60
+ }, /*#__PURE__*/React.createElement(Image, {
61
+ src: next.url,
62
+ width: imageWidth || 64,
63
+ height: imageHeight || 64,
64
+ preview: imagePreview
65
+ }));
66
+ } else {
67
+ return /*#__PURE__*/React.createElement(Tooltip, {
68
+ title: next.url
69
+ }, /*#__PURE__*/React.createElement("a", {
70
+ key: nextIndex,
71
+ href: next.url,
72
+ style: {
73
+ gap: 4,
74
+ display: 'flex',
75
+ alignItems: 'center'
76
+ },
77
+ target: "_blank"
78
+ }, /*#__PURE__*/React.createElement(LinkOutlined, null), "\u70B9\u51FB\u4E0B\u8F7D"));
79
+ }
80
+ } else {
81
+ return tools.textPlaceholder(next.name);
82
+ }
83
+ })) : tools.textPlaceholder() : tools.textPlaceholder(data.value);
84
+ }
File without changes
@@ -0,0 +1,117 @@
1
+ import React from 'react';
2
+
3
+ import { tools } from '@cqsjjb/jjb-common-lib';
4
+ import { LinkOutlined } from '@ant-design/icons';
5
+ import { Descriptions, Empty, Image, Tooltip } from 'antd';
6
+
7
+ export default function FormilyDescriptions(props) {
8
+ const dataSource = tools.getDynamicFormilyFields(props.schema, props.values);
9
+ return dataSource.length === 0
10
+ ? <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
11
+ : (
12
+ <React.Fragment>
13
+ {dataSource.map((item, index) => {
14
+ const isLast = index === dataSource.length - 1;
15
+
16
+ return (
17
+ <Descriptions
18
+ key={index}
19
+ size={props.size}
20
+ style={{
21
+ marginBottom: isLast
22
+ ? 0
23
+ : 16
24
+ }}
25
+ items={item.fromComponentEnum === 'GRID_FORM'
26
+ ? item.children.map((child, childIndex) => {
27
+ return {
28
+ key: childIndex,
29
+ label: child.name,
30
+ children: (
31
+ <ItemRender data={child} {...props} />
32
+ )
33
+ };
34
+ })
35
+ : [
36
+ {
37
+ key: 1,
38
+ label: item.name,
39
+ children: <ItemRender data={item} {...props} />
40
+ }
41
+ ]}
42
+ colon={props.colon}
43
+ title={props.title}
44
+ extra={props.extra}
45
+ layout={props.layout || 'vertical'}
46
+ column={3}
47
+ labelStyle={props.labelStyle}
48
+ contentStyle={props.contentStyle}
49
+ />
50
+ );
51
+ })}
52
+ </React.Fragment>
53
+ );
54
+ }
55
+
56
+ function ItemRender(props) {
57
+ const {
58
+ data,
59
+ imageWidth,
60
+ imageHeight,
61
+ imagePreview
62
+ } = props;
63
+
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);
117
+ }
@@ -0,0 +1,38 @@
1
+ // @ts-ignore
2
+ import * as React from 'react';
3
+ import { ComponentProps } from '../types';
4
+
5
+ interface FormilyRendererProps extends ComponentProps {
6
+ /**
7
+ * @description 表单code
8
+ */
9
+ code: string,
10
+ /**
11
+ * @description 表单初始化值
12
+ */
13
+ initialValues?: Record<string, any>,
14
+ /**
15
+ * @description 禁用字段
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?: {}
32
+ }
33
+
34
+ interface FormilyRendererFc extends React.FC<FormilyRendererProps> {
35
+ }
36
+
37
+ declare const FormilyRenderer: FormilyRendererFc;
38
+ export default FormilyRenderer;
@@ -0,0 +1,37 @@
1
+ import React from 'react';
2
+ import Renderer from '@cqsjjb-formily/renderer';
3
+ import { http, tools } from '@cqsjjb/jjb-common-lib';
4
+ export default function FormilyRenderer(props) {
5
+ const form = React.useRef();
6
+ const [schema, setSchema] = React.useState({});
7
+ React.useEffect(() => {
8
+ http.Get(`/design/designs/${props.code}`).then(res => {
9
+ if (res.success) {
10
+ const {
11
+ config
12
+ } = res.data;
13
+ setSchema(tools.parseObject(config));
14
+ }
15
+ });
16
+ }, []);
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);
29
+ }
30
+ }, [schema]);
31
+ return /*#__PURE__*/React.createElement("div", {
32
+ style: props.style
33
+ }, !tools.isEmptyObject(schema) && /*#__PURE__*/React.createElement(Renderer, {
34
+ ref: form,
35
+ schema: schema
36
+ }));
37
+ }
@@ -0,0 +1,6 @@
1
+ .@{ant-prefix}-form-renderer {
2
+ .@{ant-prefix}-formily-grid-layout {
3
+ gap: 4px 30px !important;
4
+ grid-template-columns: repeat(3, minmax(0px, 1fr)) !important;
5
+ }
6
+ }
@@ -0,0 +1,44 @@
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 function FormilyRenderer (props) {
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 (!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);
31
+ }
32
+ }, [ schema ]);
33
+
34
+ return (
35
+ <div style={props.style}>
36
+ {!tools.isEmptyObject(schema) && (
37
+ <Renderer
38
+ ref={form}
39
+ schema={schema}
40
+ />
41
+ )}
42
+ </div>
43
+ );
44
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cqsjjb/jjb-react-admin-component",
3
- "version": "3.0.15",
3
+ "version": "3.0.17",
4
4
  "description": "jjb-react-admin-组件库@new",
5
5
  "main": "index.js",
6
6
  "author": "jjb-front-team",
@@ -13,6 +13,7 @@
13
13
  "spark-md5": "^3.0.2",
14
14
  "classnames": "^2.5.1",
15
15
  "antd-img-crop": "latest",
16
+ "@cqsjjb-formily/renderer": "latest",
16
17
  "@ant-design/pro-layout": "latest",
17
18
  "use-antd-resizable-header": "latest",
18
19
  "@ant-design/pro-components": "latest"