@hw-component/table 1.9.39 → 1.9.40

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.
@@ -1,7 +1,7 @@
1
1
  import type { ProTableProps } from "@ant-design/pro-table";
2
2
  import type { ActionRenderFn, ConfigDataModal, ParamsModal, HTableInstance, HRowSelection } from "../modal";
3
3
  import React from "react";
4
- import { IPaginationProps } from "../HTablePagination";
4
+ import type { IPaginationProps } from "../HTablePagination";
5
5
  import type { AffixProps } from "antd/lib/affix";
6
6
  import type { OptionConfig } from "@ant-design/pro-table/lib/components/ToolBar";
7
7
  export interface OptionModal extends OptionConfig {
@@ -1,4 +1,4 @@
1
- import { HFormInstance, HItemProps } from "@hw-component/form/es/Form/modal";
1
+ import type { HFormInstance, HItemProps } from "@hw-component/form/es/Form/modal";
2
2
  import React from "react";
3
3
  export declare const sizeObj: {
4
4
  xl: {
@@ -1,5 +1,5 @@
1
1
  import type { IHeaderProps } from "../modal";
2
- declare const _default: ({ configData, loading, onFinish, hideLabel, labelWidth, table }: IHeaderProps) => {
2
+ declare const _default: ({ configData, loading, onFinish, hideLabel, labelWidth, table, }: IHeaderProps) => {
3
3
  tableInstance: import("../../modal").HTableInstance;
4
4
  tableLabelWidth: number | undefined;
5
5
  tableHideLabel: boolean | undefined;
@@ -1,4 +1,4 @@
1
- import { IHeaderProps } from "../modal";
2
- import { HItemProps } from "@hw-component/form/es/Form/modal";
3
- declare const _default: ({ searchSpan, configData, table, }: IHeaderProps) => HItemProps[];
1
+ import type { IHeaderProps } from "../modal";
2
+ import type { HItemProps } from "@hw-component/form/es/Form/modal";
3
+ declare const _default: ({ searchSpan, configData, table }: IHeaderProps) => HItemProps[];
4
4
  export default _default;
@@ -22,7 +22,10 @@ var useCurrentTable = (function (_ref) {
22
22
  resultTable.table.getSelectedRowData = function () {
23
23
  return selectedRowData;
24
24
  };
25
- resultTable.table.getTableSourceData = function () {
25
+ resultTable.table.getTableSourceData = function (full) {
26
+ if (full) {
27
+ return dataSource;
28
+ }
26
29
  return dataSource === null || dataSource === void 0 ? void 0 : dataSource.records;
27
30
  };
28
31
  return resultTable;
package/es/modal.d.ts CHANGED
@@ -93,7 +93,7 @@ export interface TableInstance {
93
93
  reloadWithParams: (params?: ParamsModal) => Promise<any>;
94
94
  getParams: () => any;
95
95
  getSelectedRowData: () => RowObj;
96
- getTableSourceData: () => any;
96
+ getTableSourceData: (full?: boolean) => any;
97
97
  getColSettingKeys: () => ColCheckResultKeys;
98
98
  }
99
99
  export interface HTableInstance {
@@ -1,2 +1,3 @@
1
+ /// <reference types="react" />
1
2
  declare const _default: () => JSX.Element;
2
3
  export default _default;
@@ -1,7 +1,7 @@
1
1
  import type { ProTableProps } from "@ant-design/pro-table";
2
2
  import type { ActionRenderFn, ConfigDataModal, ParamsModal, HTableInstance, HRowSelection } from "../modal";
3
3
  import React from "react";
4
- import { IPaginationProps } from "../HTablePagination";
4
+ import type { IPaginationProps } from "../HTablePagination";
5
5
  import type { AffixProps } from "antd/lib/affix";
6
6
  import type { OptionConfig } from "@ant-design/pro-table/lib/components/ToolBar";
7
7
  export interface OptionModal extends OptionConfig {
@@ -1,4 +1,4 @@
1
- import { HFormInstance, HItemProps } from "@hw-component/form/es/Form/modal";
1
+ import type { HFormInstance, HItemProps } from "@hw-component/form/es/Form/modal";
2
2
  import React from "react";
3
3
  export declare const sizeObj: {
4
4
  xl: {
@@ -1,5 +1,5 @@
1
1
  import type { IHeaderProps } from "../modal";
2
- declare const _default: ({ configData, loading, onFinish, hideLabel, labelWidth, table }: IHeaderProps) => {
2
+ declare const _default: ({ configData, loading, onFinish, hideLabel, labelWidth, table, }: IHeaderProps) => {
3
3
  tableInstance: import("../../modal").HTableInstance;
4
4
  tableLabelWidth: number | undefined;
5
5
  tableHideLabel: boolean | undefined;
@@ -1,4 +1,4 @@
1
- import { IHeaderProps } from "../modal";
2
- import { HItemProps } from "@hw-component/form/es/Form/modal";
3
- declare const _default: ({ searchSpan, configData, table, }: IHeaderProps) => HItemProps[];
1
+ import type { IHeaderProps } from "../modal";
2
+ import type { HItemProps } from "@hw-component/form/es/Form/modal";
3
+ declare const _default: ({ searchSpan, configData, table }: IHeaderProps) => HItemProps[];
4
4
  export default _default;
@@ -25,7 +25,10 @@ var useCurrentTable = (function (_ref) {
25
25
  resultTable.table.getSelectedRowData = function () {
26
26
  return selectedRowData;
27
27
  };
28
- resultTable.table.getTableSourceData = function () {
28
+ resultTable.table.getTableSourceData = function (full) {
29
+ if (full) {
30
+ return dataSource;
31
+ }
29
32
  return dataSource === null || dataSource === void 0 ? void 0 : dataSource.records;
30
33
  };
31
34
  return resultTable;
package/lib/modal.d.ts CHANGED
@@ -93,7 +93,7 @@ export interface TableInstance {
93
93
  reloadWithParams: (params?: ParamsModal) => Promise<any>;
94
94
  getParams: () => any;
95
95
  getSelectedRowData: () => RowObj;
96
- getTableSourceData: () => any;
96
+ getTableSourceData: (full?: boolean) => any;
97
97
  getColSettingKeys: () => ColCheckResultKeys;
98
98
  }
99
99
  export interface HTableInstance {
@@ -1,2 +1,3 @@
1
+ /// <reference types="react" />
1
2
  declare const _default: () => JSX.Element;
2
3
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hw-component/table",
3
- "version": "1.9.39",
3
+ "version": "1.9.40",
4
4
  "description": "基于antd二次开发table组件",
5
5
  "keywords": [
6
6
  "table"
@@ -35,16 +35,16 @@ export const useTableProps = ({
35
35
  request,
36
36
  dataSource,
37
37
  });
38
- useEffect(()=>{
39
- if (configData){
40
- setModalTableParams((oldVal)=>{
41
- return {
42
- ...oldVal,
43
- configData
44
- }
45
- })
46
- }
47
- },[configData])
38
+ useEffect(() => {
39
+ if (configData) {
40
+ setModalTableParams((oldVal) => {
41
+ return {
42
+ ...oldVal,
43
+ configData,
44
+ };
45
+ });
46
+ }
47
+ }, [configData]);
48
48
  return {
49
49
  modalTableParams,
50
50
  setModalTableParams,
@@ -17,7 +17,8 @@ import { useHTableContext } from "../context";
17
17
  import React from "react";
18
18
  import { ConfigProvider, Empty, Alert, Space } from "antd";
19
19
  import { useHTableConfigContext } from "../TableConfig";
20
- import HTablePagination, {IPaginationProps} from "../HTablePagination";
20
+ import type { IPaginationProps } from "../HTablePagination";
21
+ import HTablePagination from "../HTablePagination";
21
22
  import { useClassName } from "../hooks";
22
23
  import AlertMsg from "./AlertMsg";
23
24
  import type { AffixProps } from "antd/lib/affix";
@@ -31,7 +32,7 @@ export interface OptionModal extends OptionConfig {
31
32
  export interface HTableBodyProps
32
33
  extends Omit<
33
34
  ProTableProps<any, any>,
34
- "dataSource" | "rowSelection" | "options"|"pagination"
35
+ "dataSource" | "rowSelection" | "options" | "pagination"
35
36
  > {
36
37
  configData?: ConfigDataModal;
37
38
  onPageChange?: (params: ParamsModal) => void;
@@ -51,7 +52,7 @@ export interface HTableBodyProps
51
52
  localSorter?: boolean;
52
53
  options?: OptionModal | false;
53
54
  table?: HTableInstance;
54
- pagination?:IPaginationProps|false;
55
+ pagination?: IPaginationProps | false;
55
56
  }
56
57
  const defaultRender = () => {
57
58
  return <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />;
@@ -1,42 +1,42 @@
1
- import {HFormInstance, HItemProps} from "@hw-component/form/es/Form/modal";
1
+ import type { HFormInstance, HItemProps } from "@hw-component/form/es/Form/modal";
2
2
  import React from "react";
3
- import {DefaultSubComponent} from "../defaultSubComponent";
3
+ import { DefaultSubComponent } from "../defaultSubComponent";
4
4
 
5
5
  export const sizeObj = {
6
- xl: {
7
- min: 1200,
8
- max: 1600,
9
- },
10
- xxl: {
11
- min: 1600,
12
- },
13
- lg: {
14
- min: 992,
15
- max: 1200,
16
- },
17
- md: {
18
- min: 768,
19
- max: 992,
20
- },
21
- sm: {
22
- min: 576,
23
- max: 768,
24
- },
25
- xs: {
26
- max: 576,
27
- },
6
+ xl: {
7
+ min: 1200,
8
+ max: 1600,
9
+ },
10
+ xxl: {
11
+ min: 1600,
12
+ },
13
+ lg: {
14
+ min: 992,
15
+ max: 1200,
16
+ },
17
+ md: {
18
+ min: 768,
19
+ max: 992,
20
+ },
21
+ sm: {
22
+ min: 576,
23
+ max: 768,
24
+ },
25
+ xs: {
26
+ max: 576,
27
+ },
28
28
  };
29
29
 
30
30
  export const defaultSubItem = {
31
- type: "submit",
32
- itemProps: {
33
- position: "end",
34
- },
35
- style: {
36
- padding: 0,
37
- marginLeft: -20,
38
- },
39
- render: (item: HItemProps, node: React.ReactNode, form: HFormInstance) => {
40
- return <DefaultSubComponent form={form} />;
41
- },
31
+ type: "submit",
32
+ itemProps: {
33
+ position: "end",
34
+ },
35
+ style: {
36
+ padding: 0,
37
+ marginLeft: -20,
38
+ },
39
+ render: (item: HItemProps, node: React.ReactNode, form: HFormInstance) => {
40
+ return <DefaultSubComponent form={form} />;
41
+ },
42
42
  };
@@ -2,28 +2,36 @@ import type { IHeaderProps } from "../modal";
2
2
  import { useHTableContext } from "../../context";
3
3
  import useHTable from "../../hooks/useHTable";
4
4
 
5
- export default ({configData,loading,onFinish,hideLabel,labelWidth,table}:IHeaderProps)=>{
6
- const {
7
- tableInstance: contextTableInstance,
8
- loading: contextLoading,
9
- onFinish: contextOnFinish,
10
- configData: contextConfigData,
11
- hideLabel: contextHideLabel,
12
- labelWidth: contextLabelWidth,
13
- } = useHTableContext();
14
- const defaultTable=useHTable();
15
- const headerConfigData = configData || contextConfigData;
16
- const submitLoading=contextLoading || loading;
17
- const subOnFinish = onFinish || contextOnFinish;
18
- const tableHideLabel = typeof hideLabel === "undefined" ? contextHideLabel : hideLabel;
19
- const tableLabelWidth = labelWidth || contextLabelWidth;
20
- const tableInstance = table || contextTableInstance;
21
- return {
22
- tableInstance:tableInstance||defaultTable,
23
- tableLabelWidth,
24
- tableHideLabel,
25
- subOnFinish,
26
- submitLoading,
27
- headerConfigData
28
- }
29
- }
5
+ export default ({
6
+ configData,
7
+ loading,
8
+ onFinish,
9
+ hideLabel,
10
+ labelWidth,
11
+ table,
12
+ }: IHeaderProps) => {
13
+ const {
14
+ tableInstance: contextTableInstance,
15
+ loading: contextLoading,
16
+ onFinish: contextOnFinish,
17
+ configData: contextConfigData,
18
+ hideLabel: contextHideLabel,
19
+ labelWidth: contextLabelWidth,
20
+ } = useHTableContext();
21
+ const defaultTable = useHTable();
22
+ const headerConfigData = configData || contextConfigData;
23
+ const submitLoading = contextLoading || loading;
24
+ const subOnFinish = onFinish || contextOnFinish;
25
+ const tableHideLabel =
26
+ typeof hideLabel === "undefined" ? contextHideLabel : hideLabel;
27
+ const tableLabelWidth = labelWidth || contextLabelWidth;
28
+ const tableInstance = table || contextTableInstance;
29
+ return {
30
+ tableInstance: tableInstance || defaultTable,
31
+ tableLabelWidth,
32
+ tableHideLabel,
33
+ subOnFinish,
34
+ submitLoading,
35
+ headerConfigData,
36
+ };
37
+ };
@@ -1,174 +1,168 @@
1
- import {FormConfigDataItemProviderModal, IHeaderProps} from "../modal";
2
- import {useEffect, useState} from "react";
3
- import {HItemProps} from "@hw-component/form/es/Form/modal";
4
- import {defaultSubItem, sizeObj} from "./config";
5
- import {useHTableContext} from "../../context";
6
- import {useClassName} from "../../hooks";
7
- import {HTableInstance} from "../../modal";
8
- import {ColProps} from "antd";
9
- import {renderData} from "../defaultFormRender";
1
+ import type { FormConfigDataItemProviderModal, IHeaderProps } from "../modal";
2
+ import { useEffect, useState } from "react";
3
+ import type { HItemProps } from "@hw-component/form/es/Form/modal";
4
+ import { defaultSubItem, sizeObj } from "./config";
5
+ import { useHTableContext } from "../../context";
6
+ import { useClassName } from "../../hooks";
7
+ import type { HTableInstance } from "../../modal";
8
+ import type { ColProps } from "antd";
9
+ import { renderData } from "../defaultFormRender";
10
10
 
11
11
  const formConfigDataItemProvider = (
12
- {
13
- searchType,
14
- title,
15
- name,
16
- dataIndex,
17
- itemProps = {},
18
- searchRender,
19
- childrenDataIndex,
20
- showSearch,
21
- hideInTable,
22
- align,
23
- searchLabel,
24
- titleStr,
25
- ...props
26
- }: FormConfigDataItemProviderModal,
27
- table: HTableInstance
12
+ {
13
+ searchType,
14
+ title,
15
+ name,
16
+ dataIndex,
17
+ itemProps = {},
18
+ searchRender,
19
+ childrenDataIndex,
20
+ showSearch,
21
+ hideInTable,
22
+ align,
23
+ searchLabel,
24
+ titleStr,
25
+ ...props
26
+ }: FormConfigDataItemProviderModal,
27
+ table: HTableInstance
28
28
  ): HItemProps => {
29
- const { allowClear = true } = itemProps as any;
29
+ const { allowClear = true } = itemProps as any;
30
30
 
31
- return {
32
- ...props,
33
- itemProps: {
34
- ...itemProps,
35
- allowClear,
36
- },
37
- label: searchLabel || titleStr || title,
38
- type: searchType,
39
- name: name || (dataIndex as string),
40
- render: (item, node, form) => {
41
- if (searchRender) {
42
- return searchRender(item, node, form, table);
43
- }
44
- const defaultRender = renderData[searchType || ""];
31
+ return {
32
+ ...props,
33
+ itemProps: {
34
+ ...itemProps,
35
+ allowClear,
36
+ },
37
+ label: searchLabel || titleStr || title,
38
+ type: searchType,
39
+ name: name || (dataIndex as string),
40
+ render: (item, node, form) => {
41
+ if (searchRender) {
42
+ return searchRender(item, node, form, table);
43
+ }
44
+ const defaultRender = renderData[searchType || ""];
45
45
 
46
- return defaultRender ? defaultRender(item) : node;
47
- },
48
- };
46
+ return defaultRender ? defaultRender(item) : node;
47
+ },
48
+ };
49
49
  };
50
50
 
51
51
  const getCuSpanMaxNum = (searchSpan: ColProps = { span: 6 }) => {
52
- const clientWidth = document.documentElement.clientWidth;
53
- const keys = Object.keys(sizeObj);
54
- const index = keys.findIndex((value) => {
55
- const { min = 0, max = Number.MAX_VALUE } = sizeObj[value];
56
- return clientWidth >= min && clientWidth < max;
57
- });
58
- const cuKey = keys[index];
59
- const cuSpan = searchSpan[cuKey] || searchSpan.span;
60
- return 24 / cuSpan;
52
+ const clientWidth = document.documentElement.clientWidth;
53
+ const keys = Object.keys(sizeObj);
54
+ const index = keys.findIndex((value) => {
55
+ const { min = 0, max = Number.MAX_VALUE } = sizeObj[value];
56
+ return clientWidth >= min && clientWidth < max;
57
+ });
58
+ const cuKey = keys[index];
59
+ const cuSpan = searchSpan[cuKey] || searchSpan.span;
60
+ return 24 / cuSpan;
61
61
  };
62
62
 
63
-
64
63
  const mkNewConfig = ({ configData = [], table }: IHeaderProps) => {
65
- let subConfigData: HItemProps | undefined;
66
- const realConfigData: HItemProps[] = [];
67
- configData.forEach((value) => {
68
- const { searchType, showSearch } = value;
69
- if (!showSearch) {
70
- return false;
71
- }
72
- if (searchType === "submit") {
73
- subConfigData = formConfigDataItemProvider(
74
- value,
75
- table as HTableInstance
76
- );
77
- return false;
78
- }
79
- realConfigData.push(
80
- formConfigDataItemProvider(value, table as HTableInstance)
81
- );
82
- });
83
- return {
84
- realConfigData,
85
- subConfigData,
86
- };
64
+ let subConfigData: HItemProps | undefined;
65
+ const realConfigData: HItemProps[] = [];
66
+ configData.forEach((value) => {
67
+ const { searchType, showSearch } = value;
68
+ if (!showSearch) {
69
+ return false;
70
+ }
71
+ if (searchType === "submit") {
72
+ subConfigData = formConfigDataItemProvider(
73
+ value,
74
+ table as HTableInstance
75
+ );
76
+ return false;
77
+ }
78
+ realConfigData.push(
79
+ formConfigDataItemProvider(value, table as HTableInstance)
80
+ );
81
+ });
82
+ return {
83
+ realConfigData,
84
+ subConfigData,
85
+ };
87
86
  };
88
87
 
89
88
  const filterHideFormItem = (
90
- configData: HItemProps[],
91
- className: string,
92
- searchSpan?: ColProps
89
+ configData: HItemProps[],
90
+ className: string,
91
+ searchSpan?: ColProps
93
92
  ) => {
94
- const maxNum = getCuSpanMaxNum(searchSpan);
95
- const len = configData.length;
96
- const startIndex = maxNum - 1;
97
- if (len <= startIndex) {
98
- return {
99
- lessData: configData,
100
- hideData: [],
101
- };
102
- }
103
- const index = startIndex === 0 ? 1 : startIndex;
104
- const lessData = configData.slice(0, index);
105
- const bigData = configData.slice(index);
106
- const hideData = bigData.map((value) => {
107
- return {
108
- ...value,
109
- className,
110
- };
111
- });
93
+ const maxNum = getCuSpanMaxNum(searchSpan);
94
+ const len = configData.length;
95
+ const startIndex = maxNum - 1;
96
+ if (len <= startIndex) {
112
97
  return {
113
- lessData,
114
- hideData,
98
+ lessData: configData,
99
+ hideData: [],
115
100
  };
101
+ }
102
+ const index = startIndex === 0 ? 1 : startIndex;
103
+ const lessData = configData.slice(0, index);
104
+ const bigData = configData.slice(index);
105
+ const hideData = bigData.map((value) => {
106
+ return {
107
+ ...value,
108
+ className,
109
+ };
110
+ });
111
+ return {
112
+ lessData,
113
+ hideData,
114
+ };
116
115
  };
117
116
 
118
- const useDefaultOpen=()=>{
119
- const [open,setOpen]=useState(false);
120
- const { headerOpen=open, setHeaderOpen=setOpen } = useHTableContext();
121
-
122
- return {
123
- headerOpen,
124
- setHeaderOpen
125
- }
126
- }
127
- export default ({
128
- searchSpan,
129
- configData,
130
- table,
131
- }: IHeaderProps) => {
117
+ const useDefaultOpen = () => {
118
+ const [open, setOpen] = useState(false);
119
+ const { headerOpen = open, setHeaderOpen = setOpen } = useHTableContext();
132
120
 
133
- const [formConfigData, setFormConfigData] = useState<HItemProps[]>([]);
134
- const [subData, setSubData] = useState<HItemProps>(defaultSubItem as any);
121
+ return {
122
+ headerOpen,
123
+ setHeaderOpen,
124
+ };
125
+ };
126
+ export default ({ searchSpan, configData, table }: IHeaderProps) => {
127
+ const [formConfigData, setFormConfigData] = useState<HItemProps[]>([]);
128
+ const [subData, setSubData] = useState<HItemProps>(defaultSubItem as any);
135
129
 
136
- const { headerOpen, setHeaderOpen } = useDefaultOpen();
137
- const className = useClassName("hw-table-header-item-hide");
138
- const mkNewFn = () => {
139
- const { realConfigData, subConfigData } = mkNewConfig({
140
- searchSpan,
141
- configData,
142
- table,
143
- });
144
- const changeClassName = headerOpen ? "" : className;
145
- const { lessData, hideData } = filterHideFormItem(
146
- realConfigData,
147
- changeClassName,
148
- searchSpan
149
- );
150
- if (subConfigData) {
151
- setSubData(subConfigData);
152
- }
153
- setHeaderOpen((oldVal) => {
154
- if (hideData.length === 0) {
155
- return undefined;
156
- }
157
- if (typeof oldVal === "undefined") {
158
- return false;
159
- }
160
- return oldVal;
161
- });
162
- setFormConfigData([...lessData, ...hideData]);
130
+ const { headerOpen, setHeaderOpen } = useDefaultOpen();
131
+ const className = useClassName("hw-table-header-item-hide");
132
+ const mkNewFn = () => {
133
+ const { realConfigData, subConfigData } = mkNewConfig({
134
+ searchSpan,
135
+ configData,
136
+ table,
137
+ });
138
+ const changeClassName = headerOpen ? "" : className;
139
+ const { lessData, hideData } = filterHideFormItem(
140
+ realConfigData,
141
+ changeClassName,
142
+ searchSpan
143
+ );
144
+ if (subConfigData) {
145
+ setSubData(subConfigData);
146
+ }
147
+ setHeaderOpen((oldVal) => {
148
+ if (hideData.length === 0) {
149
+ return undefined;
150
+ }
151
+ if (typeof oldVal === "undefined") {
152
+ return false;
153
+ }
154
+ return oldVal;
155
+ });
156
+ setFormConfigData([...lessData, ...hideData]);
157
+ };
158
+ useEffect(() => {
159
+ mkNewFn();
160
+ }, [configData, searchSpan, headerOpen]);
161
+ useEffect(() => {
162
+ window.addEventListener("resize", mkNewFn);
163
+ return () => {
164
+ window.removeEventListener("resize", mkNewFn);
163
165
  };
164
- useEffect(() => {
165
- mkNewFn();
166
- }, [configData, searchSpan, headerOpen]);
167
- useEffect(() => {
168
- window.addEventListener("resize", mkNewFn);
169
- return () => {
170
- window.removeEventListener("resize", mkNewFn);
171
- };
172
- }, [configData, searchSpan, headerOpen]);
173
- return [...formConfigData, subData];
174
- };
166
+ }, [configData, searchSpan, headerOpen]);
167
+ return [...formConfigData, subData];
168
+ };