@guo514360255/antd-lib 1.4.25 → 1.4.27

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.
@@ -135,14 +135,15 @@ var CustomModal = /*#__PURE__*/forwardRef(function (props, ref) {
135
135
  if (Object.keys(valuesEnum).length > 0 && isObject(valuesEnum)) {
136
136
  values.forEach(function (item) {
137
137
  var _item;
138
- result.push((_item = valuesEnum[item]) === null || _item === void 0 ? void 0 : _item.text);
138
+ result.push(((_item = valuesEnum[item]) === null || _item === void 0 ? void 0 : _item.text) || value);
139
139
  });
140
140
  return result.join(',');
141
141
  } else if (Array.isArray(options) && options.length > 0) {
142
142
  values.forEach(function (item) {
143
143
  var _ref3 = findTreeNodeByKey(options, item) || {},
144
144
  label = _ref3.label;
145
- result.push(label);
145
+ console.log(label, '...label...');
146
+ result.push(label || value);
146
147
  });
147
148
  return result.join(',');
148
149
  }
@@ -6,7 +6,8 @@ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
6
6
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
7
7
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
8
8
  var _excluded = ["isIndex", "isDelete", "isUpdateState", "isDetail", "isUpdate", "isCreate", "createText", "columns", "rowKey", "request", "title", "defaultQueryParams", "toolBarRender", "formColumns", "formList", "dataSource", "deleteRequest", "detailRequest", "saveRequest", "updateRequest", "updateStateRequest", "handleModalData", "handleDetailData", "formProps", "detailProps"],
9
- _excluded2 = ["list"];
9
+ _excluded2 = ["text", "msg", "isConfirm", "onClick", "danger", "isShow", "order"],
10
+ _excluded3 = ["list"];
10
11
  /*
11
12
  * @Author: 郭郭
12
13
  * @Date: 2025/8/11
@@ -15,9 +16,11 @@ var _excluded = ["isIndex", "isDelete", "isUpdateState", "isDetail", "isUpdate",
15
16
 
16
17
  import { ProTable } from '@ant-design/pro-table';
17
18
  import CustomFormModal from "../CustomFormModal";
19
+ import { isEmptyValue } from "../utils/util";
18
20
  import { Button, message, Popconfirm, Progress } from 'antd';
19
21
  import cloneDeep from 'lodash/cloneDeep';
20
22
  import debounce from 'lodash/debounce';
23
+ import isFunction from 'lodash/isFunction';
21
24
  import React, { forwardRef, useEffect, useImperativeHandle, useRef, useState } from 'react';
22
25
  import CustomDetailModal from "../CustomDetailModal";
23
26
  import "./index.less";
@@ -78,57 +81,59 @@ var CustomTable = /*#__PURE__*/forwardRef(function (props, ref) {
78
81
  setScrollBar = _useState4[1];
79
82
  var tableContainerRef = useRef(null);
80
83
  var delEvent = /*#__PURE__*/function () {
81
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(id) {
84
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
85
+ var id;
82
86
  return _regeneratorRuntime().wrap(function _callee$(_context) {
83
87
  while (1) switch (_context.prev = _context.next) {
84
88
  case 0:
89
+ id = _ref.id;
85
90
  setLoading(true);
86
- _context.prev = 1;
91
+ _context.prev = 2;
87
92
  if (!deleteRequest) {
88
- _context.next = 9;
93
+ _context.next = 10;
89
94
  break;
90
95
  }
91
- _context.next = 5;
96
+ _context.next = 6;
92
97
  return deleteRequest(id);
93
- case 5:
98
+ case 6:
94
99
  messageApi.success('删除成功');
95
100
  setTimeout(function () {
96
101
  var _actionRef$current;
97
102
  (_actionRef$current = actionRef.current) === null || _actionRef$current === void 0 || _actionRef$current.reload();
98
103
  }, 0);
99
- _context.next = 10;
104
+ _context.next = 11;
100
105
  break;
101
- case 9:
102
- messageApi.error('删除接口未传入');
103
106
  case 10:
104
- _context.next = 16;
107
+ messageApi.error('删除接口未传入');
108
+ case 11:
109
+ _context.next = 17;
105
110
  break;
106
- case 12:
107
- _context.prev = 12;
108
- _context.t0 = _context["catch"](1);
111
+ case 13:
112
+ _context.prev = 13;
113
+ _context.t0 = _context["catch"](2);
109
114
  messageApi.error('删除失败');
110
115
  console.log(_context.t0);
111
- case 16:
112
- _context.prev = 16;
116
+ case 17:
117
+ _context.prev = 17;
113
118
  setLoading(false);
114
- return _context.finish(16);
115
- case 19:
119
+ return _context.finish(17);
120
+ case 20:
116
121
  case "end":
117
122
  return _context.stop();
118
123
  }
119
- }, _callee, null, [[1, 12, 16, 19]]);
124
+ }, _callee, null, [[2, 13, 17, 20]]);
120
125
  }));
121
126
  return function delEvent(_x) {
122
- return _ref.apply(this, arguments);
127
+ return _ref2.apply(this, arguments);
123
128
  };
124
129
  }();
