Merge branch 'dev' into codex/desktop-ui-stabilization

# Conflicts:
#	frontend/src/views/admin/Projects.test.ts
#	frontend/src/views/admin/Projects.vue
This commit is contained in:
Cheng Zhou
2026-07-09 15:41:13 +08:00
16 changed files with 1459 additions and 194 deletions
@@ -70,6 +70,20 @@ describe("desktop layout shell", () => {
expect(navigation).toContain("export const getActiveLayoutPath");
});
it("keeps web project switching routed through the workbench entry", () => {
const webLayout = readWebLayoutSource();
expect(webLayout).toContain('class="workbench-return-button"');
expect(webLayout).toContain('await router.push("/workbench")');
expect(webLayout).toContain("const showAdminNavigation = computed(() => Boolean(auth.user) && (!study.currentStudy || isAdminContext.value))");
expect(webLayout).not.toContain("hasDropdown: true");
expect(webLayout).not.toContain("type: 'study'");
expect(webLayout).not.toContain('type: "study"');
expect(webLayout).not.toContain("`切换项目:${item.name}`");
expect(webLayout).not.toContain("study.setCurrentStudy(cmd.value)");
expect(webLayout).not.toContain('router.push("/project/overview");');
});
it("keeps desktop context labels and command entry points de-duplicated", () => {
const source = readDesktopLayoutSource();
+5 -71
View File
@@ -7,23 +7,8 @@
</div>
<template #dropdown>
<el-dropdown-menu class="study-dropdown">
<el-dropdown-item v-if="loading" disabled>
<el-icon><Loading /></el-icon>{{ TEXT.common.loading }}
</el-dropdown-item>
<el-dropdown-item v-else-if="!studies.length" disabled>{{ TEXT.common.empty.noData }}</el-dropdown-item>
<el-dropdown-item
v-for="item in studies"
:key="item.id"
:command="{ type: 'switch', study: item }"
:class="{ active: study.currentStudy?.id === item.id }"
>
<div class="study-item">
<div class="name">{{ item.name }}</div>
<div class="code">{{ item.code }}</div>
</div>
</el-dropdown-item>
<el-dropdown-item divided command="clear" class="danger-item">
<el-icon><Close /></el-icon>{{ TEXT.common.actions.exitProject }}
<el-dropdown-item command="workbench">
<el-icon><OfficeBuilding /></el-icon>返回工作台选择项目
</el-dropdown-item>
</el-dropdown-menu>
</template>
@@ -31,48 +16,20 @@
</template>
<script setup lang="ts">
import { onMounted, ref } from "vue";
import { useRouter } from "vue-router";
import { ElMessage } from "element-plus";
import { useStudyStore } from "../store/study";
import { fetchStudies } from "../api/studies";
import type { Study } from "../types/api";
import { OfficeBuilding, ArrowDown, Close, Loading } from "@element-plus/icons-vue";
import { OfficeBuilding, ArrowDown } from "@element-plus/icons-vue";
import { TEXT } from "../locales";
const router = useRouter();
const study = useStudyStore();
const studies = ref<Study[]>([]);
const loading = ref(false);
const loadStudies = async () => {
loading.value = true;
try {
const { data } = await fetchStudies();
studies.value = data.items || [];
} catch (e: any) {
ElMessage.error(e?.response?.data?.message || TEXT.common.messages.loadFailed);
} finally {
loading.value = false;
}
};
const onCommand = async (cmd: any) => {
if (cmd === "clear") {
if (cmd === "workbench") {
study.clearCurrentStudy();
router.push("/admin/projects");
return;
}
if (cmd?.type === "switch" && cmd.study) {
study.setCurrentStudy(cmd.study as Study);
await study.loadCurrentStudyPermissions().catch(() => {});
router.push("/project/overview");
await router.push("/workbench");
}
};
onMounted(() => {
loadStudies();
});
</script>
<style scoped>
@@ -119,27 +76,4 @@ onMounted(() => {
min-width: 220px;
}
.study-item {
display: flex;
flex-direction: column;
gap: 2px;
}
.study-item .name {
font-weight: 600;
color: var(--ctms-text-main);
}
.study-item .code {
font-size: 12px;
color: var(--ctms-text-secondary);
}
.active {
background-color: var(--ctms-primary-light);
}
.danger-item {
color: var(--ctms-danger);
}
</style>
+40 -42
View File
@@ -22,7 +22,7 @@
</el-menu-item>
</el-menu-item-group>
<el-menu-item-group v-if="auth.user" class="menu-group">
<el-menu-item-group v-if="showAdminNavigation" class="menu-group">
<template #title>
<span class="menu-divider">{{ TEXT.menu.admin }}</span>
</template>
@@ -141,25 +141,8 @@
<!-- 移入 Header 的面包屑 -->
<div v-if="breadcrumbs.length" class="header-breadcrumb">
<template v-for="(item, index) in breadcrumbs" :key="breadcrumbKey(item, index)">
<!-- 带下拉的选择器类型 -->
<el-dropdown v-if="item.hasDropdown" trigger="click" @command="handleBreadcrumbCommand">
<div class="breadcrumb-item-wrapper is-link is-study">
<span class="breadcrumb-item-text is-link-text">{{ item.label }}</span>
<el-icon class="breadcrumb-dropdown-icon"><ArrowDown /></el-icon>
</div>
<template #dropdown>
<el-dropdown-menu class="breadcrumb-dropdown-menu">
<template v-if="item.type === 'study'">
<el-dropdown-item v-for="s in studies" :key="s.id" :command="{ type: 'study', value: s }" :class="{ active: study.currentStudy?.id === s.id }">
{{ s.name }}
</el-dropdown-item>
</template>
</el-dropdown-menu>
</template>
</el-dropdown>
<!-- 同级导航下拉在同级模块/页面之间横跳 -->
<el-dropdown v-else-if="item.navDropdown && item.siblings?.length" trigger="click" :hide-on-click="true" @command="handleBreadcrumbCommand">
<el-dropdown v-if="item.navDropdown && item.siblings?.length" trigger="click" :hide-on-click="true" @command="handleBreadcrumbCommand">
<div class="breadcrumb-item-wrapper is-nav" :class="{ 'is-current': index === breadcrumbs.length - 1 }">
<span class="breadcrumb-item-text" :class="{ 'is-link-text': index < breadcrumbs.length - 1 }">{{ item.label }}</span>
<el-icon class="breadcrumb-dropdown-icon breadcrumb-nav-icon"><ArrowDown /></el-icon>
@@ -221,6 +204,11 @@
</div>
<div class="header-right">
<button v-if="study.currentStudy" class="workbench-return-button" type="button" @click="openWorkbenchEntry">
<el-icon><Suitcase /></el-icon>
<span>工作台</span>
</button>
<button v-if="isDesktop" class="desktop-command-trigger" type="button" @click="openCommandPalette">
<el-icon><Search /></el-icon>
<span>搜索命令</span>
@@ -332,6 +320,10 @@
</span>
<template #dropdown>
<el-dropdown-menu class="user-dropdown-menu">
<el-dropdown-item command="workbench">
<el-icon><Suitcase /></el-icon>
<span>工作台</span>
</el-dropdown-item>
<el-dropdown-item command="profile">
<el-icon><User /></el-icon>
<span>{{ TEXT.menu.profile }}</span>
@@ -498,6 +490,7 @@ const userDisplayInitial = computed(() => {
});
const isAdminContext = computed(() => route.path.startsWith("/admin"));
const showAdminNavigation = computed(() => Boolean(auth.user) && (!study.currentStudy || isAdminContext.value));
const canReadRiskIssueAes = computed(() => !isAdminContext.value && canAccessProjectPath("/risk-issues/sae"));
const canReadMonitoringIssues = computed(() => !isAdminContext.value && canAccessProjectPath("/risk-issues/monitoring-visits"));
const hasAnyRiskReminderAccess = computed(() => canReadRiskIssueAes.value || canReadMonitoringIssues.value);
@@ -792,19 +785,6 @@ const desktopCommands = computed<DesktopCommand[]>(() => {
},
}));
const projectCommands: DesktopCommand[] = studies.value.map((item) => ({
id: `study:${item.id}`,
title: `切换项目:${item.name}`,
group: "项目",
keywords: [item.name, item.project_no, item.protocol_no].filter(Boolean),
visible: Boolean(item?.id),
run: async () => {
study.setCurrentStudy(item);
await study.loadCurrentStudyPermissions().catch(() => {});
await router.push("/project/overview");
},
}));
return [
{
id: "desktop:refresh",
@@ -846,7 +826,6 @@ const desktopCommands = computed<DesktopCommand[]>(() => {
run: toggleCurrentFavorite,
},
...navigationCommands,
...projectCommands,
];
});
@@ -918,12 +897,10 @@ const breadcrumbs = computed(() => {
return items;
}
} else if (study.currentStudy) {
// 1. 项目名(可下拉切换项目)
// 项目内不提供横向切换项目;需要切换时先回工作台重新选择。
items.push({
label: (study.currentStudy.name || "").replace(/^示例项目[:]/, ''),
path: "/project/overview",
hasDropdown: true,
type: 'study'
});
// 3. 模块级面包屑:依据侧边栏导航树,顶级模块为二级,子菜单项为三级
@@ -1029,12 +1006,6 @@ const breadcrumbKey = (item: any, index: number) => {
const handleBreadcrumbCommand = async (cmd: any) => {
if (cmd.type === 'nav') {
if (cmd.value && cmd.value !== route.path) router.push(cmd.value);
return;
}
if (cmd.type === 'study') {
study.setCurrentStudy(cmd.value);
await study.loadCurrentStudyPermissions().catch(() => {});
router.push("/project/overview");
}
};
@@ -1099,6 +1070,11 @@ const logoutImmediately = async () => {
router.replace("/login");
};
const openWorkbenchEntry = async () => {
study.clearCurrentStudy();
await router.push("/workbench");
};
const onLogout = async () => {
if (loggingOut.value) return;
const confirmed = await ElMessageBox.confirm(
@@ -1158,6 +1134,8 @@ onBeforeUnmount(() => {
const onCommand = (cmd: string) => {
if (cmd === "logout") {
onLogout();
} else if (cmd === "workbench") {
void openWorkbenchEntry();
} else if (cmd === "profile") {
profileDialogVisible.value = true;
} else if (cmd === "desktopPreferences") {
@@ -1650,6 +1628,26 @@ useDesktopShortcuts(
flex-shrink: 0;
}
.workbench-return-button {
display: inline-flex;
align-items: center;
gap: 6px;
height: 32px;
padding: 0 10px;
border: 1px solid #c7d7ec;
border-radius: 8px;
background: #eff6ff;
color: #1d4ed8;
cursor: pointer;
font-size: 12px;
font-weight: 700;
}
.workbench-return-button:hover {
border-color: #93c5fd;
background: #dbeafe;
}
.desktop-command-trigger {
display: inline-grid;
grid-template-columns: auto minmax(0, auto) auto;