优化DepartmentSelectTree
parent
80d4a3fc5f
commit
fca5fef60f
|
|
@ -2,6 +2,9 @@ import { request } from "@cqsjjb/jjb-common-lib/http.js";
|
|||
import { useEffect, useState } from "react";
|
||||
import BasicSelectTree from "../../Basic";
|
||||
|
||||
// 全局缓存
|
||||
const cacheMap = new Map();
|
||||
|
||||
/**
|
||||
* 部门下拉树组件(港务局版本)
|
||||
*/
|
||||
|
|
@ -18,10 +21,19 @@ function DepartmentSelectTree(props) {
|
|||
const [treeData, setTreeData] = useState([]);
|
||||
|
||||
const getData = async () => {
|
||||
// 生成缓存键
|
||||
const paramsStr = JSON.stringify(params);
|
||||
const cacheKey = `${searchType}_${paramsStr}`;
|
||||
|
||||
// 检查缓存,如果存在直接返回缓存结果
|
||||
if (cacheMap.has(cacheKey)) {
|
||||
setTreeData(cacheMap.get(cacheKey));
|
||||
return;
|
||||
}
|
||||
|
||||
setTreeData([]);
|
||||
|
||||
if (searchType === "current") {
|
||||
// 根据参数决定是否发送请求
|
||||
if (isNeedCorpInfoId && !params.eqCorpinfoId)
|
||||
return;
|
||||
if (isNeedParentId && !params.eqParentId)
|
||||
|
|
@ -29,7 +41,7 @@ function DepartmentSelectTree(props) {
|
|||
}
|
||||
|
||||
let requestUrl = "";
|
||||
let actualParams = params;
|
||||
const actualParams = { ...params, time: new Date().getTime() };
|
||||
if (searchType === "current") {
|
||||
requestUrl = "/basicInfo/department/listTree";
|
||||
actualParams.inType = undefined;
|
||||
|
|
@ -47,6 +59,10 @@ function DepartmentSelectTree(props) {
|
|||
}
|
||||
|
||||
const { data } = await request(requestUrl, "post", actualParams);
|
||||
|
||||
// 存入缓存
|
||||
cacheMap.set(cacheKey, data);
|
||||
|
||||
setTreeData(data);
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue