@hw-component/table 0.0.3-beta-v6 → 0.0.3-beta-v8

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.
@@ -8,6 +8,7 @@ interface HTableBodyProps extends Omit<ProTableProps<any, any>, "dataSource"> {
8
8
  emptyRender?: (tableInstance: HTableInstance) => React.ReactNode;
9
9
  errorRender?: (tableInstance: HTableInstance, error: Error) => React.ReactNode;
10
10
  tableStyle?: React.CSSProperties;
11
+ paginationStyle?: React.CSSProperties;
11
12
  }
12
- declare const _default: ({ configData, pagination, onPageChange, rowSelection, rowKey, emptyRender, errorRender, tableStyle, ...props }: HTableBodyProps) => JSX.Element;
13
+ declare const _default: ({ configData, pagination, onPageChange, rowSelection, rowKey, emptyRender, errorRender, tableStyle, paginationStyle, ...props }: HTableBodyProps) => JSX.Element;
13
14
  export default _default;
@@ -19,7 +19,7 @@ import { useHTableConfigContext } from '../TableConfig.js';
19
19
  import HTablePagination from '../HTablePagination/index.js';
20
20
  import { useClassName } from '../hooks/index.js';
21
21
 
22
- var _excluded = ["configData", "pagination", "onPageChange", "rowSelection", "rowKey", "emptyRender", "errorRender", "tableStyle"];
22
+ var _excluded = ["configData", "pagination", "onPageChange", "rowSelection", "rowKey", "emptyRender", "errorRender", "tableStyle", "paginationStyle"];
23
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; }
24
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; }
25
25
  var defaultRender = function defaultRender() {
@@ -39,6 +39,7 @@ var Body = (function (_ref) {
39
39
  emptyRender = _ref.emptyRender,
40
40
  errorRender = _ref.errorRender,
41
41
  tableStyle = _ref.tableStyle,
42
+ paginationStyle = _ref.paginationStyle,
42
43
  props = _objectWithoutProperties(_ref, _excluded);
43
44
  var selectedRowKeys = rowSelection.selectedRowKeys,
44
45
  onChange = rowSelection.onChange;
@@ -103,7 +104,8 @@ var Body = (function (_ref) {
103
104
  dataSource: records,
104
105
  pagination: false
105
106
  })), pagination !== false && jsx(HTablePagination, _objectSpread({
106
- onPageChange: onPageChange
107
+ onPageChange: onPageChange,
108
+ paginationStyle: paginationStyle
107
109
  }, pagination))]
108
110
  })
109
111
  });
@@ -1,7 +1,9 @@
1
1
  import type { PaginationProps } from "antd";
2
2
  import type { ParamsModal } from "@/components/modal";
3
+ import React from "react";
3
4
  interface IPaginationProps extends PaginationProps {
4
5
  onPageChange?: (params: ParamsModal) => void;
6
+ paginationStyle?: React.CSSProperties;
5
7
  }
6
- declare const _default: ({ onPageChange, ...props }: IPaginationProps) => JSX.Element;
8
+ declare const _default: ({ onPageChange, paginationStyle, ...props }: IPaginationProps) => JSX.Element;
7
9
  export default _default;
@@ -15,17 +15,18 @@ import _concatInstanceProperty from '@babel/runtime-corejs3/core-js/instance/con
15
15
  import { jsx, Fragment } from 'react/jsx-runtime';
16
16
  import { Row, Pagination } from 'antd';
17
17
  import { useHTableContext } from '../context.js';
18
+ import { useClassName } from '../hooks/index.js';
18
19
 
19
- var _excluded = ["onPageChange"];
20
+ var _excluded = ["onPageChange", "paginationStyle"];
20
21
  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; }
