Skip to content

Commit

Permalink
perf: 完善useTagsView
Browse files Browse the repository at this point in the history
  • Loading branch information
kailong321200875 committed Aug 13, 2023
1 parent a869a45 commit 175abd0
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/hooks/web/useTagsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,17 @@ export const useTagsView = () => {
callback?.()
}

const setTitle = (title: string) => {
tagsViewStore.setTitle(title)
}

return {
closeAll,
closeLeft,
closeRight,
closeOther,
closeCurrent,
refreshPage
refreshPage,
setTitle
}
}
3 changes: 2 additions & 1 deletion src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@ export const asyncRouterMap: AppRouteRecordRaw[] = [
meta: {
hidden: true,
title: t('router.details'),
canTo: true
canTo: true,
activeMenu: '/function/multiple-tabs'
}
}
]
Expand Down
8 changes: 8 additions & 0 deletions src/store/modules/tagsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ export const useTagsViewStore = defineStore('tagsView', {
// 设置当前选中的tag
setSelectedTag(tag: RouteLocationNormalizedLoaded) {
this.selectedTag = tag
},
setTitle(title: string) {
for (const v of this.visitedViews) {
if (v.path === this.selectedTag?.path) {
v.meta.title = title
break
}
}
}
}
})
Expand Down
5 changes: 5 additions & 0 deletions src/views/Function/MultipleTabsDemo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ import { ContentWrap } from '@/components/ContentWrap'
import { ElInput } from 'element-plus'
import { ref } from 'vue'
import { useRoute } from 'vue-router'
import { useTagsView } from '@/hooks/web/useTagsView'
const { setTitle } = useTagsView()
const { params } = useRoute()
const val = ref(params.id as string)
setTitle(`详情页-${val.value}`)
</script>

<template>
Expand Down
9 changes: 7 additions & 2 deletions src/views/hooks/useTagsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { useRouter } from 'vue-router'
const { push } = useRouter()
const { closeAll, closeLeft, closeRight, closeOther, closeCurrent, refreshPage } = useTagsView()
const { closeAll, closeLeft, closeRight, closeOther, closeCurrent, refreshPage, setTitle } =
useTagsView()
const closeAllTabs = () => {
closeAll(() => {
Expand Down Expand Up @@ -35,6 +36,10 @@ const closeCurrentTab = () => {
push('/dashboard/analysis')
})
}
const setTabTitle = () => {
setTitle(new Date().getTime().toString())
}
</script>

<template>
Expand All @@ -45,6 +50,6 @@ const closeCurrentTab = () => {
<ElButton @click="closeOtherTabs"> 关闭其他标签页 </ElButton>
<ElButton @click="closeCurrentTab"> 关闭当前标签页 </ElButton>
<ElButton @click="refresh"> 刷新当前标签页 </ElButton>
<ElButton @click="setTabTitle"> 修改当前标题 </ElButton>
</ContentWrap>
</template>
@/hooks/web/useTagsView

0 comments on commit 175abd0

Please sign in to comment.