@guo514360255/antd-lib 1.8.0 → 1.9.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.
@@ -0,0 +1,28 @@
1
+ /*
2
+ * @Author: 郭郭
3
+ * @Date: 2026/4/8
4
+ * @Description:
5
+ */
6
+ import { CustomColumnProps } from '@guo514360255/antd-lib/src';
7
+
8
+ interface CustomDescriptionsProps {
9
+ /**
10
+ * 处理详情数据
11
+ */
12
+ handleDetailData: (data: any) => any;
13
+
14
+ /**
15
+ * 请求接口
16
+ */
17
+ request?: (data: any) => any;
18
+
19
+ /**
20
+ * 字段
21
+ */
22
+ columns: CustomColumnProps[];
23
+
24
+ /**
25
+ * 值
26
+ */
27
+ values?: { [key: string]: any };
28
+ }
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import type { CustomDescriptionsProps } from './descriptions';
3
+ declare const CustomDescriptions: ({ request, handleDetailData, columns, values, ...descProps }: CustomDescriptionsProps) => JSX.Element;
4
+ export default CustomDescriptions;
@@ -0,0 +1,198 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
3
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
4
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
5
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
6
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
7
+ var _excluded = ["request", "handleDetailData", "columns", "values"];
8
+ import { findTreeNodeByKey, isEmptyValue } from "../utils/util";
9
+ import { Descriptions, Image, Spin } from 'antd';
10
+ import isNumber from 'lodash/isNumber';
11
+ import isObject from 'lodash/isObject';
12
+ import isString from 'lodash/isString';
13
+ import React, { useEffect, useState } from 'react';
14
+ /*
15
+ * @Author: 郭郭
16
+ * @Date: 2026/4/8
17
+ * @Description:
18
+ */
19
+ var CustomDescriptions = function CustomDescriptions(_ref) {
20
+ var request = _ref.request,
21
+ handleDetailData = _ref.handleDetailData,
22
+ columns = _ref.columns,
23
+ values = _ref.values,
24
+ descProps = _objectWithoutProperties(_ref, _excluded);
25
+ var _useState = useState(false),
26
+ _useState2 = _slicedToArray(_useState, 2),
27
+ loading = _useState2[0],
28
+ setLoading = _useState2[1];
29
+ var _useState3 = useState({}),
30
+ _useState4 = _slicedToArray(_useState3, 2),
31
+ detail = _useState4[0],
32
+ setDetail = _useState4[1];
33
+ var handleDetailValue = function handleDetailValue(column, value, index) {
34
+ if (isEmptyValue(value)) return value;
35
+ var fieldProps = column.fieldProps,
36
+ valueEnum = column.valueEnum;
37
+ var _ref2 = fieldProps || {},
38
+ options = _ref2.options;
39
+ if (column.render) {
40
+ return column.render(value, detail, index, {}, column);
41
+ } else if (['select', 'radio'].includes(column.type)) {
42
+ var valuesEnum = _objectSpread({}, valueEnum);
43
+ var _values = "".concat(value).split(',');
44
+ var result = [];
45
+ if (Object.keys(valuesEnum).length > 0 && isObject(valuesEnum)) {
46
+ _values.forEach(function (item) {
47
+ var _item;
48
+ result.push(((_item = valuesEnum[item]) === null || _item === void 0 ? void 0 : _item.text) || value);
49
+ });
50
+ return result.join(',');
51
+ } else if (Array.isArray(options) && options.length > 0) {
52
+ _values.forEach(function (item) {
53
+ var _ref3 = findTreeNodeByKey(options, item) || {},
54
+ label = _ref3.label;
55
+ console.log(label, '...label...');
56
+ result.push(label || value);
57
+ });
58
+ return result.join(',');
59
+ }
60
+ return value;
61
+ }
62
+ return value;
63
+ };
64
+ var DescImage = function DescImage(_ref4) {
65
+ var data = _ref4.data;
66
+ if (!data) return data;
67
+ var list = data;
68
+ if (typeof data === 'string') {
69
+ list = data.split(',');
70
+ }
71
+ return /*#__PURE__*/React.createElement(Image.PreviewGroup, null, /*#__PURE__*/React.createElement("div", {
72
+ style: {
73
+ display: 'flex',
74
+ flexWrap: 'wrap',
75
+ gap: 10
76
+ }
77
+ }, list.map(function (item, index) {
78
+ return /*#__PURE__*/React.createElement(Image, {
79
+ key: index,
80
+ width: 100,
81
+ src: item.url || item,
82
+ alt: item.name || item,
83
+ style: {
84
+ marginRight: 10
85
+ }
86
+ });
87
+ })));
88
+ };
89
+ var getDetail = /*#__PURE__*/function () {
90
+ var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(id) {
91
+ var data;
92
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
93
+ while (1) switch (_context.prev = _context.next) {
94
+ case 0:
95
+ if (!(!isString(id) && !isNumber(id))) {
96
+ _context.next = 3;
97
+ break;
98
+ }
99
+ console.warn('Invalid id parameter:', id);
100
+ return _context.abrupt("return");
101
+ case 3:
102
+ if (!loading) {
103
+ _context.next = 5;
104
+ break;
105
+ }
106
+ return _context.abrupt("return");
107
+ case 5:
108
+ setLoading(true);
109
+ _context.prev = 6;
110
+ if (!request) {
111
+ _context.next = 12;
112
+ break;
113
+ }
114
+ _context.next = 10;
115
+ return request(id);
116
+ case 10:
117
+ data = _context.sent;
118
+ setDetail(handleDetailData ? handleDetailData(data) : data);
119
+ case 12:
120
+ _context.next = 17;
121
+ break;
122
+ case 14:
123
+ _context.prev = 14;
124
+ _context.t0 = _context["catch"](6);
125
+ console.error('Failed to fetch detail:', _context.t0);
126
+ case 17:
127
+ _context.prev = 17;
128
+ setLoading(false);
129
+ return _context.finish(17);
130
+ case 20:
131
+ case "end":
132
+ return _context.stop();
133
+ }
134
+ }, _callee, null, [[6, 14, 17, 20]]);
135
+ }));
136
+ return function getDetail(_x) {
137
+ return _ref5.apply(this, arguments);
138
+ };
139
+ }();
140
+ useEffect(function () {
141
+ _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
142
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
143
+ while (1) switch (_context2.prev = _context2.next) {
144
+ case 0:
145
+ if (!(values !== null && values !== void 0 && values.id && request)) {
146
+ _context2.next = 5;
147
+ break;
148
+ }
149
+ _context2.next = 3;
150
+ return getDetail(values.id);
151
+ case 3:
152
+ _context2.next = 15;
153
+ break;
154
+ case 5:
155
+ _context2.t0 = setDetail;
156
+ if (!handleDetailData) {
157
+ _context2.next = 12;
158
+ break;
159
+ }
160
+ _context2.next = 9;
161
+ return handleDetailData(values);
162
+ case 9:
163
+ _context2.t1 = _context2.sent;
164
+ _context2.next = 13;
165
+ break;
166
+ case 12:
167
+ _context2.t1 = values;
168
+ case 13:
169
+ _context2.t2 = _context2.t1;
170
+ (0, _context2.t0)(_context2.t2);
171
+ case 15:
172
+ case "end":
173
+ return _context2.stop();
174
+ }
175
+ }, _callee2);
176
+ }))();
177
+ }, [JSON.stringify(values)]);
178
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Descriptions, _extends({
179
+ column: 1,
180
+ bordered: true
181
+ }, descProps || {}), columns === null || columns === void 0 ? void 0 : columns.filter(function (item) {
182
+ return !item.hideInDetail;
183
+ }).map(function (item, index) {
184
+ var _item$fieldProps, _item$fieldProps2;
185
+ return /*#__PURE__*/React.createElement(React.Fragment, {
186
+ key: item.dataIndex
187
+ }, /*#__PURE__*/React.createElement(Descriptions.Item, _extends({
188
+ key: item.dataIndex,
189
+ label: "".concat(item.title)
190
+ }, ((_item$fieldProps = item.fieldProps) === null || _item$fieldProps === void 0 ? void 0 : _item$fieldProps.descriptionsItemProps) || {}), item.type === 'upload' ? /*#__PURE__*/React.createElement(DescImage, {
191
+ data: detail[item.dataIndex]
192
+ }) : handleDetailValue(item, detail[item.dataIndex], index) || '-', /*#__PURE__*/React.createElement("span", null, ((_item$fieldProps2 = item.fieldProps) === null || _item$fieldProps2 === void 0 ? void 0 : _item$fieldProps2.suffix) || '')));
193
+ })), /*#__PURE__*/React.createElement(Spin, {
194
+ spinning: loading,
195
+ fullscreen: true
196
+ }));
197
+ };
198
+ export default CustomDescriptions;
@@ -1,5 +1,4 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
2
  import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