125
130
  var updateState = /*#__PURE__*/function () {
126
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref2) {
131
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref3) {
127
132
  var id, isActive, _formRef$current;
128
133
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
129
134
  while (1) switch (_context2.prev = _context2.next) {
130
135
  case 0:
131
- id = _ref2.id, isActive = _ref2.isActive;
136
+ id = _ref3.id, isActive = _ref3.isActive;
132
137
  setLoading(true);
133
138
  _context2.prev = 2;
134
139
  if (!updateStateRequest) {
@@ -166,7 +171,7 @@ var CustomTable = /*#__PURE__*/forwardRef(function (props, ref) {
166
171
  }, _callee2, null, [[2, 13, 17, 20]]);
167
172
  }));
168
173
  return function updateState(_x2) {
169
- return _ref3.apply(this, arguments);
174
+ return _ref4.apply(this, arguments);
170
175
  };
171
176
  }();
172
177
  var openModal = function openModal() {
@@ -233,8 +238,51 @@ var CustomTable = /*#__PURE__*/forwardRef(function (props, ref) {
233
238
  });
234
239
  };
235
240
  }
241
+ var getButtons = function getButtons(record) {
242
+ var _detailRef$current;
243
+ var buts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
244
+ return [{
245
+ text: '详情',
246
+ type: 'link',
247
+ // @ts-ignore
248
+ onClick: (_detailRef$current = detailRef.current) === null || _detailRef$current === void 0 ? void 0 : _detailRef$current.open,
249
+ isShow: isDetail,
250
+ order: 10
251
+ }, {
252
+ text: '编辑',
253
+ type: 'link',
254
+ onClick: openModal,
255
+ isShow: isUpdate,
256
+ order: 20
257
+ }, {
258
+ text: '删除',
259
+ type: 'link',
260
+ onClick: delEvent,
261
+ isShow: isDelete,
262
+ isConfirm: true,
263
+ danger: true,
264
+ msg: '确定删除当前数据?',
265
+ order: 30
266
+ }, {
267
+ text: record.isActive === 0 ? '禁用' : '启用',
268
+ type: 'link',
269
+ onClick: updateState,
270
+ isShow: isUpdateState,
271
+ danger: record.isActive === 0,
272
+ isConfirm: true,
273
+ msg: "\u786E\u5B9A\u8981".concat(record.isActive === 0 ? '启用' : '禁用', "\u8BE5\u6570\u636E\u5417\uFF1F"),
274
+ order: 40
275
+ }].concat(_toConsumableArray(buts));
276
+ };
236
277
 
237
- // 操作列
278
+ /**
279
+ * 操作列
280
+ * 详情:默认显示
281
+ * 编辑:默认显示
282
+ * 删除:默认显示
283
+ * 启用/禁用:默认不显示
284
+ * buttons:为函数
285
+ */
238
286
  var operation = newColumns === null || newColumns === void 0 ? void 0 : newColumns.find(function (item) {
239
287
  return item.dataIndex === 'operation' || item.valueType === 'option';
240
288
  });
