@hw-component/table 1.9.90 → 1.9.92

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 (64) hide show
  1. package/.eslintcache +1 -1
  2. package/es/HTableBody/HeaderTitle/hooks.d.ts +2 -2
  3. package/es/HTableBody/Options/Content.d.ts +1 -1
  4. package/es/HTableBody/Options/Content.js +103 -48
  5. package/es/HTableBody/Options/ContentTree.d.ts +7 -0
  6. package/es/HTableBody/Options/ContentTree.js +41 -0
  7. package/es/HTableBody/Options/Title.d.ts +1 -1
  8. package/es/HTableBody/Options/hooks.d.ts +17 -0
  9. package/es/HTableBody/Options/hooks.js +53 -1
  10. package/es/HTableBody/Options/index.d.ts +1 -1
  11. package/es/HTableBody/Options/index.js +4 -2
  12. package/es/HTableBody/Options/utils.d.ts +8 -1
  13. package/es/HTableBody/Options/utils.js +29 -2
  14. package/es/HTableBody/RowCheckBox/RowItem.d.ts +1 -1
  15. package/es/HTableBody/RowCheckBox/hooks.d.ts +1 -1
  16. package/es/HTableBody/RowRadioBoxSelection.d.ts +1 -1
  17. package/es/HTableBody/hooks/useColData.d.ts +4 -1
  18. package/es/HTableBody/hooks/useColData.js +8 -3
  19. package/es/HTableBody/index.js +10 -4
  20. package/es/HTableBody/modal.d.ts +2 -1
  21. package/es/index.css +4 -0
  22. package/es/modal.d.ts +2 -1
  23. package/lib/HTableBody/HeaderTitle/hooks.d.ts +2 -2
  24. package/lib/HTableBody/Options/Content.d.ts +1 -1
  25. package/lib/HTableBody/Options/Content.js +101 -46
  26. package/lib/HTableBody/Options/ContentTree.d.ts +7 -0
  27. package/lib/HTableBody/Options/ContentTree.js +44 -0
  28. package/lib/HTableBody/Options/Title.d.ts +1 -1
  29. package/lib/HTableBody/Options/hooks.d.ts +17 -0
  30. package/lib/HTableBody/Options/hooks.js +54 -0
  31. package/lib/HTableBody/Options/index.d.ts +1 -1
  32. package/lib/HTableBody/Options/index.js +4 -2
  33. package/lib/HTableBody/Options/utils.d.ts +8 -1
  34. package/lib/HTableBody/Options/utils.js +29 -1
  35. package/lib/HTableBody/RowCheckBox/RowItem.d.ts +1 -1
  36. package/lib/HTableBody/RowCheckBox/hooks.d.ts +1 -1
  37. package/lib/HTableBody/RowRadioBoxSelection.d.ts +1 -1
  38. package/lib/HTableBody/hooks/useColData.d.ts +4 -1
  39. package/lib/HTableBody/hooks/useColData.js +8 -3
  40. package/lib/HTableBody/index.js +10 -4
  41. package/lib/HTableBody/modal.d.ts +2 -1
  42. package/lib/index.css +4 -0
  43. package/lib/modal.d.ts +2 -1
  44. package/package.json +1 -1
  45. package/src/components/HTableBody/HeaderTitle/hooks.ts +47 -42
  46. package/src/components/HTableBody/HeaderTitle/index.tsx +7 -5
  47. package/src/components/HTableBody/Options/Content.tsx +82 -35
  48. package/src/components/HTableBody/Options/ContentTree.tsx +38 -0
  49. package/src/components/HTableBody/Options/Title.tsx +7 -2
  50. package/src/components/HTableBody/Options/hooks.tsx +79 -0
  51. package/src/components/HTableBody/Options/index.tsx +3 -0
  52. package/src/components/HTableBody/Options/modal.d.ts +2 -0
  53. package/src/components/HTableBody/Options/utils.ts +28 -0
  54. package/src/components/HTableBody/RowCheckBox/RowItem.tsx +1 -1
  55. package/src/components/HTableBody/RowCheckBox/hooks.ts +1 -1
  56. package/src/components/HTableBody/RowRadioBoxSelection.tsx +1 -1
  57. package/src/components/HTableBody/hooks/useColData.tsx +9 -2
  58. package/src/components/HTableBody/index.tsx +14 -9
  59. package/src/components/HTableBody/modal.ts +4 -3
  60. package/src/components/hooks/useRowObj.ts +1 -1
  61. package/src/components/index.less +4 -0
  62. package/src/components/modal.ts +3 -2
  63. package/src/pages/Table/index.tsx +50 -20
  64. package/src/components/HTableBody/Options/hooks.ts +0 -24