4
3
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
5
4
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
@@ -11,11 +10,8 @@ var _excluded = ["type", "columns", "detailRequest", "handleDetailData", "title"
11
10
  * @Description:
12
11
  */
13
12
 
14
- import { findTreeNodeByKey, isEmptyValue } from "../utils/util";
15
- import { Descriptions, Drawer, Image, Modal, Spin } from 'antd';
16
- import isNumber from 'lodash/isNumber';
17
- import isObject from 'lodash/isObject';
18
- import isString from 'lodash/isString';
13
+ import CustomDescriptions from "../CustomDescriptions";
14
+ import { Drawer, Modal } from 'antd';
19
15
  import React, { forwardRef, useImperativeHandle, useState } from 'react';
20
16
  import "./index.less";
21
17
  var CustomModal = /*#__PURE__*/forwardRef(function (props, ref) {
@@ -30,168 +26,37 @@ var CustomModal = /*#__PURE__*/forwardRef(function (props, ref) {
30
26
  _useState2 = _slicedToArray(_useState, 2),
31
27
  open = _useState2[0],
32
28
  setOpen = _useState2[1];
33
- var _useState3 = useState(false),
29
+ var _useState3 = useState(),
34
30
  _useState4 = _slicedToArray(_useState3, 2),
35
- loading = _useState4[0],
36
- setLoading = _useState4[1];
37
- var _useState5 = useState({}),
38
- _useState6 = _slicedToArray(_useState5, 2),
39
- detail = _useState6[0],
40
- setDetail = _useState6[1];
31
+ detail = _useState4[0],
32
+ setDetail = _useState4[1];
41
33
  var modalType = {
42
34
  modal: Modal,
43
35
  drawer: Drawer
44
36
  };
45
37
  var Component = modalType[type || 'drawer'];
46
- var getDetail = /*#__PURE__*/function () {
47
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(id) {
48
- var data;
49
- return _regeneratorRuntime().wrap(function _callee$(_context) {
50
- while (1) switch (_context.prev = _context.next) {
51
- case 0:
52
- if (!(!isString(id) && !isNumber(id))) {
53
- _context.next = 3;
54
- break;
55
- }
56
- console.warn('Invalid id parameter:', id);
57
- return _context.abrupt("return");
58
- case 3:
59
- if (!loading) {
60
- _context.next = 5;
61
- break;
62
- }
63
- return _context.abrupt("return");
64
- case 5:
65
- setLoading(true);
66
- _context.prev = 6;
67
- _context.next = 9;
68
- return detailRequest(id);
69
- case 9:
70
- data = _context.sent;
71
- setDetail(handleDetailData ? handleDetailData(data) : data);
72
- _context.next = 16;
73
- break;
74
- case 13:
75
- _context.prev = 13;
76
- _context.t0 = _context["catch"](6);
77
- console.error('Failed to fetch detail:', _context.t0);
78
- case 16:
79
- _context.prev = 16;
80
- setLoading(false);
81
- return _context.finish(16);
82
- case 19:
83
- case "end":
84
- return _context.stop();
85
- }
86
- }, _callee, null, [[6, 13, 16, 19]]);
87
- }));
88
- return function getDetail(_x) {
89
- return _ref.apply(this, arguments);
90
- };
91
- }();
92
38
  var close = function close() {
93
39
  setOpen(false);
94
40
  };
95
41
  useImperativeHandle(ref, function () {
96
42
  return {
97
43
  open: function open(values) {
98
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
99
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
100
- while (1) switch (_context2.prev = _context2.next) {
44
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
45
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
46
+ while (1) switch (_context.prev = _context.next) {
101
47
  case 0:
102
48
  setOpen(true);
103
- if (!(values.id && detailRequest)) {
104
- _context2.next = 6;
105
- break;
106
- }
107
- _context2.next = 4;
108
- return getDetail(values.id);
109
- case 4:
110
- _context2.next = 16;
111
- break;
112
- case 6:
113
- _context2.t0 = setDetail;
114
- if (!handleDetailData) {
115
- _context2.next = 13;
116
- break;
117
- }
118
- _context2.next = 10;
119
- return handleDetailData(values);
120
- case 10:
121
- _context2.t1 = _context2.sent;
122
- _context2.next = 14;
123
- break;
124
- case 13:
125
- _context2.t1 = values;
126
- case 14:
127
- _context2.t2 = _context2.t1;
128
- (0, _context2.t0)(_context2.t2);
129
- case 16:
49
+ setDetail(values);
50
+ case 2:
130
51
  case "end":
131
- return _context2.stop();
52
+ return _context.stop();
132
53
  }
133
- }, _callee2);
54
+ }, _callee);
134
55
  }))();
135
56
  },
