@hw-component/table 1.10.15 → 1.10.16

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.
@@ -2,12 +2,21 @@ import { HEditTableProps } from "./modal";
2
2
  import { MutableRefObject } from "react";
3
3
  import type { ActionType } from "@ant-design/pro-table";
4
4
  import { EditableFormInstance } from "@ant-design/pro-table/lib/components/EditableTable";
5
- export declare const useListRequest: ({ request, dataSource, manual, }: HEditTableProps) => import("@ahooksjs/use-request/lib/types").BaseResult<any, [params?: any]>;
5
+ import { ResultModal } from "../modal";
6
+ export declare const useListRequest: ({ request, dataSource, manual, }: HEditTableProps) => {
7
+ loading: boolean;
8
+ error: Error | undefined;
9
+ run: (params?: any) => Promise<void>;
10
+ data: ResultModal;
11
+ };
6
12
  export declare const useCuRef: ({ actionRef, editableFormRef }: HEditTableProps) => {
7
13
  cuActionRef: MutableRefObject<ActionType>;
8
14
  cuEditableFormRef: MutableRefObject<EditableFormInstance>;
9
15
  };
10
- export declare const useColsMk: ({ configData }: HEditTableProps) => (import("@ant-design/pro-table").ProColumnType<any, "text"> | {
16
+ interface ColProps extends HEditTableProps {
17
+ reload: VoidFunction;
18
+ }
19
+ export declare const useColsMk: ({ configData, reload }: ColProps) => (import("@ant-design/pro-table").ProColumnType<any, "text"> | {
11
20
  render: (dom: any, entity: any, index: any, action: any, schema: any) => any;
12
21
  children: import("@ant-design/pro-table").ProColumns<any, "text">[];
13
22
  key?: import("react").Key | undefined;
@@ -1555,3 +1564,4 @@ export declare const useColsMk: ({ configData }: HEditTableProps) => (import("@a
1555
1564
  } | undefined) | undefined;
1556
1565
  fieldProps?: any;
1557
1566
  })[] | undefined;
1567
+ export {};
@@ -9,11 +9,12 @@ import _Object$defineProperties from '@babel/runtime-corejs3/core-js-stable/obje
9
9
  import _Object$defineProperty from '@babel/runtime-corejs3/core-js-stable/object/define-property';
10
10
  import _defineProperty from '@babel/runtime-corejs3/helpers/defineProperty';
11
11
  import _asyncToGenerator from '@babel/runtime-corejs3/helpers/asyncToGenerator';
12
+ import _slicedToArray from '@babel/runtime-corejs3/helpers/slicedToArray';
12
13
  import _regeneratorRuntime from '@babel/runtime-corejs3/regenerator';
13
14
  import _Array$isArray from '@babel/runtime-corejs3/core-js-stable/array/is-array';
14
15
  import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/map';
15
16
  import { useRequest } from 'ahooks';
16
- import { useMemo, useRef } from 'react';
17
+ import { useState, useMemo, useEffect, useRef } from 'react';
17
18
  import config from '../render/config.js';
18
19
 
19
20
  function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
@@ -22,7 +23,15 @@ var useListRequest = function useListRequest(_ref) {
22
23
  var request = _ref.request,
23
24
  dataSource = _ref.dataSource,
24
25
  manual = _ref.manual;
25
- var relManual = request ? manual : false;
26
+ var _useState = useState({
27
+ records: [],
28
+ total: "0",
29
+ size: "10",
30
+ current: "1"
31
+ }),
32
+ _useState2 = _slicedToArray(_useState, 2),
33
+ tableDataSource = _useState2[0],
34
+ setTableDataSource = _useState2[1];
26
35
  var saveParams = useMemo(function () {
27
36
  return {
28
37
  params: {
@@ -31,38 +40,60 @@ var useListRequest = function useListRequest(_ref) {
31
40
  }
32
41
  };
33
42
  }, []);
34
- return useRequest( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
35
- var params,
36
- newParams,
37
- _args = arguments;
38
- return _regeneratorRuntime.wrap(function _callee$(_context) {
39
- while (1) switch (_context.prev = _context.next) {
40
- case 0:
41
- params = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
42
- newParams = _objectSpread(_objectSpread({}, saveParams.params), params);
43
- saveParams.params = newParams;
44
- if (!request) {
45
- _context.next = 5;
46
- break;
47
- }
48
- return _context.abrupt("return", request(newParams));
49
- case 5:
50
- if (!_Array$isArray(dataSource)) {
51
- _context.next = 7;
52
- break;
53
- }
54
- return _context.abrupt("return", dataSource);
55
- case 7:
56
- return _context.abrupt("return", dataSource);
57
- case 8:
58
- case "end":
59
- return _context.stop();
60
- }
61
- }, _callee);
62
- })), {
63
- manual: relManual,
64
- refreshDeps: [dataSource]
65
- });
43
+ var _useRequest = useRequest( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
44
+ var params,
45
+ newParams,
46
+ result,
47
+ _args = arguments;
48
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
49
+ while (1) switch (_context.prev = _context.next) {
50
+ case 0:
51
+ params = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
52
+ newParams = _objectSpread(_objectSpread({}, saveParams.params), params);
53
+ saveParams.params = newParams;
54
+ if (!request) {
55
+ _context.next = 9;
56
+ break;
57
+ }
58
+ _context.next = 6;
59
+ return request(newParams);
60
+ case 6:
61
+ result = _context.sent;
62
+ setTableDataSource(result);
63
+ return _context.abrupt("return");
64
+ case 9:
65
+ if (!_Array$isArray(dataSource)) {
66
+ _context.next = 12;
67
+ break;
68
+ }
69
+ setTableDataSource(_objectSpread(_objectSpread({}, tableDataSource), {}, {
70
+ records: dataSource
71
+ }));
72
+ return _context.abrupt("return");
73
+ case 12:
74
+ return _context.abrupt("return", setTableDataSource(dataSource || tableDataSource));
75
+ case 13:
76
+ case "end":
77
+ return _context.stop();
78
+ }
79
+ }, _callee);
80
+ })), {
81
+ manual: true
82
+ }),
83
+ loading = _useRequest.loading,
84
+ error = _useRequest.error,
85
+ run = _useRequest.run;
86
+ useEffect(function () {
87
+ if (!manual) {
88
+ run();
89
+ }
90
+ }, [dataSource]);
91
+ return {
92
+ loading: loading,
93
+ error: error,
94
+ run: run,
95
+ data: tableDataSource
96
+ };
66
97
  };