@@ -1,7 +1,11 @@
1
1
  'use strict';
2
2
 
3
3
  var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
4
+ var _indexOfInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/index-of');
5
+ var jsxRuntime = require('react/jsx-runtime');
4
6
  var React = require('react');
7
+ var utils = require('./utils.js');
8
+ var index = require('../../hooks/index.js');
5
9
 
6
10
  var useCheckKeys = function useCheckKeys(_ref) {
7
11
  var columns = _ref.columns,
@@ -26,6 +30,56 @@ var useCheckKeys = function useCheckKeys(_ref) {
26
30
  return keys;
27
31
  }, [colStatusValue, columns]);
28
32
  };
33
+ var useContentTree = function useContentTree(_ref3) {
34
+ var columns = _ref3.columns,
35
+ matchKey = _ref3.matchKey;
36
+ var titleClass = index.useClassName("hw-table-body-option-setting-content-title");
37
+ return React.useMemo(function () {
38
+ var treeData = [];
39
+ _forEachInstanceProperty(columns).call(columns, function (_ref4) {
40
+ var dataIndex = _ref4.dataIndex,
41
+ title = _ref4.title,
42
+ titleStr = _ref4.titleStr,
43
+ fixed = _ref4.fixed;
44
+ if (!dataIndex) {
45
+ return;
46
+ }
47
+ if (fixed !== matchKey) {
48
+ return;
49
+ }
50
+ var _getItemValue = utils.getItemValue({
51
+ titleStr: titleStr,
52
+ title: title
53
+ }),
54
+ cuTitleStr = _getItemValue.title;
55
+ treeData.push({
56
+ title: jsxRuntime.jsx("div", {
57
+ className: titleClass,
58
+ children: cuTitleStr
59
+ }),
60
+ key: dataIndex.toString()
61
+ });
62
+ });
63
+ return treeData;
64
+ }, [columns]);
65
+ };
66
+ var useTreeKeys = function useTreeKeys(_ref5) {
67
+ var treeData = _ref5.treeData,
68
+ checkKeys = _ref5.checkKeys;
69
+ return React.useMemo(function () {
70
+ var newKeys = [];
71
+ _forEachInstanceProperty(treeData).call(treeData, function (_ref6) {
72
+ var key = _ref6.key;
73
+ var index = _indexOfInstanceProperty(checkKeys).call(checkKeys, key);
74
+ if (index !== -1) {
75
+ newKeys.push(key);
76
+ }
77
+ });
78
+ return newKeys;
79
+ }, [treeData, checkKeys]);
80
+ };
29
81
 
30
82
  exports.useCheckKeys = useCheckKeys;
83
+ exports.useContentTree = useContentTree;
84
+ exports.useTreeKeys = useTreeKeys;
31
85
  // powered by h
@@ -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
- import type { ConfigItemModal } from "../../modal";
1
+ import type { ConfigDataModal, ConfigItemModal } from "../../modal";
2
2
  import React from "react";
3
3
  export declare const getItemValue: (data: ConfigItemModal) => {
4
4
  name?: string | any[] | undefined;
@@ -806,3 +806,10 @@ export declare const getItemValue: (data: ConfigItemModal) => {
806
806
  title: any;
807
807
  dataIndex: ((string | number | (string | number)[]) & import("rc-table/lib/interface").DataIndex) | undefined;
808
808
  };
809
+ interface MoveColProps {
810
+ startKey: string;
811
+ endKey: string;
812
+ data: ConfigDataModal;
813
+ }
814
+ export declare const moveCol: ({ startKey, endKey, data }: MoveColProps) => ConfigItemModal[];
815
+ export {};
@@ -4,12 +4,14 @@ var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
4
4
  var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
5
5
  var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
6
6
  var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
7
- var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
8
7
  var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
9
8
  var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
10
9
  var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
10
+ var _toConsumableArray = require('@babel/runtime-corejs3/helpers/toConsumableArray');
11
11
  var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
12
12
  var _objectWithoutProperties = require('@babel/runtime-corejs3/helpers/objectWithoutProperties');
13
+ var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
14
+ var _spliceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/splice');
13
15
  var React = require('react');
14
16
 
15
17
  var _excluded = ["dataIndex", "title", "titleStr"];
@@ -29,6 +31,32 @@ var getItemValue = function getItemValue(data) {
29
31
  dataIndex: dataIndex
30
32
  }, oData);
