Skip to content

Commit e0c55f4

Browse files
perf: 完善useTagsView
1 parent 175abd0 commit e0c55f4

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

src/components/TagsView/src/TagsView.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { useTemplateRefsList } from '@vueuse/core'
1313
import { ElScrollbar } from 'element-plus'
1414
import { useScrollTo } from '@/hooks/event/useScrollTo'
1515
import { useTagsView } from '@/hooks/web/useTagsView'
16+
import { cloneDeep } from 'lodash-es'
1617
1718
const { getPrefixCls } = useDesign()
1819
@@ -50,7 +51,7 @@ const initTags = () => {
5051
for (const tag of unref(affixTagArr)) {
5152
// Must have tag name
5253
if (tag.name) {
53-
tagsViewStore.addVisitedView(tag)
54+
tagsViewStore.addVisitedView(cloneDeep(tag))
5455
}
5556
}
5657
}

src/hooks/web/useTagsView.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ export const useTagsView = () => {
4747
callback?.()
4848
}
4949

50-
const setTitle = (title: string) => {
51-
tagsViewStore.setTitle(title)
50+
const setTitle = (title: string, path?: string) => {
51+
tagsViewStore.setTitle(title, path)
5252
}
5353

5454
return {

src/store/modules/tagsView.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ export const useTagsViewStore = defineStore('tagsView', {
141141
setSelectedTag(tag: RouteLocationNormalizedLoaded) {
142142
this.selectedTag = tag
143143
},
144-
setTitle(title: string) {
144+
setTitle(title: string, path?: string) {
145145
for (const v of this.visitedViews) {
146-
if (v.path === this.selectedTag?.path) {
146+
if (v.path === (path ?? this.selectedTag?.path)) {
147147
v.meta.title = title
148148
break
149149
}

src/views/hooks/useTagsView.vue

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,21 @@ const closeCurrentTab = () => {
4040
const setTabTitle = () => {
4141
setTitle(new Date().getTime().toString())
4242
}
43+
44+
const setAnalysisTitle = () => {
45+
setTitle(`分析页-${new Date().getTime().toString()}`, '/dashboard/analysis')
46+
}
4347
</script>
4448

4549
<template>
4650
<ContentWrap title="useTagsView">
47-
<ElButton @click="closeAllTabs"> 关闭所有标签页 </ElButton>
48-
<ElButton @click="closeLeftTabs"> 关闭左侧标签页 </ElButton>
49-
<ElButton @click="closeRightTabs"> 关闭右侧标签页 </ElButton>
50-
<ElButton @click="closeOtherTabs"> 关闭其他标签页 </ElButton>
51-
<ElButton @click="closeCurrentTab"> 关闭当前标签页 </ElButton>
52-
<ElButton @click="refresh"> 刷新当前标签页 </ElButton>
53-
<ElButton @click="setTabTitle"> 修改当前标题 </ElButton>
51+
<ElButton type="primary" @click="closeAllTabs"> 关闭所有标签页 </ElButton>
52+
<ElButton type="primary" @click="closeLeftTabs"> 关闭左侧标签页 </ElButton>
53+
<ElButton type="primary" @click="closeRightTabs"> 关闭右侧标签页 </ElButton>
54+
<ElButton type="primary" @click="closeOtherTabs"> 关闭其他标签页 </ElButton>
55+
<ElButton type="primary" @click="closeCurrentTab"> 关闭当前标签页 </ElButton>
56+
<ElButton type="primary" @click="refresh"> 刷新当前标签页 </ElButton>
57+
<ElButton type="primary" @click="setTabTitle"> 修改当前标题 </ElButton>
58+
<ElButton type="primary" @click="setAnalysisTitle"> 修改分析页标题 </ElButton>
5459
</ContentWrap>
5560
</template>

0 commit comments

Comments
 (0)