136
57
  close: close
137
58
  };
138
59
  });
139
- var handleDetailValue = function handleDetailValue(column, value, index) {
140
- if (isEmptyValue(value)) return value;
141
- var fieldProps = column.fieldProps,
142
- valueEnum = column.valueEnum;
143
- var _ref2 = fieldProps || {},
144
- options = _ref2.options;
145
- if (column.render) {
146
- return column.render(value, detail, index, {}, column);
147
- } else if (['select', 'radio'].includes(column.type)) {
148
- var valuesEnum = _objectSpread({}, valueEnum);
149
- var values = "".concat(value).split(',');
150
- var result = [];
151
- if (Object.keys(valuesEnum).length > 0 && isObject(valuesEnum)) {
152
- values.forEach(function (item) {
153
- var _item;
154
- result.push(((_item = valuesEnum[item]) === null || _item === void 0 ? void 0 : _item.text) || value);
155
- });
156
- return result.join(',');
157
- } else if (Array.isArray(options) && options.length > 0) {
158
- values.forEach(function (item) {
159
- var _ref3 = findTreeNodeByKey(options, item) || {},
160
- label = _ref3.label;
161
- console.log(label, '...label...');
162
- result.push(label || value);
163
- });
164
- return result.join(',');
165
- }
166
- return value;
167
- }
168
- return value;
169
- };
170
- var DescImage = function DescImage(_ref4) {
171
- var data = _ref4.data;
172
- if (!data) return data;
173
- var list = data;
174
- if (typeof data === 'string') {
175
- list = data.split(',');
176
- }
177
- return /*#__PURE__*/React.createElement(Image.PreviewGroup, null, /*#__PURE__*/React.createElement("div", {
178
- style: {
179
- display: 'flex',
180
- flexWrap: 'wrap',
181
- gap: 10
182
- }
183
- }, list.map(function (item, index) {
184
- return /*#__PURE__*/React.createElement(Image, {
185
- key: index,
186
- width: 100,
187
- src: item.url || item,
188
- alt: item.name || item,
189
- style: {
190
- marginRight: 10
191
- }
192
- });
193
- })));
194
- };
195
60
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Component, _extends({
196
61
  width: other.width || 600,
197
62
  title: "".concat(title || '', "\u8BE6\u60C5")
@@ -199,24 +64,11 @@ var CustomModal = /*#__PURE__*/forwardRef(function (props, ref) {
199
64
  open: open,
200
65
  onClose: close,
201
66
  className: "detailContainer"
202
- }), /*#__PURE__*/React.createElement(Descriptions, _extends({
203
- column: 1,
204
- bordered: true
205
- }, descProps || {}), columns === null || columns === void 0 ? void 0 : columns.filter(function (item) {
206
- return !item.hideInDetail;
207
- }).map(function (item, index) {
208
- var _item$fieldProps, _item$fieldProps2;
209
- return /*#__PURE__*/React.createElement(React.Fragment, {
210
- key: item.dataIndex
211
- }, /*#__PURE__*/React.createElement(Descriptions.Item, _extends({
212
- key: item.dataIndex,
213
- label: "".concat(item.title)
214
- }, ((_item$fieldProps = item.fieldProps) === null || _item$fieldProps === void 0 ? void 0 : _item$fieldProps.descriptionsItemProps) || {}), item.type === 'upload' ? /*#__PURE__*/React.createElement(DescImage, {
215
- data: detail[item.dataIndex]
216
- }) : handleDetailValue(item, detail[item.dataIndex], index) || '-', /*#__PURE__*/React.createElement("span", null, ((_item$fieldProps2 = item.fieldProps) === null || _item$fieldProps2 === void 0 ? void 0 : _item$fieldProps2.suffix) || '')));
217
- }))), /*#__PURE__*/React.createElement(Spin, {
218
- spinning: loading,
219
- fullscreen: true
220
- }));
67
+ }), /*#__PURE__*/React.createElement(CustomDescriptions, _extends({
68
+ request: detailRequest,
69
+ columns: columns,
70
+ handleDetailData: handleDetailData,
71
+ values: detail
72
+ }, descProps))));
221
73
  });
