Files
lislgosms/src/layouts/AdminLayout.tsx
T

204 lines
7.8 KiB
TypeScript

import {
useCallback,
useEffect,
useState,
} from 'react';
import {
Activity,
AlertTriangle,
BarChart3,
Building2,
FileCheck2,
FileText,
FileSpreadsheet,
FilePenLine,
Gauge,
Hash,
ImageIcon,
ListChecks,
Layers3,
MessageSquare,
Phone,
RefreshCw,
TrendingUp,
RadioTower,
ReceiptText,
ClipboardList,
Send,
ScanSearch,
Settings,
Shield,
ShieldOff,
ShieldCheck,
Users,
UserX,
} from 'lucide-react';
import { adminApi } from '@/api/adminApi';
import { getLastUserActivityAt, readSession, type LoginSession } from '@/api/session';
import { AppShell } from '@/layouts/AppShell';
import { PortalSessionBoundary } from '@/layouts/PortalSessionBoundary';
const EMPTY_PENDING_AUDITS = { enterpriseCertifications: 0, smsAudits: 0, templates: 0, signatures: 0, drainageInfos: 0 };
export function AdminLayout() {
return <PortalSessionBoundary portal="admin">{(session) => <AdminAuthenticatedLayout session={session} />}</PortalSessionBoundary>;
}
function AdminAuthenticatedLayout({ session }: { session: LoginSession }) {
const [pendingAudits, setPendingAudits] = useState(EMPTY_PENDING_AUDITS);
const [sessionLocked, setSessionLocked] = useState(Boolean(session.locked));
const loadPendingAuditCount = useCallback(() => {
const currentSession = readSession('admin');
if (!currentSession || currentSession.locked
|| Date.now() - getLastUserActivityAt() >= currentSession.idleTimeoutSeconds * 1000) {
return;
}
// This runs globally and on a timer, so it must not fan out through the full dashboard aggregation.
adminApi.getPendingAudits()
.then((counts) => {
setPendingAudits(counts);
})
.catch(() => {
setPendingAudits(EMPTY_PENDING_AUDITS);
});
}, []);
useEffect(() => {
if (session.portal !== 'admin' || sessionLocked) {
return;
}
loadPendingAuditCount();
const timer = window.setInterval(loadPendingAuditCount, 30000);
const onFocus = () => loadPendingAuditCount();
const onAuditRefresh = () => loadPendingAuditCount();
window.addEventListener('focus', onFocus);
window.addEventListener('cmpp-audit-count-refresh', onAuditRefresh);
return () => {
window.clearInterval(timer);
window.removeEventListener('focus', onFocus);
window.removeEventListener('cmpp-audit-count-refresh', onAuditRefresh);
};
}, [loadPendingAuditCount, session.portal, sessionLocked]);
return (
<AppShell
title="CMPP 运营端"
subtitle="平台运营管理中心"
workspaceName="平台运营工作区"
loginPath="/admin/login"
portal="admin"
userName={session.user.displayName}
userRole="平台管理员"
onSessionLockedChange={setSessionLocked}
auditNotifications={[
{ label: '企业认证待审', count: pendingAudits.enterpriseCertifications, to: '/admin/enterprise-audit' },
{ label: '短信审核待审', count: pendingAudits.smsAudits, to: '/admin/sms-audit' },
{ label: '模板待审', count: pendingAudits.templates, to: '/admin/templates' },
{ label: '签名待审', count: pendingAudits.signatures, to: '/admin/signatures' },
{ label: '引流信息待审', count: pendingAudits.drainageInfos, to: '/admin/drainage-audits' },
]}
navSections={[
{
title: '运营概览',
icon: Gauge,
items: [
{ label: '运营看板', to: '/admin', icon: Gauge },
{ label: '发送监控', to: '/admin/monitor', icon: Activity },
{ label: '网关异常', to: '/admin/gateway-submit-exceptions', icon: AlertTriangle },
{ label: '数据统计', to: '/admin/analytics', icon: BarChart3 },
],
},
{
title: '客户管理',
icon: Building2,
items: [
{ label: '企业管理', to: '/admin/customer-enterprises', icon: Building2 },
{ label: '企业应用管理', to: '/admin/enterprise-applications', icon: Layers3 },
{ label: '企业签名管理', to: '/admin/enterprise-signatures', icon: FilePenLine },
{ label: '企业模板管理', to: '/admin/enterprise-templates', icon: FileCheck2 },
],
},
{
title: '审核中心',
icon: FileCheck2,
items: [
{ label: '企业认证审核', to: '/admin/enterprise-audit', icon: ShieldCheck },
{ label: '短信审核', to: '/admin/sms-audit', icon: MessageSquare },
{ label: '短信模板审核', to: '/admin/templates', icon: FileCheck2 },
{ label: '短信签名审核', to: '/admin/signatures', icon: FilePenLine },
{ label: '引流信息审核', to: '/admin/drainage-audits', icon: FilePenLine },
],
},
{
title: '通道管理',
icon: RadioTower,
items: [
{ label: '短信通道管理', to: '/admin/channels', icon: RadioTower },
{ label: '彩信通道管理', to: '/admin/mms-channels', icon: ImageIcon, pending: true },
{ label: '短信通道组管理', to: '/admin/channel-groups', icon: Layers3 },
],
},
{
title: '报备任务',
icon: ClipboardList,
items: [
{ label: '待生成报备批次', to: '/admin/report-materials', icon: FileSpreadsheet },
{ label: '报备明细', to: '/admin/report-tasks', icon: ClipboardList },
{ label: '报备记录', to: '/admin/report-records', icon: ListChecks },
],
},
{
title: '发送任务',
icon: Send,
items: [
{ label: '短信任务进度', to: '/admin/sms-task-progress', icon: TrendingUp },
{ label: '彩信任务进度', to: '/admin/mms-task-progress', icon: BarChart3, pending: true },
],
},
{
title: '数据详单',
icon: ReceiptText,
items: [
{ label: '短信记录', to: '/admin/sms-records', icon: MessageSquare },
{ label: '彩信记录', to: '/admin/mms-records', icon: ImageIcon, pending: true },
{ label: '短信上行记录', to: '/admin/sms-uplink-records', icon: MessageSquare },
{ label: '下游投递记录', to: '/admin/downstream-deliveries', icon: Send },
{ label: '恢复状态管理', to: '/admin/downstream-recovery-statuses', icon: RefreshCw },
{ label: '充值记录', to: '/admin/recharge-records', icon: ReceiptText },
],
},
{
title: '报表对账',
icon: BarChart3,
items: [
{ label: '对账单', to: '/admin/reconciliation-reports', icon: ReceiptText },
{ label: '利润报表', to: '/admin/profit-reports', icon: TrendingUp },
{ label: '发送质量报表', to: '/admin/quality-reports', icon: BarChart3 },
],
},
{
title: '安全控制',
icon: Shield,
items: [
{ label: '风控规则', to: '/admin/risk-rules', icon: Shield },
{ label: '企业黑名单', to: '/admin/enterprise-blacklist', icon: UserX },
{ label: '全局黑名单', to: '/admin/global-blacklist', icon: ShieldOff },
{ label: '敏感词管理', to: '/admin/sensitive-words', icon: Shield },
],
},
{
title: '系统管理',
icon: Settings,
items: [
{ label: '用户管理', to: '/admin/users', icon: Users },
{ label: '手机号段库', to: '/admin/phone-segments', icon: Phone },
{ label: '报备字段库', to: '/admin/drainage-fields', icon: Hash },
{ label: '引流识别规则', to: '/admin/drainage-detection-rules', icon: ScanSearch },
{ label: '系统日志', to: '/admin/system-logs', icon: FileText },
],
},
]}
/>
);
}