@hw-component/table 0.0.1-beta-v1

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.
Files changed (80) hide show
  1. package/.babelrc +23 -0
  2. package/.eslintrc.js +8 -0
  3. package/.husky/pre-commit +4 -0
  4. package/.stylelintrc.js +5 -0
  5. package/README.en.md +36 -0
  6. package/README.md +37 -0
  7. package/es/Body/hooks.d.ts +1167 -0
  8. package/es/Body/hooks.js +51 -0
  9. package/es/Body/index.d.ts +12 -0
  10. package/es/Body/index.js +117 -0
  11. package/es/Footer/index.d.ts +6 -0
  12. package/es/Footer/index.js +65 -0
  13. package/es/Header/index.d.ts +9 -0
  14. package/es/Header/index.js +42 -0
  15. package/es/Header/utils.d.ts +7 -0
  16. package/es/Header/utils.js +67 -0
  17. package/es/Table.d.ts +3 -0
  18. package/es/Table.js +98 -0
  19. package/es/TableConfig.d.ts +13 -0
  20. package/es/TableConfig.js +29 -0
  21. package/es/context.d.ts +12 -0
  22. package/es/context.js +11 -0
  23. package/es/hooks/useCurrentTable.d.ts +7 -0
  24. package/es/hooks/useCurrentTable.js +17 -0
  25. package/es/hooks/useHTable.d.ts +8 -0
  26. package/es/hooks/useHTable.js +21 -0
  27. package/es/hooks/useRowObj.d.ts +7 -0
  28. package/es/hooks/useRowObj.js +23 -0
  29. package/es/index.d.ts +3 -0
  30. package/es/index.js +5 -0
  31. package/es/modal.d.ts +45 -0
  32. package/lib/Body/hooks.d.ts +1167 -0
  33. package/lib/Body/hooks.js +53 -0
  34. package/lib/Body/index.d.ts +12 -0
  35. package/lib/Body/index.js +120 -0
  36. package/lib/Footer/index.d.ts +6 -0
  37. package/lib/Footer/index.js +68 -0
  38. package/lib/Header/index.d.ts +9 -0
  39. package/lib/Header/index.js +45 -0
  40. package/lib/Header/utils.d.ts +7 -0
  41. package/lib/Header/utils.js +69 -0
  42. package/lib/Table.d.ts +3 -0
  43. package/lib/Table.js +101 -0
  44. package/lib/TableConfig.d.ts +13 -0
  45. package/lib/TableConfig.js +34 -0
  46. package/lib/context.d.ts +12 -0
  47. package/lib/context.js +13 -0
  48. package/lib/hooks/useCurrentTable.d.ts +7 -0
  49. package/lib/hooks/useCurrentTable.js +20 -0
  50. package/lib/hooks/useHTable.d.ts +8 -0
  51. package/lib/hooks/useHTable.js +24 -0
  52. package/lib/hooks/useRowObj.d.ts +7 -0
  53. package/lib/hooks/useRowObj.js +26 -0
  54. package/lib/index.d.ts +3 -0
  55. package/lib/index.js +12 -0
  56. package/lib/modal.d.ts +45 -0
  57. package/package.json +89 -0
  58. package/public/index.html +19 -0
  59. package/scripts/rollup.config.js +90 -0
  60. package/scripts/webpack.config.js +75 -0
  61. package/src/Layout.tsx +61 -0
  62. package/src/app.tsx +33 -0
  63. package/src/components/Body/hooks.ts +44 -0
  64. package/src/components/Body/index.tsx +85 -0
  65. package/src/components/Footer/index.tsx +43 -0
  66. package/src/components/Header/index.tsx +45 -0
  67. package/src/components/Header/utils.ts +58 -0
  68. package/src/components/Table.tsx +65 -0
  69. package/src/components/TableConfig.tsx +30 -0
  70. package/src/components/context.ts +17 -0
  71. package/src/components/hooks/useCurrentTable.ts +16 -0
  72. package/src/components/hooks/useHTable.tsx +18 -0
  73. package/src/components/hooks/useRowObj.ts +17 -0
  74. package/src/components/index.tsx +3 -0
  75. package/src/components/modal.ts +58 -0
  76. package/src/index.less +20 -0
  77. package/src/index.tsx +12 -0
  78. package/src/pages/Test/index.tsx +55 -0
  79. package/src/routes.tsx +26 -0
  80. package/tsconfig.json +29 -0
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
6
+ var React = require('react');
7
+
8
+ var useRowObj = (function () {
9
+ var _useState = React.useState({}),
10
+ _useState2 = _slicedToArray(_useState, 2),
11
+ selectedRowData = _useState2[0],
12
+ setSelectedRowData = _useState2[1];
13
+ var rowOnChange = function rowOnChange(keys, rowData) {
14
+ setSelectedRowData({
15
+ keys: keys,
16
+ rowData: rowData
17
+ });
18
+ };
19
+ return {
20
+ rowOnChange: rowOnChange,
21
+ selectedRowData: selectedRowData
22
+ };
23
+ });
24
+
25
+ exports.default = useRowObj;
26
+ // powered by h
package/lib/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { default as HTable } from "./Table";
2
+ export { default as useHTable } from "./hooks/useHTable";
3
+ export { default as HTableConfig } from "./TableConfig";
package/lib/index.js ADDED
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ var Table = require('./Table.js');
4
+ var useHTable = require('./hooks/useHTable.js');
5
+ var TableConfig = require('./TableConfig.js');
6
+
7
+
8
+
9
+ exports.HTable = Table.default;
10
+ exports.useHTable = useHTable.default;
11
+ exports.HTableConfig = TableConfig.default;
12
+ // powered by h
package/lib/modal.d.ts ADDED
@@ -0,0 +1,45 @@
1
+ import type { ProColumns } from "@ant-design/pro-table/lib/typing";
2
+ import type { ProTableProps } from "@ant-design/pro-table";
3
+ import type { HItemProps, HFormInstance } from "@hw-component/form/es/Form/modal";
4
+ import type { ColProps } from "antd";
5
+ import type React from "react";
6
+ export interface RowObj {
7
+ keys?: React.Key[];
8
+ rowData?: any[];
9
+ }
10
+ export interface ResultModal {
11
+ records: any[];
12
+ current: string;
13
+ size: string;
14
+ total: string;
15
+ }
16
+ export interface ParamsModal extends Record<string, any> {
17
+ size?: number;
18
+ current?: number;
19
+ }
20
+ interface HColumns extends Omit<ProColumns, "render"> {
21
+ render?: (dom: React.ReactNode, data: any, index: number, table: HTableInstance) => React.ReactNode;
22
+ showSearch?: boolean;
23
+ searchType?: HItemProps["type"];
24
+ searchRender?: HItemProps["render"];
25
+ }
26
+ export type ConfigItemModal = Omit<HItemProps, "render" | "type"> & HColumns;
27
+ export type ConfigDataModal = ConfigItemModal[];
28
+ export type ActionRenderFn = (allCheck: boolean, selectedRowKeys: RowObj, xjTable: HTableInstance) => React.ReactNode;
29
+ export interface HTableProps extends Omit<ProTableProps<any, any>, "request"> {
30
+ request: (params: ParamsModal) => Promise<ResultModal>;
31
+ configData: ConfigDataModal;
32
+ searchSpan?: ColProps;
33
+ table?: HTableInstance;
34
+ actionRender?: ActionRenderFn;
35
+ emptyRender?: (table: HTableInstance) => React.ReactNode;
36
+ errorRender?: (table: HTableInstance) => React.ReactNode;
37
+ }
38
+ export interface TableInstance {
39
+ reload: (params: ParamsModal) => void;
40
+ }
41
+ export interface HTableInstance {
42
+ form: HFormInstance;
43
+ table: TableInstance;
44
+ }
45
+ export {};
package/package.json ADDED
@@ -0,0 +1,89 @@
1
+ {
2
+ "name": "@hw-component/table",
3
+ "version": "0.0.1-beta-v1",
4
+ "description": "基于antd二次开发table组件",
5
+ "keywords": [
6
+ "table"
7
+ ],
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://gitee.com/hdj_wq/hw-component-table.git"
11
+ },
12
+ "license": "ISC",
13
+ "author": "hdj",
14
+ "main": "index.js",
15
+ "scripts": {
16
+ "build": "rollup --config ./scripts/rollup.config.js",
17
+ "lint:fix": "eslint --fix --cache --ext .js,.jsx,.ts,.tsx --format=pretty ./src && npm run lint:style",
18
+ "lint:js": "eslint --cache --ext .js,.jsx,.ts,.tsx --format=pretty ./src",
19
+ "lint:style": "stylelint --fix \"src/**/*.less\" --syntax less",
20
+ "prepare": "husky install",
21
+ "start": "webpack-dev-server --config ./scripts/webpack.config.js",
22
+ "test": "echo \"Error: no test specified\" && exit 1"
23
+ },
24
+ "lint-staged": {
25
+ "**/*.less": "npm run lint:style",
26
+ "**/*.{js,jsx,ts,tsx}": "npm run lint:fix",
27
+ "**/*.{js,jsx,tsx,ts,less,md,json}": [
28
+ "prettier --write"
29
+ ]
30
+ },
31
+ "dependencies": {
32
+ "@ant-design/pro-table": "2.70.0",
33
+ "@hw-component/form": "0.0.9-beta-v7",
34
+ "ahooks": "2.10.9",
35
+ "antd": "4.20.7",
36
+ "core-js": "3",
37
+ "react": "17.0.0",
38
+ "react-dom": "17.0.2",
39
+ "react-router-dom": "^6.11.2"
40
+ },
41
+ "devDependencies": {
42
+ "@babel/core": "^7.21.8",
43
+ "@babel/plugin-transform-runtime": "^7.23.2",
44
+ "@babel/preset-env": "^7.23.2",
45
+ "@babel/preset-react": "^7.18.6",
46
+ "@babel/preset-typescript": "^7.21.5",
47
+ "@babel/runtime-corejs3": "^7.21.5",
48
+ "@rollup/plugin-babel": "^6.0.3",
49
+ "@rollup/plugin-commonjs": "^25.0.0",
50
+ "@rollup/plugin-inject": "^5.0.3",
51
+ "@rollup/plugin-node-resolve": "^15.0.2",
52
+ "@rollup/plugin-url": "^8.0.1",
53
+ "@types/react": "17.0.17",
54
+ "@types/react-dom": "17.0.9",
55
+ "@typescript-eslint/eslint-plugin": "^5.59.7",
56
+ "@umijs/fabric": "^2.14.1",
57
+ "autoprefixer": "^10.4.14",
58
+ "babel-loader": "^9.1.2",
59
+ "css-loader": "^6.7.4",
60
+ "eslint": "^8.41.0",
61
+ "eslint-plugin-jest": "^27.2.1",
62
+ "eslint-plugin-react": "^7.32.2",
63
+ "eslint-plugin-react-hooks": "^4.6.0",
64
+ "eslint-plugin-unicorn": "^47.0.0",
65
+ "html-webpack-plugin": "^5.5.1",
66
+ "husky": "^8.0.3",
67
+ "less": "^4.1.3",
68
+ "less-loader": "^11.1.0",
69
+ "lint-staged": "10.5.4",
70
+ "postcss": "^8.4.23",
71
+ "postcss-less": "^6.0.0",
72
+ "rollup": "^3.23.0",
73
+ "rollup-plugin-clear": "^2.0.7",
74
+ "rollup-plugin-postcss": "4.0.0",
75
+ "rollup-plugin-typescript2": "^0.34.1",
76
+ "style-loader": "^3.3.3",
77
+ "stylelint": "13.13.1",
78
+ "typescript": "5.0.4",
79
+ "webpack": "^5.83.1",
80
+ "webpack-cli": "^5.1.1",
81
+ "webpack-dev-server": "^4.15.0",
82
+ "webpackbar": "^5.0.2"
83
+ },
84
+ "cssPrefix": "hw",
85
+ "publishConfig": {
86
+ "access": "public",
87
+ "registry": "https://registry.npmjs.org/"
88
+ }
89
+ }
@@ -0,0 +1,19 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <meta name="viewport" content="webpack5">
8
+ <title>hw-components</title>
9
+ <style>
10
+ body{
11
+ margin: 0px;
12
+ padding: 0px;
13
+ }
14
+ </style>
15
+ </head>
16
+ <body>
17
+ <div id="root"></div>
18
+ </body>
19
+ </html>
@@ -0,0 +1,90 @@
1
+ const path = require("path");
2
+ const clear = require("rollup-plugin-clear");
3
+ const { nodeResolve } = require("@rollup/plugin-node-resolve");
4
+ const { babel } = require("@rollup/plugin-babel");
5
+ const commonjs = require("@rollup/plugin-commonjs");
6
+ const typescript = require("rollup-plugin-typescript2");
7
+ const autoprefixer = require("autoprefixer");
8
+ const inject = require("@rollup/plugin-inject");
9
+ const url = require("@rollup/plugin-url");
10
+ const postcss = require("rollup-plugin-postcss");
11
+ const input = path.resolve(__dirname, "../src/components/index.tsx");
12
+ const outDir = path.resolve(__dirname, "../lib");
13
+ const esOutDir = path.resolve(__dirname, "../es");
14
+ module.exports = {
15
+ input,
16
+ output: [
17
+ {
18
+ dir: outDir,
19
+ format: "cjs",
20
+ footer: "// powered by h",
21
+ entryFileNames: "[name].js",
22
+ exports: "named",
23
+ preserveModules: true,
24
+ },
25
+ {
26
+ dir: esOutDir,
27
+ format: "es",
28
+ banner: "// welcome to hoo hoo hoo",
29
+ footer: "// powered by hdj",
30
+ entryFileNames: "[name].js",
31
+ exports: "named",
32
+ preserveModules: true,
33
+ },
34
+ ],
35
+ plugins: [
36
+ clear({
37
+ targets: [outDir, esOutDir],
38
+ }),
39
+ url({
40
+ fileName: "[dirname][hash][extname]",
41
+ }),
42
+ postcss({
43
+ extract: "index.css",
44
+ plugins: [
45
+ autoprefixer({
46
+ overrideBrowserslist: [
47
+ "last 10 Chrome versions",
48
+ "last 5 Firefox versions",
49
+ "Safari >= 6",
50
+ "ie> 8",
51
+ ],
52
+ }),
53
+ ],
54
+ }),
55
+ typescript({
56
+ tsconfigOverride: {
57
+ include: [`src/components/**/*`],
58
+ },
59
+ }),
60
+ babel({
61
+ exclude: "node_modules/**",
62
+ extensions: [".ts", ".tsx", ".js", ".jsx"],
63
+ babelHelpers: "runtime",
64
+ presets: [
65
+ [
66
+ "@babel/preset-env",
67
+ {
68
+ targets: {
69
+ chrome: "58",
70
+ ie: "11",
71
+ ios: "11",
72
+ },
73
+ useBuiltIns: "usage",
74
+ corejs: 3,
75
+ modules: false,
76
+ },
77
+ ],
78
+ ],
79
+ }),
80
+ inject({
81
+ React: "react",
82
+ }),
83
+ nodeResolve({
84
+ resolveOnly: ["node_modules"], //定义为模块
85
+ }),
86
+ commonjs({
87
+ include: ["node_modules"],
88
+ }),
89
+ ],
90
+ };
@@ -0,0 +1,75 @@
1
+ const path = require("path");
2
+ const HtmlWebpackPlugin = require("html-webpack-plugin");
3
+ const WebpackBar = require("webpackbar");
4
+ const webpack = require("webpack");
5
+
6
+ module.exports = {
7
+ mode: "development",
8
+ devtool: "cheap-module-source-map",
9
+ entry: {
10
+ app: path.resolve(__dirname, "../src/index.tsx"),
11
+ },
12
+ output: {
13
+ path: path.resolve("dist"),
14
+ publicPath: "/",
15
+ clean: true, //每次打包前清空目录
16
+ },
17
+ devServer: {
18
+ port: 3000,
19
+ compress: true,
20
+ open: true,
21
+ hot: true,
22
+ historyApiFallback: {
23
+ disableDotRule: true,
24
+ },
25
+ },
26
+ module: {
27
+ rules: [
28
+ {
29
+ test: /\.(tsx?|ts)$/,
30
+ loader: "babel-loader",
31
+ options: { cacheDirectory: true },
32
+ exclude: /node_modules/,
33
+ },
34
+ {
35
+ test: /\.css$/,
36
+ use: ["style-loader", "css-loader"],
37
+ },
38
+ {
39
+ test: /\.less$/,
40
+ use: [
41
+ "style-loader",
42
+ {
43
+ loader: "css-loader",
44
+ },
45
+ {
46
+ loader: "less-loader",
47
+ options: {
48
+ lessOptions: {
49
+ javascriptEnabled: true,
50
+ },
51
+ },
52
+ },
53
+ ],
54
+ },
55
+ ],
56
+ },
57
+ resolve: {
58
+ alias: {
59
+ "@": path.resolve(__dirname, "./src/components"),
60
+ },
61
+ extensions: [".tsx", ".ts", ".js", ".json"],
62
+ },
63
+ plugins: [
64
+ new HtmlWebpackPlugin({
65
+ template: path.resolve(__dirname, "../public/index.html"),
66
+ }),
67
+ new WebpackBar({
68
+ name: "hw components",
69
+ color: "#52c41a",
70
+ }),
71
+ new webpack.ProvidePlugin({
72
+ React: "react",
73
+ }),
74
+ ],
75
+ };
package/src/Layout.tsx ADDED
@@ -0,0 +1,61 @@
1
+ import React, { useEffect, useState } from "react";
2
+ import { Menu } from "antd";
3
+ import "./index.less";
4
+ import type { RouteModal } from "./routes";
5
+ import routes from "./routes";
6
+ import { Outlet, useNavigate, useLocation } from "react-router-dom";
7
+
8
+ const menuItem = (item: RouteModal) => {
9
+ const { name, path, children } = item;
10
+ if (!path) {
11
+ return null;
12
+ }
13
+ if (children) {
14
+ return (
15
+ <Menu.SubMenu title={name} key={path}>
16
+ {children.map((childItem) => {
17
+ return menuItem(childItem);
18
+ })}
19
+ </Menu.SubMenu>
20
+ );
21
+ }
22
+ return <Menu.Item key={path}>{name}</Menu.Item>;
23
+ };
24
+ export default () => {
25
+ const navigate = useNavigate();
26
+ const { pathname } = useLocation();
27
+ const [keys, setKeys] = useState(["/form/select"]);
28
+ const [openKey, setOpenKey] = useState(["/form"]);
29
+ useEffect(() => {
30
+ setKeys([pathname]);
31
+ const pathOpenKeys = pathname.split("/");
32
+ const openKeys = pathOpenKeys.map((path) => {
33
+ return "/" + path;
34
+ });
35
+ setOpenKey(openKeys);
36
+ }, [pathname]);
37
+ return (
38
+ <div className="layout">
39
+ <Menu
40
+ className="menu"
41
+ selectedKeys={keys}
42
+ openKeys={openKey}
43
+ onOpenChange={(openKeys) => {
44
+ setOpenKey(openKeys);
45
+ }}
46
+ onSelect={(e) => {
47
+ navigate(e.key);
48
+ }}
49
+ mode={"inline"}
50
+ theme="dark"
51
+ >
52
+ {routes.map((item) => {
53
+ return menuItem(item);
54
+ })}
55
+ </Menu>
56
+ <div className="body">
57
+ <Outlet />
58
+ </div>
59
+ </div>
60
+ );
61
+ };
package/src/app.tsx ADDED
@@ -0,0 +1,33 @@
1
+ import React from "react";
2
+ import routes from "./routes";
3
+ import {
4
+ createBrowserRouter,
5
+ Navigate,
6
+ RouterProvider,
7
+ useRouteError,
8
+ } from "react-router-dom";
9
+ import type { RouteObject } from "react-router";
10
+ import Layout from "./Layout";
11
+ const Error = () => {
12
+ const error = useRouteError();
13
+ if (error.status === 404) {
14
+ return <Navigate to="/form/select" replace />;
15
+ }
16
+ return <div>错误</div>;
17
+ };
18
+ const rootRoute = [
19
+ {
20
+ path: "/",
21
+ element: <Layout />,
22
+ errorElement: <Error />,
23
+ children: routes,
24
+ },
25
+ ];
26
+ const router = () => {
27
+ return createBrowserRouter(rootRoute as RouteObject[]);
28
+ };
29
+ export default () => {
30
+ return (
31
+ <RouterProvider router={router()} fallbackElement={<p>Loading...</p>} />
32
+ );
33
+ };
@@ -0,0 +1,44 @@
1
+ import type { ConfigDataModal, HTableInstance } from "../modal";
2
+ import type React from "react";
3
+ import { useEffect, useMemo } from "react";
4
+ import { useHTableContext } from "../context";
5
+ import type { GetRowKey } from "rc-table/lib/interface";
6
+
7
+ export const useCols = (cols: ConfigDataModal, table: HTableInstance) => {
8
+ return useMemo(() => {
9
+ return cols.map((item) => {
10
+ const { render } = item;
11
+ return {
12
+ ...item,
13
+ render: (dom: React.ReactNode, data: any, index: number) => {
14
+ if (!render) {
15
+ return dom;
16
+ }
17
+ return render(dom, data, index, table);
18
+ },
19
+ };
20
+ });
21
+ }, [cols, table]);
22
+ };
23
+ interface FilterKeysModal {
24
+ selectedRowKeys?: React.Key[];
25
+ records?: any[];
26
+ rowKey?: string | GetRowKey<any>;
27
+ }
28
+ export const useSynchronousKeys = ({
29
+ selectedRowKeys,
30
+ records,
31
+ rowKey,
32
+ }: FilterKeysModal) => {
33
+ const { rowOnChange } = useHTableContext();
34
+ useEffect(() => {
35
+ if (selectedRowKeys && records && rowKey) {
36
+ const resultData = records.filter((item, index) => {
37
+ const id =
38
+ typeof rowKey === "function" ? rowKey(item, index) : item[rowKey];
39
+ return selectedRowKeys.indexOf(id) !== -1;
40
+ });
41
+ rowOnChange(selectedRowKeys, resultData);
42
+ }
43
+ }, [selectedRowKeys, records, rowKey]);
44
+ };
@@ -0,0 +1,85 @@
1
+ import type { ProTableProps } from "@ant-design/pro-table";
2
+ import ProTable from "@ant-design/pro-table";
3
+ import type { ConfigDataModal, ParamsModal } from "../modal";
4
+ import { useCols, useSynchronousKeys } from "../Body/hooks";
5
+ import { useHTableContext } from "../context";
6
+ import React from "react";
7
+ import { ConfigProvider, Empty } from "antd";
8
+ import type { HTableInstance } from "../modal";
9
+ import { useHTableConfigContext } from "../TableConfig";
10
+
11
+ interface HTableBodyProps extends Omit<ProTableProps<any, any>, "dataSource"> {
12
+ configData: ConfigDataModal;
13
+ onPageChange: (params: ParamsModal) => void;
14
+ emptyRender?: (table: HTableInstance) => React.ReactNode;
15
+ errorRender?: (table: HTableInstance) => React.ReactNode;
16
+ }
17
+ const defaultRender = () => {
18
+ return <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />;
19
+ };
20
+ export default ({
21
+ loading,
22
+ configData,
23
+ pagination = {},
24
+ onPageChange,
25
+ rowSelection = {},
26
+ rowKey = "id",
27
+ emptyRender,
28
+ errorRender,
29
+ ...props
30
+ }: HTableBodyProps) => {
31
+ // @ts-ignore
32
+ const { selectedRowKeys, onChange } = rowSelection;
33
+ const { table, data, selectedRowData, rowOnChange, error } =
34
+ useHTableContext();
35
+ const {
36
+ emptyRender: tableEmptyRender = defaultRender,
37
+ errorRender: tableErrorRender = defaultRender,
38
+ } = useHTableConfigContext({ emptyRender, errorRender });
39
+ const { records, size, current, total } = data || {};
40
+ const cols = useCols(configData, table);
41
+ const change = (key: React.Key[], rowData: any[]) => {
42
+ if (onChange) {
43
+ return onChange(key, rowData);
44
+ }
45
+ rowOnChange(key, rowData);
46
+ };
47
+ useSynchronousKeys({ selectedRowKeys, records, rowKey });
48
+ return (
49
+ <div style={{ borderRadius: 4, overflow: "hidden" }}>
50
+ <ConfigProvider
51
+ renderEmpty={() => {
52
+ if (error) {
53
+ return tableErrorRender?.(table);
54
+ }
55
+ return tableEmptyRender?.(table);
56
+ }}
57
+ >
58
+ <ProTable
59
+ {...props}
60
+ columns={cols}
61
+ search={false}
62
+ rowSelection={{
63
+ ...rowSelection,
64
+ selectedRowKeys: selectedRowData.keys,
65
+ onChange: change,
66
+ }}
67
+ loading={loading}
68
+ rowKey={rowKey}
69
+ dataSource={records}
70
+ onChange={(paginationData) => {
71
+ const { pageSize: ps, current: pn } = paginationData;
72
+ onPageChange({ size: ps, current: pn });
73
+ }}
74
+ pagination={{
75
+ current: Number.parseInt(current || "1", 10),
76
+ total: Number.parseInt(total || "0", 10),
77
+ pageSize: Number.parseInt(size || "10", 10),
78
+ showQuickJumper: true,
79
+ ...pagination,
80
+ }}
81
+ />
82
+ </ConfigProvider>
83
+ </div>
84
+ );
85
+ };
@@ -0,0 +1,43 @@
1
+ import { Card, Affix, Row, Space, Button } from "antd";
2
+ import { Typography } from "antd";
3
+ import type { ActionRenderFn } from "../modal";
4
+ import { useHTableContext } from "../context";
5
+ import React, { useState } from "react";
6
+
7
+ const { Text, Link } = Typography;
8
+ interface IFooterProps {
9
+ actionRender?: ActionRenderFn;
10
+ }
11
+ export default ({ actionRender }: IFooterProps) => {
12
+ const { data, selectedRowData, table } = useHTableContext();
13
+ const [allCheck, setAllCheck] = useState<boolean>(false);
14
+ const { total } = data || {};
15
+ const num = allCheck ? total : 0;
16
+ const dom = (
17
+ <Card style={{ borderRadius: 4 }} bordered={false}>
18
+ <Row justify="space-between">
19
+ <Space size={20}>
20
+ <Button
21
+ type={"primary"}
22
+ ghost
23
+ style={{ padding: "4px 24px", borderRadius: "4px" }}
24
+ onClick={() => {
25
+ setAllCheck(!allCheck);
26
+ }}
27
+ >
28
+ {!allCheck ? "选择全部" : "取消选择"}
29
+ </Button>
30
+ <Text type={"secondary"}>共{total}条</Text>
31
+ <Text type={"secondary"}>
32
+ 已选择<Link>{num}</Link>条
33
+ </Text>
34
+ </Space>
35
+ {actionRender?.(allCheck, selectedRowData, table)}
36
+ </Row>
37
+ </Card>
38
+ );
39
+ if (!data) {
40
+ return dom;
41
+ }
42
+ return <Affix offsetBottom={10}>{dom}</Affix>;
43
+ };
@@ -0,0 +1,45 @@
1
+ import type { ColProps } from "antd";
2
+ import { Card } from "antd";
3
+ import type { ConfigDataModal } from "../modal";
4
+ import { useHTableContext } from "../context";
5
+ import { HForm } from "@hw-component/form";
6
+ import { useMemo } from "react";
7
+ import { formConfigDataProvider } from "./utils";
8
+ import type { HItemProps } from "@hw-component/form/lib/Form/modal";
9
+
10
+ interface IHeaderProps {
11
+ configData: ConfigDataModal;
12
+ onFinish: (value: Record<string, any>) => Promise<any>;
13
+ searchSpan?: ColProps;
14
+ }
15
+
16
+ export default ({
17
+ configData,
18
+ onFinish,
19
+ searchSpan = { span: 6 },
20
+ }: IHeaderProps) => {
21
+ const { table } = useHTableContext();
22
+ const { form } = table;
23
+
24
+ const nConfigData: HItemProps[] = useMemo(
25
+ () => formConfigDataProvider(configData),
26
+ [configData]
27
+ );
28
+
29
+ return (
30
+ <Card
31
+ style={{ borderRadius: 4 }}
32
+ bordered={false}
33
+ bodyStyle={{ paddingBottom: 0 }}
34
+ >
35
+ <HForm
36
+ itemSpan={searchSpan}
37
+ request={onFinish}
38
+ gutter={[20, 0]}
39
+ hideLabel={true}
40
+ configData={nConfigData}
41
+ form={form}
42
+ />
43
+ </Card>
44
+ );
45
+ };