2026-05-20-14-53-31 逆向结果复核与用户管理修复
This commit is contained in:
@@ -39,6 +39,7 @@ interface ModelPoseRecord {
|
||||
|
||||
interface SegmentationResultRecord {
|
||||
id: string;
|
||||
schemaVersion?: number;
|
||||
name: string;
|
||||
createdAt: string;
|
||||
segmentationScope: SegmentationExportScope;
|
||||
@@ -183,6 +184,16 @@ function publicUser(user: UserRecord) {
|
||||
return rest;
|
||||
}
|
||||
|
||||
function parseUserPayload(body: unknown, existing?: UserRecord) {
|
||||
const source = body && typeof body === 'object' ? body as Record<string, unknown> : {};
|
||||
const name = typeof source.name === 'string' ? source.name.trim() : existing?.name ?? '';
|
||||
const account = typeof source.account === 'string' ? source.account.trim() : existing?.account ?? '';
|
||||
const department = typeof source.department === 'string' ? source.department.trim() : existing?.department ?? '';
|
||||
const password = typeof source.password === 'string' ? source.password : existing?.password ?? '';
|
||||
|
||||
return { name, account, department, password };
|
||||
}
|
||||
|
||||
function publicSession(state: AppState) {
|
||||
const user = state.session.account
|
||||
? state.users.find((candidate) => candidate.account === state.session.account)
|
||||
@@ -314,6 +325,7 @@ function normalizeSegmentationResults(
|
||||
);
|
||||
|
||||
return existing
|
||||
.filter((record) => record?.schemaVersion === 2)
|
||||
.map((record, index): SegmentationResultRecord => {
|
||||
const rawStyles = record?.moduleStyles && typeof record.moduleStyles === 'object' && !Array.isArray(record.moduleStyles)
|
||||
? record.moduleStyles
|
||||
@@ -324,6 +336,7 @@ function normalizeSegmentationResults(
|
||||
id: typeof record?.id === 'string' && record.id.trim()
|
||||
? record.id.trim().slice(0, 80)
|
||||
: `segmentation-${index}`,
|
||||
schemaVersion: 2,
|
||||
name: '逆向分割结果',
|
||||
createdAt: typeof record?.createdAt === 'string' && record.createdAt.trim() ? record.createdAt : now(),
|
||||
segmentationScope: record?.segmentationScope === 'all' ? 'all' : 'visible',
|
||||
@@ -2001,6 +2014,86 @@ async function startServer() {
|
||||
res.json(readState().users.map(publicUser));
|
||||
});
|
||||
|
||||
app.post('/api/users', (req, res) => {
|
||||
const state = readState();
|
||||
const payload = parseUserPayload(req.body);
|
||||
if (!payload.name || !payload.account || !payload.department || !payload.password) {
|
||||
res.status(400).json({ message: '姓名、账号、科室和密码不能为空' });
|
||||
return;
|
||||
}
|
||||
if (state.users.some((user) => user.account === payload.account)) {
|
||||
res.status(409).json({ message: '账号已存在' });
|
||||
return;
|
||||
}
|
||||
|
||||
const nextId = Math.max(0, ...state.users.map((user) => user.id)) + 1;
|
||||
const user: UserRecord = {
|
||||
id: nextId,
|
||||
name: payload.name,
|
||||
account: payload.account,
|
||||
password: payload.password,
|
||||
department: payload.department,
|
||||
date: today(),
|
||||
};
|
||||
state.users.push(user);
|
||||
writeState(state);
|
||||
res.status(201).json(publicUser(user));
|
||||
});
|
||||
|
||||
app.patch('/api/users/:userId', (req, res) => {
|
||||
const state = readState();
|
||||
const userId = Number.parseInt(req.params.userId, 10);
|
||||
const user = state.users.find((candidate) => candidate.id === userId);
|
||||
if (!user) {
|
||||
res.status(404).json({ message: '用户不存在' });
|
||||
return;
|
||||
}
|
||||
|
||||
const payload = parseUserPayload(req.body, user);
|
||||
if (!payload.name || !payload.account || !payload.department || !payload.password) {
|
||||
res.status(400).json({ message: '姓名、账号、科室和密码不能为空' });
|
||||
return;
|
||||
}
|
||||
if (state.users.some((candidate) => candidate.id !== user.id && candidate.account === payload.account)) {
|
||||
res.status(409).json({ message: '账号已存在' });
|
||||
return;
|
||||
}
|
||||
|
||||
const previousAccount = user.account;
|
||||
user.name = payload.name;
|
||||
user.account = payload.account;
|
||||
user.department = payload.department;
|
||||
user.password = payload.password;
|
||||
if (state.session.account === previousAccount) {
|
||||
state.session = { authenticated: true, account: user.account, lastUpdated: now() };
|
||||
}
|
||||
writeState(state);
|
||||
res.json(publicUser(user));
|
||||
});
|
||||
|
||||
app.delete('/api/users/:userId', (req, res) => {
|
||||
const state = readState();
|
||||
const userId = Number.parseInt(req.params.userId, 10);
|
||||
const index = state.users.findIndex((candidate) => candidate.id === userId);
|
||||
if (index === -1) {
|
||||
res.status(404).json({ message: '用户不存在' });
|
||||
return;
|
||||
}
|
||||
const user = state.users[index];
|
||||
if (state.session.account === user.account) {
|
||||
res.status(400).json({ message: '不能删除当前登录用户' });
|
||||
return;
|
||||
}
|
||||
if (state.users.length <= 1) {
|
||||
res.status(400).json({ message: '至少保留一个用户' });
|
||||
return;
|
||||
}
|
||||
|
||||
state.users.splice(index, 1);
|
||||
writeState(state);
|
||||
res.json({ ok: true, deletedId: user.id });
|
||||
});
|
||||
|
||||
app.get('/api/projects', (_req, res) => {
|
||||
res.json(readState().projects);
|
||||
});
|
||||
@@ -2118,6 +2211,7 @@ async function startServer() {
|
||||
: project.moduleStyles;
|
||||
const record: SegmentationResultRecord = {
|
||||
id: `segmentation-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 7)}`,
|
||||
schemaVersion: 2,
|
||||
name: rawName || '逆向分割结果',
|
||||
createdAt: now(),
|
||||
segmentationScope: parseSegmentationScope(req.body?.segmentationScope),
|
||||
|
||||
@@ -27,6 +27,7 @@ export default function App() {
|
||||
const [activeProjectId, setActiveProjectId] = useState('head-ct-demo');
|
||||
const [projectLibraryInitialView, setProjectLibraryInitialView] = useState<'dicom' | 'model' | 'mask'>('dicom');
|
||||
const workspaceLeaveGuardRef = useRef<(() => Promise<boolean>) | null>(null);
|
||||
const bootSessionResetRef = useRef(false);
|
||||
|
||||
// Automatically collapse main sidebar when entering Project Library or Workspace
|
||||
useEffect(() => {
|
||||
@@ -42,6 +43,16 @@ export default function App() {
|
||||
|
||||
const syncSession = async () => {
|
||||
try {
|
||||
if (!bootSessionResetRef.current) {
|
||||
bootSessionResetRef.current = true;
|
||||
const session = await api.logout();
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
setIsAuthenticated(session.authenticated);
|
||||
setActiveView(ViewType.OVERVIEW);
|
||||
return;
|
||||
}
|
||||
const session = await api.getSession();
|
||||
if (!mounted) {
|
||||
return;
|
||||
|
||||
@@ -43,8 +43,8 @@ export default function Login({ onLogin }: LoginProps) {
|
||||
className="h-full w-full object-contain"
|
||||
/>
|
||||
</div>
|
||||
<h1 className="text-2xl font-bold leading-tight px-4">模型逆向系统</h1>
|
||||
<p className="text-slate-300 mt-2 font-medium">基于模型逆向体素化及DICOM分割标注系统</p>
|
||||
<h1 className="px-2 text-3xl font-bold leading-tight">基于模型逆向体素化及DICOM分割标注系统</h1>
|
||||
<p className="mt-3 text-lg font-semibold text-slate-300">模型逆向系统</p>
|
||||
</div>
|
||||
|
||||
<form onSubmit={handleSubmit} className="p-8 space-y-6">
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
Box,
|
||||
Image as ImageIcon,
|
||||
Info,
|
||||
ChevronLeft,
|
||||
ChevronRight,
|
||||
ChevronUp,
|
||||
ChevronDown,
|
||||
@@ -653,6 +654,10 @@ export default function ProjectLibrary({
|
||||
const [isSliceChanging, setIsSliceChanging] = useState(false);
|
||||
const [solidityLevel, setSolidityLevel] = useState<SolidityLevel>('standard');
|
||||
const [modelPose, setModelPose] = useState<ModelPose>(defaultModelPose);
|
||||
const [resultPose, setResultPose] = useState<ModelPose>(defaultModelPose);
|
||||
const [resultPreviewSlice, setResultPreviewSlice] = useState(0);
|
||||
const [resultDisplayMode, setResultDisplayMode] = useState<DisplayMode>('soft');
|
||||
const [resultRotation, setResultRotation] = useState(0);
|
||||
const [moduleStyles, setModuleStyles] = useState<Record<string, ModuleStyle>>({});
|
||||
const [dicomPreview, setDicomPreview] = useState<DicomPreview | null>(null);
|
||||
const [resultDicomPreview, setResultDicomPreview] = useState<DicomPreview | null>(null);
|
||||
@@ -747,10 +752,11 @@ export default function ProjectLibrary({
|
||||
const selectedSolidity = solidityOptions.find((option) => option.id === solidityLevel) ?? solidityOptions[0];
|
||||
const savedSegmentationResults = selectedProject?.segmentationResults ?? [];
|
||||
const latestSegmentationResult = savedSegmentationResults[savedSegmentationResults.length - 1];
|
||||
const latestResultPose = latestSegmentationResult?.pose ?? modelPose;
|
||||
const latestResultPose = latestSegmentationResult ? resultPose : modelPose;
|
||||
const latestResultStyles = latestSegmentationResult?.moduleStyles ?? moduleStyles;
|
||||
const resultMaxSlice = Math.max((selectedProject?.dicomCount ?? 1) - 1, 0);
|
||||
const resultMappingSlice = Math.max(0, Math.min(resultMaxSlice, latestSegmentationResult?.mappingSlice ?? resultMaxSlice));
|
||||
const resultMappingSlice = Math.max(0, Math.min(resultMaxSlice, resultPreviewSlice));
|
||||
const resultFineDetailLimit = solidityOptions.find((option) => option.id === 'fine')?.limit ?? 36000;
|
||||
const resultVisibleModules = stlFiles
|
||||
.map((fileName, index) => ({
|
||||
fileName,
|
||||
@@ -763,7 +769,6 @@ export default function ProjectLibrary({
|
||||
},
|
||||
}))
|
||||
.filter(({ style }) => style.visible !== false);
|
||||
const readonlyPoseChange = useMemo<React.Dispatch<React.SetStateAction<ModelPose>>>(() => () => undefined, []);
|
||||
|
||||
const makeDefaultModuleStyle = (index: number, fallback?: Partial<ModuleStyle>): ModuleStyle => ({
|
||||
visible: fallback?.visible ?? true,
|
||||
@@ -828,6 +833,10 @@ export default function ProjectLibrary({
|
||||
setModuleStyles(next);
|
||||
setSliceIndex(0);
|
||||
setModelPose(latestResult?.pose ?? defaultModelPose);
|
||||
setResultPose(latestResult?.pose ?? defaultModelPose);
|
||||
setResultPreviewSlice(Math.max(0, Math.min(Math.max((selectedProject?.dicomCount ?? 1) - 1, 0), latestResult?.mappingSlice ?? 0)));
|
||||
setResultDisplayMode('soft');
|
||||
setResultRotation(0);
|
||||
}, [selectedProject?.id]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -870,8 +879,8 @@ export default function ProjectLibrary({
|
||||
|
||||
let cancelled = false;
|
||||
const maxSlice = Math.max(selectedProject.dicomCount - 1, 0);
|
||||
const previewSlice = Math.max(0, Math.min(maxSlice, latestSegmentationResult?.mappingSlice ?? maxSlice));
|
||||
api.getDicomPreview(selectedProject.id, previewSlice, 'axial', 'soft')
|
||||
const previewSlice = Math.max(0, Math.min(maxSlice, resultPreviewSlice));
|
||||
api.getDicomPreview(selectedProject.id, previewSlice, 'axial', resultDisplayMode)
|
||||
.then((preview) => {
|
||||
if (!cancelled) {
|
||||
setResultDicomPreview(preview);
|
||||
@@ -886,7 +895,7 @@ export default function ProjectLibrary({
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [selectedProject?.id, selectedProject?.dicomCount, viewMode, latestSegmentationResult?.id, latestSegmentationResult?.mappingSlice]);
|
||||
}, [selectedProject?.id, selectedProject?.dicomCount, viewMode, latestSegmentationResult?.id, resultPreviewSlice, resultDisplayMode]);
|
||||
|
||||
useEffect(() => () => {
|
||||
if (sliceRepeatRef.current !== null) {
|
||||
@@ -1551,7 +1560,7 @@ export default function ProjectLibrary({
|
||||
<div className="absolute left-4 top-4 z-10 rounded-xl border border-white/10 bg-black/45 px-3 py-2 backdrop-blur">
|
||||
<p className="text-sm font-bold">影像与模型融合视角</p>
|
||||
<p className="mt-1 font-mono text-[10px] text-white/45">
|
||||
{latestSegmentationResult ? `Z ${resultMappingSlice + 1}/${selectedProject.dicomCount}` : '等待保存结果'}
|
||||
{latestSegmentationResult ? `模型显示 精细 · 融合显示 DICOM 高 · Z ${resultMappingSlice + 1}/${selectedProject.dicomCount}` : '等待保存结果'}
|
||||
</p>
|
||||
</div>
|
||||
{latestSegmentationResult ? (
|
||||
@@ -1559,10 +1568,10 @@ export default function ProjectLibrary({
|
||||
projectId={selectedProject.id}
|
||||
files={stlFiles}
|
||||
styles={latestResultStyles}
|
||||
detailLimit={selectedSolidity.limit}
|
||||
solidMode={solidityLevel === 'solid'}
|
||||
detailLimit={resultFineDetailLimit}
|
||||
solidMode={false}
|
||||
pose={latestResultPose}
|
||||
onPoseChange={readonlyPoseChange}
|
||||
onPoseChange={setResultPose}
|
||||
/>
|
||||
) : (
|
||||
<div className="flex h-full items-center justify-center px-8 text-center text-sm font-bold text-white/35">
|
||||
@@ -1571,22 +1580,50 @@ export default function ProjectLibrary({
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="relative min-h-[520px] overflow-hidden rounded-2xl border border-slate-900 bg-black text-white shadow-sm">
|
||||
<div className="absolute left-4 top-4 z-10 flex flex-wrap gap-2">
|
||||
<span className="rounded-lg border border-white/10 bg-black/50 px-2.5 py-1 font-mono text-[10px] font-bold text-white/70 backdrop-blur">
|
||||
BASE DICOM
|
||||
</span>
|
||||
<span className="rounded-lg border border-cyan-300/40 bg-cyan-400/15 px-2.5 py-1 font-mono text-[10px] font-bold text-cyan-100 backdrop-blur">
|
||||
OVERLAY LABEL MAP
|
||||
</span>
|
||||
<span className="rounded-lg border border-white/10 bg-black/50 px-2.5 py-1 font-mono text-[10px] font-bold text-white/70 backdrop-blur">
|
||||
Z {resultMappingSlice + 1}/{selectedProject.dicomCount}
|
||||
</span>
|
||||
</div>
|
||||
<div className="absolute inset-0 flex items-center justify-center p-8">
|
||||
<div className="relative flex min-h-[520px] flex-col overflow-hidden rounded-2xl border border-slate-900 bg-black text-white shadow-sm">
|
||||
<div className="relative min-h-0 flex-1">
|
||||
<div className="absolute left-4 top-4 z-10 flex flex-wrap gap-2">
|
||||
<span className="rounded-lg border border-white/10 bg-black/50 px-2.5 py-1 font-mono text-[10px] font-bold text-white/70 backdrop-blur">
|
||||
BASE DICOM
|
||||
</span>
|
||||
<span className="rounded-lg border border-cyan-300/40 bg-cyan-400/15 px-2.5 py-1 font-mono text-[10px] font-bold text-cyan-100 backdrop-blur">
|
||||
OVERLAY LABEL MAP
|
||||
</span>
|
||||
<span className="rounded-lg border border-white/10 bg-black/50 px-2.5 py-1 font-mono text-[10px] font-bold text-white/70 backdrop-blur">
|
||||
Z {resultMappingSlice + 1}/{selectedProject.dicomCount}
|
||||
</span>
|
||||
</div>
|
||||
<div className="absolute right-4 top-4 z-10 flex flex-wrap justify-end gap-1.5">
|
||||
<div className="flex rounded-lg border border-white/10 bg-black/50 p-1 backdrop-blur">
|
||||
{displayModes.map((mode) => (
|
||||
<button
|
||||
key={mode.id}
|
||||
onClick={() => setResultDisplayMode(mode.id)}
|
||||
className={`rounded-md px-2 py-1 text-[9px] font-bold transition ${resultDisplayMode === mode.id ? 'bg-cyan-400 text-slate-950' : 'text-white/55 hover:text-white'}`}
|
||||
>
|
||||
{mode.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<button
|
||||
onClick={() => setResultRotation((value) => (value + 270) % 360)}
|
||||
className="rounded-lg border border-white/10 bg-black/50 px-2 py-1 text-[9px] font-bold text-white/70 backdrop-blur hover:text-white"
|
||||
title="左转 90°"
|
||||
>
|
||||
<RotateCcw size={12} />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setResultRotation((value) => (value + 90) % 360)}
|
||||
className="rounded-lg border border-white/10 bg-black/50 px-2 py-1 text-[9px] font-bold text-white/70 backdrop-blur hover:text-white"
|
||||
title="右转 90°"
|
||||
>
|
||||
<RotateCw size={12} />
|
||||
</button>
|
||||
</div>
|
||||
<div className="absolute inset-0 flex items-center justify-center p-8">
|
||||
{latestSegmentationResult && resultDicomPreview ? (
|
||||
<div className="relative flex h-full w-full items-center justify-center">
|
||||
<DicomCanvas preview={resultDicomPreview} rotation={0} />
|
||||
<DicomCanvas preview={resultDicomPreview} rotation={resultRotation} />
|
||||
<div className="pointer-events-none absolute inset-x-10 bottom-10 rounded-2xl border border-white/10 bg-black/55 p-3 backdrop-blur">
|
||||
<div className="mb-2 flex items-center justify-between gap-3 text-[11px] font-bold text-white/70">
|
||||
<span>当前切片构件</span>
|
||||
@@ -1608,6 +1645,43 @@ export default function ProjectLibrary({
|
||||
{latestSegmentationResult ? '正在载入逆向分割映射视图...' : '暂无逆向分割映射视图'}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="border-t border-white/10 bg-slate-950 px-4 py-3">
|
||||
<div className="mb-2 flex items-center justify-between">
|
||||
<p className="text-[10px] font-bold uppercase tracking-widest text-slate-400">Slice Navigator</p>
|
||||
<span className="font-mono text-[10px] font-bold text-cyan-100">
|
||||
{resultMappingSlice + 1} / {Math.max(selectedProject.dicomCount, 1)}
|
||||
</span>
|
||||
</div>
|
||||
<div className="grid grid-cols-[28px_1fr_28px] items-center gap-3">
|
||||
<button
|
||||
onClick={() => setResultPreviewSlice((value) => Math.max(0, value - 1))}
|
||||
disabled={!latestSegmentationResult || resultMappingSlice <= 0}
|
||||
className="flex h-7 w-7 items-center justify-center rounded-lg border border-slate-700 bg-slate-900 text-slate-200 hover:border-cyan-400 hover:text-cyan-100 disabled:opacity-35"
|
||||
title="上一层"
|
||||
>
|
||||
<ChevronLeft size={15} />
|
||||
</button>
|
||||
<input
|
||||
type="range"
|
||||
min="0"
|
||||
max={resultMaxSlice}
|
||||
value={resultMappingSlice}
|
||||
disabled={!latestSegmentationResult}
|
||||
onChange={(event) => setResultPreviewSlice(Number(event.target.value))}
|
||||
className="h-2 w-full accent-cyan-400 disabled:opacity-35"
|
||||
aria-label="项目库逆向分割结果切片导航"
|
||||
/>
|
||||
<button
|
||||
onClick={() => setResultPreviewSlice((value) => Math.min(resultMaxSlice, value + 1))}
|
||||
disabled={!latestSegmentationResult || resultMappingSlice >= resultMaxSlice}
|
||||
className="flex h-7 w-7 items-center justify-center rounded-lg border border-slate-700 bg-slate-900 text-slate-200 hover:border-cyan-400 hover:text-cyan-100 disabled:opacity-35"
|
||||
title="下一层"
|
||||
>
|
||||
<ChevronRight size={15} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -2,6 +2,8 @@ import React, { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import {
|
||||
Settings2,
|
||||
Download,
|
||||
RotateCcw,
|
||||
RotateCw,
|
||||
Rotate3d,
|
||||
AlertCircle,
|
||||
ChevronLeft,
|
||||
@@ -28,6 +30,7 @@ interface ModelPreviewPayload {
|
||||
|
||||
type DisplayLevel = 'standard' | 'fine' | 'ultra' | 'solid';
|
||||
type DicomOpacityLevel = 'low' | 'medium' | 'high';
|
||||
type MappingDisplayMode = DicomPreview['mode'];
|
||||
type ModelPoseKey = keyof ModelPose;
|
||||
type PoseDraftValues = Record<ModelPoseKey, string>;
|
||||
type AxisKey = 'x' | 'y' | 'z';
|
||||
@@ -54,6 +57,12 @@ const dicomOpacityOptions: Array<{ id: DicomOpacityLevel; label: string; sliceOp
|
||||
{ id: 'medium', label: '中', sliceOpacity: 0.92, volumeOpacity: 0.2, boxOpacity: 0.42 },
|
||||
{ id: 'high', label: '高', sliceOpacity: 1, volumeOpacity: 0.32, boxOpacity: 0.54 },
|
||||
];
|
||||
const mappingDisplayModes: Array<{ id: MappingDisplayMode; label: string }> = [
|
||||
{ id: 'default', label: '默认' },
|
||||
{ id: 'bone', label: '骨窗' },
|
||||
{ id: 'soft', label: '软组织' },
|
||||
{ id: 'contrast', label: '高对比' },
|
||||
];
|
||||
const poseStepConfig: Record<ModelPoseKey, { min: number; max: number; step: number; minus: string; plus: string; quick?: number }> = {
|
||||
rotateX: { min: -180, max: 180, step: 1, minus: '-90°', plus: '+90°', quick: 90 },
|
||||
rotateY: { min: -180, max: 180, step: 1, minus: '-90°', plus: '+90°', quick: 90 },
|
||||
@@ -207,6 +216,41 @@ function poseValuesMatch(left: ModelPose, right: ModelPose) {
|
||||
return modelPoseKeys.every((key) => Math.abs(left[key] - right[key]) < 1e-6);
|
||||
}
|
||||
|
||||
function stableModuleStyles(styles: Record<string, ModuleStyle>) {
|
||||
return Object.keys(styles)
|
||||
.sort((left, right) => left.localeCompare(right, 'zh-Hans-CN'))
|
||||
.reduce<Record<string, ModuleStyle>>((accumulator, key) => {
|
||||
accumulator[key] = styles[key];
|
||||
return accumulator;
|
||||
}, {});
|
||||
}
|
||||
|
||||
function createWorkspaceSnapshot(input: {
|
||||
modelPose: ModelPose;
|
||||
segmentationExportScope: SegmentationExportScope;
|
||||
moduleStyles: Record<string, ModuleStyle>;
|
||||
sliceStart: number;
|
||||
sliceEnd: number;
|
||||
mappingSlice: number;
|
||||
displayLevel: DisplayLevel;
|
||||
dicomOpacityLevel: DicomOpacityLevel;
|
||||
showBounds: boolean;
|
||||
cutEnabled: boolean;
|
||||
}) {
|
||||
return JSON.stringify({
|
||||
modelPose: input.modelPose,
|
||||
segmentationExportScope: input.segmentationExportScope,
|
||||
moduleStyles: stableModuleStyles(input.moduleStyles),
|
||||
sliceStart: input.sliceStart,
|
||||
sliceEnd: input.sliceEnd,
|
||||
mappingSlice: input.mappingSlice,
|
||||
displayLevel: input.displayLevel,
|
||||
dicomOpacityLevel: input.dicomOpacityLevel,
|
||||
showBounds: input.showBounds,
|
||||
cutEnabled: input.cutEnabled,
|
||||
});
|
||||
}
|
||||
|
||||
function parseImportedPosePayload(payload: unknown) {
|
||||
const record = isRecord(payload) ? payload : {};
|
||||
const importedModelPoses = normalizeImportedModelPoses(record.modelPoses);
|
||||
@@ -1701,6 +1745,8 @@ function VoxelizationMappingView({
|
||||
slice,
|
||||
totalSlices,
|
||||
onSliceChange,
|
||||
displayMode,
|
||||
rotation,
|
||||
}: {
|
||||
project: Project | null;
|
||||
moduleStyles: Record<string, ModuleStyle>;
|
||||
@@ -1709,6 +1755,8 @@ function VoxelizationMappingView({
|
||||
slice: number;
|
||||
totalSlices: number;
|
||||
onSliceChange: (slice: number) => void;
|
||||
displayMode: MappingDisplayMode;
|
||||
rotation: number;
|
||||
}) {
|
||||
const baseCanvasRef = useRef<HTMLCanvasElement | null>(null);
|
||||
const overlayCanvasRef = useRef<HTMLCanvasElement | null>(null);
|
||||
@@ -1731,7 +1779,7 @@ function VoxelizationMappingView({
|
||||
|
||||
let disposed = false;
|
||||
setDicomStatus('正在载入 DICOM Base Layer...');
|
||||
api.getDicomPreview(project.id, safeSlice, 'axial', 'soft')
|
||||
api.getDicomPreview(project.id, safeSlice, 'axial', displayMode)
|
||||
.then((preview) => {
|
||||
if (disposed) return;
|
||||
setDicomPreview(preview);
|
||||
@@ -1746,7 +1794,7 @@ function VoxelizationMappingView({
|
||||
return () => {
|
||||
disposed = true;
|
||||
};
|
||||
}, [project?.id, project?.dicomCount, safeSlice]);
|
||||
}, [project?.id, project?.dicomCount, safeSlice, displayMode]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!project || !stlFiles.length) {
|
||||
@@ -1847,7 +1895,10 @@ function VoxelizationMappingView({
|
||||
Z {safeSlice + 1}/{Math.max(totalSlices, 1)}
|
||||
</div>
|
||||
{dicomPreview ? (
|
||||
<div className="absolute inset-0 flex items-center justify-center">
|
||||
<div
|
||||
className="absolute inset-0 flex items-center justify-center"
|
||||
style={{ transform: `rotate(${rotation}deg)` }}
|
||||
>
|
||||
<canvas ref={baseCanvasRef} className="absolute inset-0 h-full w-full object-contain" />
|
||||
<canvas ref={overlayCanvasRef} className="absolute inset-0 h-full w-full object-contain" />
|
||||
</div>
|
||||
@@ -1947,6 +1998,8 @@ export default function ReverseWorkspace({
|
||||
const [poseImportStatus, setPoseImportStatus] = useState('');
|
||||
const [displayLevel, setDisplayLevel] = useState<DisplayLevel>('standard');
|
||||
const [dicomOpacityLevel, setDicomOpacityLevel] = useState<DicomOpacityLevel>('low');
|
||||
const [mappingDisplayMode, setMappingDisplayMode] = useState<MappingDisplayMode>('soft');
|
||||
const [mappingRotation, setMappingRotation] = useState(0);
|
||||
const [showBounds, setShowBounds] = useState(true);
|
||||
const [cutEnabled, setCutEnabled] = useState(false);
|
||||
const [moduleStyles, setModuleStyles] = useState<Record<string, ModuleStyle>>({});
|
||||
@@ -1969,6 +2022,7 @@ export default function ReverseWorkspace({
|
||||
const poseRepeatRef = useRef<{ timeout: number | null; interval: number | null }>({ timeout: null, interval: null });
|
||||
const poseImportInputRef = useRef<HTMLInputElement | null>(null);
|
||||
const saveToastTimerRef = useRef<number | null>(null);
|
||||
const savedWorkspaceSnapshotRef = useRef('');
|
||||
|
||||
const handleExportSelected = async () => {
|
||||
const selectedItems = exportOptions
|
||||
@@ -1994,6 +2048,30 @@ export default function ReverseWorkspace({
|
||||
}
|
||||
};
|
||||
|
||||
const getCurrentWorkspaceSnapshot = useCallback(() => createWorkspaceSnapshot({
|
||||
modelPose,
|
||||
segmentationExportScope,
|
||||
moduleStyles,
|
||||
sliceStart,
|
||||
sliceEnd,
|
||||
mappingSlice,
|
||||
displayLevel,
|
||||
dicomOpacityLevel,
|
||||
showBounds,
|
||||
cutEnabled,
|
||||
}), [
|
||||
modelPose,
|
||||
segmentationExportScope,
|
||||
moduleStyles,
|
||||
sliceStart,
|
||||
sliceEnd,
|
||||
mappingSlice,
|
||||
displayLevel,
|
||||
dicomOpacityLevel,
|
||||
showBounds,
|
||||
cutEnabled,
|
||||
]);
|
||||
|
||||
const handleSaveSegmentationResult = useCallback(async (options: { showToast?: boolean } = {}) => {
|
||||
if (!project) {
|
||||
return false;
|
||||
@@ -2016,6 +2094,7 @@ export default function ReverseWorkspace({
|
||||
cutEnabled,
|
||||
});
|
||||
setProject(updated);
|
||||
savedWorkspaceSnapshotRef.current = getCurrentWorkspaceSnapshot();
|
||||
if (options.showToast !== false) {
|
||||
setSaveStatus('已保存至项目库的分割结果区域');
|
||||
}
|
||||
@@ -2040,6 +2119,7 @@ export default function ReverseWorkspace({
|
||||
dicomOpacityLevel,
|
||||
showBounds,
|
||||
cutEnabled,
|
||||
getCurrentWorkspaceSnapshot,
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -2072,7 +2152,10 @@ export default function ReverseWorkspace({
|
||||
if (!project) {
|
||||
return true;
|
||||
}
|
||||
const shouldSave = window.confirm('是否保存当前结果至项目库?\\n确定:保存后退出。\\n取消:直接退出,不保存当前结果。');
|
||||
if (savedWorkspaceSnapshotRef.current === getCurrentWorkspaceSnapshot()) {
|
||||
return true;
|
||||
}
|
||||
const shouldSave = window.confirm('是否保存当前结果至项目库? 确定:保存后退出。取消:直接退出,不保存当前结果。');
|
||||
if (!shouldSave) {
|
||||
return true;
|
||||
}
|
||||
@@ -2080,7 +2163,7 @@ export default function ReverseWorkspace({
|
||||
});
|
||||
|
||||
return () => onLeaveGuardChange(null);
|
||||
}, [handleSaveSegmentationResult, onLeaveGuardChange, project]);
|
||||
}, [getCurrentWorkspaceSnapshot, handleSaveSegmentationResult, onLeaveGuardChange, project]);
|
||||
|
||||
const makeDefaultModuleStyle = (index: number, fallback?: Partial<ModuleStyle>): ModuleStyle => ({
|
||||
visible: fallback?.visible ?? true,
|
||||
@@ -2149,11 +2232,26 @@ export default function ReverseWorkspace({
|
||||
setSegmentationExportScope(latestResult?.segmentationScope ?? 'visible');
|
||||
setDisplayLevel(latestResult?.displayLevel ?? 'standard');
|
||||
setDicomOpacityLevel(latestResult?.dicomOpacityLevel ?? 'low');
|
||||
setMappingDisplayMode('soft');
|
||||
setMappingRotation(0);
|
||||
setShowBounds(latestResult?.showBounds ?? true);
|
||||
setCutEnabled(latestResult?.cutEnabled ?? false);
|
||||
savedWorkspaceSnapshotRef.current = createWorkspaceSnapshot({
|
||||
modelPose: restoredPose,
|
||||
segmentationExportScope: latestResult?.segmentationScope ?? 'visible',
|
||||
moduleStyles: nextStyles,
|
||||
sliceStart: restoredSliceStart,
|
||||
sliceEnd: restoredSliceEnd,
|
||||
mappingSlice: restoredMappingSlice,
|
||||
displayLevel: latestResult?.displayLevel ?? 'standard',
|
||||
dicomOpacityLevel: latestResult?.dicomOpacityLevel ?? 'low',
|
||||
showBounds: latestResult?.showBounds ?? true,
|
||||
cutEnabled: latestResult?.cutEnabled ?? false,
|
||||
});
|
||||
}).catch(() => {
|
||||
setProject(null);
|
||||
setFusionVolume(null);
|
||||
savedWorkspaceSnapshotRef.current = '';
|
||||
});
|
||||
}, [projectId]);
|
||||
|
||||
@@ -2890,11 +2988,40 @@ export default function ReverseWorkspace({
|
||||
</div>
|
||||
|
||||
<div className="lg:col-span-4 flex flex-col gap-4 overflow-hidden">
|
||||
<div className="px-2 flex items-center justify-between shrink-0">
|
||||
<div className="px-2 flex flex-wrap items-center justify-between gap-2 shrink-0">
|
||||
<h3 className="font-bold text-slate-700 flex items-center gap-2">
|
||||
<Layers size={18} className="text-cyan-500" />
|
||||
逆向分割映射视图
|
||||
</h3>
|
||||
<div className="flex flex-wrap items-center justify-end gap-1.5">
|
||||
<div className="flex rounded-xl bg-slate-100 p-1">
|
||||
{mappingDisplayModes.map((mode) => (
|
||||
<button
|
||||
key={mode.id}
|
||||
onClick={() => setMappingDisplayMode(mode.id)}
|
||||
className={`rounded-lg px-2 py-1 text-[10px] font-bold transition ${
|
||||
mappingDisplayMode === mode.id ? 'bg-white text-cyan-600 shadow-sm' : 'text-slate-500 hover:text-slate-700'
|
||||
}`}
|
||||
>
|
||||
{mode.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<button
|
||||
onClick={() => setMappingRotation((value) => (value + 270) % 360)}
|
||||
className="flex h-7 w-7 items-center justify-center rounded-lg border border-slate-200 bg-white text-slate-500 hover:text-cyan-600"
|
||||
title="左转 90°"
|
||||
>
|
||||
<RotateCcw size={14} />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setMappingRotation((value) => (value + 90) % 360)}
|
||||
className="flex h-7 w-7 items-center justify-center rounded-lg border border-slate-200 bg-white text-slate-500 hover:text-cyan-600"
|
||||
title="右转 90°"
|
||||
>
|
||||
<RotateCw size={14} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<VoxelizationMappingView
|
||||
@@ -2905,6 +3032,8 @@ export default function ReverseWorkspace({
|
||||
slice={safeMappingSlice}
|
||||
totalSlices={project?.dicomCount ?? 0}
|
||||
onSliceChange={setMappingSlice}
|
||||
displayMode={mappingDisplayMode}
|
||||
rotation={mappingRotation}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,39 +1,176 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import { motion } from 'motion/react';
|
||||
import {
|
||||
Users,
|
||||
UserPlus,
|
||||
Search,
|
||||
MoreVertical,
|
||||
Shield,
|
||||
import {
|
||||
Users,
|
||||
UserPlus,
|
||||
Search,
|
||||
Shield,
|
||||
Calendar,
|
||||
RotateCcw,
|
||||
Edit2,
|
||||
Trash2,
|
||||
Key
|
||||
Key,
|
||||
X,
|
||||
} from 'lucide-react';
|
||||
import { api } from '../lib/api';
|
||||
import { UserRecord } from '../types';
|
||||
import { SessionState, UserRecord } from '../types';
|
||||
|
||||
type UserFormMode = 'create' | 'edit' | 'password';
|
||||
|
||||
interface UserFormState {
|
||||
id?: number;
|
||||
name: string;
|
||||
account: string;
|
||||
department: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
const emptyUserForm: UserFormState = {
|
||||
name: '',
|
||||
account: '',
|
||||
department: '',
|
||||
password: '',
|
||||
};
|
||||
|
||||
export default function UserManagement() {
|
||||
const [users, setUsers] = useState<UserRecord[]>([]);
|
||||
const [session, setSession] = useState<SessionState | null>(null);
|
||||
const [message, setMessage] = useState('登录、用户和项目状态由后端统一同步');
|
||||
const [resetting, setResetting] = useState(false);
|
||||
const [search, setSearch] = useState('');
|
||||
const [formMode, setFormMode] = useState<UserFormMode | null>(null);
|
||||
const [form, setForm] = useState<UserFormState>(emptyUserForm);
|
||||
const [saving, setSaving] = useState(false);
|
||||
|
||||
const refreshUsers = () => {
|
||||
api.getUsers().then(setUsers).catch(() => setMessage('用户列表同步失败'));
|
||||
const refreshUsers = async () => {
|
||||
try {
|
||||
const [items, currentSession] = await Promise.all([api.getUsers(), api.getSession()]);
|
||||
setUsers(items);
|
||||
setSession(currentSession);
|
||||
} catch (error) {
|
||||
setMessage(error instanceof Error ? error.message : '用户列表同步失败');
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
refreshUsers();
|
||||
void refreshUsers();
|
||||
}, []);
|
||||
|
||||
const filteredUsers = useMemo(() => {
|
||||
const keyword = search.trim().toLowerCase();
|
||||
if (!keyword) {
|
||||
return users;
|
||||
}
|
||||
return users.filter((user) => (
|
||||
user.name.toLowerCase().includes(keyword)
|
||||
|| user.account.toLowerCase().includes(keyword)
|
||||
|| user.department.toLowerCase().includes(keyword)
|
||||
));
|
||||
}, [users, search]);
|
||||
|
||||
const currentAccount = session?.currentUser?.account ?? '';
|
||||
|
||||
const openCreateForm = () => {
|
||||
setForm(emptyUserForm);
|
||||
setFormMode('create');
|
||||
setMessage('正在新增系统用户');
|
||||
};
|
||||
|
||||
const openEditForm = (user: UserRecord) => {
|
||||
setForm({
|
||||
id: user.id,
|
||||
name: user.name,
|
||||
account: user.account,
|
||||
department: user.department,
|
||||
password: '',
|
||||
});
|
||||
setFormMode('edit');
|
||||
setMessage(`正在编辑用户:${user.name}`);
|
||||
};
|
||||
|
||||
const openPasswordForm = (user: UserRecord) => {
|
||||
setForm({
|
||||
id: user.id,
|
||||
name: user.name,
|
||||
account: user.account,
|
||||
department: user.department,
|
||||
password: '',
|
||||
});
|
||||
setFormMode('password');
|
||||
setMessage(`正在修改密码:${user.name}`);
|
||||
};
|
||||
|
||||
const closeForm = () => {
|
||||
setFormMode(null);
|
||||
setForm(emptyUserForm);
|
||||
setSaving(false);
|
||||
};
|
||||
|
||||
const handleSaveUser = async () => {
|
||||
if (!formMode) {
|
||||
return;
|
||||
}
|
||||
const name = form.name.trim();
|
||||
const account = form.account.trim();
|
||||
const department = form.department.trim();
|
||||
const password = form.password.trim();
|
||||
|
||||
if (!name || !account || !department || (formMode === 'create' && !password)) {
|
||||
setMessage('姓名、账号、科室不能为空;新增用户必须填写密码');
|
||||
return;
|
||||
}
|
||||
if (formMode === 'password' && !password) {
|
||||
setMessage('请输入新密码');
|
||||
return;
|
||||
}
|
||||
|
||||
setSaving(true);
|
||||
try {
|
||||
if (formMode === 'create') {
|
||||
await api.createUser({ name, account, department, password });
|
||||
setMessage(`已添加用户:${name}`);
|
||||
} else if (form.id) {
|
||||
await api.updateUser(form.id, {
|
||||
name,
|
||||
account,
|
||||
department,
|
||||
...(password ? { password } : {}),
|
||||
});
|
||||
setMessage(formMode === 'password' ? `已更新 ${name} 的密码` : `已更新用户:${name}`);
|
||||
}
|
||||
closeForm();
|
||||
await refreshUsers();
|
||||
} catch (error) {
|
||||
setMessage(error instanceof Error ? error.message : '用户保存失败');
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleDeleteUser = async (user: UserRecord) => {
|
||||
if (user.account === currentAccount) {
|
||||
setMessage('不能删除当前登录用户');
|
||||
return;
|
||||
}
|
||||
const confirmed = window.confirm(`确认删除用户 ${user.name}?该操作不可恢复。`);
|
||||
if (!confirmed) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await api.deleteUser(user.id);
|
||||
setMessage(`已删除用户:${user.name}`);
|
||||
await refreshUsers();
|
||||
} catch (error) {
|
||||
setMessage(error instanceof Error ? error.message : '删除用户失败');
|
||||
}
|
||||
};
|
||||
|
||||
const handleReset = async () => {
|
||||
setResetting(true);
|
||||
setMessage('正在恢复演示环境...');
|
||||
try {
|
||||
const result = await api.resetDemo();
|
||||
setUsers(result.users);
|
||||
setSession(await api.getSession());
|
||||
setMessage('演示环境已恢复:默认用户、Head_CT_DICOM 与 Head_CT_ReConstruct 项目已重新载入');
|
||||
} catch (err) {
|
||||
setMessage(err instanceof Error ? err.message : '恢复失败');
|
||||
@@ -44,44 +181,52 @@ export default function UserManagement() {
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center justify-between gap-4">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold text-slate-800">系统管理工作区</h2>
|
||||
<p className="text-slate-500 mt-1">{message}</p>
|
||||
<p className="mt-1 text-slate-500">{message}</p>
|
||||
</div>
|
||||
<div className="flex gap-3">
|
||||
<button
|
||||
onClick={handleReset}
|
||||
disabled={resetting}
|
||||
className="bg-amber-100 text-amber-700 px-5 py-2.5 rounded-xl text-sm font-semibold hover:bg-amber-200 transition-all flex items-center gap-2 border border-amber-200 disabled:opacity-50"
|
||||
className="flex items-center gap-2 rounded-xl border border-amber-200 bg-amber-100 px-5 py-2.5 text-sm font-semibold text-amber-700 transition-all hover:bg-amber-200 disabled:opacity-50"
|
||||
>
|
||||
<RotateCcw size={18} />
|
||||
{resetting ? '正在恢复' : '恢复演示环境出厂设置'}
|
||||
</button>
|
||||
<button className="bg-blue-600 text-white px-5 py-2.5 rounded-xl text-sm font-semibold hover:bg-blue-700 transition-all shadow-lg shadow-blue-500/20 flex items-center gap-2">
|
||||
<button
|
||||
onClick={openCreateForm}
|
||||
className="flex items-center gap-2 rounded-xl bg-blue-600 px-5 py-2.5 text-sm font-semibold text-white shadow-lg shadow-blue-500/20 transition-all hover:bg-blue-700"
|
||||
>
|
||||
<UserPlus size={18} />
|
||||
添加用户
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="bg-white rounded-2xl border border-slate-100 shadow-sm overflow-hidden flex flex-col">
|
||||
<div className="p-4 border-b border-slate-100 flex items-center gap-4">
|
||||
<div className="flex-1 relative">
|
||||
<div className="flex flex-col overflow-hidden rounded-2xl border border-slate-100 bg-white shadow-sm">
|
||||
<div className="flex items-center gap-4 border-b border-slate-100 p-4">
|
||||
<div className="relative flex-1">
|
||||
<Search className="absolute left-3 top-1/2 -translate-y-1/2 text-slate-400" size={18} />
|
||||
<input
|
||||
type="text"
|
||||
<input
|
||||
type="text"
|
||||
placeholder="搜索用户名、账号、科室..."
|
||||
className="w-full pl-10 pr-4 py-2 border border-slate-200 rounded-xl focus:ring-2 focus:ring-blue-500 transition-all outline-none text-sm"
|
||||
value={search}
|
||||
onChange={(event) => setSearch(event.target.value)}
|
||||
className="w-full rounded-xl border border-slate-200 py-2 pl-10 pr-4 text-sm outline-none transition-all focus:ring-2 focus:ring-blue-500"
|
||||
/>
|
||||
</div>
|
||||
<button className="text-slate-500 hover:text-slate-700 p-2"><Shield size={20} /></button>
|
||||
<div className="flex items-center gap-2 rounded-xl bg-slate-50 px-3 py-2 text-xs font-bold text-slate-500">
|
||||
<Shield size={16} />
|
||||
当前账号:{currentAccount || '未同步'}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-left">
|
||||
<thead>
|
||||
<tr className="bg-slate-50 text-slate-500 text-xs font-bold uppercase tracking-wider">
|
||||
<tr className="bg-slate-50 text-xs font-bold uppercase tracking-wider text-slate-500">
|
||||
<th className="px-6 py-4">用户名</th>
|
||||
<th className="px-6 py-4">账号</th>
|
||||
<th className="px-6 py-4">所在科室</th>
|
||||
@@ -90,69 +235,141 @@ export default function UserManagement() {
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-slate-50">
|
||||
{users.map((user, i) => (
|
||||
<motion.tr
|
||||
key={user.id}
|
||||
initial={{ opacity: 0, y: 10 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
transition={{ delay: i * 0.05 }}
|
||||
className="hover:bg-slate-50/50 transition-colors"
|
||||
>
|
||||
<td className="px-6 py-4">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-10 h-10 rounded-full bg-blue-100 flex items-center justify-center text-blue-600 font-bold">
|
||||
{user.name[0]}
|
||||
{filteredUsers.map((user, index) => {
|
||||
const isCurrentUser = user.account === currentAccount;
|
||||
return (
|
||||
<motion.tr
|
||||
key={user.id}
|
||||
initial={{ opacity: 0, y: 10 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
transition={{ delay: index * 0.03 }}
|
||||
className="transition-colors hover:bg-slate-50/50"
|
||||
>
|
||||
<td className="px-6 py-4">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="flex h-10 w-10 items-center justify-center rounded-full bg-blue-100 font-bold text-blue-600">
|
||||
{user.name[0]}
|
||||
</div>
|
||||
<div>
|
||||
<p className="font-bold text-slate-800">{user.name}</p>
|
||||
{isCurrentUser && <p className="text-[10px] font-bold text-blue-600">当前登录</p>}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<p className="font-bold text-slate-800">{user.name}</p>
|
||||
</td>
|
||||
<td className="px-6 py-4 font-mono text-sm text-slate-500">{user.account}</td>
|
||||
<td className="px-6 py-4">
|
||||
<span className="rounded-lg bg-slate-100 px-2 py-1 text-sm font-medium text-slate-600">
|
||||
{user.department}
|
||||
</span>
|
||||
</td>
|
||||
<td className="px-6 py-4">
|
||||
<p className="flex items-center gap-2 text-sm text-slate-500">
|
||||
<Calendar size={14} />
|
||||
{user.date}
|
||||
</p>
|
||||
</td>
|
||||
<td className="px-6 py-4">
|
||||
<div className="flex items-center gap-3">
|
||||
<button
|
||||
onClick={() => openEditForm(user)}
|
||||
className="flex items-center gap-1 text-xs text-slate-500 transition-colors hover:text-blue-600"
|
||||
title="编辑信息"
|
||||
>
|
||||
<Edit2 size={16} />
|
||||
编辑
|
||||
</button>
|
||||
<div className="h-4 w-[1px] bg-slate-200" />
|
||||
<button
|
||||
onClick={() => openPasswordForm(user)}
|
||||
className="text-slate-400 transition-colors hover:text-amber-600"
|
||||
title="修改密码"
|
||||
>
|
||||
<Key size={16} />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => handleDeleteUser(user)}
|
||||
disabled={isCurrentUser}
|
||||
className="text-slate-400 transition-colors hover:text-rose-600 disabled:cursor-not-allowed disabled:opacity-35"
|
||||
title={isCurrentUser ? '不能删除当前登录用户' : '删除用户'}
|
||||
>
|
||||
<Trash2 size={16} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td className="px-6 py-4 px-6 text-sm font-mono text-slate-500">
|
||||
{user.account}
|
||||
</td>
|
||||
<td className="px-6 py-4">
|
||||
<span className="text-sm text-slate-600 font-medium px-2 py-1 bg-slate-100 rounded-lg">
|
||||
{user.department}
|
||||
</span>
|
||||
</td>
|
||||
<td className="px-6 py-4">
|
||||
<p className="text-sm text-slate-500 flex items-center gap-2">
|
||||
<Calendar size={14} />
|
||||
{user.date}
|
||||
</p>
|
||||
</td>
|
||||
<td className="px-6 py-4">
|
||||
<div className="flex items-center gap-4">
|
||||
<button className="text-slate-400 hover:text-blue-600 transition-colors flex items-center gap-1 text-xs" title="编辑信息">
|
||||
<Edit2 size={16} />
|
||||
编辑
|
||||
</button>
|
||||
<div className="h-4 w-[1px] bg-slate-200" />
|
||||
<button className="text-slate-400 hover:text-amber-600 transition-colors" title="修改密码">
|
||||
<Key size={16} />
|
||||
</button>
|
||||
<button className="text-slate-400 hover:text-rose-600 transition-colors" title="删除用户">
|
||||
<Trash2 size={16} />
|
||||
</button>
|
||||
<button className="text-slate-300 hover:text-slate-600 transition-colors">
|
||||
<MoreVertical size={18} />
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</motion.tr>
|
||||
))}
|
||||
</td>
|
||||
</motion.tr>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div className="p-4 border-t border-slate-50 flex items-center justify-between text-sm text-slate-500 bg-slate-50/50">
|
||||
<p>共 {users.length} 条数据</p>
|
||||
<div className="flex gap-2">
|
||||
<button className="px-3 py-1 border border-blue-500 rounded bg-blue-500 text-white">1</button>
|
||||
|
||||
<div className="flex items-center justify-between border-t border-slate-50 bg-slate-50/50 p-4 text-sm text-slate-500">
|
||||
<p>共 {filteredUsers.length} / {users.length} 条数据</p>
|
||||
<div className="flex items-center gap-2">
|
||||
<Users size={16} />
|
||||
用户管理操作实时写入后端状态
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{formMode && (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-slate-950/40 p-4 backdrop-blur-sm">
|
||||
<div className="w-full max-w-md rounded-2xl border border-slate-100 bg-white p-6 shadow-2xl">
|
||||
<div className="mb-5 flex items-center justify-between">
|
||||
<h3 className="font-bold text-slate-900">
|
||||
{formMode === 'create' && '添加用户'}
|
||||
{formMode === 'edit' && '编辑用户'}
|
||||
{formMode === 'password' && '修改密码'}
|
||||
</h3>
|
||||
<button onClick={closeForm} className="text-slate-400 hover:text-slate-700" title="关闭">
|
||||
<X size={18} />
|
||||
</button>
|
||||
</div>
|
||||
<div className="space-y-3">
|
||||
<input
|
||||
value={form.name}
|
||||
onChange={(event) => setForm((current) => ({ ...current, name: event.target.value }))}
|
||||
disabled={formMode === 'password'}
|
||||
placeholder="姓名"
|
||||
className="w-full rounded-xl border border-slate-200 bg-slate-50 px-4 py-3 text-sm outline-none focus:ring-2 focus:ring-blue-500 disabled:opacity-60"
|
||||
/>
|
||||
<input
|
||||
value={form.account}
|
||||
onChange={(event) => setForm((current) => ({ ...current, account: event.target.value }))}
|
||||
disabled={formMode === 'password'}
|
||||
placeholder="账号"
|
||||
className="w-full rounded-xl border border-slate-200 bg-slate-50 px-4 py-3 text-sm outline-none focus:ring-2 focus:ring-blue-500 disabled:opacity-60"
|
||||
/>
|
||||
<input
|
||||
value={form.department}
|
||||
onChange={(event) => setForm((current) => ({ ...current, department: event.target.value }))}
|
||||
disabled={formMode === 'password'}
|
||||
placeholder="科室"
|
||||
className="w-full rounded-xl border border-slate-200 bg-slate-50 px-4 py-3 text-sm outline-none focus:ring-2 focus:ring-blue-500 disabled:opacity-60"
|
||||
/>
|
||||
<input
|
||||
type="password"
|
||||
value={form.password}
|
||||
onChange={(event) => setForm((current) => ({ ...current, password: event.target.value }))}
|
||||
placeholder={formMode === 'edit' ? '新密码,留空则不修改' : '密码'}
|
||||
className="w-full rounded-xl border border-slate-200 bg-slate-50 px-4 py-3 text-sm outline-none focus:ring-2 focus:ring-blue-500"
|
||||
/>
|
||||
</div>
|
||||
<div className="mt-6 flex justify-end gap-3">
|
||||
<button onClick={closeForm} className="rounded-xl px-4 py-2 text-sm font-bold text-slate-600 hover:bg-slate-100">
|
||||
取消
|
||||
</button>
|
||||
<button
|
||||
onClick={handleSaveUser}
|
||||
disabled={saving}
|
||||
className="rounded-xl bg-blue-600 px-4 py-2 text-sm font-bold text-white hover:bg-blue-700 disabled:opacity-50"
|
||||
>
|
||||
{saving ? '保存中' : '保存'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -89,6 +89,20 @@ export const api = {
|
||||
request<DicomFusionVolume>(`/api/projects/${projectId}/dicom-fusion-volume?start=${start}&end=${end}&mode=${mode}`),
|
||||
getDicomInfo: (projectId: string) => request<DicomInfo>(`/api/projects/${projectId}/dicom-info`),
|
||||
getUsers: () => request<UserRecord[]>('/api/users'),
|
||||
createUser: (payload: { name: string; account: string; department: string; password: string }) =>
|
||||
request<UserRecord>('/api/users', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(payload),
|
||||
}),
|
||||
updateUser: (userId: number, payload: { name: string; account: string; department: string; password?: string }) =>
|
||||
request<UserRecord>(`/api/users/${userId}`, {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify(payload),
|
||||
}),
|
||||
deleteUser: (userId: number) =>
|
||||
request<{ ok: boolean; deletedId: number }>(`/api/users/${userId}`, {
|
||||
method: 'DELETE',
|
||||
}),
|
||||
resetDemo: () =>
|
||||
request<{ ok: boolean; projects: Project[]; users: UserRecord[] }>('/api/demo/reset', {
|
||||
method: 'POST',
|
||||
|
||||
@@ -54,6 +54,7 @@ export type SegmentationDicomOpacityLevel = 'low' | 'medium' | 'high';
|
||||
|
||||
export interface SegmentationResult {
|
||||
id: string;
|
||||
schemaVersion?: number;
|
||||
name: string;
|
||||
createdAt: string;
|
||||
segmentationScope: SegmentationExportScope;
|
||||
|
||||
Reference in New Issue
Block a user