zmdms-webui 0.0.55 → 0.0.56
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/es/tree/hooks.js +38 -2
- package/dist/es/tree/tree.js +20 -7
- package/package.json +1 -1
package/dist/es/tree/hooks.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __assign } from '../_virtual/_tslib.js';
|
|
2
|
+
import { useState, useCallback, useEffect, useMemo, useRef } from 'react';
|
|
2
3
|
import { useDebounce } from 'ahooks';
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -206,6 +207,41 @@ function flatTreeData(data, options) {
|
|
|
206
207
|
}
|
|
207
208
|
}
|
|
208
209
|
return flatData;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* 获取当前选中项得全部值
|
|
213
|
+
*/
|
|
214
|
+
function useAllCheckData(props) {
|
|
215
|
+
// 记录选中项得全部内容
|
|
216
|
+
var allCompleteData = useRef({});
|
|
217
|
+
var onCheck = props.onCheck, onSelect = props.onSelect, valueKey = props.valueKey;
|
|
218
|
+
var onCheckHandle = useCallback(function (keys, e) {
|
|
219
|
+
var compData = arrToObj(e.checkedNodes, valueKey);
|
|
220
|
+
allCompleteData.current = __assign(__assign({}, allCompleteData.current), compData);
|
|
221
|
+
onCheck && onCheck(keys, e);
|
|
222
|
+
}, [onCheck, valueKey]);
|
|
223
|
+
var onSelectHandle = useCallback(function (keys, e) {
|
|
224
|
+
var compData = arrToObj(e.selectedNodes, valueKey);
|
|
225
|
+
allCompleteData.current = __assign(__assign({}, allCompleteData.current), compData);
|
|
226
|
+
onSelect && onSelect(keys, e);
|
|
227
|
+
}, [onSelect, valueKey]);
|
|
228
|
+
return {
|
|
229
|
+
onCheckHandle: onCheckHandle,
|
|
230
|
+
onSelectHandle: onSelectHandle,
|
|
231
|
+
allCompleteData: allCompleteData,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
function arrToObj(arr, key) {
|
|
235
|
+
var obj = {};
|
|
236
|
+
if (Array.isArray(arr)) {
|
|
237
|
+
arr.forEach(function (i) {
|
|
238
|
+
var k = i[key];
|
|
239
|
+
if (k) {
|
|
240
|
+
obj[k] = i;
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
return obj;
|
|
209
245
|
}
|
|
210
246
|
|
|
211
|
-
export { useAllDataHandle, useBasicInfo, useLazySearchExpands, useSearchHandle };
|
|
247
|
+
export { useAllCheckData, useAllDataHandle, useBasicInfo, useLazySearchExpands, useSearchHandle };
|
package/dist/es/tree/tree.js
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
import { __rest, __assign } from '../_virtual/_tslib.js';
|
|
2
2
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
-
import { memo, forwardRef } from 'react';
|
|
3
|
+
import { memo, forwardRef, useImperativeHandle } from 'react';
|
|
4
4
|
import { Tree as Tree$1 } from 'antd';
|
|
5
5
|
import MemoInput from '../input/input.js';
|
|
6
6
|
import classNames from '../node_modules/classnames/index.js';
|
|
7
|
-
import { useBasicInfo, useAllDataHandle, useSearchHandle, useLazySearchExpands } from './hooks.js';
|
|
7
|
+
import { useBasicInfo, useAllCheckData, useAllDataHandle, useSearchHandle, useLazySearchExpands } from './hooks.js';
|
|
8
8
|
|
|
9
9
|
var Tree = function (props, ref) {
|
|
10
10
|
var _a;
|
|
11
|
-
var searchType = props.searchType, onSearch = props.onSearch, className = props.className, style = props.style, treeStyle = props.treeStyle, cssTreeHeight = props.cssTreeHeight, _b = props.searchMode, searchMode = _b === void 0 ? "change" : _b, treeData = props.treeData, lazySearchTreeData = props.lazySearchTreeData, loadData = props.loadData, resetProps = __rest(props, ["searchType", "onSearch", "className", "style", "treeStyle", "cssTreeHeight", "searchMode", "treeData", "lazySearchTreeData", "loadData"]);
|
|
11
|
+
var searchType = props.searchType, onSearch = props.onSearch, className = props.className, style = props.style, treeStyle = props.treeStyle, cssTreeHeight = props.cssTreeHeight, _b = props.searchMode, searchMode = _b === void 0 ? "change" : _b, treeData = props.treeData, lazySearchTreeData = props.lazySearchTreeData, loadData = props.loadData, onCheck = props.onCheck, onSelect = props.onSelect, resetProps = __rest(props, ["searchType", "onSearch", "className", "style", "treeStyle", "cssTreeHeight", "searchMode", "treeData", "lazySearchTreeData", "loadData", "onCheck", "onSelect"]);
|
|
12
12
|
var fieldNames = resetProps.fieldNames, checkedKeys = resetProps.checkedKeys;
|
|
13
13
|
var classes = classNames("ztxk-tree", className, {
|
|
14
14
|
"ztxk-tree--height": cssTreeHeight,
|
|
15
15
|
});
|
|
16
16
|
// 获取基础数据的key值
|
|
17
17
|
var _c = useBasicInfo({ fieldNames: fieldNames }), valueKey = _c.valueKey, titleKey = _c.titleKey, childrenKey = _c.childrenKey;
|
|
18
|
+
var _d = useAllCheckData({
|
|
19
|
+
onCheck: onCheck,
|
|
20
|
+
onSelect: onSelect,
|
|
21
|
+
valueKey: valueKey,
|
|
22
|
+
}), onCheckHandle = _d.onCheckHandle, onSelectHandle = _d.onSelectHandle, allCompleteData = _d.allCompleteData;
|
|
18
23
|
// 获取拉平数据
|
|
19
24
|
var flatDataList = useAllDataHandle({
|
|
20
25
|
searchType: searchType,
|
|
@@ -23,7 +28,7 @@ var Tree = function (props, ref) {
|
|
|
23
28
|
childrenKey: childrenKey,
|
|
24
29
|
titleKey: titleKey,
|
|
25
30
|
}).flatDataList;
|
|
26
|
-
var
|
|
31
|
+
var _e = useSearchHandle({
|
|
27
32
|
treeData: treeData,
|
|
28
33
|
flatDataList: flatDataList,
|
|
29
34
|
titleKey: titleKey,
|
|
@@ -31,14 +36,22 @@ var Tree = function (props, ref) {
|
|
|
31
36
|
searchType: searchType,
|
|
32
37
|
onSearch: onSearch,
|
|
33
38
|
searchMode: searchMode,
|
|
34
|
-
}), onSearchHandle =
|
|
35
|
-
var
|
|
39
|
+
}), onSearchHandle = _e.onSearchHandle, onChangeHandle = _e.onChangeHandle, searchValue = _e.searchValue, expandedKeys = _e.expandedKeys, autoExpandParent = _e.autoExpandParent, onExpand = _e.onExpand;
|
|
40
|
+
var _f = useLazySearchExpands(lazySearchTreeData), lazySearchExpandedKeys = _f.expandedKeys, lazySearchAutoExpandParent = _f.autoExpandParent, lazySearchOnExpand = _f.onExpand;
|
|
36
41
|
var showLazySearchTreeData = !!(searchType === "lazy" && searchValue);
|
|
42
|
+
useImperativeHandle(ref, function () {
|
|
43
|
+
return {
|
|
44
|
+
/** 可以根据keys来匹配 */
|
|
45
|
+
getAllCompleteData: function () {
|
|
46
|
+
return allCompleteData.current;
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
});
|
|
37
50
|
return (jsxs("div", __assign({ className: classes, style: __assign({ height: cssTreeHeight }, style) }, { children: [searchType ? (jsx(MemoInput.Search, { value: searchValue, onChange: onChangeHandle, onSearch: onSearchHandle })) : null, (props.checkable || props.multiple) && checkedKeys ? (jsxs("div", { children: ["\u5DF2\u9009\u4E2D\uFF1A", checkedKeys
|
|
38
51
|
? Array.isArray(checkedKeys)
|
|
39
52
|
? checkedKeys.length
|
|
40
53
|
: (_a = checkedKeys.checked) === null || _a === void 0 ? void 0 : _a.length
|
|
41
|
-
: 0, "\u9879"] })) : null, searchType === "lazy" && (jsx(Tree$1, __assign({ treeData: lazySearchTreeData, className: showLazySearchTreeData ? "" : "ztxk-tree--hidden", defaultExpandAll: true, expandedKeys: lazySearchExpandedKeys, autoExpandParent: lazySearchAutoExpandParent, onExpand: lazySearchOnExpand }, resetProps))), jsx(Tree$1, __assign({ expandedKeys: expandedKeys, autoExpandParent: autoExpandParent, onExpand: onExpand, treeData: treeData, loadData: loadData, className: showLazySearchTreeData ? "ztxk-tree--hidden" : "", style: treeStyle }, resetProps))] })));
|
|
54
|
+
: 0, "\u9879"] })) : null, searchType === "lazy" && (jsx(Tree$1, __assign({ treeData: lazySearchTreeData, className: showLazySearchTreeData ? "" : "ztxk-tree--hidden", defaultExpandAll: true, expandedKeys: lazySearchExpandedKeys, autoExpandParent: lazySearchAutoExpandParent, onExpand: lazySearchOnExpand, onCheck: onCheckHandle, onSelect: onSelectHandle }, resetProps))), jsx(Tree$1, __assign({ expandedKeys: expandedKeys, autoExpandParent: autoExpandParent, onExpand: onExpand, treeData: treeData, loadData: loadData, className: showLazySearchTreeData ? "ztxk-tree--hidden" : "", style: treeStyle, onCheck: onCheckHandle, onSelect: onSelectHandle }, resetProps))] })));
|
|
42
55
|
};
|
|
43
56
|
var MemoTree = memo(forwardRef(Tree));
|
|
44
57
|
MemoTree.displayName = "ZTXK_WEBUI_Tree";
|