import { resolveErrorMessage as resolveUserErrorMessage } from "../lib/resolveErrorMessage"; import { useMemo } from "react"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { fetchSystemNavigation, fetchWorkspaceSettings, updateWorkspaceSettings } from "../api/workspace"; import { ListWorkspace, PrimaryTable, WorkspaceHeader } from "../components/patterns/ListWorkspace"; import { Button } from "../components/ui/button"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "../components/ui/table"; import { toast } from "sonner"; const MODULE_LABELS: Record = { portal: "工作台", team: "团队", leaveRequests: "请假记录", attendance: "考勤", reimbursements: "报销", assets: "资产", weeklyReports: "周报", todos: "我的事项", announcements: "公告", projects: "项目", workspace: "工作区设置", people: "人员管理", organization: "组织架构", contractsRegistry: "合同", workflowDefinitions: "流程定义", systemSettings: "管理", featureFlags: "功能管理", auditLogs: "审计日志", approvalRules: "审批规则", userManagement: "用户管理", departments: "部门管理", masterData: "主数据", notificationChannels: "通知渠道", workflowTasks: "待我审批", dashboard: "仪表盘", purchaseRequests: "采购", travelRequests: "差旅申请", budgets: "预算管理", paymentBatches: "付款", apOperations: "应付账款", invoicePool: "票据", inventoryChecks: "资产盘点", cutover: "切换控制台", profile: "个人设置", }; const VISIBILITY_OPTIONS = [ { value: "main", label: "常用入口" }, { value: "admin", label: "管理与更多" }, { value: "hidden", label: "隐藏" }, ] as const; function visibilityModeLabel(mode: string) { return VISIBILITY_OPTIONS.find((item) => item.value === mode)?.label ?? mode; } export function WorkspaceSetupPage() { const queryClient = useQueryClient(); const workspaceQuery = useQuery({ queryKey: ["workspace-settings"], queryFn: fetchWorkspaceSettings }); const navigationQuery = useQuery({ queryKey: ["system-navigation"], queryFn: fetchSystemNavigation }); const mutation = useMutation({ mutationFn: updateWorkspaceSettings, onSuccess: async () => { await Promise.all([ queryClient.invalidateQueries({ queryKey: ["workspace-settings"] }), queryClient.invalidateQueries({ queryKey: ["system-navigation"] }), queryClient.invalidateQueries({ queryKey: ["portal-home"] }), ]); toast.success("工作区设置已保存"); }, onError: (error) => { const message = resolveUserErrorMessage(error, "保存失败"); toast.error(message); }, }); const workspace = workspaceQuery.data; const rolePresets = navigationQuery.data?.recommendedRolePresets ?? []; const moduleEntries = useMemo( () => Object.entries(workspace?.moduleVisibility ?? {}).filter(([key]) => key !== "erpIntegrations"), [workspace?.moduleVisibility], ); const workspaceStats = useMemo(() => { const entries = Object.entries(workspace?.moduleVisibility ?? {}).filter(([key]) => key !== "erpIntegrations"); return { total: entries.length, main: entries.filter(([, mode]) => mode === "main").length, admin: entries.filter(([, mode]) => mode === "admin").length, hidden: entries.filter(([, mode]) => mode === "hidden").length, rolePresets: rolePresets.length, }; }, [rolePresets.length, workspace?.moduleVisibility]); if (workspaceQuery.isLoading || !workspace) { return (
加载工作区设置中...
); } return (
模块总数
{workspaceStats.total}
常用入口
{workspaceStats.main}
管理与更多
{workspaceStats.admin}
隐藏
{workspaceStats.hidden}
初始化
{workspace.persisted ? "已完成" : "待初始化"}

工作区基线

{workspace.profile} · 单公司 · 账号密码 · 站内通知 · 桌面优先。

{workspaceStats.rolePresets} 个角色预设
{rolePresets.length ? (
{rolePresets.map((item) => (
{item.label}
{item.description}
角色:{item.roleCodes.join(" / ")}
))}
) : (
当前没有推荐角色预设。
)}

入口显隐

常用入口只保留高频任务;低频能力保留代码与数据,默认收进管理、更多或隐藏。

模块 当前显隐 操作 {moduleEntries.map(([key, mode]) => ( {MODULE_LABELS[key] ?? key} {visibilityModeLabel(mode)}
{VISIBILITY_OPTIONS.map((option) => ( ))}
))}
); } export default WorkspaceSetupPage;