@@ -245,38 +293,47 @@ var CustomTable = /*#__PURE__*/forwardRef(function (props, ref) {
245
293
  operation.width = [isDetail, isDelete, isUpdateState, isUpdate].filter(Boolean).length * 65;
246
294
  }
247
295
  operation.render = function (_, record) {
296
+ var _getButtons;
297
+ var buts = Array.isArray(operation.buttons) ? operation.buttons : [];
298
+ var buttons = (_getButtons = getButtons(record, buts)) === null || _getButtons === void 0 || (_getButtons = _getButtons.filter(function (item) {
299
+ return item.isShow || isEmptyValue(item.isShow);
300
+ })) === null || _getButtons === void 0 ? void 0 : _getButtons.sort(function (prev, next) {
301
+ return (prev === null || prev === void 0 ? void 0 : prev.order) - (next === null || next === void 0 ? void 0 : next.order);
302
+ });
248
303
  return /*#__PURE__*/React.createElement("div", {
249
304
  style: {
250
305
  display: 'flex'
251
306
  }
252
- }, isDetail && /*#__PURE__*/React.createElement(Button, {
253
- type: "link"
254
- // @ts-ignore
255
- ,
256
- onClick: function onClick() {
257
- var _detailRef$current;
258
- return (_detailRef$current = detailRef.current) === null || _detailRef$current === void 0 ? void 0 : _detailRef$current.open(record);
259
- }
260
- }, "\u8BE6\u60C5"), isUpdate && /*#__PURE__*/React.createElement(Button, {
261
- type: "link",
262
- onClick: function onClick() {
263
- return openModal(record);
264
- }
265
- }, "\u7F16\u8F91"), isDelete && /*#__PURE__*/React.createElement(Popconfirm, {
266
- title: "\u786E\u5B9A\u5220\u9664\u5F53\u524D\u6570\u636E\uFF1F",
267
- onConfirm: function onConfirm() {
268
- return delEvent(record.id);
269
- }
270
- }, /*#__PURE__*/React.createElement(Button, {
271
- type: "link",
272
- danger: true
273
- }, "\u5220\u9664")), isUpdateState && /*#__PURE__*/React.createElement(Button, {
274
- type: "link",
275
- danger: record.isActive === 1,
276
- onClick: function onClick() {
277
- return updateState(record);
307
+ }, buttons === null || buttons === void 0 ? void 0 : buttons.map(function (_ref5, index) {
308
+ var text = _ref5.text,
309
+ msg = _ref5.msg,
310
+ isConfirm = _ref5.isConfirm,
311
+ _onClick = _ref5.onClick,
312
+ danger = _ref5.danger,
313
+ isShow = _ref5.isShow,
314
+ order = _ref5.order,
315
+ item = _objectWithoutProperties(_ref5, _excluded2);
316
+ if (isConfirm) {
317
+ return /*#__PURE__*/React.createElement(Popconfirm, _extends({
318
+ key: index,
319
+ title: msg,
320
+ onConfirm: function onConfirm() {
321
+ return _onClick && _onClick(record);
322
+ }
323
+ }, item || {}), /*#__PURE__*/React.createElement(Button, _extends({
324
+ type: "link",
325
+ danger: danger
326
+ }, item), text));
278
327
  }
279
- }, record.isActive === 0 ? '启用' : '禁用'), operation.buttons && operation.buttons(record));
328
+ return /*#__PURE__*/React.createElement(Button, _extends({
329
+ key: index,
330
+ type: "link",
331
+ onClick: function onClick() {
332
+ return _onClick && _onClick(record);
333
+ },
334
+ danger: danger
335
+ }, item), text);
336
+ }), isFunction(operation.buttons) && operation.buttons(record));
280
337
  };
281
338
  }
282
339
  return newColumns === null || newColumns === void 0 ? void 0 : newColumns.map(function (item) {
@@ -285,6 +342,8 @@ var CustomTable = /*#__PURE__*/forwardRef(function (props, ref) {
285
342
  }) : item;
286
343
  });
