feat: 新增useTagsView
parent
7a2b3a9d84
commit
a869a457e6
@ -0,0 +1,58 @@
|
|||||||
|
import { useTagsViewStoreWithOut } from '@/store/modules/tagsView'
|
||||||
|
import { RouteLocationNormalizedLoaded, useRouter } from 'vue-router'
|
||||||
|
import { computed, nextTick, unref } from 'vue'
|
||||||
|
|
||||||
|
export const useTagsView = () => {
|
||||||
|
const tagsViewStore = useTagsViewStoreWithOut()
|
||||||
|
|
||||||
|
const { replace, currentRoute } = useRouter()
|
||||||
|
|
||||||
|
const selectedTag = computed(() => tagsViewStore.getSelectedTag)
|
||||||
|
|
||||||
|
const closeAll = (callback?: Fn) => {
|
||||||
|
tagsViewStore.delAllViews()
|
||||||
|
callback?.()
|
||||||
|
}
|
||||||
|
|
||||||
|
const closeLeft = (callback?: Fn) => {
|
||||||
|
tagsViewStore.delLeftViews(unref(selectedTag) as RouteLocationNormalizedLoaded)
|
||||||
|
callback?.()
|
||||||
|
}
|
||||||
|
|
||||||
|
const closeRight = (callback?: Fn) => {
|
||||||
|
tagsViewStore.delRightViews(unref(selectedTag) as RouteLocationNormalizedLoaded)
|
||||||
|
callback?.()
|
||||||
|
}
|
||||||
|
|
||||||
|
const closeOther = (callback?: Fn) => {
|
||||||
|
tagsViewStore.delOthersViews(unref(selectedTag) as RouteLocationNormalizedLoaded)
|
||||||
|
callback?.()
|
||||||
|
}
|
||||||
|
|
||||||
|
const closeCurrent = (view?: RouteLocationNormalizedLoaded, callback?: Fn) => {
|
||||||
|
if (view?.meta?.affix) return
|
||||||
|
tagsViewStore.delView(view || unref(currentRoute))
|
||||||
|
|
||||||
|
callback?.()
|
||||||
|
}
|
||||||
|
|
||||||
|
const refreshPage = async (view?: RouteLocationNormalizedLoaded, callback?: Fn) => {
|
||||||
|
tagsViewStore.delCachedView()
|
||||||
|
const { path, query } = view || unref(currentRoute)
|
||||||
|
await nextTick()
|
||||||
|
replace({
|
||||||
|
path: '/redirect' + path,
|
||||||
|
query: query
|
||||||
|
})
|
||||||
|
callback?.()
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
closeAll,
|
||||||
|
closeLeft,
|
||||||
|
closeRight,
|
||||||
|
closeOther,
|
||||||
|
closeCurrent,
|
||||||
|
refreshPage
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,50 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { ContentWrap } from '@/components/ContentWrap'
|
||||||
|
import { ElButton } from 'element-plus'
|
||||||
|
import { useTagsView } from '@/hooks/web/useTagsView'
|
||||||
|
import { useRouter } from 'vue-router'
|
||||||
|
|
||||||
|
const { push } = useRouter()
|
||||||
|
|
||||||
|
const { closeAll, closeLeft, closeRight, closeOther, closeCurrent, refreshPage } = useTagsView()
|
||||||
|
|
||||||
|
const closeAllTabs = () => {
|
||||||
|
closeAll(() => {
|
||||||
|
push('/dashboard/analysis')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const closeLeftTabs = () => {
|
||||||
|
closeLeft()
|
||||||
|
}
|
||||||
|
|
||||||
|
const closeRightTabs = () => {
|
||||||
|
closeRight()
|
||||||
|
}
|
||||||
|
|
||||||
|
const closeOtherTabs = () => {
|
||||||
|
closeOther()
|
||||||
|
}
|
||||||
|
|
||||||
|
const refresh = () => {
|
||||||
|
refreshPage()
|
||||||
|
}
|
||||||
|
|
||||||
|
const closeCurrentTab = () => {
|
||||||
|
closeCurrent(undefined, () => {
|
||||||
|
push('/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>
|
||||||
|
</ContentWrap>
|
||||||
|
</template>
|
||||||
|
@/hooks/web/useTagsView
|
||||||
Loading…
Reference in New Issue