21
22
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context3, _context4; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context3 = ownKeys(Object(t), !0)).call(_context3, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context4 = ownKeys(Object(t))).call(_context4, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
22
23
  var HTablePagination = (function (_ref) {
23
24
  var onPageChange = _ref.onPageChange,
25
+ paginationStyle = _ref.paginationStyle,
24
26
  props = _objectWithoutProperties(_ref, _excluded);
25
27
  var _useHTableContext = useHTableContext(),
26
- contextOnPageChange = _useHTableContext.onPageChange;
27
- _useHTableContext.configData;
28
- var data = _useHTableContext.data;
28
+ contextOnPageChange = _useHTableContext.onPageChange,
29
+ data = _useHTableContext.data;
29
30
  var tableOnPageChange = onPageChange || contextOnPageChange;
30
31
  var _ref2 = data || {},
31
32
  size = _ref2.size,
@@ -34,14 +35,12 @@ var HTablePagination = (function (_ref) {
34
35
  var pageCurrent = _Number$parseInt(current || "1", 10);
35
36
  var pageSize = _Number$parseInt(size || "10", 10);
36
37
  var pageTotal = _Number$parseInt(total || "0", 10);
38
+ var className = useClassName("hw-table-pagination");
37
39
  if (data) {
38
40
  return jsx(Row, {
39
41
  justify: "end",
40
- style: {
41
- paddingBottom: 24,
42
- paddingRight: 24,
43
- paddingLeft: 24
44
- },
42
+ className: className,
43
+ style: paginationStyle,
45
44
  children: jsx(Pagination, _objectSpread({
46
45
  size: "small",
47
46
  showQuickJumper: true,
package/es/Table.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import type { HTableProps } from "./modal";
2
- declare const _default: ({ request, configData, searchSpan, table, actionRender, footerRender, hideHeader, headerStyle, footerStyle, tableStyle, action, spaceSize, className, ...props }: HTableProps) => JSX.Element;
2
+ declare const _default: ({ request, configData, searchSpan, table, actionRender, footerRender, hideHeader, headerStyle, footerStyle, tableStyle, action, spaceSize, className, paginationStyle, ...props }: HTableProps) => JSX.Element;
3
3
  export default _default;
package/es/Table.js CHANGED
@@ -20,7 +20,7 @@ import { Space } from 'antd';
20
20
  import useReq from './hooks/useReq.js';
21
21
  import useDispatch from './hooks/useDispatch.js';
22
22
 
23
- var _excluded = ["request", "configData", "searchSpan", "table", "actionRender", "footerRender", "hideHeader", "headerStyle", "footerStyle", "tableStyle", "action", "spaceSize", "className"];
23
+ var _excluded = ["request", "configData", "searchSpan", "table", "actionRender", "footerRender", "hideHeader", "headerStyle", "footerStyle", "tableStyle", "action", "spaceSize", "className", "paginationStyle"];
24
24
  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; }
25
25
  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; }
26
26
  var Table = (function (_ref) {
@@ -42,6 +42,7 @@ var Table = (function (_ref) {
42
42
  _ref$spaceSize = _ref.spaceSize,
43
43
  spaceSize = _ref$spaceSize === void 0 ? 15 : _ref$spaceSize,
44
44
  className = _ref.className,
45
+ paginationStyle = _ref.paginationStyle,
45
46
  props = _objectWithoutProperties(_ref, _excluded);
46
47
  var _useReq = useReq({
47
48
  request: request
@@ -91,7 +92,8 @@ var Table = (function (_ref) {
91
92
  searchSpan: searchSpan,
92
93
  headerStyle: headerStyle
93
94
  }), jsx(Body, _objectSpread({
94
- tableStyle: tableStyle
95
+ tableStyle: tableStyle,
96
+ paginationStyle: paginationStyle
95
97
  }, props)), footerRender !== false && jsx(Footer, {
96
98
  actionRender: actionRender,
97
99
  footerRender: footerRender,
@@ -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
- var _useReq = useReq({
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,
@@ -1,8 +1,13 @@
1
1
  import type { ParamsModal, ResultModal } from "@/components/modal";
2
- interface IParamsModal {
3
- request: (params: ParamsModal) => Promise<ResultModal>;
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;
@@ -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 { useMemo } from 'react';
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 _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
+ 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$size = params.size,
28
- size = _params$size === void 0 ? "10" : _params$size,
29
- _params$current = params.current,
30
- current = _params$current === void 0 ? "1" : _params$current,
31
- oParams = _objectWithoutProperties(params, _excluded);
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
- return _objectSpread(_objectSpread({}, resultAction), {}, {
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 CHANGED
@@ -3,3 +3,11 @@
3
3
  background-color: #fff;
4
4
  overflow: hidden;
5
5
  }
6
+ .ant-hw-table-body .ant-hw-table-pagination {
7
+ padding: 0 24px 24px;
8
+ }
9
+ .ant-hw-table-pagination {
10
+ padding: 24px;
11
+ border-radius: 4px;
12
+ background-color: #ffffff;
13
+ }
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: (params: ParamsModal) => Promise<ResultModal>;
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,11 @@ 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;
52
+ paginationStyle?: React.CSSProperties;
48
53
  }
49
54
  export interface TableInstance {
50
55
  reload: (params?: ParamsModal) => Promise<any>;
@@ -8,6 +8,7 @@ interface HTableBodyProps extends Omit<ProTableProps<any, any>, "dataSource"> {
8
8
  emptyRender?: (tableInstance: HTableInstance) => React.ReactNode;
9
9
  errorRender?: (tableInstance: HTableInstance, error: Error) => React.ReactNode;
10
10
  tableStyle?: React.CSSProperties;
11
+ paginationStyle?: React.CSSProperties;
11
12
  }
12
- declare const _default: ({ configData, pagination, onPageChange, rowSelection, rowKey, emptyRender, errorRender, tableStyle, ...props }: HTableBodyProps) => JSX.Element;
13
+ declare const _default: ({ configData, pagination, onPageChange, rowSelection, rowKey, emptyRender, errorRender, tableStyle, paginationStyle, ...props }: HTableBodyProps) => JSX.Element;
13
14
  export default _default;
@@ -22,7 +22,7 @@ var TableConfig = require('../TableConfig.js');
22
22
  var index$1 = require('../HTablePagination/index.js');
23
23
  var index = require('../hooks/index.js');
24
24
 
25
- var _excluded = ["configData", "pagination", "onPageChange", "rowSelection", "rowKey", "emptyRender", "errorRender", "tableStyle"];
25
+ var _excluded = ["configData", "pagination", "onPageChange", "rowSelection", "rowKey", "emptyRender", "errorRender", "tableStyle", "paginationStyle"];
26
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; }
27
27
  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; }
28
28
  var defaultRender = function defaultRender() {
@@ -42,6 +42,7 @@ var Body = (function (_ref) {
42
42
  emptyRender = _ref.emptyRender,
43
43
  errorRender = _ref.errorRender,
44
44
  tableStyle = _ref.tableStyle,
45
+ paginationStyle = _ref.paginationStyle,
45
46
  props = _objectWithoutProperties(_ref, _excluded);
46
47
  var selectedRowKeys = rowSelection.selectedRowKeys,
47
48
  onChange = rowSelection.onChange;
@@ -106,7 +107,8 @@ var Body = (function (_ref) {
106
107
  dataSource: records,
107
108
  pagination: false
108
109
  })), pagination !== false && jsxRuntime.jsx(index$1.default, _objectSpread({
109
- onPageChange: onPageChange
110
+ onPageChange: onPageChange,
111
+ paginationStyle: paginationStyle
110
112
  }, pagination))]
111
113
  })
112
114
  });
@@ -1,7 +1,9 @@
1
1
  import type { PaginationProps } from "antd";
2
2
  import type { ParamsModal } from "@/components/modal";
3
+ import React from "react";
3
4
  interface IPaginationProps extends PaginationProps {
4
5
  onPageChange?: (params: ParamsModal) => void;
6
+ paginationStyle?: React.CSSProperties;
5
7
  }
6
- declare const _default: ({ onPageChange, ...props }: IPaginationProps) => JSX.Element;
8
+ declare const _default: ({ onPageChange, paginationStyle, ...props }: IPaginationProps) => JSX.Element;
7
9
  export default _default;
@@ -18,17 +18,18 @@ var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/c
18
18
  var jsxRuntime = require('react/jsx-runtime');
19
19
  var antd = require('antd');
20
20
  var context = require('../context.js');
21
+ var index = require('../hooks/index.js');
21
22
 
22
- var _excluded = ["onPageChange"];
23
+ var _excluded = ["onPageChange", "paginationStyle"];
23
24
  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; }
24
25
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context3, _context4; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context3 = ownKeys(Object(t), !0)).call(_context3, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context4 = ownKeys(Object(t))).call(_context4, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
25
26
  var HTablePagination = (function (_ref) {
26
27
  var onPageChange = _ref.onPageChange,
28
+ paginationStyle = _ref.paginationStyle,
27
29
  props = _objectWithoutProperties(_ref, _excluded);
28
30
  var _useHTableContext = context.useHTableContext(),
29
- contextOnPageChange = _useHTableContext.onPageChange;
30
- _useHTableContext.configData;
31
- var data = _useHTableContext.data;
31
+ contextOnPageChange = _useHTableContext.onPageChange,
32
+ data = _useHTableContext.data;
32
33
  var tableOnPageChange = onPageChange || contextOnPageChange;
33
34
  var _ref2 = data || {},
34
35
  size = _ref2.size,
@@ -37,14 +38,12 @@ var HTablePagination = (function (_ref) {
37
38
  var pageCurrent = _Number$parseInt(current || "1", 10);
38
39
  var pageSize = _Number$parseInt(size || "10", 10);
39
40
  var pageTotal = _Number$parseInt(total || "0", 10);
41
+ var className = index.useClassName("hw-table-pagination");
40
42
  if (data) {
41
43
  return jsxRuntime.jsx(antd.Row, {
42
44
  justify: "end",
43
- style: {
44
- paddingBottom: 24,
45
- paddingRight: 24,
46
- paddingLeft: 24
47
- },
45
+ className: className,
46
+ style: paginationStyle,
48
47
  children: jsxRuntime.jsx(antd.Pagination, _objectSpread({
49
48
  size: "small",
50
49
  showQuickJumper: true,
package/lib/Table.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import type { HTableProps } from "./modal";
2
- declare const _default: ({ request, configData, searchSpan, table, actionRender, footerRender, hideHeader, headerStyle, footerStyle, tableStyle, action, spaceSize, className, ...props }: HTableProps) => JSX.Element;
2
+ declare const _default: ({ request, configData, searchSpan, table, actionRender, footerRender, hideHeader, headerStyle, footerStyle, tableStyle, action, spaceSize, className, paginationStyle, ...props }: HTableProps) => JSX.Element;
3
3
  export default _default;
package/lib/Table.js CHANGED
@@ -23,7 +23,7 @@ var antd = require('antd');
23
23
  var useReq = require('./hooks/useReq.js');
24
24
  var useDispatch = require('./hooks/useDispatch.js');
25
25
 
26
- var _excluded = ["request", "configData", "searchSpan", "table", "actionRender", "footerRender", "hideHeader", "headerStyle", "footerStyle", "tableStyle", "action", "spaceSize", "className"];
26
+ var _excluded = ["request", "configData", "searchSpan", "table", "actionRender", "footerRender", "hideHeader", "headerStyle", "footerStyle", "tableStyle", "action", "spaceSize", "className", "paginationStyle"];
27
27
  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; }
28
28
  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; }
29
29
  var Table = (function (_ref) {
@@ -45,6 +45,7 @@ var Table = (function (_ref) {
45
45
  _ref$spaceSize = _ref.spaceSize,
46
46
  spaceSize = _ref$spaceSize === void 0 ? 15 : _ref$spaceSize,
47
47
  className = _ref.className,
48
+ paginationStyle = _ref.paginationStyle,
48
49
  props = _objectWithoutProperties(_ref, _excluded);
49
50
  var _useReq = useReq.default({
50
51
  request: request
@@ -94,7 +95,8 @@ var Table = (function (_ref) {
94
95
  searchSpan: searchSpan,
95
96
  headerStyle: headerStyle
96
97
  }), jsxRuntime.jsx(index$1.default, _objectSpread({
97
- tableStyle: tableStyle
98
+ tableStyle: tableStyle,
99
+ paginationStyle: paginationStyle
98
100
  }, props)), footerRender !== false && jsxRuntime.jsx(index$2.default, {
99
101
  actionRender: actionRender,
100
102
  footerRender: footerRender,
@@ -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
- var _useReq = useReq.default({
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,
@@ -1,8 +1,13 @@
1
1
  import type { ParamsModal, ResultModal } from "@/components/modal";
2
- interface IParamsModal {
3
- request: (params: ParamsModal) => Promise<ResultModal>;
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;
@@ -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 _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
+ 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$size = params.size,
31
- size = _params$size === void 0 ? "10" : _params$size,
32
- _params$current = params.current,
33
- current = _params$current === void 0 ? "1" : _params$current,
34
- oParams = _objectWithoutProperties(params, _excluded);
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
- return _objectSpread(_objectSpread({}, resultAction), {}, {
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 CHANGED
@@ -3,3 +3,11 @@
3
3
  background-color: #fff;
4
4
  overflow: hidden;
5
5
  }
6
+ .ant-hw-table-body .ant-hw-table-pagination {
7
+ padding: 0 24px 24px;
8
+ }
9
+ .ant-hw-table-pagination {
10
+ padding: 24px;
11
+ border-radius: 4px;
12
+ background-color: #ffffff;
13
+ }
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: (params: ParamsModal) => Promise<ResultModal>;
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,11 @@ 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;
52
+ paginationStyle?: React.CSSProperties;
48
53
  }
49
54
  export interface TableInstance {
50
55
  reload: (params?: ParamsModal) => Promise<any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hw-component/table",
3
- "version": "0.0.3-beta-v6",
3
+ "version": "0.0.3-beta-v8",
4
4
  "description": "基于antd二次开发table组件",
5
5
  "keywords": [
6
6
  "table"
@@ -18,6 +18,7 @@ interface HTableBodyProps extends Omit<ProTableProps<any, any>, "dataSource"> {
18
18
  error: Error
19
19
  ) => React.ReactNode;
20
20
  tableStyle?: React.CSSProperties;
21
+ paginationStyle?: React.CSSProperties;
21
22
  }
22
23
  const defaultRender = () => {
23
24
  return <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />;
@@ -31,6 +32,7 @@ export default ({
31
32
  emptyRender,
32
33
  errorRender,
33
34
  tableStyle,
35
+ paginationStyle,
34
36
  ...props
35
37
  }: HTableBodyProps) => {
36
38
  // @ts-ignore
@@ -88,7 +90,7 @@ export default ({
88
90
  pagination={false}
89
91
  />
90
92
  {pagination !== false && (
91
- <HTablePagination onPageChange={onPageChange} {...pagination} />
93
+ <HTablePagination onPageChange={onPageChange} paginationStyle={paginationStyle} {...pagination} />
92
94
  )}
93
95
  </ConfigProvider>
94
96
  </div>
@@ -2,13 +2,15 @@ import type { PaginationProps} from "antd";
2
2
  import { Pagination, Row } from "antd";
3
3
  import { useHTableContext } from "../context";
4
4
  import type { ParamsModal } from "@/components/modal";
5
+ import {useClassName} from "../hooks";
6
+ import React from "react";
5
7
  interface IPaginationProps extends PaginationProps {
6
8
  onPageChange?: (params: ParamsModal) => void;
9
+ paginationStyle?: React.CSSProperties;
7
10
  }
8
- export default ({ onPageChange, ...props }: IPaginationProps) => {
11
+ export default ({ onPageChange,paginationStyle, ...props }: IPaginationProps) => {
9
12
  const {
10
13
  onPageChange: contextOnPageChange,
11
- configData: contextConfigData,
12
14
  data,
13
15
  } = useHTableContext();
14
16
  const tableOnPageChange = onPageChange || contextOnPageChange;
@@ -16,11 +18,13 @@ export default ({ onPageChange, ...props }: IPaginationProps) => {
16
18
  const pageCurrent = Number.parseInt(current || "1", 10);
17
19
  const pageSize = Number.parseInt(size || "10", 10);
18
20
  const pageTotal = Number.parseInt(total || "0", 10);
21
+ const className = useClassName("hw-table-pagination");
19
22
  if (data) {
20
23
  return (
21
24
  <Row
22
25
  justify={"end"}
23
- style={{ paddingBottom: 24, paddingRight: 24, paddingLeft: 24 }}
26
+ className={className}
27
+ style={paginationStyle}
24
28
  >
25
29
  <Pagination
26
30
  size={"small"}
@@ -22,6 +22,7 @@ export default ({
22
22
  action = {},
23
23
  spaceSize = 15,
24
24
  className,
25
+ paginationStyle,
25
26
  ...props
26
27
  }: HTableProps) => {
27
28
  const { run, loading, data, error, saveParams } = useReq({ request });
@@ -61,7 +62,7 @@ export default ({
61
62
  {!hideHeader && (
62
63
  <Header searchSpan={searchSpan} headerStyle={headerStyle} />
63
64
  )}
64
- <Body tableStyle={tableStyle} {...props} />
65
+ <Body tableStyle={tableStyle} paginationStyle={paginationStyle} {...props} />
65
66
  {footerRender !== false && (
66
67
  <Footer
67
68
  actionRender={actionRender}
@@ -2,6 +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 type {IParamsModal} from "./hooks/useReq";
5
6
  import useReq from "./hooks/useReq";
6
7
  import useDispatch from "./hooks/useDispatch";
7
8
  import React from "react";
@@ -11,8 +12,9 @@ const Index: React.FC<HTableProps> = ({
11
12
  table,
12
13
  action = {},
13
14
  children,
15
+ ...props
14
16
  }) => {
15
- const { run, loading, data, error, saveParams } = useReq({ request });
17
+ const { run, loading, data, error, saveParams } = useReq(({ request,...props } as IParamsModal));
16
18
  const dispatch = useDispatch(action);
17
19
  const { selectedRowData, rowOnChange, allSelectChange } = useRowObj();
18
20
  const tableInstance = useCurrentTable({
@@ -1,23 +1,55 @@
1
- import { useMemo } from "react";
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: (params: ParamsModal) => Promise<ResultModal>;
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
- return {
20
- ...resultAction,
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
  };
@@ -3,4 +3,12 @@
3
3
  border-radius: 4px;
4
4
  background-color: #fff;
5
5
  overflow: hidden;
6
+ .@{ant-prefix}-hw-table-pagination{
7
+ padding: 0 24px 24px;
8
+ }
9
+ }
10
+ .@{ant-prefix}-hw-table-pagination{
11
+ padding: 24px;
12
+ border-radius: 4px;
13
+ background-color: #ffffff;
6
14
  }
@@ -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: (params: ParamsModal) => Promise<ResultModal>;
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,11 @@ 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;
71
+ paginationStyle?: React.CSSProperties
67
72
  }
68
73
  export interface TableInstance {
69
74
  reload: (params?: ParamsModal) => Promise<any>;
@@ -5,6 +5,8 @@ import {
5
5
  HTableFooter,
6
6
  HTablePagination,
7
7
  } from "../../components";
8
+ import {useRequest} from "ahooks";
9
+ import {Space} from "antd";
8
10
 
9
11
  const configData = [
10
12
  {
@@ -21,33 +23,39 @@ const configData = [
21
23
  },
22
24
  ];
23
25
  export default () => {
26
+ const {run,loading,error,data}=useRequest((params)=>{
27
+ const { current = 1 } = params;
28
+ return new Promise((resolve, reject) => {
29
+ setTimeout(() => {
30
+ // reject(new Error("错误"));
31
+ resolve({
32
+ size: "10",
33
+ current: current.toString(10),
34
+ total: "100",
35
+ records: [
36
+ {
37
+ id: 1,
38
+ name: "111",
39
+ },
40
+ ],
41
+ });
42
+ }, 2000);
43
+ });
44
+ });
24
45
  return (
25
46
  <TableCustomize
26
47
  configData={configData}
27
- request={(params) => {
28
- const { current = 1 } = params;
29
- return new Promise((resolve, reject) => {
30
- setTimeout(() => {
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
- }}
48
+ loading={loading}
49
+ error={error}
50
+ dataSource={data}
51
+ reload={run}
46
52
  >
47
- <HTableHeader />
48
- <HTableBody pagination={false} />
49
- <HTablePagination />
50
- <HTableFooter />
53
+ <Space direction={"vertical"} style={{width:"100%"}}>
54
+ <HTableHeader />
55
+ <HTableBody pagination={false} />
56
+ <HTablePagination />
57
+ <HTableFooter />
58
+ </Space>
51
59
  </TableCustomize>
52
60
  );
53
61
  };