2026-06-30 15:56:53 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 浼佷笟淇℃伅妯″潡鍒濆鍖栦笌涓嬫媺鏁版嵁鎷夊彇锛堢粫杩?DVA锛岄伩鍏?loading 鐘舵€佸鑷撮〉闈㈤噸娓叉煋姝诲惊鐜級
|
2026-06-25 16:30:37 +08:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
|
fromPageResponse,
|
|
|
|
|
|
fromSingleResponse,
|
|
|
|
|
|
toDepartmentForm,
|
|
|
|
|
|
toOrgInfoForm,
|
|
|
|
|
|
toPageQuery,
|
|
|
|
|
|
toPositionForm,
|
|
|
|
|
|
} from "./adapter";
|
|
|
|
|
|
import { apiGet } from "./http";
|
2026-06-26 14:27:49 +08:00
|
|
|
|
import { clearOrgInfoId, getOrgInfoId, setOrgInfoId } from "./orgContext";
|
|
|
|
|
|
|
2026-06-30 15:56:53 +08:00
|
|
|
|
/** 鏈烘瀯淇℃伅绠$悊椤佃矾寰勶紙鏃犳満鏋勬暟鎹椂鍞竴鍙闂〉锛?*/
|
2026-06-26 14:27:49 +08:00
|
|
|
|
export const ORG_INFO_PAGE_PATH = "/certificate/container/EnterpriseInfo/OrgInfo";
|
2026-06-30 15:56:53 +08:00
|
|
|
|
export const MATERIAL_REPORT_PAGE_PATH = "/certificate/container/EnterpriseInfo/MaterialReport";
|
2026-06-25 16:30:37 +08:00
|
|
|
|
|
|
|
|
|
|
let ensureOrgPromise = null;
|
2026-06-30 15:56:53 +08:00
|
|
|
|
/** 鏈€杩戜竴娆?getInfo 杞崲缁撴灉锛屼緵鏈烘瀯淇℃伅椤靛鐢紝閬垮厤閲嶅璇锋眰 */
|
2026-06-26 14:27:49 +08:00
|
|
|
|
let lastOrgInfoDetail = null;
|
|
|
|
|
|
|
|
|
|
|
|
export function isOrgInfoPage(path = window.location.pathname) {
|
2026-06-30 15:56:53 +08:00
|
|
|
|
return path === ORG_INFO_PAGE_PATH || path.startsWith(`${ORG_INFO_PAGE_PATH}/`) || path === MATERIAL_REPORT_PAGE_PATH || path.startsWith(`${MATERIAL_REPORT_PAGE_PATH}/`);
|
2026-06-26 14:27:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function getOrgInfoDetail() {
|
|
|
|
|
|
return lastOrgInfoDetail;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function setOrgInfoDetailCache(detail) {
|
|
|
|
|
|
lastOrgInfoDetail = detail;
|
|
|
|
|
|
}
|
2026-06-25 16:30:37 +08:00
|
|
|
|
|
2026-06-26 14:27:49 +08:00
|
|
|
|
function fetchOrgInfoContext() {
|
|
|
|
|
|
return apiGet("/safety-eval/org-info/getInfo", {}, {}, { includeOrgContext: false })
|
|
|
|
|
|
.then((res) => {
|
|
|
|
|
|
lastOrgInfoDetail = fromSingleResponse(res, toOrgInfoForm);
|
|
|
|
|
|
const id = lastOrgInfoDetail?.data?.id ?? res?.data?.id;
|
|
|
|
|
|
if (id) {
|
|
|
|
|
|
setOrgInfoId(id);
|
|
|
|
|
|
return { hasOrg: true, orgInfoId: String(id), detail: lastOrgInfoDetail };
|
|
|
|
|
|
}
|
|
|
|
|
|
clearOrgInfoId();
|
|
|
|
|
|
return { hasOrg: false, orgInfoId: null, detail: lastOrgInfoDetail };
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
console.warn("[ensureOrgContext] getInfo failed:", err);
|
|
|
|
|
|
clearOrgInfoId();
|
|
|
|
|
|
lastOrgInfoDetail = { success: false, data: null };
|
|
|
|
|
|
return { hasOrg: false, orgInfoId: null, detail: lastOrgInfoDetail, networkError: true };
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2026-06-30 15:56:53 +08:00
|
|
|
|
* 纭繚宸茬紦瀛樻満鏋?id锛堝瓙琛ㄥ垎椤?璇锋眰澶?orgInfoId 渚濊禆姝ゅ€硷級
|
|
|
|
|
|
* @param {{ force?: boolean }} options force=true 鏃跺拷鐣ョ紦瀛樺苟閲嶆柊 getInfo锛堣繘鍏ヤ紒涓氫俊鎭ā鍧楁椂浣跨敤锛?
|
2026-06-26 14:27:49 +08:00
|
|
|
|
* @returns {Promise<{ hasOrg: boolean, orgInfoId: string|null, detail?: object, networkError?: boolean }>}
|
|
|
|
|
|
*/
|
|
|
|
|
|
export function ensureOrgContext(options = {}) {
|
|
|
|
|
|
const { force = false } = options;
|
|
|
|
|
|
|
|
|
|
|
|
if (!force) {
|
|
|
|
|
|
const cached = getOrgInfoId();
|
|
|
|
|
|
if (cached) {
|
|
|
|
|
|
return Promise.resolve({ hasOrg: true, orgInfoId: cached, detail: lastOrgInfoDetail });
|
|
|
|
|
|
}
|
2026-06-25 16:30:37 +08:00
|
|
|
|
}
|
2026-06-26 14:27:49 +08:00
|
|
|
|
|
|
|
|
|
|
if (ensureOrgPromise) {
|
|
|
|
|
|
return ensureOrgPromise;
|
2026-06-25 16:30:37 +08:00
|
|
|
|
}
|
2026-06-26 14:27:49 +08:00
|
|
|
|
|
|
|
|
|
|
ensureOrgPromise = fetchOrgInfoContext().finally(() => {
|
|
|
|
|
|
ensureOrgPromise = null;
|
|
|
|
|
|
});
|
2026-06-25 16:30:37 +08:00
|
|
|
|
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);
|
|
|
|
|
|
}
|
2026-06-30 15:56:53 +08:00
|
|
|
|
|
|
|
|
|
|
|