fan-standard-comp 3.2.11 → 3.2.13
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/dist/fan-standard-comp.umd.js +150 -150
- package/es/FormComp/FieldComponent/RefactorTreeSelect.d.ts +4 -0
- package/es/FormComp/FieldComponent/RefactorTreeSelect.js +96 -221
- package/es/FormComp/FieldComponent/index.js +1 -1
- package/es/RefactorTree/util.d.ts +4 -3
- package/es/RefactorTree/util.js +52 -8
- package/es/hooks/use-language.d.ts +2 -0
- package/es/hooks/use-language.js +44 -0
- package/es/hooks/use-throttle.d.ts +1 -0
- package/es/hooks/use-throttle.js +33 -0
- package/es/locales/bn-BD/settings.d.ts +34 -0
- package/es/locales/bn-BD/settings.js +36 -0
- package/es/locales/bn-BD.d.ts +35 -0
- package/es/locales/bn-BD.js +4 -0
- package/es/locales/en-US/settings.d.ts +34 -0
- package/es/locales/en-US/settings.js +36 -0
- package/es/locales/en-US.d.ts +35 -0
- package/es/locales/en-US.js +4 -0
- package/es/locales/fa-IR/settings.d.ts +34 -0
- package/es/locales/fa-IR/settings.js +36 -0
- package/es/locales/fa-IR.d.ts +35 -0
- package/es/locales/fa-IR.js +4 -0
- package/es/locales/id-ID/settings.d.ts +34 -0
- package/es/locales/id-ID/settings.js +36 -0
- package/es/locales/id-ID.d.ts +35 -0
- package/es/locales/id-ID.js +4 -0
- package/es/locales/ja-JP/settings.d.ts +33 -0
- package/es/locales/ja-JP/settings.js +35 -0
- package/es/locales/ja-JP.d.ts +34 -0
- package/es/locales/ja-JP.js +4 -0
- package/es/locales/pt-BR/settings.d.ts +34 -0
- package/es/locales/pt-BR/settings.js +36 -0
- package/es/locales/pt-BR.d.ts +35 -0
- package/es/locales/pt-BR.js +4 -0
- package/es/locales/zh-CN/settings.d.ts +34 -0
- package/es/locales/zh-CN/settings.js +36 -0
- package/es/locales/zh-CN.d.ts +35 -0
- package/es/locales/zh-CN.js +4 -0
- package/es/locales/zh-TW/settings.d.ts +34 -0
- package/es/locales/zh-TW/settings.js +36 -0
- package/es/locales/zh-TW.d.ts +34 -0
- package/es/locales/zh-TW.js +2 -0
- package/es/utils/getParentNodes.d.ts +109 -0
- package/es/utils/getParentNodes.js +119 -20
- package/lib/FormComp/FieldComponent/RefactorTreeSelect.d.ts +4 -0
- package/lib/FormComp/FieldComponent/RefactorTreeSelect.js +94 -218
- package/lib/FormComp/FieldComponent/index.js +1 -1
- package/lib/RefactorTree/util.d.ts +4 -3
- package/lib/RefactorTree/util.js +51 -9
- package/lib/hooks/use-language.d.ts +2 -0
- package/lib/hooks/use-language.js +51 -0
- package/lib/hooks/use-throttle.d.ts +1 -0
- package/lib/hooks/use-throttle.js +38 -0
- package/lib/locales/bn-BD/settings.d.ts +34 -0
- package/lib/locales/bn-BD/settings.js +42 -0
- package/lib/locales/bn-BD.d.ts +35 -0
- package/lib/locales/bn-BD.js +11 -0
- package/lib/locales/en-US/settings.d.ts +34 -0
- package/lib/locales/en-US/settings.js +42 -0
- package/lib/locales/en-US.d.ts +35 -0
- package/lib/locales/en-US.js +11 -0
- package/lib/locales/fa-IR/settings.d.ts +34 -0
- package/lib/locales/fa-IR/settings.js +42 -0
- package/lib/locales/fa-IR.d.ts +35 -0
- package/lib/locales/fa-IR.js +11 -0
- package/lib/locales/id-ID/settings.d.ts +34 -0
- package/lib/locales/id-ID/settings.js +42 -0
- package/lib/locales/id-ID.d.ts +35 -0
- package/lib/locales/id-ID.js +11 -0
- package/lib/locales/ja-JP/settings.d.ts +33 -0
- package/lib/locales/ja-JP/settings.js +41 -0
- package/lib/locales/ja-JP.d.ts +34 -0
- package/lib/locales/ja-JP.js +11 -0
- package/lib/locales/pt-BR/settings.d.ts +34 -0
- package/lib/locales/pt-BR/settings.js +42 -0
- package/lib/locales/pt-BR.d.ts +35 -0
- package/lib/locales/pt-BR.js +11 -0
- package/lib/locales/zh-CN/settings.d.ts +34 -0
- package/lib/locales/zh-CN/settings.js +42 -0
- package/lib/locales/zh-CN.d.ts +35 -0
- package/lib/locales/zh-CN.js +11 -0
- package/lib/locales/zh-TW/settings.d.ts +34 -0
- package/lib/locales/zh-TW/settings.js +42 -0
- package/lib/locales/zh-TW.d.ts +34 -0
- package/lib/locales/zh-TW.js +9 -0
- package/lib/utils/getParentNodes.d.ts +109 -0
- package/lib/utils/getParentNodes.js +118 -22
- package/package.json +5 -3
|
@@ -1,31 +1,20 @@
|
|
|
1
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
-
import "antd/es/popover/style";
|
|
3
|
-
import _Popover from "antd/es/popover";
|
|
4
|
-
import "antd/es/tag/style";
|
|
5
|
-
import _Tag from "antd/es/tag";
|
|
6
1
|
import "antd/es/tree-select/style";
|
|
7
2
|
import _TreeSelect from "antd/es/tree-select";
|
|
8
|
-
var _excluded = ["treeData", "value", "showFullLevel", "separator", "disabled", "disabledFields", "fieldStatus", "treeOptionName", "placeholder", "protoTreeNode", "onSelect", "labelInValue"];
|
|
9
|
-
function _objectDestructuringEmpty(t) { if (null == t) throw new TypeError("Cannot destructure " + t); }
|
|
10
|
-
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
11
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
12
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
13
|
-
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
14
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
15
|
-
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
16
3
|
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
17
4
|
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."); }
|
|
18
5
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
19
6
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
20
7
|
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; } }
|
|
21
8
|
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
import React, { useRef, useState, useEffect } from "react";
|
|
9
|
+
import { __rest } from "tslib";
|
|
10
|
+
import React, { useMemo, useState } from "react";
|
|
25
11
|
import './style/index.less';
|
|
26
|
-
import
|
|
12
|
+
import classNames from 'classnames';
|
|
13
|
+
import _ from 'lodash';
|
|
14
|
+
import { getParentNodes, getNodePaths } from '../../utils';
|
|
27
15
|
import { UpOutlined, DownOutlined } from "@ant-design/icons";
|
|
28
|
-
|
|
16
|
+
import { transDataParam } from '../../RefactorTree/util';
|
|
17
|
+
import { useLanguageObject } from "../../hooks/use-language";
|
|
29
18
|
var RefactorTreeSelect = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
30
19
|
var _props$treeData = props.treeData,
|
|
31
20
|
treeData = _props$treeData === void 0 ? [] : _props$treeData,
|
|
@@ -39,6 +28,7 @@ var RefactorTreeSelect = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
39
28
|
_props$treeOptionName = props.treeOptionName,
|
|
40
29
|
treeOptionName = _props$treeOptionName === void 0 ? {
|
|
41
30
|
title: 'title',
|
|
31
|
+
label: 'label',
|
|
42
32
|
value: 'value',
|
|
43
33
|
children: 'children',
|
|
44
34
|
disabled: 'disabled'
|
|
@@ -47,239 +37,124 @@ var RefactorTreeSelect = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
47
37
|
protoTreeNode = props.protoTreeNode,
|
|
48
38
|
_onSelect = props.onSelect,
|
|
49
39
|
labelInValue = props.labelInValue,
|
|
50
|
-
otherProps =
|
|
51
|
-
var
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
setIndeterminate(false);
|
|
66
|
-
setCheckAll(e.target.checked);
|
|
67
|
-
// 全选
|
|
68
|
-
if (e.target.checked) {
|
|
69
|
-
console.log(convertToArray(treeData))
|
|
70
|
-
// 还需要按showCheckedStrategy判断选择的节点数量
|
|
71
|
-
otherProps?.onChange(convertToArray(treeData).map(item=> item[treeOptionName.value]))
|
|
72
|
-
} else {
|
|
73
|
-
otherProps?.onChange([])
|
|
74
|
-
}
|
|
75
|
-
}*/
|
|
76
|
-
|
|
77
|
-
var _renderTreeNode = function renderTreeNode(data, dataOptionName) {
|
|
78
|
-
var nodeProps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
79
|
-
return data.map(function (dataItem) {
|
|
80
|
-
var prevDataItem = _objectSpread({}, dataItem);
|
|
81
|
-
var item = _extends({}, (_objectDestructuringEmpty(prevDataItem), prevDataItem));
|
|
82
|
-
// 筛选与禁用字段内值相同的节点进行禁用
|
|
83
|
-
var resetByDisabledFields = function resetByDisabledFields(initItem) {
|
|
84
|
-
var oldItem = _objectSpread({}, initItem);
|
|
85
|
-
var nodeItem = _extends({}, (_objectDestructuringEmpty(oldItem), oldItem));
|
|
86
|
-
Object.keys(nodeItem).forEach(function (itemKeyName) {
|
|
87
|
-
var isMatch = disabledFields.find(function (fItem) {
|
|
88
|
-
return fItem.key === itemKeyName;
|
|
89
|
-
});
|
|
90
|
-
if (isMatch) {
|
|
91
|
-
var _isMatch$value$split;
|
|
92
|
-
// 确认是否匹配数据,进行设置 disabled
|
|
93
|
-
if ((_isMatch$value$split = isMatch.value.split(',')) === null || _isMatch$value$split === void 0 ? void 0 : _isMatch$value$split.includes(nodeItem[itemKeyName])) {
|
|
94
|
-
nodeItem.disabled = true;
|
|
95
|
-
} else if (nodeItem.hasOwnProperty(dataOptionName.disabled || 'disabled')) {
|
|
96
|
-
nodeItem.disabled = nodeItem[dataOptionName.disabled || 'disabled'];
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
return nodeItem;
|
|
101
|
-
};
|
|
102
|
-
if (disabledFields && Array.isArray(disabledFields)) {
|
|
103
|
-
item = resetByDisabledFields(item);
|
|
104
|
-
}
|
|
105
|
-
if (item[dataOptionName.children] && item[dataOptionName.children].length > 0) {
|
|
106
|
-
return /*#__PURE__*/React.createElement(TreeNode, _extends({
|
|
107
|
-
title: item[dataOptionName.title],
|
|
108
|
-
key: item[dataOptionName.value],
|
|
109
|
-
value: item[dataOptionName.value],
|
|
110
|
-
selectable: item[(dataOptionName === null || dataOptionName === void 0 ? void 0 : dataOptionName.selectable) || 'selectable'],
|
|
111
|
-
checkable: item[(dataOptionName === null || dataOptionName === void 0 ? void 0 : dataOptionName.checkable) || 'checkable'],
|
|
112
|
-
disableCheckbox: item[(dataOptionName === null || dataOptionName === void 0 ? void 0 : dataOptionName.disableCheckbox) || 'disableCheckbox'],
|
|
113
|
-
disabled: item[(dataOptionName === null || dataOptionName === void 0 ? void 0 : dataOptionName.disabled) || 'disabled']
|
|
114
|
-
}, nodeProps), _renderTreeNode(item[dataOptionName.children], dataOptionName));
|
|
115
|
-
}
|
|
116
|
-
return /*#__PURE__*/React.createElement(TreeNode, _extends({
|
|
117
|
-
title: item[dataOptionName.title],
|
|
118
|
-
key: item[dataOptionName.value],
|
|
119
|
-
value: item[dataOptionName.value],
|
|
120
|
-
selectable: item[(dataOptionName === null || dataOptionName === void 0 ? void 0 : dataOptionName.selectable) || 'selectable'],
|
|
121
|
-
checkable: item[(dataOptionName === null || dataOptionName === void 0 ? void 0 : dataOptionName.checkable) || 'checkable'],
|
|
122
|
-
disableCheckbox: item[(dataOptionName === null || dataOptionName === void 0 ? void 0 : dataOptionName.disableCheckbox) || 'disableCheckbox'],
|
|
123
|
-
disabled: item[(dataOptionName === null || dataOptionName === void 0 ? void 0 : dataOptionName.disabled) || 'disabled']
|
|
124
|
-
}, nodeProps));
|
|
125
|
-
});
|
|
126
|
-
};
|
|
127
|
-
useEffect(function () {
|
|
128
|
-
if (value) {
|
|
129
|
-
// 获取选中节点相关数据:包括当前完整数据值、当前父节点以上层层级节点数据集合及id集合
|
|
130
|
-
var nodeInfo = getParentNodes(treeData, labelInValue ? value.value : value, {
|
|
131
|
-
childrenParam: treeOptionName.children,
|
|
132
|
-
keyParam: treeOptionName.value
|
|
133
|
-
}, _objectSpread({}, otherProps));
|
|
134
|
-
setFullLevelName(renderParenName(nodeInfo));
|
|
135
|
-
} else {
|
|
136
|
-
// value,无值时
|
|
137
|
-
setFullLevelName(null);
|
|
138
|
-
}
|
|
139
|
-
}, [value, treeData, fieldStatus]);
|
|
140
|
-
var renderParenName = function renderParenName(selectNodeInfo) {
|
|
141
|
-
// 有父级节点,及当前模式是showFullLevel时,渲染名称为完整层级名称,否则为当前节点名称
|
|
142
|
-
var parentItems = selectNodeInfo.nodeParent;
|
|
143
|
-
if (parentItems.length > 0 && showFullLevel && !otherProps.showCheckedStrategy) {
|
|
144
|
-
// 当前查找到的父级节点拼合当前节点的标题字段值进行显示
|
|
145
|
-
return parentItems.reverse().map(function (item) {
|
|
146
|
-
return item[treeOptionName.title];
|
|
147
|
-
}).concat(selectNodeInfo.matchNode[0][treeOptionName.title]).join(separator);
|
|
148
|
-
}
|
|
149
|
-
if (Array.isArray(value)) {
|
|
150
|
-
return selectNodeInfo.matchNode.length > 0 ? selectNodeInfo.matchNode.map(function (item) {
|
|
151
|
-
return item[treeOptionName.title] || item[treeOptionName.value];
|
|
152
|
-
}).join(',') : null;
|
|
153
|
-
}
|
|
154
|
-
return selectNodeInfo.matchNode.length > 0 ? selectNodeInfo.matchNode[0][treeOptionName.title] : null;
|
|
155
|
-
};
|
|
156
|
-
var renderTreeSelectNode = function renderTreeSelectNode() {
|
|
157
|
-
// 限制显示多个tag
|
|
158
|
-
if (otherProps.treeCheckable && otherProps.maxTagCount) {
|
|
159
|
-
// 未自行配置`maxTagPlaceholder`时,使用当前结构,点击"+xxx"后,浮层将显示对应的标签
|
|
160
|
-
if (!otherProps.hasOwnProperty('maxTagPlaceholder')) {
|
|
161
|
-
otherProps.maxTagPlaceholder = function (omittedValues) {
|
|
162
|
-
return /*#__PURE__*/React.createElement(_Popover, {
|
|
163
|
-
zIndex: 10000,
|
|
164
|
-
content: /*#__PURE__*/React.createElement("div", {
|
|
165
|
-
style: {
|
|
166
|
-
maxWidth: '350px'
|
|
167
|
-
}
|
|
168
|
-
}, omittedValues.map(function (item) {
|
|
169
|
-
return /*#__PURE__*/React.createElement(_Tag, {
|
|
170
|
-
key: item.value
|
|
171
|
-
}, item.label);
|
|
172
|
-
}))
|
|
173
|
-
}, "+", omittedValues.length);
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
return /*#__PURE__*/React.createElement(_TreeSelect, _extends({
|
|
178
|
-
placeholder: placeholder,
|
|
179
|
-
value: value,
|
|
180
|
-
ref: ref
|
|
181
|
-
}, otherProps, {
|
|
182
|
-
labelInValue: labelInValue,
|
|
183
|
-
title: otherProps.title || ((disabled || fieldStatus === 'disabled') && !otherProps.treeCheckable ? fullLevelName : null),
|
|
184
|
-
showCheckedStrategy: otherProps.showCheckedStrategy,
|
|
185
|
-
disabled: disabled,
|
|
186
|
-
onSelect: function onSelect(value, node, extra) {
|
|
187
|
-
var newNodeInfo = getParentNodes(treeData, value, {
|
|
188
|
-
childrenParam: treeOptionName.children,
|
|
189
|
-
keyParam: treeOptionName.value
|
|
190
|
-
});
|
|
191
|
-
setFullLevelName(renderParenName(newNodeInfo));
|
|
192
|
-
if (_onSelect) _onSelect(value, _objectSpread(_objectSpread({}, node), newNodeInfo.matchNode[0]), extra, newNodeInfo.nodeParent);
|
|
193
|
-
},
|
|
194
|
-
onDropdownVisibleChange: function onDropdownVisibleChange(open) {
|
|
195
|
-
var _otherProps$onDropdow;
|
|
196
|
-
setFullLevelStyle({
|
|
197
|
-
opacity: open ? 0.3 : ''
|
|
198
|
-
});
|
|
199
|
-
otherProps === null || otherProps === void 0 ? void 0 : (_otherProps$onDropdow = otherProps.onDropdownVisibleChange) === null || _otherProps$onDropdow === void 0 ? void 0 : _otherProps$onDropdow.call(otherProps, open);
|
|
200
|
-
},
|
|
201
|
-
onSearch: function onSearch(value) {
|
|
202
|
-
var _otherProps$onSearch;
|
|
203
|
-
setFullLevelStyle({
|
|
204
|
-
opacity: value ? 0 : ''
|
|
205
|
-
});
|
|
206
|
-
otherProps === null || otherProps === void 0 ? void 0 : (_otherProps$onSearch = otherProps.onSearch) === null || _otherProps$onSearch === void 0 ? void 0 : _otherProps$onSearch.call(otherProps, value);
|
|
207
|
-
}
|
|
208
|
-
// 下拉浮层中显示"全选"按钮
|
|
209
|
-
// dropdownRender={(originNode) => {
|
|
210
|
-
// return otherProps?.dropdownRender ? otherProps?.dropdownRender(originNode, <div>
|
|
211
|
-
// <div>
|
|
212
|
-
// <Checkbox indeterminate={indeterminate} onChange={onCheckAllChange} checked={checkAll}>
|
|
213
|
-
// 全选
|
|
214
|
-
// </Checkbox> <span>已选{value?.length}</span></div>
|
|
215
|
-
// </div>) : originNode
|
|
216
|
-
// }}
|
|
217
|
-
}), _renderTreeNode(treeData, treeOptionName, protoTreeNode || {}));
|
|
40
|
+
otherProps = __rest(props, ["treeData", "value", "showFullLevel", "separator", "disabled", "disabledFields", "fieldStatus", "treeOptionName", "placeholder", "protoTreeNode", "onSelect", "labelInValue"]);
|
|
41
|
+
var lang = useLanguageObject(); // 当前使用的语言包
|
|
42
|
+
var componentName = 'refactor-tree-select';
|
|
43
|
+
// 重组数据
|
|
44
|
+
var transTreeData = useMemo(function () {
|
|
45
|
+
var newTree = _.cloneDeep(treeData || []);
|
|
46
|
+
return transDataParam(newTree, (otherProps === null || otherProps === void 0 ? void 0 : otherProps.fieldNames) || treeOptionName, {
|
|
47
|
+
separator: separator,
|
|
48
|
+
disabledFields: disabledFields
|
|
49
|
+
}); // 通过转换后的数据
|
|
50
|
+
}, [treeData, treeOptionName, otherProps.fieldNames, separator, disabledFields]);
|
|
51
|
+
// 设置名称字段值
|
|
52
|
+
var setLabelKeyName = function setLabelKeyName() {
|
|
53
|
+
var _a;
|
|
54
|
+
return showFullLevelKeyName || ((_a = otherProps.fieldNames) === null || _a === void 0 ? void 0 : _a.label) || treeOptionName.title || treeOptionName.label;
|
|
218
55
|
};
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
56
|
+
// 判断是否指定显示完整名称
|
|
57
|
+
var showFullLevelKeyName = useMemo(function () {
|
|
58
|
+
return showFullLevel ? 'treeFullLevelName' : otherProps === null || otherProps === void 0 ? void 0 : otherProps.treeNodeLabelProp;
|
|
59
|
+
}, [showFullLevel, otherProps === null || otherProps === void 0 ? void 0 : otherProps.treeNodeLabelProp]);
|
|
60
|
+
var _useState = useState(false),
|
|
61
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
62
|
+
showAllPath = _useState2[0],
|
|
63
|
+
setShowAllPath = _useState2[1]; // 显示所有树选择路径
|
|
223
64
|
var renderTreeSelectNodePath = function renderTreeSelectNodePath() {
|
|
224
65
|
//获取节点路径
|
|
225
|
-
var pathNodes = getNodePaths(
|
|
66
|
+
var pathNodes = getNodePaths(transTreeData, value, {
|
|
226
67
|
childrenParam: treeOptionName.children,
|
|
227
68
|
keyParam: treeOptionName.value
|
|
228
|
-
},
|
|
69
|
+
}, Object.assign({}, otherProps));
|
|
229
70
|
var togglePath = function togglePath() {
|
|
230
71
|
setShowAllPath(!showAllPath);
|
|
231
72
|
};
|
|
232
73
|
if (pathNodes.length > 0) {
|
|
233
74
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
234
75
|
className: "tree-select-viewonly-list ".concat(showAllPath ? 'collapsed' : '')
|
|
235
|
-
},
|
|
76
|
+
},
|
|
77
|
+
// @ts-ignore
|
|
78
|
+
pathNodes.map(function (item, index) {
|
|
236
79
|
if (item.length > 0) {
|
|
237
80
|
// 超过2个且不显示所有
|
|
238
|
-
if (index > 1 && !showAllPath) return;
|
|
81
|
+
if (index > 1 && !showAllPath) return '';
|
|
239
82
|
return /*#__PURE__*/React.createElement("div", {
|
|
240
83
|
className: 'tree-select-viewonly-item',
|
|
241
84
|
key: index
|
|
242
85
|
}, /*#__PURE__*/React.createElement("b", null, "\xB7 "), item.map(function (i) {
|
|
243
|
-
return i[
|
|
86
|
+
return i[setLabelKeyName()];
|
|
244
87
|
}).join(separator));
|
|
245
88
|
}
|
|
246
|
-
}), pathNodes.length > 2 ? /*#__PURE__*/React.createElement("div", {
|
|
89
|
+
}), pathNodes.length > 2 ? (/*#__PURE__*/React.createElement("div", {
|
|
247
90
|
className: "toggle-icon",
|
|
248
91
|
onClick: togglePath
|
|
249
|
-
}, !showAllPath ? /*#__PURE__*/React.createElement(React.Fragment, null, "
|
|
92
|
+
}, !showAllPath ? /*#__PURE__*/React.createElement(React.Fragment, null, (lang === null || lang === void 0 ? void 0 : lang['field.expand']) || '展开', " ", /*#__PURE__*/React.createElement(DownOutlined, null)) : /*#__PURE__*/React.createElement(React.Fragment, null, (lang === null || lang === void 0 ? void 0 : lang['field.collapse']) || '收起', " ", /*#__PURE__*/React.createElement(UpOutlined, null)))) : null));
|
|
250
93
|
} else {
|
|
251
94
|
return '-';
|
|
252
95
|
}
|
|
253
96
|
};
|
|
254
97
|
if (fieldStatus === 'viewOnly') {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
98
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
99
|
+
className: classNames(componentName, otherProps === null || otherProps === void 0 ? void 0 : otherProps.className, componentName + '-viewOnly')
|
|
100
|
+
}, function () {
|
|
101
|
+
var _a;
|
|
102
|
+
//多选下拉框 详情展示 showCheckedStrategy 有值且显示完整路径时
|
|
103
|
+
if (otherProps.showCheckedStrategy && showFullLevelKeyName) {
|
|
104
|
+
return renderTreeSelectNodePath();
|
|
105
|
+
}
|
|
106
|
+
// 多选状态
|
|
107
|
+
if (otherProps.multiple) {
|
|
108
|
+
if (labelInValue) {
|
|
109
|
+
return value && value.length > 0 ? value.map(function (item) {
|
|
110
|
+
return item[setLabelKeyName()] || item['title'] || item['label'];
|
|
111
|
+
}).join(',') : '-';
|
|
112
|
+
}
|
|
113
|
+
var pathNodes = getNodePaths(transTreeData, value, {
|
|
114
|
+
childrenParam: treeOptionName.children,
|
|
115
|
+
keyParam: treeOptionName.value
|
|
116
|
+
}, Object.assign({}, otherProps));
|
|
117
|
+
return pathNodes.length > 0 ? pathNodes.map(function (nItem) {
|
|
118
|
+
var _a;
|
|
119
|
+
return (_a = nItem[nItem.length - 1]) === null || _a === void 0 ? void 0 : _a[setLabelKeyName()];
|
|
264
120
|
}).join(',') : '-';
|
|
265
121
|
}
|
|
266
|
-
var
|
|
122
|
+
var nodeInfo = getParentNodes(transTreeData, labelInValue ? value.value : value, {
|
|
267
123
|
childrenParam: treeOptionName.children,
|
|
268
124
|
keyParam: treeOptionName.value
|
|
269
|
-
},
|
|
270
|
-
return
|
|
271
|
-
|
|
272
|
-
return (_nItem = nItem[nItem.length - 1]) === null || _nItem === void 0 ? void 0 : _nItem[treeOptionName.title];
|
|
273
|
-
}).join(',') : '-';
|
|
274
|
-
}
|
|
275
|
-
return fullLevelName || '-'; // 只读显示时,只返回文本
|
|
125
|
+
}, Object.assign({}, otherProps));
|
|
126
|
+
return ((_a = nodeInfo === null || nodeInfo === void 0 ? void 0 : nodeInfo.matchNode[0]) === null || _a === void 0 ? void 0 : _a[setLabelKeyName()]) || '-'; // 只读显示时,只返回文本
|
|
127
|
+
}());
|
|
276
128
|
}
|
|
277
|
-
return /*#__PURE__*/React.createElement(
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
129
|
+
return /*#__PURE__*/React.createElement(_TreeSelect, Object.assign({
|
|
130
|
+
placeholder: placeholder,
|
|
131
|
+
value: value,
|
|
132
|
+
ref: ref
|
|
133
|
+
}, otherProps, {
|
|
134
|
+
treeNodeLabelProp: showFullLevel ? 'treeFullLevelName' : otherProps === null || otherProps === void 0 ? void 0 : otherProps.treeNodeLabelProp,
|
|
135
|
+
className: classNames(componentName, otherProps === null || otherProps === void 0 ? void 0 : otherProps.className),
|
|
136
|
+
labelInValue: labelInValue,
|
|
137
|
+
showCheckedStrategy: otherProps.showCheckedStrategy,
|
|
138
|
+
disabled: disabled,
|
|
139
|
+
onSelect: function onSelect(value, node, extra) {
|
|
140
|
+
var newNodeInfo = getParentNodes(transTreeData, value, {
|
|
141
|
+
childrenParam: treeOptionName.children,
|
|
142
|
+
keyParam: treeOptionName.value
|
|
143
|
+
});
|
|
144
|
+
if (_onSelect) _onSelect(value, Object.assign(Object.assign({}, node), newNodeInfo.matchNode[0]), extra, newNodeInfo.nodeParent);
|
|
145
|
+
},
|
|
146
|
+
onDropdownVisibleChange: function onDropdownVisibleChange(open) {
|
|
147
|
+
var _a;
|
|
148
|
+
(_a = otherProps === null || otherProps === void 0 ? void 0 : otherProps.onDropdownVisibleChange) === null || _a === void 0 ? void 0 : _a.call(otherProps, open);
|
|
149
|
+
},
|
|
150
|
+
onSearch: function onSearch(value) {
|
|
151
|
+
var _a;
|
|
152
|
+
(_a = otherProps === null || otherProps === void 0 ? void 0 : otherProps.onSearch) === null || _a === void 0 ? void 0 : _a.call(otherProps, value);
|
|
153
|
+
},
|
|
154
|
+
treeData: transTreeData,
|
|
155
|
+
fieldNames: Object.assign(Object.assign(Object.assign({}, treeOptionName), {
|
|
156
|
+
label: (treeOptionName === null || treeOptionName === void 0 ? void 0 : treeOptionName.title) || (treeOptionName === null || treeOptionName === void 0 ? void 0 : treeOptionName.label)
|
|
157
|
+
}), (otherProps === null || otherProps === void 0 ? void 0 : otherProps.fieldNames) || {})
|
|
158
|
+
}));
|
|
284
159
|
});
|
|
285
160
|
export default RefactorTreeSelect;
|
|
@@ -27,7 +27,7 @@ import _Input from "antd/es/input";
|
|
|
27
27
|
import React, { useContext } from "react";
|
|
28
28
|
import Uploader from '../Uploader';
|
|
29
29
|
import SpecIcon from '../../SpecIcon';
|
|
30
|
-
import RefactorTreeSelect from './RefactorTreeSelect
|
|
30
|
+
import RefactorTreeSelect from './RefactorTreeSelect';
|
|
31
31
|
import { setSelectValue, setDatePickerValue, setTimePickerValue, setCascaderValue } from './setReadonlyValues.js';
|
|
32
32
|
import TitleNode from './TitleNode';
|
|
33
33
|
import ReUpload from './ReUpload';
|
|
@@ -5,15 +5,16 @@ interface optionNameProps {
|
|
|
5
5
|
children?: string;
|
|
6
6
|
disabled?: string;
|
|
7
7
|
selectable?: string;
|
|
8
|
+
label?: string;
|
|
8
9
|
}
|
|
9
10
|
/**
|
|
10
11
|
* transDataParam 根据指定选项字段名重组数据
|
|
11
12
|
*
|
|
12
13
|
* @params {array} array 树数据集合
|
|
13
|
-
* @params {object} optionName 选项字段值
|
|
14
|
+
* @params {object} optionName 选项字段值(tree-select的标题使用的是label字段)
|
|
14
15
|
*
|
|
15
16
|
* */
|
|
16
|
-
export declare function transDataParam(array
|
|
17
|
+
export declare function transDataParam(array: any[], optionName?: optionNameProps, extra?: any): any[];
|
|
17
18
|
/**
|
|
18
19
|
* 根据限制字段limitKey进行重组数据
|
|
19
20
|
*
|
|
@@ -25,7 +26,7 @@ export declare function transDataParam(array?: any[], optionName?: optionNamePro
|
|
|
25
26
|
* @Return {array} 返回结果数据
|
|
26
27
|
*
|
|
27
28
|
* */
|
|
28
|
-
export declare function resetDataWithLimit(hasKeys: any[], list: any[], optionName
|
|
29
|
+
export declare function resetDataWithLimit(hasKeys: any[], list: any[], optionName: optionNameProps, limitKey: string): any[];
|
|
29
30
|
/**
|
|
30
31
|
* 根据指定禁用字段 disabledFields 进行重组数据
|
|
31
32
|
*
|
package/es/RefactorTree/util.js
CHANGED
|
@@ -5,11 +5,14 @@ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Sym
|
|
|
5
5
|
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
6
6
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
7
7
|
import { __rest } from "tslib";
|
|
8
|
+
/* eslint-disable */
|
|
9
|
+
// import * as React from 'react';
|
|
10
|
+
import { getNodePaths, getParentNodes } from '../utils/getParentNodes';
|
|
8
11
|
/**
|
|
9
12
|
* transDataParam 根据指定选项字段名重组数据
|
|
10
13
|
*
|
|
11
14
|
* @params {array} array 树数据集合
|
|
12
|
-
* @params {object} optionName 选项字段值
|
|
15
|
+
* @params {object} optionName 选项字段值(tree-select的标题使用的是label字段)
|
|
13
16
|
*
|
|
14
17
|
* */
|
|
15
18
|
export function transDataParam(array) {
|
|
@@ -17,29 +20,70 @@ export function transDataParam(array) {
|
|
|
17
20
|
key: 'key',
|
|
18
21
|
value: 'key',
|
|
19
22
|
title: 'title',
|
|
23
|
+
label: 'label',
|
|
20
24
|
children: 'children',
|
|
21
25
|
disabled: 'disabled',
|
|
22
26
|
selectable: 'selectable'
|
|
23
27
|
};
|
|
28
|
+
var extra = arguments.length > 2 ? arguments[2] : undefined;
|
|
24
29
|
var _trans = function trans(list) {
|
|
25
|
-
if (!list) return
|
|
30
|
+
if (!list) return [];
|
|
26
31
|
return list.map(function (item) {
|
|
27
32
|
if (item.hasOwnProperty(optionName.disabled || 'disabled')) {
|
|
28
|
-
item.disabled = item[optionName.disabled || 'disabled'];
|
|
33
|
+
item[optionName.disabled || 'disabled'] = item[optionName.disabled || 'disabled'];
|
|
29
34
|
}
|
|
30
35
|
if (item.hasOwnProperty(optionName.selectable || 'selectable')) {
|
|
31
|
-
item.selectable = item[optionName.selectable || 'selectable'];
|
|
36
|
+
item[optionName.selectable || 'selectable'] = item[optionName.selectable || 'selectable'];
|
|
32
37
|
}
|
|
33
38
|
if (item.hasOwnProperty(optionName.children || 'children')) {
|
|
34
39
|
item.children = item[optionName.children || 'children'] ? _trans(item[optionName.children || 'children']) : [];
|
|
40
|
+
item[optionName.children || 'children'] = item[optionName.children || 'children'] ? _trans(item[optionName.children || 'children']) : [];
|
|
41
|
+
}
|
|
42
|
+
var newNodeInfo = getParentNodes(array, item[optionName.value || optionName.key || 'key'], {
|
|
43
|
+
childrenParam: (optionName === null || optionName === void 0 ? void 0 : optionName.children) || 'children',
|
|
44
|
+
keyParam: optionName.value || optionName.key || 'key'
|
|
45
|
+
});
|
|
46
|
+
var pathNodes = getNodePaths(array, item[optionName.value || optionName.key || 'key'], {
|
|
47
|
+
childrenParam: (optionName === null || optionName === void 0 ? void 0 : optionName.children) || 'children',
|
|
48
|
+
keyParam: optionName.value || optionName.key || 'key'
|
|
49
|
+
}, {});
|
|
50
|
+
/// disabledFields:指定禁用节点
|
|
51
|
+
var resetByDisabledFields = function resetByDisabledFields(initItem) {
|
|
52
|
+
var oldItem = Object.assign({}, initItem);
|
|
53
|
+
var nodeItem = __rest(oldItem, []);
|
|
54
|
+
Object.keys(nodeItem).forEach(function (itemKeyName) {
|
|
55
|
+
var _a;
|
|
56
|
+
var isMatch = extra.disabledFields.find(function (fItem) {
|
|
57
|
+
return fItem.key === itemKeyName;
|
|
58
|
+
});
|
|
59
|
+
if (isMatch) {
|
|
60
|
+
// 确认是否匹配数据,进行设置 disabled
|
|
61
|
+
if ((_a = isMatch.value.split(',')) === null || _a === void 0 ? void 0 : _a.includes(nodeItem[itemKeyName])) {
|
|
62
|
+
nodeItem[optionName.disabled || 'disabled'] = true;
|
|
63
|
+
} else if (nodeItem.hasOwnProperty(optionName.disabled || 'disabled')) {
|
|
64
|
+
nodeItem[optionName.disabled || 'disabled'] = nodeItem[optionName.disabled || 'disabled'];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
return nodeItem;
|
|
69
|
+
};
|
|
70
|
+
if ((extra === null || extra === void 0 ? void 0 : extra.disabledFields) && Array.isArray(extra === null || extra === void 0 ? void 0 : extra.disabledFields)) {
|
|
71
|
+
item = resetByDisabledFields(item);
|
|
35
72
|
}
|
|
36
73
|
return Object.assign(Object.assign({}, item), {
|
|
37
74
|
key: item[optionName.value || optionName.key || 'key'],
|
|
38
|
-
title: item[optionName.title || 'title']
|
|
75
|
+
title: item[optionName.title || optionName.label || 'label' || 'title'],
|
|
76
|
+
label: item[optionName.title || optionName.label || 'label' || 'title'],
|
|
77
|
+
treeFullLevelNamePath: pathNodes,
|
|
78
|
+
treeFullLevelName: pathNodes.map(function (item) {
|
|
79
|
+
return item[optionName.title || optionName.label || 'label' || 'title'];
|
|
80
|
+
}).join((extra === null || extra === void 0 ? void 0 : extra.separator) || '/'),
|
|
81
|
+
treeParentKeys: newNodeInfo.parentKeys.reverse(),
|
|
82
|
+
treeParentNodes: newNodeInfo.nodeParent.reverse()
|
|
39
83
|
});
|
|
40
84
|
});
|
|
41
85
|
};
|
|
42
|
-
return _trans(array);
|
|
86
|
+
return _trans(array || []);
|
|
43
87
|
}
|
|
44
88
|
/**
|
|
45
89
|
* 根据限制字段limitKey进行重组数据
|
|
@@ -81,7 +125,7 @@ export function resetDataWithLimit(hasKeys, list) {
|
|
|
81
125
|
var _filterResetSameLevel = function filterResetSameLevel(preList, matchDataValue) {
|
|
82
126
|
if (!preList) return [];
|
|
83
127
|
if (!matchDataValue) return preList;
|
|
84
|
-
return preList
|
|
128
|
+
return (preList || []).map(function (preItem) {
|
|
85
129
|
var oldItem = Object.assign({}, preItem);
|
|
86
130
|
var item = __rest(oldItem, []);
|
|
87
131
|
if (item[limitKey] !== matchDataValue) {
|
|
@@ -128,7 +172,7 @@ export function resetDataWithDisabled(list, optionName, disabledFields) {
|
|
|
128
172
|
var item = __rest(oldItem, []);
|
|
129
173
|
Object.keys(item).forEach(function (itemKeyName) {
|
|
130
174
|
var _a;
|
|
131
|
-
var isMatch = fields.find(function (fItem) {
|
|
175
|
+
var isMatch = (fields || []).find(function (fItem) {
|
|
132
176
|
return fItem.key === itemKeyName;
|
|
133
177
|
});
|
|
134
178
|
if (isMatch) {
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { FanContext } from "../ConfigContext";
|
|
3
|
+
import bnBD from '../locales/bn-BD';
|
|
4
|
+
import enUS from '../locales/en-US';
|
|
5
|
+
import faIR from '../locales/fa-IR';
|
|
6
|
+
import idID from '../locales/id-ID';
|
|
7
|
+
import jaJP from '../locales/ja-JP';
|
|
8
|
+
import ptBR from '../locales/pt-BR';
|
|
9
|
+
import zhCN from '../locales/zh-CN';
|
|
10
|
+
import zhTW from '../locales/zh-TW';
|
|
11
|
+
var langCompare = {
|
|
12
|
+
'bn': 'bn-BD',
|
|
13
|
+
'en': 'en-US',
|
|
14
|
+
'fa': 'fa-IR',
|
|
15
|
+
'id': 'id-ID',
|
|
16
|
+
'ja': 'ja-JP',
|
|
17
|
+
'pt': 'pt-BR',
|
|
18
|
+
'zh-cn': 'zh-CN',
|
|
19
|
+
'zh-tw': 'zh-TW'
|
|
20
|
+
};
|
|
21
|
+
// 'bn-BD', 'en-US', 'fa-IR', 'id-ID', 'ja-JP', 'pt-BR', 'zh-CN', 'zh-TW'
|
|
22
|
+
export var renderLangObject = function renderLangObject(obj, language) {
|
|
23
|
+
if (!obj) return {};
|
|
24
|
+
if (obj === null || obj === void 0 ? void 0 : obj[language.replace('-', '')]) return obj[language.replace('-', '')];
|
|
25
|
+
// @ts-ignore
|
|
26
|
+
if ((langCompare === null || langCompare === void 0 ? void 0 : langCompare[language]) && (obj === null || obj === void 0 ? void 0 : obj[langCompare === null || langCompare === void 0 ? void 0 : langCompare[language].replace('-', '')])) return obj[langCompare[language].replace('-', '')];
|
|
27
|
+
return obj.zhCN; // Object.values(obj)[0] // 默认使用中文
|
|
28
|
+
};
|
|
29
|
+
export var useLanguageObject = function useLanguageObject() {
|
|
30
|
+
var _a;
|
|
31
|
+
var InitFanContext = useContext(FanContext);
|
|
32
|
+
var language = ((_a = InitFanContext === null || InitFanContext === void 0 ? void 0 : InitFanContext.locale) === null || _a === void 0 ? void 0 : _a.locale) || 'zh-CN';
|
|
33
|
+
var customObj = (InitFanContext === null || InitFanContext === void 0 ? void 0 : InitFanContext.locale) || {}; // 里面可以配置扩展语言包或者替换原来的语言包
|
|
34
|
+
return renderLangObject(Object.assign({
|
|
35
|
+
zhCN: zhCN,
|
|
36
|
+
enUS: enUS,
|
|
37
|
+
bnBD: bnBD,
|
|
38
|
+
faIR: faIR,
|
|
39
|
+
idID: idID,
|
|
40
|
+
jaJP: jaJP,
|
|
41
|
+
ptBR: ptBR,
|
|
42
|
+
zhTW: zhTW
|
|
43
|
+
}, customObj), language);
|
|
44
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useThrottle: (callback: any, delay: any) => (boolean | ((...args: any) => void))[];
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
2
|
+
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."); }
|
|
3
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
4
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
5
|
+
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; } }
|
|
6
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
7
|
+
// @ts-nocheck
|
|
8
|
+
import { useCallback, useState, useRef, useEffect } from 'react';
|
|
9
|
+
// 自定义节流Hook
|
|
10
|
+
export var useThrottle = function useThrottle(callback, delay) {
|
|
11
|
+
var _useState = useState(true),
|
|
12
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
13
|
+
isReady = _useState2[0],
|
|
14
|
+
setIsReady = _useState2[1];
|
|
15
|
+
var timerRef = useRef(null);
|
|
16
|
+
var throttledFn = useCallback(function () {
|
|
17
|
+
if (isReady) {
|
|
18
|
+
setIsReady(false);
|
|
19
|
+
callback === null || callback === void 0 ? void 0 : callback.apply(void 0, arguments); // 执行回调
|
|
20
|
+
//
|
|
21
|
+
timerRef.current = setTimeout(function () {
|
|
22
|
+
setIsReady(true);
|
|
23
|
+
}, delay);
|
|
24
|
+
}
|
|
25
|
+
}, [callback, delay, isReady]);
|
|
26
|
+
// 清理定时器
|
|
27
|
+
useEffect(function () {
|
|
28
|
+
return function () {
|
|
29
|
+
if (timerRef.current) clearTimeout(timerRef.current);
|
|
30
|
+
};
|
|
31
|
+
}, []);
|
|
32
|
+
return [throttledFn, isReady]; // 返回函数和就绪状态
|
|
33
|
+
};
|