@hw-component/table 1.10.13 → 1.10.16

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hw-component/table",
3
- "version": "1.10.13",
3
+ "version": "1.10.16",
4
4
  "description": "基于antd二次开发table组件",
5
5
  "keywords": [
6
6
  "table"
@@ -1,6 +1,6 @@
1
- import Table from "@/components/Table";
1
+ import Table from "../Table";
2
2
  import type { ModalTableProps } from "../modal";
3
- import { HEditTable } from "@/components";
3
+ import EditTable from "../EditTable";
4
4
  import { ProColumns } from "@ant-design/pro-table/lib/typing";
5
5
 
6
6
  export const TableContent = ({
@@ -32,7 +32,7 @@ export const EditTableContent = ({
32
32
  dataSource,
33
33
  }: ModalTableProps<ProColumns[]>) => {
34
34
  const node = (
35
- <HEditTable
35
+ <EditTable
36
36
  {...editTableProps}
37
37
  configData={configData || []}
38
38
  request={request}
@@ -1,12 +1,22 @@
1
1
  import { useRequest } from "ahooks";
2
2
  import { HEditTableProps } from "./modal";
3
- import {MutableRefObject, useEffect, useMemo, useRef} from "react";
3
+ import {MutableRefObject, useEffect, useMemo, useRef, useState} from "react";
4
4
  import type { ActionType } from "@ant-design/pro-table";
5
5
  import { EditableFormInstance } from "@ant-design/pro-table/lib/components/EditableTable";
6
6
  import config from "../render/config";
7
+ import {ResultModal} from "../modal";
7
8
 
8
- export const useListRequest = ({ request, dataSource ,manual}: HEditTableProps) => {
9
- const relManual=request?manual:false;
9
+ export const useListRequest = ({
10
+ request,
11
+ dataSource,
12
+ manual,
13
+ }: HEditTableProps) => {
14
+ const [tableDataSource,setTableDataSource]=useState<ResultModal>({
15
+ records:[],
16
+ total:"0",
17
+ size:"10",
18
+ current:"1"
19
+ });
10
20
  const saveParams = useMemo(() => {
11
21
  return {
12
22
  params: {
@@ -15,7 +25,7 @@ export const useListRequest = ({ request, dataSource ,manual}: HEditTableProps)
15
25
  },
16
26
  };
17
27
  }, []);
18
- return useRequest(
28
+ const {loading,error,run}=useRequest(
19
29
  async (params = {}) => {
20
30
  const newParams = {
21
31
  ...saveParams.params,
@@ -23,15 +33,32 @@ export const useListRequest = ({ request, dataSource ,manual}: HEditTableProps)
23
33
  };
24
34
  saveParams.params = newParams;
25
35
  if (request) {
26
- return request(newParams);
36
+ const result=await request(newParams);
37
+ setTableDataSource(result);
38
+ return ;
27
39
  }
28
40
  if (Array.isArray(dataSource)) {
29
- return dataSource;
41
+ setTableDataSource({
42
+ ...tableDataSource,
43
+ records:dataSource,
44
+ })
45
+ return ;
30
46
  }
31
- return dataSource;
47
+ return setTableDataSource(dataSource||tableDataSource);
32
48
  },
33
- { manual: relManual,refreshDeps:[dataSource]}
49
+ { manual:true}
34
50
  );
51
+ useEffect(() => {
52
+ if (!manual){
53
+ run();
54
+ }
55
+ }, [dataSource]);
56
+ return {
57
+ loading,
58
+ error,
59
+ run,
60
+ data:tableDataSource
61
+ }
35
62
  };
36
63
 
37
64
  export const useCuRef = ({ actionRef, editableFormRef }: HEditTableProps) => {
@@ -46,23 +73,34 @@ export const useCuRef = ({ actionRef, editableFormRef }: HEditTableProps) => {
46
73
  cuEditableFormRef,
47
74
  };
48
75
  };
76
+ interface ColProps extends HEditTableProps{
77
+ reload:VoidFunction;
78
+ }
49
79
 
50
- export const useColsMk = ({ configData }: HEditTableProps) => {
80
+ export const useColsMk = ({ configData,reload }: ColProps) => {
51
81
  return configData?.map((item) => {
52
82
  const { valueType, render } = item;
53
83
  const configType = valueType as string;
54
- if (!config[configType]) {
55
- return item;
84
+ if (config[configType]) {
85
+ return {
86
+ ...item,
87
+ render: (dom, entity, index, action, schema) => {
88
+ const node = config[configType](item, entity, index);
89
+ if (render) {
90
+ return render(node, entity, index, {...action,reload}, schema);
91
+ }
92
+ return node;
93
+ },
94
+ };
56
95
  }
57
- return {
58
- ...item,
59
- render: (dom, entity, index, action, schema) => {
60
- const node = config[configType](item, entity, index);
61
- if (render) {
62
- return render(node, entity, index, action, schema);
63
- }
64
- return node;
65
- },
66
- };
96
+ if (render){
97
+ return {
98
+ ...item,
99
+ render: (dom, entity, index, action, schema) => {
100
+ return render(dom, entity, index, {...action,reload}, schema);
101
+ },
102
+ };
103
+ }
104
+ return item;
67
105
  });
68
106
  };
@@ -41,20 +41,18 @@ export default ({
41
41
  errorRender: tableErrorRender = errorDefaultRender,
42
42
  } = useHTableConfigContext({ emptyRender, errorRender });
43
43
 
44
- const isLocalData = Array.isArray(data);
45
- const values = isLocalData ? data : data?.records;
46
44
  const { cuActionRef, cuEditableFormRef } = useCuRef({
47
45
  actionRef,
48
46
  editableFormRef,
49
47
  });
50
- const columns = useColsMk({ configData });
48
+ const columns = useColsMk({ configData,reload:run});
51
49
  return (
52
50
  <div className={tableBody}>
53
51
  <ConfigProvider
54
52
  renderEmpty={() => {
55
53
  if (error) {
56
54
  return tableErrorRender?.({
57
- reload: cuActionRef.current.reload,
55
+ reload: run,
58
56
  error,
59
57
  });
60
58
  }
@@ -66,10 +64,8 @@ export default ({
66
64
  loading={loading}
67
65
  rowKey={rowKey}
68
66
  editableFormRef={cuEditableFormRef}
69
- manualRequest={true}
70
- request={run}
71
67
  actionRef={cuActionRef}
72
- value={values}
68
+ value={data?.records}
73
69
  recordCreatorProps={{
74
70
  position: "bottom",
75
71
  record: () => ({ id: "add", ...defaultRecordValue }),
@@ -89,7 +85,7 @@ export default ({
89
85
  if (key === "add") {
90
86
  await onAdd?.(oRow);
91
87
  cuEditableFormRef.current?.resetFields(["add"]);
92
- cuActionRef.current?.reload();
88
+ run();
93
89
  return;
94
90
  }
95
91
  await onEdit?.({
@@ -97,23 +93,23 @@ export default ({
97
93
  ...oRow,
98
94
  });
99
95
  cuEditableFormRef.current?.resetFields([key]);
100
- cuActionRef.current?.reload();
96
+ run();
101
97
  },
102
98
  ...editable,
103
99
  }}
104
100
  {...props}
105
101
  />
106
102
  </ConfigProvider>
107
- <HTablePagination
108
- data={isLocalData ? null : data}
109
- {...pagination}
110
- onChange={(page, pageSize) => {
111
- run({
112
- size: pageSize,
113
- current: page,
114
- });
115
- }}
116
- />
103
+ {pagination===false?null:<HTablePagination
104
+ data={data}
105
+ {...pagination}
106
+ onChange={(page, pageSize) => {
107
+ run({
108
+ size: pageSize,
109
+ current: page,
110
+ });
111
+ }}
112
+ />}
117
113
  </div>
118
114
  );
119
115
  };
@@ -16,7 +16,7 @@ export interface HEditTableProps<T = any>
16
16
  >;
17
17
  dataSource?: any[];
18
18
  request?: (params: Record<string, any>) => Promise<T>;
19
- pagination?: IPaginationProps;
19
+ pagination?: IPaginationProps|false;
20
20
  manual?: boolean;
21
21
  emptyRender?: EmptyPageRender;
22
22
  errorRender?: ErrorPageRender;
@@ -7,60 +7,64 @@ const dataSource = [
7
7
  id: 1,
8
8
  title: "1",
9
9
  time: "1757574280",
10
- }
10
+ },
11
11
  ];
12
12
  export default () => {
13
13
  const defaultActionRef = useRef<ActionType>();
14
14
  const [cuData, setCuData] = useState(dataSource);
15
- console.log(defaultActionRef,"defaultActionRef")
15
+ console.log(defaultActionRef, "defaultActionRef");
16
16
  return (
17
17
  <div>
18
- <div onClick={()=>{
19
- defaultActionRef.current?.reload();
20
- }}>刷新</div>
21
- <HEditTable
22
- actionRef={defaultActionRef}
23
- manual
24
- onAdd={async (data) => {
25
- const newData = [...cuData];
26
- newData.push({
27
- id:new Date().valueOf(),
28
- ...data
29
- });
30
- setCuData(newData);
31
- }}
32
- onEdit={async (data) => {}}
33
- request={()=>{
34
- console.log("rrrrr")
35
- return {
36
- records:[{
37
- id: 1,
38
- title: "1",
39
- time: "1757574280",
40
- }]
41
- }
42
- }}
43
- configData={[
44
- { title: "标题", dataIndex: "title" },
45
- { title: "标题2", dataIndex: "time", valueType: "date" },
46
- {
47
- title: "操作",
48
- valueType: "option",
49
- align: "center",
50
- render: (text: any, record: any, index: any, action: any) => [
51
- <a
52
- key="editable"
53
- type={"link"}
54
- onClick={() => {
55
- action?.startEditable?.(record.id);
56
- }}
57
- >
58
- 编辑
59
- </a>
60
- ],
61
- },
62
- ]}
63
- />
18
+ <div
19
+ onClick={() => {
20
+
21
+ }}
22
+ >
23
+ 刷新
24
+ </div>
25
+ <HEditTable
26
+ manual
27
+ onAdd={async (data) => {
28
+ const newData = [...cuData];
29
+ newData.push({
30
+ id: new Date().valueOf(),
31
+ ...data,
32
+ });
33
+ setCuData(newData);
34
+ }}
35
+ onEdit={async (data) => {}}
36
+ request={() => {
37
+ return {
38
+ records: [
39
+ {
40
+ id: 1,
41
+ title: "1",
42
+ time: "1757574280",
43
+ },
44
+ ],
45
+ };
46
+ }}
47
+ configData={[
48
+ { title: "标题", dataIndex: "title" },
49
+ { title: "标题2", dataIndex: "time", valueType: "date" },
50
+ {
51
+ title: "操作",
52
+ valueType: "option",
53
+ align: "center",
54
+ render: (text: any, record: any, index: any, action: any) => [
55
+ <a
56
+ key="editable"
57
+ type={"link"}
58
+ onClick={() => {
59
+ action?.startEditable?.(record.id);
60
+ }}
61
+ >
62
+ 编辑
63
+ </a>,
64
+ ],
65
+ },
66
+ ]}
67
+ />
64
68
  </div>
65
69
  );
66
70
  };
@@ -40,25 +40,26 @@ export default () => {
40
40
  </div>
41
41
  <HDwEditTable
42
42
  title="编辑"
43
- request={async () => {
44
- return {
45
- records: [
46
- {
47
- id: "213213",
48
- title: "100",
49
- },
50
- ],
51
- current: "1",
52
- size: "10",
53
- total: "10",
54
- };
43
+ request={() => {
44
+ return new Promise(resolve => {
45
+ setTimeout(() => {
46
+ resolve( {
47
+ records: [
48
+ {
49
+ id: "213213",
50
+ title: "100",
51
+ },
52
+ ],
53
+ current: "1",
54
+ size: "10",
55
+ total: "10",
56
+ })
57
+ },2000)
58
+ })
55
59
  }}
56
60
  editTableProps={{
57
61
  onAdd: async (data) => {},
58
62
  onEdit: async (data) => {},
59
- defaultRecordValue: {
60
- title: "21312",
61
- },
62
63
  }}
63
64
  dialogTable={dialogTable}
64
65
  configData={[
@@ -68,17 +69,28 @@ export default () => {
68
69
  title: "操作",
69
70
  valueType: "option",
70
71
  align: "center",
71
- render: (text: any, record: any, _: any, action: any) => [
72
- <a
73
- key="editable"
74
- type={"link"}
75
- onClick={() => {
76
- action?.startEditable?.(record.id);
77
- }}
78
- >
79
- 编辑
80
- </a>,
81
- ],
72
+ render: (text: any, record: any, _: any, action: any) =>{
73
+ return <>
74
+ <a
75
+ key="editable"
76
+ type={"link"}
77
+ onClick={() => {
78
+ action?.startEditable?.(record.id);
79
+ }}
80
+ >
81
+ 编辑
82
+ </a>
83
+ <a
84
+ key="editable"
85
+ type={"link"}
86
+ onClick={() => {
87
+ action.reload()
88
+ }}
89
+ >
90
+ 刷新
91
+ </a>
92
+ </>
93
+ }
82
94
  },
83
95
  ]}
84
96
  />