@hw-component/table 1.9.79 → 1.9.80

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 (35) hide show
  1. package/.eslintcache +1 -1
  2. package/es/HTableBody/HeaderTitle/index.js +41 -5
  3. package/es/HTableBody/RowCheckBox/Title.d.ts +1 -1
  4. package/es/HTableBody/RowCheckBox/hooks.d.ts +1 -1
  5. package/es/HTableBody/RowRadioBoxSelection.d.ts +3 -3
  6. package/es/HTableBody/hooks/colsMk.d.ts +1 -1
  7. package/es/HTableBody/hooks/useControl.d.ts +1 -1
  8. package/es/index.css +24 -2
  9. package/es/render/Text.d.ts +0 -1
  10. package/lib/HTableBody/HeaderTitle/index.js +40 -4
  11. package/lib/HTableBody/RowCheckBox/Title.d.ts +1 -1
  12. package/lib/HTableBody/RowCheckBox/hooks.d.ts +1 -1
  13. package/lib/HTableBody/RowRadioBoxSelection.d.ts +3 -3
  14. package/lib/HTableBody/hooks/colsMk.d.ts +1 -1
  15. package/lib/HTableBody/hooks/useControl.d.ts +1 -1
  16. package/lib/index.css +24 -2
  17. package/lib/render/Text.d.ts +0 -1
  18. package/package.json +1 -1
  19. package/src/components/HTableBody/HeaderTitle/index.tsx +40 -9
  20. package/src/components/HTableBody/RowCheckBox/RowItem.tsx +40 -41
  21. package/src/components/HTableBody/RowCheckBox/Title.tsx +59 -63
  22. package/src/components/HTableBody/RowCheckBox/hooks.ts +64 -63
  23. package/src/components/HTableBody/RowRadioBoxSelection.tsx +24 -24
  24. package/src/components/HTableBody/hooks/colsMk.tsx +47 -47
  25. package/src/components/HTableBody/hooks/useColData.tsx +9 -9
  26. package/src/components/HTableBody/hooks/useControl.tsx +12 -10
  27. package/src/components/HTableBody/index.tsx +14 -5
  28. package/src/components/Table.tsx +10 -4
  29. package/src/components/hooks/useRowObj.ts +11 -11
  30. package/src/components/index.less +8 -3
  31. package/src/components/modal.ts +2 -2
  32. package/src/components/render/CopyComponent.tsx +9 -9
  33. package/src/components/render/TagsComponent.tsx +18 -8
  34. package/src/pages/DwTable/index.tsx +4 -4
  35. package/src/pages/Table/index.tsx +16 -16
@@ -1,7 +1,7 @@
1
1
  // welcome to hoo hoo hoo
2
+ import _slicedToArray from '@babel/runtime-corejs3/helpers/slicedToArray';
2
3
  import { jsxs, jsx } from 'react/jsx-runtime';
3
- import { Row } from 'antd';
4
- import React from 'react';
4
+ import React, { useRef, useState, useLayoutEffect, useEffect } from 'react';
5
5
  import { useHTableContext } from '../../context.js';
6
6
  import { useClassName } from '../../hooks/index.js';
7
7
 
