zy-react-library/src/components/Select/Personnel/Gwj/index.js

74 lines
1.9 KiB
JavaScript
Raw Normal View History

2026-01-06 15:24:18 +08:00
import { request } from "@cqsjjb/jjb-common-lib/http.js";
2025-11-06 09:38:23 +08:00
import { useEffect, useState } from "react";
import BasicSelect from "../../Basic";
2025-11-06 09:38:23 +08:00
2026-01-19 11:04:14 +08:00
// 全局缓存
const cacheMap = new Map();
2025-11-06 09:38:23 +08:00
/**
* 人员下拉组件港务局版本
2025-11-06 09:38:23 +08:00
*/
function PersonnelSelect(props) {
const {
params = {},
placeholder = "人员",
isNeedCorpInfoId = false,
isNeedDepartmentId = true,
isNeedPostId = false,
2026-01-27 15:49:52 +08:00
extraParams = {},
2025-11-06 09:38:23 +08:00
...restProps
} = props;
2026-01-27 15:49:52 +08:00
const defaultExtraParams = {
noMain: "",
eqEmploymentFlag: 1,
};
2025-11-06 09:38:23 +08:00
const [data, setData] = useState([]);
const getData = async () => {
2026-01-27 15:49:52 +08:00
const actualExtraParams = { ...defaultExtraParams, ...extraParams };
2026-01-19 11:04:14 +08:00
// 生成缓存键
2026-01-27 15:49:52 +08:00
const cacheKey = JSON.stringify({ params, extraParams: actualExtraParams });
2026-01-19 11:04:14 +08:00
// 检查缓存,如果存在直接返回缓存结果
if (cacheMap.has(cacheKey)) {
setData(cacheMap.get(cacheKey));
return;
}
2025-11-06 09:38:23 +08:00
setData([]);
// 根据参数决定是否发送请求
if (isNeedCorpInfoId && !params.corpinfoId)
return;
if (isNeedDepartmentId && !params.departmentId)
return;
if (isNeedPostId && !params.postId)
return;
2026-01-05 15:09:14 +08:00
if (!isNeedCorpInfoId && !isNeedDepartmentId && !isNeedPostId) {
console.error("【PersonnelSelect】 请至少传入一个参数");
2026-01-05 15:09:14 +08:00
return;
}
2025-11-06 09:38:23 +08:00
2026-01-27 15:49:52 +08:00
const { data } = await request("/basicInfo/user/listAll", "get", { ...params, ...actualExtraParams, time: new Date().getTime() });
2026-01-19 11:04:14 +08:00
// 存入缓存
cacheMap.set(cacheKey, data);
2025-11-06 09:38:23 +08:00
setData(data);
};
useEffect(() => {
getData();
2025-12-18 16:30:10 +08:00
}, [JSON.stringify(params), isNeedCorpInfoId, isNeedDepartmentId, isNeedPostId, JSON.stringify(extraParams)]);
2025-11-06 09:38:23 +08:00
return (
<BasicSelect data={data} placeholder={placeholder} {...restProps} />
);
}
PersonnelSelect.displayName = "PersonnelSelect";
export default PersonnelSelect;