venus-design 1.0.1 → 1.0.2

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.
@@ -335,8 +335,11 @@ export default /*#__PURE__*/React.forwardRef(function (props, ref) {
335
335
  console.log("是退回的流程");
336
336
  setisReturn(true);
337
337
  }
338
+ if (process.env.DUMI_APP_BUILD_ENV === 'development') {
339
+ setVisible(true);
340
+ }
338
341
  findByOption(record, code, name);
339
- case 4:
342
+ case 5:
340
343
  case "end":
341
344
  return _context3.stop();
342
345
  }
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { ExcelCom } from '..';
2
+ import { ExcelCom } from "./..";
3
3
  var Demo = function Demo() {
4
4
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ExcelCom, null));
5
5
  };
@@ -15,6 +15,7 @@ export declare const VENUS_TABLE_ONCELL_TYPE: any;
15
15
  * 表格列的格式化
16
16
  */
17
17
  export declare const VENUS_TABLE_COLUMNRENDER_TYPE: any;
18
+ export declare const VENUS_COLOR: any;
18
19
  /**
19
20
  * 定义一个方法,用于动态添加渲染函数
20
21
  * @param name render名称
@@ -1,3 +1,5 @@
1
+ import "antd/es/tag/style";
2
+ import _Tag from "antd/es/tag";
1
3
  import "antd/es/badge/style";
2
4
  import _Badge from "antd/es/badge";
3
5
  import "antd/es/rate/style";
@@ -453,9 +455,29 @@ export var VENUS_TABLE_COLUMNRENDER_TYPE = {
453
455
  }
454
456
  }, text))];
455
457
  };
458
+ },
459
+ "renderABCD": function renderABCD(column, actions) {
460
+ return function (text, record, _, action) {
461
+ return [/*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_Tag, {
462
+ bordered: false,
463
+ color: VENUS_COLOR[text || "A"] || "cyan"
464
+ }, text))];
465
+ };
456
466
  }
457
467
  };
458
-
468
+ export var VENUS_COLOR = {
469
+ "A": "success",
470
+ "B": "processing",
471
+ "C": "error",
472
+ "D": "warning",
473
+ "E": "magenta",
474
+ "F": "red",
475
+ "J": "volcano",
476
+ "H": "orange",
477
+ "I": "gold",
478
+ "G": "lime",
479
+ "K": "green"
480
+ };
459
481
  /**
460
482
  * 定义一个方法,用于动态添加渲染函数
461
483
  * @param name render名称
@@ -41,6 +41,7 @@ var RangePicker = _DatePicker.RangePicker;
41
41
  import useDeepCompareEffect from 'use-deep-compare-effect';
42
42
  import { groupFields } from "./src/util";
43
43
  import { SelectBysceneIdAndCreateBy } from "../Config/api";
44
+ import { addData } from "../DataView/service";
44
45
  export default function VirtTable(props) {
45
46
  var columns = props.columns,
46
47
  data = props.data,
@@ -88,45 +89,48 @@ export default function VirtTable(props) {
88
89
  selectMode = _useState12[0],
89
90
  setSelectMode = _useState12[1];
90
91
  var pathname = window.location.pathname;
91
-
92
- /* 各编辑器值 */
93
92
  var _useState13 = useState(),
94
93
  _useState14 = _slicedToArray(_useState13, 2),
95
- selectValue = _useState14[0],
96
- setSelectValue = _useState14[1];
94
+ columnsCustomMap = _useState14[0],
95
+ setColumnsCustomMap = _useState14[1];
96
+ /* 各编辑器值 */
97
97
  var _useState15 = useState(),
98
98
  _useState16 = _slicedToArray(_useState15, 2),
99
- numberValue = _useState16[0],
100
- setNumberValue = _useState16[1];
99
+ selectValue = _useState16[0],
100
+ setSelectValue = _useState16[1];
101
101
  var _useState17 = useState(),
102
102
  _useState18 = _slicedToArray(_useState17, 2),
103
- dateValue = _useState18[0],
104
- setDateValue = _useState18[1];
105
- var _useState19 = useState(''),
103
+ numberValue = _useState18[0],
104
+ setNumberValue = _useState18[1];
105
+ var _useState19 = useState(),
106
106
  _useState20 = _slicedToArray(_useState19, 2),
