58 lines
1.6 KiB
JavaScript
58 lines
1.6 KiB
JavaScript
|
|
/**
|
|||
|
|
* 企业信息模块初始化与下拉数据拉取(绕过 DVA,避免 loading 状态导致页面重渲染死循环)
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
import {
|
|||
|
|
fromPageResponse,
|
|||
|
|
fromSingleResponse,
|
|||
|
|
toDepartmentForm,
|
|||
|
|
toOrgInfoForm,
|
|||
|
|
toPageQuery,
|
|||
|
|
toPositionForm,
|
|||
|
|
} from "./adapter";
|
|||
|
|
import { apiGet } from "./http";
|
|||
|
|
import { getOrgInfoId, setOrgInfoId } from "./orgContext";
|
|||
|
|
|
|||
|
|
let ensureOrgPromise = null;
|
|||
|
|
|
|||
|
|
/** 确保已缓存机构 id(全局只发起一次 getInfo) */
|
|||
|
|
export function ensureOrgContext() {
|
|||
|
|
const cached = getOrgInfoId();
|
|||
|
|
if (cached) {
|
|||
|
|
return Promise.resolve(cached);
|
|||
|
|
}
|
|||
|
|
if (!ensureOrgPromise) {
|
|||
|
|
ensureOrgPromise = apiGet("/safety-eval/org-info/getInfo", {}, {}, { includeOrgContext: false })
|
|||
|
|
.then((res) => {
|
|||
|
|
const result = fromSingleResponse(res, toOrgInfoForm);
|
|||
|
|
const id = result?.data?.id ?? res?.data?.id;
|
|||
|
|
if (id) {
|
|||
|
|
setOrgInfoId(id);
|
|||
|
|
}
|
|||
|
|
return getOrgInfoId();
|
|||
|
|
})
|
|||
|
|
.catch(() => null)
|
|||
|
|
.finally(() => {
|
|||
|
|
ensureOrgPromise = null;
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
return ensureOrgPromise;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
export async function fetchOrgDepartmentPage(params = {}) {
|
|||
|
|
await ensureOrgContext();
|
|||
|
|
const query = toPageQuery(params, { likeDeptName: "deptName" });
|
|||
|
|
const res = await apiGet("/safety-eval/org-department/page", query);
|
|||
|
|
return fromPageResponse(res, toDepartmentForm);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
export async function fetchOrgPositionPage(params = {}) {
|
|||
|
|
await ensureOrgContext();
|
|||
|
|
const query = toPageQuery(params, {
|
|||
|
|
eqDeptId: "deptId",
|
|||
|
|
likePositionName: "positionName",
|
|||
|
|
});
|
|||
|
|
const res = await apiGet("/safety-eval/org-position/page", query);
|
|||
|
|
return fromPageResponse(res, toPositionForm);
|
|||
|
|
}
|