31
33
  };
34
+ var moveCol = function moveCol(_ref) {
35
+ var startKey = _ref.startKey,
36
+ endKey = _ref.endKey,
37
+ data = _ref.data;
38
+ var indexArray = [-1, -1];
39
+ _forEachInstanceProperty(data).call(data, function (item, index) {
40
+ var dataIndex = item.dataIndex;
41
+ if (!dataIndex) {
42
+ return;
43
+ }
44
+ if (dataIndex === startKey) {
45
+ indexArray[0] = index;
46
+ }
47
+ if (dataIndex === endKey) {
48
+ indexArray[1] = index;
49
+ }
50
+ });
51
+ var oldIndex = indexArray[0],
52
+ newIndex = indexArray[1];
53
+ var newData = _toConsumableArray(data);
54
+ var oldItem = data[oldIndex];
55
+ _spliceInstanceProperty(newData).call(newData, oldIndex, 1);
56
+ _spliceInstanceProperty(newData).call(newData, newIndex, 0, oldItem);
57
+ return newData;
58
+ };
32
59
 
33
60
  exports.getItemValue = getItemValue;
61
+ exports.moveCol = moveCol;
34
62
  // powered by h
@@ -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 '../modal';
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,3 +1,3 @@
1
1
  /// <reference types="react" />
2
- import { RowRadioSelectionProps } from './modal';
2
+ import type { RowRadioSelectionProps } from "./modal";
3
3
  export declare const RowRadioSelection: ({ data, onChange, index, getCheckboxProps, }: RowRadioSelectionProps) => JSX.Element;
@@ -1,8 +1,11 @@
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>>;
8
+ resetCols: () => void;
6
9
  };