107
- selevelValue = _useState20[0],
108
- setSelevelValue = _useState20[1];
109
- var _useState21 = useState([]),
107
+ dateValue = _useState20[0],
108
+ setDateValue = _useState20[1];
109
+ var _useState21 = useState(''),
110
110
  _useState22 = _slicedToArray(_useState21, 2),
111
- userValue = _useState22[0],
112
- setUserValue = _useState22[1];
111
+ selevelValue = _useState22[0],
112
+ setSelevelValue = _useState22[1];
113
113
  var _useState23 = useState([]),
114
114
  _useState24 = _slicedToArray(_useState23, 2),
115
- deptValue = _useState24[0],
116
- setDeptValue = _useState24[1];
115
+ userValue = _useState24[0],
116
+ setUserValue = _useState24[1];
117
+ var _useState25 = useState([]),
118
+ _useState26 = _slicedToArray(_useState25, 2),
119
+ deptValue = _useState26[0],
120
+ setDeptValue = _useState26[1];
117
121
 
118
122
  // 新增状态:保存所有列的过滤条件
119
- var _useState25 = useState(new Map()),
120
- _useState26 = _slicedToArray(_useState25, 2),
121
- filterMap = _useState26[0],
122
- setFilterMap = _useState26[1];
123
+ var _useState27 = useState(new Map()),
124
+ _useState28 = _slicedToArray(_useState27, 2),
125
+ filterMap = _useState28[0],
126
+ setFilterMap = _useState28[1];
123
127
  /* overlayer 渲染用 */