67
98
  var useCuRef = function useCuRef(_ref3) {
68
99
  var actionRef = _ref3.actionRef,
@@ -77,23 +108,35 @@ var useCuRef = function useCuRef(_ref3) {
77
108
  };
78
109
  };
79
110
  var useColsMk = function useColsMk(_ref4) {
80
- var configData = _ref4.configData;
111
+ var configData = _ref4.configData,
112
+ reload = _ref4.reload;
81
113
  return configData === null || configData === void 0 ? void 0 : _mapInstanceProperty(configData).call(configData, function (item) {
82
114
  var valueType = item.valueType,
83
115
  _render = item.render;
84
116
  var configType = valueType;
85
- if (!config[configType]) {
86
- return item;
117
+ if (config[configType]) {
118
+ return _objectSpread(_objectSpread({}, item), {}, {
119
+ render: function render(dom, entity, index, action, schema) {
120
+ var node = config[configType](item, entity, index);
121
+ if (_render) {
122
+ return _render(node, entity, index, _objectSpread(_objectSpread({}, action), {}, {
123
+ reload: reload
124
+ }), schema);
125
+ }
126
+ return node;
127
+ }
128
+ });
87
129
  }
88
- return _objectSpread(_objectSpread({}, item), {}, {
89
- render: function render(dom, entity, index, action, schema) {
90
- var node = config[configType](item, entity, index);
91
- if (_render) {
92
- return _render(node, entity, index, action, schema);
130
+ if (_render) {
131
+ return _objectSpread(_objectSpread({}, item), {}, {
132
+ render: function render(dom, entity, index, action, schema) {
133
+ return _render(dom, entity, index, _objectSpread(_objectSpread({}, action), {}, {
134
+ reload: reload
135
+ }), schema);
93
136
  }
94
- return node;
95
- }
96
- });
137
+ });
138
+ }
139
+ return item;
97
140
  });
98
141
  };
99
142
 
@@ -1,9 +1,4 @@
1
1
  // welcome to hoo hoo hoo
2
- import _asyncToGenerator from '@babel/runtime-corejs3/helpers/asyncToGenerator';
3
- import _defineProperty from '@babel/runtime-corejs3/helpers/defineProperty';
4
- import _objectWithoutProperties from '@babel/runtime-corejs3/helpers/objectWithoutProperties';
5
- import _regeneratorRuntime from '@babel/runtime-corejs3/regenerator';
6
- import _Array$isArray from '@babel/runtime-corejs3/core-js-stable/array/is-array';
7
2
  import _Object$keys from '@babel/runtime-corejs3/core-js-stable/object/keys';
8
3
  import _Object$getOwnPropertySymbols from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols';
9
4
  import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
@@ -12,6 +7,10 @@ import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js-stable/inst
12
7
  import _Object$getOwnPropertyDescriptors from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors';
13
8
  import _Object$defineProperties from '@babel/runtime-corejs3/core-js-stable/object/define-properties';
14
9
  import _Object$defineProperty from '@babel/runtime-corejs3/core-js-stable/object/define-property';
10
+ import _asyncToGenerator from '@babel/runtime-corejs3/helpers/asyncToGenerator';
11
+ import _defineProperty from '@babel/runtime-corejs3/helpers/defineProperty';
12
+ import _objectWithoutProperties from '@babel/runtime-corejs3/helpers/objectWithoutProperties';
13
+ import _regeneratorRuntime from '@babel/runtime-corejs3/regenerator';
15
14
  import { jsxs, jsx } from 'react/jsx-runtime';
16
15
  import { EditableProTable } from '@ant-design/pro-table';
17
16
  import { useClassName } from '../hooks/index.js';
@@ -66,8 +65,6 @@ var EditTable = (function (_ref) {
66
65
  tableEmptyRender = _useHTableConfigConte2 === void 0 ? emptyDefaultRender : _useHTableConfigConte2,
67
66
  _useHTableConfigConte3 = _useHTableConfigConte.errorRender,
68
67
  tableErrorRender = _useHTableConfigConte3 === void 0 ? errorDefaultRender : _useHTableConfigConte3;
69
- var isLocalData = _Array$isArray(data);
70
- var values = isLocalData ? data : data === null || data === void 0 ? void 0 : data.records;
71
68
  var _useCuRef = useCuRef({
72
69
  actionRef: actionRef,
73
70
  editableFormRef: editableFormRef
@@ -75,7 +72,8 @@ var EditTable = (function (_ref) {
75
72
  cuActionRef = _useCuRef.cuActionRef,
76
73
  cuEditableFormRef = _useCuRef.cuEditableFormRef;
77
74
  var columns = useColsMk({
78
- configData: configData
75
+ configData: configData,
76
+ reload: run
79
77
  });
80
78
  return jsxs("div", {
81
79
  className: tableBody,
@@ -94,10 +92,8 @@ var EditTable = (function (_ref) {
94
92
  loading: loading,
95
93
  rowKey: rowKey,
96
94
  editableFormRef: cuEditableFormRef,
97
- manualRequest: true,
98
- request: run,
99
95
  actionRef: cuActionRef,
100
- value: values,
96
+ value: data === null || data === void 0 ? void 0 : data.records,
101
97
  recordCreatorProps: _objectSpread({
102
98
  position: "bottom",
103
99
  record: function record() {
@@ -169,8 +165,8 @@ var EditTable = (function (_ref) {
169
165
  }()
170
166
  }, editable)
171
167
  }, props))
172
- }), jsx(HTablePagination, _objectSpread(_objectSpread({
173
- data: isLocalData ? null : data
168
+ }), pagination === false ? null : jsx(HTablePagination, _objectSpread(_objectSpread({
169
+ data: data
174
170
  }, pagination), {}, {
175
171
  onChange: function onChange(page, pageSize) {
176
172
  run({
@@ -9,7 +9,7 @@ export interface HEditTableProps<T = any> extends Omit<EditableProTableProps<T,
9
9
  recordCreatorProps?: Partial<EditableProTableProps<T, ParamsType>["recordCreatorProps"]>;
10
10
  dataSource?: any[];
11
11
  request?: (params: Record<string, any>) => Promise<T>;
12
- pagination?: IPaginationProps;
12
+ pagination?: IPaginationProps | false;
13
13
  manual?: boolean;
14
14
  emptyRender?: EmptyPageRender;
15
15
  errorRender?: ErrorPageRender;
@@ -2,12 +2,21 @@ import { HEditTableProps } from "./modal";
2
2
  import { MutableRefObject } from "react";
3
3
  import type { ActionType } from "@ant-design/pro-table";
4
4
  import { EditableFormInstance } from "@ant-design/pro-table/lib/components/EditableTable";
5
- export declare const useListRequest: ({ request, dataSource, manual, }: HEditTableProps) => import("@ahooksjs/use-request/lib/types").BaseResult<any, [params?: any]>;
5
+ import { ResultModal } from "../modal";
6
+ export declare const useListRequest: ({ request, dataSource, manual, }: HEditTableProps) => {
7
+ loading: boolean;
8
+ error: Error | undefined;
9
+ run: (params?: any) => Promise<void>;
10
+ data: ResultModal;
11
+ };
6
12
  export declare const useCuRef: ({ actionRef, editableFormRef }: HEditTableProps) => {
7
13
  cuActionRef: MutableRefObject<ActionType>;
8
14
  cuEditableFormRef: MutableRefObject<EditableFormInstance>;
9
15
  };
10
- export declare const useColsMk: ({ configData }: HEditTableProps) => (import("@ant-design/pro-table").ProColumnType<any, "text"> | {
16
+ interface ColProps extends HEditTableProps {
17
+ reload: VoidFunction;
18
+ }
19
+ export declare const useColsMk: ({ configData, reload }: ColProps) => (import("@ant-design/pro-table").ProColumnType<any, "text"> | {
11
20
  render: (dom: any, entity: any, index: any, action: any, schema: any) => any;
12
21
  children: import("@ant-design/pro-table").ProColumns<any, "text">[];
13
22
  key?: import("react").Key | undefined;
@@ -1555,3 +1564,4 @@ export declare const useColsMk: ({ configData }: HEditTableProps) => (import("@a
1555
1564
  } | undefined) | undefined;
1556
1565
  fieldProps?: any;
1557
1566
  })[] | undefined;
1567
+ export {};
@@ -10,6 +10,7 @@ var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/ob
10
10
  var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
11
11
  var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
12
12
  var _asyncToGenerator = require('@babel/runtime-corejs3/helpers/asyncToGenerator');
13
+ var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
13
14
  var _regeneratorRuntime = require('@babel/runtime-corejs3/regenerator');
14
15
  var _Array$isArray = require('@babel/runtime-corejs3/core-js-stable/array/is-array');
15
16
  var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
@@ -23,7 +24,15 @@ var useListRequest = function useListRequest(_ref) {
23
24
  var request = _ref.request,
24
25
  dataSource = _ref.dataSource,
25
26
  manual = _ref.manual;
26
- var relManual = request ? manual : false;
27
+ var _useState = React.useState({
28
+ records: [],
29
+ total: "0",
30
+ size: "10",
31
+ current: "1"
32
+ }),
33
+ _useState2 = _slicedToArray(_useState, 2),
34
+ tableDataSource = _useState2[0],
35
+ setTableDataSource = _useState2[1];
27
36
  var saveParams = React.useMemo(function () {
28
37
  return {
29
38
  params: {
@@ -32,38 +41,60 @@ var useListRequest = function useListRequest(_ref) {
32
41
  }
33
42
  };
34
43
  }, []);
35
- return ahooks.useRequest( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
36
- var params,
37
- newParams,
38
- _args = arguments;
39
- return _regeneratorRuntime.wrap(function _callee$(_context) {
40
- while (1) switch (_context.prev = _context.next) {
41
- case 0:
42
- params = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
43
- newParams = _objectSpread(_objectSpread({}, saveParams.params), params);
44
- saveParams.params = newParams;
45
- if (!request) {
46
- _context.next = 5;
47
- break;
48
- }
49
- return _context.abrupt("return", request(newParams));
50
- case 5:
51
- if (!_Array$isArray(dataSource)) {
52
- _context.next = 7;
53
- break;
54
- }
55
- return _context.abrupt("return", dataSource);
56
- case 7:
57
- return _context.abrupt("return", dataSource);
58
- case 8:
59
- case "end":
60
- return _context.stop();
61
- }
62
- }, _callee);
63
- })), {
64
- manual: relManual,
65
- refreshDeps: [dataSource]
66
- });
44
+ var _useRequest = ahooks.useRequest( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
45
+ var params,
46
+ newParams,
47
+ result,
48
+ _args = arguments;
49
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
50
+ while (1) switch (_context.prev = _context.next) {
51
+ case 0:
52
+ params = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
53
+ newParams = _objectSpread(_objectSpread({}, saveParams.params), params);
54
+ saveParams.params = newParams;
55
+ if (!request) {
56
+ _context.next = 9;
57
+ break;
58
+ }
59
+ _context.next = 6;
60
+ return request(newParams);
61
+ case 6:
62
+ result = _context.sent;
63
+ setTableDataSource(result);
64
+ return _context.abrupt("return");
65
+ case 9:
66
+ if (!_Array$isArray(dataSource)) {
67
+ _context.next = 12;
68
+ break;
69
+ }
70
+ setTableDataSource(_objectSpread(_objectSpread({}, tableDataSource), {}, {
71
+ records: dataSource
72
+ }));
73
+ return _context.abrupt("return");
74
+ case 12:
75
+ return _context.abrupt("return", setTableDataSource(dataSource || tableDataSource));
76
+ case 13:
77
+ case "end":
78
+ return _context.stop();
79
+ }
80
+ }, _callee);
81
+ })), {
82
+ manual: true
83
+ }),
84
+ loading = _useRequest.loading,
85
+ error = _useRequest.error,
86
+ run = _useRequest.run;
87
+ React.useEffect(function () {
88
+ if (!manual) {
89
+ run();
90
+ }
91
+ }, [dataSource]);
92
+ return {
93
+ loading: loading,
94
+ error: error,
95
+ run: run,
96
+ data: tableDataSource
97
+ };
67
98
  };
68
99
  var useCuRef = function useCuRef(_ref3) {
69
100
  var actionRef = _ref3.actionRef,
@@ -78,23 +109,35 @@ var useCuRef = function useCuRef(_ref3) {
78
109
  };
79
110
  };
80
111
  var useColsMk = function useColsMk(_ref4) {
81
- var configData = _ref4.configData;
112
+ var configData = _ref4.configData,
113
+ reload = _ref4.reload;
82
114
  return configData === null || configData === void 0 ? void 0 : _mapInstanceProperty(configData).call(configData, function (item) {
83
115
  var valueType = item.valueType,
84
116
  _render = item.render;
85
117
  var configType = valueType;
86
- if (!config.default[configType]) {
87
- return item;
118
+ if (config.default[configType]) {
119
+ return _objectSpread(_objectSpread({}, item), {}, {
120
+ render: function render(dom, entity, index, action, schema) {
121
+ var node = config.default[configType](item, entity, index);
122
+ if (_render) {
123
+ return _render(node, entity, index, _objectSpread(_objectSpread({}, action), {}, {
124
+ reload: reload
125
+ }), schema);
126
+ }
127
+ return node;
128
+ }
129
+ });
88
130
  }
89
- return _objectSpread(_objectSpread({}, item), {}, {
90
- render: function render(dom, entity, index, action, schema) {
91
- var node = config.default[configType](item, entity, index);
92
- if (_render) {
93
- return _render(node, entity, index, action, schema);
131
+ if (_render) {
132
+ return _objectSpread(_objectSpread({}, item), {}, {
133
+ render: function render(dom, entity, index, action, schema) {
134
+ return _render(dom, entity, index, _objectSpread(_objectSpread({}, action), {}, {
135
+ reload: reload
136
+ }), schema);
94
137
  }
95
- return node;
96
- }
97
- });
138
+ });
139
+ }
140
+ return item;
98
141
  });
99
142
  };
100
143
 
@@ -2,11 +2,6 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var _asyncToGenerator = require('@babel/runtime-corejs3/helpers/asyncToGenerator');
6
- var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
7
- var _objectWithoutProperties = require('@babel/runtime-corejs3/helpers/objectWithoutProperties');
8
- var _regeneratorRuntime = require('@babel/runtime-corejs3/regenerator');
9
- var _Array$isArray = require('@babel/runtime-corejs3/core-js-stable/array/is-array');
10
5
  var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
11
6
  var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
12
7
  var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
@@ -15,6 +10,10 @@ var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/in
15
10
  var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
16
11
  var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
17
12
  var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
13
+ var _asyncToGenerator = require('@babel/runtime-corejs3/helpers/asyncToGenerator');
14
+ var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
15
+ var _objectWithoutProperties = require('@babel/runtime-corejs3/helpers/objectWithoutProperties');
16
+ var _regeneratorRuntime = require('@babel/runtime-corejs3/regenerator');
18
17
  var jsxRuntime = require('react/jsx-runtime');
19
18
  var ProTable = require('@ant-design/pro-table');
20
19
  var index = require('../hooks/index.js');
@@ -69,8 +68,6 @@ var EditTable = (function (_ref) {
69
68
  tableEmptyRender = _useHTableConfigConte2 === void 0 ? defaultRender.emptyDefaultRender : _useHTableConfigConte2,
70
69
  _useHTableConfigConte3 = _useHTableConfigConte.errorRender,
71
70
  tableErrorRender = _useHTableConfigConte3 === void 0 ? defaultRender.errorDefaultRender : _useHTableConfigConte3;
72
- var isLocalData = _Array$isArray(data);
73
- var values = isLocalData ? data : data === null || data === void 0 ? void 0 : data.records;
74
71
  var _useCuRef = hooks.useCuRef({
75
72
  actionRef: actionRef,
76
73
  editableFormRef: editableFormRef
@@ -78,7 +75,8 @@ var EditTable = (function (_ref) {
78
75
  cuActionRef = _useCuRef.cuActionRef,
79
76
  cuEditableFormRef = _useCuRef.cuEditableFormRef;
80
77
  var columns = hooks.useColsMk({
81
- configData: configData
78
+ configData: configData,
79
+ reload: run
82
80
  });
83
81
  return jsxRuntime.jsxs("div", {
84
82
  className: tableBody,
@@ -97,10 +95,8 @@ var EditTable = (function (_ref) {
97
95
  loading: loading,
98
96
  rowKey: rowKey,
99
97
  editableFormRef: cuEditableFormRef,
100
- manualRequest: true,
101
- request: run,
102
98
  actionRef: cuActionRef,
103
- value: values,
99
+ value: data === null || data === void 0 ? void 0 : data.records,
104
100
  recordCreatorProps: _objectSpread({
105
101
  position: "bottom",
106
102
  record: function record() {
@@ -172,8 +168,8 @@ var EditTable = (function (_ref) {
172
168
  }()
173
169
  }, editable)
174
170
  }, props))
175
- }), jsxRuntime.jsx(index$1.default, _objectSpread(_objectSpread({
176
- data: isLocalData ? null : data
171
+ }), pagination === false ? null : jsxRuntime.jsx(index$1.default, _objectSpread(_objectSpread({
172
+ data: data
177
173
  }, pagination), {}, {
178
174
  onChange: function onChange(page, pageSize) {
179
175
  run({
@@ -9,7 +9,7 @@ export interface HEditTableProps<T = any> extends Omit<EditableProTableProps<T,
9
9
  recordCreatorProps?: Partial<EditableProTableProps<T, ParamsType>["recordCreatorProps"]>;
10
10
  dataSource?: any[];
11
11
  request?: (params: Record<string, any>) => Promise<T>;
12
- pagination?: IPaginationProps;
12
+ pagination?: IPaginationProps | false;
13
13
  manual?: boolean;
14
14
  emptyRender?: EmptyPageRender;
15
15
  errorRender?: ErrorPageRender;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hw-component/table",
3
- "version": "1.10.15",
3
+ "version": "1.10.16",
4
4
  "description": "基于antd二次开发table组件",
5
5
  "keywords": [
6
6
  "table"
@@ -1,16 +1,22 @@
1
1
  import { useRequest } from "ahooks";
2
2
  import { HEditTableProps } from "./modal";
3
- import { MutableRefObject, useEffect, useMemo, useRef } from "react";
3
+ import {MutableRefObject, useEffect, useMemo, useRef, useState} from "react";
4
4
  import type { ActionType } from "@ant-design/pro-table";
5
5
  import { EditableFormInstance } from "@ant-design/pro-table/lib/components/EditableTable";
6
6
  import config from "../render/config";
7
+ import {ResultModal} from "../modal";
7
8
 
8
9
  export const useListRequest = ({
9
10
  request,
10
11
  dataSource,
11
12
  manual,
12
13
  }: HEditTableProps) => {
13
- const relManual = request ? manual : false;
14
+ const [tableDataSource,setTableDataSource]=useState<ResultModal>({
15
+ records:[],
16
+ total:"0",
17
+ size:"10",
18
+ current:"1"
19
+ });
14
20
  const saveParams = useMemo(() => {
15
21
  return {
16
22
  params: {
@@ -19,7 +25,7 @@ export const useListRequest = ({
19
25
  },
20
26
  };
21
27
  }, []);
22
- return useRequest(
28
+ const {loading,error,run}=useRequest(
23
29
  async (params = {}) => {
24
30
  const newParams = {
25
31
  ...saveParams.params,
@@ -27,15 +33,32 @@ export const useListRequest = ({
27
33
  };
28
34
  saveParams.params = newParams;
29
35
  if (request) {
30
- return request(newParams);
36
+ const result=await request(newParams);
37
+ setTableDataSource(result);
38
+ return ;
31
39
  }
32
40
  if (Array.isArray(dataSource)) {
33
- return dataSource;
41
+ setTableDataSource({
42
+ ...tableDataSource,
43
+ records:dataSource,
44
+ })
45
+ return ;
34
46
  }
35
- return dataSource;
47
+ return setTableDataSource(dataSource||tableDataSource);
36
48
  },
37
- { manual: relManual, refreshDeps: [dataSource] }
49
+ { manual:true}
38
50
  );
51
+ useEffect(() => {
52
+ if (!manual){
53
+ run();
54
+ }
55
+ }, [dataSource]);
56
+ return {
57
+ loading,
58
+ error,
59
+ run,
60
+ data:tableDataSource
61
+ }
39
62
  };
40
63
 
41
64
  export const useCuRef = ({ actionRef, editableFormRef }: HEditTableProps) => {
@@ -50,23 +73,34 @@ export const useCuRef = ({ actionRef, editableFormRef }: HEditTableProps) => {
50
73
  cuEditableFormRef,
51
74
  };
52
75
  };
76
+ interface ColProps extends HEditTableProps{
77
+ reload:VoidFunction;
78
+ }
53
79
 
54
- export const useColsMk = ({ configData }: HEditTableProps) => {
80
+ export const useColsMk = ({ configData,reload }: ColProps) => {
55
81
  return configData?.map((item) => {
56
82
  const { valueType, render } = item;
57
83
  const configType = valueType as string;
58
- if (!config[configType]) {
59
- return item;
84
+ if (config[configType]) {
85
+ return {
86
+ ...item,
87
+ render: (dom, entity, index, action, schema) => {
88
+ const node = config[configType](item, entity, index);
89
+ if (render) {
90
+ return render(node, entity, index, {...action,reload}, schema);
91
+ }
92
+ return node;
93
+ },
94
+ };
60
95
  }
61
- return {
62
- ...item,
63
- render: (dom, entity, index, action, schema) => {
64
- const node = config[configType](item, entity, index);
65
- if (render) {
66
- return render(node, entity, index, action, schema);
67
- }
68
- return node;
69
- },
70
- };
96
+ if (render){
97
+ return {
98
+ ...item,
99
+ render: (dom, entity, index, action, schema) => {
100
+ return render(dom, entity, index, {...action,reload}, schema);
101
+ },
102
+ };
103
+ }
104
+ return item;
71
105
  });
72
106
  };
@@ -41,13 +41,11 @@ export default ({
41
41
  errorRender: tableErrorRender = errorDefaultRender,
42
42
  } = useHTableConfigContext({ emptyRender, errorRender });
43
43
 
44
- const isLocalData = Array.isArray(data);
45
- const values = isLocalData ? data : data?.records;
46
44
  const { cuActionRef, cuEditableFormRef } = useCuRef({
47
45
  actionRef,
48
46
  editableFormRef,
49
47
  });
50
- const columns = useColsMk({ configData });
48
+ const columns = useColsMk({ configData,reload:run});
51
49
  return (
52
50
  <div className={tableBody}>
53
51
  <ConfigProvider
@@ -66,10 +64,8 @@ export default ({
66
64
  loading={loading}
67
65
  rowKey={rowKey}
68
66
  editableFormRef={cuEditableFormRef}
69
- manualRequest={true}
70
- request={run}
71
67
  actionRef={cuActionRef}
72
- value={values}
68
+ value={data?.records}
73
69
  recordCreatorProps={{
74
70
  position: "bottom",
75
71
  record: () => ({ id: "add", ...defaultRecordValue }),
@@ -104,16 +100,16 @@ export default ({
104
100
  {...props}
105
101
  />
106
102
  </ConfigProvider>
107
- <HTablePagination
108
- data={isLocalData ? null : data}
109
- {...pagination}
110
- onChange={(page, pageSize) => {
111
- run({
112
- size: pageSize,
113
- current: page,
114
- });
115
- }}
116
- />
103
+ {pagination===false?null:<HTablePagination
104
+ data={data}
105
+ {...pagination}
106
+ onChange={(page, pageSize) => {
107
+ run({
108
+ size: pageSize,
109
+ current: page,
110
+ });
111
+ }}
112
+ />}
117
113
  </div>
118
114
  );
119
115
  };
@@ -16,7 +16,7 @@ export interface HEditTableProps<T = any>
16
16
  >;
17
17
  dataSource?: any[];
18
18
  request?: (params: Record<string, any>) => Promise<T>;
19
- pagination?: IPaginationProps;
19
+ pagination?: IPaginationProps|false;
20
20
  manual?: boolean;
21
21
  emptyRender?: EmptyPageRender;
22
22
  errorRender?: ErrorPageRender;
@@ -40,25 +40,26 @@ export default () => {
40
40
  </div>
41
41
  <HDwEditTable
42
42
  title="编辑"
43
- request={async () => {
44
- return {
45
- records: [
46
- {
47
- id: "213213",
48
- title: "100",
49
- },
50
- ],
51
- current: "1",
52
- size: "10",
53
- total: "10",
54
- };
43
+ request={() => {
44
+ return new Promise(resolve => {
45
+ setTimeout(() => {
46
+ resolve( {
47
+ records: [
48
+ {
49
+ id: "213213",
50
+ title: "100",
51
+ },
52
+ ],
53
+ current: "1",
54
+ size: "10",
55
+ total: "10",
56
+ })
57
+ },2000)
58
+ })
55
59
  }}
56
60
  editTableProps={{
57
61
  onAdd: async (data) => {},
58
62
  onEdit: async (data) => {},
59
- defaultRecordValue: {
60
- title: "21312",
61
- },
62
63
  }}
63
64
  dialogTable={dialogTable}
64
65
  configData={[
@@ -68,17 +69,28 @@ export default () => {
68
69
  title: "操作",
69
70
  valueType: "option",
70
71
  align: "center",
71
- render: (text: any, record: any, _: any, action: any) => [
72
- <a
73
- key="editable"
74
- type={"link"}
75
- onClick={() => {
76
- action?.startEditable?.(record.id);
77
- }}
78
- >
79
- 编辑
80
- </a>,
81
- ],
72
+ render: (text: any, record: any, _: any, action: any) =>{
73
+ return <>
74
+ <a
75
+ key="editable"
76
+ type={"link"}
77
+ onClick={() => {
78
+ action?.startEditable?.(record.id);
79
+ }}
80
+ >
81
+ 编辑
82
+ </a>
83
+ <a
84
+ key="editable"
85
+ type={"link"}
86
+ onClick={() => {
87
+ action.reload()
88
+ }}
89
+ >
90
+ 刷新
91
+ </a>
92
+ </>
93
+ }
82
94
  },
83
95
  ]}
84
96
  />