From 8b7e0438603200b2ae3801807cda9a978b05cbf8 Mon Sep 17 00:00:00 2001 From: shunli Date: Wed, 6 May 2026 00:30:36 +0800 Subject: [PATCH] =?UTF-8?q?R95=20A5=20=E5=90=88=E5=90=8C=E5=8F=B0=E8=B4=A6?= =?UTF-8?q?=E6=9D=83=E9=99=90=E8=AF=B7=E6=B1=82=E9=99=8D=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/pages/ContractsRegistryPage.tsx | 56 +++++++++++++++------- 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/client/src/pages/ContractsRegistryPage.tsx b/client/src/pages/ContractsRegistryPage.tsx index 562588d7..df323ba8 100644 --- a/client/src/pages/ContractsRegistryPage.tsx +++ b/client/src/pages/ContractsRegistryPage.tsx @@ -19,6 +19,8 @@ import { fetchEmployees } from "../api/employees"; import { mapApiErrorMessage } from "../api/errorMessages"; import { fetchProjects, type ConfidentialityLevel } from "../api/projects"; import { isApiError } from "../api/types"; +import { useAuth } from "../auth/AuthContext"; +import { hasAnyPermission } from "../auth/permissions"; import { PageHeader } from "../components/common/PageHeader"; import { StatusBadge } from "../components/common/StatusBadge"; import { Button } from "../components/ui/button"; @@ -124,7 +126,9 @@ function buildFiltersPayload(filters: FiltersState): ContractRegistryFilters { }; } -function buildSavePayload(form: EditorState) { +function buildSavePayload(form: EditorState, options: { includeOwnerEmployeeId?: boolean } = {}) { + const includeOwnerEmployeeId = options.includeOwnerEmployeeId ?? true; + return { contractNo: form.contractNo.trim(), projectId: form.projectId || null, @@ -139,7 +143,7 @@ function buildSavePayload(form: EditorState) { confidentialityLevel: form.confidentialityLevel, archiveLocation: form.archiveLocation.trim(), offlineArchiveNo: form.offlineArchiveNo.trim() || null, - ownerEmployeeId: form.ownerEmployeeId || undefined, + ...(includeOwnerEmployeeId && form.ownerEmployeeId ? { ownerEmployeeId: form.ownerEmployeeId } : {}), status: form.status, }; } @@ -170,8 +174,10 @@ function nextPersistedStatus(item: ContractRegistryItem): ContractRegistryPersis export function ContractsRegistryPage() { const queryClient = useQueryClient(); + const { permissions } = useAuth(); const [searchParams] = useSearchParams(); const initialProjectId = searchParams.get("projectId") ?? ""; + const canBrowseEmployees = hasAnyPermission(permissions, ["system.users", "report.dashboard.view"]); const [filters, setFilters] = useState({ projectId: initialProjectId, @@ -199,15 +205,21 @@ export function ContractsRegistryPage() { queryFn: () => fetchProjects({}), }); const employeesQuery = useQuery({ + enabled: canBrowseEmployees, queryKey: ["employees", "contracts-page"], queryFn: () => fetchEmployees({ page: 1, pageSize: 100, status: "active" }), }); const projectOptions = projectsQuery.data?.items ?? []; - const employeeOptions = employeesQuery.data?.items ?? []; + const employeeOptions = canBrowseEmployees ? employeesQuery.data?.items ?? [] : []; const contracts = contractsQuery.data?.items ?? []; const expiringItems = expiringQuery.data?.items ?? []; const editingItem = editorId ? contracts.find((item) => item.id === editorId) ?? null : null; + const readonlyOwnerLabel = editingItem?.owner + ? `${editingItem.owner.name} · ${editingItem.owner.employeeNo}` + : editor.ownerEmployeeId + ? "保留现有责任人" + : "默认当前用户"; const amountInvalid = Boolean(editor.amount.trim()) && !AMOUNT_PATTERN.test(editor.amount.trim()); const refreshAll = async () => { @@ -224,10 +236,11 @@ export function ContractsRegistryPage() { const saveMutation = useMutation({ mutationFn: async () => { + const payload = buildSavePayload(editor, { includeOwnerEmployeeId: canBrowseEmployees }); if (editorId) { - return patchContractRegistry(editorId, buildSavePayload(editor)); + return patchContractRegistry(editorId, payload); } - return createContractRegistry(buildSavePayload(editor)); + return createContractRegistry(payload); }, onSuccess: async () => { await refreshAll(); @@ -537,18 +550,27 @@ export function ContractsRegistryPage() {
- + {canBrowseEmployees ? ( + + ) : ( +
+
{readonlyOwnerLabel}
+
+ 当前账号无人员目录权限,新建时使用当前用户,编辑时保留原责任人。 +
+
+ )}