222
74
  export default CustomModal;
package/dist/index.d.ts CHANGED
@@ -9,6 +9,8 @@ export { default as CustomScroll } from './CustomScroll';
9
9
  export type { CustomScrollProps } from './CustomScroll/scroll';
10
10
  export { default as CustomForm } from './CustomForm';
11
11
  export type { CustomFormProps } from './CustomForm/form';
12
+ export { default as CustomDescriptions } from './CustomDescriptions';
13
+ export type { CustomDescriptionsProps } from './CustomDescriptions/descriptions';
12
14
  export { default as CustomTag } from './CustomTag';
13
15
  export { default as CustomUpload } from './CustomUpload';
14
16
  export { default as DynamicIcon } from './DynamicIcon';
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@ export { default as CustomModal } from "./CustomFormModal";
3
3
  export { default as CustomTable } from "./CustomTable";
4
4
  export { default as CustomScroll } from "./CustomScroll";
5
5
  export { default as CustomForm } from "./CustomForm";
6
+ export { default as CustomDescriptions } from "./CustomDescriptions";
6
7
  export { default as CustomTag } from "./CustomTag";
7
8
  export { default as CustomUpload } from "./CustomUpload";
8
9
  export { default as DynamicIcon } from "./DynamicIcon";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guo514360255/antd-lib",
3
- "version": "1.8.0",
3
+ "version": "1.9.0",
4
4
  "description": "react design 5 lib",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",