perf: 完善useTagsView

master
kailong321200875 2 years ago
parent 175abd0aa3
commit e0c55f40d4

@ -13,6 +13,7 @@ import { useTemplateRefsList } from '@vueuse/core'
import { ElScrollbar } from 'element-plus' import { ElScrollbar } from 'element-plus'
import { useScrollTo } from '@/hooks/event/useScrollTo' import { useScrollTo } from '@/hooks/event/useScrollTo'
import { useTagsView } from '@/hooks/web/useTagsView' import { useTagsView } from '@/hooks/web/useTagsView'
import { cloneDeep } from 'lodash-es'
const { getPrefixCls } = useDesign() const { getPrefixCls } = useDesign()
@ -50,7 +51,7 @@ const initTags = () => {
for (const tag of unref(affixTagArr)) { for (const tag of unref(affixTagArr)) {
// Must have tag name // Must have tag name
if (tag.name) { if (tag.name) {
tagsViewStore.addVisitedView(tag) tagsViewStore.addVisitedView(cloneDeep(tag))
} }
} }
} }

@ -47,8 +47,8 @@ export const useTagsView = () => {
callback?.() callback?.()
} }
const setTitle = (title: string) => { const setTitle = (title: string, path?: string) => {
tagsViewStore.setTitle(title) tagsViewStore.setTitle(title, path)
} }
return { return {

@ -141,9 +141,9 @@ export const useTagsViewStore = defineStore('tagsView', {
setSelectedTag(tag: RouteLocationNormalizedLoaded) { setSelectedTag(tag: RouteLocationNormalizedLoaded) {
this.selectedTag = tag this.selectedTag = tag
}, },
setTitle(title: string) { setTitle(title: string, path?: string) {
for (const v of this.visitedViews) { for (const v of this.visitedViews) {
if (v.path === this.selectedTag?.path) { if (v.path === (path ?? this.selectedTag?.path)) {
v.meta.title = title v.meta.title = title
break break
} }

@ -40,16 +40,21 @@ const closeCurrentTab = () => {
const setTabTitle = () => { const setTabTitle = () => {
setTitle(new Date().getTime().toString()) setTitle(new Date().getTime().toString())
} }
const setAnalysisTitle = () => {
setTitle(`分析页-${new Date().getTime().toString()}`, '/dashboard/analysis')
}
</script> </script>
<template> <template>
<ContentWrap title="useTagsView"> <ContentWrap title="useTagsView">
<ElButton @click="closeAllTabs"> </ElButton> <ElButton type="primary" @click="closeAllTabs"> </ElButton>
<ElButton @click="closeLeftTabs"> </ElButton> <ElButton type="primary" @click="closeLeftTabs"> </ElButton>
<ElButton @click="closeRightTabs"> </ElButton> <ElButton type="primary" @click="closeRightTabs"> </ElButton>
<ElButton @click="closeOtherTabs"> </ElButton> <ElButton type="primary" @click="closeOtherTabs"> </ElButton>
<ElButton @click="closeCurrentTab"> </ElButton> <ElButton type="primary" @click="closeCurrentTab"> </ElButton>
<ElButton @click="refresh"> </ElButton> <ElButton type="primary" @click="refresh"> </ElButton>
<ElButton @click="setTabTitle"> </ElButton> <ElButton type="primary" @click="setTabTitle"> </ElButton>
<ElButton type="primary" @click="setAnalysisTitle"> </ElButton>
</ContentWrap> </ContentWrap>
</template> </template>

Loading…
Cancel
Save