124
- var _useState27 = useState({
128
+ var _useState29 = useState({
125
129
  views: []
126
130
  }),
127
- _useState28 = _slicedToArray(_useState27, 2),
128
- overlayerViews = _useState28[0],
129
- setOverlayerViews = _useState28[1];
131
+ _useState30 = _slicedToArray(_useState29, 2),
132
+ overlayerViews = _useState30[0],
133
+ setOverlayerViews = _useState30[1];
130
134
  /* 0. 永远保留完整树 */
131
135
  var fullForestRef = useRef(data);
132
136
  useDeepCompareEffect(function () {
@@ -405,7 +409,7 @@ export default function VirtTable(props) {
405
409
  show: false
406
410
  },
407
411
  name: {
408
- fixed: 'left'
412
+ show: false
409
413
  },
410
414
  secLevel: {
411
415
  fixed: 'right',
@@ -434,13 +438,14 @@ export default function VirtTable(props) {
434
438
  while (1) switch (_context2.prev = _context2.next) {
435
439
  case 0:
436
440
  if (!(process.env.DUMI_APP_BUILD_ENV === 'development')) {
437
- _context2.next = 7;
441
+ _context2.next = 8;
438
442
  break;
439
443
  }
440
444
  //@ts-ignore
441
445
  _groupFields = groupFields(costumColumnMap, columns), leftKeys = _groupFields.leftKeys, rightKeys = _groupFields.rightKeys, unfixedKeys = _groupFields.unfixedKeys, left = _groupFields.left, right = _groupFields.right, unfixed = _groupFields.unfixed;
442
446
  /* 按当前勾选值生成完整列并回写 */
443
- fullColumns = [].concat(_toConsumableArray(createColumns(left, [])), _toConsumableArray(createColumns(right, [])), _toConsumableArray(createColumns(unfixed, [])));
447
+ fullColumns = [].concat(_toConsumableArray(createColumns(left, leftKeys)), _toConsumableArray(createColumns(right, rightKeys)), _toConsumableArray(createColumns(unfixed, unfixedKeys)));
448
+ setColumnsCustomMap(costumColumnMap);
444
449
  grid === null || grid === void 0 || grid.loadColumns(fullColumns);
445
450
  setColumnStatus({
446
451
  leftKeys: leftKeys,
@@ -450,19 +455,20 @@ export default function VirtTable(props) {
450
455
  right: right,
451
456
  unfixed: unfixed
452
457
  });
453
- _context2.next = 11;
458
+ _context2.next = 12;
454
459
  break;
455
- case 7:
456
- _context2.next = 9;
460
+ case 8:
461
+ _context2.next = 10;
457
462
  return SelectBysceneIdAndCreateBy(pathname);
458
- case 9:
463
+ case 10:
459
464
  res = _context2.sent;
460
465
  if (res && res.success) {
461
466
  _data3 = res.data || {};
462
467
  /* ****** 2. 分组 + showKeys ****** */
463
468
  _groupFields2 = groupFields(_data3.costumColumnMap, columns), _leftKeys = _groupFields2.leftKeys, _rightKeys = _groupFields2.rightKeys, _unfixedKeys = _groupFields2.unfixedKeys, _left = _groupFields2.left, _right = _groupFields2.right, _unfixed = _groupFields2.unfixed;
464
469
  /* 按当前勾选值生成完整列并回写 */
465
- _fullColumns = [].concat(_toConsumableArray(createColumns(_left, [])), _toConsumableArray(createColumns(_right, [])), _toConsumableArray(createColumns(_unfixed, [])));
470
+ _fullColumns = [].concat(_toConsumableArray(createColumns(_left, _leftKeys)), _toConsumableArray(createColumns(_right, _rightKeys)), _toConsumableArray(createColumns(_unfixed, _unfixedKeys)));
471
+ setColumnsCustomMap(costumColumnMap);
466
472
  grid === null || grid === void 0 || grid.loadColumns(_fullColumns);
467
473
  setColumnStatus({
468
474
  leftKeys: _leftKeys,
@@ -473,7 +479,7 @@ export default function VirtTable(props) {
473
479
  unfixed: _unfixed
474
480
  });
475
481
  }
476
- case 11:
482
+ case 12:
477
483
  case "end":
478
484
  return _context2.stop();
479
485
  }
@@ -484,8 +490,39 @@ export default function VirtTable(props) {
484
490
  };
485
491
  }();
486
492
  useEffect(function () {
487
- getColumnStatus();
488
- }, [pathname]);
493
+ if (grid) {
494
+ getColumnStatus();
495
+ }
496
+ }, [pathname, grid]);
497
+
498
+ /**
499
+ * 更新配置列
500
+ * @param ucolumnStatus
501
+ * @param columns
502
+ */
503
+ var updateColumnStatus = function updateColumnStatus(ucolumnStatus, columns) {
504
+ var _groupFields3 = groupFields(ucolumnStatus, columns),
505
+ leftKeys = _groupFields3.leftKeys,
506
+ rightKeys = _groupFields3.rightKeys,
507
+ unfixedKeys = _groupFields3.unfixedKeys,
508
+ left = _groupFields3.left,
509
+ right = _groupFields3.right,
510
+ unfixed = _groupFields3.unfixed;
511
+ setColumnStatus({
512
+ leftKeys: leftKeys,
513
+ rightKeys: rightKeys,
514
+ unfixedKeys: unfixedKeys,
515
+ left: left,
516
+ right: right,
517
+ unfixed: unfixed
518
+ });
519
+
520
+ //保存显示列
521
+ addData({
522
+ pathName: pathname,
523
+ costumColumnMap: ucolumnStatus
524
+ });
525
+ };
489
526
 
490
527
  /* 编辑器节点 */
491
528
  var editorNode = useMemo(function () {
@@ -621,7 +658,9 @@ export default function VirtTable(props) {
621
658
  className: "virt-table-header-title"
622
659
  }, props.headerTitle), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Tools, _extends({}, props, {
623
660
  //@ts-ignore
624
- gridRef: grid
661
+ gridRef: grid,
662
+ columnsCustomMap: columnsCustomMap,
663
+ updateColumnStatus: updateColumnStatus
625
664
  //@ts-ignore
626
665
  ,
627
666
  columnStatus: columnStatus
@@ -20,8 +20,8 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
20
20
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
21
21
  import React, { useEffect, useMemo, useState } from 'react';
22
22
  import { VerticalAlignTopOutlined, VerticalAlignBottomOutlined, VerticalAlignMiddleOutlined } from '@ant-design/icons';
23
+ import { buildColumnProps, upsertColumnProps } from "../utils";
23
24
  var ColumnSet = function ColumnSet(props) {
24
- console.log(props);
25
25
  var _props$columnStatus = props.columnStatus,
26
26
  left = _props$columnStatus.left,
27
27
  right = _props$columnStatus.right,
@@ -30,7 +30,20 @@ var ColumnSet = function ColumnSet(props) {
30
30
  rightKeys = _props$columnStatus.rightKeys,
31
31
  unfixedKeys = _props$columnStatus.unfixedKeys,
32
32
  columns = props.columns,
33
- gridRef = props.gridRef;
33
+ gridRef = props.gridRef,
34
+ columnsCustomMap = props.columnsCustomMap;
35
+ var _useState = useState(columnsCustomMap),
36
+ _useState2 = _slicedToArray(_useState, 2),
37
+ columnsCustomMapState = _useState2[0],
38
+ setColumnsCustomMapState = _useState2[1];
39
+ var _useState3 = useState(columns),
40
+ _useState4 = _slicedToArray(_useState3, 2),
41
+ columnList = _useState4[0],
42
+ setColumnList = _useState4[1];
43
+ var _useState5 = useState(false),
44
+ _useState6 = _slicedToArray(_useState5, 2),
45
+ firstUpdate = _useState6[0],
46
+ setFirstUpdate = _useState6[1];
34
47
  var pathname = window.location.pathname;
35
48
  /* ****** 1. 静态配置(仅用于首次分组) ****** */
36
49
 
@@ -57,24 +70,23 @@ var ColumnSet = function ColumnSet(props) {
57
70
  }, [unfixed]);
58
71
 
59
72
  /* ****** 4. 勾选受控值 = 当前未隐藏的列 ****** */
60
- var _useState = useState(leftKeys),
61
- _useState2 = _slicedToArray(_useState, 2),
62
- checkedLeft = _useState2[0],
63
- setCheckedLeft = _useState2[1];
64
- var _useState3 = useState(rightKeys),
65
- _useState4 = _slicedToArray(_useState3, 2),
66
- checkedRight = _useState4[0],
67
- setCheckedRight = _useState4[1];
68
- var _useState5 = useState(unfixedKeys),
69
- _useState6 = _slicedToArray(_useState5, 2),
70
- checkedUnfixed = _useState6[0],
71
- setCheckedUnfixed = _useState6[1];
73
+ var _useState7 = useState(leftKeys),
74
+ _useState8 = _slicedToArray(_useState7, 2),
75
+ checkedLeft = _useState8[0],
76
+ setCheckedLeft = _useState8[1];
77
+ var _useState9 = useState(rightKeys),
78
+ _useState10 = _slicedToArray(_useState9, 2),
79
+ checkedRight = _useState10[0],
80
+ setCheckedRight = _useState10[1];
81
+ var _useState11 = useState(unfixedKeys),
82
+ _useState12 = _slicedToArray(_useState11, 2),
83
+ checkedUnfixed = _useState12[0],
84
+ setCheckedUnfixed = _useState12[1];
72
85
  /* ****** 7. 首次/依赖变化后主动回写 ****** */
73
86
  useEffect(function () {
74
87
  var _props$gridRef;
75
88
  /* 按当前勾选值生成完整列并回写 */
76
89
  var fullColumns = [].concat(_toConsumableArray(createColumns(left, checkedLeft)), _toConsumableArray(createColumns(right, checkedRight)), _toConsumableArray(createColumns(unfixed, checkedUnfixed)));
77
- console.log(fullColumns);
78
90
  (_props$gridRef = props.gridRef) === null || _props$gridRef === void 0 || _props$gridRef.loadColumns(fullColumns);
79
91
  // 只在分组依赖变化时执行;checkedXXX 已在 state 初始化,这里直接用即可
80
92
  }, [left, right, unfixed, checkedLeft, checkedRight, checkedUnfixed]);
@@ -102,7 +114,78 @@ var ColumnSet = function ColumnSet(props) {
102
114
  /* ****** 回写父级(用你真实的回调名) ****** */
103
115
  (_props$gridRef2 = props.gridRef) === null || _props$gridRef2 === void 0 || _props$gridRef2.loadColumns(newCols);
104
116
  };
117
+ var onDragEnter = function onDragEnter(info) {
118
+ console.log(info);
119
+ // expandedKeys, set it when controlled is needed
120
+ // setExpandedKeys(info.expandedKeys)
121
+ };
122
+ var onDrop = function onDrop(info) {
123
+ var _props$gridRef3;
124
+ console.log(info);
125
+ var dropKey = info.node.key;
126
+ var dragKey = info.dragNode.key;
127
+ var dropPos = info.node.pos.split('-');
128
+ var dropPosition = info.dropPosition - Number(dropPos[dropPos.length - 1]); // the drop position relative to the drop node, inside 0, top -1, bottom 1
129
+
130
+ var loop = function loop(data, key, callback) {
131
+ for (var _i = 0; _i < data.length; _i++) {
132
+ if (data[_i].key === key) {
133
+ return callback(data[_i], _i, data);
134
+ }
135
+ if (data[_i].children) {
136
+ loop(data[_i].children, key, callback);
137
+ }
138
+ }
139
+ };
140
+ var data = _toConsumableArray(columns);
105
141
 
142
+ // Find dragObject
143
+ var dragObj;
144
+ loop(data, dragKey, function (item, index, arr) {
145
+ arr.splice(index, 1);
146
+ dragObj = item;
147
+ });
148
+ if (!info.dropToGap) {
149
+ // Drop on the content
150
+ loop(data, dropKey, function (item) {
151
+ item.children = item.children || [];
152
+ // where to insert. New item was inserted to the start of the array in this example, but can be anywhere
153
+ item.children.unshift(dragObj);
154
+ });
155
+ } else {
156
+ var ar = [];
157
+ var _i2;
158
+ loop(data, dropKey, function (_item, index, arr) {
159
+ ar = arr;
160
+ _i2 = index;
161
+ });
162
+ if (dropPosition === -1) {
163
+ // Drop on the top of the drop node
164
+ ar.splice(_i2, 0, dragObj);
165
+ } else {
166
+ // Drop on the bottom of the drop node
167
+ ar.splice(_i2 + 1, 0, dragObj);
168
+ }
169
+ }
170
+ var finalMap = buildColumnProps(columns, columnsCustomMapState);
171
+ setColumnsCustomMapState(finalMap);
172
+ setColumnList(data);
173
+ (_props$gridRef3 = props.gridRef) === null || _props$gridRef3 === void 0 || _props$gridRef3.loadColumns(data);
174
+ };
175
+ var onFixed = function onFixed(key, fixed) {
176
+ //@ts-ignore
177
+ var newMap = upsertColumnProps(columnsCustomMapState, _defineProperty({}, key, {
178
+ fixed: fixed
179
+ }));
180
+ setColumnsCustomMapState(newMap);
181
+ };
182
+ useEffect(function () {
183
+ if (firstUpdate) {
184
+ props.updateColumnStatus(columnsCustomMapState, columnList);
185
+ } else {
186
+ setFirstUpdate(true);
187
+ }
188
+ }, [columnsCustomMapState]);
106
189
  /* ****** 6. 统一渲染 ****** */
107
190
  var renderTree = function renderTree(title, data, checked, setChecked, group) {
108
191
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", {
@@ -111,11 +194,19 @@ var ColumnSet = function ColumnSet(props) {
111
194
  className: "draggable-tree",
112
195
  checkable: true,
113
196
  blockNode: true,
197
+ draggable: true,
114
198
  treeData: data,
115
199
  checkedKeys: checked,
116
- onCheck: function onCheck(keys) {
117
- setChecked(keys);
118
- emitChange(keys, group);
200
+ onDragEnter: onDragEnter,
201
+ onDrop: onDrop
202
+ //@ts-ignore
203
+ ,
204
+ onCheck: function onCheck(checkedKeys, e) {
205
+ setChecked(checkedKeys);
206
+ var newMap = upsertColumnProps(columnsCustomMapState, _defineProperty({}, e.node.key, {
207
+ show: e.checked
208
+ }));
209
+ setColumnsCustomMapState(newMap);
119
210
  },
120
211
  titleRender: function titleRender(node) {
121
212
  return /*#__PURE__*/React.createElement("div", {
@@ -124,17 +215,41 @@ var ColumnSet = function ColumnSet(props) {
124
215
  className: "virt-table-header-setting-icon-tree-node-icon"
125
216
  }, group == "unfixed" ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_Tooltip, {
126
217
  title: "\u56FA\u5B9A\u5728\u5217\u9996"
127
- }, /*#__PURE__*/React.createElement(VerticalAlignTopOutlined, null)), /*#__PURE__*/React.createElement(_Tooltip, {
218
+ }, /*#__PURE__*/React.createElement(VerticalAlignTopOutlined, {
219
+ onClick: function onClick() {
220
+ return onFixed(node.key, 'left');
221
+ }
222
+ })), /*#__PURE__*/React.createElement(_Tooltip, {
128
223
  title: "\u56FA\u5B9A\u5728\u5217\u5C3E"
129
- }, /*#__PURE__*/React.createElement(VerticalAlignBottomOutlined, null))) : group == "right" ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_Tooltip, {
224
+ }, /*#__PURE__*/React.createElement(VerticalAlignBottomOutlined, {
225
+ onClick: function onClick() {
226
+ return onFixed(node.key, 'right');
227
+ }
228
+ }))) : group == "right" ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_Tooltip, {
130
229
  title: "\u56FA\u5B9A\u5728\u5217\u9996"
131
- }, /*#__PURE__*/React.createElement(VerticalAlignTopOutlined, null)), /*#__PURE__*/React.createElement(_Tooltip, {
230
+ }, /*#__PURE__*/React.createElement(VerticalAlignTopOutlined, {
231
+ onClick: function onClick() {
232
+ return onFixed(node.key, 'left');
233
+ }
234
+ })), /*#__PURE__*/React.createElement(_Tooltip, {
132
235
  title: "\u4E0D\u56FA\u5B9A"
133
- }, /*#__PURE__*/React.createElement(VerticalAlignMiddleOutlined, null))) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_Tooltip, {
236
+ }, /*#__PURE__*/React.createElement(VerticalAlignMiddleOutlined, {
237
+ onClick: function onClick() {
238
+ return onFixed(node.key, undefined);
239
+ }
240
+ }))) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_Tooltip, {
134
241
  title: "\u4E0D\u56FA\u5B9A"
135
- }, /*#__PURE__*/React.createElement(VerticalAlignMiddleOutlined, null)), /*#__PURE__*/React.createElement(_Tooltip, {
242
+ }, /*#__PURE__*/React.createElement(VerticalAlignMiddleOutlined, {
243
+ onClick: function onClick() {
244
+ return onFixed(node.key, undefined);
245
+ }
246
+ })), /*#__PURE__*/React.createElement(_Tooltip, {
136
247
  title: "\u56FA\u5B9A\u5728\u5217\u5C3E"
137
- }, /*#__PURE__*/React.createElement(VerticalAlignBottomOutlined, null)))));
248
+ }, /*#__PURE__*/React.createElement(VerticalAlignBottomOutlined, {
249
+ onClick: function onClick() {
250
+ return onFixed(node.key, 'right');
251
+ }
252
+ })))));
138
253
  }
