@para-ui/core 3.0.105 → 3.0.107-rc
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/AutoBox/index.js +5 -9
- package/AutoTips/index.js +4 -11
- package/Breadcrumbs/index.js +7 -11
- package/Button/index.js +8 -12
- package/ButtonGroup/index.js +8 -12
- package/Carousel/index.js +4 -8
- package/Cascader/index.js +7 -11
- package/Checkbox/index.js +4 -8
- package/CheckboxGroup/index.js +4 -8
- package/Collapse/index.js +1 -5
- package/CollapseBox/index.js +4 -8
- package/CollapseLayout/index.js +6 -10
- package/ColorPicker/index.js +0 -2
- package/ComboSelect/index.js +14 -18
- package/Container/index.js +1 -5
- package/DatePicker/index.js +10 -14
- package/Desktop/index.js +10 -14
- package/DragVerify/index.js +6 -10
- package/Drawer/index.js +8 -12
- package/Dropdown/index.js +3 -4
- package/DynamicMultiBox/index.js +15 -19
- package/Empty/index.js +3 -7
- package/Form/index.js +15 -16
- package/FormItem/index.js +15 -16
- package/FunctionModal/index.js +14 -15
- package/GlobalContext/index.js +3 -3
- package/Help/index.js +4 -8
- package/HelperText/index.js +1 -5
- package/InputLang/index.js +11 -15
- package/InputNumber/index.js +4 -8
- package/Label/index.js +4 -8
- package/Loading/index.js +1 -5
- package/Menu/index.js +5 -9
- package/Message/index.js +4 -8
- package/Modal/index.js +10 -17
- package/MultiBox/index.js +10 -14
- package/Notification/index.js +3 -7
- package/OperateBtn/index.js +9 -13
- package/PageHeader/index.js +9 -13
- package/Pagination/index.js +11 -15
- package/ParauiProvider/index.d.ts +1 -0
- package/ParauiProvider/index.js +3 -7
- package/PasswordRules/index.js +3 -7
- package/PopConfirm/index.js +8 -12
- package/Popover/index.js +5 -9
- package/Progress/index.js +2 -6
- package/Querying/index.js +3 -7
- package/README.md +10 -0
- package/Radio/index.js +4 -8
- package/RadioGroup/index.js +4 -8
- package/Search/index.js +9 -13
- package/Select/index.js +11 -15
- package/SelectInput/index.js +11 -12
- package/Selector/index.js +11 -24
- package/SelectorPicker/index.js +12 -16
- package/SingleBox/index.js +10 -14
- package/Slider/index.js +6 -10
- package/Split/index.js +4 -8
- package/Status/index.js +1 -5
- package/Stepper/index.js +3 -7
- package/Styles/theme/theme-api.scss +75 -0
- package/Styles/theme/theme-default.scss +74 -0
- package/Styles/theme/theme-shrcb.scss +80 -0
- package/Styles/theme.scss +1 -69
- package/Switch/index.js +6 -10
- package/Table/index.js +16 -39
- package/Tabs/index.js +9 -13
- package/Tag/index.js +7 -11
- package/TextEditor/index.js +5 -12
- package/TextField/index.js +8 -12
- package/TimePicker/index.js +10 -11
- package/Timeline/index.js +4 -8
- package/Title/index.js +1 -5
- package/ToggleButton/index.js +9 -13
- package/Tooltip/index.js +4 -8
- package/Transfer/index.js +13 -17
- package/Tree/index.js +12 -13
- package/Upload/ImageUpload/index.d.ts +2 -7
- package/Upload/index.js +113 -57
- package/Upload/interface.d.ts +18 -0
- package/_verture/{index-f4f86121.js → closestPolyfill-aa558c48.js} +8 -15
- package/_verture/closestPolyfill-e4aed056.js +1354 -0
- package/_verture/constant-8992bf83.js +10 -0
- package/_verture/{defineProperty-62acccfc.js → defineProperty-19daf078.js} +1 -1
- package/_verture/defineProperty-dbb356cd.js +34 -0
- package/_verture/{index-effca97a.js → index-5ca0cf2c.js} +4 -11
- package/_verture/{index-77f9e0fb.js → index-6217784a.js} +2 -6
- package/_verture/index-78f024fe.js +757 -0
- package/_verture/index-82ba60b5.js +232 -0
- package/_verture/index-8b6ea6cc.js +340 -0
- package/_verture/index-d7a0e820.js +18 -0
- package/_verture/{intl-4a9f1b44.js → intl-1d1097e2.js} +1 -1
- package/_verture/intl-23fe77b7.js +81 -0
- package/_verture/{modalContext-c04790c8.js → modalContext-32a590e2.js} +4 -8
- package/_verture/modalContext-d13603c6.js +197 -0
- package/_verture/{slicedToArray-76060636.js → slicedToArray-d0df4205.js} +1 -1
- package/_verture/slicedToArray-d0e9ca41.js +43 -0
- package/_verture/sortable.esm-476eb33a.js +3791 -0
- package/_verture/{toConsumableArray-81040c9e.js → toConsumableArray-0e19ce18.js} +1 -1
- package/_verture/toConsumableArray-d872f770.js +19 -0
- package/_verture/tslib.es6-85d7d0d5.js +38 -0
- package/_verture/typeof-efd93d53.js +11 -0
- package/_verture/unsupportedIterableToArray-eba4c7dc.js +16 -0
- package/_verture/useFormatMessage-df50b866.js +20 -0
- package/_verture/useGlobalProps-277b28c9.js +11 -0
- package/_verture/usePopupContainer-f7dd18e3.js +68 -0
- package/_verture/util-fb1ffb04.js +18 -0
- package/_verture/{utils-1ffeadec.js → utils-8c2aabfe.js} +1 -1
- package/_verture/utils-a36cfe72.js +92 -0
- package/index.js +20 -22
- package/package.json +4 -1
- package/theme/theme-shrcb.css +14616 -0
- package/theme/theme.css +15012 -0
- package/umd/Breadcrumbs.js +1 -1
- package/umd/Button.js +1 -1
- package/umd/ButtonGroup.js +1 -1
- package/umd/Checkbox.js +1 -1
- package/umd/CheckboxGroup.js +1 -1
- package/umd/CollapseLayout.js +3 -3
- package/umd/ComboSelect.js +2 -2
- package/umd/DatePicker.js +1 -1
- package/umd/Desktop.js +1 -1
- package/umd/DragVerify.js +1 -1
- package/umd/Drawer.js +1 -1
- package/umd/DynamicMultiBox.js +2 -2
- package/umd/Empty.js +1 -1
- package/umd/Form.js +2 -2
- package/umd/FormItem.js +2 -2
- package/umd/FunctionModal.js +4 -4
- package/umd/Help.js +1 -1
- package/umd/InputLang.js +1 -1
- package/umd/InputNumber.js +1 -1
- package/umd/Label.js +1 -1
- package/umd/Menu.js +3 -3
- package/umd/Message.js +1 -1
- package/umd/Modal.js +3 -3
- package/umd/MultiBox.js +1 -1
- package/umd/Notification.js +1 -1
- package/umd/OperateBtn.js +1 -1
- package/umd/PageHeader.js +7 -7
- package/umd/Pagination.js +4 -4
- package/umd/ParauiProvider.js +1 -1
- package/umd/PopConfirm.js +1 -1
- package/umd/Progress.js +1 -1
- package/umd/Radio.js +1 -1
- package/umd/RadioGroup.js +1 -1
- package/umd/Search.js +1 -1
- package/umd/Select.js +1 -1
- package/umd/SelectInput.js +1 -1
- package/umd/Selector.js +1 -1
- package/umd/SelectorPicker.js +1 -1
- package/umd/SingleBox.js +1 -1
- package/umd/Slider.js +1 -1
- package/umd/Stepper.js +4 -4
- package/umd/Switch.js +4 -4
- package/umd/Table.js +2 -2
- package/umd/Tabs.js +1 -1
- package/umd/Tag.js +1 -1
- package/umd/TextEditor.js +1 -1
- package/umd/TextField.js +1 -1
- package/umd/TimePicker.js +1 -1
- package/umd/Timeline.js +1 -1
- package/umd/Title.js +1 -1
- package/umd/ToggleButton.js +1 -1
- package/umd/Transfer.js +1 -1
- package/umd/Tree.js +1 -1
- package/umd/Upload.js +5 -5
- package/_verture/index-a369ca3f.js +0 -4
- package/_verture/style-inject.es-300983ab.js +0 -28
- /package/_verture/{constant-66aa48a1.js → constant-0ef8de65.js} +0 -0
- /package/_verture/{index-65bbd1e4.js → index-178adec2.js} +0 -0
- /package/_verture/{index-beef914f.js → index-485070a0.js} +0 -0
- /package/_verture/{sortable.esm-49896035.js → sortable.esm-30288b43.js} +0 -0
- /package/_verture/{tslib.es6-55ed4bd2.js → tslib.es6-575049a5.js} +0 -0
- /package/_verture/{typeof-498dd2b1.js → typeof-d4922fc6.js} +0 -0
- /package/_verture/{unsupportedIterableToArray-cb478f24.js → unsupportedIterableToArray-878ef803.js} +0 -0
- /package/_verture/{useFormatMessage-703f8b20.js → useFormatMessage-24a86ca6.js} +0 -0
- /package/_verture/{useGlobalProps-1b846a65.js → useGlobalProps-13b65974.js} +0 -0
- /package/_verture/{usePopupContainer-87febeb9.js → usePopupContainer-6db7e9f3.js} +0 -0
- /package/_verture/{util-7e1fb1e2.js → util-10192b53.js} +0 -0
|
@@ -0,0 +1,1354 @@
|
|
|
1
|
+
import { _ as _toConsumableArray } from './toConsumableArray-d872f770.js';
|
|
2
|
+
import { _ as _defineProperty } from './defineProperty-19daf078.js';
|
|
3
|
+
import { _ as _slicedToArray } from './slicedToArray-d0e9ca41.js';
|
|
4
|
+
import { r as regenerator } from './index-8b6ea6cc.js';
|
|
5
|
+
import { _ as __rest, a as __awaiter } from './tslib.es6-575049a5.js';
|
|
6
|
+
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
7
|
+
import React__default, { isValidElement, cloneElement, useRef, useState, useImperativeHandle, useEffect, useMemo } from 'react';
|
|
8
|
+
import RcTree from 'rc-tree';
|
|
9
|
+
import clsx from 'clsx';
|
|
10
|
+
import { _ as _typeof } from './typeof-d4922fc6.js';
|
|
11
|
+
import LoadingOutlined from '@para-ui/icons/LoadingF';
|
|
12
|
+
import FileOutlined from '@para-ui/icons/Document';
|
|
13
|
+
import SolidArrowDown from '@para-ui/icons/DownTriangleF';
|
|
14
|
+
import { Radio } from '../Radio/index.js';
|
|
15
|
+
import { $ as $prefixCls } from './constant-0ef8de65.js';
|
|
16
|
+
import ReactDOM from 'react-dom';
|
|
17
|
+
import EditOutlinedIcon from '@para-ui/icons/EditFile';
|
|
18
|
+
import AddOutlinedIcon from '@para-ui/icons/PlusCircle';
|
|
19
|
+
import Delete from '@para-ui/icons/Delete';
|
|
20
|
+
import Forbid from '@para-ui/icons/Forbid';
|
|
21
|
+
import { Tooltip } from '../Tooltip/index.js';
|
|
22
|
+
import { UUID, Request } from '@paraview/lib';
|
|
23
|
+
import { u as useFormatMessage } from './useFormatMessage-df50b866.js';
|
|
24
|
+
import MoreOutlinedIcon from '@para-ui/icons/MoreCircle';
|
|
25
|
+
import Empty from '../Empty/index.js';
|
|
26
|
+
import { Loading } from '../Loading/index.js';
|
|
27
|
+
import AutoTips from '../AutoTips/index.js';
|
|
28
|
+
|
|
29
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
30
|
+
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); }
|
|
31
|
+
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; }
|
|
32
|
+
//深拷贝包括函数
|
|
33
|
+
var deepCopy = function deepCopy(target) {
|
|
34
|
+
var copyedObjs = []; //此数组解决了循环引用和相同引用的问题,它存放已经递归到的目标对象
|
|
35
|
+
function _deepCopy(target) {
|
|
36
|
+
if (_typeof(target) !== 'object' || !target) {
|
|
37
|
+
return target;
|
|
38
|
+
}
|
|
39
|
+
for (var i = 0; i < copyedObjs.length; i++) {
|
|
40
|
+
if (copyedObjs[i].target === target) {
|
|
41
|
+
return copyedObjs[i].copyTarget;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
var obj = {};
|
|
45
|
+
if (Array.isArray(target)) {
|
|
46
|
+
obj = []; //处理target是数组的情况
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
copyedObjs.push({
|
|
50
|
+
target: target,
|
|
51
|
+
copyTarget: obj
|
|
52
|
+
});
|
|
53
|
+
Object.keys(target).forEach(function (key) {
|
|
54
|
+
if (obj[key]) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
obj[key] = _deepCopy(target[key]);
|
|
58
|
+
});
|
|
59
|
+
return obj;
|
|
60
|
+
}
|
|
61
|
+
return _deepCopy(target);
|
|
62
|
+
};
|
|
63
|
+
//树结构转扁平
|
|
64
|
+
var flatten = function flatten(data) {
|
|
65
|
+
return data ? data.reduce(function (arr, _a) {
|
|
66
|
+
var _a$children = _a.children,
|
|
67
|
+
children = _a$children === void 0 ? [] : _a$children,
|
|
68
|
+
rest = __rest(_a, ["children"]);
|
|
69
|
+
return arr.concat([rest], flatten(children));
|
|
70
|
+
}, []) : [];
|
|
71
|
+
};
|
|
72
|
+
//数组转树结构
|
|
73
|
+
var convert = function convert(list) {
|
|
74
|
+
var rFiled = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
75
|
+
key: 'key',
|
|
76
|
+
parentId: 'parentId'
|
|
77
|
+
};
|
|
78
|
+
var res = [];
|
|
79
|
+
var map = list.reduce(function (acc, v) {
|
|
80
|
+
return acc[v[rFiled.key]] = v, acc;
|
|
81
|
+
}, {});
|
|
82
|
+
var _iterator = _createForOfIteratorHelper(list),
|
|
83
|
+
_step;
|
|
84
|
+
try {
|
|
85
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
86
|
+
var item = _step.value;
|
|
87
|
+
var parentId = item[rFiled.parentId];
|
|
88
|
+
if (parentId in map) {
|
|
89
|
+
var parent = map[parentId];
|
|
90
|
+
parent.children = parent.children || [];
|
|
91
|
+
parent.children.push(item);
|
|
92
|
+
} else {
|
|
93
|
+
res.push(item);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
} catch (err) {
|
|
97
|
+
_iterator.e(err);
|
|
98
|
+
} finally {
|
|
99
|
+
_iterator.f();
|
|
100
|
+
}
|
|
101
|
+
return res;
|
|
102
|
+
};
|
|
103
|
+
//本地过滤时,转为树结构
|
|
104
|
+
var convertByFilter = function convertByFilter(sourceList, filterList) {
|
|
105
|
+
var rFiled = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
|
|
106
|
+
key: 'key',
|
|
107
|
+
parentId: 'parentId'
|
|
108
|
+
};
|
|
109
|
+
var obj = {};
|
|
110
|
+
var map = sourceList.reduce(function (acc, v) {
|
|
111
|
+
return acc[v[rFiled.key]] = v, acc;
|
|
112
|
+
}, {});
|
|
113
|
+
var filterMap = filterList.reduce(function (acc, v) {
|
|
114
|
+
return acc[v[rFiled.key]] = v, acc;
|
|
115
|
+
}, {});
|
|
116
|
+
var _iterator2 = _createForOfIteratorHelper(sourceList),
|
|
117
|
+
_step2;
|
|
118
|
+
try {
|
|
119
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
120
|
+
var item = _step2.value;
|
|
121
|
+
if (item[rFiled.key] in filterMap) _handleNode(item);
|
|
122
|
+
}
|
|
123
|
+
} catch (err) {
|
|
124
|
+
_iterator2.e(err);
|
|
125
|
+
} finally {
|
|
126
|
+
_iterator2.f();
|
|
127
|
+
}
|
|
128
|
+
function _handleNode(node) {
|
|
129
|
+
obj[node[rFiled.key]] = node;
|
|
130
|
+
var parent = map[node[rFiled.parentId]];
|
|
131
|
+
if (!parent) return;
|
|
132
|
+
obj[parent[rFiled.key]] = parent;
|
|
133
|
+
if (parent[rFiled.parentId]) _handleNode(parent);
|
|
134
|
+
}
|
|
135
|
+
var tempArr = Object.keys(obj).reduce(function (acc, curr) {
|
|
136
|
+
return acc.concat(obj[curr]);
|
|
137
|
+
}, []);
|
|
138
|
+
return convert(tempArr);
|
|
139
|
+
};
|
|
140
|
+
//获得checkedkeys
|
|
141
|
+
var getCheckedKeys = function getCheckedKeys(cKeys) {
|
|
142
|
+
if (!Array.isArray(cKeys)) {
|
|
143
|
+
return cKeys.checked;
|
|
144
|
+
}
|
|
145
|
+
return cKeys;
|
|
146
|
+
};
|
|
147
|
+
//获得halfchecked keys
|
|
148
|
+
var getHalfCheckedKeys = function getHalfCheckedKeys(cKeys) {
|
|
149
|
+
if (!Array.isArray(cKeys)) {
|
|
150
|
+
return cKeys.halfChecked;
|
|
151
|
+
}
|
|
152
|
+
return [];
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
var getCollapsedHeight = function getCollapsedHeight() {
|
|
156
|
+
return {
|
|
157
|
+
height: 0,
|
|
158
|
+
opacity: 0
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
var getRealHeight = function getRealHeight(node) {
|
|
162
|
+
return {
|
|
163
|
+
height: node.scrollHeight,
|
|
164
|
+
opacity: 1
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
var getCurrentHeight = function getCurrentHeight(node) {
|
|
168
|
+
return {
|
|
169
|
+
height: node.offsetHeight
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
var skipOpacityTransition = function skipOpacityTransition(_, event) {
|
|
173
|
+
return event.propertyName === 'height';
|
|
174
|
+
};
|
|
175
|
+
var collapseMotion = {
|
|
176
|
+
motionName: "".concat($prefixCls, "-tree-motion-collapse"),
|
|
177
|
+
onAppearStart: getCollapsedHeight,
|
|
178
|
+
onEnterStart: getCollapsedHeight,
|
|
179
|
+
onAppearActive: getRealHeight,
|
|
180
|
+
onEnterActive: getRealHeight,
|
|
181
|
+
onLeaveStart: getCurrentHeight,
|
|
182
|
+
onLeaveActive: getCollapsedHeight,
|
|
183
|
+
onAppearEnd: skipOpacityTransition,
|
|
184
|
+
onEnterEnd: skipOpacityTransition,
|
|
185
|
+
onLeaveEnd: skipOpacityTransition,
|
|
186
|
+
motionDeadline: 500
|
|
187
|
+
};
|
|
188
|
+
function renderSwitcherIcon(prefixCls, switcherIcon, showLine, _ref) {
|
|
189
|
+
var isLeaf = _ref.isLeaf,
|
|
190
|
+
expanded = _ref.expanded,
|
|
191
|
+
loading = _ref.loading;
|
|
192
|
+
_ref.eventKey;
|
|
193
|
+
if (loading) {
|
|
194
|
+
return jsx(LoadingOutlined, {
|
|
195
|
+
className: "".concat(prefixCls, "-switcher-loading-icon")
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
var showLeafIcon;
|
|
199
|
+
if (showLine && _typeof(showLine) === 'object') {
|
|
200
|
+
showLeafIcon = showLine.showLeafIcon;
|
|
201
|
+
}
|
|
202
|
+
if (isLeaf) {
|
|
203
|
+
if (showLine) {
|
|
204
|
+
if (_typeof(showLine) === 'object' && !showLeafIcon) {
|
|
205
|
+
return jsx("span", {
|
|
206
|
+
className: "".concat(prefixCls, "-switcher-leaf-line")
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
return jsx(FileOutlined, {
|
|
210
|
+
className: "".concat(prefixCls, "-switcher-line-icon")
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
var switcherCls = "".concat(prefixCls, "-switcher-icon");
|
|
216
|
+
if ( /*#__PURE__*/isValidElement(switcherIcon)) {
|
|
217
|
+
return /*#__PURE__*/cloneElement(switcherIcon, {
|
|
218
|
+
className: clsx(switcherIcon.props.className || '', switcherCls)
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
if (switcherIcon) {
|
|
222
|
+
return switcherIcon;
|
|
223
|
+
}
|
|
224
|
+
if (showLine) {
|
|
225
|
+
return expanded ? jsx(SolidArrowDown, {
|
|
226
|
+
className: "".concat(prefixCls, "-switcher-line-icon")
|
|
227
|
+
}) : jsx(SolidArrowDown, {
|
|
228
|
+
className: "".concat(prefixCls, "-switcher-line-icon")
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
return jsx(SolidArrowDown, {
|
|
232
|
+
className: switcherCls
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
function renderTreeNodeIcon(nodeProps, radioable, checkedKey, replaceFields) {
|
|
236
|
+
var _a;
|
|
237
|
+
if (!radioable) return null;
|
|
238
|
+
var key = replaceFields.key;
|
|
239
|
+
var isChecked = ((_a = nodeProps.data) === null || _a === void 0 ? void 0 : _a[key]) === checkedKey;
|
|
240
|
+
return jsx(Radio, {
|
|
241
|
+
className: "".concat($prefixCls, "-tree-node-radio"),
|
|
242
|
+
checked: isChecked
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
var en = {
|
|
247
|
+
loadMore: 'Load more',
|
|
248
|
+
add: 'Add',
|
|
249
|
+
edit: 'Edit',
|
|
250
|
+
disabled: 'Disabled',
|
|
251
|
+
delete: 'Delete'
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
var zh = {
|
|
255
|
+
loadMore: '加载更多',
|
|
256
|
+
add: '新增',
|
|
257
|
+
edit: '编辑',
|
|
258
|
+
disabled: '禁用',
|
|
259
|
+
delete: '删除'
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
var localeJson = {
|
|
263
|
+
zh: zh,
|
|
264
|
+
en: en
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
//默认扇形按钮图标
|
|
268
|
+
var getIconMap = function getIconMap(intl) {
|
|
269
|
+
return {
|
|
270
|
+
'add': {
|
|
271
|
+
icon: jsx(AddOutlinedIcon, {}),
|
|
272
|
+
text: intl({
|
|
273
|
+
id: 'add'
|
|
274
|
+
})
|
|
275
|
+
},
|
|
276
|
+
'edit': {
|
|
277
|
+
icon: jsx(EditOutlinedIcon, {}),
|
|
278
|
+
text: intl({
|
|
279
|
+
id: 'edit'
|
|
280
|
+
})
|
|
281
|
+
},
|
|
282
|
+
'enable': {
|
|
283
|
+
icon: jsx(Forbid, {}),
|
|
284
|
+
text: intl({
|
|
285
|
+
id: 'disabled'
|
|
286
|
+
})
|
|
287
|
+
},
|
|
288
|
+
'del': {
|
|
289
|
+
icon: jsx(Delete, {}),
|
|
290
|
+
text: intl({
|
|
291
|
+
id: 'delete'
|
|
292
|
+
})
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
};
|
|
296
|
+
//action array
|
|
297
|
+
var toActionArr = function toActionArr(actions, nodeData, IconMap) {
|
|
298
|
+
if (actions === undefined || actions === false) return [];
|
|
299
|
+
if (actions === true) {
|
|
300
|
+
return Object.keys(IconMap).map(function (k) {
|
|
301
|
+
return Object.assign(Object.assign({}, IconMap[k]), {
|
|
302
|
+
action: k
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
var arr = [];
|
|
307
|
+
Object.keys(actions).forEach(function (k) {
|
|
308
|
+
var aItem = actions[k];
|
|
309
|
+
if (k !== 'customizeActions') {
|
|
310
|
+
//非自定义
|
|
311
|
+
if (_typeof(aItem) === 'object') {
|
|
312
|
+
if (typeof aItem.show === 'function') {
|
|
313
|
+
if (aItem.show(nodeData)) arr.push(Object.assign(Object.assign(Object.assign({}, IconMap[k]), aItem), {
|
|
314
|
+
action: k
|
|
315
|
+
}));
|
|
316
|
+
} else {
|
|
317
|
+
arr.push(Object.assign(Object.assign(Object.assign({}, IconMap[k]), aItem), {
|
|
318
|
+
action: k
|
|
319
|
+
}));
|
|
320
|
+
}
|
|
321
|
+
} else if (typeof aItem === 'function') {
|
|
322
|
+
if (aItem(nodeData)) {
|
|
323
|
+
arr.push(Object.assign(Object.assign({}, IconMap[k]), {
|
|
324
|
+
action: k
|
|
325
|
+
}));
|
|
326
|
+
}
|
|
327
|
+
} else if (aItem) {
|
|
328
|
+
arr.push(Object.assign(Object.assign({}, IconMap[k]), {
|
|
329
|
+
action: k
|
|
330
|
+
}));
|
|
331
|
+
}
|
|
332
|
+
} else if (Array.isArray(aItem) && aItem.length) {
|
|
333
|
+
//自定义按钮
|
|
334
|
+
aItem.forEach(function (_) {
|
|
335
|
+
if (typeof _.show === 'function') {
|
|
336
|
+
if (_.show(nodeData)) {
|
|
337
|
+
arr.push(_);
|
|
338
|
+
}
|
|
339
|
+
} else arr.push(_);
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
return arr;
|
|
344
|
+
};
|
|
345
|
+
//tree node 操作栏
|
|
346
|
+
var OperateBar = function OperateBar(props) {
|
|
347
|
+
var actionsCallback = props.actionsCallback,
|
|
348
|
+
opRef = props.opRef,
|
|
349
|
+
mouseInRef = props.mouseInRef,
|
|
350
|
+
showActions = props.showActions,
|
|
351
|
+
onRemove = props.onRemove;
|
|
352
|
+
var portalRef = useRef(null); //portal
|
|
353
|
+
var uidRef = useRef(UUID().replace(/-/g, '')); //portal uid
|
|
354
|
+
var _useState = useState({}),
|
|
355
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
356
|
+
nodeData = _useState2[0],
|
|
357
|
+
setNodeData = _useState2[1]; //节点数据
|
|
358
|
+
var _useState3 = useState(false),
|
|
359
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
360
|
+
isRender = _useState4[0],
|
|
361
|
+
setIsRender = _useState4[1]; //重新渲染
|
|
362
|
+
var _useState5 = useState(false),
|
|
363
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
364
|
+
hasPortal = _useState6[0],
|
|
365
|
+
setHasPortal = _useState6[1]; //创建插槽portal
|
|
366
|
+
var opRefCurrent = opRef.current;
|
|
367
|
+
var intl = useFormatMessage('Tree', localeJson);
|
|
368
|
+
//扇形位置
|
|
369
|
+
var getPosition = function getPosition(length, deg) {
|
|
370
|
+
var left = Math.round(Math.sin(Math.PI / 180 * deg) * length) + "px";
|
|
371
|
+
var top = -Math.round(Math.cos(Math.PI / 180 * deg) * length + 12) + "px";
|
|
372
|
+
return {
|
|
373
|
+
"left": left,
|
|
374
|
+
"top": top
|
|
375
|
+
};
|
|
376
|
+
};
|
|
377
|
+
//计算扇形半径
|
|
378
|
+
var calcRadius = function calcRadius(num) {
|
|
379
|
+
if (num <= 4) return 40;else if (num === 5) return 60;else if (num > 5 && num < 7) return 80;else return 100;
|
|
380
|
+
};
|
|
381
|
+
//更新外层容器样式
|
|
382
|
+
var updateContainerStyles = function updateContainerStyles(C, r) {
|
|
383
|
+
var _a, _b;
|
|
384
|
+
var _ref = ((_b = (_a = opRef.current) === null || _a === void 0 ? void 0 : _a.anchorEl) === null || _b === void 0 ? void 0 : _b.getBoundingClientRect()) || {},
|
|
385
|
+
top = _ref.top,
|
|
386
|
+
left = _ref.left,
|
|
387
|
+
height = _ref.height;
|
|
388
|
+
var w = r + 24 + 12;
|
|
389
|
+
var h = r * 2 + 24 + 12;
|
|
390
|
+
top = top - h / 2 + height / 2;
|
|
391
|
+
C.style.cssText = "\n position: fixed;\n width:".concat(w, "px;\n height: ").concat(h, "px;\n top: ").concat(top, "px;\n left: ").concat(left, "px;\n ");
|
|
392
|
+
};
|
|
393
|
+
//计算角度
|
|
394
|
+
var getActionsAngle = function getActionsAngle(num, i) {
|
|
395
|
+
var interval = 0;
|
|
396
|
+
var deg = 0;
|
|
397
|
+
if (num === 4) {
|
|
398
|
+
interval = 60;
|
|
399
|
+
deg = i * interval;
|
|
400
|
+
} else if (num === 3) {
|
|
401
|
+
interval = 30;
|
|
402
|
+
deg = (2 * i + 1) * interval;
|
|
403
|
+
} else if (num === 2) {
|
|
404
|
+
interval = 60;
|
|
405
|
+
deg = (i + 1) * interval;
|
|
406
|
+
} else if (num === 1) {
|
|
407
|
+
deg = 90;
|
|
408
|
+
} else if (num === 5) {
|
|
409
|
+
interval = 45;
|
|
410
|
+
deg = i * interval;
|
|
411
|
+
} else if (num > 5 && num <= 7) {
|
|
412
|
+
interval = 30;
|
|
413
|
+
deg = i * interval;
|
|
414
|
+
} else if (num > 7) {
|
|
415
|
+
interval = 20;
|
|
416
|
+
deg = i * interval;
|
|
417
|
+
}
|
|
418
|
+
return deg;
|
|
419
|
+
};
|
|
420
|
+
//扇形展开
|
|
421
|
+
var sectorAndRotate = function sectorAndRotate() {
|
|
422
|
+
var _a;
|
|
423
|
+
var portal = document.getElementById(uidRef.current);
|
|
424
|
+
var container = (_a = portal === null || portal === void 0 ? void 0 : portal.getElementsByClassName('sector-item-container')) === null || _a === void 0 ? void 0 : _a[0];
|
|
425
|
+
var items = (container === null || container === void 0 ? void 0 : container.childNodes) || [];
|
|
426
|
+
var parentContainer = container === null || container === void 0 ? void 0 : container.parentNode;
|
|
427
|
+
var r = calcRadius(items.length);
|
|
428
|
+
if (parentContainer) {
|
|
429
|
+
updateContainerStyles(parentContainer, r);
|
|
430
|
+
}
|
|
431
|
+
for (var i = 0; i < items.length; i++) {
|
|
432
|
+
var item = items[i];
|
|
433
|
+
item.style.transition = ".3s";
|
|
434
|
+
item.style.opacity = 1;
|
|
435
|
+
//计算角度
|
|
436
|
+
var deg = getActionsAngle(items.length, i);
|
|
437
|
+
var _getPosition = getPosition(r, deg),
|
|
438
|
+
left = _getPosition.left,
|
|
439
|
+
top = _getPosition.top;
|
|
440
|
+
item.style.transform = "translate(".concat(left, ",").concat(top, ")");
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
//扇形收缩
|
|
444
|
+
var sectorAndRotateReverse = function sectorAndRotateReverse() {
|
|
445
|
+
var _a, _b;
|
|
446
|
+
var portal = document.getElementById(uidRef.current);
|
|
447
|
+
var container = (_a = portal === null || portal === void 0 ? void 0 : portal.getElementsByClassName('sector-item-container')) === null || _a === void 0 ? void 0 : _a[0];
|
|
448
|
+
var items = (container === null || container === void 0 ? void 0 : container.childNodes) || [];
|
|
449
|
+
for (var i = 0; i < items.length; i++) {
|
|
450
|
+
var item = items[i];
|
|
451
|
+
item.style.transition = ".3s";
|
|
452
|
+
item.style.transform = "translate(0,0)";
|
|
453
|
+
item.style.opacity = 0;
|
|
454
|
+
}
|
|
455
|
+
(_b = portal === null || portal === void 0 ? void 0 : portal.parentNode) === null || _b === void 0 ? void 0 : _b.removeChild(portal);
|
|
456
|
+
setHasPortal(false);
|
|
457
|
+
};
|
|
458
|
+
//显示扇形
|
|
459
|
+
var onShowSector = function onShowSector(nodeData, isShow) {
|
|
460
|
+
if (isShow) {
|
|
461
|
+
setNodeData(nodeData);
|
|
462
|
+
sectorAndRotate();
|
|
463
|
+
} else {
|
|
464
|
+
sectorAndRotateReverse();
|
|
465
|
+
}
|
|
466
|
+
};
|
|
467
|
+
//鼠标进入扇形
|
|
468
|
+
var onMouseInSector = function onMouseInSector() {
|
|
469
|
+
mouseInRef.current = true;
|
|
470
|
+
};
|
|
471
|
+
//鼠标离开扇形
|
|
472
|
+
var onMouseLeaveSector = function onMouseLeaveSector() {
|
|
473
|
+
onRemove === null || onRemove === void 0 ? void 0 : onRemove(opRefCurrent.anchorEl);
|
|
474
|
+
};
|
|
475
|
+
//操作按钮点击回调
|
|
476
|
+
var handleNodeActions = function handleNodeActions(nodeData, type, evt) {
|
|
477
|
+
evt.stopPropagation();
|
|
478
|
+
actionsCallback === null || actionsCallback === void 0 ? void 0 : actionsCallback(nodeData, type, evt);
|
|
479
|
+
};
|
|
480
|
+
//渲染操作栏
|
|
481
|
+
var renderOperateBar = function renderOperateBar() {
|
|
482
|
+
var actionArr = toActionArr(showActions, nodeData, getIconMap(intl));
|
|
483
|
+
if (!(actionArr === null || actionArr === void 0 ? void 0 : actionArr.length)) return null;
|
|
484
|
+
return actionArr.map(function (item, idx) {
|
|
485
|
+
var _ref2 = item !== null && item !== void 0 ? item : {},
|
|
486
|
+
action = _ref2.action,
|
|
487
|
+
text = _ref2.text,
|
|
488
|
+
icon = _ref2.icon;
|
|
489
|
+
return jsx(Tooltip, Object.assign({
|
|
490
|
+
title: text
|
|
491
|
+
}, {
|
|
492
|
+
children: jsx("li", Object.assign({
|
|
493
|
+
className: clsx('sector-item', {
|
|
494
|
+
'sector-item--del': action === 'del'
|
|
495
|
+
}),
|
|
496
|
+
onClick: function onClick(evt) {
|
|
497
|
+
return handleNodeActions(nodeData, action, evt);
|
|
498
|
+
}
|
|
499
|
+
}, {
|
|
500
|
+
children: icon
|
|
501
|
+
}))
|
|
502
|
+
}), idx);
|
|
503
|
+
});
|
|
504
|
+
};
|
|
505
|
+
//透传mouse enter 事件
|
|
506
|
+
useImperativeHandle(opRef, function () {
|
|
507
|
+
return Object.assign(Object.assign({}, opRefCurrent), {
|
|
508
|
+
uid: uidRef.current,
|
|
509
|
+
onShowSector: onShowSector
|
|
510
|
+
});
|
|
511
|
+
});
|
|
512
|
+
useEffect(function () {
|
|
513
|
+
//创建portal
|
|
514
|
+
var createPortal = function createPortal() {
|
|
515
|
+
var portal = document.getElementById(uidRef.current);
|
|
516
|
+
if (!portal) {
|
|
517
|
+
portal = document.createElement('div');
|
|
518
|
+
portal.id = uidRef.current;
|
|
519
|
+
portal.style.position = 'fixed';
|
|
520
|
+
portal.style.top = '-9999px';
|
|
521
|
+
portal.style.zIndex = 1500;
|
|
522
|
+
document.body.appendChild(portal);
|
|
523
|
+
setHasPortal(true);
|
|
524
|
+
}
|
|
525
|
+
setIsRender(true);
|
|
526
|
+
portalRef.current = portal;
|
|
527
|
+
};
|
|
528
|
+
if (!hasPortal) createPortal();
|
|
529
|
+
}, [hasPortal]);
|
|
530
|
+
//销毁
|
|
531
|
+
useEffect(function () {
|
|
532
|
+
return function () {
|
|
533
|
+
var _a, _b;
|
|
534
|
+
(_b = (_a = portalRef.current) === null || _a === void 0 ? void 0 : _a.parentNode) === null || _b === void 0 ? void 0 : _b.removeChild(portalRef.current);
|
|
535
|
+
setHasPortal(false);
|
|
536
|
+
};
|
|
537
|
+
}, []);
|
|
538
|
+
return jsx(Fragment, {
|
|
539
|
+
children: isRender && /*#__PURE__*/ReactDOM.createPortal(jsx("div", Object.assign({
|
|
540
|
+
className: "sector-container",
|
|
541
|
+
onMouseLeave: onMouseLeaveSector,
|
|
542
|
+
onMouseEnter: onMouseInSector
|
|
543
|
+
}, {
|
|
544
|
+
children: jsx("ul", Object.assign({
|
|
545
|
+
className: "sector-item-container"
|
|
546
|
+
}, {
|
|
547
|
+
children: renderOperateBar()
|
|
548
|
+
}))
|
|
549
|
+
})), portalRef.current)
|
|
550
|
+
});
|
|
551
|
+
};
|
|
552
|
+
|
|
553
|
+
//默认分页信息
|
|
554
|
+
var defaultPageSize = {
|
|
555
|
+
page: 1,
|
|
556
|
+
size: 10
|
|
557
|
+
};
|
|
558
|
+
//tree 组件
|
|
559
|
+
var Tree = /*#__PURE__*/React__default.forwardRef(function (props, ref) {
|
|
560
|
+
var url = props.url,
|
|
561
|
+
ctx = props.ctx,
|
|
562
|
+
_props$params = props.params,
|
|
563
|
+
params = _props$params === void 0 ? null : _props$params,
|
|
564
|
+
_props$method = props.method,
|
|
565
|
+
method = _props$method === void 0 ? 'GET' : _props$method,
|
|
566
|
+
headers = props.headers,
|
|
567
|
+
requestCallback = props.requestCallback,
|
|
568
|
+
refresh = props.refresh,
|
|
569
|
+
_props$replaceFields = props.replaceFields,
|
|
570
|
+
replaceFields = _props$replaceFields === void 0 ? {
|
|
571
|
+
key: 'key',
|
|
572
|
+
parentId: 'parentId',
|
|
573
|
+
children: 'children',
|
|
574
|
+
title: 'title',
|
|
575
|
+
loadKey: 'key'
|
|
576
|
+
} : _props$replaceFields,
|
|
577
|
+
originTreeData = props.treeData,
|
|
578
|
+
className = props.className,
|
|
579
|
+
showIcon = props.showIcon,
|
|
580
|
+
_icon = props.icon,
|
|
581
|
+
showLine = props.showLine,
|
|
582
|
+
_switcherIcon = props.switcherIcon,
|
|
583
|
+
blockNode = props.blockNode,
|
|
584
|
+
checkable = props.checkable,
|
|
585
|
+
selectable = props.selectable,
|
|
586
|
+
_props$radioable = props.radioable,
|
|
587
|
+
radioable = _props$radioable === void 0 ? false : _props$radioable,
|
|
588
|
+
_props$showRadio = props.showRadio,
|
|
589
|
+
showRadio = _props$showRadio === void 0 ? true : _props$showRadio,
|
|
590
|
+
_props$checkStrictly = props.checkStrictly,
|
|
591
|
+
checkStrictly = _props$checkStrictly === void 0 ? false : _props$checkStrictly,
|
|
592
|
+
actionsCallback = props.actionsCallback,
|
|
593
|
+
showActions = props.showActions,
|
|
594
|
+
checkedKeys = props.checkedKeys,
|
|
595
|
+
defaultCheckedKeys = props.defaultCheckedKeys,
|
|
596
|
+
expandedKeys = props.expandedKeys,
|
|
597
|
+
defaultExpandedKeys = props.defaultExpandedKeys,
|
|
598
|
+
loadedKeys = props.loadedKeys,
|
|
599
|
+
onCheck = props.onCheck,
|
|
600
|
+
onExpand = props.onExpand,
|
|
601
|
+
_props$asyncLoad = props.asyncLoad,
|
|
602
|
+
asyncLoad = _props$asyncLoad === void 0 ? false : _props$asyncLoad,
|
|
603
|
+
_props$pagination = props.pagination,
|
|
604
|
+
pagination = _props$pagination === void 0 ? false : _props$pagination,
|
|
605
|
+
_props$pageSize = props.pageSize,
|
|
606
|
+
pageSize = _props$pageSize === void 0 ? defaultPageSize : _props$pageSize,
|
|
607
|
+
loadData = props.loadData,
|
|
608
|
+
_props$localFilter = props.localFilter,
|
|
609
|
+
localFilter = _props$localFilter === void 0 ? false : _props$localFilter,
|
|
610
|
+
localParams = props.localParams,
|
|
611
|
+
onFilter = props.onFilter,
|
|
612
|
+
_props$loadMoreNode = props.loadMoreNode,
|
|
613
|
+
loadMoreNode = _props$loadMoreNode === void 0 ? null : _props$loadMoreNode,
|
|
614
|
+
paramsCallback = props.paramsCallback,
|
|
615
|
+
titleRender = props.titleRender,
|
|
616
|
+
emptyProps = props.emptyProps,
|
|
617
|
+
notFoundContent = props.notFoundContent,
|
|
618
|
+
wrapperClassName = props.wrapperClassName,
|
|
619
|
+
wrapperStyle = props.wrapperStyle,
|
|
620
|
+
_props$showLoading = props.showLoading,
|
|
621
|
+
showLoading = _props$showLoading === void 0 ? true : _props$showLoading,
|
|
622
|
+
_props$tipMaxWidth = props.tipMaxWidth,
|
|
623
|
+
tipMaxWidth = _props$tipMaxWidth === void 0 ? 500 : _props$tipMaxWidth,
|
|
624
|
+
onLoadedKey = props.onLoadedKey;
|
|
625
|
+
var _useState = useState([]),
|
|
626
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
627
|
+
treeData = _useState2[0],
|
|
628
|
+
setTreeData = _useState2[1]; //树数据
|
|
629
|
+
var _useState3 = useState([]),
|
|
630
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
631
|
+
inCheckedKeys = _useState4[0],
|
|
632
|
+
setInCheckedKeys = _useState4[1]; //选中keys
|
|
633
|
+
var _useState5 = useState([]),
|
|
634
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
635
|
+
inExpandedKeysKeys = _useState6[0],
|
|
636
|
+
setInExpandedKeys = _useState6[1]; //展开keys
|
|
637
|
+
var opRef = useRef({}); //操作栏
|
|
638
|
+
var mouseInSectorRef = useRef(false); //是否鼠标进入扇形
|
|
639
|
+
var timeSectorRef = useRef(-1); //定时显示扇形
|
|
640
|
+
var nodesRef = useRef([]); //保存节点状态
|
|
641
|
+
var prefixCls = "".concat($prefixCls, "-tree"); //tree容器前缀
|
|
642
|
+
var treeMapRef = useRef({}); //tree map
|
|
643
|
+
var treeOriDataRef = useRef([]); //tree origin data
|
|
644
|
+
var nPageSize = Object.assign(Object.assign({}, defaultPageSize), pageSize);
|
|
645
|
+
var halfCheckedKeys = useRef([]); //半选keys
|
|
646
|
+
var intl = useFormatMessage('Tree', localeJson);
|
|
647
|
+
var _useState7 = useState(false),
|
|
648
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
649
|
+
loading = _useState8[0],
|
|
650
|
+
setLoading = _useState8[1];
|
|
651
|
+
var firstRender = useRef(true); //是否第一次渲染
|
|
652
|
+
var _useState9 = useState([]),
|
|
653
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
654
|
+
inLoadedKeys = _useState10[0],
|
|
655
|
+
setInLoadKeys = _useState10[1];
|
|
656
|
+
//新属性
|
|
657
|
+
var newProps = Object.assign(Object.assign({}, props), {
|
|
658
|
+
showLine: Boolean(showLine),
|
|
659
|
+
checkStrictly: radioable || checkStrictly,
|
|
660
|
+
showIcon: radioable || showIcon
|
|
661
|
+
});
|
|
662
|
+
//生成class
|
|
663
|
+
var makeCls = function makeCls() {
|
|
664
|
+
var _clsx;
|
|
665
|
+
return clsx((_clsx = {}, _defineProperty(_clsx, "".concat(prefixCls, "-icon-hide"), !showIcon), _defineProperty(_clsx, "".concat(prefixCls, "-block-node"), blockNode), _defineProperty(_clsx, "".concat(prefixCls, "-unselectable"), !selectable), _defineProperty(_clsx, "".concat(prefixCls, "-radioable"), radioable), _defineProperty(_clsx, "".concat(prefixCls, "-radioable-showradio"), radioable && showRadio), _clsx), className);
|
|
666
|
+
};
|
|
667
|
+
//格式化treeData 替换显示字段
|
|
668
|
+
var formatTreeData = function formatTreeData(treeData) {
|
|
669
|
+
function recursive(dataList) {
|
|
670
|
+
var _ref = replaceFields || {},
|
|
671
|
+
key = _ref.key,
|
|
672
|
+
title = _ref.title,
|
|
673
|
+
children = _ref.children,
|
|
674
|
+
parentId = _ref.parentId;
|
|
675
|
+
dataList.forEach(function (item) {
|
|
676
|
+
var _a;
|
|
677
|
+
if (key) item.key = item[key];
|
|
678
|
+
if (title) item.title = item[title];
|
|
679
|
+
if (children) item.children = item[children];
|
|
680
|
+
if (parentId) item.parentId = item[parentId];
|
|
681
|
+
if ((_a = item.children) === null || _a === void 0 ? void 0 : _a.length) recursive(item.children);
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
if (replaceFields) recursive(treeData);
|
|
685
|
+
return treeData;
|
|
686
|
+
};
|
|
687
|
+
//内部 tree title render
|
|
688
|
+
var internalTitleRender = function internalTitleRender(nodeData) {
|
|
689
|
+
if (nodeData.moreFlag) {
|
|
690
|
+
//加载更多节点
|
|
691
|
+
return jsx("span", Object.assign({
|
|
692
|
+
className: "".concat($prefixCls, "-tree-title-wrapper"),
|
|
693
|
+
title: ''
|
|
694
|
+
}, {
|
|
695
|
+
children: jsx(AutoTips, Object.assign({
|
|
696
|
+
tipMaxWidth: tipMaxWidth
|
|
697
|
+
}, {
|
|
698
|
+
children: nodeData.title
|
|
699
|
+
}))
|
|
700
|
+
}));
|
|
701
|
+
}
|
|
702
|
+
return jsxs("span", Object.assign({
|
|
703
|
+
className: "".concat($prefixCls, "-tree-title-wrapper"),
|
|
704
|
+
onMouseEnter: handleTreeNodeMEnter,
|
|
705
|
+
onMouseLeave: handleTreeNodeMLeave,
|
|
706
|
+
onClick: handleTreeNodeClick,
|
|
707
|
+
title: blockNode ? '' : undefined
|
|
708
|
+
}, {
|
|
709
|
+
children: [jsx(AutoTips, Object.assign({
|
|
710
|
+
tipMaxWidth: tipMaxWidth
|
|
711
|
+
}, {
|
|
712
|
+
children: typeof titleRender === 'function' ? titleRender(nodeData) : nodeData.title
|
|
713
|
+
})), !!showActions && jsx("div", Object.assign({
|
|
714
|
+
className: "sector-anchor",
|
|
715
|
+
onMouseEnter: function onMouseEnter(evt) {
|
|
716
|
+
return handleSectorMEnter(nodeData, evt);
|
|
717
|
+
},
|
|
718
|
+
onMouseLeave: handleSectorMLeave
|
|
719
|
+
}, {
|
|
720
|
+
children: jsx(MoreOutlinedIcon, {})
|
|
721
|
+
}))]
|
|
722
|
+
}));
|
|
723
|
+
};
|
|
724
|
+
//tree node mouse enter
|
|
725
|
+
var handleTreeNodeMEnter = function handleTreeNodeMEnter(evt) {
|
|
726
|
+
evt.stopPropagation();
|
|
727
|
+
clearNodesState();
|
|
728
|
+
var _currTarget = evt.currentTarget;
|
|
729
|
+
if (_currTarget) {
|
|
730
|
+
var pClsx = ".".concat($prefixCls, "-tree-node-content-wrapper");
|
|
731
|
+
var cParentEl = _currTarget.closest(pClsx);
|
|
732
|
+
nodesRef.current.push(cParentEl);
|
|
733
|
+
showMoreActionIcon(cParentEl, true);
|
|
734
|
+
}
|
|
735
|
+
};
|
|
736
|
+
//tree node mouse leave
|
|
737
|
+
var handleTreeNodeMLeave = function handleTreeNodeMLeave(evt) {
|
|
738
|
+
evt.stopPropagation();
|
|
739
|
+
clearNodesState();
|
|
740
|
+
var _currTarget = evt.currentTarget;
|
|
741
|
+
if (_currTarget) {
|
|
742
|
+
var pClsx = ".".concat($prefixCls, "-tree-node-content-wrapper");
|
|
743
|
+
var cParentEl = _currTarget.closest(pClsx);
|
|
744
|
+
showMoreActionIcon(cParentEl, false);
|
|
745
|
+
}
|
|
746
|
+
};
|
|
747
|
+
// Tree node Click
|
|
748
|
+
var handleTreeNodeClick = function handleTreeNodeClick() {
|
|
749
|
+
var _a;
|
|
750
|
+
if (!showActions) return;
|
|
751
|
+
// 点击tree node 的时候 rc 内部会把node节点的样式重写,导致之前逻辑添加的样式不存在,需要点击的时候加上样式
|
|
752
|
+
if (((_a = nodesRef.current) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
753
|
+
// 需要滞后到下次事件循环
|
|
754
|
+
setTimeout(function () {
|
|
755
|
+
nodesRef.current.forEach(function (el) {
|
|
756
|
+
showMoreActionIcon(el, true);
|
|
757
|
+
});
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
};
|
|
761
|
+
//节点显示更多图标
|
|
762
|
+
var showMoreActionIcon = function showMoreActionIcon(cParentEl, isShow) {
|
|
763
|
+
if (!cParentEl) return;
|
|
764
|
+
if (isShow) {
|
|
765
|
+
cParentEl === null || cParentEl === void 0 ? void 0 : cParentEl.classList.add("".concat($prefixCls, "-tree-node-content-wrapper--active"));
|
|
766
|
+
} else {
|
|
767
|
+
cParentEl === null || cParentEl === void 0 ? void 0 : cParentEl.classList.remove("".concat($prefixCls, "-tree-node-content-wrapper--active"));
|
|
768
|
+
}
|
|
769
|
+
};
|
|
770
|
+
//mouse enter sector
|
|
771
|
+
var handleSectorMEnter = function handleSectorMEnter(nodeData, evt) {
|
|
772
|
+
evt.stopPropagation();
|
|
773
|
+
var _currTarget = evt.currentTarget;
|
|
774
|
+
opRef.current.anchorEl = _currTarget;
|
|
775
|
+
timeSectorRef.current = setTimeout(function () {
|
|
776
|
+
clearTimeout(timeSectorRef.current);
|
|
777
|
+
showSector(_currTarget, nodeData);
|
|
778
|
+
}, 300);
|
|
779
|
+
};
|
|
780
|
+
//mouse sector leave
|
|
781
|
+
var handleSectorMLeave = function handleSectorMLeave(evt) {
|
|
782
|
+
evt.stopPropagation();
|
|
783
|
+
clearTimeout(timeSectorRef.current);
|
|
784
|
+
var _anchor = evt.currentTarget;
|
|
785
|
+
var timer = setTimeout(function () {
|
|
786
|
+
clearTimeout(timer);
|
|
787
|
+
if (!mouseInSectorRef.current) {
|
|
788
|
+
removeSector(_anchor);
|
|
789
|
+
}
|
|
790
|
+
}, 300);
|
|
791
|
+
};
|
|
792
|
+
//显示扇形
|
|
793
|
+
var showSector = function showSector(anchorEl, nodeData) {
|
|
794
|
+
var _a, _b;
|
|
795
|
+
var portalRoot = document.getElementById(opRef.current.uid);
|
|
796
|
+
anchorEl.classList.add('sector-anchor--active');
|
|
797
|
+
if (portalRoot) {
|
|
798
|
+
var container = portalRoot.querySelector('.sector-container');
|
|
799
|
+
if (container) {
|
|
800
|
+
(_b = (_a = opRef.current) === null || _a === void 0 ? void 0 : _a.onShowSector) === null || _b === void 0 ? void 0 : _b.call(_a, nodeData, true);
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
};
|
|
804
|
+
//移除扇形
|
|
805
|
+
var removeSector = function removeSector(anchorEl) {
|
|
806
|
+
var _a, _b;
|
|
807
|
+
if (anchorEl) {
|
|
808
|
+
anchorEl.classList.remove('sector-anchor--active');
|
|
809
|
+
(_b = (_a = opRef.current) === null || _a === void 0 ? void 0 : _a.onShowSector) === null || _b === void 0 ? void 0 : _b.call(_a, {}, false);
|
|
810
|
+
}
|
|
811
|
+
};
|
|
812
|
+
//离开扇形回调
|
|
813
|
+
var handleOnRemove = function handleOnRemove(anchorEl) {
|
|
814
|
+
if (anchorEl) {
|
|
815
|
+
var pCls = ".".concat($prefixCls, "-tree-node-content-wrapper");
|
|
816
|
+
var cParentEl = anchorEl.closest(pCls);
|
|
817
|
+
showMoreActionIcon(cParentEl, false);
|
|
818
|
+
removeSector(anchorEl);
|
|
819
|
+
}
|
|
820
|
+
};
|
|
821
|
+
//清除节点状态
|
|
822
|
+
var clearNodesState = function clearNodesState() {
|
|
823
|
+
var _a;
|
|
824
|
+
if ((_a = nodesRef.current) === null || _a === void 0 ? void 0 : _a.length) {
|
|
825
|
+
nodesRef.current.forEach(function (el) {
|
|
826
|
+
var _a;
|
|
827
|
+
(_a = el === null || el === void 0 ? void 0 : el.classList) === null || _a === void 0 ? void 0 : _a.remove("".concat($prefixCls, "-tree-node-content-wrapper--active"));
|
|
828
|
+
});
|
|
829
|
+
nodesRef.current.length = 0;
|
|
830
|
+
}
|
|
831
|
+
};
|
|
832
|
+
//内部check
|
|
833
|
+
var internalCheck = function internalCheck(checkedKeys, e) {
|
|
834
|
+
var _a;
|
|
835
|
+
var temp = [];
|
|
836
|
+
var halfChecked = [];
|
|
837
|
+
if (radioable) {
|
|
838
|
+
//单选
|
|
839
|
+
var node = e.node;
|
|
840
|
+
var key = (_a = replaceFields.key) !== null && _a !== void 0 ? _a : 'key';
|
|
841
|
+
if (e.checked) temp = [node[key]];
|
|
842
|
+
} else if (checkStrictly) {
|
|
843
|
+
//严格模式
|
|
844
|
+
temp = checkedKeys.checked;
|
|
845
|
+
halfChecked = checkedKeys.halfChecked;
|
|
846
|
+
halfCheckedKeys.current = halfChecked;
|
|
847
|
+
} else {
|
|
848
|
+
temp = checkedKeys;
|
|
849
|
+
halfChecked = e.halfCheckedKeys;
|
|
850
|
+
}
|
|
851
|
+
if (!('checkedKeys' in props)) {
|
|
852
|
+
setInCheckedKeys(temp);
|
|
853
|
+
}
|
|
854
|
+
onCheck === null || onCheck === void 0 ? void 0 : onCheck(temp, e, halfChecked);
|
|
855
|
+
};
|
|
856
|
+
//展开节点
|
|
857
|
+
var internalExpand = function internalExpand(expandedKeys, e) {
|
|
858
|
+
if (!('expandedKeys' in props)) {
|
|
859
|
+
setInExpandedKeys(_toConsumableArray(expandedKeys));
|
|
860
|
+
}
|
|
861
|
+
onExpand === null || onExpand === void 0 ? void 0 : onExpand(expandedKeys, e);
|
|
862
|
+
};
|
|
863
|
+
//请求树数据
|
|
864
|
+
var requestTreeData = function requestTreeData() {
|
|
865
|
+
var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
866
|
+
return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee() {
|
|
867
|
+
var tParams, m, opts, _yield$Request, data, err;
|
|
868
|
+
return regenerator.wrap(function _callee$(_context) {
|
|
869
|
+
while (1) switch (_context.prev = _context.next) {
|
|
870
|
+
case 0:
|
|
871
|
+
if (url) {
|
|
872
|
+
_context.next = 2;
|
|
873
|
+
break;
|
|
874
|
+
}
|
|
875
|
+
return _context.abrupt("return", []);
|
|
876
|
+
case 2:
|
|
877
|
+
showLoading && setLoading(true);
|
|
878
|
+
tParams = (paramsCallback === null || paramsCallback === void 0 ? void 0 : paramsCallback(params)) || params;
|
|
879
|
+
m = method === null || method === void 0 ? void 0 : method.toUpperCase();
|
|
880
|
+
opts = _defineProperty({
|
|
881
|
+
url: url,
|
|
882
|
+
ctx: ctx,
|
|
883
|
+
method: m
|
|
884
|
+
}, m === 'GET' ? 'params' : 'data', tParams || {});
|
|
885
|
+
if (headers) opts.headers = headers;
|
|
886
|
+
_context.next = 9;
|
|
887
|
+
return Request(opts);
|
|
888
|
+
case 9:
|
|
889
|
+
_yield$Request = _context.sent;
|
|
890
|
+
data = _yield$Request.data;
|
|
891
|
+
err = _yield$Request.err;
|
|
892
|
+
//分页数据格式 {list,page,size,total},否则 []
|
|
893
|
+
showLoading && setLoading(false);
|
|
894
|
+
if (!err) {
|
|
895
|
+
_context.next = 15;
|
|
896
|
+
break;
|
|
897
|
+
}
|
|
898
|
+
return _context.abrupt("return", pagination ? {} : []);
|
|
899
|
+
case 15:
|
|
900
|
+
return _context.abrupt("return", pagination ? data.data || {} : data.data || []);
|
|
901
|
+
case 16:
|
|
902
|
+
case "end":
|
|
903
|
+
return _context.stop();
|
|
904
|
+
}
|
|
905
|
+
}, _callee);
|
|
906
|
+
}));
|
|
907
|
+
};
|
|
908
|
+
//加载更多节点数据
|
|
909
|
+
var getLoadMoreData = function getLoadMoreData() {
|
|
910
|
+
return {
|
|
911
|
+
key: String((Math.random() * 1000000 | 0) + Date.now()),
|
|
912
|
+
title: intl({
|
|
913
|
+
id: 'loadMore'
|
|
914
|
+
}),
|
|
915
|
+
checkable: false,
|
|
916
|
+
disableCheckbox: true,
|
|
917
|
+
isLeaf: true,
|
|
918
|
+
selectable: false,
|
|
919
|
+
icon: null,
|
|
920
|
+
moreFlag: true
|
|
921
|
+
};
|
|
922
|
+
};
|
|
923
|
+
//渲染加载更多节点
|
|
924
|
+
var renderLoadMoreNode = function renderLoadMoreNode(dataNode) {
|
|
925
|
+
return jsx("span", Object.assign({
|
|
926
|
+
className: "".concat($prefixCls, "-tree-treenode-more-wrapper"),
|
|
927
|
+
onClick: function onClick(e) {
|
|
928
|
+
e.stopPropagation();
|
|
929
|
+
onLoadData(dataNode);
|
|
930
|
+
}
|
|
931
|
+
}, {
|
|
932
|
+
children: loadMoreNode || dataNode.title
|
|
933
|
+
}));
|
|
934
|
+
};
|
|
935
|
+
//更新tree数据
|
|
936
|
+
var updateTreeData = function updateTreeData(list, key, children, moreFlag) {
|
|
937
|
+
//root节点
|
|
938
|
+
if (key === 'ROOT_KEY') {
|
|
939
|
+
list.pop(); //删除加载更多节点
|
|
940
|
+
return list.concat(children);
|
|
941
|
+
}
|
|
942
|
+
return list.map(function (node) {
|
|
943
|
+
if (node.key === key) {
|
|
944
|
+
if (moreFlag) {
|
|
945
|
+
//加载更多
|
|
946
|
+
var child = node.children || [];
|
|
947
|
+
child.pop();
|
|
948
|
+
return Object.assign(Object.assign({}, node), {
|
|
949
|
+
children: child.concat(children)
|
|
950
|
+
});
|
|
951
|
+
}
|
|
952
|
+
return Object.assign(Object.assign({}, node), {
|
|
953
|
+
children: children
|
|
954
|
+
});
|
|
955
|
+
}
|
|
956
|
+
if (node.children) {
|
|
957
|
+
return Object.assign(Object.assign({}, node), {
|
|
958
|
+
children: updateTreeData(node.children, key, children, moreFlag)
|
|
959
|
+
});
|
|
960
|
+
}
|
|
961
|
+
return node;
|
|
962
|
+
});
|
|
963
|
+
};
|
|
964
|
+
//异步数据加载 [moreFlag]:加载更多标识
|
|
965
|
+
var onLoadData = function onLoadData(dataNode) {
|
|
966
|
+
var key = dataNode.key,
|
|
967
|
+
children = dataNode.children,
|
|
968
|
+
parentId = dataNode.parentId,
|
|
969
|
+
moreFlag = dataNode.moreFlag;
|
|
970
|
+
setInLoadKeys([].concat(_toConsumableArray(inLoadedKeys), [key]));
|
|
971
|
+
onLoadedKey === null || onLoadedKey === void 0 ? void 0 : onLoadedKey(key, dataNode);
|
|
972
|
+
return new Promise(function (resolve) {
|
|
973
|
+
return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee2() {
|
|
974
|
+
var _a, tKey, loadKey, loadParams, treeData, handledData, pageInfo, _treeData, _treeData$list, list, page, size, total;
|
|
975
|
+
return regenerator.wrap(function _callee2$(_context2) {
|
|
976
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
977
|
+
case 0:
|
|
978
|
+
if (!children) {
|
|
979
|
+
_context2.next = 3;
|
|
980
|
+
break;
|
|
981
|
+
}
|
|
982
|
+
resolve();
|
|
983
|
+
return _context2.abrupt("return");
|
|
984
|
+
case 3:
|
|
985
|
+
//当前节点key
|
|
986
|
+
tKey = key; //参数动态字段
|
|
987
|
+
loadKey = (_a = replaceFields.loadKey) !== null && _a !== void 0 ? _a : 'key'; //加载节点时参数
|
|
988
|
+
loadParams = Object.assign(_defineProperty({}, loadKey, tKey), params); //是否分页
|
|
989
|
+
if (pagination) {
|
|
990
|
+
if (moreFlag) {
|
|
991
|
+
//是否加载更多
|
|
992
|
+
tKey = parentId;
|
|
993
|
+
treeMapRef.current[tKey].page += 1;
|
|
994
|
+
loadParams[loadKey] = tKey;
|
|
995
|
+
if (tKey === 'ROOT_KEY') {
|
|
996
|
+
//根节点加载更多,不需要key
|
|
997
|
+
delete loadParams[loadKey];
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
//分页参数
|
|
1001
|
+
loadParams.page = treeMapRef.current[tKey].page;
|
|
1002
|
+
loadParams.size = treeMapRef.current[tKey].size;
|
|
1003
|
+
}
|
|
1004
|
+
_context2.next = 9;
|
|
1005
|
+
return requestTreeData(loadParams);
|
|
1006
|
+
case 9:
|
|
1007
|
+
treeData = _context2.sent;
|
|
1008
|
+
_context2.next = 12;
|
|
1009
|
+
return requestCallback === null || requestCallback === void 0 ? void 0 : requestCallback(treeData);
|
|
1010
|
+
case 12:
|
|
1011
|
+
handledData = _context2.sent;
|
|
1012
|
+
if (handledData) treeData = handledData;
|
|
1013
|
+
pageInfo = {}; //分页信息
|
|
1014
|
+
if (!pagination) {
|
|
1015
|
+
_context2.next = 22;
|
|
1016
|
+
break;
|
|
1017
|
+
}
|
|
1018
|
+
if (Object.keys(treeData).length) {
|
|
1019
|
+
_context2.next = 19;
|
|
1020
|
+
break;
|
|
1021
|
+
}
|
|
1022
|
+
resolve();
|
|
1023
|
+
return _context2.abrupt("return");
|
|
1024
|
+
case 19:
|
|
1025
|
+
_treeData = treeData, _treeData$list = _treeData.list, list = _treeData$list === void 0 ? [] : _treeData$list, page = _treeData.page, size = _treeData.size, total = _treeData.total;
|
|
1026
|
+
treeData = list;
|
|
1027
|
+
pageInfo = {
|
|
1028
|
+
page: page,
|
|
1029
|
+
size: size,
|
|
1030
|
+
total: total
|
|
1031
|
+
};
|
|
1032
|
+
case 22:
|
|
1033
|
+
if (treeData === null || treeData === void 0 ? void 0 : treeData.length) {
|
|
1034
|
+
treeData = formatTreeData(treeData);
|
|
1035
|
+
if (pagination) {
|
|
1036
|
+
//是否分页
|
|
1037
|
+
treeData = transformTreeData(treeData, pageInfo, tKey);
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
if (Array.isArray(treeData)) setTreeData(function (origin) {
|
|
1041
|
+
return updateTreeData(origin, tKey, treeData, moreFlag);
|
|
1042
|
+
});
|
|
1043
|
+
resolve();
|
|
1044
|
+
case 25:
|
|
1045
|
+
case "end":
|
|
1046
|
+
return _context2.stop();
|
|
1047
|
+
}
|
|
1048
|
+
}, _callee2);
|
|
1049
|
+
}));
|
|
1050
|
+
});
|
|
1051
|
+
};
|
|
1052
|
+
//转化tree数据
|
|
1053
|
+
var transformTreeData = function transformTreeData(treeData, pageInfo, parentId) {
|
|
1054
|
+
var newTreeData = convert(treeData); //tree结构
|
|
1055
|
+
var page = pageInfo.page,
|
|
1056
|
+
size = pageInfo.size,
|
|
1057
|
+
total = pageInfo.total;
|
|
1058
|
+
//计算分页,是否显示加载更多
|
|
1059
|
+
if (page * size < total) {
|
|
1060
|
+
var loadMoreData = getLoadMoreData();
|
|
1061
|
+
loadMoreData.parentId = parentId || 'ROOT_KEY';
|
|
1062
|
+
loadMoreData.title = renderLoadMoreNode(loadMoreData);
|
|
1063
|
+
newTreeData.push(loadMoreData);
|
|
1064
|
+
}
|
|
1065
|
+
treeMapRef.current = _toObject(newTreeData);
|
|
1066
|
+
function _toObject(data) {
|
|
1067
|
+
var obj = treeMapRef.current;
|
|
1068
|
+
if (!(data === null || data === void 0 ? void 0 : data.length)) return obj;
|
|
1069
|
+
data.forEach(function (item) {
|
|
1070
|
+
var tKey = item.moreFlag ? item.parentId : item.key;
|
|
1071
|
+
if (!obj[tKey]) {
|
|
1072
|
+
obj[tKey] = Object.assign(Object.assign({}, item), nPageSize);
|
|
1073
|
+
}
|
|
1074
|
+
});
|
|
1075
|
+
return obj;
|
|
1076
|
+
}
|
|
1077
|
+
return newTreeData;
|
|
1078
|
+
};
|
|
1079
|
+
//初始化树
|
|
1080
|
+
var initTree = function initTree() {
|
|
1081
|
+
return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee3() {
|
|
1082
|
+
var tParams, treeData, pageInfo, handledData, _treeData2, _treeData2$list, list, page, size, total;
|
|
1083
|
+
return regenerator.wrap(function _callee3$(_context3) {
|
|
1084
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
1085
|
+
case 0:
|
|
1086
|
+
tParams = Object.assign({}, params);
|
|
1087
|
+
if (pagination) {
|
|
1088
|
+
//分页参数
|
|
1089
|
+
tParams.page = nPageSize.page;
|
|
1090
|
+
tParams.size = nPageSize.size;
|
|
1091
|
+
}
|
|
1092
|
+
_context3.next = 4;
|
|
1093
|
+
return requestTreeData(tParams);
|
|
1094
|
+
case 4:
|
|
1095
|
+
treeData = _context3.sent;
|
|
1096
|
+
pageInfo = {}; //分页信息
|
|
1097
|
+
//透传数据
|
|
1098
|
+
_context3.next = 8;
|
|
1099
|
+
return requestCallback === null || requestCallback === void 0 ? void 0 : requestCallback(treeData);
|
|
1100
|
+
case 8:
|
|
1101
|
+
handledData = _context3.sent;
|
|
1102
|
+
if (handledData) treeData = handledData;
|
|
1103
|
+
if (!pagination) {
|
|
1104
|
+
_context3.next = 17;
|
|
1105
|
+
break;
|
|
1106
|
+
}
|
|
1107
|
+
if (Object.keys(treeData).length) {
|
|
1108
|
+
_context3.next = 13;
|
|
1109
|
+
break;
|
|
1110
|
+
}
|
|
1111
|
+
return _context3.abrupt("return", setTreeData([]));
|
|
1112
|
+
case 13:
|
|
1113
|
+
_treeData2 = treeData, _treeData2$list = _treeData2.list, list = _treeData2$list === void 0 ? [] : _treeData2$list, page = _treeData2.page, size = _treeData2.size, total = _treeData2.total;
|
|
1114
|
+
treeData = list;
|
|
1115
|
+
pageInfo = {
|
|
1116
|
+
page: page,
|
|
1117
|
+
size: size,
|
|
1118
|
+
total: total
|
|
1119
|
+
};
|
|
1120
|
+
//clean treeMapRef
|
|
1121
|
+
treeMapRef.current = {};
|
|
1122
|
+
case 17:
|
|
1123
|
+
if (treeData === null || treeData === void 0 ? void 0 : treeData.length) {
|
|
1124
|
+
_context3.next = 19;
|
|
1125
|
+
break;
|
|
1126
|
+
}
|
|
1127
|
+
return _context3.abrupt("return", setTreeData([]));
|
|
1128
|
+
case 19:
|
|
1129
|
+
treeData = formatTreeData(treeData);
|
|
1130
|
+
if (localFilter)
|
|
1131
|
+
//本地过滤
|
|
1132
|
+
treeOriDataRef.current = deepCopy(treeData);
|
|
1133
|
+
if (pagination)
|
|
1134
|
+
//是否分页
|
|
1135
|
+
treeData = transformTreeData(treeData, pageInfo);
|
|
1136
|
+
setTreeData(_toConsumableArray(treeData));
|
|
1137
|
+
case 23:
|
|
1138
|
+
case "end":
|
|
1139
|
+
return _context3.stop();
|
|
1140
|
+
}
|
|
1141
|
+
}, _callee3);
|
|
1142
|
+
}));
|
|
1143
|
+
};
|
|
1144
|
+
//额外的属性
|
|
1145
|
+
var getAdditionProps = function getAdditionProps() {
|
|
1146
|
+
var additionProps = {};
|
|
1147
|
+
if (asyncLoad)
|
|
1148
|
+
//异步加载
|
|
1149
|
+
additionProps.loadData = onLoadData;
|
|
1150
|
+
if (loadData) additionProps.loadData = loadData;
|
|
1151
|
+
additionProps.titleRender = internalTitleRender;
|
|
1152
|
+
return additionProps;
|
|
1153
|
+
};
|
|
1154
|
+
useEffect(function () {
|
|
1155
|
+
if (defaultCheckedKeys) {
|
|
1156
|
+
//默认值checked
|
|
1157
|
+
setInCheckedKeys(_toConsumableArray(defaultCheckedKeys));
|
|
1158
|
+
}
|
|
1159
|
+
if (defaultExpandedKeys) {
|
|
1160
|
+
//默认值expanded
|
|
1161
|
+
setInExpandedKeys(_toConsumableArray(defaultExpandedKeys));
|
|
1162
|
+
}
|
|
1163
|
+
}, [defaultCheckedKeys, defaultExpandedKeys]);
|
|
1164
|
+
useEffect(function () {
|
|
1165
|
+
if (checkedKeys) {
|
|
1166
|
+
//选中keys
|
|
1167
|
+
setInCheckedKeys(_toConsumableArray(getCheckedKeys(checkedKeys)));
|
|
1168
|
+
halfCheckedKeys.current = getHalfCheckedKeys(checkedKeys);
|
|
1169
|
+
}
|
|
1170
|
+
if (expandedKeys) {
|
|
1171
|
+
//展开keys
|
|
1172
|
+
setInExpandedKeys(_toConsumableArray(expandedKeys));
|
|
1173
|
+
}
|
|
1174
|
+
}, [checkedKeys, expandedKeys]);
|
|
1175
|
+
useEffect(function () {
|
|
1176
|
+
if (loadedKeys) {
|
|
1177
|
+
//loadedKeys
|
|
1178
|
+
if (loadedKeys.length === 0) {
|
|
1179
|
+
setInLoadKeys([]);
|
|
1180
|
+
setInExpandedKeys([]);
|
|
1181
|
+
} else {
|
|
1182
|
+
setInLoadKeys(_toConsumableArray(loadedKeys));
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
}, [loadedKeys]);
|
|
1186
|
+
useEffect(function () {
|
|
1187
|
+
//默认展开所有
|
|
1188
|
+
function _expandAllNode(newTreeData) {
|
|
1189
|
+
var keys = [];
|
|
1190
|
+
function recursive(dataList) {
|
|
1191
|
+
dataList.forEach(function (item) {
|
|
1192
|
+
var _a;
|
|
1193
|
+
if ((_a = item.children) === null || _a === void 0 ? void 0 : _a.length) {
|
|
1194
|
+
keys.push(item.key);
|
|
1195
|
+
recursive(item.children);
|
|
1196
|
+
}
|
|
1197
|
+
});
|
|
1198
|
+
}
|
|
1199
|
+
if (!expandedKeys && !defaultExpandedKeys) {
|
|
1200
|
+
recursive(newTreeData);
|
|
1201
|
+
if (keys.length) setInExpandedKeys(keys);
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
//tree 初始化
|
|
1205
|
+
if (Array.isArray(originTreeData)) {
|
|
1206
|
+
var newTreeData = formatTreeData(originTreeData);
|
|
1207
|
+
//本地过滤
|
|
1208
|
+
if (localFilter) treeOriDataRef.current = deepCopy(newTreeData);
|
|
1209
|
+
if (newProps.defaultExpandAll) {
|
|
1210
|
+
//默认展开所有
|
|
1211
|
+
_expandAllNode(newTreeData);
|
|
1212
|
+
}
|
|
1213
|
+
setTreeData(_toConsumableArray(newTreeData));
|
|
1214
|
+
} else {
|
|
1215
|
+
initTree();
|
|
1216
|
+
}
|
|
1217
|
+
}, [url, ctx, params, method, refresh, originTreeData]);
|
|
1218
|
+
useEffect(function () {
|
|
1219
|
+
//过滤数据
|
|
1220
|
+
function _filterData(_ref2) {
|
|
1221
|
+
var searchKey = _ref2.searchKey,
|
|
1222
|
+
searchValue = _ref2.searchValue;
|
|
1223
|
+
if (!searchKey) return;
|
|
1224
|
+
if (searchValue === '') {
|
|
1225
|
+
setTreeData(treeOriDataRef.current);
|
|
1226
|
+
var tKeys = expandedKeys || defaultExpandedKeys;
|
|
1227
|
+
setInExpandedKeys(_toConsumableArray(tKeys || []));
|
|
1228
|
+
return;
|
|
1229
|
+
}
|
|
1230
|
+
var flatData = flatten(treeOriDataRef.current);
|
|
1231
|
+
//匹配数据
|
|
1232
|
+
var filterTreeData = flatData.reduce(function (acc, curr) {
|
|
1233
|
+
var title = String(curr[searchKey]).toLowerCase();
|
|
1234
|
+
var isMatch = title.includes(searchValue === null || searchValue === void 0 ? void 0 : searchValue.toLowerCase());
|
|
1235
|
+
return isMatch ? acc.concat(curr) : acc;
|
|
1236
|
+
}, []);
|
|
1237
|
+
var newTreeData = convertByFilter(deepCopy(flatData), filterTreeData);
|
|
1238
|
+
setTreeData(newTreeData);
|
|
1239
|
+
setInExpandedKeys(_handleExpendKey(newTreeData));
|
|
1240
|
+
}
|
|
1241
|
+
//处理展开key
|
|
1242
|
+
function _handleExpendKey(list) {
|
|
1243
|
+
return list.reduce(function (acc, curr) {
|
|
1244
|
+
return acc.concat(curr.key, _handleExpendKey(curr.children || []));
|
|
1245
|
+
}, []);
|
|
1246
|
+
}
|
|
1247
|
+
if (localFilter) {
|
|
1248
|
+
//开启本地过滤
|
|
1249
|
+
if (onFilter) {
|
|
1250
|
+
var fData = onFilter(treeOriDataRef.current);
|
|
1251
|
+
if (!fData) return;
|
|
1252
|
+
setTreeData(fData);
|
|
1253
|
+
return;
|
|
1254
|
+
}
|
|
1255
|
+
if (localParams) _filterData(localParams);
|
|
1256
|
+
}
|
|
1257
|
+
}, [localFilter, localParams]);
|
|
1258
|
+
//渲染空状态
|
|
1259
|
+
var renderEmpty = jsx("div", Object.assign({
|
|
1260
|
+
className: clsx("".concat($prefixCls, "-tree ").concat($prefixCls, "-tree-empty"), className),
|
|
1261
|
+
style: props.style
|
|
1262
|
+
}, {
|
|
1263
|
+
children: notFoundContent !== null && notFoundContent !== void 0 ? notFoundContent : jsx(Empty, Object.assign({
|
|
1264
|
+
size: 'small'
|
|
1265
|
+
}, emptyProps))
|
|
1266
|
+
}));
|
|
1267
|
+
//tree memo
|
|
1268
|
+
var treeMemo = useMemo(function () {
|
|
1269
|
+
if (!(treeData === null || treeData === void 0 ? void 0 : treeData.length) && firstRender.current) {
|
|
1270
|
+
firstRender.current = false;
|
|
1271
|
+
return null;
|
|
1272
|
+
} else if (!(treeData === null || treeData === void 0 ? void 0 : treeData.length)) {
|
|
1273
|
+
return !loading ? renderEmpty : null;
|
|
1274
|
+
}
|
|
1275
|
+
var tCheckedKeys = inCheckedKeys;
|
|
1276
|
+
if (checkStrictly) {
|
|
1277
|
+
tCheckedKeys = {
|
|
1278
|
+
checked: inCheckedKeys,
|
|
1279
|
+
halfChecked: halfCheckedKeys.current
|
|
1280
|
+
};
|
|
1281
|
+
}
|
|
1282
|
+
return jsx(RcTree, Object.assign({
|
|
1283
|
+
itemHeight: 20,
|
|
1284
|
+
ref: ref
|
|
1285
|
+
}, newProps, {
|
|
1286
|
+
prefixCls: prefixCls,
|
|
1287
|
+
className: makeCls(),
|
|
1288
|
+
checkable: radioable || checkable ? jsx("span", {
|
|
1289
|
+
className: "".concat(prefixCls, "-checkbox-inner")
|
|
1290
|
+
}) : checkable,
|
|
1291
|
+
selectable: radioable ? false : selectable,
|
|
1292
|
+
switcherIcon: function switcherIcon(nodeProps) {
|
|
1293
|
+
return renderSwitcherIcon(prefixCls, _switcherIcon, showLine, nodeProps);
|
|
1294
|
+
}
|
|
1295
|
+
}, getAdditionProps(), {
|
|
1296
|
+
treeData: treeData,
|
|
1297
|
+
checkedKeys: tCheckedKeys,
|
|
1298
|
+
expandedKeys: inExpandedKeysKeys,
|
|
1299
|
+
loadedKeys: inLoadedKeys,
|
|
1300
|
+
onCheck: internalCheck,
|
|
1301
|
+
onExpand: internalExpand,
|
|
1302
|
+
icon: function icon(nodeProps) {
|
|
1303
|
+
if (_icon) {
|
|
1304
|
+
return typeof _icon === 'function' ? _icon(nodeProps) : _icon;
|
|
1305
|
+
}
|
|
1306
|
+
if (nodeProps.checkable === false) return null;
|
|
1307
|
+
if (!radioable) return null;else if (!showRadio) return null;
|
|
1308
|
+
return renderTreeNodeIcon(nodeProps, radioable, inCheckedKeys[0], replaceFields);
|
|
1309
|
+
}
|
|
1310
|
+
}));
|
|
1311
|
+
}, [treeData, inCheckedKeys, inExpandedKeysKeys, newProps.selectedKeys, inLoadedKeys]);
|
|
1312
|
+
//OperateBar render
|
|
1313
|
+
var renderOperateBar = function renderOperateBar() {
|
|
1314
|
+
return !!showActions ? jsx(OperateBar, {
|
|
1315
|
+
opRef: opRef,
|
|
1316
|
+
mouseInRef: mouseInSectorRef,
|
|
1317
|
+
actionsCallback: actionsCallback,
|
|
1318
|
+
onRemove: handleOnRemove,
|
|
1319
|
+
showActions: showActions
|
|
1320
|
+
}) : null;
|
|
1321
|
+
};
|
|
1322
|
+
return jsxs(Fragment, {
|
|
1323
|
+
children: [jsxs("div", Object.assign({
|
|
1324
|
+
className: clsx("".concat($prefixCls, "-tree-wrapper"), wrapperClassName),
|
|
1325
|
+
style: wrapperStyle
|
|
1326
|
+
}, {
|
|
1327
|
+
children: [treeMemo, loading && jsx(Loading, {})]
|
|
1328
|
+
})), renderOperateBar()]
|
|
1329
|
+
});
|
|
1330
|
+
});
|
|
1331
|
+
Tree.defaultProps = {
|
|
1332
|
+
checkable: false,
|
|
1333
|
+
selectable: true,
|
|
1334
|
+
showIcon: false,
|
|
1335
|
+
motion: Object.assign(Object.assign({}, collapseMotion), {
|
|
1336
|
+
motionAppear: false
|
|
1337
|
+
}),
|
|
1338
|
+
blockNode: false
|
|
1339
|
+
};
|
|
1340
|
+
|
|
1341
|
+
// @ts-ignore
|
|
1342
|
+
if (!Element.prototype.closest) {
|
|
1343
|
+
Element.prototype.closest = function (s) {
|
|
1344
|
+
var el = this;
|
|
1345
|
+
if (!document.documentElement.contains(el)) return null;
|
|
1346
|
+
do {
|
|
1347
|
+
if (el.matches(s)) return el;
|
|
1348
|
+
el = el.parentElement;
|
|
1349
|
+
} while (el !== null);
|
|
1350
|
+
return null;
|
|
1351
|
+
};
|
|
1352
|
+
}
|
|
1353
|
+
|
|
1354
|
+
export { Tree as T };
|