287
344
  };
345
+
346
+ // 控制操作列宽度
288
347
  var getAntTableContainer = function getAntTableContainer() {
289
348
  var tableContainer = tableContainerRef.current;
290
349
  var tableBody = tableContainer === null || tableContainer === void 0 ? void 0 : tableContainer.querySelector('.ant-table-body');
@@ -343,7 +402,7 @@ var CustomTable = /*#__PURE__*/forwardRef(function (props, ref) {
343
402
  formRef: formRef,
344
403
  columns: handleColumns() || [],
345
404
  request: ( /*#__PURE__*/function () {
346
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params, sort, filter) {
405
+ var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params, sort, filter) {
347
406
  var pageNo, _yield$request, list, data;
348
407
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
349
408
  while (1) switch (_context3.prev = _context3.next) {
@@ -363,7 +422,7 @@ var CustomTable = /*#__PURE__*/forwardRef(function (props, ref) {
363
422
  case 7:
364
423
  _yield$request = _context3.sent;
365
424
  list = _yield$request.list;
366
- data = _objectWithoutProperties(_yield$request, _excluded2);
425
+ data = _objectWithoutProperties(_yield$request, _excluded3);
367
426
  getAntTableContainer();
368
427
  return _context3.abrupt("return", _objectSpread({
369
428
  data: list
@@ -388,7 +447,7 @@ var CustomTable = /*#__PURE__*/forwardRef(function (props, ref) {
388
447
  }, _callee3, null, [[2, 14, 17, 20]]);
389
448
  }));
390
449
  return function (_x3, _x4, _x5) {
391
- return _ref4.apply(this, arguments);
450
+ return _ref6.apply(this, arguments);
392
451
  };
393
452
  }()),
394
453
  rowKey: rowKey || 'id',
@@ -1,3 +1,4 @@
1
1
  /// <reference types="react" />
2
- declare const CustomTag: ({ value, valueEnum }: CustomTagProps, record?: any, __?: any, ___?: any, column?: any) => JSX.Element;
2
+ import type { CustomTagProps } from "./tag";
3
+ declare const CustomTag: ({ value, valueEnum, options }: CustomTagProps) => JSX.Element | JSX.Element[];
3
4
  export default CustomTag;
@@ -1,30 +1,65 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
1
2
  /*
2
3
  * @Author: 郭郭
3
4
  * @Date: 2025/11/11
4
5
  * @Description:
5
6
  */
6
- import { isEmptyValue } from "../src";
7
+
8
+ import { isEmptyValue } from "../utils/util";
7
9
  import { Tag } from 'antd';
10
+ import isObject from 'lodash/isObject';
8
11
  import React from 'react';
9
- var CustomTag = function CustomTag(_ref, record, __, ___, column) {
12
+ var CustomTag = function CustomTag(_ref) {
13
+ var _ref2;
10
14
  var value = _ref.value,
11
- valueEnum = _ref.valueEnum;
12
- if (column) {
13
- var _ref2 = column.valueEnum[record.status] || {},
14
- _color = _ref2.color,
15
- _status = _ref2.status,
16
- _text = _ref2.text;
17
- return /*#__PURE__*/React.createElement(Tag, {
18
- color: _color || _status
19
- }, _text);
15
+ valueEnum = _ref.valueEnum,
16
+ options = _ref.options;
17
+ // 判空
18
+ if (isEmptyValue(value)) return /*#__PURE__*/React.createElement(React.Fragment, null, "-");
19
+
20
+ // 判断valueEnum 和 options是否为空
21
+ if (!valueEnum && !options || !isObject(valueEnum) && !options || !Array.isArray(options) && !valueEnum) {
22
+ return /*#__PURE__*/React.createElement(React.Fragment, null, value);
20
23
  }
21
- if (isEmptyValue(value)) return /*#__PURE__*/React.createElement(React.Fragment, null, value);
22
- var _ref3 = valueEnum[value] || {},
23
- color = _ref3.color,
24
- status = _ref3.status,
25
- text = _ref3.text;
26
- return /*#__PURE__*/React.createElement(Tag, {
27
- color: color || status
28
- }, text);
24
+
25
+ // 渲染标签
26
+ var render = function render(color, text, tagProps) {
27
+ return /*#__PURE__*/React.createElement(Tag, _extends({
28
+ color: color
29
+ }, tagProps || {}), text);
30
+ };
31
+ var newValues = (_ref2 = "".concat(value)) === null || _ref2 === void 0 ? void 0 : _ref2.split(',');
32
+ var result = [];
33
+
34
+ // 判断newValues长度
35
+ if (newValues.length === 1) {
36
+ newValues = [value];
37
+ }
38
+
39
+ // 循环value值获取text || label
40
+ newValues.forEach(function (val) {
41
+ if (Array.isArray(options)) {
42
+ var _ref3 = options.filter(function (item) {
43
+ return "".concat(item.value) === "".concat(val);
44
+ }) || {},
45
+ label = _ref3.label,
46
+ color = _ref3.color,
47
+ status = _ref3.status,
48
+ tagProps = _ref3.tagProps;
49
+ result.push(render(color || status, label || val, tagProps));
50
+ } else {
51
+ var _ref4 = valueEnum[val] || {},
52
+ _color = _ref4.color,
53
+ _status = _ref4.status,
54
+ text = _ref4.text,
55
+ _tagProps = _ref4.tagProps;
56
+ result.push(render(_color || _status, text || val, _tagProps));
57
+ }
58
+ });
59
+ return result.map(function (item, index) {
60
+ return /*#__PURE__*/React.createElement(React.Fragment, {
61
+ key: index
62
+ }, item);
63
+ });
29
64
  };
30
65
  export default CustomTag;
@@ -4,16 +4,36 @@
4
4
  * @Description:
5
5
  */
6
6
 
7
+ import type { TagProps } from 'antd';
8
+
7
9
  interface CustomTagProps {
8
10
  /**
9
11
  * 标签名称
10
12
  */
11
- value: string | number;
13
+ value: string | number | boolean;
14
+
15
+ /**
16
+ * 配置数组
17
+ */
18
+ options?: Array<{
19
+ [key: string | number | boolean]: any;
20
+ tagProps?: TagProps;
21
+ }>;
22
+
23
+ /**
24
+ * 异步数据
25
+ */
26
+ // request?: (params: any) => Promise<any>;
12
27
 
13
28
  /**
14
29
  * 枚举
15
30
  */
16
- valueEnum: {
17
- [key: stirng]: { text: string; status?: string; color?: string };
31
+ valueEnum?: {
32
+ [key: stirng | number | boolean]: {
33
+ text: string;
34
+ status?: string;
35
+ color?: string;
36
+ tagProps?: TagProps;
37
+ };
18
38
  };
19
39
  }
@@ -4,10 +4,10 @@
4
4
  * @Description:
5
5
  */
6
6
 
7
- import { ProColumns } from '@ant-design/pro-table';
8
- import { Rules } from '@rc-component/async-validator';
9
- import { ImgCropProps } from 'antd-img-crop';
10
- import { ReactNode } from 'react';
7
+ import type { ProColumns } from '@ant-design/pro-table';
8
+ import type { Rules } from '@rc-component/async-validator';
9
+ import type { ButtonProps } from 'antd';
10
+ import type { ImgCropProps } from 'antd-img-crop';
11
11
 
12
12
  interface CustomColumnProps extends ProColumns {
13
13
  /**
@@ -82,5 +82,7 @@ interface CustomColumnProps extends ProColumns {
82
82
  /**
83
83
  * 操作按钮
84
84
  */
85
- buttons?: (data: { [key: string]: any }) => ReactNode;
85
+ buttons?: (data: {
86
+ [key: string]: any;
87
+ }) => any | (ButtonProps & { text: string; order: number }[]);
86
88
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guo514360255/antd-lib",
3
- "version": "1.4.25",
3
+ "version": "1.4.27",
4
4
  "description": "react design 5 lib",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",