@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,58 @@
1
+ import type { ConfigDataModal, ConfigItemModal } from "../modal";
2
+ import type { HItemProps } from "@hw-component/form/lib/Form/modal";
3
+
4
+ const defaultSubItem = {
5
+ type: "submit",
6
+ itemProps: {
7
+ extraList: ["submit", "reset"],
8
+ style: { padding: "4px 24px", borderRadius: "4px" },
9
+ },
10
+ };
11
+
12
+ export function formConfigDataFilter(arr: ConfigDataModal) {
13
+ let subConfigData: HItemProps = defaultSubItem;
14
+ const realConfigData = arr.filter((item) => {
15
+ const { showSearch, searchType } = item;
16
+ if (searchType === "submit" && showSearch) {
17
+ subConfigData = formConfigDataItemProvider(item);
18
+ return false;
19
+ }
20
+ if (showSearch) {
21
+ return true;
22
+ }
23
+ return false;
24
+ });
25
+
26
+ return {
27
+ realConfigData,
28
+ subConfigData,
29
+ };
30
+ }
31
+
32
+ export function formConfigDataProvider(configData: ConfigDataModal) {
33
+ const { realConfigData, subConfigData } = formConfigDataFilter(configData);
34
+ const nConfigData = realConfigData.map((item) =>
35
+ formConfigDataItemProvider(item)
36
+ );
37
+
38
+ return [...nConfigData, subConfigData];
39
+ }
40
+
41
+ function formConfigDataItemProvider({
42
+ colon = false,
43
+ searchType,
44
+ title,
45
+ name,
46
+ dataIndex,
47
+ itemProps,
48
+ searchRender,
49
+ }: ConfigItemModal): HItemProps {
50
+ return {
51
+ itemProps,
52
+ label: title,
53
+ colon,
54
+ type: searchType,
55
+ name: name || (dataIndex as string),
56
+ render: searchRender,
57
+ };
58
+ }
@@ -0,0 +1,65 @@
1
+ import Header from "./Header";
2
+ import Body from "./Body";
3
+ import { useRequest } from "ahooks";
4
+ import { useMemo } from "react";
5
+ import useCurrentTable from "./hooks/useCurrentTable";
6
+ import Footer from "./Footer";
7
+ import useRowObj from "./hooks/useRowObj";
8
+ import { HTableContext } from "./context";
9
+ import { Space } from "antd";
10
+ import type { HTableProps } from "./modal";
11
+ export default ({
12
+ request,
13
+ configData,
14
+ searchSpan,
15
+ table,
16
+ actionRender,
17
+ ...props
18
+ }: HTableProps) => {
19
+ const saveParams = useMemo(() => {
20
+ return {
21
+ params: {},
22
+ };
23
+ }, []);
24
+ const { run, loading, data, error } = useRequest((params = {}) => {
25
+ const { size = "10", current = "1", ...oParams } = params;
26
+ const reqParams = { size, current, ...oParams };
27
+ saveParams.params = reqParams;
28
+ return request(reqParams);
29
+ });
30
+ const cuTable = useCurrentTable({
31
+ table,
32
+ reload: () => {
33
+ run({ ...saveParams.params });
34
+ },
35
+ });
36
+ const { selectedRowData, rowOnChange } = useRowObj();
37
+ return (
38
+ <HTableContext.Provider
39
+ value={{
40
+ table: cuTable,
41
+ selectedRowData,
42
+ rowOnChange,
43
+ data,
44
+ error,
45
+ }}
46
+ >
47
+ <Space size={20} direction={"vertical"} style={{ width: "100%" }}>
48
+ <Header
49
+ configData={configData}
50
+ onFinish={run}
51
+ searchSpan={searchSpan}
52
+ />
53
+ <Body
54
+ loading={loading}
55
+ configData={configData}
56
+ onPageChange={(page) => {
57
+ run({ ...saveParams.params, ...page });
58
+ }}
59
+ {...props}
60
+ />
61
+ <Footer actionRender={actionRender} />
62
+ </Space>
63
+ </HTableContext.Provider>
64
+ );
65
+ };
@@ -0,0 +1,30 @@
1
+ import React, { useContext } from "react";
2
+ import type { HTableInstance } from "./modal";
3
+
4
+ interface HTableConfigContextModal {
5
+ emptyRender?: (table: HTableInstance) => React.ReactNode;
6
+ errorRender?: (table: HTableInstance) => React.ReactNode;
7
+ }
8
+ export const HTableConfigContext =
9
+ React.createContext<HTableConfigContextModal | null>(null);
10
+
11
+ export const useHTableConfigContext = ({
12
+ emptyRender,
13
+ errorRender,
14
+ }: HTableConfigContextModal) => {
15
+ const { errorRender: configErrorRender, emptyRender: configEmptyRender } =
16
+ useContext(HTableConfigContext) || {};
17
+
18
+ return {
19
+ errorRender: errorRender || configErrorRender,
20
+ emptyRender: emptyRender || configEmptyRender,
21
+ };
22
+ };
23
+ const Index: React.FC<HTableConfigContextModal> = ({ children, ...props }) => {
24
+ return (
25
+ <HTableConfigContext.Provider value={props}>
26
+ {children}
27
+ </HTableConfigContext.Provider>
28
+ );
29
+ };
30
+ export default Index;
@@ -0,0 +1,17 @@
1
+ import React, { useContext } from "react";
2
+ import type { ResultModal, RowObj, HTableInstance } from "./modal";
3
+
4
+ interface HContextModal {
5
+ table: HTableInstance;
6
+ data?: ResultModal;
7
+ selectedRowData: RowObj;
8
+ rowOnChange: (keys: React.Key[], rowData: any[]) => void;
9
+ error?: Error;
10
+ }
11
+
12
+ export const HTableContext = React.createContext<HContextModal | null>(null);
13
+
14
+ export const useHTableContext = () => {
15
+ const result = useContext(HTableContext);
16
+ return (result || {}) as HContextModal;
17
+ };
@@ -0,0 +1,16 @@
1
+ import { useMemo } from "react";
2
+ import type { ParamsModal, HTableInstance } from "../modal";
3
+ import useHTable from "../hooks/useHTable";
4
+
5
+ interface currentTableParams {
6
+ table?: HTableInstance;
7
+ reload: (params: ParamsModal) => void;
8
+ }
9
+ export default ({ table, reload }: currentTableParams) => {
10
+ const useCurrentTable = useHTable();
11
+ return useMemo(() => {
12
+ const resultTable = table || useCurrentTable;
13
+ resultTable.table.reload = reload;
14
+ return resultTable;
15
+ }, [table]);
16
+ };
@@ -0,0 +1,18 @@
1
+ import { useMemo } from "react";
2
+ import type { ParamsModal } from "../modal";
3
+ import { useHForm } from "@hw-component/form";
4
+
5
+ export default () => {
6
+ const form = useHForm();
7
+ const table = useMemo(() => {
8
+ return {
9
+ reload: (params: ParamsModal) => {
10
+ return params;
11
+ },
12
+ };
13
+ }, []);
14
+ return {
15
+ form,
16
+ table,
17
+ };
18
+ };
@@ -0,0 +1,17 @@
1
+ import type React from "react";
2
+ import { useState } from "react";
3
+ import type { RowObj } from "../modal";
4
+
5
+ export default () => {
6
+ const [selectedRowData, setSelectedRowData] = useState<RowObj>({});
7
+ const rowOnChange = (keys: React.Key[], rowData: any[]) => {
8
+ setSelectedRowData({
9
+ keys,
10
+ rowData,
11
+ });
12
+ };
13
+ return {
14
+ rowOnChange,
15
+ selectedRowData,
16
+ };
17
+ };
@@ -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";
@@ -0,0 +1,58 @@
1
+ import type { ProColumns } from "@ant-design/pro-table/lib/typing";
2
+ import type { ProTableProps } from "@ant-design/pro-table";
3
+ import type {
4
+ HItemProps,
5
+ HFormInstance,
6
+ } from "@hw-component/form/es/Form/modal";
7
+ import type { ColProps } from "antd";
8
+ import type React from "react";
9
+
10
+ export interface RowObj {
11
+ keys?: React.Key[];
12
+ rowData?: any[];
13
+ }
14
+ export interface ResultModal {
15
+ records: any[];
16
+ current: string;
17
+ size: string;
18
+ total: string;
19
+ }
20
+ export interface ParamsModal extends Record<string, any> {
21
+ size?: number;
22
+ current?: number;
23
+ }
24
+ interface HColumns extends Omit<ProColumns, "render"> {
25
+ render?: (
26
+ dom: React.ReactNode,
27
+ data: any,
28
+ index: number,
29
+ table: HTableInstance
30
+ ) => React.ReactNode;
31
+ showSearch?: boolean;
32
+ searchType?: HItemProps["type"];
33
+ searchRender?: HItemProps["render"];
34
+ }
35
+ export type ConfigItemModal = Omit<HItemProps, "render" | "type"> & HColumns;
36
+ export type ConfigDataModal = ConfigItemModal[];
37
+ export type ActionRenderFn = (
38
+ allCheck: boolean,
39
+ selectedRowKeys: RowObj,
40
+ xjTable: HTableInstance
41
+ ) => React.ReactNode;
42
+
43
+ export interface HTableProps extends Omit<ProTableProps<any, any>, "request"> {
44
+ request: (params: ParamsModal) => Promise<ResultModal>;
45
+ configData: ConfigDataModal;
46
+ searchSpan?: ColProps;
47
+ table?: HTableInstance;
48
+ actionRender?: ActionRenderFn;
49
+ emptyRender?: (table: HTableInstance) => React.ReactNode;
50
+ errorRender?: (table: HTableInstance) => React.ReactNode;
51
+ }
52
+ export interface TableInstance {
53
+ reload: (params: ParamsModal) => void;
54
+ }
55
+ export interface HTableInstance {
56
+ form: HFormInstance;
57
+ table: TableInstance;
58
+ }
package/src/index.less ADDED
@@ -0,0 +1,20 @@
1
+ .layout {
2
+ position: fixed;
3
+ top: 0;
4
+ right: 0;
5
+ bottom: 0;
6
+ left: 0;
7
+ display: flex;
8
+ }
9
+ .menu {
10
+ width: 256px !important;
11
+ height: 100vh;
12
+ }
13
+
14
+ .body {
15
+ width: calc(100vw - 256px);
16
+ height: 100vh;
17
+ padding: 16px;
18
+ overflow: hidden;
19
+ background-color: #ccc;
20
+ }
package/src/index.tsx ADDED
@@ -0,0 +1,12 @@
1
+ import { render } from "react-dom";
2
+ import App from "./app";
3
+ import React from "react";
4
+ import "antd/dist/antd.css";
5
+ import zhCN from "antd/es/locale/zh_CN";
6
+ import { ConfigProvider } from "antd";
7
+ render(
8
+ <ConfigProvider locale={zhCN}>
9
+ <App />
10
+ </ConfigProvider>,
11
+ document.getElementById("root")
12
+ );
@@ -0,0 +1,55 @@
1
+ import { HTable, HTableConfig } from "../../components";
2
+ import { Button } from "antd";
3
+ const configData = [
4
+ {
5
+ title: "座位",
6
+ showSearch: true,
7
+ searchType: "select",
8
+ dataIndex: "name",
9
+ },
10
+ {
11
+ title: "操作",
12
+ name: "aaa",
13
+ showSearch: true,
14
+ searchType: "rangePicker",
15
+ },
16
+ ];
17
+ export default () => {
18
+ return (
19
+ <HTableConfig
20
+ emptyRender={() => {
21
+ return <div>红</div>;
22
+ }}
23
+ >
24
+ <HTable
25
+ configData={configData}
26
+ rowKey={"id"}
27
+ emptyRender={() => {
28
+ return <div>无数据</div>;
29
+ }}
30
+ actionRender={(allCheck, selectedRowKeys, xjTable) => {
31
+ console.log(allCheck, selectedRowKeys, xjTable);
32
+ return <Button>点我</Button>;
33
+ }}
34
+ request={(a) => {
35
+ console.log("aaa", a);
36
+
37
+ return new Promise((resolve) => {
38
+ setTimeout(() => {
39
+ resolve({
40
+ records: [
41
+ { name: "ddd", id: 1 },
42
+ { name: "ddd", id: 2 },
43
+ { name: "ddd", id: 3 },
44
+ ],
45
+ size: "10",
46
+ current: "1",
47
+ total: "1000",
48
+ });
49
+ }, 2000);
50
+ });
51
+ }}
52
+ />
53
+ </HTableConfig>
54
+ );
55
+ };
package/src/routes.tsx ADDED
@@ -0,0 +1,26 @@
1
+ import React from "react";
2
+ import { Navigate } from "react-router-dom";
3
+ import Select from "./pages/Test";
4
+
5
+ export interface RouteModal {
6
+ path?: string;
7
+ name?: string;
8
+ children?: RouteModal[];
9
+ element?: JSX.Element;
10
+ index?: boolean;
11
+ errorElement?: JSX.Element;
12
+ }
13
+
14
+ const routes: RouteModal[] = [
15
+ {
16
+ index: true,
17
+ element: <Navigate to="/select" replace={true} />,
18
+ },
19
+ {
20
+ path: "/select",
21
+ name: "下拉框",
22
+ element: <Select />,
23
+ },
24
+ ];
25
+
26
+ export default routes;
package/tsconfig.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "compilerOptions": {
3
+ "allowUnreachableCode": true,
4
+ "allowUnusedLabels": false,
5
+ "alwaysStrict": false,
6
+ "baseUrl": ".",
7
+ "experimentalDecorators": true,
8
+ "jsx": "react-jsx",
9
+ "sourceMap": true,
10
+ "module": "ESNext",
11
+ "noImplicitAny": false,
12
+ "removeComments": true,
13
+ "allowSyntheticDefaultImports": true,
14
+ "moduleResolution": "Node",
15
+ "strict": true,
16
+ "types": ["node"],
17
+ "target": "ESNext",
18
+ "outDir": "./build",
19
+ "declaration": true,
20
+ "allowJs": true,
21
+ "lib": ["es5", "es2015", "es2016", "es2017", "es2018", "dom"],
22
+ "typeRoots": ["./node_modules/@types/", "./src/typings.d.ts"],
23
+ "paths": {
24
+ "@/*": ["./src/*"]
25
+ }
26
+ },
27
+ "include": ["src/**/*"],
28
+ "exclude": ["node_modules", "**/*.spec.ts", "**/*.css", "**/*.less"]
29
+ }