import { request } from "@cqsjjb/jjb-common-lib/http.js"; import { useEffect, useState } from "react"; import BasicLeftTree from "../../Basic"; // 全局缓存 const cacheMap = new Map(); /** * 部门左侧树组件(港务局版本) */ function DepartmentLeftTree(props) { const { params = {}, searchType = "current", ...restProps } = props; const [treeData, setTreeData] = useState([]); const getData = async () => { setTreeData([]); // 生成缓存键 const paramsStr = JSON.stringify(params); const cacheKey = `${searchType}_${paramsStr}`; // 检查缓存,如果存在直接返回缓存结果 if (cacheMap.has(cacheKey)) { setTreeData(cacheMap.get(cacheKey)); return; } let requestUrl = ""; const actualParams = { ...params, time: new Date().getTime() }; if (searchType === "current") { requestUrl = "/basicInfo/department/listTree"; delete actualParams.inType; delete actualParams.enterpriseType; } if (searchType === "all") { requestUrl = "/basicInfo/department/listAllTree"; delete actualParams.inType; delete actualParams.enterpriseType; delete actualParams.eqCorpinfoId; delete actualParams.eqParentId; } if (searchType === "inType") { requestUrl = "/basicInfo/department/listAllTreeByCorpType"; delete actualParams.eqCorpinfoId; delete actualParams.eqParentId; if (actualParams.enterpriseType && !Array.isArray(actualParams.enterpriseType)) { actualParams.enterpriseType = [actualParams.enterpriseType]; } } const { data } = await request(requestUrl, "post", actualParams); // 存入缓存 cacheMap.set(cacheKey, data); setTreeData(data); }; useEffect(() => { getData(); }, []); return ( ); } DepartmentLeftTree.displayName = "DepartmentLeftTree"; export default DepartmentLeftTree;