139
254
  }));
140
255
  };
@@ -1,22 +1,60 @@
1
1
  import "antd/es/popover/style";
2
2
  import _Popover from "antd/es/popover";
3
+ import "antd/es/tooltip/style";
4
+ import _Tooltip from "antd/es/tooltip";
3
5
  import "antd/es/checkbox/style";
4
6
  import _Checkbox from "antd/es/checkbox";
7
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
8
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
9
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
10
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
11
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
12
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
5
13
  import { SettingOutlined } from '@ant-design/icons';
6
- import React from 'react';
14
+ import React, { useState, useEffect } from 'react';
7
15
  import ColumnSet from "./ColumnSet";
16
+ import { hasHiddenColumn, setShowForAllColumns } from "../utils";
8
17
  var Tools = function Tools(props) {
18
+ var _useState = useState(false),
19
+ _useState2 = _slicedToArray(_useState, 2),
20
+ allStatus = _useState2[0],
21
+ setAllStatus = _useState2[1];
22
+ var checkAll = function checkAll(show) {
23
+ var newMap = setShowForAllColumns(props.columnsCustomMap, props.columns, show);
24
+ props.updateColumnStatus(newMap, props.columns);
25
+ };
26
+ useEffect(function () {
27
+ if (props.columnsCustomMap) {
28
+ setAllStatus(!hasHiddenColumn(props.columnsCustomMap));
29
+ }
30
+ }, [props.columnsCustomMap]);
9
31
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_Popover, {
10
32
  trigger: "click",
11
33
  placement: "bottom",
12
34
  content: /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ColumnSet, props)),
