feat: 项目详情路由调整

This commit is contained in:
huangchenhao 2026-04-09 18:27:00 +08:00
parent 17b0871ab5
commit 0a062cb564

View File

@ -1,21 +1,19 @@
<template> <template>
<div class="breadcrumb-container"> <div class="breadcrumb-container">
<el-breadcrumb separator="/"> <el-breadcrumb separator="/">
<el-breadcrumb-item <el-breadcrumb-item v-for="(item, index) in breadcrumbList" :key="index"
v-for="(item, index) in breadcrumbList" :class="{ 'is-link': index < breadcrumbList.length - 1 }" @click="handleBreadcrumbClick(item, index)">
:key="index"
:class="{ 'is-link': index < breadcrumbList.length - 1 }"
@click="handleBreadcrumbClick(item, index)"
>
{{ item.title }} {{ item.title }}
</el-breadcrumb-item> </el-breadcrumb-item>
</el-breadcrumb> </el-breadcrumb>
<!-- 关闭按钮组 --> <!-- 关闭按钮组 -->
<div class="breadcrumb-actions" v-if="breadcrumbList.length > 1"> <div class="breadcrumb-actions" v-if="breadcrumbList.length > 1">
<el-dropdown trigger="click" @command="handleCloseAction"> <el-dropdown trigger="click" @command="handleCloseAction">
<el-button type="text" size="small" class="close-btn"> <el-button type="text" size="small" class="close-btn">
<el-icon><Close /></el-icon> <el-icon>
<Close />
</el-icon>
关闭 关闭
</el-button> </el-button>
<template #dropdown> <template #dropdown>
@ -23,7 +21,8 @@
<el-dropdown-item command="close-current">关闭当前页</el-dropdown-item> <el-dropdown-item command="close-current">关闭当前页</el-dropdown-item>
<el-dropdown-item command="close-other" :disabled="breadcrumbList.length <= 2">关闭其他页</el-dropdown-item> <el-dropdown-item command="close-other" :disabled="breadcrumbList.length <= 2">关闭其他页</el-dropdown-item>
<el-dropdown-item command="close-left" :disabled="currentIndex === 0">关闭左侧</el-dropdown-item> <el-dropdown-item command="close-left" :disabled="currentIndex === 0">关闭左侧</el-dropdown-item>
<el-dropdown-item command="close-right" :disabled="currentIndex === breadcrumbList.length - 1">关闭右侧</el-dropdown-item> <el-dropdown-item command="close-right"
:disabled="currentIndex === breadcrumbList.length - 1">关闭右侧</el-dropdown-item>
<el-dropdown-item command="close-all" :disabled="breadcrumbList.length <= 1">全部关闭</el-dropdown-item> <el-dropdown-item command="close-all" :disabled="breadcrumbList.length <= 1">全部关闭</el-dropdown-item>
</el-dropdown-menu> </el-dropdown-menu>
</template> </template>
@ -56,7 +55,7 @@ const currentIndex = ref(0)
// //
const generateBreadcrumb = () => { const generateBreadcrumb = () => {
const matched = route.matched.filter(item => item.meta && item.meta.breadcrumb !== false) const matched = route.matched.filter(item => item.meta && item.meta.breadcrumb !== false)
// //
breadcrumbList.value = [ breadcrumbList.value = [
{ {
@ -65,9 +64,9 @@ const generateBreadcrumb = () => {
name: 'Home' name: 'Home'
} }
] ]
const currentPath = route.path const currentPath = route.path
// //
if (currentPath.includes('/ledgerManagement')) { if (currentPath.includes('/ledgerManagement')) {
// //
@ -77,7 +76,7 @@ const generateBreadcrumb = () => {
name: 'warningManagement', name: 'warningManagement',
meta: { title: '响应预警' } meta: { title: '响应预警' }
}) })
// //
breadcrumbList.value.push({ breadcrumbList.value.push({
title: '驻地台账', title: '驻地台账',
@ -94,7 +93,7 @@ const generateBreadcrumb = () => {
name: 'projectManagement', name: 'projectManagement',
meta: { title: '项目管理' } meta: { title: '项目管理' }
}) })
// //
breadcrumbList.value.push({ breadcrumbList.value.push({
title: '项目填报', title: '项目填报',
@ -102,15 +101,33 @@ const generateBreadcrumb = () => {
name: 'projectAdd', name: 'projectAdd',
meta: { title: '项目填报' } meta: { title: '项目填报' }
}) })
} else { } else if (currentPath.includes('/projectDetail')) {
//
//
breadcrumbList.value.push({
title: '项目管理',
path: '/projectManagement',
name: 'projectManagement',
meta: { title: '项目管理' }
})
//
breadcrumbList.value.push({
title: '项目详情',
path: currentPath,
name: 'projectDetail',
meta: { title: '项目详情' }
})
}
else {
// //
matched.forEach((record, index) => { matched.forEach((record, index) => {
// //
if (record.path === '/') return if (record.path === '/') return
if (record.meta && record.meta.title) { if (record.meta && record.meta.title) {
let fullPath = record.path let fullPath = record.path
// //
if (!fullPath.startsWith('/') && index > 0) { if (!fullPath.startsWith('/') && index > 0) {
const parentPath = breadcrumbList.value[breadcrumbList.value.length - 1]?.path || '' const parentPath = breadcrumbList.value[breadcrumbList.value.length - 1]?.path || ''
@ -118,7 +135,7 @@ const generateBreadcrumb = () => {
fullPath = parentPath + (parentPath.endsWith('/') ? '' : '/') + record.path fullPath = parentPath + (parentPath.endsWith('/') ? '' : '/') + record.path
} }
} }
breadcrumbList.value.push({ breadcrumbList.value.push({
title: record.meta.title, title: record.meta.title,
path: fullPath, path: fullPath,
@ -128,7 +145,7 @@ const generateBreadcrumb = () => {
} }
}) })
} }
// //
const currentIndexInList = breadcrumbList.value.findIndex(item => item.path === currentPath) const currentIndexInList = breadcrumbList.value.findIndex(item => item.path === currentPath)
currentIndex.value = currentIndexInList >= 0 ? currentIndexInList : breadcrumbList.value.length - 1 currentIndex.value = currentIndexInList >= 0 ? currentIndexInList : breadcrumbList.value.length - 1
@ -165,10 +182,10 @@ const handleCloseAction = (command) => {
// //
const closeCurrentPage = () => { const closeCurrentPage = () => {
if (breadcrumbList.value.length <= 1) return if (breadcrumbList.value.length <= 1) return
const currentPath = route.path const currentPath = route.path
const currentIndex = breadcrumbList.value.findIndex(item => item.path === currentPath) const currentIndex = breadcrumbList.value.findIndex(item => item.path === currentPath)
if (currentIndex > 0) { if (currentIndex > 0) {
// //
const prevPage = breadcrumbList.value[currentIndex - 1] const prevPage = breadcrumbList.value[currentIndex - 1]
@ -180,16 +197,16 @@ const closeCurrentPage = () => {
// //
const closeOtherPages = () => { const closeOtherPages = () => {
if (breadcrumbList.value.length <= 2) return if (breadcrumbList.value.length <= 2) return
const currentPath = route.path const currentPath = route.path
const currentItem = breadcrumbList.value.find(item => item.path === currentPath) const currentItem = breadcrumbList.value.find(item => item.path === currentPath)
if (currentItem) { if (currentItem) {
breadcrumbList.value = [ breadcrumbList.value = [
breadcrumbList.value[0], // breadcrumbList.value[0], //
currentItem currentItem
] ]
// //
emit('breadcrumb-change', breadcrumbList.value) emit('breadcrumb-change', breadcrumbList.value)
} }
@ -198,15 +215,15 @@ const closeOtherPages = () => {
// //
const closeLeftPages = () => { const closeLeftPages = () => {
if (currentIndex.value <= 1) return if (currentIndex.value <= 1) return
const currentItem = breadcrumbList.value[currentIndex.value] const currentItem = breadcrumbList.value[currentIndex.value]
breadcrumbList.value = [ breadcrumbList.value = [
breadcrumbList.value[0], // breadcrumbList.value[0], //
currentItem currentItem
] ]
// //
let targetPath = '/' let targetPath = '/'
if (currentItem.path !== '/') { if (currentItem.path !== '/') {
targetPath = currentItem.path targetPath = currentItem.path
} }
@ -216,9 +233,9 @@ const closeLeftPages = () => {
// //
const closeRightPages = () => { const closeRightPages = () => {
if (currentIndex.value >= breadcrumbList.value.length - 1) return if (currentIndex.value >= breadcrumbList.value.length - 1) return
breadcrumbList.value = breadcrumbList.value.slice(0, currentIndex.value + 1) breadcrumbList.value = breadcrumbList.value.slice(0, currentIndex.value + 1)
// //
const lastItem = breadcrumbList.value[breadcrumbList.value.length - 1] const lastItem = breadcrumbList.value[breadcrumbList.value.length - 1]
router.push(lastItem.path) router.push(lastItem.path)
@ -260,23 +277,23 @@ defineExpose({
:deep(.el-breadcrumb) { :deep(.el-breadcrumb) {
font-size: 14px; font-size: 14px;
.el-breadcrumb__item { .el-breadcrumb__item {
.el-breadcrumb__inner { .el-breadcrumb__inner {
color: #606266; color: #606266;
font-weight: 400; font-weight: 400;
&.is-link { &.is-link {
color: #409eff; color: #409eff;
cursor: pointer; cursor: pointer;
transition: color 0.3s; transition: color 0.3s;
&:hover { &:hover {
color: #66b1ff; color: #66b1ff;
} }
} }
} }
&:last-child .el-breadcrumb__inner { &:last-child .el-breadcrumb__inner {
color: #303133; color: #303133;
font-weight: 500; font-weight: 500;
@ -288,7 +305,7 @@ defineExpose({
.breadcrumb-actions { .breadcrumb-actions {
display: flex; display: flex;
align-items: center; align-items: center;
.close-btn { .close-btn {
display: flex; display: flex;
align-items: center; align-items: center;
@ -298,12 +315,12 @@ defineExpose({
padding: 4px 8px; padding: 4px 8px;
border-radius: 4px; border-radius: 4px;
transition: all 0.3s; transition: all 0.3s;
&:hover { &:hover {
background-color: #f5f7fa; background-color: #f5f7fa;
color: #409eff; color: #409eff;
} }
.el-icon { .el-icon {
font-size: 12px; font-size: 12px;
} }