@hw-component/table 0.0.3-beta-v6 → 0.0.3-beta-v7
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.
- package/es/HTablePagination/index.js +2 -1
- package/es/TableCustomize.js +6 -3
- package/es/hooks/useReq.d.ts +16 -3
- package/es/hooks/useReq.js +72 -12
- package/es/modal.d.ts +6 -2
- package/lib/HTablePagination/index.js +2 -1
- package/lib/TableCustomize.js +6 -3
- package/lib/hooks/useReq.d.ts +16 -3
- package/lib/hooks/useReq.js +71 -11
- package/lib/modal.d.ts +6 -2
- package/package.json +1 -1
- package/src/components/HTablePagination/index.tsx +1 -1
- package/src/components/TableCustomize.tsx +3 -2
- package/src/components/hooks/useReq.ts +41 -9
- package/src/components/modal.ts +6 -2
- package/src/pages/TableCustomize/index.tsx +24 -19
package/es/TableCustomize.js
CHANGED
|
@@ -8,6 +8,7 @@ import _Object$getOwnPropertyDescriptors from '@babel/runtime-corejs3/core-js/ob
|
|
|
8
8
|
import _Object$defineProperties from '@babel/runtime-corejs3/core-js/object/define-properties';
|
|
9
9
|
import _Object$defineProperty from '@babel/runtime-corejs3/core-js/object/define-property';
|
|
10
10
|
import _defineProperty from '@babel/runtime-corejs3/helpers/defineProperty';
|
|
11
|
+
import _objectWithoutProperties from '@babel/runtime-corejs3/helpers/objectWithoutProperties';
|
|
11
12
|
import { jsx } from 'react/jsx-runtime';
|
|
12
13
|
import useCurrentTable from './hooks/useCurrentTable.js';
|
|
13
14
|
import useRowObj from './hooks/useRowObj.js';
|
|
@@ -15,6 +16,7 @@ import { HTableContext } from './context.js';
|
|
|
15
16
|
import useReq from './hooks/useReq.js';
|
|
16
17
|
import useDispatch from './hooks/useDispatch.js';
|
|
17
18
|
|
|
19
|
+
var _excluded = ["request", "configData", "table", "action", "children"];
|
|
18
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; }
|
|
19
21
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context2 = ownKeys(Object(t))).call(_context2, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
20
22
|
var Index = function Index(_ref) {
|
|
@@ -23,10 +25,11 @@ var Index = function Index(_ref) {
|
|
|
23
25
|
table = _ref.table,
|
|
24
26
|
_ref$action = _ref.action,
|
|
25
27
|
action = _ref$action === void 0 ? {} : _ref$action,
|
|
26
|
-
children = _ref.children
|
|
27
|
-
|
|
28
|
+
children = _ref.children,
|
|
29
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
30
|
+
var _useReq = useReq(_objectSpread({
|
|
28
31
|
request: request
|
|
29
|
-
}),
|
|
32
|
+
}, props)),
|
|
30
33
|
run = _useReq.run,
|
|
31
34
|
loading = _useReq.loading,
|
|
32
35
|
data = _useReq.data,
|
package/es/hooks/useReq.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import type { ParamsModal, ResultModal } from "@/components/modal";
|
|
2
|
-
interface IParamsModal {
|
|
3
|
-
request
|
|
2
|
+
export interface IParamsModal {
|
|
3
|
+
request?: (params: ParamsModal) => Promise<ResultModal>;
|
|
4
|
+
loading?: boolean;
|
|
5
|
+
error?: Error;
|
|
6
|
+
reload?: (params: any) => Promise<any>;
|
|
7
|
+
dataSource?: any;
|
|
8
|
+
manual?: boolean;
|
|
4
9
|
}
|
|
5
|
-
declare const _default: ({ request }: IParamsModal) => {
|
|
10
|
+
declare const _default: ({ request, loading, error, reload, dataSource, manual }: IParamsModal) => {
|
|
6
11
|
saveParams: {
|
|
7
12
|
old: {};
|
|
8
13
|
};
|
|
@@ -19,5 +24,13 @@ declare const _default: ({ request }: IParamsModal) => {
|
|
|
19
24
|
mutate: import("@ahooksjs/use-request/lib/types").Mutate<ResultModal>;
|
|
20
25
|
run: (params?: any) => Promise<ResultModal>;
|
|
21
26
|
unmount: () => void;
|
|
27
|
+
} | {
|
|
28
|
+
loading: boolean | undefined;
|
|
29
|
+
error: Error | undefined;
|
|
30
|
+
data: any;
|
|
31
|
+
run: (params?: Record<string, any>) => Promise<any>;
|
|
32
|
+
saveParams: {
|
|
33
|
+
old: {};
|
|
34
|
+
};
|
|
22
35
|
};
|
|
23
36
|
export default _default;
|
package/es/hooks/useReq.js
CHANGED
|
@@ -9,36 +9,96 @@ import _Object$defineProperties from '@babel/runtime-corejs3/core-js/object/defi
|
|
|
9
9
|
import _Object$defineProperty from '@babel/runtime-corejs3/core-js/object/define-property';
|
|
10
10
|
import _defineProperty from '@babel/runtime-corejs3/helpers/defineProperty';
|
|
11
11
|
import _objectWithoutProperties from '@babel/runtime-corejs3/helpers/objectWithoutProperties';
|
|
12
|
-
import
|
|
12
|
+
import _asyncToGenerator from '@babel/runtime-corejs3/helpers/asyncToGenerator';
|
|
13
|
+
import _regeneratorRuntime from '@babel/runtime-corejs3/regenerator';
|
|
14
|
+
import { useMemo, useEffect } from 'react';
|
|
13
15
|
import { useRequest } from 'ahooks';
|
|
14
16
|
|
|
15
|
-
var _excluded = ["size", "current"]
|
|
17
|
+
var _excluded = ["size", "current"],
|
|
18
|
+
_excluded2 = ["size", "current"];
|
|
16
19
|
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; }
|
|
17
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var
|
|
20
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context2, _context3; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context2 = ownKeys(Object(t), !0)).call(_context2, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context3 = ownKeys(Object(t))).call(_context3, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
18
21
|
var useReq = (function (_ref) {
|
|
19
|
-
var request = _ref.request
|
|
22
|
+
var request = _ref.request,
|
|
23
|
+
loading = _ref.loading,
|
|
24
|
+
error = _ref.error,
|
|
25
|
+
reload = _ref.reload,
|
|
26
|
+
dataSource = _ref.dataSource,
|
|
27
|
+
_ref$manual = _ref.manual,
|
|
28
|
+
manual = _ref$manual === void 0 ? false : _ref$manual;
|
|
20
29
|
var saveParams = useMemo(function () {
|
|
21
30
|
return {
|
|
22
31
|
old: {}
|
|
23
32
|
};
|
|
24
33
|
}, []);
|
|
34
|
+
var reloadFn = /*#__PURE__*/function () {
|
|
35
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
36
|
+
var params,
|
|
37
|
+
_params$size,
|
|
38
|
+
size,
|
|
39
|
+
_params$current,
|
|
40
|
+
current,
|
|
41
|
+
oParams,
|
|
42
|
+
reqParams,
|
|
43
|
+
_args = arguments;
|
|
44
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
45
|
+
while (1) switch (_context.prev = _context.next) {
|
|
46
|
+
case 0:
|
|
47
|
+
params = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
|
|
48
|
+
_params$size = params.size, size = _params$size === void 0 ? "10" : _params$size, _params$current = params.current, current = _params$current === void 0 ? "1" : _params$current, oParams = _objectWithoutProperties(params, _excluded);
|
|
49
|
+
reqParams = _objectSpread({
|
|
50
|
+
size: size,
|
|
51
|
+
current: current
|
|
52
|
+
}, oParams);
|
|
53
|
+
return _context.abrupt("return", reload === null || reload === void 0 ? void 0 : reload(reqParams));
|
|
54
|
+
case 4:
|
|
55
|
+
case "end":
|
|
56
|
+
return _context.stop();
|
|
57
|
+
}
|
|
58
|
+
}, _callee);
|
|
59
|
+
}));
|
|
60
|
+
return function reloadFn() {
|
|
61
|
+
return _ref2.apply(this, arguments);
|
|
62
|
+
};
|
|
63
|
+
}();
|
|
25
64
|
var resultAction = useRequest(function () {
|
|
26
65
|
var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
27
|
-
var _params$
|
|
28
|
-
size = _params$
|
|
29
|
-
_params$
|
|
30
|
-
current = _params$
|
|
31
|
-
oParams = _objectWithoutProperties(params,
|
|
66
|
+
var _params$size2 = params.size,
|
|
67
|
+
size = _params$size2 === void 0 ? "10" : _params$size2,
|
|
68
|
+
_params$current2 = params.current,
|
|
69
|
+
current = _params$current2 === void 0 ? "1" : _params$current2,
|
|
70
|
+
oParams = _objectWithoutProperties(params, _excluded2);
|
|
32
71
|
var reqParams = _objectSpread({
|
|
33
72
|
size: size,
|
|
34
73
|
current: current
|
|
35
74
|
}, oParams);
|
|
36
75
|
saveParams.old = reqParams;
|
|
37
|
-
return request(reqParams);
|
|
76
|
+
return request === null || request === void 0 ? void 0 : request(reqParams);
|
|
77
|
+
}, {
|
|
78
|
+
manual: true
|
|
38
79
|
});
|
|
39
|
-
|
|
80
|
+
useEffect(function () {
|
|
81
|
+
if (manual) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (request) {
|
|
85
|
+
resultAction.run();
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
reloadFn();
|
|
89
|
+
}, []);
|
|
90
|
+
if (request) {
|
|
91
|
+
return _objectSpread(_objectSpread({}, resultAction), {}, {
|
|
92
|
+
saveParams: saveParams
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
loading: loading,
|
|
97
|
+
error: error,
|
|
98
|
+
data: dataSource,
|
|
99
|
+
run: reloadFn,
|
|
40
100
|
saveParams: saveParams
|
|
41
|
-
}
|
|
101
|
+
};
|
|
42
102
|
});
|
|
43
103
|
|
|
44
104
|
export { useReq as default };
|
package/es/modal.d.ts
CHANGED
|
@@ -29,8 +29,8 @@ export type ConfigDataModal = ConfigItemModal[];
|
|
|
29
29
|
export type ActionRenderFn = (selectedRowKeys: RowObj, tableInstance: HTableInstance) => React.ReactNode;
|
|
30
30
|
export type actionFn = (...arg: any[]) => void;
|
|
31
31
|
type FooterRenderFn = (tableInstance: HTableInstance, selectedRowData: RowObj, data?: ResultModal) => React.ReactNode;
|
|
32
|
-
export interface HTableProps extends Omit<ProTableProps<any, any>, "request"> {
|
|
33
|
-
request
|
|
32
|
+
export interface HTableProps extends Omit<ProTableProps<any, any>, "request" | "dataSource"> {
|
|
33
|
+
request?: (params: ParamsModal) => Promise<ResultModal>;
|
|
34
34
|
configData: ConfigDataModal;
|
|
35
35
|
searchSpan?: ColProps;
|
|
36
36
|
table?: HTableInstance;
|
|
@@ -45,6 +45,10 @@ export interface HTableProps extends Omit<ProTableProps<any, any>, "request"> {
|
|
|
45
45
|
footerStyle?: React.CSSProperties;
|
|
46
46
|
spaceSize?: number;
|
|
47
47
|
className?: string;
|
|
48
|
+
error?: Error;
|
|
49
|
+
reload?: (params: any) => Promise<any>;
|
|
50
|
+
manual?: boolean;
|
|
51
|
+
dataSource?: ResultModal;
|
|
48
52
|
}
|
|
49
53
|
export interface TableInstance {
|
|
50
54
|
reload: (params?: ParamsModal) => Promise<any>;
|
package/lib/TableCustomize.js
CHANGED
|
@@ -11,6 +11,7 @@ var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js/
|
|
|
11
11
|
var _Object$defineProperties = require('@babel/runtime-corejs3/core-js/object/define-properties');
|
|
12
12
|
var _Object$defineProperty = require('@babel/runtime-corejs3/core-js/object/define-property');
|
|
13
13
|
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
14
|
+
var _objectWithoutProperties = require('@babel/runtime-corejs3/helpers/objectWithoutProperties');
|
|
14
15
|
var jsxRuntime = require('react/jsx-runtime');
|
|
15
16
|
var useCurrentTable = require('./hooks/useCurrentTable.js');
|
|
16
17
|
var useRowObj = require('./hooks/useRowObj.js');
|
|
@@ -18,6 +19,7 @@ var context = require('./context.js');
|
|
|
18
19
|
var useReq = require('./hooks/useReq.js');
|
|
19
20
|
var useDispatch = require('./hooks/useDispatch.js');
|
|
20
21
|
|
|
22
|
+
var _excluded = ["request", "configData", "table", "action", "children"];
|
|
21
23
|
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
24
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context2 = ownKeys(Object(t))).call(_context2, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
23
25
|
var Index = function Index(_ref) {
|
|
@@ -26,10 +28,11 @@ var Index = function Index(_ref) {
|
|
|
26
28
|
table = _ref.table,
|
|
27
29
|
_ref$action = _ref.action,
|
|
28
30
|
action = _ref$action === void 0 ? {} : _ref$action,
|
|
29
|
-
children = _ref.children
|
|
30
|
-
|
|
31
|
+
children = _ref.children,
|
|
32
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
33
|
+
var _useReq = useReq.default(_objectSpread({
|
|
31
34
|
request: request
|
|
32
|
-
}),
|
|
35
|
+
}, props)),
|
|
33
36
|
run = _useReq.run,
|
|
34
37
|
loading = _useReq.loading,
|
|
35
38
|
data = _useReq.data,
|
package/lib/hooks/useReq.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import type { ParamsModal, ResultModal } from "@/components/modal";
|
|
2
|
-
interface IParamsModal {
|
|
3
|
-
request
|
|
2
|
+
export interface IParamsModal {
|
|
3
|
+
request?: (params: ParamsModal) => Promise<ResultModal>;
|
|
4
|
+
loading?: boolean;
|
|
5
|
+
error?: Error;
|
|
6
|
+
reload?: (params: any) => Promise<any>;
|
|
7
|
+
dataSource?: any;
|
|
8
|
+
manual?: boolean;
|
|
4
9
|
}
|
|
5
|
-
declare const _default: ({ request }: IParamsModal) => {
|
|
10
|
+
declare const _default: ({ request, loading, error, reload, dataSource, manual }: IParamsModal) => {
|
|
6
11
|
saveParams: {
|
|
7
12
|
old: {};
|
|
8
13
|
};
|
|
@@ -19,5 +24,13 @@ declare const _default: ({ request }: IParamsModal) => {
|
|
|
19
24
|
mutate: import("@ahooksjs/use-request/lib/types").Mutate<ResultModal>;
|
|
20
25
|
run: (params?: any) => Promise<ResultModal>;
|
|
21
26
|
unmount: () => void;
|
|
27
|
+
} | {
|
|
28
|
+
loading: boolean | undefined;
|
|
29
|
+
error: Error | undefined;
|
|
30
|
+
data: any;
|
|
31
|
+
run: (params?: Record<string, any>) => Promise<any>;
|
|
32
|
+
saveParams: {
|
|
33
|
+
old: {};
|
|
34
|
+
};
|
|
22
35
|
};
|
|
23
36
|
export default _default;
|
package/lib/hooks/useReq.js
CHANGED
|
@@ -12,36 +12,96 @@ var _Object$defineProperties = require('@babel/runtime-corejs3/core-js/object/de
|
|
|
12
12
|
var _Object$defineProperty = require('@babel/runtime-corejs3/core-js/object/define-property');
|
|
13
13
|
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
14
14
|
var _objectWithoutProperties = require('@babel/runtime-corejs3/helpers/objectWithoutProperties');
|
|
15
|
+
var _asyncToGenerator = require('@babel/runtime-corejs3/helpers/asyncToGenerator');
|
|
16
|
+
var _regeneratorRuntime = require('@babel/runtime-corejs3/regenerator');
|
|
15
17
|
var React = require('react');
|
|
16
18
|
var ahooks = require('ahooks');
|
|
17
19
|
|
|
18
|
-
var _excluded = ["size", "current"]
|
|
20
|
+
var _excluded = ["size", "current"],
|
|
21
|
+
_excluded2 = ["size", "current"];
|
|
19
22
|
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; }
|
|
20
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var
|
|
23
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context2, _context3; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context2 = ownKeys(Object(t), !0)).call(_context2, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context3 = ownKeys(Object(t))).call(_context3, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
21
24
|
var useReq = (function (_ref) {
|
|
22
|
-
var request = _ref.request
|
|
25
|
+
var request = _ref.request,
|
|
26
|
+
loading = _ref.loading,
|
|
27
|
+
error = _ref.error,
|
|
28
|
+
reload = _ref.reload,
|
|
29
|
+
dataSource = _ref.dataSource,
|
|
30
|
+
_ref$manual = _ref.manual,
|
|
31
|
+
manual = _ref$manual === void 0 ? false : _ref$manual;
|
|
23
32
|
var saveParams = React.useMemo(function () {
|
|
24
33
|
return {
|
|
25
34
|
old: {}
|
|
26
35
|
};
|
|
27
36
|
}, []);
|
|
37
|
+
var reloadFn = /*#__PURE__*/function () {
|
|
38
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
39
|
+
var params,
|
|
40
|
+
_params$size,
|
|
41
|
+
size,
|
|
42
|
+
_params$current,
|
|
43
|
+
current,
|
|
44
|
+
oParams,
|
|
45
|
+
reqParams,
|
|
46
|
+
_args = arguments;
|
|
47
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
48
|
+
while (1) switch (_context.prev = _context.next) {
|
|
49
|
+
case 0:
|
|
50
|
+
params = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
|
|
51
|
+
_params$size = params.size, size = _params$size === void 0 ? "10" : _params$size, _params$current = params.current, current = _params$current === void 0 ? "1" : _params$current, oParams = _objectWithoutProperties(params, _excluded);
|
|
52
|
+
reqParams = _objectSpread({
|
|
53
|
+
size: size,
|
|
54
|
+
current: current
|
|
55
|
+
}, oParams);
|
|
56
|
+
return _context.abrupt("return", reload === null || reload === void 0 ? void 0 : reload(reqParams));
|
|
57
|
+
case 4:
|
|
58
|
+
case "end":
|
|
59
|
+
return _context.stop();
|
|
60
|
+
}
|
|
61
|
+
}, _callee);
|
|
62
|
+
}));
|
|
63
|
+
return function reloadFn() {
|
|
64
|
+
return _ref2.apply(this, arguments);
|
|
65
|
+
};
|
|
66
|
+
}();
|
|
28
67
|
var resultAction = ahooks.useRequest(function () {
|
|
29
68
|
var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
30
|
-
var _params$
|
|
31
|
-
size = _params$
|
|
32
|
-
_params$
|
|
33
|
-
current = _params$
|
|
34
|
-
oParams = _objectWithoutProperties(params,
|
|
69
|
+
var _params$size2 = params.size,
|
|
70
|
+
size = _params$size2 === void 0 ? "10" : _params$size2,
|
|
71
|
+
_params$current2 = params.current,
|
|
72
|
+
current = _params$current2 === void 0 ? "1" : _params$current2,
|
|
73
|
+
oParams = _objectWithoutProperties(params, _excluded2);
|
|
35
74
|
var reqParams = _objectSpread({
|
|
36
75
|
size: size,
|
|
37
76
|
current: current
|
|
38
77
|
}, oParams);
|
|
39
78
|
saveParams.old = reqParams;
|
|
40
|
-
return request(reqParams);
|
|
79
|
+
return request === null || request === void 0 ? void 0 : request(reqParams);
|
|
80
|
+
}, {
|
|
81
|
+
manual: true
|
|
41
82
|
});
|
|
42
|
-
|
|
83
|
+
React.useEffect(function () {
|
|
84
|
+
if (manual) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (request) {
|
|
88
|
+
resultAction.run();
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
reloadFn();
|
|
92
|
+
}, []);
|
|
93
|
+
if (request) {
|
|
94
|
+
return _objectSpread(_objectSpread({}, resultAction), {}, {
|
|
95
|
+
saveParams: saveParams
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
loading: loading,
|
|
100
|
+
error: error,
|
|
101
|
+
data: dataSource,
|
|
102
|
+
run: reloadFn,
|
|
43
103
|
saveParams: saveParams
|
|
44
|
-
}
|
|
104
|
+
};
|
|
45
105
|
});
|
|
46
106
|
|
|
47
107
|
exports.default = useReq;
|
package/lib/modal.d.ts
CHANGED
|
@@ -29,8 +29,8 @@ export type ConfigDataModal = ConfigItemModal[];
|
|
|
29
29
|
export type ActionRenderFn = (selectedRowKeys: RowObj, tableInstance: HTableInstance) => React.ReactNode;
|
|
30
30
|
export type actionFn = (...arg: any[]) => void;
|
|
31
31
|
type FooterRenderFn = (tableInstance: HTableInstance, selectedRowData: RowObj, data?: ResultModal) => React.ReactNode;
|
|
32
|
-
export interface HTableProps extends Omit<ProTableProps<any, any>, "request"> {
|
|
33
|
-
request
|
|
32
|
+
export interface HTableProps extends Omit<ProTableProps<any, any>, "request" | "dataSource"> {
|
|
33
|
+
request?: (params: ParamsModal) => Promise<ResultModal>;
|
|
34
34
|
configData: ConfigDataModal;
|
|
35
35
|
searchSpan?: ColProps;
|
|
36
36
|
table?: HTableInstance;
|
|
@@ -45,6 +45,10 @@ export interface HTableProps extends Omit<ProTableProps<any, any>, "request"> {
|
|
|
45
45
|
footerStyle?: React.CSSProperties;
|
|
46
46
|
spaceSize?: number;
|
|
47
47
|
className?: string;
|
|
48
|
+
error?: Error;
|
|
49
|
+
reload?: (params: any) => Promise<any>;
|
|
50
|
+
manual?: boolean;
|
|
51
|
+
dataSource?: ResultModal;
|
|
48
52
|
}
|
|
49
53
|
export interface TableInstance {
|
|
50
54
|
reload: (params?: ParamsModal) => Promise<any>;
|
package/package.json
CHANGED
|
@@ -20,7 +20,7 @@ export default ({ onPageChange, ...props }: IPaginationProps) => {
|
|
|
20
20
|
return (
|
|
21
21
|
<Row
|
|
22
22
|
justify={"end"}
|
|
23
|
-
style={{ paddingBottom: 24, paddingRight: 24, paddingLeft: 24 }}
|
|
23
|
+
style={{ paddingBottom: 24, paddingRight: 24, paddingLeft: 24 ,backgroundColor:"#fff"}}
|
|
24
24
|
>
|
|
25
25
|
<Pagination
|
|
26
26
|
size={"small"}
|
|
@@ -2,7 +2,7 @@ import useCurrentTable from "./hooks/useCurrentTable";
|
|
|
2
2
|
import useRowObj from "./hooks/useRowObj";
|
|
3
3
|
import { HTableContext } from "./context";
|
|
4
4
|
import type { HTableProps } from "./modal";
|
|
5
|
-
import useReq from "./hooks/useReq";
|
|
5
|
+
import useReq, {IParamsModal} from "./hooks/useReq";
|
|
6
6
|
import useDispatch from "./hooks/useDispatch";
|
|
7
7
|
import React from "react";
|
|
8
8
|
const Index: React.FC<HTableProps> = ({
|
|
@@ -11,8 +11,9 @@ const Index: React.FC<HTableProps> = ({
|
|
|
11
11
|
table,
|
|
12
12
|
action = {},
|
|
13
13
|
children,
|
|
14
|
+
...props
|
|
14
15
|
}) => {
|
|
15
|
-
const { run, loading, data, error, saveParams } = useReq({ request });
|
|
16
|
+
const { run, loading, data, error, saveParams } = useReq(({ request,...props } as IParamsModal));
|
|
16
17
|
const dispatch = useDispatch(action);
|
|
17
18
|
const { selectedRowData, rowOnChange, allSelectChange } = useRowObj();
|
|
18
19
|
const tableInstance = useCurrentTable({
|
|
@@ -1,23 +1,55 @@
|
|
|
1
|
-
import { useMemo
|
|
1
|
+
import {useEffect, useMemo} from "react";
|
|
2
2
|
import { useRequest } from "ahooks";
|
|
3
3
|
import type { ParamsModal, ResultModal } from "@/components/modal";
|
|
4
|
-
interface IParamsModal {
|
|
5
|
-
request
|
|
4
|
+
export interface IParamsModal {
|
|
5
|
+
request?: (params: ParamsModal) => Promise<ResultModal>;
|
|
6
|
+
loading?:boolean;
|
|
7
|
+
error?:Error;
|
|
8
|
+
reload?:(params:any)=>Promise<any>;
|
|
9
|
+
dataSource?:any;
|
|
10
|
+
manual?:boolean
|
|
6
11
|
}
|
|
7
|
-
export default ({ request }: IParamsModal) => {
|
|
12
|
+
export default ({ request ,loading,error,reload,dataSource,manual=false}: IParamsModal) => {
|
|
8
13
|
const saveParams = useMemo(() => {
|
|
9
14
|
return {
|
|
10
15
|
old: {},
|
|
11
16
|
};
|
|
12
17
|
}, []);
|
|
18
|
+
const reloadFn=async (params:Record<string, any>={})=>{
|
|
19
|
+
const { size = "10", current = "1", ...oParams } = params;
|
|
20
|
+
const reqParams = { size, current, ...oParams };
|
|
21
|
+
return reload?.(reqParams);
|
|
22
|
+
}
|
|
13
23
|
const resultAction = useRequest((params = {}) => {
|
|
14
24
|
const { size = "10", current = "1", ...oParams } = params;
|
|
15
25
|
const reqParams = { size, current, ...oParams };
|
|
16
26
|
saveParams.old = reqParams;
|
|
17
|
-
return request(reqParams);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
|
|
27
|
+
return request?.(reqParams);
|
|
28
|
+
},{manual:true});
|
|
29
|
+
|
|
30
|
+
useEffect(()=>{
|
|
31
|
+
if (manual){
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (request){
|
|
35
|
+
resultAction.run();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
reloadFn();
|
|
39
|
+
},[]);
|
|
40
|
+
|
|
41
|
+
if (request){
|
|
42
|
+
return {
|
|
43
|
+
...resultAction,
|
|
44
|
+
saveParams,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
loading,
|
|
49
|
+
error,
|
|
50
|
+
data:dataSource,
|
|
51
|
+
run:reloadFn,
|
|
21
52
|
saveParams,
|
|
22
|
-
|
|
53
|
+
|
|
54
|
+
}
|
|
23
55
|
};
|
package/src/components/modal.ts
CHANGED
|
@@ -45,8 +45,8 @@ type FooterRenderFn = (
|
|
|
45
45
|
selectedRowData: RowObj,
|
|
46
46
|
data?: ResultModal
|
|
47
47
|
) => React.ReactNode;
|
|
48
|
-
export interface HTableProps extends Omit<ProTableProps<any, any>, "request"> {
|
|
49
|
-
request
|
|
48
|
+
export interface HTableProps extends Omit<ProTableProps<any, any>, "request"|"dataSource"> {
|
|
49
|
+
request?: (params: ParamsModal) => Promise<ResultModal>;
|
|
50
50
|
configData: ConfigDataModal;
|
|
51
51
|
searchSpan?: ColProps;
|
|
52
52
|
table?: HTableInstance;
|
|
@@ -64,6 +64,10 @@ export interface HTableProps extends Omit<ProTableProps<any, any>, "request"> {
|
|
|
64
64
|
footerStyle?: React.CSSProperties;
|
|
65
65
|
spaceSize?: number;
|
|
66
66
|
className?: string;
|
|
67
|
+
error?:Error;
|
|
68
|
+
reload?:(params:any)=>Promise<any>;
|
|
69
|
+
manual?:boolean;
|
|
70
|
+
dataSource?:ResultModal
|
|
67
71
|
}
|
|
68
72
|
export interface TableInstance {
|
|
69
73
|
reload: (params?: ParamsModal) => Promise<any>;
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
HTableFooter,
|
|
6
6
|
HTablePagination,
|
|
7
7
|
} from "../../components";
|
|
8
|
+
import {useRequest} from "ahooks";
|
|
8
9
|
|
|
9
10
|
const configData = [
|
|
10
11
|
{
|
|
@@ -21,28 +22,32 @@ const configData = [
|
|
|
21
22
|
},
|
|
22
23
|
];
|
|
23
24
|
export default () => {
|
|
25
|
+
const {run,loading,error,data}=useRequest((params)=>{
|
|
26
|
+
const { current = 1 } = params;
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
setTimeout(() => {
|
|
29
|
+
// reject(new Error("错误"));
|
|
30
|
+
resolve({
|
|
31
|
+
size: "10",
|
|
32
|
+
current: current.toString(10),
|
|
33
|
+
total: "100",
|
|
34
|
+
records: [
|
|
35
|
+
{
|
|
36
|
+
id: 1,
|
|
37
|
+
name: "111",
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
});
|
|
41
|
+
}, 2000);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
24
44
|
return (
|
|
25
45
|
<TableCustomize
|
|
26
46
|
configData={configData}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
// reject(new Error("错误"));
|
|
32
|
-
resolve({
|
|
33
|
-
size: "10",
|
|
34
|
-
current: current.toString(10),
|
|
35
|
-
total: "100",
|
|
36
|
-
records: [
|
|
37
|
-
{
|
|
38
|
-
id: 1,
|
|
39
|
-
name: "111",
|
|
40
|
-
},
|
|
41
|
-
],
|
|
42
|
-
});
|
|
43
|
-
}, 2000);
|
|
44
|
-
});
|
|
45
|
-
}}
|
|
47
|
+
loading={loading}
|
|
48
|
+
error={error}
|
|
49
|
+
dataSource={data}
|
|
50
|
+
reload={run}
|
|
46
51
|
>
|
|
47
52
|
<HTableHeader />
|
|
48
53
|
<HTableBody pagination={false} />
|