13
35
  title: /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(_Checkbox, {
14
- onChange: function onChange() {}
36
+ indeterminate: allStatus,
37
+ onChange: function onChange(e) {
38
+ if (e.target.checked) {
39
+ checkAll(true);
40
+ } else {
41
+ checkAll(false);
42
+ setAllStatus(false);
43
+ }
44
+ }
15
45
  }, "\u5217\u5C55\u793A"), " ", /*#__PURE__*/React.createElement("a", {
16
- className: "virt-table-header-setting-icon-reset"
46
+ className: "virt-table-header-setting-icon-reset",
47
+ onClick: function onClick() {
48
+ checkAll(true);
49
+ }
17
50
  }, "\u91CD\u7F6E"))
51
+ }, /*#__PURE__*/React.createElement(_Tooltip, {
52
+ title: "\u5217\u8BBE\u7F6E"
18
53
  }, /*#__PURE__*/React.createElement(SettingOutlined, {
54
+ style: {
55
+ color: "#777575ff"
56
+ },
19
57
  className: "virt-table-header-setting-icon"
20
- })));
58
+ }))));
21
59
  };
22
60
  export default Tools;
@@ -41,6 +41,8 @@ export interface ToolsProps {
41
41
  columns: Column[];
42
42
  columnStatus: ColumnStatus;
43
43
  gridRef: EVirtTable;
44
+ updateColumnStatus: (ucolumnStatus: any, columns: Column[]) => void;
45
+ columnsCustomMap: any;
44
46
  }
