@hw-component/table 1.9.91 → 1.9.93

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 (45) hide show
  1. package/.eslintcache +1 -1
  2. package/es/HTableBody/Options/Content.d.ts +1 -1
  3. package/es/HTableBody/Options/Content.js +93 -85
  4. package/es/HTableBody/Options/ContentTree.d.ts +7 -0
  5. package/es/HTableBody/Options/ContentTree.js +41 -0
  6. package/es/HTableBody/Options/Title.d.ts +1 -1
  7. package/es/HTableBody/Options/hooks.d.ts +17 -0
  8. package/es/HTableBody/Options/hooks.js +53 -1
  9. package/es/HTableBody/Options/index.d.ts +1 -1
  10. package/es/HTableBody/Options/utils.d.ts +8 -1
  11. package/es/HTableBody/Options/utils.js +29 -2
  12. package/es/HTableBody/hooks/useColData.d.ts +2 -1
  13. package/es/HTableBody/hooks/useColData.js +7 -3
  14. package/es/HTableBody/index.js +8 -4
  15. package/es/Table.js +1 -1
  16. package/es/index.css +4 -0
  17. package/lib/HTableBody/Options/Content.d.ts +1 -1
  18. package/lib/HTableBody/Options/Content.js +91 -83
  19. package/lib/HTableBody/Options/ContentTree.d.ts +7 -0
  20. package/lib/HTableBody/Options/ContentTree.js +44 -0
  21. package/lib/HTableBody/Options/Title.d.ts +1 -1
  22. package/lib/HTableBody/Options/hooks.d.ts +17 -0
  23. package/lib/HTableBody/Options/hooks.js +54 -0
  24. package/lib/HTableBody/Options/index.d.ts +1 -1
  25. package/lib/HTableBody/Options/utils.d.ts +8 -1
  26. package/lib/HTableBody/Options/utils.js +29 -1
  27. package/lib/HTableBody/hooks/useColData.d.ts +2 -1
  28. package/lib/HTableBody/hooks/useColData.js +7 -3
  29. package/lib/HTableBody/index.js +8 -4
  30. package/lib/Table.js +1 -1
  31. package/lib/index.css +4 -0
  32. package/package.json +1 -1
  33. package/src/components/HTableBody/Options/Content.tsx +81 -76
  34. package/src/components/HTableBody/Options/ContentTree.tsx +34 -0
  35. package/src/components/HTableBody/Options/Title.tsx +6 -1
  36. package/src/components/HTableBody/Options/hooks.tsx +76 -0
  37. package/src/components/HTableBody/Options/index.tsx +1 -3
  38. package/src/components/HTableBody/Options/modal.d.ts +2 -2
  39. package/src/components/HTableBody/Options/utils.ts +28 -0
  40. package/src/components/HTableBody/hooks/useColData.tsx +12 -7
  41. package/src/components/HTableBody/index.tsx +11 -7
  42. package/src/components/Table.tsx +1 -2
  43. package/src/components/index.less +4 -0
  44. package/src/pages/Table/index.tsx +67 -6
  45. 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, onDrop }: 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;
@@ -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
@@ -5,6 +5,7 @@ import type { ColumnsStateType } from "@ant-design/pro-table/es/typing";
5
5
  export declare const useCols: ({ configData, rowSelection, table, bordered, }: HTableProps) => {
6
6
  cols: ConfigDataModal;
7
7
  setCols: import("react").Dispatch<import("react").SetStateAction<ConfigDataModal>>;
8
+ resetCols: () => void;
8
9
  };
9
10
  interface useColumnsStateTypeModal {
10
11
  columnsState?: ColumnsStateType;
@@ -15,6 +16,6 @@ export declare const useColumnsStateType: ({ columnsState, columns, }: useColumn
15
16
  persistenceKey: string | undefined;
16
17
  value: Record<string, ColumnsState> | undefined;
17
18
  onChange: (keys: string[], notCheck: string[]) => void;
18
- reset: () => void;
19
+ resetCheckCol: () => void;
19
20
  };
20
21
  export {};
@@ -93,9 +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
100
  cols: cols,
98
- setCols: setCols
101
+ setCols: setCols,
102
+ resetCols: resetCols
99
103
  };
