@hw-component/table 0.0.3-beta-v5 → 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/HTableBody/index.js +4 -5
- package/es/HTablePagination/index.js +2 -1
- package/es/TableCustomize.js +6 -3
- package/es/hooks/index.d.ts +1 -0
- package/es/hooks/index.js +25 -0
- package/es/hooks/useReq.d.ts +16 -3
- package/es/hooks/useReq.js +72 -12
- package/es/index.css +5 -0
- package/es/index.d.ts +1 -0
- package/es/modal.d.ts +6 -2
- package/lib/HTableBody/index.js +6 -7
- package/lib/HTablePagination/index.js +2 -1
- package/lib/TableCustomize.js +6 -3
- package/lib/hooks/index.d.ts +1 -0
- package/lib/hooks/index.js +26 -0
- package/lib/hooks/useReq.d.ts +16 -3
- package/lib/hooks/useReq.js +71 -11
- package/lib/index.css +5 -0
- package/lib/index.d.ts +1 -0
- package/lib/modal.d.ts +6 -2
- package/package.json +1 -1
- package/src/components/HTableBody/index.tsx +3 -4
- package/src/components/HTablePagination/index.tsx +1 -1
- package/src/components/TableCustomize.tsx +3 -2
- package/src/components/hooks/index.ts +14 -0
- package/src/components/hooks/useReq.ts +41 -9
- package/src/components/index.less +6 -0
- package/src/components/index.tsx +1 -0
- package/src/components/modal.ts +6 -2
- package/src/components/styles/local.less +1 -0
- package/src/pages/Table/index.tsx +0 -4
- package/src/pages/TableCustomize/index.tsx +24 -19
package/es/HTableBody/index.js
CHANGED
|
@@ -17,6 +17,7 @@ import { useHTableContext } from '../context.js';
|
|
|
17
17
|
import { ConfigProvider, Empty } from 'antd';
|
|
18
18
|
import { useHTableConfigContext } from '../TableConfig.js';
|
|
19
19
|
import HTablePagination from '../HTablePagination/index.js';
|
|
20
|
+
import { useClassName } from '../hooks/index.js';
|
|
20
21
|
|
|
21
22
|
var _excluded = ["configData", "pagination", "onPageChange", "rowSelection", "rowKey", "emptyRender", "errorRender", "tableStyle"];
|
|
22
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; }
|
|
@@ -75,12 +76,10 @@ var Body = (function (_ref) {
|
|
|
75
76
|
records: records,
|
|
76
77
|
rowKey: rowKey
|
|
77
78
|
});
|
|
79
|
+
var className = useClassName("hw-table-body");
|
|
78
80
|
return jsx("div", {
|
|
79
|
-
style:
|
|
80
|
-
|
|
81
|
-
overflow: "hidden"
|
|
82
|
-
}, tableStyle),
|
|
83
|
-
className: "hw_table_body",
|
|
81
|
+
style: tableStyle,
|
|
82
|
+
className: "hw_table_body ".concat(className),
|
|
84
83
|
children: jsxs(ConfigProvider, {
|
|
85
84
|
renderEmpty: function renderEmpty() {
|
|
86
85
|
if (error) {
|
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,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useClassName: (className: string | string[]) => string;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// welcome to hoo hoo hoo
|
|
2
|
+
import 'core-js/modules/es.array.join.js';
|
|
3
|
+
import _Array$isArray from '@babel/runtime-corejs3/core-js/array/is-array';
|
|
4
|
+
import _mapInstanceProperty from '@babel/runtime-corejs3/core-js/instance/map';
|
|
5
|
+
import _concatInstanceProperty from '@babel/runtime-corejs3/core-js/instance/concat';
|
|
6
|
+
import { useContext, useMemo } from 'react';
|
|
7
|
+
import { ConfigContext } from 'antd/es/config-provider';
|
|
8
|
+
|
|
9
|
+
var useClassName = function useClassName(className) {
|
|
10
|
+
var config = useContext(ConfigContext);
|
|
11
|
+
return useMemo(function () {
|
|
12
|
+
var _context2;
|
|
13
|
+
if (_Array$isArray(className)) {
|
|
14
|
+
var classNames = _mapInstanceProperty(className).call(className, function (item) {
|
|
15
|
+
var _context;
|
|
16
|
+
return _concatInstanceProperty(_context = "".concat(config.getPrefixCls(), "-")).call(_context, item);
|
|
17
|
+
});
|
|
18
|
+
return classNames.join(" ");
|
|
19
|
+
}
|
|
20
|
+
return _concatInstanceProperty(_context2 = "".concat(config.getPrefixCls(), "-")).call(_context2, className);
|
|
21
|
+
}, [className]);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export { useClassName };
|
|
25
|
+
// powered by hdj
|
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/index.css
ADDED
package/es/index.d.ts
CHANGED
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/HTableBody/index.js
CHANGED
|
@@ -19,7 +19,8 @@ var hooks = require('./hooks.js');
|
|
|
19
19
|
var context = require('../context.js');
|
|
20
20
|
var antd = require('antd');
|
|
21
21
|
var TableConfig = require('../TableConfig.js');
|
|
22
|
-
var index = require('../HTablePagination/index.js');
|
|
22
|
+
var index$1 = require('../HTablePagination/index.js');
|
|
23
|
+
var index = require('../hooks/index.js');
|
|
23
24
|
|
|
24
25
|
var _excluded = ["configData", "pagination", "onPageChange", "rowSelection", "rowKey", "emptyRender", "errorRender", "tableStyle"];
|
|
25
26
|
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; }
|
|
@@ -78,12 +79,10 @@ var Body = (function (_ref) {
|
|
|
78
79
|
records: records,
|
|
79
80
|
rowKey: rowKey
|
|
80
81
|
});
|
|
82
|
+
var className = index.useClassName("hw-table-body");
|
|
81
83
|
return jsxRuntime.jsx("div", {
|
|
82
|
-
style:
|
|
83
|
-
|
|
84
|
-
overflow: "hidden"
|
|
85
|
-
}, tableStyle),
|
|
86
|
-
className: "hw_table_body",
|
|
84
|
+
style: tableStyle,
|
|
85
|
+
className: "hw_table_body ".concat(className),
|
|
87
86
|
children: jsxRuntime.jsxs(antd.ConfigProvider, {
|
|
88
87
|
renderEmpty: function renderEmpty() {
|
|
89
88
|
if (error) {
|
|
@@ -106,7 +105,7 @@ var Body = (function (_ref) {
|
|
|
106
105
|
rowKey: rowKey,
|
|
107
106
|
dataSource: records,
|
|
108
107
|
pagination: false
|
|
109
|
-
})), pagination !== false && jsxRuntime.jsx(index.default, _objectSpread({
|
|
108
|
+
})), pagination !== false && jsxRuntime.jsx(index$1.default, _objectSpread({
|
|
110
109
|
onPageChange: onPageChange
|
|
111
110
|
}, pagination))]
|
|
112
111
|
})
|
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,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useClassName: (className: string | string[]) => string;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('core-js/modules/es.array.join.js');
|
|
4
|
+
var _Array$isArray = require('@babel/runtime-corejs3/core-js/array/is-array');
|
|
5
|
+
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/map');
|
|
6
|
+
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/concat');
|
|
7
|
+
var React = require('react');
|
|
8
|
+
var configProvider = require('antd/es/config-provider');
|
|
9
|
+
|
|
10
|
+
var useClassName = function useClassName(className) {
|
|
11
|
+
var config = React.useContext(configProvider.ConfigContext);
|
|
12
|
+
return React.useMemo(function () {
|
|
13
|
+
var _context2;
|
|
14
|
+
if (_Array$isArray(className)) {
|
|
15
|
+
var classNames = _mapInstanceProperty(className).call(className, function (item) {
|
|
16
|
+
var _context;
|
|
17
|
+
return _concatInstanceProperty(_context = "".concat(config.getPrefixCls(), "-")).call(_context, item);
|
|
18
|
+
});
|
|
19
|
+
return classNames.join(" ");
|
|
20
|
+
}
|
|
21
|
+
return _concatInstanceProperty(_context2 = "".concat(config.getPrefixCls(), "-")).call(_context2, className);
|
|
22
|
+
}, [className]);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
exports.useClassName = useClassName;
|
|
26
|
+
// powered by h
|
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/index.css
ADDED
package/lib/index.d.ts
CHANGED
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
|
@@ -8,6 +8,7 @@ import { ConfigProvider, Empty } from "antd";
|
|
|
8
8
|
import type { HTableInstance } from "../modal";
|
|
9
9
|
import { useHTableConfigContext } from "../TableConfig";
|
|
10
10
|
import HTablePagination from "../HTablePagination";
|
|
11
|
+
import { useClassName } from "../hooks";
|
|
11
12
|
interface HTableBodyProps extends Omit<ProTableProps<any, any>, "dataSource"> {
|
|
12
13
|
configData?: ConfigDataModal;
|
|
13
14
|
onPageChange?: (params: ParamsModal) => void;
|
|
@@ -57,11 +58,9 @@ export default ({
|
|
|
57
58
|
rowOnChange(key, rowData);
|
|
58
59
|
};
|
|
59
60
|
useSynchronousKeys({ selectedRowKeys, records, rowKey });
|
|
61
|
+
const className = useClassName("hw-table-body");
|
|
60
62
|
return (
|
|
61
|
-
<div
|
|
62
|
-
style={{ borderRadius: 4, overflow: "hidden", ...tableStyle }}
|
|
63
|
-
className="hw_table_body"
|
|
64
|
-
>
|
|
63
|
+
<div style={tableStyle} className={`hw_table_body ${className}`}>
|
|
65
64
|
<ConfigProvider
|
|
66
65
|
renderEmpty={() => {
|
|
67
66
|
if (error) {
|
|
@@ -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({
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useContext, useMemo } from "react";
|
|
2
|
+
import { ConfigContext } from "antd/es/config-provider";
|
|
3
|
+
export const useClassName = (className: string | string[]) => {
|
|
4
|
+
const config = useContext(ConfigContext);
|
|
5
|
+
return useMemo(() => {
|
|
6
|
+
if (Array.isArray(className)) {
|
|
7
|
+
const classNames = className.map((item) => {
|
|
8
|
+
return `${config.getPrefixCls()}-${item}`;
|
|
9
|
+
});
|
|
10
|
+
return classNames.join(" ");
|
|
11
|
+
}
|
|
12
|
+
return `${config.getPrefixCls()}-${className}`;
|
|
13
|
+
}, [className]);
|
|
14
|
+
};
|
|
@@ -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/index.tsx
CHANGED
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>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@ant-prefix: ant;
|
|
@@ -22,10 +22,6 @@ export default () => {
|
|
|
22
22
|
<HTable
|
|
23
23
|
configData={configData}
|
|
24
24
|
rowKey={"id"}
|
|
25
|
-
headerStyle={{ borderRadius: 0 }}
|
|
26
|
-
tableStyle={{ borderRadius: 0, background: "#fff" }}
|
|
27
|
-
spaceSize={0}
|
|
28
|
-
footerStyle={{ marginTop: 20 }}
|
|
29
25
|
table={hTable}
|
|
30
26
|
actionRender={(allCheck, selectedRowKeys, xjTable) => {
|
|
31
27
|
console.log(allCheck, selectedRowKeys, xjTable);
|
|
@@ -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} />
|