45
47
  export type TypeCheckbox = 'checkbox-uncheck' | 'checkbox-check' | 'checkbox-check-disabled' | 'checkbox-disabled' | 'checkbox-indeterminate';
46
48
  export type CellType = 'header' | 'body' | 'footer';
@@ -1,2 +1,40 @@
1
1
  export declare function flattenSnap(nodes: any[], flat?: any[]): any[];
2
2
  export declare function pruneTree(nodes: any[], keepSet: Set<any>): any[];
3
+ /**
4
+ * 1. 为每个字段生成 orderBy
5
+ * 2. 用 costumColumnMap 里的配置合并(同名字段出现冲突时,costumColumnMap 优先级高)
6
+ */
7
+ export declare function buildColumnProps(columns: Array<Record<string, any>>, costumColumnMap?: Record<string, Record<string, any>>): Record<string, {
8
+ orderBy: number;
9
+ [k: string]: any;
10
+ }>;
11
+ /**
12
+ * 批量更新或新增 column-map 中的任意属性
13
+ * @param map 原 column-map
14
+ * @param updates key -> 要合并(或新增)的属性对象
15
+ * @returns 新的 column-map(原 map 不变)
16
+ */
17
+ export declare function upsertColumnProps<T extends Record<string, Record<string, any>>>(map: T, updates: Partial<Record<keyof T, Partial<T[keyof T]>>>): T;
18
+ /**
19
+ * 根据传入的 columns 集合,一键给 column-map 统一设置/新增 show 属性
20
+ * 规则:
21
+ * 1. 遍历 columns 里每一项的 key
22
+ * 2. 如果 key 已存在于 map,则合并 show 值
23
+ * 3. 如果 key 不存在,则新增该 key,并把 show 值写进去(其余字段先留空,后续可再 patch)
24
+ * @param map 原 column-map
25
+ * @param columns 列配置数组
26
+ * @param show 要写入的 show 值
27
+ * @returns 新的 column-map(原 map 不变)
28
+ */
29
+ export declare function setShowForAllColumns<T extends Record<string, Record<string, any>>>(map: T, columns: Array<{
30
+ key?: string;
31
+ [k: string]: any;
32
+ }>, show: boolean): T;
33
+ /**
34
+ * 判断 column-map 中是否存在任一列 show === false
35
+ * @param map 列映射表
36
+ * @returns 存在 false 返回 true,否则返回 false
37
+ */
38
+ export declare function hasHiddenColumn(map: Record<string, {
39
+ show?: boolean;
40
+ }>): boolean;
@@ -32,4 +32,91 @@ export function pruneTree(nodes, keepSet) {
32
32
  }
