优化桌面端标签导航与后台交互
Client Quality Gates / Shared client and Web (push) Has been cancelled
Client Quality Gates / macOS Desktop (push) Has been cancelled

This commit is contained in:
Cheng Zhou
2026-07-09 08:56:13 +08:00
parent 76f2d9f22a
commit 0aff10fe0d
17 changed files with 1232 additions and 207 deletions
+25 -5
View File
@@ -100,26 +100,46 @@ for (const group of requiredOverviewGroups) {
} }
} }
const financeAndFilePages = [ const unifiedShellPages = [
"src/views/fees/ContractFees.vue", "src/views/fees/ContractFees.vue",
"src/views/ia/FileVersionManagement.vue" "src/views/documents/DocumentList.vue"
]; ];
const requiredFinanceAndFileClasses = [ const requiredUnifiedShellClasses = [
"ctms-page-shell", "ctms-page-shell",
"unified-action-bar", "unified-action-bar",
"unified-shell" "unified-shell"
]; ];
for (const file of financeAndFilePages) { for (const file of unifiedShellPages) {
const content = readFileSync(file, "utf8"); const content = readFileSync(file, "utf8");
for (const className of requiredFinanceAndFileClasses) { for (const className of requiredUnifiedShellClasses) {
if (!content.includes(className)) { if (!content.includes(className)) {
missing.push(`${file}:${className}`); missing.push(`${file}:${className}`);
} }
} }
} }
const router = readFileSync("src/router/index.ts", "utf8");
const legacyFileVersionRouteIndex = router.indexOf('name: "FileVersionManagement"');
const canonicalDocumentRouteIndex = router.indexOf('path: "trial/:trialId/documents"', legacyFileVersionRouteIndex);
const legacyFileVersionRoute =
legacyFileVersionRouteIndex >= 0 && canonicalDocumentRouteIndex > legacyFileVersionRouteIndex
? router.slice(legacyFileVersionRouteIndex, canonicalDocumentRouteIndex)
: "";
if (router.includes("FileVersionManagement.vue")) {
missing.push("src/router/index.ts:legacy FileVersionManagement component import");
}
if (!legacyFileVersionRoute.includes("component: DocumentList")) {
missing.push("src/router/index.ts:FileVersionManagement->DocumentList");
}
if (!router.includes('next({ name: "DocumentList", params: { trialId: studyStore.currentStudy.id }, replace: true });')) {
missing.push("src/router/index.ts:legacy file version canonical redirect");
}
const adminProjectDetail = readFileSync("src/views/admin/ProjectDetail.vue", "utf8"); const adminProjectDetail = readFileSync("src/views/admin/ProjectDetail.vue", "utf8");
const requiredAdminProjectDetailClasses = [ const requiredAdminProjectDetailClasses = [
"ctms-page-shell", "ctms-page-shell",
+3 -3
View File
@@ -58,7 +58,7 @@ fn desktop_menu<R: Runtime>(handle: &tauri::AppHandle<R>) -> tauri::Result<Menu<
"ctms.desktop.refresh", "ctms.desktop.refresh",
"刷新当前视图", "刷新当前视图",
true, true,
Some("CmdOrCtrl+R"), None::<&str>,
)?, )?,
&PredefinedMenuItem::fullscreen(handle, None)?, &PredefinedMenuItem::fullscreen(handle, None)?,
], ],
@@ -73,14 +73,14 @@ fn desktop_menu<R: Runtime>(handle: &tauri::AppHandle<R>) -> tauri::Result<Menu<
"ctms.desktop.back", "ctms.desktop.back",
"返回", "返回",
true, true,
Some("CmdOrCtrl+["), None::<&str>,
)?, )?,
&MenuItem::with_id( &MenuItem::with_id(
handle, handle,
"ctms.desktop.forward", "ctms.desktop.forward",
"前进", "前进",
true, true,
Some("CmdOrCtrl+]"), None::<&str>,
)?, )?,
], ],
)?, )?,
+484 -28
View File
@@ -5,7 +5,7 @@
<div class="sidebar-title-row"> <div class="sidebar-title-row">
<h1>{{ TEXT.common.appName }}</h1> <h1>{{ TEXT.common.appName }}</h1>
<button v-if="!study.currentStudy" class="study-switcher-trigger empty" type="button" @click="openDesktopProjectEntry"> <button v-if="showSidebarProjectChooser" class="study-switcher-trigger empty" type="button" @click="openDesktopProjectEntry">
选择项目 选择项目
</button> </button>
</div> </div>
@@ -269,9 +269,13 @@
</div> </div>
</header> </header>
<div class="workspace-tabs" v-if="workspaceTabs.length"> <div v-if="workspaceTabs.length" ref="workspaceTabsElement" class="workspace-tabs">
<div <div
v-for="item in workspaceTabs" class="workspace-tabs-list"
:style="{ gridTemplateColumns: `repeat(${visibleWorkspaceTabs.length}, minmax(0, 238px))` }"
>
<div
v-for="item in visibleWorkspaceTabs"
:key="item.path" :key="item.path"
class="workspace-tab" class="workspace-tab"
:class="{ active: activeMenu === item.path, dragging: draggingWorkspaceTabPath === item.path }" :class="{ active: activeMenu === item.path, dragging: draggingWorkspaceTabPath === item.path }"
@@ -282,7 +286,12 @@
@dragend="draggingWorkspaceTabPath = ''" @dragend="draggingWorkspaceTabPath = ''"
@contextmenu.prevent.stop="openWorkspaceTabMenu(item, $event)" @contextmenu.prevent.stop="openWorkspaceTabMenu(item, $event)"
> >
<button class="workspace-tab-action" type="button" @click="navigateWorkspaceTab(item.path)"> <button
class="workspace-tab-action"
type="button"
:title="item.title"
@click="navigateWorkspaceTab(item.path)"
>
<span>{{ item.title }}</span> <span>{{ item.title }}</span>
</button> </button>
<button class="tab-close" type="button" title="关闭标签" @click.stop="closeWorkspaceTab(item.path)"> <button class="tab-close" type="button" title="关闭标签" @click.stop="closeWorkspaceTab(item.path)">
@@ -291,6 +300,58 @@
</div> </div>
</div> </div>
<el-dropdown
v-if="overflowWorkspaceTabs.length"
class="workspace-tabs-overflow"
popper-class="workspace-tabs-overflow-popper"
trigger="click"
placement="bottom-end"
@command="navigateOverflowWorkspaceTab"
@visible-change="workspaceTabsOverflowOpen = $event"
>
<button
class="workspace-tabs-overflow-trigger"
:class="{ 'is-open': workspaceTabsOverflowOpen }"
type="button"
:aria-label="`查看其余 ${overflowWorkspaceTabs.length} 个标签`"
>
<span>更多</span>
<span class="workspace-tabs-overflow-count">{{ overflowWorkspaceTabs.length }}</span>
<el-icon><ArrowDown /></el-icon>
</button>
<template #dropdown>
<div class="workspace-tabs-overflow-menu">
<div class="workspace-tabs-overflow-header">
<span>其他标签</span>
<span>{{ overflowWorkspaceTabs.length }} </span>
</div>
<el-dropdown-menu>
<el-dropdown-item
v-for="item in overflowWorkspaceTabs"
:key="item.path"
:command="item.path"
:class="{ 'is-current': activeMenu === item.path }"
>
<span class="workspace-tabs-overflow-item-mark" aria-hidden="true"></span>
<span class="workspace-tabs-overflow-label">
<span :title="item.title">{{ item.title }}</span>
</span>
<button
class="workspace-tabs-overflow-close"
type="button"
:aria-label="`关闭标签:${item.title}`"
title="关闭标签"
@click.stop="closeWorkspaceTab(item.path)"
>
×
</button>
</el-dropdown-item>
</el-dropdown-menu>
</div>
</template>
</el-dropdown>
</div>
<main class="desktop-content"> <main class="desktop-content">
<router-view v-slot="{ Component, route: currentRoute }"> <router-view v-slot="{ Component, route: currentRoute }">
<transition name="desktop-route" mode="out-in"> <transition name="desktop-route" mode="out-in">
@@ -415,13 +476,17 @@ import {
} from "../session/desktopActivityCenter"; } from "../session/desktopActivityCenter";
import { import {
DESKTOP_SERVER_URL_CHANGED_EVENT, DESKTOP_SERVER_URL_CHANGED_EVENT,
DESKTOP_SHORTCUTS_CHANGED_EVENT,
clearLegacyDesktopRouteHistoryPreference, clearLegacyDesktopRouteHistoryPreference,
formatDesktopShortcut,
getAppMetadata, getAppMetadata,
getDesktopServerUrl, getDesktopServerUrl,
listenDesktopMenuCommand, listenDesktopMenuCommand,
readDesktopFavoriteRoutes, readDesktopFavoriteRoutes,
readDesktopShortcutPreferences,
toggleDesktopFavoriteRoute, toggleDesktopFavoriteRoute,
type DesktopRoutePreference, type DesktopRoutePreference,
type DesktopShortcutPreferences,
} from "../runtime"; } from "../runtime";
import { dispatchDesktopRefreshCurrentView } from "../composables/useDesktopRefresh"; import { dispatchDesktopRefreshCurrentView } from "../composables/useDesktopRefresh";
import { useDesktopShortcuts } from "../composables/useDesktopShortcuts"; import { useDesktopShortcuts } from "../composables/useDesktopShortcuts";
@@ -438,6 +503,14 @@ import {
type LayoutNavigationIcon, type LayoutNavigationIcon,
type LayoutNavigationItem, type LayoutNavigationItem,
} from "./layout/navigation"; } from "./layout/navigation";
import {
createWorkspaceTabHistory,
currentWorkspaceTabPath,
moveWorkspaceTabHistory,
recordWorkspaceTabPath,
replaceWorkspaceTabPath,
type WorkspaceTabHistory,
} from "./layout/workspaceTabHistory";
const auth = useAuthStore(); const auth = useAuthStore();
const study = useStudyStore(); const study = useStudyStore();
@@ -445,6 +518,10 @@ const router = useRouter();
const route = useRoute(); const route = useRoute();
const desktopMetadata = getAppMetadata(); const desktopMetadata = getAppMetadata();
const DESKTOP_WORKSPACE_TAB_CACHE_MAX = 12; const DESKTOP_WORKSPACE_TAB_CACHE_MAX = 12;
const DESKTOP_WORKSPACE_TAB_MIN_WIDTH = 130;
const DESKTOP_WORKSPACE_TAB_GAP = 6;
const DESKTOP_WORKSPACE_TABS_HORIZONTAL_PADDING = 20;
const DESKTOP_WORKSPACE_TABS_OVERFLOW_WIDTH = 106;
const DESKTOP_ADMIN_SECTION_LABEL = "系统管理"; const DESKTOP_ADMIN_SECTION_LABEL = "系统管理";
const isAdmin = computed(() => !!auth.user?.is_admin); const isAdmin = computed(() => !!auth.user?.is_admin);
const projectRole = computed(() => study.currentStudyRole || (study.currentStudy as any)?.role_in_study || ""); const projectRole = computed(() => study.currentStudyRole || (study.currentStudy as any)?.role_in_study || "");
@@ -453,6 +530,7 @@ const canAccessProjectPath = (path: string) =>
hasProjectPermission(study.currentPermissions, projectRole.value, getProjectRoutePermission(path), isAdmin.value); hasProjectPermission(study.currentPermissions, projectRole.value, getProjectRoutePermission(path), isAdmin.value);
const hasAnyProjectModuleAccess = computed(() => projectRouteLandingPaths.some((path) => canAccessProjectPath(path))); const hasAnyProjectModuleAccess = computed(() => projectRouteLandingPaths.some((path) => canAccessProjectPath(path)));
const isAdminContext = computed(() => route.path.startsWith("/admin")); const isAdminContext = computed(() => route.path.startsWith("/admin"));
const showSidebarProjectChooser = computed(() => !study.currentStudy && !isAdminContext.value);
const loggingOut = ref(false); const loggingOut = ref(false);
const commandPaletteVisible = ref(false); const commandPaletteVisible = ref(false);
const desktopPreferencesVisible = ref(false); const desktopPreferencesVisible = ref(false);
@@ -462,9 +540,15 @@ const desktopServerUrl = ref(getDesktopServerUrl());
const desktopUpdateStatus = ref<DesktopUpdateStatusSnapshot>(getDesktopUpdateStatus()); const desktopUpdateStatus = ref<DesktopUpdateStatusSnapshot>(getDesktopUpdateStatus());
const desktopActivities = ref<DesktopActivityItem[]>(getDesktopActivities()); const desktopActivities = ref<DesktopActivityItem[]>(getDesktopActivities());
const desktopFavoriteRoutes = ref<DesktopRoutePreference[]>(readDesktopFavoriteRoutes()); const desktopFavoriteRoutes = ref<DesktopRoutePreference[]>(readDesktopFavoriteRoutes());
const desktopShortcutPreferences = ref<DesktopShortcutPreferences>(readDesktopShortcutPreferences());
const workspaceTabs = ref<DesktopRoutePreference[]>([]); const workspaceTabs = ref<DesktopRoutePreference[]>([]);
const workspaceTabHistories = ref<Record<string, WorkspaceTabHistory>>({});
const workspaceTabsElement = ref<HTMLElement | null>(null);
const workspaceTabsAvailableWidth = ref(0);
const workspaceTabsOverflowOpen = ref(false);
const draggingWorkspaceTabPath = ref(""); const draggingWorkspaceTabPath = ref("");
const lastClosedWorkspaceTab = ref<DesktopRoutePreference | null>(null); const lastClosedWorkspaceTab = ref<DesktopRoutePreference | null>(null);
const lastClosedWorkspaceTabHistory = ref<WorkspaceTabHistory | null>(null);
const workspaceTabMenu = ref<{ const workspaceTabMenu = ref<{
visible: boolean; visible: boolean;
x: number; x: number;
@@ -477,11 +561,13 @@ const workspaceTabMenu = ref<{
tab: null, tab: null,
}); });
const expandedNavigationGroups = ref<Set<string>>(new Set()); const expandedNavigationGroups = ref<Set<string>>(new Set());
const collapsedNavigationGroups = ref<Set<string>>(new Set());
const headerRemindersLoading = ref(false); const headerRemindersLoading = ref(false);
const headerReminderStats = ref({ overdueAes: 0, overdueMonitoringIssues: 0 }); const headerReminderStats = ref({ overdueAes: 0, overdueMonitoringIssues: 0 });
let desktopMenuUnlisten: (() => void) | undefined; let desktopMenuUnlisten: (() => void) | undefined;
let desktopUpdateStatusUnlisten: (() => void) | undefined; let desktopUpdateStatusUnlisten: (() => void) | undefined;
let desktopActivityUnlisten: (() => void) | undefined; let desktopActivityUnlisten: (() => void) | undefined;
let workspaceTabsResizeObserver: ResizeObserver | undefined;
const iconComponentMap = { const iconComponentMap = {
audit: Document, audit: Document,
@@ -507,17 +593,23 @@ const activeMenu = computed(() => getActiveLayoutPath(route.path));
const navigationGroupKey = (item: LayoutNavigationItem) => `${item.group}:${item.label}:${item.path}`; const navigationGroupKey = (item: LayoutNavigationItem) => `${item.group}:${item.label}:${item.path}`;
const isNavigationGroupActive = (item: LayoutNavigationItem) => const isNavigationGroupActive = (item: LayoutNavigationItem) =>
Boolean(item.children?.some((child) => activeMenu.value === child.path)); Boolean(item.children?.some((child) => activeMenu.value === child.path));
const isNavigationGroupExpanded = (item: LayoutNavigationItem) => const isNavigationGroupExpanded = (item: LayoutNavigationItem) => {
isNavigationGroupActive(item) || expandedNavigationGroups.value.has(navigationGroupKey(item)); const key = navigationGroupKey(item);
return expandedNavigationGroups.value.has(key) || (isNavigationGroupActive(item) && !collapsedNavigationGroups.value.has(key));
};
const toggleNavigationGroup = (item: LayoutNavigationItem) => { const toggleNavigationGroup = (item: LayoutNavigationItem) => {
const key = navigationGroupKey(item); const key = navigationGroupKey(item);
const next = new Set(expandedNavigationGroups.value); const nextExpanded = new Set(expandedNavigationGroups.value);
if (next.has(key)) { const nextCollapsed = new Set(collapsedNavigationGroups.value);
next.delete(key); if (isNavigationGroupExpanded(item)) {
nextExpanded.delete(key);
nextCollapsed.add(key);
} else { } else {
next.add(key); nextExpanded.add(key);
nextCollapsed.delete(key);
} }
expandedNavigationGroups.value = next; expandedNavigationGroups.value = nextExpanded;
collapsedNavigationGroups.value = nextCollapsed;
}; };
const adminNavigationItems = computed(() => const adminNavigationItems = computed(() =>
study.currentStudy study.currentStudy
@@ -540,6 +632,10 @@ const projectDesktopNavigationItems = computed(() => flattenLayoutNavigationItem
const desktopNavigationItems = computed(() => const desktopNavigationItems = computed(() =>
[...adminDesktopNavigationItems.value, ...projectDesktopNavigationItems.value], [...adminDesktopNavigationItems.value, ...projectDesktopNavigationItems.value],
); );
const workspaceTabFallbackPath = computed(() => {
if (isAdminContext.value) return adminDesktopNavigationItems.value[0]?.path || "/admin/projects";
return study.currentStudy ? "/project/overview" : "/desktop/project-entry";
});
const userDisplayName = computed( const userDisplayName = computed(
() => auth.user?.full_name || auth.user?.username || auth.user?.email || TEXT.common.labels.userFallback, () => auth.user?.full_name || auth.user?.username || auth.user?.email || TEXT.common.labels.userFallback,
@@ -595,6 +691,35 @@ const currentDesktopRoutePreference = computed(() => {
if (!item) return null; if (!item) return null;
return { path: item.path, title: item.label, group: item.group }; return { path: item.path, title: item.label, group: item.group };
}); });
const visibleWorkspaceTabCapacity = computed(() => {
const tabCount = workspaceTabs.value.length;
const availableWidth = workspaceTabsAvailableWidth.value;
if (!tabCount || availableWidth <= 0) return tabCount;
const maxWithoutOverflow = Math.max(
1,
Math.floor((availableWidth + DESKTOP_WORKSPACE_TAB_GAP) / (DESKTOP_WORKSPACE_TAB_MIN_WIDTH + DESKTOP_WORKSPACE_TAB_GAP)),
);
if (tabCount <= maxWithoutOverflow) return tabCount;
return Math.max(
1,
Math.floor(
(availableWidth - DESKTOP_WORKSPACE_TABS_OVERFLOW_WIDTH) /
(DESKTOP_WORKSPACE_TAB_MIN_WIDTH + DESKTOP_WORKSPACE_TAB_GAP),
),
);
});
const visibleWorkspaceTabs = computed(() => {
const capacity = visibleWorkspaceTabCapacity.value;
if (workspaceTabs.value.length <= capacity) return workspaceTabs.value;
const firstTabs = workspaceTabs.value.slice(0, capacity);
const activeTab = workspaceTabs.value.find((item) => item.path === activeMenu.value);
if (!activeTab || firstTabs.some((item) => item.path === activeTab.path)) return firstTabs;
return [...firstTabs.slice(0, -1), activeTab];
});
const overflowWorkspaceTabs = computed(() => {
const visiblePaths = new Set(visibleWorkspaceTabs.value.map((item) => item.path));
return workspaceTabs.value.filter((item) => !visiblePaths.has(item.path));
});
const currentRouteFavorited = computed(() => { const currentRouteFavorited = computed(() => {
const current = currentDesktopRoutePreference.value; const current = currentDesktopRoutePreference.value;
return Boolean(current && desktopFavoriteRoutes.value.some((item) => item.path === current.path)); return Boolean(current && desktopFavoriteRoutes.value.some((item) => item.path === current.path));
@@ -673,11 +798,64 @@ const addWorkspaceTab = (routePreference: Pick<DesktopRoutePreference, "path" |
workspaceTabs.value = [...workspaceTabs.value, item]; workspaceTabs.value = [...workspaceTabs.value, item];
}; };
const setWorkspaceTabHistory = (tabPath: string, history: WorkspaceTabHistory) => {
workspaceTabHistories.value = { ...workspaceTabHistories.value, [tabPath]: history };
};
const removeWorkspaceTabHistory = (tabPath: string) => {
if (!workspaceTabHistories.value[tabPath]) return;
const next = { ...workspaceTabHistories.value };
delete next[tabPath];
workspaceTabHistories.value = next;
};
const recordWorkspaceTabRoute = (tabPath: string, fullPath: string) => {
setWorkspaceTabHistory(tabPath, recordWorkspaceTabPath(workspaceTabHistories.value[tabPath], fullPath));
};
const replaceWorkspaceTabRoute = (tabPath: string, fullPath: string) => {
setWorkspaceTabHistory(tabPath, replaceWorkspaceTabPath(workspaceTabHistories.value[tabPath], fullPath));
};
const workspaceTabDestination = (tabPath: string) =>
currentWorkspaceTabPath(workspaceTabHistories.value[tabPath], tabPath);
const desktopRouteCacheKey = (currentRoute: { fullPath: string }) => currentRoute.fullPath; const desktopRouteCacheKey = (currentRoute: { fullPath: string }) => currentRoute.fullPath;
const navigateWorkspaceTab = (path: string) => { const navigateWorkspaceTab = (path: string) => {
if (activeMenu.value === path) return; if (activeMenu.value === path) return;
void router.push(path); void router.push(workspaceTabDestination(path));
};
const navigateCurrentWorkspaceTabHistory = (offset: -1 | 1) => {
const tabPath = activeMenu.value;
const movement = moveWorkspaceTabHistory(workspaceTabHistories.value[tabPath], offset);
if (!movement) return;
setWorkspaceTabHistory(tabPath, movement.history);
void router.push(movement.path);
};
const navigateOverflowWorkspaceTab = (path: string) => {
navigateWorkspaceTab(path);
};
const updateWorkspaceTabsAvailableWidth = () => {
const element = workspaceTabsElement.value;
workspaceTabsAvailableWidth.value = element
? Math.max(0, element.clientWidth - DESKTOP_WORKSPACE_TABS_HORIZONTAL_PADDING)
: 0;
};
const observeWorkspaceTabsElement = (element: HTMLElement | null) => {
workspaceTabsResizeObserver?.disconnect();
if (!element) {
workspaceTabsAvailableWidth.value = 0;
return;
}
updateWorkspaceTabsAvailableWidth();
if (typeof ResizeObserver === "undefined") return;
workspaceTabsResizeObserver ||= new ResizeObserver(updateWorkspaceTabsAvailableWidth);
workspaceTabsResizeObserver.observe(element);
}; };
const closeWorkspaceTabMenu = () => { const closeWorkspaceTabMenu = () => {
@@ -734,17 +912,21 @@ const dropWorkspaceTab = (targetPath: string, event: DragEvent) => {
const closeWorkspaceTab = (path: string) => { const closeWorkspaceTab = (path: string) => {
const index = workspaceTabs.value.findIndex((tab) => tab.path === path); const index = workspaceTabs.value.findIndex((tab) => tab.path === path);
if (index >= 0) lastClosedWorkspaceTab.value = workspaceTabs.value[index]; if (index >= 0) {
lastClosedWorkspaceTab.value = workspaceTabs.value[index];
lastClosedWorkspaceTabHistory.value = workspaceTabHistories.value[path] || createWorkspaceTabHistory(path);
}
workspaceTabs.value = workspaceTabs.value.filter((tab) => tab.path !== path); workspaceTabs.value = workspaceTabs.value.filter((tab) => tab.path !== path);
removeWorkspaceTabHistory(path);
if (activeMenu.value !== path) return; if (activeMenu.value !== path) return;
const next = const next =
workspaceTabs.value[index] || workspaceTabs.value[index] ||
workspaceTabs.value[index - 1] || workspaceTabs.value[index - 1] ||
desktopFavoriteRoutes.value.find((item) => item.path !== path); desktopFavoriteRoutes.value.find((item) => item.path !== path);
if (next) { if (next) {
router.push(next.path); router.push(workspaceTabDestination(next.path));
} else { } else {
router.push(study.currentStudy ? "/project/overview" : "/desktop/project-entry"); router.push(workspaceTabFallbackPath.value);
} }
}; };
@@ -757,7 +939,9 @@ const closeOtherWorkspaceTabs = (path: string) => {
const target = workspaceTabs.value.find((tab) => tab.path === path); const target = workspaceTabs.value.find((tab) => tab.path === path);
if (!target) return; if (!target) return;
workspaceTabs.value = [target]; workspaceTabs.value = [target];
if (activeMenu.value !== path) void router.push(path); const targetHistory = workspaceTabHistories.value[path];
workspaceTabHistories.value = targetHistory ? { [path]: targetHistory } : {};
if (activeMenu.value !== path) void router.push(workspaceTabDestination(path));
closeWorkspaceTabMenu(); closeWorkspaceTabMenu();
}; };
@@ -765,8 +949,12 @@ const restoreLastClosedWorkspaceTab = () => {
const tab = lastClosedWorkspaceTab.value; const tab = lastClosedWorkspaceTab.value;
if (!tab) return; if (!tab) return;
addWorkspaceTab(tab); addWorkspaceTab(tab);
void router.push(tab.path); if (lastClosedWorkspaceTabHistory.value) {
setWorkspaceTabHistory(tab.path, lastClosedWorkspaceTabHistory.value);
}
void router.push(workspaceTabDestination(tab.path));
lastClosedWorkspaceTab.value = null; lastClosedWorkspaceTab.value = null;
lastClosedWorkspaceTabHistory.value = null;
closeWorkspaceTabMenu(); closeWorkspaceTabMenu();
}; };
@@ -774,6 +962,11 @@ const updateDesktopServerUrl = () => {
desktopServerUrl.value = getDesktopServerUrl(); desktopServerUrl.value = getDesktopServerUrl();
}; };
const updateDesktopShortcutPreferences = (event?: Event) => {
desktopShortcutPreferences.value =
(event as CustomEvent<DesktopShortcutPreferences> | undefined)?.detail || readDesktopShortcutPreferences();
};
const openCommandPalette = () => { const openCommandPalette = () => {
commandPaletteVisible.value = true; commandPaletteVisible.value = true;
}; };
@@ -785,7 +978,9 @@ const openDesktopPreferences = () => {
const openDesktopProjectEntry = async () => { const openDesktopProjectEntry = async () => {
study.clearCurrentStudy(); study.clearCurrentStudy();
workspaceTabs.value = []; workspaceTabs.value = [];
workspaceTabHistories.value = {};
lastClosedWorkspaceTab.value = null; lastClosedWorkspaceTab.value = null;
lastClosedWorkspaceTabHistory.value = null;
await router.push("/desktop/project-entry"); await router.push("/desktop/project-entry");
}; };
@@ -819,11 +1014,11 @@ const handleDesktopMenuCommand = (command: string) => {
return; return;
} }
if (command === "ctms.desktop.back") { if (command === "ctms.desktop.back") {
router.back(); navigateCurrentWorkspaceTabHistory(-1);
return; return;
} }
if (command === "ctms.desktop.forward") { if (command === "ctms.desktop.forward") {
router.forward(); navigateCurrentWorkspaceTabHistory(1);
} }
}; };
@@ -847,11 +1042,27 @@ const desktopCommands = computed<DesktopCommand[]>(() => {
run: () => navigateWorkspaceTab(item.path), run: () => navigateWorkspaceTab(item.path),
})); }));
return [ return [
{
id: "desktop:tab-back",
title: "当前标签后退",
group: "标签页",
shortcut: formatDesktopShortcut(desktopShortcutPreferences.value.back),
visible: true,
run: () => navigateCurrentWorkspaceTabHistory(-1),
},
{
id: "desktop:tab-forward",
title: "当前标签前进",
group: "标签页",
shortcut: formatDesktopShortcut(desktopShortcutPreferences.value.forward),
visible: true,
run: () => navigateCurrentWorkspaceTabHistory(1),
},
{ {
id: "desktop:refresh", id: "desktop:refresh",
title: "刷新当前视图", title: "刷新当前视图",
group: "桌面", group: "桌面",
shortcut: "⌘R", shortcut: formatDesktopShortcut(desktopShortcutPreferences.value.refresh),
visible: true, visible: true,
run: refreshCurrentDesktopView, run: refreshCurrentDesktopView,
}, },
@@ -1009,12 +1220,20 @@ const beforeProfileDialogClose = async (done: () => void) => {
}; };
watch( watch(
() => route.path, () => route.fullPath,
() => { (fullPath, previousFullPath) => {
study.setViewContext(null); study.setViewContext(null);
const current = currentDesktopRoutePreference.value; const current = currentDesktopRoutePreference.value;
if (current) { if (current) {
addWorkspaceTab(current); addWorkspaceTab(current);
const previousTabPath = previousFullPath ? getActiveLayoutPath(router.resolve(previousFullPath).path) : "";
const replacesCurrentTabEntry =
previousTabPath === current.path && Boolean((window.history.state as { replaced?: boolean } | null)?.replaced);
if (replacesCurrentTabEntry) {
replaceWorkspaceTabRoute(current.path, fullPath);
} else {
recordWorkspaceTabRoute(current.path, fullPath);
}
refreshDesktopRoutePreferences(); refreshDesktopRoutePreferences();
} }
}, },
@@ -1033,12 +1252,17 @@ watch(
() => refreshDesktopRoutePreferences(), () => refreshDesktopRoutePreferences(),
); );
watch(workspaceTabsElement, (element) => observeWorkspaceTabsElement(element), { flush: "post" });
onMounted(async () => { onMounted(async () => {
window.addEventListener(DESKTOP_SERVER_URL_CHANGED_EVENT, updateDesktopServerUrl); window.addEventListener(DESKTOP_SERVER_URL_CHANGED_EVENT, updateDesktopServerUrl);
window.addEventListener(DESKTOP_SHORTCUTS_CHANGED_EVENT, updateDesktopShortcutPreferences);
window.addEventListener("resize", updateWorkspaceTabsAvailableWidth);
clearLegacyDesktopRouteHistoryPreference(); clearLegacyDesktopRouteHistoryPreference();
const current = currentDesktopRoutePreference.value; const current = currentDesktopRoutePreference.value;
if (current) { if (current) {
addWorkspaceTab(current); addWorkspaceTab(current);
recordWorkspaceTabRoute(current.path, route.fullPath);
} }
refreshDesktopRoutePreferences(); refreshDesktopRoutePreferences();
desktopMenuUnlisten = await listenDesktopMenuCommand(handleDesktopMenuCommand).catch(() => undefined); desktopMenuUnlisten = await listenDesktopMenuCommand(handleDesktopMenuCommand).catch(() => undefined);
@@ -1065,6 +1289,9 @@ onMounted(async () => {
onBeforeUnmount(() => { onBeforeUnmount(() => {
window.removeEventListener(DESKTOP_SERVER_URL_CHANGED_EVENT, updateDesktopServerUrl); window.removeEventListener(DESKTOP_SERVER_URL_CHANGED_EVENT, updateDesktopServerUrl);
window.removeEventListener(DESKTOP_SHORTCUTS_CHANGED_EVENT, updateDesktopShortcutPreferences);
window.removeEventListener("resize", updateWorkspaceTabsAvailableWidth);
workspaceTabsResizeObserver?.disconnect();
desktopMenuUnlisten?.(); desktopMenuUnlisten?.();
desktopUpdateStatusUnlisten?.(); desktopUpdateStatusUnlisten?.();
desktopActivityUnlisten?.(); desktopActivityUnlisten?.();
@@ -1089,8 +1316,8 @@ useDesktopShortcuts(
} }
return false; return false;
}, },
navigateBack: () => router.back(), navigateBack: () => navigateCurrentWorkspaceTabHistory(-1),
navigateForward: () => router.forward(), navigateForward: () => navigateCurrentWorkspaceTabHistory(1),
refreshCurrentView: refreshCurrentDesktopView, refreshCurrentView: refreshCurrentDesktopView,
}, },
); );
@@ -1772,22 +1999,31 @@ useDesktopShortcuts(
.workspace-tabs { .workspace-tabs {
display: flex; display: flex;
align-items: center;
min-width: 0; min-width: 0;
gap: 6px; gap: 6px;
padding: 7px 10px; padding: 7px 10px;
overflow-x: auto; overflow: hidden;
border-bottom: 1px solid #dfe7f0; border-bottom: 1px solid #dfe7f0;
background: #f4f7fa; background: #f4f7fa;
} }
.workspace-tabs-list {
display: grid;
flex: 1 1 auto;
min-width: 0;
gap: 6px;
overflow: hidden;
}
.workspace-tab { .workspace-tab {
display: grid; display: grid;
grid-template-columns: minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr) auto;
align-items: center; align-items: center;
gap: 8px; gap: 8px;
min-width: 150px; min-width: 0;
max-width: 238px;
height: 30px; height: 30px;
box-sizing: border-box;
padding: 0 5px 0 10px; padding: 0 5px 0 10px;
border: 1px solid #d2dce8; border: 1px solid #d2dce8;
border-radius: 8px; border-radius: 8px;
@@ -1848,6 +2084,172 @@ useDesktopShortcuts(
color: #142033; color: #142033;
} }
.workspace-tabs-overflow {
display: flex;
flex: 0 0 106px;
min-width: 0;
}
.workspace-tabs-overflow-trigger {
appearance: none;
display: flex;
align-items: center;
justify-content: center;
width: 106px;
height: 30px;
gap: 6px;
padding: 0 9px 0 11px;
border: 1px solid #c5d1df;
border-radius: 8px;
background: #ffffff;
box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
color: #3d5068;
cursor: pointer;
font: inherit;
font-size: 12px;
font-weight: 700;
white-space: nowrap;
}
.workspace-tabs-overflow-trigger:hover,
.workspace-tabs-overflow-trigger:focus-visible,
.workspace-tabs-overflow-trigger.is-open {
border-color: #aebfd1;
background: #eaf1f8;
color: #183756;
outline: none;
}
.workspace-tabs-overflow-count {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 20px;
height: 18px;
box-sizing: border-box;
padding: 0 6px;
border-radius: 9px;
background: #e3ebf4;
color: #31506f;
font-size: 10px;
line-height: 1;
}
:global(.workspace-tabs-overflow-popper.el-popper) {
overflow: hidden;
padding: 0;
border: 1px solid #d6e0eb;
border-radius: 10px;
background: #ffffff;
box-shadow: 0 14px 38px rgba(15, 23, 42, 0.16), 0 2px 8px rgba(15, 23, 42, 0.08);
}
:global(.workspace-tabs-overflow-popper .el-popper__arrow::before) {
border-color: #d6e0eb;
background: #ffffff;
}
.workspace-tabs-overflow-menu {
width: 252px;
}
.workspace-tabs-overflow-header {
display: flex;
align-items: center;
justify-content: space-between;
height: 38px;
padding: 0 12px;
border-bottom: 1px solid #e5ebf2;
color: #2d4058;
font-size: 12px;
font-weight: 800;
}
.workspace-tabs-overflow-header span:last-child {
color: #8292a6;
font-size: 11px;
font-weight: 700;
}
:global(.workspace-tabs-overflow-popper .el-dropdown-menu) {
min-width: 0;
max-height: min(360px, calc(100vh - 120px));
padding: 6px;
border: 0;
background: transparent;
overflow-y: auto;
}
:global(.workspace-tabs-overflow-popper .el-dropdown-menu__item) {
display: flex;
min-height: 38px;
gap: 9px;
padding: 0 6px 0 10px;
border-radius: 7px;
color: #33485f;
font-size: 12px;
font-weight: 700;
}
:global(.workspace-tabs-overflow-popper .el-dropdown-menu__item:hover),
:global(.workspace-tabs-overflow-popper .el-dropdown-menu__item:focus) {
background: #f0f5fa;
color: #183756;
}
:global(.workspace-tabs-overflow-popper .el-dropdown-menu__item.is-current) {
background: #eaf1f8;
color: #183756;
}
.workspace-tabs-overflow-label {
display: block;
flex: 1 1 auto;
min-width: 0;
}
.workspace-tabs-overflow-item-mark {
flex: 0 0 7px;
width: 7px;
height: 7px;
border-radius: 50%;
background: #9fb1c4;
}
.workspace-tabs-overflow-label > span {
display: block;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.workspace-tabs-overflow-close {
appearance: none;
display: inline-flex;
align-items: center;
justify-content: center;
flex: 0 0 24px;
width: 24px;
height: 24px;
padding: 0;
border: 0;
border-radius: 6px;
background: transparent;
color: #7b8da3;
cursor: pointer;
font: inherit;
font-size: 16px;
opacity: 0.62;
}
.workspace-tabs-overflow-close:hover,
.workspace-tabs-overflow-close:focus-visible {
background: rgba(15, 23, 42, 0.08);
color: #142033;
opacity: 1;
outline: none;
}
.workspace-tab-context-menu { .workspace-tab-context-menu {
position: fixed; position: fixed;
z-index: 2300; z-index: 2300;
@@ -2007,7 +2409,8 @@ useDesktopShortcuts(
:global([data-ctms-theme="dark"] .update-notice), :global([data-ctms-theme="dark"] .update-notice),
:global([data-ctms-theme="dark"] .connection-button), :global([data-ctms-theme="dark"] .connection-button),
:global([data-ctms-theme="dark"] .account-button), :global([data-ctms-theme="dark"] .account-button),
:global([data-ctms-theme="dark"] .workspace-tab) { :global([data-ctms-theme="dark"] .workspace-tab),
:global([data-ctms-theme="dark"] .workspace-tabs-overflow-trigger) {
border-color: #334155; border-color: #334155;
background: #172033; background: #172033;
color: #dbe5f1; color: #dbe5f1;
@@ -2047,6 +2450,59 @@ useDesktopShortcuts(
background: #111827; background: #111827;
} }
:global([data-ctms-theme="dark"] .workspace-tabs-overflow-count) {
background: #243247;
color: #bfdbfe;
}
:global([data-ctms-theme="dark"] .workspace-tabs-overflow-popper .el-dropdown-menu) {
background: transparent;
}
:global([data-ctms-theme="dark"] .workspace-tabs-overflow-popper.el-popper) {
border-color: #334155;
background: #172033;
}
:global([data-ctms-theme="dark"] .workspace-tabs-overflow-popper .el-popper__arrow::before) {
border-color: #334155;
background: #172033;
}
:global([data-ctms-theme="dark"] .workspace-tabs-overflow-header) {
border-bottom-color: #334155;
color: #e5edf7;
}
:global([data-ctms-theme="dark"] .workspace-tabs-overflow-header span:last-child) {
color: #94a3b8;
}
:global([data-ctms-theme="dark"] .workspace-tabs-overflow-popper .el-dropdown-menu__item) {
color: #dbe5f1;
}
:global([data-ctms-theme="dark"] .workspace-tabs-overflow-popper .el-dropdown-menu__item:hover),
:global([data-ctms-theme="dark"] .workspace-tabs-overflow-popper .el-dropdown-menu__item:focus),
:global([data-ctms-theme="dark"] .workspace-tabs-overflow-popper .el-dropdown-menu__item.is-current) {
background: #243247;
color: #bfdbfe;
}
:global([data-ctms-theme="dark"] .workspace-tabs-overflow-item-mark) {
background: #6f87a1;
}
:global([data-ctms-theme="dark"] .workspace-tabs-overflow-close) {
color: #94a3b8;
}
:global([data-ctms-theme="dark"] .workspace-tabs-overflow-close:hover),
:global([data-ctms-theme="dark"] .workspace-tabs-overflow-close:focus-visible) {
background: rgba(226, 232, 240, 0.1);
color: #f8fafc;
}
:global([data-ctms-theme="dark"] .desktop-content) { :global([data-ctms-theme="dark"] .desktop-content) {
background: #0f172a; background: #0f172a;
} }
+71 -3
View File
@@ -8,6 +8,7 @@ const readDesktopLayoutSource = () => readFileSync(resolve(__dirname, "./Desktop
const readWebLayoutSource = () => readFileSync(resolve(__dirname, "./WebLayout.vue"), "utf8"); const readWebLayoutSource = () => readFileSync(resolve(__dirname, "./WebLayout.vue"), "utf8");
const readNavigationSource = () => readFileSync(resolve(__dirname, "./layout/navigation.ts"), "utf8"); const readNavigationSource = () => readFileSync(resolve(__dirname, "./layout/navigation.ts"), "utf8");
const readTauriConfigSource = () => readFileSync(resolve(__dirname, "../../src-tauri/tauri.conf.json"), "utf8"); const readTauriConfigSource = () => readFileSync(resolve(__dirname, "../../src-tauri/tauri.conf.json"), "utf8");
const readTauriLibSource = () => readFileSync(resolve(__dirname, "../../src-tauri/src/lib.rs"), "utf8");
const readDesktopPreferencesSource = () => readFileSync(resolve(__dirname, "../views/DesktopPreferences.vue"), "utf8"); const readDesktopPreferencesSource = () => readFileSync(resolve(__dirname, "../views/DesktopPreferences.vue"), "utf8");
const readDesktopServerSettingsSource = () => readFileSync(resolve(__dirname, "../views/DesktopServerSettings.vue"), "utf8"); const readDesktopServerSettingsSource = () => readFileSync(resolve(__dirname, "../views/DesktopServerSettings.vue"), "utf8");
const readDesktopUpdateManagerSource = () => readFileSync(resolve(__dirname, "../session/desktopUpdateManager.ts"), "utf8"); const readDesktopUpdateManagerSource = () => readFileSync(resolve(__dirname, "../session/desktopUpdateManager.ts"), "utf8");
@@ -92,7 +93,7 @@ describe("desktop layout shell", () => {
expect(source).toContain("const adminDesktopNavigationItems"); expect(source).toContain("const adminDesktopNavigationItems");
expect(source).toContain("const projectDesktopNavigationItems"); expect(source).toContain("const projectDesktopNavigationItems");
expect(source).toContain('id: "desktop:refresh"'); expect(source).toContain('id: "desktop:refresh"');
expect(source).toContain('shortcut: "⌘R"'); expect(source).toContain("shortcut: formatDesktopShortcut(desktopShortcutPreferences.value.refresh)");
expect(source).toContain('command === "ctms.desktop.back"'); expect(source).toContain('command === "ctms.desktop.back"');
expect(source).toContain('command === "ctms.desktop.forward"'); expect(source).toContain('command === "ctms.desktop.forward"');
expect(source).not.toContain("const root = study.currentStudy?.name || TEXT.menu.currentProject"); expect(source).not.toContain("const root = study.currentStudy?.name || TEXT.menu.currentProject");
@@ -127,12 +128,13 @@ describe("desktop layout shell", () => {
expect(layout).toContain('command="projectEntry"'); expect(layout).toContain('command="projectEntry"');
expect(layout).toContain("projectEntryMenuLabel"); expect(layout).toContain("projectEntryMenuLabel");
expect(layout).toContain("openDesktopProjectEntry"); expect(layout).toContain("openDesktopProjectEntry");
expect(layout).toContain("const showSidebarProjectChooser = computed(() => !study.currentStudy && !isAdminContext.value);");
expect(layout).toContain("padding: 10px 8px 24px;"); expect(layout).toContain("padding: 10px 8px 24px;");
expect(layout).toContain("margin-top: 12px;"); expect(layout).toContain("margin-top: 12px;");
expect(layout).toContain("font-size: 14px;"); expect(layout).toContain("font-size: 14px;");
expect(sidebarHeadTemplate).toContain('<div class="sidebar-title-row">'); expect(sidebarHeadTemplate).toContain('<div class="sidebar-title-row">');
expect(sidebarHeadTemplate.indexOf("<h1>{{ TEXT.common.appName }}</h1>")).toBeLessThan( expect(sidebarHeadTemplate.indexOf("<h1>{{ TEXT.common.appName }}</h1>")).toBeLessThan(
sidebarHeadTemplate.indexOf('<button v-if="!study.currentStudy" class="study-switcher-trigger empty"'), sidebarHeadTemplate.indexOf('<button v-if="showSidebarProjectChooser" class="study-switcher-trigger empty"'),
); );
expect(sidebarHeadTemplate).not.toContain("study-context-badge"); expect(sidebarHeadTemplate).not.toContain("study-context-badge");
expect(layout).not.toContain(".study-context-badge"); expect(layout).not.toContain(".study-context-badge");
@@ -158,6 +160,7 @@ describe("desktop layout shell", () => {
expect(preferences).toContain("scrollbar-gutter: stable;"); expect(preferences).toContain("scrollbar-gutter: stable;");
expect(preferences).toContain('{ id: "connection", label: "连接"'); expect(preferences).toContain('{ id: "connection", label: "连接"');
expect(preferences).toContain('{ id: "appearance", label: "外观"'); expect(preferences).toContain('{ id: "appearance", label: "外观"');
expect(preferences).toContain('{ id: "shortcuts", label: "快捷键"');
expect(preferences).toContain('{ id: "notifications", label: "通知"'); expect(preferences).toContain('{ id: "notifications", label: "通知"');
expect(preferences).toContain('{ id: "updates", label: "更新"'); expect(preferences).toContain('{ id: "updates", label: "更新"');
expect(preferences).toContain('{ id: "diagnostics", label: "诊断信息"'); expect(preferences).toContain('{ id: "diagnostics", label: "诊断信息"');
@@ -222,7 +225,7 @@ describe("desktop layout shell", () => {
it("keeps workspace tabs stable and draggable like browser tabs", () => { it("keeps workspace tabs stable and draggable like browser tabs", () => {
const source = readDesktopLayoutSource(); const source = readDesktopLayoutSource();
const tabsStart = source.indexOf('<div class="workspace-tabs"'); const tabsStart = source.indexOf('<div v-if="workspaceTabs.length" ref="workspaceTabsElement" class="workspace-tabs">');
const tabsEnd = source.indexOf('<main class="desktop-content"', tabsStart); const tabsEnd = source.indexOf('<main class="desktop-content"', tabsStart);
const tabsTemplate = source.slice(tabsStart, tabsEnd); const tabsTemplate = source.slice(tabsStart, tabsEnd);
@@ -248,11 +251,72 @@ describe("desktop layout shell", () => {
expect(source).toContain("const workspaceTabMenu = ref<"); expect(source).toContain("const workspaceTabMenu = ref<");
expect(source).toContain("const closeOtherWorkspaceTabs = (path: string) => {"); expect(source).toContain("const closeOtherWorkspaceTabs = (path: string) => {");
expect(source).toContain("const restoreLastClosedWorkspaceTab = () => {"); expect(source).toContain("const restoreLastClosedWorkspaceTab = () => {");
expect(source).toContain("const workspaceTabFallbackPath = computed(() => {");
expect(source).toContain('if (isAdminContext.value) return adminDesktopNavigationItems.value[0]?.path || "/admin/projects";');
expect(source).toContain("router.push(workspaceTabFallbackPath.value);");
expect(source).not.toContain('router.push(study.currentStudy ? "/project/overview" : "/desktop/project-entry");');
expect(source).toContain('id: `workspace-tab:${item.path}`'); expect(source).toContain('id: `workspace-tab:${item.path}`');
expect(source).toContain('title: `切换标签:${item.title}`'); expect(source).toContain('title: `切换标签:${item.title}`');
expect(source).toContain('title: "重新打开最近关闭标签"'); expect(source).toContain('title: "重新打开最近关闭标签"');
}); });
it("keeps shortcut navigation history isolated to the active workspace tab", () => {
const source = readDesktopLayoutSource();
expect(source).toContain("const workspaceTabHistories = ref<Record<string, WorkspaceTabHistory>>({});");
expect(source).toContain("recordWorkspaceTabRoute(current.path, fullPath);");
expect(source).toContain("replaceWorkspaceTabRoute(current.path, fullPath);");
expect(source).toContain("currentWorkspaceTabPath(workspaceTabHistories.value[tabPath], tabPath)");
expect(source).toContain("moveWorkspaceTabHistory(workspaceTabHistories.value[tabPath], offset)");
expect(source).toContain("navigateBack: () => navigateCurrentWorkspaceTabHistory(-1)");
expect(source).toContain("navigateForward: () => navigateCurrentWorkspaceTabHistory(1)");
expect(source).toContain('id: "desktop:tab-back"');
expect(source).toContain('id: "desktop:tab-forward"');
expect(source).not.toContain("navigateBack: () => router.back()");
expect(source).not.toContain("navigateForward: () => router.forward()");
});
it("allows desktop shortcuts to be customized from system preferences", () => {
const preferences = readDesktopPreferencesSource();
const tauriLib = readTauriLibSource();
expect(preferences).toContain("activeSectionId === 'shortcuts'");
expect(preferences).toContain("desktopShortcutFromKeyboardEvent");
expect(preferences).toContain("setDesktopShortcutPreference");
expect(preferences).toContain("resetDesktopShortcutPreferences");
expect(preferences).toContain("startDesktopShortcutCapture($event, item.action)");
expect(preferences).toContain('window.addEventListener("keydown", captureDesktopShortcut, { capture: true })');
expect(preferences).toContain('window.addEventListener("pointerdown", cancelDesktopShortcutCaptureOnPointerDown, { capture: true })');
expect(preferences).toContain("event.stopImmediatePropagation()");
expect(preferences).toContain("恢复默认");
expect(tauriLib).not.toContain('Some("CmdOrCtrl+R")');
expect(tauriLib).not.toContain('Some("CmdOrCtrl+[")');
expect(tauriLib).not.toContain('Some("CmdOrCtrl+]")');
});
it("moves overflowing workspace tabs into a fixed dropdown without horizontal scrolling", () => {
const source = readDesktopLayoutSource();
const tabsStart = source.indexOf('<div v-if="workspaceTabs.length" ref="workspaceTabsElement" class="workspace-tabs">');
const tabsEnd = source.indexOf('<main class="desktop-content"', tabsStart);
const tabsTemplate = source.slice(tabsStart, tabsEnd);
expect(tabsTemplate).toContain('v-for="item in visibleWorkspaceTabs"');
expect(tabsTemplate).toContain('v-if="overflowWorkspaceTabs.length"');
expect(tabsTemplate).toContain('popper-class="workspace-tabs-overflow-popper"');
expect(tabsTemplate).toContain('{{ overflowWorkspaceTabs.length }}');
expect(tabsTemplate).toContain('@command="navigateOverflowWorkspaceTab"');
expect(tabsTemplate).toContain('gridTemplateColumns: `repeat(${visibleWorkspaceTabs.length}, minmax(0, 238px))`');
expect(tabsTemplate).toContain('class="workspace-tabs-overflow-header"');
expect(source).toContain("const visibleWorkspaceTabCapacity = computed(() => {");
expect(source).toContain("const visibleWorkspaceTabs = computed(() => {");
expect(source).toContain("const overflowWorkspaceTabs = computed(() => {");
expect(source).toContain('workspaceTabsResizeObserver ||= new ResizeObserver(updateWorkspaceTabsAvailableWidth);');
expect(source).toContain("const DESKTOP_WORKSPACE_TABS_OVERFLOW_WIDTH = 106;");
expect(source).toContain(".workspace-tabs-list {\n display: grid;");
expect(source).toContain("overflow: hidden;");
expect(source).not.toContain("overflow-x: auto;");
});
it("keeps desktop navigation hierarchy aligned with the web sidebar", () => { it("keeps desktop navigation hierarchy aligned with the web sidebar", () => {
const desktopLayout = readDesktopLayoutSource(); const desktopLayout = readDesktopLayoutSource();
const navigation = readNavigationSource(); const navigation = readNavigationSource();
@@ -267,6 +331,10 @@ describe("desktop layout shell", () => {
expect(sidebarTemplate).toContain(':aria-expanded="isNavigationGroupExpanded(item)"'); expect(sidebarTemplate).toContain(':aria-expanded="isNavigationGroupExpanded(item)"');
expect(sidebarTemplate).toContain('v-show="isNavigationGroupExpanded(item)"'); expect(sidebarTemplate).toContain('v-show="isNavigationGroupExpanded(item)"');
expect(desktopLayout).toContain("const expandedNavigationGroups = ref<Set<string>>(new Set());"); expect(desktopLayout).toContain("const expandedNavigationGroups = ref<Set<string>>(new Set());");
expect(desktopLayout).toContain("const collapsedNavigationGroups = ref<Set<string>>(new Set());");
expect(desktopLayout).toContain("isNavigationGroupActive(item) && !collapsedNavigationGroups.value.has(key)");
expect(desktopLayout).toContain("nextCollapsed.add(key);");
expect(desktopLayout).toContain("nextCollapsed.delete(key);");
expect(navigation).toContain('label: "系统设置"'); expect(navigation).toContain('label: "系统设置"');
expect(navigation).toContain('label: "邮件服务"'); expect(navigation).toContain('label: "邮件服务"');
expect(navigation).toContain('group: "系统设置"'); expect(navigation).toContain('group: "系统设置"');
@@ -0,0 +1,50 @@
import { describe, expect, it } from "vitest";
import {
canMoveWorkspaceTabHistory,
createWorkspaceTabHistory,
currentWorkspaceTabPath,
moveWorkspaceTabHistory,
recordWorkspaceTabPath,
replaceWorkspaceTabPath,
} from "./workspaceTabHistory";
describe("workspace tab history", () => {
it("records full paths without duplicating the current entry", () => {
const initial = createWorkspaceTabHistory("/subjects");
const detail = recordWorkspaceTabPath(initial, "/subjects/subject-1?tab=ae");
expect(detail).toEqual({ entries: ["/subjects", "/subjects/subject-1?tab=ae"], index: 1 });
expect(recordWorkspaceTabPath(detail, "/subjects/subject-1?tab=ae")).toBe(detail);
});
it("moves backward and forward without adding entries", () => {
const detail = recordWorkspaceTabPath(createWorkspaceTabHistory("/subjects"), "/subjects/subject-1");
const backward = moveWorkspaceTabHistory(detail, -1);
const forward = moveWorkspaceTabHistory(backward?.history, 1);
expect(backward?.path).toBe("/subjects");
expect(forward?.path).toBe("/subjects/subject-1");
expect(canMoveWorkspaceTabHistory(backward?.history, -1)).toBe(false);
expect(canMoveWorkspaceTabHistory(backward?.history, 1)).toBe(true);
});
it("drops forward entries after a new navigation branch", () => {
const detail = recordWorkspaceTabPath(createWorkspaceTabHistory("/subjects"), "/subjects/subject-1");
const backward = moveWorkspaceTabHistory(detail, -1);
const branch = recordWorkspaceTabPath(backward?.history, "/subjects/new");
expect(branch).toEqual({ entries: ["/subjects", "/subjects/new"], index: 1 });
expect(canMoveWorkspaceTabHistory(branch, 1)).toBe(false);
});
it("replaces canonical redirects without creating a backward loop", () => {
const canonical = replaceWorkspaceTabPath(
createWorkspaceTabHistory("/file-versions"),
"/trial/study-1/documents",
);
expect(canonical).toEqual({ entries: ["/trial/study-1/documents"], index: 0 });
expect(canMoveWorkspaceTabHistory(canonical, -1)).toBe(false);
expect(currentWorkspaceTabPath(canonical, "/file-versions")).toBe("/trial/study-1/documents");
});
});
@@ -0,0 +1,54 @@
export type WorkspaceTabHistory = {
entries: string[];
index: number;
};
export type WorkspaceTabHistoryMove = {
history: WorkspaceTabHistory;
path: string;
};
const WORKSPACE_TAB_HISTORY_MAX_ENTRIES = 50;
export const createWorkspaceTabHistory = (path: string): WorkspaceTabHistory => ({ entries: [path], index: 0 });
export const recordWorkspaceTabPath = (
history: WorkspaceTabHistory | undefined,
path: string,
): WorkspaceTabHistory => {
if (!history?.entries.length) return createWorkspaceTabHistory(path);
if (history.entries[history.index] === path) return history;
const entries = [...history.entries.slice(0, history.index + 1), path].slice(-WORKSPACE_TAB_HISTORY_MAX_ENTRIES);
return { entries, index: entries.length - 1 };
};
export const replaceWorkspaceTabPath = (
history: WorkspaceTabHistory | undefined,
path: string,
): WorkspaceTabHistory => {
if (!history?.entries.length) return createWorkspaceTabHistory(path);
if (history.entries[history.index] === path) return history;
const entries = [...history.entries];
entries[history.index] = path;
return { entries, index: history.index };
};
export const moveWorkspaceTabHistory = (
history: WorkspaceTabHistory | undefined,
offset: -1 | 1,
): WorkspaceTabHistoryMove | null => {
if (!history?.entries.length) return null;
const index = history.index + offset;
if (index < 0 || index >= history.entries.length) return null;
return { history: { ...history, index }, path: history.entries[index] };
};
export const currentWorkspaceTabPath = (history: WorkspaceTabHistory | undefined, fallbackPath: string) =>
history?.entries[history.index] || fallbackPath;
export const canMoveWorkspaceTabHistory = (history: WorkspaceTabHistory | undefined, offset: -1 | 1) => {
if (!history?.entries.length) return false;
const index = history.index + offset;
return index >= 0 && index < history.entries.length;
};
+27 -18
View File
@@ -1,4 +1,10 @@
import { onBeforeUnmount, onMounted } from "vue"; import { onBeforeUnmount, onMounted } from "vue";
import {
DESKTOP_SHORTCUTS_CHANGED_EVENT,
readDesktopShortcutPreferences,
resolveDesktopShortcutAction,
type DesktopShortcutPreferences,
} from "../runtime";
export interface DesktopShortcutHandlers { export interface DesktopShortcutHandlers {
openCommandPalette: () => void; openCommandPalette: () => void;
@@ -18,6 +24,12 @@ export const isEditableShortcutTarget = (target: EventTarget | null): boolean =>
}; };
export const useDesktopShortcuts = (enabled: () => boolean, handlers: DesktopShortcutHandlers) => { export const useDesktopShortcuts = (enabled: () => boolean, handlers: DesktopShortcutHandlers) => {
let shortcuts = readDesktopShortcutPreferences();
const onShortcutsChanged = (event: Event) => {
shortcuts = (event as CustomEvent<DesktopShortcutPreferences>).detail || readDesktopShortcutPreferences();
};
const onKeydown = (event: KeyboardEvent) => { const onKeydown = (event: KeyboardEvent) => {
if (!enabled() || isEditableShortcutTarget(event.target)) return; if (!enabled() || isEditableShortcutTarget(event.target)) return;
const modifier = event.metaKey || event.ctrlKey; const modifier = event.metaKey || event.ctrlKey;
@@ -28,31 +40,28 @@ export const useDesktopShortcuts = (enabled: () => boolean, handlers: DesktopSho
return; return;
} }
if (!modifier) return; if (modifier && key === "k") {
if (key === "k") {
event.preventDefault(); event.preventDefault();
handlers.openCommandPalette(); handlers.openCommandPalette();
return; return;
} }
if (key === "[") {
const action = resolveDesktopShortcutAction(event, shortcuts);
if (!action) return;
event.preventDefault(); event.preventDefault();
handlers.navigateBack?.(); if (action === "back") handlers.navigateBack?.();
return; if (action === "forward") handlers.navigateForward?.();
} if (action === "refresh") handlers.refreshCurrentView?.();
if (key === "]") {
event.preventDefault();
handlers.navigateForward?.();
return;
}
if (key === "r") {
event.preventDefault();
handlers.refreshCurrentView?.();
}
}; };
onMounted(() => window.addEventListener("keydown", onKeydown)); onMounted(() => {
onBeforeUnmount(() => window.removeEventListener("keydown", onKeydown)); window.addEventListener("keydown", onKeydown);
window.addEventListener(DESKTOP_SHORTCUTS_CHANGED_EVENT, onShortcutsChanged);
});
onBeforeUnmount(() => {
window.removeEventListener("keydown", onKeydown);
window.removeEventListener(DESKTOP_SHORTCUTS_CHANGED_EVENT, onShortcutsChanged);
});
return { onKeydown }; return { onKeydown };
}; };
+15
View File
@@ -94,6 +94,21 @@ describe("admin project route permissions", () => {
expect(source).toContain('if (token && !studyStore.currentStudy && !isDesktopRuntime)'); expect(source).toContain('if (token && !studyStore.currentStudy && !isDesktopRuntime)');
}); });
it("canonicalizes the legacy file version entry before rendering its loading fallback", () => {
const source = readRouter();
const guardIndex = source.indexOf('if (to.name === "FileVersionManagement" && studyStore.currentStudy?.id)');
const requiresStudyIndex = source.indexOf("if (to.meta.requiresStudy && !studyStore.currentStudy)");
const legacyRouteIndex = source.indexOf('name: "FileVersionManagement"');
const legacyRouteEnd = source.indexOf('path: "trial/:trialId/documents"', legacyRouteIndex);
const legacyRoute = source.slice(legacyRouteIndex, legacyRouteEnd);
expect(guardIndex).toBeGreaterThan(-1);
expect(requiresStudyIndex).toBeGreaterThan(guardIndex);
expect(legacyRoute).toContain("component: DocumentList");
expect(source).not.toContain('import FileVersionManagement from "../views/ia/FileVersionManagement.vue";');
expect(source).toContain('next({ name: "DocumentList", params: { trialId: studyStore.currentStudy.id }, replace: true });');
});
it("validates restored session tokens through /me before entering protected routes", () => { it("validates restored session tokens through /me before entering protected routes", () => {
const source = readRouter(); const source = readRouter();
const restoreGuardIndex = source.indexOf("if (!auth.user && getToken() && !isDesktopSessionRestoreRoute)"); const restoreGuardIndex = source.indexOf("if (!auth.user && getToken() && !isDesktopSessionRestoreRoute)");
+5 -2
View File
@@ -32,7 +32,6 @@ import DrugShipments from "../views/ia/DrugShipments.vue";
import ShipmentDetail from "../views/drug/ShipmentDetail.vue"; import ShipmentDetail from "../views/drug/ShipmentDetail.vue";
import MaterialEquipment from "../views/ia/MaterialEquipment.vue"; import MaterialEquipment from "../views/ia/MaterialEquipment.vue";
import MaterialEquipmentDetail from "../views/materials/MaterialEquipmentDetail.vue"; import MaterialEquipmentDetail from "../views/materials/MaterialEquipmentDetail.vue";
import FileVersionManagement from "../views/ia/FileVersionManagement.vue";
import DocumentList from "../views/documents/DocumentList.vue"; import DocumentList from "../views/documents/DocumentList.vue";
import DocumentDetail from "../views/documents/DocumentDetail.vue"; import DocumentDetail from "../views/documents/DocumentDetail.vue";
import StartupFeasibilityEthics from "../views/ia/StartupFeasibilityEthics.vue"; import StartupFeasibilityEthics from "../views/ia/StartupFeasibilityEthics.vue";
@@ -164,7 +163,7 @@ const routes: RouteRecordRaw[] = [
{ {
path: "file-versions", path: "file-versions",
name: "FileVersionManagement", name: "FileVersionManagement",
component: FileVersionManagement, component: DocumentList,
meta: { title: TEXT.menu.fileVersionManagement, requiresStudy: true }, meta: { title: TEXT.menu.fileVersionManagement, requiresStudy: true },
}, },
{ {
@@ -610,6 +609,10 @@ router.beforeEach(async (to, _from, next) => {
return; return;
} }
} }
if (to.name === "FileVersionManagement" && studyStore.currentStudy?.id) {
next({ name: "DocumentList", params: { trialId: studyStore.currentStudy.id }, replace: true });
return;
}
if (to.meta.adminProjectPermission) { if (to.meta.adminProjectPermission) {
const allowed = await ensureAdminProjectAccess(to, isAdmin).catch(() => false); const allowed = await ensureAdminProjectAccess(to, isAdmin).catch(() => false);
if (!allowed) { if (!allowed) {
@@ -1,11 +1,18 @@
import { beforeEach, describe, expect, it } from "vitest"; import { beforeEach, describe, expect, it } from "vitest";
import { import {
DEFAULT_DESKTOP_SHORTCUTS,
DESKTOP_FAVORITE_ROUTES_KEY, DESKTOP_FAVORITE_ROUTES_KEY,
DESKTOP_SHORTCUTS_KEY,
DESKTOP_THEME_KEY, DESKTOP_THEME_KEY,
applyDesktopThemePreference, applyDesktopThemePreference,
clearLegacyDesktopRouteHistoryPreference, clearLegacyDesktopRouteHistoryPreference,
desktopShortcutFromKeyboardEvent,
readDesktopFavoriteRoutes, readDesktopFavoriteRoutes,
readDesktopShortcutPreferences,
readDesktopThemePreference, readDesktopThemePreference,
resetDesktopShortcutPreferences,
resolveDesktopShortcutAction,
setDesktopShortcutPreference,
setDesktopThemePreference, setDesktopThemePreference,
toggleDesktopFavoriteRoute, toggleDesktopFavoriteRoute,
} from "./desktopUiPreferences"; } from "./desktopUiPreferences";
@@ -81,4 +88,37 @@ describe("desktop UI preferences", () => {
applyDesktopThemePreference("light"); applyDesktopThemePreference("light");
expect(document.documentElement.getAttribute("data-ctms-theme")).toBe("light"); expect(document.documentElement.getAttribute("data-ctms-theme")).toBe("light");
}); });
it("stores validated non-conflicting desktop shortcuts", () => {
const result = setDesktopShortcutPreference("back", "Mod+Shift+[");
expect(result.ok).toBe(true);
expect(readDesktopShortcutPreferences().back).toBe("Mod+Shift+[");
expect(window.localStorage.getItem(DESKTOP_SHORTCUTS_KEY)).not.toContain("token");
const conflict = setDesktopShortcutPreference("forward", "Mod+Shift+[");
expect(conflict.ok).toBe(false);
expect(readDesktopShortcutPreferences().forward).toBe(DEFAULT_DESKTOP_SHORTCUTS.forward);
});
it("rejects reserved shortcuts and resets invalid storage to defaults", () => {
expect(setDesktopShortcutPreference("refresh", "Mod+Q").ok).toBe(false);
window.localStorage.setItem(
DESKTOP_SHORTCUTS_KEY,
JSON.stringify({ back: "Mod+R", forward: "Mod+R", refresh: "invalid" }),
);
expect(readDesktopShortcutPreferences()).toEqual(DEFAULT_DESKTOP_SHORTCUTS);
expect(resetDesktopShortcutPreferences()).toEqual(DEFAULT_DESKTOP_SHORTCUTS);
});
it("captures and resolves shortcut keyboard events", () => {
const backEvent = new KeyboardEvent("keydown", { key: "[", metaKey: true });
const customRefreshEvent = new KeyboardEvent("keydown", { key: "R", metaKey: true, shiftKey: true });
const shortcuts = { ...DEFAULT_DESKTOP_SHORTCUTS, refresh: "Mod+Shift+R" };
expect(desktopShortcutFromKeyboardEvent(backEvent)).toBe("Mod+[");
expect(resolveDesktopShortcutAction(backEvent, shortcuts)).toBe("back");
expect(resolveDesktopShortcutAction(customRefreshEvent, shortcuts)).toBe("refresh");
});
}); });
@@ -1,8 +1,18 @@
export const DESKTOP_FAVORITE_ROUTES_KEY = "ctms_desktop_favorite_routes"; export const DESKTOP_FAVORITE_ROUTES_KEY = "ctms_desktop_favorite_routes";
export const DESKTOP_THEME_KEY = "ctms_desktop_theme"; export const DESKTOP_THEME_KEY = "ctms_desktop_theme";
export const DESKTOP_THEME_CHANGED_EVENT = "ctms:desktop-theme-changed"; export const DESKTOP_THEME_CHANGED_EVENT = "ctms:desktop-theme-changed";
export const DESKTOP_SHORTCUTS_KEY = "ctms_desktop_shortcuts";
export const DESKTOP_SHORTCUTS_CHANGED_EVENT = "ctms:desktop-shortcuts-changed";
export type DesktopThemePreference = "light" | "dark"; export type DesktopThemePreference = "light" | "dark";
export type DesktopShortcutAction = "back" | "forward" | "refresh";
export type DesktopShortcutPreferences = Record<DesktopShortcutAction, string>;
export const DEFAULT_DESKTOP_SHORTCUTS: DesktopShortcutPreferences = Object.freeze({
back: "Mod+[",
forward: "Mod+]",
refresh: "Mod+R",
});
export interface DesktopRoutePreference { export interface DesktopRoutePreference {
path: string; path: string;
@@ -15,6 +25,20 @@ const MAX_FAVORITE_ROUTES = 12;
const DEFAULT_DESKTOP_THEME: DesktopThemePreference = "light"; const DEFAULT_DESKTOP_THEME: DesktopThemePreference = "light";
const DESKTOP_THEME_ATTRIBUTE = "data-ctms-theme"; const DESKTOP_THEME_ATTRIBUTE = "data-ctms-theme";
const LEGACY_DESKTOP_ROUTE_HISTORY_KEY = "ctms_desktop_recent_routes"; const LEGACY_DESKTOP_ROUTE_HISTORY_KEY = "ctms_desktop_recent_routes";
const DESKTOP_SHORTCUT_ACTIONS: DesktopShortcutAction[] = ["back", "forward", "refresh"];
const DESKTOP_SHORTCUT_PATTERN = /^Mod(?:\+Shift)?(?:\+Alt)?\+(?:[A-Z0-9]|\[|\]|,|\.|\/|;|=|-|ArrowLeft|ArrowRight|ArrowUp|ArrowDown|Home|End|PageUp|PageDown)$/;
const RESERVED_DESKTOP_SHORTCUTS = new Set([
"Mod+K",
"Mod+,",
"Mod+W",
"Mod+Q",
"Mod+C",
"Mod+V",
"Mod+X",
"Mod+A",
"Mod+Z",
"Mod+Shift+Z",
]);
const isStorageAvailable = () => typeof window !== "undefined" && typeof window.localStorage !== "undefined"; const isStorageAvailable = () => typeof window !== "undefined" && typeof window.localStorage !== "undefined";
@@ -53,6 +77,112 @@ const writeRoutePreferences = (key: string, routes: DesktopRoutePreference[]) =>
const sanitizeDesktopThemePreference = (value: unknown): DesktopThemePreference => const sanitizeDesktopThemePreference = (value: unknown): DesktopThemePreference =>
value === "dark" ? "dark" : DEFAULT_DESKTOP_THEME; value === "dark" ? "dark" : DEFAULT_DESKTOP_THEME;
const sanitizeDesktopShortcut = (value: unknown): string | null => {
if (typeof value !== "string") return null;
const shortcut = value.trim();
return DESKTOP_SHORTCUT_PATTERN.test(shortcut) && !RESERVED_DESKTOP_SHORTCUTS.has(shortcut) ? shortcut : null;
};
const isDesktopShortcutPreferences = (value: unknown): value is DesktopShortcutPreferences => {
if (!value || typeof value !== "object") return false;
const shortcuts = value as Partial<DesktopShortcutPreferences>;
const values = DESKTOP_SHORTCUT_ACTIONS.map((action) => sanitizeDesktopShortcut(shortcuts[action]));
return values.every(Boolean) && new Set(values).size === DESKTOP_SHORTCUT_ACTIONS.length;
};
const writeDesktopShortcutPreferences = (shortcuts: DesktopShortcutPreferences) => {
if (!isStorageAvailable()) return;
window.localStorage.setItem(DESKTOP_SHORTCUTS_KEY, JSON.stringify(shortcuts));
};
const emitDesktopShortcutPreferences = (shortcuts: DesktopShortcutPreferences) => {
if (typeof window === "undefined") return;
window.dispatchEvent(new CustomEvent(DESKTOP_SHORTCUTS_CHANGED_EVENT, { detail: shortcuts }));
};
const normalizeKeyboardShortcutKey = (key: string) => {
if (/^[a-z]$/i.test(key)) return key.toUpperCase();
if (/^[0-9]$/.test(key)) return key;
if (["[", "]", ",", ".", "/", ";", "=", "-"].includes(key)) return key;
if (["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Home", "End", "PageUp", "PageDown"].includes(key)) {
return key;
}
return null;
};
export const desktopShortcutFromKeyboardEvent = (event: KeyboardEvent): string | null => {
if (!event.metaKey && !event.ctrlKey) return null;
const key = normalizeKeyboardShortcutKey(event.key);
if (!key) return null;
return ["Mod", event.shiftKey ? "Shift" : "", event.altKey ? "Alt" : "", key].filter(Boolean).join("+");
};
export const formatDesktopShortcut = (shortcut: string): string => {
const isMac = typeof navigator === "undefined" || /Mac|iPhone|iPad|iPod/i.test(navigator.platform);
const labels: Record<string, string> = {
Mod: isMac ? "⌘" : "Ctrl",
Shift: isMac ? "⇧" : "Shift",
Alt: isMac ? "⌥" : "Alt",
ArrowLeft: "←",
ArrowRight: "→",
ArrowUp: "↑",
ArrowDown: "↓",
};
const parts = shortcut.split("+").map((part) => labels[part] || part);
return isMac ? parts.join("") : parts.join("+");
};
export const readDesktopShortcutPreferences = (): DesktopShortcutPreferences => {
if (!isStorageAvailable()) return { ...DEFAULT_DESKTOP_SHORTCUTS };
try {
const raw = window.localStorage.getItem(DESKTOP_SHORTCUTS_KEY);
if (!raw) return { ...DEFAULT_DESKTOP_SHORTCUTS };
const parsed = JSON.parse(raw);
return isDesktopShortcutPreferences(parsed) ? { ...parsed } : { ...DEFAULT_DESKTOP_SHORTCUTS };
} catch {
return { ...DEFAULT_DESKTOP_SHORTCUTS };
}
};
export type SetDesktopShortcutResult =
| { ok: true; shortcuts: DesktopShortcutPreferences }
| { ok: false; reason: string; shortcuts: DesktopShortcutPreferences };
export const setDesktopShortcutPreference = (
action: DesktopShortcutAction,
shortcut: string,
): SetDesktopShortcutResult => {
const current = readDesktopShortcutPreferences();
const sanitized = sanitizeDesktopShortcut(shortcut);
if (!sanitized) {
return { ok: false, reason: "请使用包含 Command(或 Ctrl)的快捷键,且不要占用系统常用快捷键", shortcuts: current };
}
const conflict = DESKTOP_SHORTCUT_ACTIONS.find((item) => item !== action && current[item] === sanitized);
if (conflict) {
return { ok: false, reason: "该快捷键已被其他标签操作使用", shortcuts: current };
}
const shortcuts = { ...current, [action]: sanitized };
writeDesktopShortcutPreferences(shortcuts);
emitDesktopShortcutPreferences(shortcuts);
return { ok: true, shortcuts };
};
export const resetDesktopShortcutPreferences = (): DesktopShortcutPreferences => {
const shortcuts = { ...DEFAULT_DESKTOP_SHORTCUTS };
writeDesktopShortcutPreferences(shortcuts);
emitDesktopShortcutPreferences(shortcuts);
return shortcuts;
};
export const resolveDesktopShortcutAction = (
event: KeyboardEvent,
shortcuts: DesktopShortcutPreferences = readDesktopShortcutPreferences(),
): DesktopShortcutAction | null => {
const captured = desktopShortcutFromKeyboardEvent(event);
if (!captured) return null;
return DESKTOP_SHORTCUT_ACTIONS.find((action) => shortcuts[action] === captured) || null;
};
export const readDesktopThemePreference = (): DesktopThemePreference => { export const readDesktopThemePreference = (): DesktopThemePreference => {
if (!isStorageAvailable()) return DEFAULT_DESKTOP_THEME; if (!isStorageAvailable()) return DEFAULT_DESKTOP_THEME;
return sanitizeDesktopThemePreference(window.localStorage.getItem(DESKTOP_THEME_KEY)); return sanitizeDesktopThemePreference(window.localStorage.getItem(DESKTOP_THEME_KEY));
+12
View File
@@ -10,17 +10,29 @@ export {
} from "./desktopServerConfig"; } from "./desktopServerConfig";
export { export {
DESKTOP_FAVORITE_ROUTES_KEY, DESKTOP_FAVORITE_ROUTES_KEY,
DEFAULT_DESKTOP_SHORTCUTS,
DESKTOP_SHORTCUTS_CHANGED_EVENT,
DESKTOP_SHORTCUTS_KEY,
DESKTOP_THEME_CHANGED_EVENT, DESKTOP_THEME_CHANGED_EVENT,
DESKTOP_THEME_KEY, DESKTOP_THEME_KEY,
applyDesktopThemePreference, applyDesktopThemePreference,
clearLegacyDesktopRouteHistoryPreference, clearLegacyDesktopRouteHistoryPreference,
desktopShortcutFromKeyboardEvent,
formatDesktopShortcut,
isDesktopFavoriteRoute, isDesktopFavoriteRoute,
readDesktopFavoriteRoutes, readDesktopFavoriteRoutes,
readDesktopShortcutPreferences,
readDesktopThemePreference, readDesktopThemePreference,
resetDesktopShortcutPreferences,
resolveDesktopShortcutAction,
setDesktopShortcutPreference,
setDesktopThemePreference, setDesktopThemePreference,
toggleDesktopFavoriteRoute, toggleDesktopFavoriteRoute,
type DesktopRoutePreference, type DesktopRoutePreference,
type DesktopShortcutAction,
type DesktopShortcutPreferences,
type DesktopThemePreference, type DesktopThemePreference,
type SetDesktopShortcutResult,
} from "./desktopUiPreferences"; } from "./desktopUiPreferences";
export { export {
DESKTOP_MENU_COMMAND_EVENT, DESKTOP_MENU_COMMAND_EVENT,
+190 -2
View File
@@ -122,6 +122,36 @@
</div> </div>
</section> </section>
<section v-else-if="activeSectionId === 'shortcuts'" key="shortcuts" class="preference-panel">
<div class="shortcut-settings">
<div class="shortcut-settings-head">
<div>
<div class="row-title">标签页导航</div>
<div class="row-desc">快捷键仅作用于当前激活标签点击快捷键后按下新的组合键</div>
</div>
<el-button size="small" @click="resetDesktopShortcuts">恢复默认</el-button>
</div>
<div class="shortcut-list">
<div v-for="item in shortcutDefinitions" :key="item.action" class="shortcut-row">
<div>
<div class="row-title">{{ item.label }}</div>
<div class="row-desc">{{ item.description }}</div>
</div>
<button
class="shortcut-recorder"
:class="{ capturing: capturingShortcutAction === item.action }"
type="button"
@click="startDesktopShortcutCapture($event, item.action)"
>
<kbd>{{ formatDesktopShortcut(desktopShortcuts[item.action]) }}</kbd>
<span>{{ capturingShortcutAction === item.action ? "请按组合键" : "点击修改" }}</span>
</button>
</div>
</div>
</div>
</section>
<section v-else-if="activeSectionId === 'notifications'" key="notifications" class="preference-panel"> <section v-else-if="activeSectionId === 'notifications'" key="notifications" class="preference-panel">
<div class="preference-row"> <div class="preference-row">
<div> <div>
@@ -189,24 +219,31 @@
import { computed, onBeforeUnmount, onMounted, ref, type Component } from "vue"; import { computed, onBeforeUnmount, onMounted, ref, type Component } from "vue";
import { useRouter } from "vue-router"; import { useRouter } from "vue-router";
import { ElMessage, ElMessageBox } from "element-plus"; import { ElMessage, ElMessageBox } from "element-plus";
import { Bell, Close, Download, InfoFilled, Link, Monitor, Moon, Sunny } from "@element-plus/icons-vue"; import { Bell, Close, Download, InfoFilled, Key, Link, Monitor, Moon, Sunny } from "@element-plus/icons-vue";
import { import {
getDesktopNotificationSubscription, getDesktopNotificationSubscription,
setDesktopNotificationSubscription, setDesktopNotificationSubscription,
} from "../api/desktopNotifications"; } from "../api/desktopNotifications";
import { import {
clientRuntime, clientRuntime,
desktopShortcutFromKeyboardEvent,
formatDesktopShortcut,
getAppMetadata, getAppMetadata,
getDesktopServerUrl, getDesktopServerUrl,
getNotificationPermission, getNotificationPermission,
isDesktopUpdaterAvailable, isDesktopUpdaterAvailable,
normalizeDesktopServerUrl, normalizeDesktopServerUrl,
readDesktopShortcutPreferences,
readDesktopThemePreference, readDesktopThemePreference,
requestNotificationPermission, requestNotificationPermission,
resetDesktopShortcutPreferences,
setDesktopShortcutPreference,
setDesktopServerUrl, setDesktopServerUrl,
setDesktopThemePreference, setDesktopThemePreference,
showSystemNotificationProbe, showSystemNotificationProbe,
type DesktopThemePreference, type DesktopThemePreference,
type DesktopShortcutAction,
type DesktopShortcutPreferences,
type NotificationPermissionState, type NotificationPermissionState,
} from "../runtime"; } from "../runtime";
import { import {
@@ -227,7 +264,7 @@ const emit = defineEmits<{
const router = useRouter(); const router = useRouter();
const auth = useAuthStore(); const auth = useAuthStore();
const studyStore = useStudyStore(); const studyStore = useStudyStore();
type PreferenceSectionId = "connection" | "appearance" | "notifications" | "updates" | "diagnostics"; type PreferenceSectionId = "connection" | "appearance" | "shortcuts" | "notifications" | "updates" | "diagnostics";
const preferenceSections: Array<{ const preferenceSections: Array<{
id: PreferenceSectionId; id: PreferenceSectionId;
@@ -237,6 +274,7 @@ const preferenceSections: Array<{
}> = [ }> = [
{ id: "connection", label: "连接", description: "服务器入口与在线状态", icon: Link }, { id: "connection", label: "连接", description: "服务器入口与在线状态", icon: Link },
{ id: "appearance", label: "外观", description: "主题与界面偏好", icon: Monitor }, { id: "appearance", label: "外观", description: "主题与界面偏好", icon: Monitor },
{ id: "shortcuts", label: "快捷键", description: "当前标签的导航与刷新操作", icon: Key },
{ id: "notifications", label: "通知", description: "系统通知权限与投递状态", icon: Bell }, { id: "notifications", label: "通知", description: "系统通知权限与投递状态", icon: Bell },
{ id: "updates", label: "更新", description: "桌面端签名更新与安装状态", icon: Download }, { id: "updates", label: "更新", description: "桌面端签名更新与安装状态", icon: Download },
{ id: "diagnostics", label: "诊断信息", description: "客户端版本、平台与能力", icon: InfoFilled }, { id: "diagnostics", label: "诊断信息", description: "客户端版本、平台与能力", icon: InfoFilled },
@@ -267,6 +305,9 @@ const desktopNotificationLoading = ref(false);
const desktopNotificationTestLoading = ref(false); const desktopNotificationTestLoading = ref(false);
const desktopUpdateChecking = ref(false); const desktopUpdateChecking = ref(false);
const desktopTheme = ref<DesktopThemePreference>(readDesktopThemePreference()); const desktopTheme = ref<DesktopThemePreference>(readDesktopThemePreference());
const desktopShortcuts = ref<DesktopShortcutPreferences>(readDesktopShortcutPreferences());
const capturingShortcutAction = ref<DesktopShortcutAction | null>(null);
const shortcutCaptureElement = ref<HTMLElement | null>(null);
const notificationPermission = ref<NotificationPermissionState>("unsupported"); const notificationPermission = ref<NotificationPermissionState>("unsupported");
const desktopUpdateStatus = ref<DesktopUpdateStatusSnapshot>(getDesktopUpdateStatus()); const desktopUpdateStatus = ref<DesktopUpdateStatusSnapshot>(getDesktopUpdateStatus());
let updateStatusUnlisten: (() => void) | undefined; let updateStatusUnlisten: (() => void) | undefined;
@@ -275,6 +316,15 @@ const themeOptions = [
{ value: "light" as const, label: "明亮", icon: Sunny }, { value: "light" as const, label: "明亮", icon: Sunny },
{ value: "dark" as const, label: "暗黑", icon: Moon }, { value: "dark" as const, label: "暗黑", icon: Moon },
]; ];
const shortcutDefinitions: Array<{
action: DesktopShortcutAction;
label: string;
description: string;
}> = [
{ action: "back", label: "后退", description: "返回当前标签的上一页面" },
{ action: "forward", label: "前进", description: "前往当前标签的下一页面" },
{ action: "refresh", label: "刷新", description: "重新加载当前标签的数据" },
];
const HEALTH_TIMEOUT_MS = 10_000; const HEALTH_TIMEOUT_MS = 10_000;
const clientMetadataRows = computed(() => [ const clientMetadataRows = computed(() => [
@@ -645,6 +695,59 @@ const setTheme = (theme: DesktopThemePreference) => {
desktopTheme.value = setDesktopThemePreference(theme); desktopTheme.value = setDesktopThemePreference(theme);
}; };
const clearDesktopShortcutCapture = () => {
capturingShortcutAction.value = null;
shortcutCaptureElement.value = null;
};
const startDesktopShortcutCapture = (event: MouseEvent, action: DesktopShortcutAction) => {
event.preventDefault();
event.stopPropagation();
capturingShortcutAction.value = action;
shortcutCaptureElement.value = event.currentTarget as HTMLElement | null;
shortcutCaptureElement.value?.focus();
};
const captureDesktopShortcut = (event: KeyboardEvent) => {
const action = capturingShortcutAction.value;
if (!action) return;
event.preventDefault();
event.stopPropagation();
event.stopImmediatePropagation();
if (event.key === "Escape") {
clearDesktopShortcutCapture();
return;
}
const shortcut = desktopShortcutFromKeyboardEvent(event);
if (!shortcut) {
if (!["Meta", "Control", "Shift", "Alt"].includes(event.key)) {
ElMessage.warning("请按下包含 Command(或 Ctrl)的组合键");
}
return;
}
const result = setDesktopShortcutPreference(action, shortcut);
if (!result.ok) {
ElMessage.warning(result.reason);
return;
}
desktopShortcuts.value = result.shortcuts;
ElMessage.success("快捷键已更新");
clearDesktopShortcutCapture();
};
const cancelDesktopShortcutCaptureOnPointerDown = (event: PointerEvent) => {
if (!capturingShortcutAction.value) return;
const target = event.target;
if (target instanceof Node && shortcutCaptureElement.value?.contains(target)) return;
clearDesktopShortcutCapture();
};
const resetDesktopShortcuts = () => {
desktopShortcuts.value = resetDesktopShortcutPreferences();
clearDesktopShortcutCapture();
ElMessage.success("快捷键已恢复默认");
};
const copyClientMetadata = async () => { const copyClientMetadata = async () => {
const text = clientMetadataRows.value.map((row) => `${row.label}: ${row.value}`).join("\n"); const text = clientMetadataRows.value.map((row) => `${row.label}: ${row.value}`).join("\n");
if (!navigator.clipboard?.writeText) { if (!navigator.clipboard?.writeText) {
@@ -656,6 +759,8 @@ const copyClientMetadata = async () => {
}; };
onMounted(() => { onMounted(() => {
window.addEventListener("keydown", captureDesktopShortcut, { capture: true });
window.addEventListener("pointerdown", cancelDesktopShortcutCaptureOnPointerDown, { capture: true });
updateStatusUnlisten = listenDesktopUpdateStatus((status) => { updateStatusUnlisten = listenDesktopUpdateStatus((status) => {
desktopUpdateStatus.value = status; desktopUpdateStatus.value = status;
}); });
@@ -663,6 +768,8 @@ onMounted(() => {
}); });
onBeforeUnmount(() => { onBeforeUnmount(() => {
window.removeEventListener("keydown", captureDesktopShortcut, { capture: true });
window.removeEventListener("pointerdown", cancelDesktopShortcutCaptureOnPointerDown, { capture: true });
clearConnectionPendingTimer(); clearConnectionPendingTimer();
updateStatusUnlisten?.(); updateStatusUnlisten?.();
}); });
@@ -983,6 +1090,7 @@ h3 {
.preferences-panel-enter-active .connection-alert, .preferences-panel-enter-active .connection-alert,
.preferences-panel-enter-active .connection-diagnostic, .preferences-panel-enter-active .connection-diagnostic,
.preferences-panel-enter-active .preference-row, .preferences-panel-enter-active .preference-row,
.preferences-panel-enter-active .shortcut-settings,
.preferences-panel-enter-active .metadata-panel { .preferences-panel-enter-active .metadata-panel {
animation: preference-card-rise 220ms cubic-bezier(0.2, 0.8, 0.2, 1) both; animation: preference-card-rise 220ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
} }
@@ -1004,6 +1112,7 @@ h3 {
* ===================================================== */ * ===================================================== */
.server-overview, .server-overview,
.preference-row, .preference-row,
.shortcut-settings,
.metadata-panel { .metadata-panel {
border: 1px solid var(--pref-border-card); border: 1px solid var(--pref-border-card);
border-radius: 10px; border-radius: 10px;
@@ -1178,6 +1287,73 @@ h3 {
flex-shrink: 0; flex-shrink: 0;
} }
/* =====================================================
* 快捷键
* ===================================================== */
.shortcut-settings {
overflow: hidden;
}
.shortcut-settings-head,
.shortcut-row {
display: grid;
grid-template-columns: minmax(0, 1fr) auto;
align-items: center;
gap: 18px;
padding: 14px 16px;
}
.shortcut-settings-head {
border-bottom: 1px solid var(--pref-border);
background: #f8fafc;
}
.shortcut-list {
display: grid;
}
.shortcut-row + .shortcut-row {
border-top: 1px solid var(--pref-border);
}
.shortcut-recorder {
appearance: none;
display: grid;
justify-items: end;
min-width: 126px;
gap: 3px;
padding: 7px 9px;
border: 1px solid var(--pref-border-card);
border-radius: 8px;
background: #f8fafc;
color: var(--pref-text-secondary);
cursor: pointer;
font: inherit;
transition: border-color 140ms ease, background-color 140ms ease, box-shadow 140ms ease;
}
.shortcut-recorder:hover,
.shortcut-recorder:focus-visible,
.shortcut-recorder.capturing {
border-color: var(--pref-accent);
background: var(--pref-accent-light);
box-shadow: 0 0 0 3px rgba(30, 77, 130, 0.1);
outline: none;
}
.shortcut-recorder kbd {
color: var(--pref-text-primary);
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
font-size: 13px;
font-weight: 750;
}
.shortcut-recorder span {
color: var(--pref-text-muted);
font-size: 10px;
font-weight: 600;
}
/* ===================================================== /* =====================================================
* 主题切换器 * 主题切换器
* ===================================================== */ * ===================================================== */
@@ -1349,6 +1525,7 @@ code {
:global([data-ctms-theme="dark"] .desktop-preferences .server-config-form), :global([data-ctms-theme="dark"] .desktop-preferences .server-config-form),
:global([data-ctms-theme="dark"] .desktop-preferences .connection-diagnostic), :global([data-ctms-theme="dark"] .desktop-preferences .connection-diagnostic),
:global([data-ctms-theme="dark"] .desktop-preferences .preference-row), :global([data-ctms-theme="dark"] .desktop-preferences .preference-row),
:global([data-ctms-theme="dark"] .desktop-preferences .shortcut-settings),
:global([data-ctms-theme="dark"] .desktop-preferences .metadata-panel) { :global([data-ctms-theme="dark"] .desktop-preferences .metadata-panel) {
border-color: var(--pref-border-card); border-color: var(--pref-border-card);
background: var(--pref-bg-card); background: var(--pref-bg-card);
@@ -1388,6 +1565,17 @@ code {
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
} }
:global([data-ctms-theme="dark"] .desktop-preferences .shortcut-settings-head),
:global([data-ctms-theme="dark"] .desktop-preferences .shortcut-recorder) {
background: #101827;
}
:global([data-ctms-theme="dark"] .desktop-preferences .shortcut-recorder:hover),
:global([data-ctms-theme="dark"] .desktop-preferences .shortcut-recorder:focus-visible),
:global([data-ctms-theme="dark"] .desktop-preferences .shortcut-recorder.capturing) {
background: var(--pref-accent-light);
}
:global([data-ctms-theme="dark"] .desktop-preferences .server-status-dot.connected) { :global([data-ctms-theme="dark"] .desktop-preferences .server-status-dot.connected) {
box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.2); box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.2);
} }
+35 -35
View File
@@ -279,9 +279,9 @@ onMounted(() => {
flex-direction: column; flex-direction: column;
justify-content: space-between; justify-content: space-between;
padding: 40px 28px; padding: 40px 28px;
background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%); background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
border-right: 1px solid rgba(255, 255, 255, 0.05); border-right: 1px solid #e2e8f0;
box-shadow: 10px 0 40px rgba(15, 23, 42, 0.15); box-shadow: 6px 0 30px rgba(15, 23, 42, 0.02);
} }
/* 顶部品牌与Logo */ /* 顶部品牌与Logo */
@@ -298,19 +298,19 @@ onMounted(() => {
justify-content: center; justify-content: center;
width: 44px; width: 44px;
height: 44px; height: 44px;
border: 1px solid rgba(255, 255, 255, 0.15); border: 1px solid rgba(59, 130, 246, 0.1);
border-radius: 10px; border-radius: 10px;
background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%); background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
color: #ffffff; color: #ffffff;
font-size: 13.5px; font-size: 13.5px;
font-weight: 900; font-weight: 900;
letter-spacing: 0.05em; letter-spacing: 0.05em;
box-shadow: 0 8px 20px rgba(37, 99, 235, 0.25); box-shadow: 0 8px 20px rgba(37, 99, 235, 0.18);
} }
.brand-text h1 { .brand-text h1 {
margin: 1px 0 0; margin: 1px 0 0;
color: #ffffff; color: #0f172a;
font-size: 17.5px; font-size: 17.5px;
font-weight: 800; font-weight: 800;
letter-spacing: -0.02em; letter-spacing: -0.02em;
@@ -318,14 +318,14 @@ onMounted(() => {
.brand-kicker { .brand-kicker {
display: block; display: block;
color: rgba(147, 197, 253, 0.65); color: #2563eb;
font-size: 9.5px; font-size: 9.5px;
font-weight: 800; font-weight: 800;
letter-spacing: 0.1em; letter-spacing: 0.1em;
text-transform: uppercase; text-transform: uppercase;
} }
/* 个人信息卡片(色拟物化) */ /* 个人信息卡片(色拟物化) */
.sidebar-account { .sidebar-account {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@@ -333,9 +333,9 @@ onMounted(() => {
text-align: center; text-align: center;
padding: 24px 20px; padding: 24px 20px;
border-radius: 16px; border-radius: 16px;
background: rgba(255, 255, 255, 0.03); background: #ffffff;
border: 1px solid rgba(255, 255, 255, 0.05); border: 1px solid rgba(226, 232, 240, 0.9);
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05); box-shadow: 0 4px 16px rgba(15, 23, 42, 0.02);
} }
.avatar-wrapper { .avatar-wrapper {
@@ -354,7 +354,7 @@ onMounted(() => {
color: #ffffff; color: #ffffff;
font-size: 21px; font-size: 21px;
font-weight: 800; font-weight: 800;
box-shadow: 0 8px 24px rgba(29, 78, 216, 0.3); box-shadow: 0 8px 24px rgba(29, 78, 216, 0.15);
} }
.status-dot-active { .status-dot-active {
@@ -363,7 +363,7 @@ onMounted(() => {
right: -2px; right: -2px;
width: 12px; width: 12px;
height: 12px; height: 12px;
border: 2.5px solid #1e293b; border: 2.5px solid #ffffff;
border-radius: 50%; border-radius: 50%;
background: #10b981; background: #10b981;
} }
@@ -377,7 +377,7 @@ onMounted(() => {
} }
.account-details small { .account-details small {
color: rgba(255, 255, 255, 0.4); color: #64748b;
font-size: 9.5px; font-size: 9.5px;
font-weight: 800; font-weight: 800;
letter-spacing: 0.05em; letter-spacing: 0.05em;
@@ -385,16 +385,15 @@ onMounted(() => {
} }
.account-details strong { .account-details strong {
color: #ffffff; color: #0f172a;
font-size: 15px; font-size: 15px;
font-weight: 700; font-weight: 700;
} }
.account-email { .account-email {
color: #94a3b8; color: #475569;
font-size: 11.5px; font-size: 11.5px;
word-break: break-all; word-break: break-all;
opacity: 0.8;
} }
.logout-btn { .logout-btn {
@@ -405,10 +404,10 @@ onMounted(() => {
gap: 6px; gap: 6px;
width: 100%; width: 100%;
height: 36px; height: 36px;
border: 1px solid rgba(255, 255, 255, 0.1); border: 1px solid #cbd5e1;
border-radius: 10px; border-radius: 10px;
background: transparent; background: transparent;
color: rgba(255, 255, 255, 0.7); color: #475569;
font-size: 12.5px; font-size: 12.5px;
font-weight: 700; font-weight: 700;
cursor: pointer; cursor: pointer;
@@ -416,12 +415,12 @@ onMounted(() => {
} }
.logout-btn:hover { .logout-btn:hover {
background: rgba(239, 68, 68, 0.1); background: rgba(239, 68, 68, 0.05);
border-color: rgba(239, 68, 68, 0.2); border-color: rgba(239, 68, 68, 0.15);
color: #f87171; color: #ef4444;
} }
/* 常驻管理后台卡片(精致深黑流光) */ /* 常驻管理后台卡片(精致浅色流光) */
.sidebar-admin { .sidebar-admin {
width: 100%; width: 100%;
} }
@@ -433,13 +432,13 @@ onMounted(() => {
width: 100%; width: 100%;
overflow: hidden; overflow: hidden;
padding: 18px; padding: 18px;
border: 1px solid rgba(255, 255, 255, 0.08); border: 1px solid rgba(59, 130, 246, 0.12);
border-radius: 12px; border-radius: 12px;
background: linear-gradient(135deg, #090d16 0%, #111827 100%); background: linear-gradient(135deg, #ffffff 0%, #f0f7ff 100%);
color: #ffffff; color: #0f172a;
cursor: pointer; cursor: pointer;
text-align: left; text-align: left;
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3); box-shadow: 0 8px 20px rgba(37, 99, 235, 0.04);
transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1); transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
} }
@@ -450,15 +449,15 @@ onMounted(() => {
width: 120px; width: 120px;
height: 120px; height: 120px;
border-radius: 50%; border-radius: 50%;
background: rgba(59, 130, 246, 0.15); background: rgba(59, 130, 246, 0.06);
filter: blur(15px); filter: blur(15px);
pointer-events: none; pointer-events: none;
} }
.admin-action-card:hover { .admin-action-card:hover {
transform: translateY(-2px); transform: translateY(-2px);
border-color: rgba(59, 130, 246, 0.3); border-color: rgba(59, 130, 246, 0.28);
box-shadow: 0 16px 30px rgba(59, 130, 246, 0.12); box-shadow: 0 12px 28px rgba(37, 99, 235, 0.08);
} }
.admin-card-head { .admin-card-head {
@@ -475,8 +474,8 @@ onMounted(() => {
width: 32px; width: 32px;
height: 32px; height: 32px;
border-radius: 8px; border-radius: 8px;
background: rgba(59, 130, 246, 0.15); background: rgba(59, 130, 246, 0.08);
color: #3b82f6; color: #2563eb;
font-size: 16px; font-size: 16px;
} }
@@ -486,7 +485,7 @@ onMounted(() => {
} }
.admin-kicker { .admin-kicker {
color: rgba(59, 130, 246, 0.7); color: #2563eb;
font-size: 8.5px; font-size: 8.5px;
font-weight: 800; font-weight: 800;
letter-spacing: 0.05em; letter-spacing: 0.05em;
@@ -494,13 +493,14 @@ onMounted(() => {
} }
.admin-text-box strong { .admin-text-box strong {
color: #0f172a;
font-size: 13.5px; font-size: 13.5px;
font-weight: 700; font-weight: 700;
} }
.admin-desc { .admin-desc {
margin: 0 0 12px; margin: 0 0 12px;
color: #64748b; color: #475569;
font-size: 11px; font-size: 11px;
line-height: 1.4; line-height: 1.4;
} }
@@ -509,7 +509,7 @@ onMounted(() => {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
color: #3b82f6; color: #2563eb;
font-size: 11.5px; font-size: 11.5px;
font-weight: 700; font-weight: 700;
} }
@@ -1,41 +0,0 @@
<template>
<div class="redirecting ctms-page-shell page--flush">
<section class="unified-action-bar bar--flush">
<div class="redirecting-title">{{ TEXT.menu.fileVersionManagement }}</div>
</section>
<section class="unified-shell">
<section class="unified-section section--flush">
<el-empty :description="`${TEXT.common.loading}...`" />
</section>
</section>
</div>
</template>
<script setup lang="ts">
import { onMounted } from "vue";
import { useRouter } from "vue-router";
import { useStudyStore } from "../../store/study";
import { TEXT } from "../../locales";
const router = useRouter();
const study = useStudyStore();
onMounted(() => {
const currentStudy = study.currentStudy?.id;
if (currentStudy) {
router.replace(`/trial/${currentStudy}/documents`);
}
});
</script>
<style scoped>
.redirecting {
min-height: 180px;
}
.redirecting-title {
font-size: 15px;
font-weight: 700;
color: var(--ctms-text-main);
}
</style>
@@ -38,4 +38,18 @@ describe("MaterialEquipment desktop list workflow", () => {
expect(source).toContain("if (!isDesktop || !row?.id) return;"); expect(source).toContain("if (!isDesktop || !row?.id) return;");
expect(source).toContain('v-if="!isDesktop && (canUpdate || canDelete)"'); expect(source).toContain('v-if="!isDesktop && (canUpdate || canDelete)"');
}); });
it("aligns the desktop preview pane with the drug shipment preview layout", () => {
const source = readSource();
expect(source).toContain("grid-template-columns: minmax(0, 1fr) 316px;");
expect(source).toContain(".equipment-preview-pane");
expect(source).toContain("background: #f8fafc;");
expect(source).toContain("grid-template-columns: 78px minmax(0, 1fr);");
expect(source).toContain("gap: 10px 12px;");
expect(source).toContain("font-weight: 650;");
expect(source).not.toContain("float: left;");
expect(source).not.toContain("border-radius: 10px;");
expect(source).not.toContain("box-shadow: 0 1px 4px rgba(15, 23, 42, 0.05);");
});
}); });
+62 -55
View File
@@ -117,9 +117,6 @@
</div> </div>
</template> </template>
<div v-else class="preview-empty"> <div v-else class="preview-empty">
<div class="empty-icon">
<svg width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M8 6h13"/><path d="M8 12h13"/><path d="M8 18h13"/><path d="M3 6h.01"/><path d="M3 12h.01"/><path d="M3 18h.01"/></svg>
</div>
<span>选择一行查看详情摘要</span> <span>选择一行查看详情摘要</span>
</div> </div>
</aside> </aside>
@@ -725,7 +722,7 @@ onBeforeUnmount(() => {
.equipment-workbench.is-desktop { .equipment-workbench.is-desktop {
display: grid; display: grid;
grid-template-columns: minmax(0, 1fr) 304px; grid-template-columns: minmax(0, 1fr) 316px;
/* 桌面端:不限定固定高度,由父容器 flex 撑满 */ /* 桌面端:不限定固定高度,由父容器 flex 撑满 */
flex: 1; flex: 1;
min-height: 0; min-height: 0;
@@ -753,10 +750,9 @@ onBeforeUnmount(() => {
min-width: 0; min-width: 0;
min-height: 0; min-height: 0;
flex-direction: column; flex-direction: column;
gap: 14px; gap: 16px;
padding: 16px; padding: 16px;
background: linear-gradient(180deg, #f5f8ff 0%, #eef3fb 100%); background: #f8fafc;
border-left: 1px solid rgba(79, 126, 207, 0.1);
} }
.equipment-table { .equipment-table {
@@ -852,70 +848,46 @@ onBeforeUnmount(() => {
align-items: flex-start; align-items: flex-start;
justify-content: space-between; justify-content: space-between;
gap: 12px; gap: 12px;
padding-bottom: 14px;
border-bottom: 1px solid rgba(79, 126, 207, 0.12);
} }
.preview-kicker { .preview-kicker {
display: inline-flex; margin-bottom: 5px;
align-items: center; color: #6b7e95;
gap: 5px; font-size: 11px;
color: #4f7ecf;
font-size: 10px;
font-weight: 800; font-weight: 800;
text-transform: uppercase;
letter-spacing: 0.08em;
background: rgba(79, 126, 207, 0.1);
padding: 2px 8px;
border-radius: 20px;
} }
.preview-title { .preview-title {
margin-top: 8px; display: -webkit-box;
color: #0f172a; overflow: hidden;
color: #142033;
font-size: 17px; font-size: 17px;
font-weight: 800; font-weight: 800;
word-break: break-word; line-height: 1.35;
letter-spacing: -0.01em; -webkit-box-orient: vertical;
line-height: 1.3; -webkit-line-clamp: 3;
} }
.preview-list { .preview-list {
display: block; display: grid;
grid-template-columns: 78px minmax(0, 1fr);
gap: 10px 12px;
margin: 0; margin: 0;
border: 1px solid rgba(79, 126, 207, 0.1);
border-radius: 10px;
overflow: hidden;
background: #fff;
box-shadow: 0 1px 4px rgba(15, 23, 42, 0.05);
} }
/* dt/dd float 布局:dt 左浮动作为标签列,dd 跟随在右侧 */
.preview-list dt { .preview-list dt {
float: left; color: #7b8da3;
clear: left; font-size: 12px;
width: 64px;
padding: 9px 6px 9px 14px;
color: #7a8ca8;
font-size: 11px;
font-weight: 700; font-weight: 700;
letter-spacing: 0.02em;
line-height: 1.5;
} }
.preview-list dd { .preview-list dd {
margin-left: 0;
padding: 9px 14px 9px 78px;
border-bottom: 1px solid rgba(79, 126, 207, 0.07);
color: #1a2540;
font-size: 13px;
font-weight: 700;
overflow-wrap: anywhere;
min-width: 0; min-width: 0;
} margin: 0;
overflow-wrap: anywhere;
.preview-list dd:last-child { color: #223349;
border-bottom: none; font-size: 13px;
font-weight: 650;
} }
.preview-actions { .preview-actions {
@@ -923,18 +895,16 @@ onBeforeUnmount(() => {
flex-wrap: wrap; flex-wrap: wrap;
gap: 8px; gap: 8px;
margin-top: auto; margin-top: auto;
padding-top: 4px;
} }
.preview-empty { .preview-empty {
min-height: 320px;
display: flex; display: flex;
flex-direction: column; min-height: 180px;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
gap: 12px; color: #7b8da3;
color: #94a3b8;
font-size: 13px; font-size: 13px;
font-weight: 700;
text-align: center; text-align: center;
} }
@@ -1163,4 +1133,41 @@ onBeforeUnmount(() => {
width: 100%; width: 100%;
} }
} }
:global([data-ctms-theme="dark"] .equipment-page--desktop .table-card) {
background: #172033;
}
:global([data-ctms-theme="dark"] .equipment-page--desktop .equipment-preview-pane) {
border-color: #26364a;
background: #111827;
}
:global([data-ctms-theme="dark"] .equipment-page--desktop .preview-title),
:global([data-ctms-theme="dark"] .equipment-page--desktop .preview-list dd) {
color: #f8fafc;
}
:global([data-ctms-theme="dark"] .equipment-page--desktop .preview-kicker),
:global([data-ctms-theme="dark"] .equipment-page--desktop .preview-list dt),
:global([data-ctms-theme="dark"] .equipment-page--desktop .preview-empty) {
color: #94a3b8;
}
:global([data-ctms-theme="dark"] .equipment-page--desktop .equipment-context-menu) {
border-color: #334155;
background: #172033;
}
:global([data-ctms-theme="dark"] .equipment-page--desktop .equipment-context-menu button) {
color: #dbe5f1;
}
:global([data-ctms-theme="dark"] .equipment-page--desktop .equipment-context-menu button:hover:not(:disabled)) {
background: #243247;
}
:global([data-ctms-theme="dark"] .equipment-page--desktop .equipment-context-menu button.danger) {
color: #fca5a5;
}
</style> </style>