zy-react-library 1.0.80 → 1.0.81
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.
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { FC } from "react";
|
|
2
|
+
import type { BasicSelectTreeProps } from "../../Basic";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 组件属性
|
|
6
|
+
*/
|
|
7
|
+
export interface HiddenLevelSelectTreeProps extends Omit<BasicSelectTreeProps, "treeData" | "nameKey" | "idKey" | "childrenKey" | "level"> {
|
|
8
|
+
/** 是否显示忽略隐患,默认 true */
|
|
9
|
+
isShowNeglect?: boolean;
|
|
10
|
+
/** 是否显示较大隐患,默认 true */
|
|
11
|
+
isShowLarger?: boolean;
|
|
12
|
+
/** 是否显示重大隐患,默认 true */
|
|
13
|
+
isShowMajor?: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 隐患级别下拉树组件(港务局版本)
|
|
18
|
+
*/
|
|
19
|
+
declare const HiddenLevelSelectTree: FC<HiddenLevelSelectTreeProps>;
|
|
20
|
+
|
|
21
|
+
export default HiddenLevelSelectTree;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { request } from "@cqsjjb/jjb-common-lib/http";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { DICTIONARY_APP_KEY_ENUM } from "../../../../enum/dictionary";
|
|
4
|
+
import BasicSelectTree from "../../Basic";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 隐患级别下拉树组件(港务局版本)
|
|
8
|
+
*/
|
|
9
|
+
function HiddenLevelSelectTree(props) {
|
|
10
|
+
const {
|
|
11
|
+
isShowNeglect = true,
|
|
12
|
+
isShowLarger = true,
|
|
13
|
+
isShowMajor = true,
|
|
14
|
+
...restProps
|
|
15
|
+
} = props;
|
|
16
|
+
|
|
17
|
+
const [treeData, setTreeData] = useState([]);
|
|
18
|
+
|
|
19
|
+
// 过滤隐患级别的树数据
|
|
20
|
+
const filterTreeData = (treeData) => {
|
|
21
|
+
// 隐患级别的特定ID
|
|
22
|
+
const HIDDEN_LEVEL_IDS = {
|
|
23
|
+
neglect: "hiddenLevel1001", // 忽略隐患
|
|
24
|
+
larger: "jdyh001", // 较大隐患
|
|
25
|
+
major: "hiddenLevel0002", // 重大隐患
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// 递归过滤树数据
|
|
29
|
+
const filterTree = (nodes) => {
|
|
30
|
+
if (!nodes || !Array.isArray(nodes))
|
|
31
|
+
return [];
|
|
32
|
+
|
|
33
|
+
return nodes.filter((node) => {
|
|
34
|
+
// 根据不同的ID和对应的props来决定是否显示
|
|
35
|
+
if (node.dictValue === HIDDEN_LEVEL_IDS.neglect)
|
|
36
|
+
return isShowNeglect;
|
|
37
|
+
if (node.dictValue === HIDDEN_LEVEL_IDS.larger)
|
|
38
|
+
return isShowLarger;
|
|
39
|
+
if (node.dictValue === HIDDEN_LEVEL_IDS.major)
|
|
40
|
+
return isShowMajor;
|
|
41
|
+
|
|
42
|
+
// 如果有子节点,递归过滤子节点
|
|
43
|
+
if (node.children && node.children.length > 0)
|
|
44
|
+
node.children = filterTree(node.children);
|
|
45
|
+
|
|
46
|
+
// 默认显示其他节点
|
|
47
|
+
return true;
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
return filterTree(treeData);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const getData = async () => {
|
|
55
|
+
setTreeData([]);
|
|
56
|
+
const { data } = await request("/config/dict-trees/list/by/dictValues", "get", { appKey: DICTIONARY_APP_KEY_ENUM.GWJ, dictValue: "hiddenLevel" });
|
|
57
|
+
const filterData = filterTreeData(data);
|
|
58
|
+
setTreeData(filterData);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
getData();
|
|
63
|
+
}, []);
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<BasicSelectTree treeData={treeData} nameKey="dictLabel" idKey="dictValue" {...restProps} />
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
HiddenLevelSelectTree.displayName = "HiddenLevelSelectTree";
|
|
71
|
+
|
|
72
|
+
export default HiddenLevelSelectTree;
|