7
10
  interface useColumnsStateTypeModal {
8
11
  columnsState?: ColumnsStateType;
@@ -13,6 +16,6 @@ export declare const useColumnsStateType: ({ columnsState, columns, }: useColumn
13
16
  persistenceKey: string | undefined;
14
17
  value: Record<string, ColumnsState> | undefined;
15
18
  onChange: (keys: string[], notCheck: string[]) => void;
16
- reset: () => void;
19
+ resetCheckCol: () => void;
17
20
  };
18
21
  export {};
@@ -93,8 +93,13 @@ var useCols = function useCols(_ref) {
93
93
  React.useEffect(function () {
94
94
  setCols(changeConfigData(configData));
95
95
  }, [configData, table, rowSelection]);
96
+ var resetCols = function resetCols() {
97
+ setCols(changeConfigData(configData));
98
+ };
96
99
  return {
97
- cols: cols
100
+ cols: cols,
101
+ setCols: setCols,
102
+ resetCols: resetCols
98
103
  };
99
104
  };
100
105
  var useColumnsStateType = function useColumnsStateType(_ref3) {
@@ -133,7 +138,7 @@ var useColumnsStateType = function useColumnsStateType(_ref3) {
133
138
  setSelfValue(newObj);
134
139
  onChange === null || onChange === void 0 || onChange(newObj);
135
140
  };
136
- var reset = function reset() {
141
+ var resetCheckCol = function resetCheckCol() {
137
142
  setSelfValue(initTableColsVal);
138
143
  };
139
144
  return {
@@ -141,7 +146,7 @@ var useColumnsStateType = function useColumnsStateType(_ref3) {
141
146
  persistenceKey: persistenceKey,
142
147
  value: selfValue,
143
148
  onChange: change,
144
- reset: reset
149
+ resetCheckCol: resetCheckCol
145
150
  };
146
151
  };
147
152
 
@@ -28,7 +28,7 @@ var defaultRender = require('./defaultRender.js');
28
28
  var useRowClassName = require('./hooks/useRowClassName.js');
29
29
 
30
30
  var _excluded = ["configData", "pagination", "onPageChange", "rowSelection", "rowKey", "emptyRender", "errorRender", "tableStyle", "paginationStyle", "headerTitle", "options", "actionRender", "affixProps", "goTop", "size", "optionsRender", "paginationActionRender", "localSorter", "columnsState", "tableExtraRender", "table", "onChange", "bordered", "rowClassName"],
31
- _excluded2 = ["value", "onChange", "reset"];
31
+ _excluded2 = ["value", "onChange", "resetCheckCol"];
32
32
  function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
33
33
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context2 = ownKeys(Object(t))).call(_context2, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
34
34
  var Body = (function (bodyProps) {
@@ -92,14 +92,16 @@ 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,
97
+ resetCols = _useCols.resetCols;
96
98
  var _useColumnsStateType = useColData.useColumnsStateType({
97
99
  columnsState: columnsState,
98
100
  columns: cols
99
101
  }),
100
102
  value = _useColumnsStateType.value,
101
103
  onChange = _useColumnsStateType.onChange,
102
- reset = _useColumnsStateType.reset,
104
+ resetCheckCol = _useColumnsStateType.resetCheckCol,
103
105
  selfColStatus = _objectWithoutProperties(_useColumnsStateType, _excluded2);
104
106
  useControl.useSynchronousKeys({
105
107
  selectedRowKeys: selectedRowKeys,
@@ -116,7 +118,11 @@ var Body = (function (bodyProps) {
116
118
  setSizeChange: setCuSize,
117
119
  colStatusValue: value || {},
118
120
  onChange: onChange,
119
- reset: reset
121
+ reset: function reset() {
122
+ resetCheckCol();
123
+ resetCols();
124
+ },
125
+ onDrop: setCols
120
126
  }));
121
127
  var defaultOptionsNode = optionsRender ? optionsRender(optionsNode) : optionsNode;
122
128
  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 React, { Key } from "react";
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/index.css CHANGED
@@ -83,6 +83,10 @@
83
83
  display: -ms-flexbox;
84
84
  display: flex;
85
85
  }
86
+ .ant-hw-table-op-tree-content {
87
+ padding: 6px 6px 6px 0px;
88
+ width: 100%;
89
+ }
86
90
  .ant-hw-table-body-option-tree .ant-tree-treenode {
87
91
  width: 100%;
88
92
  padding-left: 24px !important;
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 React, { Key } from "react";
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@hw-component/table",
3
- "version": "1.9.90",
3
+ "version": "1.9.92",
4
4
  "description": "基于antd二次开发table组件",
5
5
  "keywords": [
6
6
  "table"
@@ -1,47 +1,52 @@
1
- import {MutableRefObject, useEffect, useLayoutEffect, useState} from "react";
1
+ import type { MutableRefObject} from "react";
2
+ import { useEffect, useLayoutEffect, useState } from "react";
2
3
 
3
4
  interface HeaderStyleParams {
4
- bodyRef:MutableRefObject<HTMLDivElement|null>;
5
- titleContentRef:MutableRefObject<HTMLDivElement|null>;
6
- rightNodeRef:MutableRefObject<HTMLDivElement|null>;
5
+ bodyRef: MutableRefObject<HTMLDivElement | null>;
6
+ titleContentRef: MutableRefObject<HTMLDivElement | null>;
7
+ rightNodeRef: MutableRefObject<HTMLDivElement | null>;
7
8
  }
8
9
 
9
- export const useHeaderStyle = ({bodyRef,titleContentRef,rightNodeRef}:HeaderStyleParams) => {
10
- const [style, setStyle] = useState({});
11
- const setHeaderStyle = () => {
12
- const headerWidth = bodyRef.current?.clientWidth || 0;
13
- const titleWidth = titleContentRef.current?.clientWidth || 0;
14
- const rightNodeWidth = rightNodeRef.current?.clientWidth || 0;
15
- if (rightNodeWidth + titleWidth >= headerWidth) {
16
- setStyle({
17
- overflow: "auto",
18
- });
19
- return;
20
- }
21
- setStyle({});
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();
22
34
  };
23
- useLayoutEffect(() => {
24
- setHeaderStyle();
25
- }, []);
26
- useEffect(() => {
27
- const resizeFn = () => {
28
- setHeaderStyle();
29
- };
30
- window.addEventListener("resize", resizeFn);
31
- return () => {
32
- window.removeEventListener("resize", resizeFn);
33
- };
34
- }, []);
35
- useEffect(() => {
36
- const element = titleContentRef.current;
37
- if (!element||!window.ResizeObserver) return;
38
- const observer = new ResizeObserver(() => {
39
- setHeaderStyle();
40
- });
41
- observer.observe(element);
42
- return () => {
43
- observer.disconnect();
44
- }
45
- }, []);
46
- return style;
47
- }
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, useLayoutEffect} from "react";
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 } = useHTableContext();
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;
@@ -1,37 +1,40 @@
1
1
  import { useClassName } from "../../hooks";
2
- import { useMemo } from "react";
3
- import type { ConfigDataModal } from "../../modal";
4
- import { Tree } from "antd";
5
2
  import type { ItemProps } from "./modal";
6
- import { getItemValue } from "./utils";
3
+ import { moveCol } from "./utils";
4
+ import ContentTree from "./ContentTree";
5
+ import { useContentTree, useTreeKeys } from "./hooks";
7
6
 
8
7
  export const ColsSettingContent = ({
9
8
  columns,
10
9
  onCheck,
11
10
  checkKeys,
11
+ onDrop,
12
12
  }: ItemProps) => {
13
13
  const content = useClassName("hw-table-body-option-setting-content");
14
- const titleClass = useClassName("hw-table-body-option-setting-content-title");
15
- const treeClass = useClassName("hw-table-body-option-tree");
16
- const contentTreeData = useMemo(() => {
17
- const treeData: ConfigDataModal = [];
18
- columns.forEach(({ dataIndex, title, titleStr }) => {
19
- if (dataIndex) {
20
- const { title: cuTitleStr } = getItemValue({
21
- titleStr,
22
- title,
23
- });
24
- treeData.push({
25
- title: <div className={titleClass}>{cuTitleStr}</div>,
26
- key: dataIndex.toString(),
27
- });
28
- }
29
- });
30
- return treeData;
31
- }, [columns]);
14
+ const norContentTreeData = useContentTree({ columns });
15
+ const leftContentTreeData = useContentTree({ columns, matchKey: "left" });
16
+ const rightContentTreeData = useContentTree({ columns, matchKey: "right" });
17
+ const norCheckKeys = useTreeKeys({
18
+ treeData: norContentTreeData,
19
+ checkKeys,
20
+ });
21
+ const leftCheckKeys = useTreeKeys({
22
+ treeData: leftContentTreeData,
23
+ checkKeys,
24
+ });
25
+ const rightCheckKeys = useTreeKeys({
26
+ treeData: rightContentTreeData,
27
+ checkKeys,
28
+ });
29
+
32
30
  const check = (keys: string[]) => {
33
31
  const notCheck: string[] = [];
34
- contentTreeData.forEach(({ key }) => {
32
+ const allTreeData = [
33
+ ...leftContentTreeData,
34
+ ...norContentTreeData,
35
+ ...rightContentTreeData,
36
+ ];
37
+ allTreeData.forEach(({ key }) => {
35
38
  const cuKey = key as string;
36
39
  const index = keys.indexOf(cuKey);
37
40
  if (index === -1) {
@@ -40,20 +43,64 @@ export const ColsSettingContent = ({
40
43
  });
41
44
  onCheck(keys, notCheck);
42
45
  };
46
+ const onDropEnd = ({ dragNodesKeys, dropPosition }) => {
47
+ if (dropPosition < 1) {
48
+ return;
49
+ }
50
+ const allTreeData = [
51
+ ...leftContentTreeData,
52
+ ...norContentTreeData,
53
+ ...rightContentTreeData,
54
+ ];
55
+ const [key] = dragNodesKeys;
56
+ const sourceKey = allTreeData[dropPosition - 1].key;
57
+ const newData = moveCol({
58
+ startKey: key,
59
+ endKey: sourceKey as string,
60
+ data: columns,
61
+ });
62
+ onDrop(newData);
63
+ };
43
64
  return (
44
65
  <div className={content}>
45
- <div style={{ paddingTop: 6, paddingBottom: 6 }}>
46
- <Tree
47
- checkable
48
- className={treeClass}
49
- checkedKeys={checkKeys}
50
- onCheck={(key) => {
51
- check(key as string[]);
52
- }}
53
- height={268}
54
- treeData={contentTreeData}
55
- />
56
- </div>
66
+ <ContentTree
67
+ title="固定在左侧"
68
+ treeData={leftContentTreeData}
69
+ checkedKeys={leftCheckKeys}
70
+ onDrop={onDropEnd}
71
+ onCheck={(key) => {
72
+ const curKey = key as string[];
73
+ check([...curKey,...norCheckKeys,...rightCheckKeys]);
74
+ }}
75
+ />
76
+ <ContentTree
77
+ title="不固定"
78
+ treeData={norContentTreeData}
79
+ checkedKeys={norCheckKeys}
80
+ onDrop={({ dragNodesKeys, dropPosition })=>{
81
+ const cuDropPosition=leftContentTreeData.length+dropPosition;
82
+ onDropEnd({dragNodesKeys, dropPosition:cuDropPosition});
83
+ }}
84
+ onCheck={(key) => {
85
+ const curKey = key as string[];
86
+ check([...leftCheckKeys,...curKey,...rightCheckKeys]);
87
+ }}
88
+ />
89
+ <ContentTree
90
+ title="固定在右侧"
91
+ treeData={rightContentTreeData}
92
+ checkedKeys={rightCheckKeys}
93
+ onDrop={({ dragNodesKeys, dropPosition })=>{
94
+ const leftLen=leftContentTreeData.length;
95
+ const norLen=norContentTreeData.length;
96
+ const cuDropPosition=leftLen+norLen+dropPosition;
97
+ onDropEnd({dragNodesKeys, dropPosition:cuDropPosition});
98
+ }}
99
+ onCheck={(key) => {
100
+ const curKey = key as string[];
101
+ check([...leftCheckKeys,...norCheckKeys,...curKey]);
102
+ }}
103
+ />
57
104
  </div>
58
105
  );
59
106
  };
@@ -0,0 +1,38 @@
1
+ import React from "react";
2
+ import { Space, Tree, Typography } from "antd";
3
+ import { useClassName } from "@/components/hooks";
4
+ import type { TreeProps } from "antd/lib/tree/Tree";
5
+
6
+ interface IProps extends TreeProps {
7
+ title: string;
8
+ }
9
+
10
+ export default ({ treeData, checkedKeys, onDrop, onCheck, title }: IProps) => {
11
+ const treeClass = useClassName("hw-table-body-option-tree");
12
+ const treeItemContent = useClassName("hw-table-op-tree-content");
13
+
14
+ if (!treeData?.length) {
15
+ return null;
16
+ }
17
+ return (
18
+ <Space
19
+ className={treeItemContent}
20
+ direction="vertical"
21
+ size={12}
22
+ >
23
+ <Typography.Text type={"secondary"} style={{ paddingLeft: 24 }}>
24
+ {title}
25
+ </Typography.Text>
26
+ <Tree
27
+ checkable
28
+ className={treeClass}
29
+ draggable
30
+ checkedKeys={checkedKeys}
31
+ onDrop={onDrop}
32
+ onCheck={onCheck}
33
+ height={268}
34
+ treeData={treeData}
35
+ />
36
+ </Space>
37
+ );
38
+ };
@@ -2,8 +2,14 @@ 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 = ({
8
+ columns,
9
+ onCheck,
10
+ checkKeys,
11
+ reset,
12
+ }: Omit<ItemProps, "onDrop">) => {
7
13
  const title = useClassName("hw-table-body-option-setting-title");
8
14
  const relArrayKeys = useMemo(() => {
9
15
  const keys: string[] = [];
@@ -17,7 +23,6 @@ export const Title = ({ columns, onCheck, checkKeys, reset }: ItemProps) => {
17
23
  });
18
24
  return keys;
19
25
  }, [columns]);
20
- const allKeys = columns;
21
26
  const allCheck = () => {
22
27
  onCheck(relArrayKeys, []);
23
28
  };