Parcourir la source

perf: 完善useTagsView

kailong321200875 il y a 1 an
Parent
commit
137334a754

+ 2 - 1
src/components/TagsView/src/TagsView.vue

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

+ 2 - 2
src/hooks/web/useTagsView.ts

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

+ 2 - 2
src/store/modules/tagsView.ts

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

+ 12 - 7
src/views/hooks/useTagsView.vue

@@ -40,16 +40,21 @@ const closeCurrentTab = () => {
 const setTabTitle = () => {
   setTitle(new Date().getTime().toString())
 }
+
+const setAnalysisTitle = () => {
+  setTitle(`分析页-${new Date().getTime().toString()}`, '/dashboard/analysis')
+}
 </script>
 
 <template>
   <ContentWrap title="useTagsView">
-    <ElButton @click="closeAllTabs"> 关闭所有标签页 </ElButton>
-    <ElButton @click="closeLeftTabs"> 关闭左侧标签页 </ElButton>
-    <ElButton @click="closeRightTabs"> 关闭右侧标签页 </ElButton>
-    <ElButton @click="closeOtherTabs"> 关闭其他标签页 </ElButton>
-    <ElButton @click="closeCurrentTab"> 关闭当前标签页 </ElButton>
-    <ElButton @click="refresh"> 刷新当前标签页 </ElButton>
-    <ElButton @click="setTabTitle"> 修改当前标题 </ElButton>
+    <ElButton type="primary" @click="closeAllTabs"> 关闭所有标签页 </ElButton>
+    <ElButton type="primary" @click="closeLeftTabs"> 关闭左侧标签页 </ElButton>
+    <ElButton type="primary" @click="closeRightTabs"> 关闭右侧标签页 </ElButton>
+    <ElButton type="primary" @click="closeOtherTabs"> 关闭其他标签页 </ElButton>
+    <ElButton type="primary" @click="closeCurrentTab"> 关闭当前标签页 </ElButton>
+    <ElButton type="primary" @click="refresh"> 刷新当前标签页 </ElButton>
+    <ElButton type="primary" @click="setTabTitle"> 修改当前标题 </ElButton>
+    <ElButton type="primary" @click="setAnalysisTitle"> 修改分析页标题 </ElButton>
   </ContentWrap>
 </template>