2026-01-06 15:24:18 +08:00
|
|
|
|
import { request } from "@cqsjjb/jjb-common-lib/http.js";
|
2025-11-03 16:50:34 +08:00
|
|
|
|
import { useEffect, useState } from "react";
|
2025-11-06 14:31:25 +08:00
|
|
|
|
import BasicSelectTree from "../../Basic";
|
2025-11-03 16:50:34 +08:00
|
|
|
|
|
2026-01-19 11:04:24 +08:00
|
|
|
|
// 全局缓存
|
|
|
|
|
|
const cacheMap = new Map();
|
|
|
|
|
|
|
2025-11-03 16:50:34 +08:00
|
|
|
|
/**
|
2025-11-06 14:31:25 +08:00
|
|
|
|
* 部门下拉树组件(港务局版本)
|
2025-11-03 16:50:34 +08:00
|
|
|
|
*/
|
|
|
|
|
|
function DepartmentSelectTree(props) {
|
|
|
|
|
|
const {
|
|
|
|
|
|
params = {},
|
2025-11-06 09:38:23 +08:00
|
|
|
|
placeholder = "部门",
|
|
|
|
|
|
isNeedCorpInfoId = false,
|
|
|
|
|
|
isNeedParentId = false,
|
2025-11-19 17:38:56 +08:00
|
|
|
|
searchType = "current",
|
2025-11-03 16:50:34 +08:00
|
|
|
|
...restProps
|
|
|
|
|
|
} = props;
|
|
|
|
|
|
|
2025-11-04 17:41:15 +08:00
|
|
|
|
const [treeData, setTreeData] = useState([]);
|
2025-11-03 16:50:34 +08:00
|
|
|
|
|
|
|
|
|
|
const getData = async () => {
|
2026-01-19 11:04:24 +08:00
|
|
|
|
// 生成缓存键
|
|
|
|
|
|
const paramsStr = JSON.stringify(params);
|
|
|
|
|
|
const cacheKey = `${searchType}_${paramsStr}`;
|
|
|
|
|
|
|
|
|
|
|
|
// 检查缓存,如果存在直接返回缓存结果
|
|
|
|
|
|
if (cacheMap.has(cacheKey)) {
|
|
|
|
|
|
setTreeData(cacheMap.get(cacheKey));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-06 09:38:23 +08:00
|
|
|
|
setTreeData([]);
|
|
|
|
|
|
|
2025-11-19 17:40:49 +08:00
|
|
|
|
if (searchType === "current") {
|
2025-11-19 17:38:56 +08:00
|
|
|
|
if (isNeedCorpInfoId && !params.eqCorpinfoId)
|
|
|
|
|
|
return;
|
|
|
|
|
|
if (isNeedParentId && !params.eqParentId)
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-11-06 09:38:23 +08:00
|
|
|
|
|
2026-01-07 15:35:29 +08:00
|
|
|
|
let requestUrl = "";
|
2026-01-19 11:04:24 +08:00
|
|
|
|
const actualParams = { ...params, time: new Date().getTime() };
|
2026-01-16 10:16:27 +08:00
|
|
|
|
if (searchType === "current") {
|
2026-01-07 15:35:29 +08:00
|
|
|
|
requestUrl = "/basicInfo/department/listTree";
|
2026-01-16 10:16:27 +08:00
|
|
|
|
actualParams.inType = undefined;
|
|
|
|
|
|
actualParams.enterpriseType = undefined;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (searchType === "all") {
|
2026-01-07 15:35:29 +08:00
|
|
|
|
requestUrl = "/basicInfo/department/listAllTree";
|
2026-01-16 10:16:27 +08:00
|
|
|
|
actualParams.inType = undefined;
|
|
|
|
|
|
actualParams.enterpriseType = undefined;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (searchType === "inType") {
|
2026-01-07 15:35:29 +08:00
|
|
|
|
requestUrl = "/basicInfo/department/listAllTreeByCorpType";
|
2026-01-16 10:16:27 +08:00
|
|
|
|
actualParams.eqCorpinfoId = undefined;
|
|
|
|
|
|
actualParams.eqParentId = undefined;
|
|
|
|
|
|
}
|
2026-01-07 15:35:29 +08:00
|
|
|
|
|
2026-01-16 10:16:27 +08:00
|
|
|
|
const { data } = await request(requestUrl, "post", actualParams);
|
2026-01-19 11:04:24 +08:00
|
|
|
|
|
|
|
|
|
|
// 存入缓存
|
|
|
|
|
|
cacheMap.set(cacheKey, data);
|
|
|
|
|
|
|
2025-11-03 16:50:34 +08:00
|
|
|
|
setTreeData(data);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
getData();
|
2025-11-19 17:38:56 +08:00
|
|
|
|
}, [JSON.stringify(params), isNeedCorpInfoId, isNeedParentId, searchType]);
|
2025-11-03 16:50:34 +08:00
|
|
|
|
|
|
|
|
|
|
return (
|
2025-11-08 12:07:29 +08:00
|
|
|
|
<BasicSelectTree treeData={treeData} placeholder={placeholder} childrenKey="childrenList" {...restProps} />
|
2025-11-03 16:50:34 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DepartmentSelectTree.displayName = "DepartmentSelectTree";
|
|
|
|
|
|
|
|
|
|
|
|
export default DepartmentSelectTree;
|