61 lines
1.5 KiB
JavaScript
61 lines
1.5 KiB
JavaScript
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;
|