@hw-component/table 1.9.89 → 1.9.91
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/.eslintcache +1 -1
- package/es/HTableBody/HeaderTitle/hooks.d.ts +2 -2
- package/es/HTableBody/HeaderTitle/hooks.js +0 -1
- package/es/HTableBody/Options/Content.d.ts +1 -1
- package/es/HTableBody/Options/Content.js +57 -10
- package/es/HTableBody/Options/Title.d.ts +1 -1
- package/es/HTableBody/Options/index.d.ts +1 -1
- package/es/HTableBody/Options/index.js +4 -2
- package/es/HTableBody/RowCheckBox/RowItem.d.ts +1 -1
- package/es/HTableBody/RowCheckBox/hooks.d.ts +1 -1
- package/es/HTableBody/RowRadioBoxSelection.d.ts +1 -1
- package/es/HTableBody/hooks/useColData.d.ts +2 -0
- package/es/HTableBody/hooks/useColData.js +2 -1
- package/es/HTableBody/index.js +4 -2
- package/es/HTableBody/modal.d.ts +2 -1
- package/es/modal.d.ts +2 -1
- package/lib/HTableBody/HeaderTitle/hooks.d.ts +2 -2
- package/lib/HTableBody/HeaderTitle/hooks.js +0 -1
- package/lib/HTableBody/Options/Content.d.ts +1 -1
- package/lib/HTableBody/Options/Content.js +57 -10
- package/lib/HTableBody/Options/Title.d.ts +1 -1
- package/lib/HTableBody/Options/index.d.ts +1 -1
- package/lib/HTableBody/Options/index.js +4 -2
- package/lib/HTableBody/RowCheckBox/RowItem.d.ts +1 -1
- package/lib/HTableBody/RowCheckBox/hooks.d.ts +1 -1
- package/lib/HTableBody/RowRadioBoxSelection.d.ts +1 -1
- package/lib/HTableBody/hooks/useColData.d.ts +2 -0
- package/lib/HTableBody/hooks/useColData.js +2 -1
- package/lib/HTableBody/index.js +4 -2
- package/lib/HTableBody/modal.d.ts +2 -1
- package/lib/modal.d.ts +2 -1
- package/package.json +1 -1
- package/src/components/HTableBody/HeaderTitle/hooks.ts +47 -43
- package/src/components/HTableBody/HeaderTitle/index.tsx +7 -5
- package/src/components/HTableBody/Options/Content.tsx +42 -0
- package/src/components/HTableBody/Options/Title.tsx +2 -2
- package/src/components/HTableBody/Options/index.tsx +5 -0
- package/src/components/HTableBody/Options/modal.d.ts +2 -0
- package/src/components/HTableBody/RowCheckBox/RowItem.tsx +1 -1
- package/src/components/HTableBody/RowCheckBox/hooks.ts +1 -1
- package/src/components/HTableBody/RowRadioBoxSelection.tsx +1 -1
- package/src/components/HTableBody/hooks/useColData.tsx +7 -5
- package/src/components/HTableBody/index.tsx +4 -3
- package/src/components/HTableBody/modal.ts +4 -3
- package/src/components/hooks/useRowObj.ts +1 -1
- package/src/components/modal.ts +3 -2
- package/src/pages/Table/index.tsx +19 -20
|
@@ -14,7 +14,6 @@ var useHeaderStyle = function useHeaderStyle(_ref) {
|
|
|
14
14
|
var setHeaderStyle = function setHeaderStyle() {
|
|
15
15
|
var _bodyRef$current, _titleContentRef$curr, _rightNodeRef$current;
|
|
16
16
|
var headerWidth = ((_bodyRef$current = bodyRef.current) === null || _bodyRef$current === void 0 ? void 0 : _bodyRef$current.clientWidth) || 0;
|
|
17
|
-
console.log(headerWidth, "headerWidth");
|
|
18
17
|
var titleWidth = ((_titleContentRef$curr = titleContentRef.current) === null || _titleContentRef$curr === void 0 ? void 0 : _titleContentRef$curr.clientWidth) || 0;
|
|
19
18
|
var rightNodeWidth = ((_rightNodeRef$current = rightNodeRef.current) === null || _rightNodeRef$current === void 0 ? void 0 : _rightNodeRef$current.clientWidth) || 0;
|
|
20
19
|
if (rightNodeWidth + titleWidth >= headerWidth) {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { ItemProps } from "./modal";
|
|
3
|
-
export declare const ColsSettingContent: ({ columns, onCheck, checkKeys, }: ItemProps) => JSX.Element;
|
|
3
|
+
export declare const ColsSettingContent: ({ columns, onCheck, checkKeys, onDrop }: ItemProps) => JSX.Element;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
4
|
+
var _toConsumableArray = require('@babel/runtime-corejs3/helpers/toConsumableArray');
|
|
3
5
|
var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
|
|
6
|
+
var _spliceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/splice');
|
|
4
7
|
var _indexOfInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/index-of');
|
|
5
8
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
9
|
var index = require('../../hooks/index.js');
|
|
@@ -8,19 +11,45 @@ var React = require('react');
|
|
|
8
11
|
var antd = require('antd');
|
|
9
12
|
var utils = require('./utils.js');
|
|
10
13
|
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
var moveArray = function moveArray(_ref) {
|
|
15
|
+
var startKey = _ref.startKey,
|
|
16
|
+
endKey = _ref.endKey,
|
|
17
|
+
data = _ref.data;
|
|
18
|
+
var indexArray = [-1, -1];
|
|
19
|
+
_forEachInstanceProperty(data).call(data, function (item, index) {
|
|
20
|
+
var dataIndex = item.dataIndex;
|
|
21
|
+
if (!dataIndex) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (dataIndex === startKey) {
|
|
25
|
+
indexArray[0] = index;
|
|
26
|
+
}
|
|
27
|
+
if (dataIndex === endKey) {
|
|
28
|
+
indexArray[1] = index;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
var oldIndex = indexArray[0],
|
|
32
|
+
newIndex = indexArray[1];
|
|
33
|
+
var newData = _toConsumableArray(data);
|
|
34
|
+
var oldItem = data[oldIndex];
|
|
35
|
+
_spliceInstanceProperty(newData).call(newData, oldIndex, 1);
|
|
36
|
+
_spliceInstanceProperty(newData).call(newData, newIndex, 0, oldItem);
|
|
37
|
+
return newData;
|
|
38
|
+
};
|
|
39
|
+
var ColsSettingContent = function ColsSettingContent(_ref2) {
|
|
40
|
+
var columns = _ref2.columns,
|
|
41
|
+
onCheck = _ref2.onCheck,
|
|
42
|
+
checkKeys = _ref2.checkKeys,
|
|
43
|
+
onDrop = _ref2.onDrop;
|
|
15
44
|
var content = index.useClassName("hw-table-body-option-setting-content");
|
|
16
45
|
var titleClass = index.useClassName("hw-table-body-option-setting-content-title");
|
|
17
46
|
var treeClass = index.useClassName("hw-table-body-option-tree");
|
|
18
47
|
var contentTreeData = React.useMemo(function () {
|
|
19
48
|
var treeData = [];
|
|
20
|
-
_forEachInstanceProperty(columns).call(columns, function (
|
|
21
|
-
var dataIndex =
|
|
22
|
-
title =
|
|
23
|
-
titleStr =
|
|
49
|
+
_forEachInstanceProperty(columns).call(columns, function (_ref3) {
|
|
50
|
+
var dataIndex = _ref3.dataIndex,
|
|
51
|
+
title = _ref3.title,
|
|
52
|
+
titleStr = _ref3.titleStr;
|
|
24
53
|
if (dataIndex) {
|
|
25
54
|
var _getItemValue = utils.getItemValue({
|
|
26
55
|
titleStr: titleStr,
|
|
@@ -40,8 +69,8 @@ var ColsSettingContent = function ColsSettingContent(_ref) {
|
|
|
40
69
|
}, [columns]);
|
|
41
70
|
var check = function check(keys) {
|
|
42
71
|
var notCheck = [];
|
|
43
|
-
_forEachInstanceProperty(contentTreeData).call(contentTreeData, function (
|
|
44
|
-
var key =
|
|
72
|
+
_forEachInstanceProperty(contentTreeData).call(contentTreeData, function (_ref4) {
|
|
73
|
+
var key = _ref4.key;
|
|
45
74
|
var cuKey = key;
|
|
46
75
|
var index = _indexOfInstanceProperty(keys).call(keys, cuKey);
|
|
47
76
|
if (index === -1) {
|
|
@@ -50,6 +79,22 @@ var ColsSettingContent = function ColsSettingContent(_ref) {
|
|
|
50
79
|
});
|
|
51
80
|
onCheck(keys, notCheck);
|
|
52
81
|
};
|
|
82
|
+
var onDropEnd = function onDropEnd(_ref5) {
|
|
83
|
+
var dragNodesKeys = _ref5.dragNodesKeys,
|
|
84
|
+
dropPosition = _ref5.dropPosition;
|
|
85
|
+
if (dropPosition < 1) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
var _dragNodesKeys = _slicedToArray(dragNodesKeys, 1),
|
|
89
|
+
key = _dragNodesKeys[0];
|
|
90
|
+
var sourceKey = contentTreeData[dropPosition - 1].key;
|
|
91
|
+
var newData = moveArray({
|
|
92
|
+
startKey: key,
|
|
93
|
+
endKey: sourceKey,
|
|
94
|
+
data: columns
|
|
95
|
+
});
|
|
96
|
+
onDrop(newData);
|
|
97
|
+
};
|
|
53
98
|
return jsxRuntime.jsx("div", {
|
|
54
99
|
className: content,
|
|
55
100
|
children: jsxRuntime.jsx("div", {
|
|
@@ -60,7 +105,9 @@ var ColsSettingContent = function ColsSettingContent(_ref) {
|
|
|
60
105
|
children: jsxRuntime.jsx(antd.Tree, {
|
|
61
106
|
checkable: true,
|
|
62
107
|
className: treeClass,
|
|
108
|
+
draggable: true,
|
|
63
109
|
checkedKeys: checkKeys,
|
|
110
|
+
onDrop: onDropEnd,
|
|
64
111
|
onCheck: function onCheck(key) {
|
|
65
112
|
check(key);
|
|
66
113
|
},
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { ItemProps } from "./modal";
|
|
3
|
-
export declare const Title: ({ columns, onCheck, checkKeys, reset }: ItemProps) => JSX.Element;
|
|
3
|
+
export declare const Title: ({ columns, onCheck, checkKeys, reset }: Omit<ItemProps, "onDrop">) => JSX.Element;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { IProps } from "./modal";
|
|
3
|
-
declare const _default: ({ reload, size, density, setSizeChange, columns, onChange, colStatusValue, reset, settingRender, }: IProps) => JSX.Element;
|
|
3
|
+
declare const _default: ({ reload, size, density, setSizeChange, columns, onChange, colStatusValue, reset, settingRender, onDrop }: IProps) => JSX.Element;
|
|
4
4
|
export default _default;
|
|
@@ -22,7 +22,8 @@ var Options = (function (_ref) {
|
|
|
22
22
|
onChange = _ref.onChange,
|
|
23
23
|
colStatusValue = _ref.colStatusValue,
|
|
24
24
|
reset = _ref.reset,
|
|
25
|
-
settingRender = _ref.settingRender
|
|
25
|
+
settingRender = _ref.settingRender,
|
|
26
|
+
onDrop = _ref.onDrop;
|
|
26
27
|
var pointer = index.useClassName(["hw-table-pointer", "hw-table-body-option-icon"]);
|
|
27
28
|
var ref = React.useRef(null);
|
|
28
29
|
var checkKeys = hooks.useCheckKeys({
|
|
@@ -87,7 +88,8 @@ var Options = (function (_ref) {
|
|
|
87
88
|
content: jsxRuntime.jsx(Content.ColsSettingContent, {
|
|
88
89
|
columns: columns,
|
|
89
90
|
checkKeys: checkKeys,
|
|
90
|
-
onCheck: onChange
|
|
91
|
+
onCheck: onChange,
|
|
92
|
+
onDrop: onDrop
|
|
91
93
|
}),
|
|
92
94
|
title: jsxRuntime.jsx(Title.Title, {
|
|
93
95
|
columns: columns,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { RowRadioSelectionProps } from "@/components/HTableBody/modal";
|
|
2
|
+
import type { RowRadioSelectionProps } from "@/components/HTableBody/modal";
|
|
3
3
|
declare const _default: ({ data, onChange, index, getCheckboxProps, }: RowRadioSelectionProps) => JSX.Element;
|
|
4
4
|
export default _default;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Key } from "react";
|
|
2
|
-
import { RowRadioSelectionProps } from
|
|
2
|
+
import type { RowRadioSelectionProps } from "../modal";
|
|
3
3
|
export declare const useAllChecked: (keys?: Key[], data?: any[]) => boolean;
|
|
4
4
|
export declare const useCheckControl: (data: any[] | undefined, onChange: RowRadioSelectionProps["onChange"]) => {
|
|
5
5
|
checkChange: (e: any) => void;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import type { ConfigDataModal, HTableProps } from "@/components/modal";
|
|
2
3
|
import type { ColumnsState } from "@ant-design/pro-table/es/container";
|
|
3
4
|
import type { ColumnsStateType } from "@ant-design/pro-table/es/typing";
|
|
4
5
|
export declare const useCols: ({ configData, rowSelection, table, bordered, }: HTableProps) => {
|
|
5
6
|
cols: ConfigDataModal;
|
|
7
|
+
setCols: import("react").Dispatch<import("react").SetStateAction<ConfigDataModal>>;
|
|
6
8
|
};
|
|
7
9
|
interface useColumnsStateTypeModal {
|
|
8
10
|
columnsState?: ColumnsStateType;
|
|
@@ -94,7 +94,8 @@ var useCols = function useCols(_ref) {
|
|
|
94
94
|
setCols(changeConfigData(configData));
|
|
95
95
|
}, [configData, table, rowSelection]);
|
|
96
96
|
return {
|
|
97
|
-
cols: cols
|
|
97
|
+
cols: cols,
|
|
98
|
+
setCols: setCols
|
|
98
99
|
};
|
|
99
100
|
};
|
|
100
101
|
var useColumnsStateType = function useColumnsStateType(_ref3) {
|
package/lib/HTableBody/index.js
CHANGED
|
@@ -92,7 +92,8 @@ var Body = (function (bodyProps) {
|
|
|
92
92
|
rowSelection: rowSelection,
|
|
93
93
|
bordered: bordered
|
|
94
94
|
}),
|
|
95
|
-
cols = _useCols.cols
|
|
95
|
+
cols = _useCols.cols,
|
|
96
|
+
setCols = _useCols.setCols;
|
|
96
97
|
var _useColumnsStateType = useColData.useColumnsStateType({
|
|
97
98
|
columnsState: columnsState,
|
|
98
99
|
columns: cols
|
|
@@ -116,7 +117,8 @@ var Body = (function (bodyProps) {
|
|
|
116
117
|
setSizeChange: setCuSize,
|
|
117
118
|
colStatusValue: value || {},
|
|
118
119
|
onChange: onChange,
|
|
119
|
-
reset: reset
|
|
120
|
+
reset: reset,
|
|
121
|
+
onDrop: setCols
|
|
120
122
|
}));
|
|
121
123
|
var defaultOptionsNode = optionsRender ? optionsRender(optionsNode) : optionsNode;
|
|
122
124
|
var alwaysShowAlert = useControl.useAlwaysShowAlert(selectedRowData, configAlwaysShowAlert);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { OptionConfig } from "@ant-design/pro-table/lib/components/ToolBar";
|
|
2
|
-
import
|
|
2
|
+
import type { Key } from "react";
|
|
3
|
+
import type React from "react";
|
|
3
4
|
import type { ProTableProps } from "@ant-design/pro-table";
|
|
4
5
|
import type { ActionRenderFn, ConfigDataModal, HRowSelection, HTableInstance, ParamsModal } from "@/components/modal";
|
|
5
6
|
import type { AffixProps } from "antd/lib/affix";
|
package/lib/modal.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ import type { ProColumns } from "@ant-design/pro-table/lib/typing";
|
|
|
2
2
|
import type { ProTableProps } from "@ant-design/pro-table";
|
|
3
3
|
import type { HItemProps, HFormInstance } from "@hw-component/form/es/Form/modal";
|
|
4
4
|
import type { ColProps, FormInstance } from "antd";
|
|
5
|
-
import
|
|
5
|
+
import type { Key } from "react";
|
|
6
|
+
import type React from "react";
|
|
6
7
|
import type { ModalProps } from "antd";
|
|
7
8
|
import type { TableProps } from "antd/lib/table";
|
|
8
9
|
import type { AffixProps } from "antd/lib/affix";
|
package/package.json
CHANGED
|
@@ -1,48 +1,52 @@
|
|
|
1
|
-
import {MutableRefObject
|
|
1
|
+
import type { MutableRefObject} from "react";
|
|
2
|
+
import { useEffect, useLayoutEffect, useState } from "react";
|
|
2
3
|
|
|
3
4
|
interface HeaderStyleParams {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
bodyRef: MutableRefObject<HTMLDivElement | null>;
|
|
6
|
+
titleContentRef: MutableRefObject<HTMLDivElement | null>;
|
|
7
|
+
rightNodeRef: MutableRefObject<HTMLDivElement | null>;
|
|
7
8
|
}
|
|
8
9
|
|
|
9
|
-
export const useHeaderStyle = ({
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
10
|
+
export const useHeaderStyle = ({
|
|
11
|
+
bodyRef,
|
|
12
|
+
titleContentRef,
|
|
13
|
+
rightNodeRef,
|
|
14
|
+
}: HeaderStyleParams) => {
|
|
15
|
+
const [style, setStyle] = useState({});
|
|
16
|
+
const setHeaderStyle = () => {
|
|
17
|
+
const headerWidth = bodyRef.current?.clientWidth || 0;
|
|
18
|
+
const titleWidth = titleContentRef.current?.clientWidth || 0;
|
|
19
|
+
const rightNodeWidth = rightNodeRef.current?.clientWidth || 0;
|
|
20
|
+
if (rightNodeWidth + titleWidth >= headerWidth) {
|
|
21
|
+
setStyle({
|
|
22
|
+
overflow: "auto",
|
|
23
|
+
});
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
setStyle({});
|
|
27
|
+
};
|
|
28
|
+
useLayoutEffect(() => {
|
|
29
|
+
setHeaderStyle();
|
|
30
|
+
}, []);
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
const resizeFn = () => {
|
|
33
|
+
setHeaderStyle();
|
|
23
34
|
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
observer.observe(element);
|
|
43
|
-
return () => {
|
|
44
|
-
observer.disconnect();
|
|
45
|
-
}
|
|
46
|
-
}, []);
|
|
47
|
-
return style;
|
|
48
|
-
}
|
|
35
|
+
window.addEventListener("resize", resizeFn);
|
|
36
|
+
return () => {
|
|
37
|
+
window.removeEventListener("resize", resizeFn);
|
|
38
|
+
};
|
|
39
|
+
}, []);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
const element = titleContentRef.current;
|
|
42
|
+
if (!element || !window.ResizeObserver) return;
|
|
43
|
+
const observer = new ResizeObserver(() => {
|
|
44
|
+
setHeaderStyle();
|
|
45
|
+
});
|
|
46
|
+
observer.observe(element);
|
|
47
|
+
return () => {
|
|
48
|
+
observer.disconnect();
|
|
49
|
+
};
|
|
50
|
+
}, []);
|
|
51
|
+
return style;
|
|
52
|
+
};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { HTableBodyProps } from "../modal";
|
|
2
|
-
import {DetailedReactHTMLElement
|
|
2
|
+
import type { DetailedReactHTMLElement} from "react";
|
|
3
|
+
import { useLayoutEffect } from "react";
|
|
3
4
|
import React, { useRef } from "react";
|
|
4
5
|
import { useHTableContext } from "../../context";
|
|
5
6
|
import { useClassName } from "../../hooks";
|
|
6
|
-
import {useHeaderStyle} from "./hooks";
|
|
7
|
+
import { useHeaderStyle } from "./hooks";
|
|
7
8
|
|
|
8
9
|
interface IProps {
|
|
9
10
|
headerTitle: HTableBodyProps["headerTitle"];
|
|
@@ -11,7 +12,8 @@ interface IProps {
|
|
|
11
12
|
rNode?: React.ReactNode;
|
|
12
13
|
}
|
|
13
14
|
export default ({ headerTitle, contentStyle, rNode }: IProps) => {
|
|
14
|
-
const { tableInstance, selectedRowData, rowOnChange, allSelectChange } =
|
|
15
|
+
const { tableInstance, selectedRowData, rowOnChange, allSelectChange } =
|
|
16
|
+
useHTableContext();
|
|
15
17
|
const bodyRef = useRef<any>();
|
|
16
18
|
const titleContentRef = useRef<any>();
|
|
17
19
|
const rightNodeRef = useRef<any>();
|
|
@@ -19,10 +21,10 @@ export default ({ headerTitle, contentStyle, rNode }: IProps) => {
|
|
|
19
21
|
const headerBoxContent = useClassName("hw-table-header-title-box-content");
|
|
20
22
|
const titleClassname = useClassName("hw-table-header-title");
|
|
21
23
|
const rightNodeClassname = useClassName("hw-table-header-right-node");
|
|
22
|
-
const style=useHeaderStyle({
|
|
24
|
+
const style = useHeaderStyle({
|
|
23
25
|
bodyRef,
|
|
24
26
|
titleContentRef,
|
|
25
|
-
rightNodeRef
|
|
27
|
+
rightNodeRef,
|
|
26
28
|
});
|
|
27
29
|
if (!headerTitle && !rNode) {
|
|
28
30
|
return null;
|
|
@@ -5,14 +5,44 @@ import { Tree } from "antd";
|
|
|
5
5
|
import type { ItemProps } from "./modal";
|
|
6
6
|
import { getItemValue } from "./utils";
|
|
7
7
|
|
|
8
|
+
interface MoveArrayProps {
|
|
9
|
+
startKey:string;
|
|
10
|
+
endKey:string;
|
|
11
|
+
data: ConfigDataModal;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
const moveArray=({startKey,endKey,data}:MoveArrayProps)=>{
|
|
16
|
+
const indexArray=[-1,-1];
|
|
17
|
+
data.forEach((item,index)=>{
|
|
18
|
+
const{dataIndex}=item;
|
|
19
|
+
if(!dataIndex){
|
|
20
|
+
return;
|
|
21
|
+
};
|
|
22
|
+
if(dataIndex===startKey){
|
|
23
|
+
indexArray[0]=index;
|
|
24
|
+
}
|
|
25
|
+
if(dataIndex===endKey){
|
|
26
|
+
indexArray[1]=index;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
const [oldIndex,newIndex]=indexArray;
|
|
30
|
+
const newData = [...data];
|
|
31
|
+
const oldItem = data[oldIndex];
|
|
32
|
+
newData.splice(oldIndex, 1);
|
|
33
|
+
newData.splice(newIndex, 0, oldItem);
|
|
34
|
+
return newData;
|
|
35
|
+
};
|
|
8
36
|
export const ColsSettingContent = ({
|
|
9
37
|
columns,
|
|
10
38
|
onCheck,
|
|
11
39
|
checkKeys,
|
|
40
|
+
onDrop
|
|
12
41
|
}: ItemProps) => {
|
|
13
42
|
const content = useClassName("hw-table-body-option-setting-content");
|
|
14
43
|
const titleClass = useClassName("hw-table-body-option-setting-content-title");
|
|
15
44
|
const treeClass = useClassName("hw-table-body-option-tree");
|
|
45
|
+
|
|
16
46
|
const contentTreeData = useMemo(() => {
|
|
17
47
|
const treeData: ConfigDataModal = [];
|
|
18
48
|
columns.forEach(({ dataIndex, title, titleStr }) => {
|
|
@@ -29,6 +59,7 @@ export const ColsSettingContent = ({
|
|
|
29
59
|
});
|
|
30
60
|
return treeData;
|
|
31
61
|
}, [columns]);
|
|
62
|
+
|
|
32
63
|
const check = (keys: string[]) => {
|
|
33
64
|
const notCheck: string[] = [];
|
|
34
65
|
contentTreeData.forEach(({ key }) => {
|
|
@@ -40,13 +71,24 @@ export const ColsSettingContent = ({
|
|
|
40
71
|
});
|
|
41
72
|
onCheck(keys, notCheck);
|
|
42
73
|
};
|
|
74
|
+
const onDropEnd=({dragNodesKeys,dropPosition})=>{
|
|
75
|
+
if (dropPosition<1) {
|
|
76
|
+
return;
|
|
77
|
+
};
|
|
78
|
+
const [key]=dragNodesKeys;
|
|
79
|
+
const sourceKey=contentTreeData[dropPosition-1].key;
|
|
80
|
+
const newData= moveArray({startKey:key,endKey:(sourceKey as string),data:columns});
|
|
81
|
+
onDrop(newData);
|
|
82
|
+
}
|
|
43
83
|
return (
|
|
44
84
|
<div className={content}>
|
|
45
85
|
<div style={{ paddingTop: 6, paddingBottom: 6 }}>
|
|
46
86
|
<Tree
|
|
47
87
|
checkable
|
|
48
88
|
className={treeClass}
|
|
89
|
+
draggable
|
|
49
90
|
checkedKeys={checkKeys}
|
|
91
|
+
onDrop={onDropEnd}
|
|
50
92
|
onCheck={(key) => {
|
|
51
93
|
check(key as string[]);
|
|
52
94
|
}}
|
|
@@ -2,8 +2,9 @@ import { useClassName } from "../../hooks";
|
|
|
2
2
|
import { Checkbox, Row, Space, Typography } from "antd";
|
|
3
3
|
import type { ItemProps } from "./modal";
|
|
4
4
|
import { useMemo } from "react";
|
|
5
|
+
|
|
5
6
|
const { Link } = Typography;
|
|
6
|
-
export const Title = ({ columns, onCheck, checkKeys, reset }: ItemProps) => {
|
|
7
|
+
export const Title = ({ columns, onCheck, checkKeys, reset }: Omit<ItemProps,"onDrop">) => {
|
|
7
8
|
const title = useClassName("hw-table-body-option-setting-title");
|
|
8
9
|
const relArrayKeys = useMemo(() => {
|
|
9
10
|
const keys: string[] = [];
|
|
@@ -17,7 +18,6 @@ export const Title = ({ columns, onCheck, checkKeys, reset }: ItemProps) => {
|
|
|
17
18
|
});
|
|
18
19
|
return keys;
|
|
19
20
|
}, [columns]);
|
|
20
|
-
const allKeys = columns;
|
|
21
21
|
const allCheck = () => {
|
|
22
22
|
onCheck(relArrayKeys, []);
|
|
23
23
|
};
|
|
@@ -11,6 +11,9 @@ import { ColsSettingContent } from "./Content";
|
|
|
11
11
|
import { Title } from "./Title";
|
|
12
12
|
import type { IProps } from "./modal";
|
|
13
13
|
import { useCheckKeys } from "@/components/HTableBody/Options/hooks";
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
14
17
|
export default ({
|
|
15
18
|
reload,
|
|
16
19
|
size = "middle",
|
|
@@ -21,6 +24,7 @@ export default ({
|
|
|
21
24
|
colStatusValue,
|
|
22
25
|
reset,
|
|
23
26
|
settingRender,
|
|
27
|
+
onDrop
|
|
24
28
|
}: IProps) => {
|
|
25
29
|
const pointer = useClassName([
|
|
26
30
|
"hw-table-pointer",
|
|
@@ -84,6 +88,7 @@ export default ({
|
|
|
84
88
|
columns={columns}
|
|
85
89
|
checkKeys={checkKeys}
|
|
86
90
|
onCheck={onChange}
|
|
91
|
+
onDrop={onDrop}
|
|
87
92
|
/>
|
|
88
93
|
}
|
|
89
94
|
title={
|
|
@@ -12,6 +12,7 @@ export interface IProps extends OptionConfig {
|
|
|
12
12
|
colStatusValue: Record<string, ColumnsState>;
|
|
13
13
|
reset: VoidFunction;
|
|
14
14
|
settingRender?: () => React.ReactNode;
|
|
15
|
+
onDrop:(columns:ConfigDataModal)=>void;
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
export interface ItemProps {
|
|
@@ -19,4 +20,5 @@ export interface ItemProps {
|
|
|
19
20
|
onCheck: (keys: string[], notCheck: string[]) => void;
|
|
20
21
|
columns: ConfigDataModal;
|
|
21
22
|
reset?: VoidFunction;
|
|
23
|
+
onDrop:(columns:ConfigDataModal)=>void;
|
|
22
24
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { HTableProps } from "@/components/modal";
|
|
2
2
|
import type { Key } from "react";
|
|
3
3
|
import { useHTableContext } from "@/components/context";
|
|
4
|
-
import {RowRadioSelectionProps} from
|
|
4
|
+
import type { RowRadioSelectionProps } from "../modal";
|
|
5
5
|
|
|
6
6
|
const getRowKey = (item: any, index: number, rowKey: HTableProps["rowKey"]) => {
|
|
7
7
|
return typeof rowKey === "function"
|
|
@@ -78,11 +78,14 @@ export const useCols = ({
|
|
|
78
78
|
useEffect(() => {
|
|
79
79
|
setCols(changeConfigData(configData));
|
|
80
80
|
}, [configData, table, rowSelection]);
|
|
81
|
+
|
|
81
82
|
return {
|
|
82
83
|
cols,
|
|
84
|
+
setCols
|
|
83
85
|
};
|
|
84
86
|
};
|
|
85
87
|
|
|
88
|
+
|
|
86
89
|
interface useColumnsStateTypeModal {
|
|
87
90
|
columnsState?: ColumnsStateType;
|
|
88
91
|
columns: ConfigDataModal;
|
|
@@ -93,11 +96,9 @@ export const useColumnsStateType = ({
|
|
|
93
96
|
columns,
|
|
94
97
|
}: useColumnsStateTypeModal) => {
|
|
95
98
|
const { tableInstance } = useHTableContext();
|
|
96
|
-
const { persistenceType, persistenceKey, value, defaultValue, onChange } =
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
Record<string, ColumnsState> | undefined
|
|
100
|
-
>(defaultValue);
|
|
99
|
+
const { persistenceType, persistenceKey, value, defaultValue, onChange } = columnsState || {};
|
|
100
|
+
const [selfValue, setSelfValue] = useState<Record<string, ColumnsState> | undefined>(defaultValue);
|
|
101
|
+
|
|
101
102
|
const initTableColsVal = useMemo(() => {
|
|
102
103
|
return selfValue || {};
|
|
103
104
|
}, []);
|
|
@@ -118,6 +119,7 @@ export const useColumnsStateType = ({
|
|
|
118
119
|
setSelfValue(newObj);
|
|
119
120
|
onChange?.(newObj);
|
|
120
121
|
};
|
|
122
|
+
|
|
121
123
|
const reset = () => {
|
|
122
124
|
setSelfValue(initTableColsVal);
|
|
123
125
|
};
|
|
@@ -65,13 +65,13 @@ export default (bodyProps: HTableBodyProps) => {
|
|
|
65
65
|
const bodyConfigData = configData || contextConfigData;
|
|
66
66
|
const { records } = data || {};
|
|
67
67
|
const tableInstance = table || contextTableInstance;
|
|
68
|
-
|
|
68
|
+
|
|
69
|
+
const { cols ,setCols} = useCols({
|
|
69
70
|
configData: bodyConfigData,
|
|
70
71
|
table: tableInstance,
|
|
71
72
|
rowSelection,
|
|
72
73
|
bordered,
|
|
73
74
|
});
|
|
74
|
-
|
|
75
75
|
const { value, onChange, reset, ...selfColStatus } = useColumnsStateType({
|
|
76
76
|
columnsState,
|
|
77
77
|
columns: cols,
|
|
@@ -90,6 +90,7 @@ export default (bodyProps: HTableBodyProps) => {
|
|
|
90
90
|
colStatusValue={value || {}}
|
|
91
91
|
onChange={onChange}
|
|
92
92
|
reset={reset}
|
|
93
|
+
onDrop={setCols}
|
|
93
94
|
/>
|
|
94
95
|
);
|
|
95
96
|
const defaultOptionsNode = optionsRender
|
|
@@ -131,7 +132,7 @@ export default (bodyProps: HTableBodyProps) => {
|
|
|
131
132
|
>
|
|
132
133
|
<ProTable
|
|
133
134
|
{...props}
|
|
134
|
-
rowClassName={
|
|
135
|
+
rowClassName={rowClassNameFn as any}
|
|
135
136
|
bordered={bordered}
|
|
136
137
|
columnsState={{
|
|
137
138
|
...selfColStatus,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { OptionConfig } from "@ant-design/pro-table/lib/components/ToolBar";
|
|
2
|
-
import
|
|
2
|
+
import type { Key } from "react";
|
|
3
|
+
import type React from "react";
|
|
3
4
|
import type { ProTableProps } from "@ant-design/pro-table";
|
|
4
5
|
import type {
|
|
5
6
|
ActionRenderFn,
|
|
@@ -42,7 +43,7 @@ export interface HTableBodyProps
|
|
|
42
43
|
|
|
43
44
|
export interface RowRadioSelectionProps {
|
|
44
45
|
data: any;
|
|
45
|
-
onChange?:(keys:Key[],data:any[])=>void;
|
|
46
|
+
onChange?: (keys: Key[], data: any[]) => void;
|
|
46
47
|
getCheckboxProps?: HRowSelection["getCheckboxProps"];
|
|
47
48
|
index: number;
|
|
48
|
-
}
|
|
49
|
+
}
|