@@ -14,20 +14,55 @@ var HeaderTitle = (function (_ref) {
14
14
  selectedRowData = _useHTableContext.selectedRowData,
15
15
  rowOnChange = _useHTableContext.rowOnChange,
16
16
  allSelectChange = _useHTableContext.allSelectChange;
17
+ var bodyRef = useRef();
18
+ var titleContentRef = useRef();
19
+ var rightNodeRef = useRef();
20
+ var _useState = useState({}),
21
+ _useState2 = _slicedToArray(_useState, 2),
22
+ style = _useState2[0],
23
+ setStyle = _useState2[1];
17
24
  var headerBox = useClassName("hw-table-header-title-box");
18
25
  var headerBoxContent = useClassName("hw-table-header-title-box-content");
26
+ var titleClassname = useClassName("hw-table-header-title");
19
27
  var rightNodeClassname = useClassName("hw-table-header-right-node");
28
+ var setHeaderStyle = function setHeaderStyle() {
29
+ var _bodyRef$current, _titleContentRef$curr, _rightNodeRef$current;
30
+ var headerWidth = ((_bodyRef$current = bodyRef.current) === null || _bodyRef$current === void 0 ? void 0 : _bodyRef$current.clientWidth) || 0;
31
+ var titleWidth = ((_titleContentRef$curr = titleContentRef.current) === null || _titleContentRef$curr === void 0 ? void 0 : _titleContentRef$curr.clientWidth) || 0;
32
+ var rightNodeWidth = ((_rightNodeRef$current = rightNodeRef.current) === null || _rightNodeRef$current === void 0 ? void 0 : _rightNodeRef$current.clientWidth) || 0;
33
+ if (rightNodeWidth + titleWidth >= headerWidth) {
34
+ setStyle({
35
+ overflow: "auto"
36
+ });
37
+ return;
38
+ }
39
+ setStyle({});
40
+ };
41
+ useLayoutEffect(function () {
42
+ setHeaderStyle();
43
+ }, []);
44
+ useEffect(function () {
45
+ var resizeFn = function resizeFn() {
46
+ setHeaderStyle();
47
+ };
48
+ window.addEventListener('resize', resizeFn);
49
+ return function () {
50
+ window.removeEventListener("resize", resizeFn);
51
+ };
52
+ }, []);
20
53
  if (!headerTitle && !rNode) {
21
54
  return null;
22
55
  }
23
- return jsxs(Row, {
24
- justify: "space-between",
25
- align: "middle",
56
+ return jsxs("div", {
57
+ ref: bodyRef,
58
+ className: titleClassname,
26
59
  style: contentStyle,
27
60
  children: [jsx("div", {
28
61
  className: headerBox,
62
+ style: style,
29
63
  children: jsx("div", {
30
64
  className: headerBoxContent,
65
+ ref: titleContentRef,
31
66
  children: headerTitle && /*#__PURE__*/React.cloneElement(headerTitle, {
32
67
  selectedRowData: selectedRowData,
33
68
  allSelectChange: allSelectChange,
@@ -37,6 +72,7 @@ var HeaderTitle = (function (_ref) {
37
72
  })
38
73
  }), rNode && jsx("div", {
39
74
  className: rightNodeClassname,
75
+ ref: rightNodeRef,
40
76
  children: rNode
41
77
  })]
42
78
  });
@@ -1,4 +1,4 @@
1
1
  /// <reference types="react" />
2
- import { HRowSelection } from "@/components/modal";
2
+ import type { HRowSelection } from "@/components/modal";
3
3
  declare const _default: ({ allPageCheck, onChange, getCheckboxProps, }: HRowSelection) => JSX.Element;
4
4
  export default _default;
@@ -1,4 +1,4 @@
1
- import { Key } from "react";
1
+ import type { Key } from "react";
2
2
  import type { HRowSelection } from "../../modal";
3
3
  export declare const useAllChecked: (keys?: Key[], data?: any[]) => boolean;
4
4
  export declare const useCheckControl: (data: any[] | undefined, onChange: HRowSelection["onChange"]) => {
@@ -1,10 +1,10 @@
1
1
  /// <reference types="react" />
2
- import { HRowSelection } from "@/components/modal";
3
- interface RowRadioSelection {
2
+ import type { HRowSelection } from "@/components/modal";
3
+ interface RowRadioSelectionProps {
4
4
  data: any;
5
5
  onChange?: HRowSelection["onChange"];
6
6
  getCheckboxProps?: HRowSelection["getCheckboxProps"];
7
7
  index: number;
8
8
  }
9
- export declare const RowRadioSelection: ({ data, onChange, index, getCheckboxProps, }: RowRadioSelection) => JSX.Element;
9
+ export declare const RowRadioSelection: ({ data, onChange, index, getCheckboxProps, }: RowRadioSelectionProps) => JSX.Element;
10
10
  export {};
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { HRowSelection } from "@/components/modal";
2
+ import type { HRowSelection } from "@/components/modal";
3
3
  export declare const checkBoxSelectionCol: (rowSelection: HRowSelection) => {
4
4
  title: JSX.Element;
5
5
  width: number;
@@ -2,7 +2,7 @@ import type React from "react";
2
2
  import type { SizeType } from "antd/lib/config-provider/SizeContext";
3
3
  import type { HTableBodyProps } from "../modal";
4
4
  import type { GetRowKey } from "rc-table/lib/interface";
5
- import { RowObj } from "@/components/modal";
5
+ import type { RowObj } from "@/components/modal";
6
6
  export declare const useSize: (size: SizeType) => {
7
7
  cuSize: "small" | "middle" | "large" | undefined;
8
8
  setCuSize: React.Dispatch<React.SetStateAction<"small" | "middle" | "large" | undefined>>;
package/es/index.css CHANGED
@@ -119,14 +119,36 @@
119
119
  display: flex;
120
120
  position: relative;
121
121
  box-sizing: border-box;
122
- overflow: auto;
123
122
  margin: -10px 0px;
124
123
  padding: 10px 0px;
125
- margin-right: 12px;
126
124
  }
127
125
  .ant-hw-table-header-title-box .ant-hw-table-header-title-box-content {
128
126
  white-space: nowrap;
129
127
  }
128
+ .ant-hw-table-header-title {
129
+ display: -webkit-box;
130
+ display: -webkit-flex;
131
+ display: -ms-flexbox;
132
+ display: flex;
133
+ -webkit-box-pack: justify;
134
+ -webkit-justify-content: space-between;
135
+ -ms-flex-pack: justify;
136
+ justify-content: space-between;
137
+ -webkit-align-content: center;
138
+ -ms-flex-line-pack: center;
139
+ align-content: center;
140
+ }
141
+ .ant-hw-table-header-right-node {
142
+ padding-left: 12px;
143
+ display: -webkit-box;
144
+ display: -webkit-flex;
145
+ display: -ms-flexbox;
146
+ display: flex;
147
+ -webkit-box-align: center;
148
+ -webkit-align-items: center;
149
+ -ms-flex-align: center;
150
+ align-items: center;
151
+ }
130
152
  .ant-hw-table-render-copy {
131
153
  margin-bottom: 0 !important;
132
154
  color: #1890ff !important;
@@ -1,3 +1,2 @@
1
- /// <reference types="react" />
2
1
  declare const _default: () => JSX.Element;
3
2
  export default _default;
@@ -2,8 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
5
6
  var jsxRuntime = require('react/jsx-runtime');
6
- var antd = require('antd');
7
7
  var React = require('react');
8
8
  var context = require('../../context.js');
9
9
  var index = require('../../hooks/index.js');
@@ -17,20 +17,55 @@ var HeaderTitle = (function (_ref) {
17
17
  selectedRowData = _useHTableContext.selectedRowData,
18
18
  rowOnChange = _useHTableContext.rowOnChange,
19
19
  allSelectChange = _useHTableContext.allSelectChange;
20
+ var bodyRef = React.useRef();
21
+ var titleContentRef = React.useRef();
22
+ var rightNodeRef = React.useRef();
23
+ var _useState = React.useState({}),
24
+ _useState2 = _slicedToArray(_useState, 2),
25
+ style = _useState2[0],
26
+ setStyle = _useState2[1];
20
27
  var headerBox = index.useClassName("hw-table-header-title-box");
21
28
  var headerBoxContent = index.useClassName("hw-table-header-title-box-content");
29
+ var titleClassname = index.useClassName("hw-table-header-title");
22
30
  var rightNodeClassname = index.useClassName("hw-table-header-right-node");
31
+ var setHeaderStyle = function setHeaderStyle() {
32
+ var _bodyRef$current, _titleContentRef$curr, _rightNodeRef$current;
33
+ var headerWidth = ((_bodyRef$current = bodyRef.current) === null || _bodyRef$current === void 0 ? void 0 : _bodyRef$current.clientWidth) || 0;
34
+ var titleWidth = ((_titleContentRef$curr = titleContentRef.current) === null || _titleContentRef$curr === void 0 ? void 0 : _titleContentRef$curr.clientWidth) || 0;
35
+ var rightNodeWidth = ((_rightNodeRef$current = rightNodeRef.current) === null || _rightNodeRef$current === void 0 ? void 0 : _rightNodeRef$current.clientWidth) || 0;
36
+ if (rightNodeWidth + titleWidth >= headerWidth) {
37
+ setStyle({
38
+ overflow: "auto"
39
+ });
40
+ return;
41
+ }
42
+ setStyle({});
43
+ };
44
+ React.useLayoutEffect(function () {
45
+ setHeaderStyle();
46
+ }, []);
47
+ React.useEffect(function () {
48
+ var resizeFn = function resizeFn() {
49
+ setHeaderStyle();
50
+ };
51
+ window.addEventListener('resize', resizeFn);
52
+ return function () {
53
+ window.removeEventListener("resize", resizeFn);
54
+ };
55
+ }, []);
23
56
  if (!headerTitle && !rNode) {
24
57
  return null;
25
58
  }
26
- return jsxRuntime.jsxs(antd.Row, {
27
- justify: "space-between",
28
- align: "middle",
59
+ return jsxRuntime.jsxs("div", {
60
+ ref: bodyRef,
61
+ className: titleClassname,
29
62
  style: contentStyle,
30
63
  children: [jsxRuntime.jsx("div", {
31
64
  className: headerBox,
65
+ style: style,
32
66
  children: jsxRuntime.jsx("div", {
33
67
  className: headerBoxContent,
68
+ ref: titleContentRef,
34
69
  children: headerTitle && /*#__PURE__*/React.cloneElement(headerTitle, {
35
70
  selectedRowData: selectedRowData,
36
71
  allSelectChange: allSelectChange,
@@ -40,6 +75,7 @@ var HeaderTitle = (function (_ref) {
40
75
  })
41
76
  }), rNode && jsxRuntime.jsx("div", {
42
77
  className: rightNodeClassname,
78
+ ref: rightNodeRef,
43
79
  children: rNode
44
80
  })]
45
81
  });
@@ -1,4 +1,4 @@
1
1
  /// <reference types="react" />
2
- import { HRowSelection } from "@/components/modal";
2
+ import type { HRowSelection } from "@/components/modal";
3
3
  declare const _default: ({ allPageCheck, onChange, getCheckboxProps, }: HRowSelection) => JSX.Element;
4
4
  export default _default;
@@ -1,4 +1,4 @@
1
- import { Key } from "react";
1
+ import type { Key } from "react";
2
2
  import type { HRowSelection } from "../../modal";
3
3
  export declare const useAllChecked: (keys?: Key[], data?: any[]) => boolean;
4
4
  export declare const useCheckControl: (data: any[] | undefined, onChange: HRowSelection["onChange"]) => {
@@ -1,10 +1,10 @@
1
1
  /// <reference types="react" />
2
- import { HRowSelection } from "@/components/modal";
3
- interface RowRadioSelection {
2
+ import type { HRowSelection } from "@/components/modal";
3
+ interface RowRadioSelectionProps {
4
4
  data: any;
5
5
  onChange?: HRowSelection["onChange"];
6
6
  getCheckboxProps?: HRowSelection["getCheckboxProps"];
7
7
  index: number;
8
8
  }
9
- export declare const RowRadioSelection: ({ data, onChange, index, getCheckboxProps, }: RowRadioSelection) => JSX.Element;
9
+ export declare const RowRadioSelection: ({ data, onChange, index, getCheckboxProps, }: RowRadioSelectionProps) => JSX.Element;
10
10
  export {};
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { HRowSelection } from "@/components/modal";
2
+ import type { HRowSelection } from "@/components/modal";
3
3
  export declare const checkBoxSelectionCol: (rowSelection: HRowSelection) => {
4
4
  title: JSX.Element;
5
5
  width: number;
@@ -2,7 +2,7 @@ import type React from "react";
2
2
  import type { SizeType } from "antd/lib/config-provider/SizeContext";
3
3
  import type { HTableBodyProps } from "../modal";
4
4
  import type { GetRowKey } from "rc-table/lib/interface";
5
- import { RowObj } from "@/components/modal";
5
+ import type { RowObj } from "@/components/modal";
6
6
  export declare const useSize: (size: SizeType) => {
7
7
  cuSize: "small" | "middle" | "large" | undefined;
8
8
  setCuSize: React.Dispatch<React.SetStateAction<"small" | "middle" | "large" | undefined>>;
package/lib/index.css CHANGED
@@ -119,14 +119,36 @@
119
119
  display: flex;
120
120
  position: relative;
121
121
  box-sizing: border-box;
122
- overflow: auto;
123
122
  margin: -10px 0px;
124
123
  padding: 10px 0px;
125
- margin-right: 12px;
126
124
  }
127
125
  .ant-hw-table-header-title-box .ant-hw-table-header-title-box-content {
128
126
  white-space: nowrap;
129
127
  }
128
+ .ant-hw-table-header-title {
129
+ display: -webkit-box;
130
+ display: -webkit-flex;
131
+ display: -ms-flexbox;
132
+ display: flex;
133
+ -webkit-box-pack: justify;
134
+ -webkit-justify-content: space-between;
135
+ -ms-flex-pack: justify;
136
+ justify-content: space-between;
137
+ -webkit-align-content: center;
138
+ -ms-flex-line-pack: center;
139
+ align-content: center;
140
+ }
141
+ .ant-hw-table-header-right-node {
142
+ padding-left: 12px;
143
+ display: -webkit-box;
144
+ display: -webkit-flex;
145
+ display: -ms-flexbox;
146
+ display: flex;
147
+ -webkit-box-align: center;
148
+ -webkit-align-items: center;
149
+ -ms-flex-align: center;
150
+ align-items: center;
151
+ }
130
152
  .ant-hw-table-render-copy {
131
153
  margin-bottom: 0 !important;
132
154
  color: #1890ff !important;
@@ -1,3 +1,2 @@
1
- /// <reference types="react" />
2
1
  declare const _default: () => JSX.Element;
3
2
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hw-component/table",
3
- "version": "1.9.79",
3
+ "version": "1.9.80",
4
4
  "description": "基于antd二次开发table组件",
5
5
  "keywords": [
6
6
  "table"
@@ -1,7 +1,7 @@
1
1
  import { Row } from "antd";
2
2
  import type { HTableBodyProps } from "../modal";
3
3
  import type { DetailedReactHTMLElement } from "react";
4
- import React from "react";
4
+ import React, {useEffect, useLayoutEffect, useRef, useState} from "react";
5
5
  import { useHTableContext } from "../../context";
6
6
  import { useClassName } from "../../hooks";
7
7
  interface IProps {
@@ -10,18 +10,49 @@ interface IProps {
10
10
  rNode?: React.ReactNode;
11
11
  }
12
12
  export default ({ headerTitle, contentStyle, rNode }: IProps) => {
13
- const { tableInstance, selectedRowData, rowOnChange, allSelectChange } =
14
- useHTableContext();
13
+ const { tableInstance, selectedRowData, rowOnChange, allSelectChange } = useHTableContext();
14
+ const bodyRef=useRef<any>();
15
+ const titleContentRef=useRef<any>();
16
+ const rightNodeRef=useRef<any>();
17
+ const [style,setStyle]=useState({
18
+
19
+ });
15
20
  const headerBox = useClassName("hw-table-header-title-box");
16
21
  const headerBoxContent = useClassName("hw-table-header-title-box-content");
17
- const rightNodeClassname=useClassName("hw-table-header-right-node");
22
+ const titleClassname=useClassName("hw-table-header-title")
23
+ const rightNodeClassname = useClassName("hw-table-header-right-node");
24
+ const setHeaderStyle=()=>{
25
+ const headerWidth=bodyRef.current?.clientWidth||0;
26
+ const titleWidth=titleContentRef.current?.clientWidth||0;
27
+ const rightNodeWidth=rightNodeRef.current?.clientWidth||0;
28
+ if (rightNodeWidth+titleWidth>=headerWidth){
29
+ setStyle({
30
+ overflow:"auto"
31
+ });
32
+ return;
33
+ }
34
+ setStyle({});
35
+ }
36
+ useLayoutEffect(()=>{
37
+ setHeaderStyle()
38
+ },[]);
39
+ useEffect(()=>{
40
+ const resizeFn=()=>{
41
+ setHeaderStyle();
42
+ }
43
+ window.addEventListener('resize', resizeFn);
44
+ return ()=>{
45
+ window.removeEventListener("resize",resizeFn);
46
+ }
47
+ },[]);
18
48
  if (!headerTitle && !rNode) {
19
49
  return null;
20
50
  }
51
+
21
52
  return (
22
- <Row justify={"space-between"} align={"middle"} style={contentStyle}>
23
- <div className={headerBox} >
24
- <div className={headerBoxContent}>
53
+ <div ref={bodyRef} className={titleClassname} style={contentStyle}>
54
+ <div className={headerBox} style={style}>
55
+ <div className={headerBoxContent} ref={titleContentRef}>
25
56
  {headerTitle &&
26
57
  React.cloneElement(
27
58
  headerTitle as DetailedReactHTMLElement<any, any>,
@@ -29,7 +60,7 @@ export default ({ headerTitle, contentStyle, rNode }: IProps) => {
29
60
  )}
30
61
  </div>
31
62
  </div>
32
- {rNode && <div className={rightNodeClassname}>{rNode}</div>}
33
- </Row>
63
+ {rNode && <div className={rightNodeClassname} ref={rightNodeRef}>{rNode}</div>}
64
+ </div>
34
65
  );
35
66
  };
@@ -2,48 +2,47 @@ import { useHTableContext } from "../../context";
2
2
  import { Checkbox } from "antd";
3
3
  import type { HRowSelection } from "../../modal";
4
4
 
5
-
6
5
  interface RowSelectionBoxProps {
7
- data: any;
8
- onChange?: HRowSelection["onChange"];
9
- getCheckboxProps?: HRowSelection["getCheckboxProps"];
10
- index: number;
6
+ data: any;
7
+ onChange?: HRowSelection["onChange"];
8
+ getCheckboxProps?: HRowSelection["getCheckboxProps"];
9
+ index: number;
11
10
  }
12
11
  export default ({
13
- data,
14
- onChange,
15
- index,
16
- getCheckboxProps,
17
- }: RowSelectionBoxProps) => {
18
- const { selectedRowData, rowOnChange, rowKey = "id" } = useHTableContext();
19
- const { rowData = [], keys = [] } = selectedRowData;
20
- const key = typeof rowKey === "function" ? rowKey(data, index) : data[rowKey];
21
- const add = () => {
22
- const newKeys = [...keys];
23
- const newRowData = [...rowData];
24
- newKeys.push(key);
25
- newRowData.push(data);
26
- rowOnChange(newKeys, newRowData);
27
- onChange?.(newKeys, newRowData);
28
- };
29
- const cancel = () => {
30
- const newKeys = [...keys];
31
- const newRowData = [...rowData];
32
- const keyIndex = newKeys.indexOf(key);
33
- newKeys.splice(keyIndex, 1);
34
- newRowData.splice(keyIndex, 1);
35
- rowOnChange(newKeys, newRowData);
36
- onChange?.(newKeys, newRowData);
37
- };
38
- const check = (e) => {
39
- const checked = e.target.checked;
40
- if (checked) {
41
- add();
42
- return;
43
- }
44
- cancel();
45
- };
46
- const { disabled = false } = getCheckboxProps?.(data) || {};
47
- const checked = keys.indexOf(key) !== -1;
48
- return <Checkbox checked={checked} onChange={check} disabled={disabled} />;
12
+ data,
13
+ onChange,
14
+ index,
15
+ getCheckboxProps,
16
+ }: RowSelectionBoxProps) => {
17
+ const { selectedRowData, rowOnChange, rowKey = "id" } = useHTableContext();
18
+ const { rowData = [], keys = [] } = selectedRowData;
19
+ const key = typeof rowKey === "function" ? rowKey(data, index) : data[rowKey];
20
+ const add = () => {
21
+ const newKeys = [...keys];
22
+ const newRowData = [...rowData];
23
+ newKeys.push(key);
24
+ newRowData.push(data);
25
+ rowOnChange(newKeys, newRowData);
26
+ onChange?.(newKeys, newRowData);
27
+ };
28
+ const cancel = () => {
29
+ const newKeys = [...keys];
30
+ const newRowData = [...rowData];
31
+ const keyIndex = newKeys.indexOf(key);
32
+ newKeys.splice(keyIndex, 1);
33
+ newRowData.splice(keyIndex, 1);
34
+ rowOnChange(newKeys, newRowData);
35
+ onChange?.(newKeys, newRowData);
36
+ };
37
+ const check = (e) => {
38
+ const checked = e.target.checked;
39
+ if (checked) {
40
+ add();
41
+ return;
42
+ }
43
+ cancel();
44
+ };
45
+ const { disabled = false } = getCheckboxProps?.(data) || {};
46
+ const checked = keys.indexOf(key) !== -1;
47
+ return <Checkbox checked={checked} onChange={check} disabled={disabled} />;
49
48
  };
@@ -1,66 +1,62 @@
1
- import {HRowSelection} from "@/components/modal";
2
- import {useHTableContext} from "@/components/context";
3
- import {useMemo} from "react";
4
- import {Checkbox, Dropdown, Menu} from "antd";
5
- import {useAllChecked, useCheckControl} from "./hooks";
6
- export default ({
7
- allPageCheck = true,
8
- onChange,
9
- getCheckboxProps,
10
- }: HRowSelection) => {
11
- const {
12
- data,
13
- selectedRowData,
14
- rowKey = "id",
15
- } = useHTableContext();
16
- const { records = [] } = data || {};
17
- const newData = records?.filter((item) => {
18
- const { disabled = false } = getCheckboxProps?.(item) || {};
19
- return !disabled;
20
- });
21
- const { keys, selectAll } = selectedRowData;
22
- const {checkChange,menuClick}=useCheckControl(newData,onChange);
23
- const dataLen = newData?.length || 0;
24
- const checked = useAllChecked(keys,newData);
25
- const configItems = useMemo(() => {
26
- const fsArray = checked
27
- ? {
28
- label: "取消此页数据",
29
- key: "cancel",
30
- }
31
- : {
32
- label: "选择此页数据",
33
- key: "check",
34
- };
35
- const enArray = selectAll
36
- ? {
37
- label: "取消全部数据",
38
- key: "cancelAll",
39
- }
40
- : {
41
- label: "选择全部数据",
42
- key: "checkAll",
43
- };
44
- return [fsArray, enArray];
45
- }, [checked, selectAll]);
1
+ import type { HRowSelection } from "@/components/modal";
2
+ import { useHTableContext } from "@/components/context";
3
+ import { useMemo } from "react";
4
+ import { Checkbox, Dropdown, Menu } from "antd";
5
+ import { useAllChecked, useCheckControl } from "./hooks";
6
+ export default ({
7
+ allPageCheck = true,
8
+ onChange,
9
+ getCheckboxProps,
10
+ }: HRowSelection) => {
11
+ const { data, selectedRowData, rowKey = "id" } = useHTableContext();
12
+ const { records = [] } = data || {};
13
+ const newData = records?.filter((item) => {
14
+ const { disabled = false } = getCheckboxProps?.(item) || {};
15
+ return !disabled;
16
+ });
17
+ const { keys, selectAll } = selectedRowData;
18
+ const { checkChange, menuClick } = useCheckControl(newData, onChange);
19
+ const dataLen = newData?.length || 0;
20
+ const checked = useAllChecked(keys, newData);
21
+ const configItems = useMemo(() => {
22
+ const fsArray = checked
23
+ ? {
24
+ label: "取消此页数据",
25
+ key: "cancel",
26
+ }
27
+ : {
28
+ label: "选择此页数据",
29
+ key: "check",
30
+ };
31
+ const enArray = selectAll
32
+ ? {
33
+ label: "取消全部数据",
34
+ key: "cancelAll",
35
+ }
36
+ : {
37
+ label: "选择全部数据",
38
+ key: "checkAll",
39
+ };
40
+ return [fsArray, enArray];
41
+ }, [checked, selectAll]);
46
42
 
47
- const menu = () => {
48
- const MenuEle = Menu as any;
49
- return <MenuEle onClick={menuClick} items={configItems} />;
50
- };
51
- const disabled = dataLen === 0;
52
- if (allPageCheck) {
53
- return (
54
- <Dropdown overlay={menu} arrow placement={"bottom"} disabled={disabled}>
55
- <Checkbox
56
- checked={checked}
57
- onChange={checkChange}
58
- disabled={disabled}
59
- />
60
- </Dropdown>
61
- );
62
- }
43
+ const menu = () => {
44
+ const MenuEle = Menu as any;
45
+ return <MenuEle onClick={menuClick} items={configItems} />;
46
+ };
47
+ const disabled = dataLen === 0;
48
+ if (allPageCheck) {
63
49
  return (
64
- <Checkbox checked={checked} onChange={checkChange} disabled={disabled} />
50
+ <Dropdown overlay={menu} arrow placement={"bottom"} disabled={disabled}>
51
+ <Checkbox
52
+ checked={checked}
53
+ onChange={checkChange}
54
+ disabled={disabled}
55
+ />
56
+ </Dropdown>
65
57
  );
66
- };
58
+ }
59
+ return (
60
+ <Checkbox checked={checked} onChange={checkChange} disabled={disabled} />
61
+ );
62
+ };