100
104
  };
101
105
  var useColumnsStateType = function useColumnsStateType(_ref3) {
@@ -134,7 +138,7 @@ var useColumnsStateType = function useColumnsStateType(_ref3) {
134
138
  setSelfValue(newObj);
135
139
  onChange === null || onChange === void 0 || onChange(newObj);
136
140
  };
137
- var reset = function reset() {
141
+ var resetCheckCol = function resetCheckCol() {
138
142
  setSelfValue(initTableColsVal);
139
143
  };
140
144
  return {
@@ -142,7 +146,7 @@ var useColumnsStateType = function useColumnsStateType(_ref3) {
142
146
  persistenceKey: persistenceKey,
143
147
  value: selfValue,
144
148
  onChange: change,
145
- reset: reset
149
+ resetCheckCol: resetCheckCol
146
150
  };
147
151
  };
148
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) {
@@ -93,14 +93,15 @@ var Body = (function (bodyProps) {
93
93
  bordered: bordered
94
94
  }),
95
95
  cols = _useCols.cols,
96
- setCols = _useCols.setCols;
96
+ setCols = _useCols.setCols,
97
+ resetCols = _useCols.resetCols;
97
98
  var _useColumnsStateType = useColData.useColumnsStateType({
98
99
  columnsState: columnsState,
99
100
  columns: cols
100
101
  }),
101
102
  value = _useColumnsStateType.value,
102
103
  onChange = _useColumnsStateType.onChange,
103
- reset = _useColumnsStateType.reset,
104
+ resetCheckCol = _useColumnsStateType.resetCheckCol,
104
105
  selfColStatus = _objectWithoutProperties(_useColumnsStateType, _excluded2);
105
106
  useControl.useSynchronousKeys({
106
107
  selectedRowKeys: selectedRowKeys,
@@ -117,7 +118,10 @@ var Body = (function (bodyProps) {
117
118
  setSizeChange: setCuSize,
118
119
  colStatusValue: value || {},
119
120
  onChange: onChange,
120
- reset: reset,
121
+ reset: function reset() {
122
+ resetCheckCol();
123
+ resetCols();
124
+ },
121
125
  onDrop: setCols
122
126
  }));
123
127
  var defaultOptionsNode = optionsRender ? optionsRender(optionsNode) : optionsNode;
package/lib/Table.js CHANGED
@@ -114,7 +114,7 @@ var Table = (function (_ref) {
114
114
  configData: configData,
115
115
  onFinish: function onFinish(value) {
116
116
  rowSelectionReload();
117
- return run(_objectSpread(_objectSpread(_objectSpread({}, saveParams.old), value), {}, {
117
+ return run(_objectSpread(_objectSpread({}, value), {}, {
118
118
  current: 1
119
119
  }));
120
120
  },
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hw-component/table",
3
- "version": "1.9.91",
3
+ "version": "1.9.93",
4
4
  "description": "基于antd二次开发table组件",
5
5
  "keywords": [
6
6
  "table"
@@ -1,68 +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
- 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
- };
36
7
  export const ColsSettingContent = ({
37
8
  columns,
38
9
  onCheck,
39
10
  checkKeys,
40
- onDrop
11
+ onDrop,
41
12
  }: ItemProps) => {
42
13
  const content = useClassName("hw-table-body-option-setting-content");
43
- const titleClass = useClassName("hw-table-body-option-setting-content-title");
44
- const treeClass = useClassName("hw-table-body-option-tree");
45
-
46
- const contentTreeData = useMemo(() => {
47
- const treeData: ConfigDataModal = [];
48
- columns.forEach(({ dataIndex, title, titleStr }) => {
49
- if (dataIndex) {
50
- const { title: cuTitleStr } = getItemValue({
51
- titleStr,
52
- title,
53
- });
54
- treeData.push({
55
- title: <div className={titleClass}>{cuTitleStr}</div>,
56
- key: dataIndex.toString(),
57
- });
58
- }
59
- });
60
- return treeData;
61
- }, [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
+ });
62
29
 
63
30
  const check = (keys: string[]) => {
64
31
  const notCheck: string[] = [];
65
- contentTreeData.forEach(({ key }) => {
32
+ const allTreeData = [
33
+ ...leftContentTreeData,
34
+ ...norContentTreeData,
35
+ ...rightContentTreeData,
36
+ ];
37
+ allTreeData.forEach(({ key }) => {
66
38
  const cuKey = key as string;
67
39
  const index = keys.indexOf(cuKey);
68
40
  if (index === -1) {
@@ -71,31 +43,64 @@ export const ColsSettingContent = ({
71
43
  });
72
44
  onCheck(keys, notCheck);
73
45
  };
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
- }
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
+ };
83
64
  return (
84
65
  <div className={content}>
85
- <div style={{ paddingTop: 6, paddingBottom: 6 }}>
86
- <Tree
87
- checkable
88
- className={treeClass}
89
- draggable
90
- checkedKeys={checkKeys}
91
- onDrop={onDropEnd}
92
- onCheck={(key) => {
93
- check(key as string[]);
94
- }}
95
- height={268}
96
- treeData={contentTreeData}
97
- />
98
- </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
+ />
99
104
  </div>
100
105
  );
101
106
  };
@@ -0,0 +1,34 @@
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 className={treeItemContent} direction="vertical" size={12}>
19
+ <Typography.Text type={"secondary"} style={{ paddingLeft: 24 }}>
20
+ {title}
21
+ </Typography.Text>
22
+ <Tree
23
+ checkable
24
+ className={treeClass}
25
+ draggable
26
+ checkedKeys={checkedKeys}
27
+ onDrop={onDrop}
28
+ onCheck={onCheck}
29
+ height={268}
30
+ treeData={treeData}
31
+ />
32
+ </Space>
33
+ );
34
+ };
@@ -4,7 +4,12 @@ import type { ItemProps } from "./modal";
4
4
  import { useMemo } from "react";
5
5
 
6
6
  const { Link } = Typography;
7
- export const Title = ({ columns, onCheck, checkKeys, reset }: Omit<ItemProps,"onDrop">) => {
7
+ export const Title = ({
8
+ columns,
9
+ onCheck,
10
+ checkKeys,
11
+ reset,
12
+ }: Omit<ItemProps, "onDrop">) => {
8
13
  const title = useClassName("hw-table-body-option-setting-title");
9
14
  const relArrayKeys = useMemo(() => {
10
15
  const keys: string[] = [];
@@ -0,0 +1,76 @@
1
+ import React, { useEffect, useMemo, useState } from "react";
2
+ import type { IProps, ItemProps } from "@/components/HTableBody/Options/modal";
3
+ import type { ConfigDataModal } from "@/components/modal";
4
+ import { getItemValue } from "@/components/HTableBody/Options/utils";
5
+ import { useClassName } from "@/components/hooks";
6
+
7
+ export const useCheckKeys = ({
8
+ columns,
9
+ colStatusValue,
10
+ }: Pick<IProps, "colStatusValue" | "columns">) => {
11
+ return useMemo(() => {
12
+ const keys: string[] = [];
13
+ columns.forEach((value) => {
14
+ const { dataIndex, hideInTable } = value;
15
+ if (hideInTable || !dataIndex) {
16
+ return;
17
+ }
18
+ const dataIndexStr = dataIndex.toString();
19
+ const { show = true } = colStatusValue[dataIndexStr] || {};
20
+ if (!show) {
21
+ return;
22
+ }
23
+ keys.push(dataIndexStr);
24
+ });
25
+ return keys;
26
+ }, [colStatusValue, columns]);
27
+ };
28
+
29
+ interface UseContentTreeModal {
30
+ columns: ConfigDataModal;
31
+ matchKey?: "right" | "left";
32
+ }
33
+ interface ColDataNode {
34
+ title: React.ReactNode;
35
+ key: string;
36
+ }
37
+ export const useContentTree = ({ columns, matchKey }: UseContentTreeModal) => {
38
+ const titleClass = useClassName("hw-table-body-option-setting-content-title");
39
+ return useMemo<ColDataNode[]>(() => {
40
+ const treeData: ColDataNode[] = [];
41
+ columns.forEach(({ dataIndex, title, titleStr, fixed }) => {
42
+ if (!dataIndex) {
43
+ return;
44
+ }
45
+ if (fixed !== matchKey) {
46
+ return;
47
+ }
48
+ const { title: cuTitleStr } = getItemValue({
49
+ titleStr,
50
+ title,
51
+ });
52
+ treeData.push({
53
+ title: <div className={titleClass}>{cuTitleStr}</div>,
54
+ key: dataIndex.toString(),
55
+ });
56
+ });
57
+ return treeData;
58
+ }, [columns]);
59
+ };
60
+ interface UseTreeKeysModal {
61
+ treeData: ColDataNode[];
62
+ checkKeys: string[];
63
+ }
64
+
65
+ export const useTreeKeys = ({ treeData, checkKeys }: UseTreeKeysModal) => {
66
+ return useMemo(() => {
67
+ const newKeys: string[] = [];
68
+ treeData.forEach(({ key }) => {
69
+ const index = checkKeys.indexOf(key);
70
+ if (index !== -1) {
71
+ newKeys.push(key);
72
+ }
73
+ });
74
+ return newKeys;
75
+ }, [treeData, checkKeys]);
76
+ };
@@ -12,8 +12,6 @@ import { Title } from "./Title";
12
12
  import type { IProps } from "./modal";
13
13
  import { useCheckKeys } from "@/components/HTableBody/Options/hooks";
14
14
 
15
-
16
-
17
15
  export default ({
18
16
  reload,
19
17
  size = "middle",
@@ -24,7 +22,7 @@ export default ({
24
22
  colStatusValue,
25
23
  reset,
26
24
  settingRender,
27
- onDrop
25
+ onDrop,
28
26
  }: IProps) => {
29
27
  const pointer = useClassName([
30
28
  "hw-table-pointer",
@@ -12,7 +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
+ onDrop: (columns: ConfigDataModal) => void;
16
16
  }
17
17
 
18
18
  export interface ItemProps {
@@ -20,5 +20,5 @@ export interface ItemProps {
20
20
  onCheck: (keys: string[], notCheck: string[]) => void;
21
21
  columns: ConfigDataModal;
22
22
  reset?: VoidFunction;
23
- onDrop:(columns:ConfigDataModal)=>void;
23
+ onDrop: (columns: ConfigDataModal) => void;
24
24
  }
@@ -13,3 +13,31 @@ export const getItemValue = (data: ConfigItemModal) => {
13
13
  ...oData,
14
14
  };
15
15
  };
16
+
17
+ interface MoveColProps {
18
+ startKey: string;
19
+ endKey: string;
20
+ data: ConfigDataModal;
21
+ }
22
+
23
+ export const moveCol = ({ startKey, endKey, data }: MoveColProps) => {
24
+ const indexArray = [-1, -1];
25
+ data.forEach((item, index) => {
26
+ const { dataIndex } = item;
27
+ if (!dataIndex) {
28
+ return;
29
+ }
30
+ if (dataIndex === startKey) {
31
+ indexArray[0] = index;
32
+ }
33
+ if (dataIndex === endKey) {
34
+ indexArray[1] = index;
35
+ }
36
+ });
37
+ const [oldIndex, newIndex] = indexArray;
38
+ const newData = [...data];
39
+ const oldItem = data[oldIndex];
40
+ newData.splice(oldIndex, 1);
41
+ newData.splice(newIndex, 0, oldItem);
42
+ return newData;
43
+ };