safety-eval-service-frontend/src/pages/Container/EnterpriseInfo/index.js

61 lines
1.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import { message, Spin } from "antd";
import { useEffect, useState } from "react";
import {
ensureOrgContext,
isOrgInfoPage,
ORG_INFO_PAGE_PATH,
} from "~/api/enterpriseInfo/orgBootstrap";
/**
* 企业信息模块入口:进入时 getInfo有机构则缓存 orgInfoId无机构则仅允许访问机构信息管理页。
*/
function EnterpriseInfo(props) {
const [checking, setChecking] = useState(true);
const onOrgInfoPage = isOrgInfoPage();
useEffect(() => {
let cancelled = false;
ensureOrgContext({ force: true })
.then((ctx) => {
if (cancelled) {
return;
}
if (ctx?.networkError && onOrgInfoPage) {
message.warning("机构信息加载失败,请确认后端服务已启动");
}
if (!ctx?.hasOrg && !onOrgInfoPage) {
message.warning("请先完善机构信息");
window.location.replace(ORG_INFO_PAGE_PATH);
return;
}
setChecking(false);
})
.catch((err) => {
console.warn("[EnterpriseInfo] ensureOrgContext failed:", err);
if (!cancelled) {
if (onOrgInfoPage) {
message.warning("机构信息加载失败,请确认后端服务已启动");
}
setChecking(false);
}
});
return () => {
cancelled = true;
};
}, [onOrgInfoPage]);
if (checking) {
return <Spin fullscreen tip="正在加载机构信息..." />;
}
return (
<div style={{ height: "100%" }}>
{props.children}
</div>
);
}
export default EnterpriseInfo;