916 lines
34 KiB
React
916 lines
34 KiB
React
/*
|
||
Copyright (C) 2025 QuantumNous
|
||
|
||
This program is free software: you can redistribute it and/or modify
|
||
it under the terms of the GNU Affero General Public License as
|
||
published by the Free Software Foundation, either version 3 of the
|
||
License, or (at your option) any later version.
|
||
|
||
This program is distributed in the hope that it will be useful,
|
||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
GNU Affero General Public License for more details.
|
||
|
||
You should have received a copy of the GNU Affero General Public License
|
||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||
|
||
For commercial licensing, please contact support@quantumnous.com
|
||
*/
|
||
import React, {
|
||
useContext,
|
||
useEffect,
|
||
useState,
|
||
useCallback,
|
||
useRef,
|
||
useMemo,
|
||
} from 'react';
|
||
import { Routes, Route, Navigate, useNavigate } from 'react-router-dom';
|
||
import { useTranslation } from 'react-i18next';
|
||
import { Button } from '@douyinfe/semi-ui';
|
||
import OrgSideSheet from './components/OrgSideSheet';
|
||
import { Menu } from 'lucide-react';
|
||
import { StatusContext } from '../../context/Status';
|
||
import { UserContext } from '../../context/User';
|
||
import { API } from '../../helpers/api';
|
||
import { showError } from '../../helpers';
|
||
import Loading from '../../components/common/ui/Loading';
|
||
import PageBackground from '../../components/common/PageBackground';
|
||
import OrgSidebar from './OrgSidebar';
|
||
import OrgWorkbench from './OrgWorkbench';
|
||
import OrgDashboard from './OrgDashboard';
|
||
import OrgMembers from './OrgMembers';
|
||
import OrgDepartments from './OrgDepartments';
|
||
import OrgProjects from './OrgProjects';
|
||
import OrgBudgets from './OrgBudgets';
|
||
import OrgRequests from './OrgRequests';
|
||
import OrgTokens from './OrgTokens';
|
||
import OrgDeptManage from './OrgDeptManage';
|
||
import OrgProjectManage from './OrgProjectManage';
|
||
import OrgAudit from './OrgAudit';
|
||
import OrgLogs from './OrgLogs';
|
||
import OrgSettings from './OrgSettings';
|
||
import OrgRecharge from './OrgRecharge';
|
||
import OrgPersonalSettings from './OrgPersonalSettings';
|
||
import CloudBrain from '../CloudBrain';
|
||
import OrgKnowledge from './OrgKnowledge';
|
||
import OrgSkillCenter from './OrgSkillCenter';
|
||
import OrgSkillAssignments from './OrgSkillAssignments';
|
||
import OrgMyCapabilities from './OrgMyCapabilities';
|
||
import OrgExperts from './OrgExperts';
|
||
import OrgAgentAudit from './OrgAgentAudit';
|
||
import OrgConnectors from './OrgConnectors';
|
||
import OrgEffectiveness from './OrgEffectiveness';
|
||
import OrgQuality from './OrgQuality';
|
||
import { normalizeSidebarModulesAdmin } from '../../constants/sidebarModules';
|
||
import { canAccessOrgSettings } from './orgFeatureFlags';
|
||
import {
|
||
CLOUD_BRAIN_UI_ENABLED,
|
||
isCloudBrainOrgModule,
|
||
} from '../../config/cloudBrainUi';
|
||
import '../../styles/org.css';
|
||
|
||
const routeFeatureRequirements = {
|
||
cloudBrain: 'cloud_brain',
|
||
knowledge: 'knowledge_base',
|
||
skillLibrary: 'skill_market',
|
||
skillAssignments: 'skill_market',
|
||
mySkills: 'skill_market',
|
||
experts: 'expert',
|
||
agentAudit: 'cloud_brain',
|
||
connectors: 'connector',
|
||
myConnectors: 'connector',
|
||
effectiveness: 'agent_effectiveness',
|
||
quality: 'quality_monitor',
|
||
privateSkills: 'skill_market',
|
||
departments: 'dept',
|
||
projects: 'project',
|
||
projectManage: 'project',
|
||
budgets: 'budget',
|
||
requests: 'approval',
|
||
};
|
||
|
||
const parseFeatureFlags = (raw) => {
|
||
if (!raw) return {};
|
||
if (typeof raw === 'object') return raw;
|
||
try {
|
||
return JSON.parse(raw) || {};
|
||
} catch {
|
||
return {};
|
||
}
|
||
};
|
||
|
||
const isFeatureEnabled = (flags, key) => {
|
||
if (!key) return true;
|
||
const value = flags?.[key];
|
||
return value === true || value === 'true' || value === '1' || value === 1;
|
||
};
|
||
|
||
const Organization = () => {
|
||
const { t } = useTranslation();
|
||
const navigate = useNavigate();
|
||
const [mobileNavOpen, setMobileNavOpen] = useState(false);
|
||
const navigateRef = useRef(navigate);
|
||
navigateRef.current = navigate;
|
||
|
||
const [statusState] = useContext(StatusContext);
|
||
const [userState] = useContext(UserContext);
|
||
// org_only 员工被 App 守卫限制在 /org;这里的回退不能再把他们踢回 C 端,否则死循环
|
||
const isOrgUser = userState?.user?.org_only_mode === true;
|
||
const [orgInfo, setOrgInfo] = useState(null);
|
||
const [orgRole, setOrgRole] = useState(null);
|
||
const [canManageCloudBrain, setCanManageCloudBrain] = useState(false);
|
||
const [canManageKnowledge, setCanManageKnowledge] = useState(false);
|
||
const [canAuditKnowledge, setCanAuditKnowledge] = useState(false);
|
||
const [canManageSkills, setCanManageSkills] = useState(false);
|
||
const [canAssignSkills, setCanAssignSkills] = useState(false);
|
||
const [canManageExperts, setCanManageExperts] = useState(false);
|
||
const [canManageConnectors, setCanManageConnectors] = useState(false);
|
||
const [canAuditAgentMetadata, setCanAuditAgentMetadata] = useState(false);
|
||
const [canAuditAgentContent, setCanAuditAgentContent] = useState(false);
|
||
const [canViewAgentEffect, setCanViewAgentEffect] = useState(false);
|
||
const [canViewQuality, setCanViewQuality] = useState(false);
|
||
const [canManageAgentPolicy, setCanManageAgentPolicy] = useState(false);
|
||
// 平台超管查看企业时没有成员身份,成员型接口一律 member_actor_required;
|
||
// 用该标志收敛“我的技能/我的业务系统授权”这类必失败入口。
|
||
const [isMemberActor, setIsMemberActor] = useState(true);
|
||
const [loading, setLoading] = useState(true);
|
||
const [pendingActivation, setPendingActivation] = useState(false);
|
||
const [isDeptManager, setIsDeptManager] = useState(false);
|
||
const [deptScopeLoaded, setDeptScopeLoaded] = useState(false);
|
||
const [isProjectManager, setIsProjectManager] = useState(false);
|
||
const [projectScopeLoaded, setProjectScopeLoaded] = useState(false);
|
||
|
||
const hasMarquee = !!statusState?.status?.marquee_content?.trim();
|
||
const isAdmin =
|
||
orgRole === 'owner' || orgRole === 'admin' || orgRole === 'super_admin';
|
||
const orgConfig = useMemo(
|
||
() =>
|
||
normalizeSidebarModulesAdmin(statusState?.status?.SidebarModulesAdmin)
|
||
.orgCenter,
|
||
[statusState?.status?.SidebarModulesAdmin],
|
||
);
|
||
const orgFeatureFlags = useMemo(
|
||
() => parseFeatureFlags(orgInfo?.feature_flags),
|
||
[orgInfo?.feature_flags],
|
||
);
|
||
const canManageSettings = canAccessOrgSettings(orgRole, orgFeatureFlags);
|
||
const isOrgModuleVisible = useCallback(
|
||
(key) => {
|
||
if (!CLOUD_BRAIN_UI_ENABLED && isCloudBrainOrgModule(key)) return false;
|
||
return (
|
||
orgConfig?.enabled !== false &&
|
||
orgConfig?.[key] !== false &&
|
||
isFeatureEnabled(orgFeatureFlags, routeFeatureRequirements[key])
|
||
);
|
||
},
|
||
[orgConfig, orgFeatureFlags],
|
||
);
|
||
const visibleOrgRoutes = useMemo(() => {
|
||
const routes = [];
|
||
// 管理员默认落 dashboard;普通成员默认落 workbench(§36 角色化首屏)
|
||
if (isAdmin && isOrgModuleVisible('dashboard')) routes.push('dashboard');
|
||
if (isOrgModuleVisible('workbench')) routes.push('workbench');
|
||
if (isOrgModuleVisible('cloudBrain')) routes.push('cloud-brain');
|
||
// 成员型入口对无成员身份的超管隐藏;否则模块配置特定组合下
|
||
// hiddenOrgTarget 可能算出指向自身的 Navigate 造成重定向自环。
|
||
// 我的技能 + 业务系统授权已合并为「我的 AI 能力」,任一页签可见即入路由。
|
||
if (
|
||
isMemberActor &&
|
||
(isOrgModuleVisible('mySkills') || isOrgModuleVisible('myConnectors'))
|
||
)
|
||
routes.push('my-capabilities');
|
||
if (isAdmin && canManageConnectors && isOrgModuleVisible('connectors'))
|
||
routes.push('connectors');
|
||
if (isAdmin && canManageExperts && isOrgModuleVisible('experts'))
|
||
routes.push('experts');
|
||
if (isAdmin && canViewAgentEffect && isOrgModuleVisible('effectiveness'))
|
||
routes.push('effectiveness');
|
||
if (isAdmin && canViewQuality && isOrgModuleVisible('quality'))
|
||
routes.push('quality');
|
||
// 审计路由组后端是 OrgAdminAuth(仅 owner/admin),不放行部门负责人;
|
||
// 这里必须同样只认 isAdmin。此前的 isDeptManager 分支当前不可达
|
||
// (canAuditAgentMetadata 对非 owner/admin 恒 false),但一旦把
|
||
// agent_audit_metadata 下放给 dept_admin,就会变成"入口可见但接口必 403"。
|
||
if (isAdmin && canAuditAgentMetadata && isOrgModuleVisible('agentAudit'))
|
||
routes.push('agent-audit');
|
||
// 技能库 + 自研 Skill 已合并为「技能中心」;平台技能的启用动作
|
||
// 有两个入口:平台技能超市(/skill-market)就地启用,或技能中心内的
|
||
// 「引入技能」抽屉(供超管与被挡在超市外的管理员使用)。企业技能市场
|
||
// 路由已不存在,旧路径重定向。
|
||
if (
|
||
isAdmin &&
|
||
canManageSkills &&
|
||
(isOrgModuleVisible('skillLibrary') ||
|
||
isOrgModuleVisible('privateSkills'))
|
||
)
|
||
routes.push('skill-center');
|
||
if (
|
||
(isAdmin || isDeptManager) &&
|
||
canAssignSkills &&
|
||
isOrgModuleVisible('skillAssignments')
|
||
)
|
||
routes.push('skill-assignments');
|
||
if (isAdmin && canManageKnowledge && isOrgModuleVisible('knowledge'))
|
||
routes.push('knowledge');
|
||
if (
|
||
isAdmin &&
|
||
(isOrgModuleVisible('members') || isOrgModuleVisible('memberAccounts'))
|
||
) {
|
||
routes.push('members');
|
||
}
|
||
if (isDeptManager && isOrgModuleVisible('deptManage'))
|
||
routes.push('dept-manage');
|
||
if (isProjectManager && isOrgModuleVisible('projectManage'))
|
||
routes.push('project-manage');
|
||
if (isAdmin && isOrgModuleVisible('departments'))
|
||
routes.push('departments');
|
||
if (isAdmin && isOrgModuleVisible('projects')) routes.push('projects');
|
||
if (isAdmin && isOrgModuleVisible('budgets')) routes.push('budgets');
|
||
if (isOrgModuleVisible('requests')) routes.push('requests');
|
||
if (isOrgModuleVisible('tokens')) routes.push('tokens');
|
||
if (isOrgModuleVisible('logs')) routes.push('logs');
|
||
if (isAdmin && isOrgModuleVisible('audit')) routes.push('audit');
|
||
if (isAdmin && isOrgModuleVisible('recharge')) routes.push('recharge');
|
||
if (canManageSettings && isOrgModuleVisible('settings'))
|
||
routes.push('settings');
|
||
return routes;
|
||
}, [
|
||
isAdmin,
|
||
canManageKnowledge,
|
||
canManageSkills,
|
||
canAssignSkills,
|
||
canManageExperts,
|
||
canManageConnectors,
|
||
canAuditAgentMetadata,
|
||
canViewAgentEffect,
|
||
canViewQuality,
|
||
isDeptManager,
|
||
isProjectManager,
|
||
isMemberActor,
|
||
canManageSettings,
|
||
isOrgModuleVisible,
|
||
]);
|
||
const firstOrgRoute = visibleOrgRoutes[0] || null;
|
||
const firstOrgTarget = firstOrgRoute
|
||
? `/org/${firstOrgRoute}`
|
||
: '/user-center/dashboard';
|
||
const hiddenOrgTarget = firstOrgTarget;
|
||
const guardOrgRoute = (key, element) => {
|
||
if (!isOrgModuleVisible(key)) {
|
||
return <Navigate to={hiddenOrgTarget} replace />;
|
||
}
|
||
return element;
|
||
};
|
||
|
||
// 从 localStorage 获取当前企业ID
|
||
const orgId = parseInt(localStorage.getItem('current_org_id') || '0', 10);
|
||
|
||
const fetchOrgInfo = useCallback(async () => {
|
||
if (!orgId) {
|
||
setLoading(false);
|
||
return;
|
||
}
|
||
setLoading(true);
|
||
setPendingActivation(false);
|
||
try {
|
||
const res = await API.get('/api/org/info', {
|
||
headers: { 'X-Org-Id': String(orgId) },
|
||
});
|
||
if (res.data.success) {
|
||
const member = res.data.data.member || res.data.data;
|
||
setOrgInfo(res.data.data.organization);
|
||
setOrgRole(member.role);
|
||
setCanManageCloudBrain(member.can_manage_cloud_brain === true);
|
||
setCanManageKnowledge(member.can_manage_knowledge === true);
|
||
setCanAuditKnowledge(member.can_audit_knowledge === true);
|
||
setCanManageSkills(member.can_manage_skills === true);
|
||
setCanAssignSkills(member.can_assign_skills === true);
|
||
setCanManageExperts(member.can_manage_experts === true);
|
||
setCanManageConnectors(member.can_manage_connectors === true);
|
||
setCanViewAgentEffect(member.can_view_agent_effect === true);
|
||
setCanViewQuality(member.can_view_quality === true);
|
||
setCanManageAgentPolicy(member.can_manage_agent_policy === true);
|
||
// 后端未返回该键时按“有成员身份”处理,避免旧后端下入口消失。
|
||
setIsMemberActor(member.is_member_actor !== false);
|
||
setCanAuditAgentMetadata(member.can_audit_agent_metadata === true);
|
||
setCanAuditAgentContent(member.can_audit_agent_content === true);
|
||
} else if (res.data.code === 'org_pending_activation') {
|
||
// 待激活:不跳转创建页,展示占位页,保留 current_org_id
|
||
setPendingActivation(true);
|
||
} else {
|
||
showError(res.data.message);
|
||
localStorage.removeItem('current_org_id');
|
||
navigateRef.current('/org/create', { replace: true });
|
||
}
|
||
} catch {
|
||
localStorage.removeItem('current_org_id');
|
||
navigateRef.current('/org/create', { replace: true });
|
||
} finally {
|
||
setLoading(false);
|
||
}
|
||
}, [orgId]);
|
||
|
||
useEffect(() => {
|
||
fetchOrgInfo();
|
||
}, [fetchOrgInfo]);
|
||
|
||
// 是否为部门负责人(控制「部门管理」入口/路由),失败按非负责人处理。
|
||
useEffect(() => {
|
||
let cancelled = false;
|
||
if (!orgId) {
|
||
setIsDeptManager(false);
|
||
setDeptScopeLoaded(true);
|
||
return () => {
|
||
cancelled = true;
|
||
};
|
||
}
|
||
setIsDeptManager(false);
|
||
setDeptScopeLoaded(false);
|
||
API.get('/api/org/me/dept-scope', {
|
||
headers: { 'X-Org-Id': String(orgId) },
|
||
})
|
||
.then((res) => {
|
||
if (!cancelled) {
|
||
setIsDeptManager(
|
||
!!(res.data.success && res.data.data?.is_dept_manager),
|
||
);
|
||
}
|
||
})
|
||
.catch(() => {
|
||
if (!cancelled) setIsDeptManager(false);
|
||
})
|
||
.finally(() => {
|
||
if (!cancelled) setDeptScopeLoaded(true);
|
||
});
|
||
return () => {
|
||
cancelled = true;
|
||
};
|
||
}, [orgId]);
|
||
|
||
// 是否为项目经理(控制「我的项目」入口/路由)
|
||
useEffect(() => {
|
||
if (!orgId) {
|
||
setIsProjectManager(false);
|
||
setProjectScopeLoaded(true);
|
||
return;
|
||
}
|
||
setProjectScopeLoaded(false);
|
||
API.get('/api/org/me/project-scope', {
|
||
headers: { 'X-Org-Id': String(orgId) },
|
||
})
|
||
.then((res) => {
|
||
setIsProjectManager(
|
||
!!(res.data.success && res.data.data?.is_project_manager),
|
||
);
|
||
})
|
||
.catch(() => setIsProjectManager(false))
|
||
.finally(() => setProjectScopeLoaded(true));
|
||
}, [orgId]);
|
||
|
||
// org_only 员工无可用企业功能时的非循环提示(不跳 C 端)
|
||
const orgUnavailableFallback = (
|
||
<div className='flex flex-col items-center justify-center h-screen px-6 text-center bg-[var(--surface-bg-base)]'>
|
||
<div className='max-w-md'>
|
||
<div className='text-2xl font-semibold mb-3'>
|
||
{t('暂无可用的企业功能')}
|
||
</div>
|
||
<p className='text-[var(--text-secondary)]'>
|
||
{t('您的账号当前没有可访问的企业功能,请联系企业管理员开通。')}
|
||
</p>
|
||
</div>
|
||
</div>
|
||
);
|
||
|
||
if (orgConfig.enabled === false) {
|
||
if (isOrgUser) return orgUnavailableFallback;
|
||
return <Navigate to='/user-center/dashboard' replace />;
|
||
}
|
||
|
||
if (!orgId) {
|
||
return <Navigate to='/org/create' replace />;
|
||
}
|
||
|
||
if (loading) {
|
||
return <Loading />;
|
||
}
|
||
|
||
// 待激活占位页:不展示任何企业功能,仅引导联系客服/管理员
|
||
if (pendingActivation) {
|
||
return (
|
||
<div className='flex flex-col items-center justify-center h-screen px-6 text-center bg-[var(--surface-bg-base)]'>
|
||
<div className='max-w-md'>
|
||
<div className='text-2xl font-semibold mb-3'>{t('企业待激活')}</div>
|
||
<p className='text-[var(--text-secondary)] mb-6'>
|
||
{t(
|
||
'您的企业已创建,正在等待平台管理员审核激活。激活后即可使用企业工作台与治理功能,请联系客服或销售协助开通。',
|
||
)}
|
||
</p>
|
||
<div className='flex gap-3 justify-center'>
|
||
<button
|
||
className='px-4 py-2 rounded-md border border-[var(--semi-color-border)]'
|
||
onClick={() => fetchOrgInfo()}
|
||
>
|
||
{t('刷新状态')}
|
||
</button>
|
||
{!isOrgUser && (
|
||
<button
|
||
className='px-4 py-2 rounded-md bg-[var(--semi-color-primary)] text-white'
|
||
onClick={() =>
|
||
navigateRef.current('/user-center/dashboard', {
|
||
replace: true,
|
||
})
|
||
}
|
||
>
|
||
{t('返回个人中心')}
|
||
</button>
|
||
)}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
if (!firstOrgRoute) {
|
||
if (isOrgUser) return orgUnavailableFallback;
|
||
return <Navigate to='/user-center/dashboard' replace />;
|
||
}
|
||
|
||
return (
|
||
<div
|
||
className={`org-center flex flex-col md:flex-row h-screen overflow-hidden bg-[var(--surface-bg-base)] transition-colors duration-300 ${hasMarquee ? 'pt-[96px] sm:pt-[104px]' : 'pt-14 sm:pt-16'}`}
|
||
>
|
||
{/* Sidebar - desktop only */}
|
||
<div className='hidden md:block flex-shrink-0 h-full'>
|
||
<OrgSidebar
|
||
orgName={orgInfo?.name}
|
||
orgRole={orgRole}
|
||
featureFlags={orgFeatureFlags}
|
||
isDeptManager={isDeptManager}
|
||
isProjectManager={isProjectManager}
|
||
canManageKnowledge={canManageKnowledge}
|
||
canManageSkills={canManageSkills}
|
||
canAssignSkills={canAssignSkills}
|
||
canManageExperts={canManageExperts}
|
||
canManageConnectors={canManageConnectors}
|
||
canAuditAgentMetadata={canAuditAgentMetadata}
|
||
canViewAgentEffect={canViewAgentEffect}
|
||
canViewQuality={canViewQuality}
|
||
isMemberActor={isMemberActor}
|
||
/>
|
||
</div>
|
||
|
||
{/* Main Content */}
|
||
<div className='flex-1 h-full overflow-hidden relative flex flex-col'>
|
||
{/* 移动端顶栏:汉堡菜单 + 当前企业名(窄屏唯一的菜单入口) */}
|
||
<div className='md:hidden flex items-center gap-2 px-3 h-12 flex-shrink-0 border-b border-[var(--border-subtle)] bg-[var(--surface-header)] relative z-20'>
|
||
<Button
|
||
icon={<Menu size={20} />}
|
||
theme='borderless'
|
||
type='tertiary'
|
||
onClick={() => setMobileNavOpen(true)}
|
||
aria-label={t('打开菜单')}
|
||
/>
|
||
<span className='font-semibold text-gray-900 dark:text-white truncate'>
|
||
{orgInfo?.name || t('企业中心')}
|
||
</span>
|
||
</div>
|
||
|
||
<div className='flex-1 relative overflow-hidden'>
|
||
{/* 统一页面背景层 —— 唯一背景来源;实底卡片方案下降为 subtle 档,
|
||
不再叠加硬编码渐变装饰层(原 teal/amber 层不跟主题预设,已删除) */}
|
||
<PageBackground variant='subtle' />
|
||
|
||
<div className='relative z-10 h-full overflow-y-auto uc-page-scrollbar'>
|
||
<Routes>
|
||
{/* 默认路由:管理员进数据看板,普通成员进工作台 */}
|
||
<Route
|
||
path='/'
|
||
element={<Navigate to={firstOrgTarget} replace />}
|
||
/>
|
||
{/* 数据看板、员工管理、审计日志、企业设置仅 admin/owner 可访问;消耗明细普通成员可看本人 */}
|
||
<Route
|
||
path='dashboard'
|
||
element={
|
||
isAdmin ? (
|
||
guardOrgRoute(
|
||
'dashboard',
|
||
<OrgDashboard
|
||
orgId={orgId}
|
||
orgRole={orgRole}
|
||
featureFlags={orgFeatureFlags}
|
||
/>,
|
||
)
|
||
) : (
|
||
<Navigate to={hiddenOrgTarget} replace />
|
||
)
|
||
}
|
||
/>
|
||
<Route
|
||
path='members'
|
||
element={
|
||
isAdmin &&
|
||
(isOrgModuleVisible('members') ||
|
||
isOrgModuleVisible('memberAccounts')) ? (
|
||
<OrgMembers
|
||
orgId={orgId}
|
||
orgRole={orgRole}
|
||
showMemberList={isOrgModuleVisible('members')}
|
||
showAccounts={isOrgModuleVisible('memberAccounts')}
|
||
featureFlags={orgFeatureFlags}
|
||
/>
|
||
) : (
|
||
<Navigate to={hiddenOrgTarget} replace />
|
||
)
|
||
}
|
||
/>
|
||
<Route
|
||
path='member-accounts'
|
||
element={
|
||
isAdmin &&
|
||
(isOrgModuleVisible('members') ||
|
||
isOrgModuleVisible('memberAccounts')) ? (
|
||
<Navigate to='/org/members' replace />
|
||
) : (
|
||
<Navigate to={hiddenOrgTarget} replace />
|
||
)
|
||
}
|
||
/>
|
||
<Route
|
||
path='departments'
|
||
element={
|
||
isAdmin ? (
|
||
guardOrgRoute(
|
||
'departments',
|
||
<OrgDepartments orgId={orgId} orgRole={orgRole} />,
|
||
)
|
||
) : (
|
||
<Navigate to={hiddenOrgTarget} replace />
|
||
)
|
||
}
|
||
/>
|
||
<Route
|
||
path='projects'
|
||
element={
|
||
isAdmin ? (
|
||
guardOrgRoute(
|
||
'projects',
|
||
<OrgProjects orgId={orgId} orgRole={orgRole} />,
|
||
)
|
||
) : (
|
||
<Navigate to={hiddenOrgTarget} replace />
|
||
)
|
||
}
|
||
/>
|
||
<Route
|
||
path='logs'
|
||
element={guardOrgRoute(
|
||
'logs',
|
||
isAdmin || deptScopeLoaded ? (
|
||
<OrgLogs
|
||
orgId={orgId}
|
||
orgRole={orgRole}
|
||
isDeptManager={isDeptManager}
|
||
/>
|
||
) : (
|
||
<Loading />
|
||
),
|
||
)}
|
||
/>
|
||
<Route
|
||
path='audit'
|
||
element={
|
||
isAdmin ? (
|
||
guardOrgRoute('audit', <OrgAudit orgId={orgId} />)
|
||
) : (
|
||
<Navigate to={hiddenOrgTarget} replace />
|
||
)
|
||
}
|
||
/>
|
||
<Route
|
||
path='settings'
|
||
element={
|
||
canManageSettings ? (
|
||
guardOrgRoute(
|
||
'settings',
|
||
<OrgSettings
|
||
key={orgId}
|
||
orgId={orgId}
|
||
orgRole={orgRole}
|
||
/>,
|
||
)
|
||
) : (
|
||
<Navigate to={hiddenOrgTarget} replace />
|
||
)
|
||
}
|
||
/>
|
||
<Route
|
||
path='recharge'
|
||
element={
|
||
isAdmin ? (
|
||
guardOrgRoute('recharge', <OrgRecharge orgId={orgId} />)
|
||
) : (
|
||
<Navigate to={hiddenOrgTarget} replace />
|
||
)
|
||
}
|
||
/>
|
||
{/* 部门管理 - 部门负责人可访问(阶段一);与菜单/project-manage
|
||
同口径消费 deptManage 管理开关,避免"菜单隐藏但直达 URL 可进" */}
|
||
<Route
|
||
path='dept-manage'
|
||
element={
|
||
isDeptManager && isOrgModuleVisible('deptManage') ? (
|
||
<OrgDeptManage
|
||
orgId={orgId}
|
||
orgRole={orgRole}
|
||
featureFlags={orgFeatureFlags}
|
||
/>
|
||
) : !deptScopeLoaded ? (
|
||
<Loading />
|
||
) : (
|
||
<Navigate to={hiddenOrgTarget} replace />
|
||
)
|
||
}
|
||
/>
|
||
{/* 我的项目 - 项目经理可访问(阶段一) */}
|
||
<Route
|
||
path='project-manage'
|
||
element={
|
||
isProjectManager && isOrgModuleVisible('projectManage') ? (
|
||
<OrgProjectManage orgId={orgId} orgRole={orgRole} />
|
||
) : !projectScopeLoaded ? (
|
||
<Loading />
|
||
) : (
|
||
<Navigate to={hiddenOrgTarget} replace />
|
||
)
|
||
}
|
||
/>
|
||
{/* 企业工作台 - 所有成员可访问(§36.1) */}
|
||
<Route
|
||
path='workbench'
|
||
element={guardOrgRoute(
|
||
'workbench',
|
||
<OrgWorkbench
|
||
orgId={orgId}
|
||
orgRole={orgRole}
|
||
featureFlags={orgFeatureFlags}
|
||
/>,
|
||
)}
|
||
/>
|
||
<Route
|
||
path='cloud-brain'
|
||
element={guardOrgRoute(
|
||
'cloudBrain',
|
||
<CloudBrain
|
||
organization
|
||
orgId={orgId}
|
||
canManage={canManageCloudBrain}
|
||
/>,
|
||
)}
|
||
/>
|
||
<Route
|
||
path='knowledge'
|
||
element={
|
||
isAdmin && canManageKnowledge ? (
|
||
guardOrgRoute(
|
||
'knowledge',
|
||
<OrgKnowledge
|
||
orgId={orgId}
|
||
canAuditContent={canAuditKnowledge}
|
||
/>,
|
||
)
|
||
) : (
|
||
<Navigate to={hiddenOrgTarget} replace />
|
||
)
|
||
}
|
||
/>
|
||
{/* 我的 AI 能力:我的技能 + 业务系统授权 合并页(成员自助视图) */}
|
||
<Route
|
||
path='my-capabilities'
|
||
element={
|
||
isMemberActor &&
|
||
(isOrgModuleVisible('mySkills') ||
|
||
isOrgModuleVisible('myConnectors')) ? (
|
||
<OrgMyCapabilities
|
||
orgId={orgId}
|
||
showSkills={isOrgModuleVisible('mySkills')}
|
||
showConnectors={isOrgModuleVisible('myConnectors')}
|
||
/>
|
||
) : (
|
||
<Navigate to={hiddenOrgTarget} replace />
|
||
)
|
||
}
|
||
/>
|
||
{/* 旧路径兼容:合并前的两个成员页重定向到对应页签 */}
|
||
<Route
|
||
path='my-connectors'
|
||
element={
|
||
<Navigate to='/org/my-capabilities?tab=connectors' replace />
|
||
}
|
||
/>
|
||
<Route
|
||
path='connectors'
|
||
element={
|
||
isAdmin && canManageConnectors ? (
|
||
guardOrgRoute('connectors', <OrgConnectors orgId={orgId} />)
|
||
) : (
|
||
<Navigate to={hiddenOrgTarget} replace />
|
||
)
|
||
}
|
||
/>
|
||
<Route
|
||
path='experts'
|
||
element={
|
||
isAdmin && canManageExperts ? (
|
||
guardOrgRoute('experts', <OrgExperts orgId={orgId} />)
|
||
) : (
|
||
<Navigate to={hiddenOrgTarget} replace />
|
||
)
|
||
}
|
||
/>
|
||
<Route
|
||
path='effectiveness'
|
||
element={
|
||
isAdmin && canViewAgentEffect ? (
|
||
guardOrgRoute(
|
||
'effectiveness',
|
||
<OrgEffectiveness
|
||
orgId={orgId}
|
||
canManagePolicy={canManageAgentPolicy}
|
||
canManageSkills={canManageSkills}
|
||
/>,
|
||
)
|
||
) : (
|
||
<Navigate to={hiddenOrgTarget} replace />
|
||
)
|
||
}
|
||
/>
|
||
<Route
|
||
path='quality'
|
||
element={
|
||
isAdmin && canViewQuality ? (
|
||
guardOrgRoute('quality', <OrgQuality orgId={orgId} />)
|
||
) : (
|
||
<Navigate to={hiddenOrgTarget} replace />
|
||
)
|
||
}
|
||
/>
|
||
<Route
|
||
path='agent-audit'
|
||
element={
|
||
isAdmin && canAuditAgentMetadata ? (
|
||
guardOrgRoute(
|
||
'agentAudit',
|
||
<OrgAgentAudit
|
||
orgId={orgId}
|
||
canAuditContent={canAuditAgentContent}
|
||
canManagePolicy={canManageAgentPolicy}
|
||
/>,
|
||
)
|
||
) : (
|
||
<Navigate to={hiddenOrgTarget} replace />
|
||
)
|
||
}
|
||
/>
|
||
<Route
|
||
path='my-skills'
|
||
element={
|
||
<Navigate to='/org/my-capabilities?tab=skills' replace />
|
||
}
|
||
/>
|
||
{/* 技能中心:企业技能库 + 企业自研 Skill 合并页 */}
|
||
<Route
|
||
path='skill-center'
|
||
element={
|
||
isAdmin &&
|
||
canManageSkills &&
|
||
(isOrgModuleVisible('skillLibrary') ||
|
||
isOrgModuleVisible('privateSkills')) ? (
|
||
<OrgSkillCenter
|
||
orgId={orgId}
|
||
orgRole={orgRole}
|
||
canAssignSkills={canAssignSkills}
|
||
showLibrary={isOrgModuleVisible('skillLibrary')}
|
||
showPrivate={isOrgModuleVisible('privateSkills')}
|
||
/>
|
||
) : (
|
||
<Navigate to={hiddenOrgTarget} replace />
|
||
)
|
||
}
|
||
/>
|
||
{/* 企业技能市场页已并入平台技能超市:管理员在 /skill-market 就地
|
||
为企业启用技能(普通成员落到超市浏览页也无害) */}
|
||
<Route
|
||
path='skill-market'
|
||
element={<Navigate to='/skill-market' replace />}
|
||
/>
|
||
{/* 旧路径兼容:合并前的两个管理页重定向到对应页签 */}
|
||
<Route
|
||
path='skill-library'
|
||
element={
|
||
<Navigate to='/org/skill-center?tab=library' replace />
|
||
}
|
||
/>
|
||
<Route
|
||
path='private-skills'
|
||
element={
|
||
<Navigate to='/org/skill-center?tab=private' replace />
|
||
}
|
||
/>
|
||
<Route
|
||
path='skill-assignments'
|
||
element={
|
||
(isAdmin || isDeptManager) && canAssignSkills ? (
|
||
guardOrgRoute(
|
||
'skillAssignments',
|
||
<OrgSkillAssignments orgId={orgId} orgRole={orgRole} />,
|
||
)
|
||
) : (
|
||
<Navigate to={hiddenOrgTarget} replace />
|
||
)
|
||
}
|
||
/>
|
||
{/* 申请/审批 - 所有成员可访问(成员看自己,管理员审批) */}
|
||
<Route
|
||
path='requests'
|
||
element={guardOrgRoute(
|
||
'requests',
|
||
<OrgRequests
|
||
orgId={orgId}
|
||
orgRole={orgRole}
|
||
featureFlags={orgFeatureFlags}
|
||
/>,
|
||
)}
|
||
/>
|
||
{/* 预算中心 - 仅管理员 */}
|
||
<Route
|
||
path='budgets'
|
||
element={
|
||
isAdmin ? (
|
||
guardOrgRoute('budgets', <OrgBudgets orgId={orgId} />)
|
||
) : (
|
||
<Navigate to={hiddenOrgTarget} replace />
|
||
)
|
||
}
|
||
/>
|
||
{/* 用量分析统一归入数据看板,旧路径重定向 */}
|
||
<Route
|
||
path='analytics'
|
||
element={
|
||
<Navigate
|
||
to={isAdmin ? '/org/dashboard' : hiddenOrgTarget}
|
||
replace
|
||
/>
|
||
}
|
||
/>
|
||
{/* 令牌管理 - 所有成员可访问 */}
|
||
<Route
|
||
path='tokens'
|
||
element={guardOrgRoute(
|
||
'tokens',
|
||
<OrgTokens orgId={orgId} orgRole={orgRole} />,
|
||
)}
|
||
/>
|
||
{/* 个人设置 - 所有成员可访问(头像/昵称/密码/配额预警通知) */}
|
||
<Route
|
||
path='personal-settings'
|
||
element={<OrgPersonalSettings key={orgId} orgId={orgId} />}
|
||
/>
|
||
</Routes>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
{/* 移动端侧栏抽屉(窄屏点击顶栏汉堡菜单打开) */}
|
||
<OrgSideSheet
|
||
placement='left'
|
||
visible={mobileNavOpen}
|
||
onCancel={() => setMobileNavOpen(false)}
|
||
width={260}
|
||
closable={false}
|
||
bodyStyle={{ padding: 0 }}
|
||
>
|
||
<OrgSidebar
|
||
orgName={orgInfo?.name}
|
||
orgRole={orgRole}
|
||
featureFlags={orgFeatureFlags}
|
||
isDeptManager={isDeptManager}
|
||
isProjectManager={isProjectManager}
|
||
canManageKnowledge={canManageKnowledge}
|
||
canManageSkills={canManageSkills}
|
||
canAssignSkills={canAssignSkills}
|
||
canManageExperts={canManageExperts}
|
||
canManageConnectors={canManageConnectors}
|
||
canAuditAgentMetadata={canAuditAgentMetadata}
|
||
canViewAgentEffect={canViewAgentEffect}
|
||
canViewQuality={canViewQuality}
|
||
isMemberActor={isMemberActor}
|
||
mobile
|
||
onNavigate={() => setMobileNavOpen(false)}
|
||
/>
|
||
</OrgSideSheet>
|
||
</div>
|
||
);
|
||
};
|
||
|
||
export default Organization;
|