明树Git Lab
Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
J
jt_front
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
jt_front
Commits
6c6712a9
Commit
6c6712a9
authored
Mar 23, 2026
by
zhanghan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
历史路由处理
parent
b7568991
Pipeline
#108701
passed with stage
in 20 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
29 deletions
+57
-29
MainLayout.vue
src/layouts/MainLayout.vue
+57
-29
No files found.
src/layouts/MainLayout.vue
View file @
6c6712a9
...
...
@@ -63,9 +63,9 @@
>
<el-tab-pane
v-for=
"view in visitedViews"
:key=
"view.
p
ath"
:key=
"view.
fullP
ath"
:label=
"view.title"
:name=
"view.
p
ath"
:name=
"view.
fullP
ath"
/>
</el-tabs>
</div>
...
...
@@ -114,56 +114,84 @@ const router = useRouter();
const
route
=
useRoute
();
// ========== 路由标签页相关 ==========
const
visitedViews
=
ref
([]);
// 已访问的路由列表
const
activePath
=
ref
(
""
);
// 当前激活的路由路径
// 添加路由到已访问列表
const
visitedViews
=
ref
([]);
const
activePath
=
ref
(
""
);
// 添加路由到已访问列表(合并同路径不同参数的路由)
const
addView
=
(
view
)
=>
{
// 检查路由是否已存在
const
index
=
visitedViews
.
value
.
findIndex
((
v
)
=>
v
.
path
===
view
.
path
);
if
(
index
===
-
1
)
{
// 不存在则添加,优先使用 title,其次 meta.title,最后 name
const
basePath
=
view
.
path
;
const
fullPath
=
view
.
fullPath
||
view
.
path
;
// 1. 先找同基础路径的路由
const
samePathIndex
=
visitedViews
.
value
.
findIndex
(
(
v
)
=>
v
.
path
===
basePath
,
);
if
(
samePathIndex
!==
-
1
)
{
// 2. 如果存在同路径路由,更新它的参数和fullPath(不新增)
visitedViews
.
value
[
samePathIndex
]
=
{
...
visitedViews
.
value
[
samePathIndex
],
fullPath
:
fullPath
,
query
:
{
...
view
.
query
},
params
:
{
...
view
.
params
},
};
}
else
{
// 3. 不存在则新增
visitedViews
.
value
.
push
({
path
:
view
.
path
,
path
:
basePath
,
fullPath
:
fullPath
,
query
:
{
...
view
.
query
},
params
:
{
...
view
.
params
},
title
:
view
.
title
||
view
.
meta
?.
title
||
view
.
name
||
"未命名"
,
});
console
.
log
(
visitedViews
,
"visitedViewsvisitedViews"
);
}
// 设置当前激活的路由
activePath
.
value
=
view
.
path
;
// 更新激活状态
activePath
.
value
=
fullPath
;
};
// 点击标签切换路由
// 点击标签切换路由
(优化:确保切换时参数正确)
const
handleTabClick
=
(
tab
)
=>
{
const
path
=
tab
.
paneName
;
if
(
path
!==
route
.
path
)
{
router
.
push
(
path
);
const
fullPath
=
tab
.
paneName
;
if
(
fullPath
!==
route
.
fullPath
)
{
const
targetView
=
visitedViews
.
value
.
find
((
v
)
=>
v
.
fullPath
===
fullPath
);
if
(
targetView
)
{
router
.
push
({
path
:
targetView
.
path
,
query
:
targetView
.
query
,
params
:
targetView
.
params
,
});
}
else
{
// 备用方案:直接通过fullPath跳转
router
.
push
(
fullPath
);
}
}
};
// 关闭标签
const
handleTabRemove
=
(
targetPath
)
=>
{
const
index
=
visitedViews
.
value
.
findIndex
((
v
)
=>
v
.
path
===
targetPath
);
if
(
index
!==
-
1
)
{
// 移除路由
visitedViews
.
value
.
splice
(
index
,
1
)
;
// 关闭标签
(逻辑调整:删除同路径的所有记录)
const
handleTabRemove
=
(
target
Full
Path
)
=>
{
const
targetView
=
visitedViews
.
value
.
find
(
(
v
)
=>
v
.
fullPath
===
targetFullPath
,
);
if
(
!
targetView
)
return
;
// 如果关闭的是当前路由,则跳转到上一个路由
if
(
targetPath
===
route
.
path
)
{
// 根据基础路径删除(确保同路径的标签只删一次)
const
index
=
visitedViews
.
value
.
findIndex
((
v
)
=>
v
.
path
===
targetView
.
path
);
if
(
index
!==
-
1
)
{
// 跳转逻辑保持不变
if
(
targetFullPath
===
route
.
fullPath
)
{
if
(
visitedViews
.
value
.
length
>
0
)
{
// 跳转到相邻路由(优先后面的,如果没有则前面的)
const
nextView
=
visitedViews
.
value
[
index
]
||
visitedViews
.
value
[
index
-
1
];
if
(
nextView
)
{
router
.
push
(
nextView
.
p
ath
);
router
.
push
(
nextView
.
fullP
ath
);
}
}
else
{
// 如果没有其他路由,跳转到首页
router
.
push
(
"/"
);
}
}
}
};
// ========== 路由标签页相关结束 ==========
// 获取资源库数据
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment