优化PersonnelSelect

master
LiuJiaNan 2026-01-19 11:04:14 +08:00
parent 60e668e2a6
commit 80d4a3fc5f
1 changed files with 17 additions and 1 deletions

View File

@ -2,6 +2,9 @@ import { request } from "@cqsjjb/jjb-common-lib/http.js";
import { useEffect, useState } from "react";
import BasicSelect from "../../Basic";
// 全局缓存
const cacheMap = new Map();
/**
* 人员下拉组件港务局版本
*/
@ -22,6 +25,15 @@ function PersonnelSelect(props) {
const [data, setData] = useState([]);
const getData = async () => {
// 生成缓存键
const cacheKey = JSON.stringify({ params, extraParams });
// 检查缓存,如果存在直接返回缓存结果
if (cacheMap.has(cacheKey)) {
setData(cacheMap.get(cacheKey));
return;
}
setData([]);
// 根据参数决定是否发送请求
if (isNeedCorpInfoId && !params.corpinfoId)
@ -35,7 +47,11 @@ function PersonnelSelect(props) {
return;
}
const { data } = await request("/basicInfo/user/listAll", "get", { ...params, ...extraParams });
const { data } = await request("/basicInfo/user/listAll", "get", { ...params, ...extraParams, time: new Date().getTime() });
// 存入缓存
cacheMap.set(cacheKey, data);
setData(data);
};