33
33
  return acc;
34
34
  }, []);
35
+ }
36
+
37
+ /**
38
+ * 1. 为每个字段生成 orderBy
39
+ * 2. 用 costumColumnMap 里的配置合并(同名字段出现冲突时,costumColumnMap 优先级高)
40
+ */
41
+ export function buildColumnProps(columns) {
42
+ var costumColumnMap = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
43
+ var res = {};
44
+ columns.forEach(function (col, idx) {
45
+ var key = col.key;
46
+ if (!key) return; // 跳过无 key 的列
47
+
48
+ // 先写入 orderBy
49
+ res[key] = {
50
+ orderBy: idx
51
+ };
52
+
53
+ // 再合并用户自定义配置(同名属性会覆盖 orderBy 以外的字段)
54
+ if (costumColumnMap[key]) {
55
+ Object.assign(res[key], costumColumnMap[key]);
56
+ }
57
+ });
58
+ return res;
59
+ }
60
+
61
+ /**
62
+ * 批量更新或新增 column-map 中的任意属性
63
+ * @param map 原 column-map
64
+ * @param updates key -> 要合并(或新增)的属性对象
65
+ * @returns 新的 column-map(原 map 不变)
66
+ */
67
+ export function upsertColumnProps(map, updates) {
68
+ var clone = _objectSpread({}, map);
69
+ Object.keys(updates).forEach(function (key) {
70
+ var patch = updates[key];
71
+ if (!patch) return;
72
+
73
+ // 已存在 -> 合并;不存在 -> 新增
74
+ clone[key] = clone[key] ? _objectSpread(_objectSpread({}, clone[key]), patch) : _objectSpread({}, patch);
75
+ });
76
+ return clone;
77
+ }
78
+
79
+ /**
80
+ * 根据传入的 columns 集合,一键给 column-map 统一设置/新增 show 属性
81
+ * 规则:
82
+ * 1. 遍历 columns 里每一项的 key
83
+ * 2. 如果 key 已存在于 map,则合并 show 值
84
+ * 3. 如果 key 不存在,则新增该 key,并把 show 值写进去(其余字段先留空,后续可再 patch)
85
+ * @param map 原 column-map
86
+ * @param columns 列配置数组
87
+ * @param show 要写入的 show 值
88
+ * @returns 新的 column-map(原 map 不变)
89
+ */
90
+ export function setShowForAllColumns(map, columns, show) {
91
+ var clone = _objectSpread({}, map);
92
+ columns.forEach(function (col) {
93
+ var key = col.key;
94
+ if (!key) return; // 跳过无 key 的列
95
+
96
+ if (clone[key]) {
97
+ // 已存在 -> 合并 show
98
+ //@ts-ignore
99
+ clone[key] = _objectSpread(_objectSpread({}, clone[key]), {}, {
100
+ show: show
101
+ });
102
+ } else {
103
+ // 不存在 -> 新增,只写 show(后续可再 patch 其它字段)
104
+ //@ts-ignore
105
+ clone[key] = {
106
+ show: show
107
+ };
108
+ }
109
+ });
110
+ return clone;
111
+ }
112
+
113
+ /**
114
+ * 判断 column-map 中是否存在任一列 show === false
115
+ * @param map 列映射表
116
+ * @returns 存在 false 返回 true,否则返回 false
117
+ */
118
+ export function hasHiddenColumn(map) {
119
+ return Object.values(map).some(function (col) {
120
+ return col.show != undefined && col.show === false;
121
+ });
35
122
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "venus-design",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "venus all compoments",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",