perf: 完善useTagsView

This commit is contained in:
kailong321200875 2023-08-13 14:25:49 +08:00
parent a869a457e6
commit 175abd0aa3
5 changed files with 28 additions and 4 deletions

View File

@ -47,12 +47,17 @@ export const useTagsView = () => {
callback?.() callback?.()
} }
const setTitle = (title: string) => {
tagsViewStore.setTitle(title)
}
return { return {
closeAll, closeAll,
closeLeft, closeLeft,
closeRight, closeRight,
closeOther, closeOther,
closeCurrent, closeCurrent,
refreshPage refreshPage,
setTitle
} }
} }

View File

@ -339,7 +339,8 @@ export const asyncRouterMap: AppRouteRecordRaw[] = [
meta: { meta: {
hidden: true, hidden: true,
title: t('router.details'), title: t('router.details'),
canTo: true canTo: true,
activeMenu: '/function/multiple-tabs'
} }
} }
] ]

View File

@ -140,6 +140,14 @@ export const useTagsViewStore = defineStore('tagsView', {
// 设置当前选中的tag // 设置当前选中的tag
setSelectedTag(tag: RouteLocationNormalizedLoaded) { setSelectedTag(tag: RouteLocationNormalizedLoaded) {
this.selectedTag = tag this.selectedTag = tag
},
setTitle(title: string) {
for (const v of this.visitedViews) {
if (v.path === this.selectedTag?.path) {
v.meta.title = title
break
}
}
} }
} }
}) })

View File

@ -3,10 +3,15 @@ import { ContentWrap } from '@/components/ContentWrap'
import { ElInput } from 'element-plus' import { ElInput } from 'element-plus'
import { ref } from 'vue' import { ref } from 'vue'
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
import { useTagsView } from '@/hooks/web/useTagsView'
const { setTitle } = useTagsView()
const { params } = useRoute() const { params } = useRoute()
const val = ref(params.id as string) const val = ref(params.id as string)
setTitle(`详情页-${val.value}`)
</script> </script>
<template> <template>

View File

@ -6,7 +6,8 @@ import { useRouter } from 'vue-router'
const { push } = useRouter() const { push } = useRouter()
const { closeAll, closeLeft, closeRight, closeOther, closeCurrent, refreshPage } = useTagsView() const { closeAll, closeLeft, closeRight, closeOther, closeCurrent, refreshPage, setTitle } =
useTagsView()
const closeAllTabs = () => { const closeAllTabs = () => {
closeAll(() => { closeAll(() => {
@ -35,6 +36,10 @@ const closeCurrentTab = () => {
push('/dashboard/analysis') push('/dashboard/analysis')
}) })
} }
const setTabTitle = () => {
setTitle(new Date().getTime().toString())
}
</script> </script>
<template> <template>
@ -45,6 +50,6 @@ const closeCurrentTab = () => {
<ElButton @click="closeOtherTabs"> 关闭其他标签页 </ElButton> <ElButton @click="closeOtherTabs"> 关闭其他标签页 </ElButton>
<ElButton @click="closeCurrentTab"> 关闭当前标签页 </ElButton> <ElButton @click="closeCurrentTab"> 关闭当前标签页 </ElButton>
<ElButton @click="refresh"> 刷新当前标签页 </ElButton> <ElButton @click="refresh"> 刷新当前标签页 </ElButton>
<ElButton @click="setTabTitle"> 修改当前标题 </ElButton>
</ContentWrap> </ContentWrap>
</template> </template>
@/hooks/web/useTagsView