Skip to content

Commit 2a029ba

Browse files
committed
feat: add useTagsView hooks
1 parent 57e8256 commit 2a029ba

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

src/hooks/web/useTagsView.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { useTagsViewStoreWithOut } from '@/store/modules/tagsView'
2+
import { RouteLocationNormalizedLoaded, useRouter } from 'vue-router'
3+
import { computed, nextTick, unref } from 'vue'
4+
5+
export const useTagsView = () => {
6+
const tagsViewStore = useTagsViewStoreWithOut()
7+
8+
const { replace, currentRoute } = useRouter()
9+
10+
const selectedTag = computed(() => tagsViewStore.getSelectedTag)
11+
12+
const closeAll = (callback?: Fn) => {
13+
tagsViewStore.delAllViews()
14+
callback?.()
15+
}
16+
17+
const closeLeft = (callback?: Fn) => {
18+
tagsViewStore.delLeftViews(unref(selectedTag) as RouteLocationNormalizedLoaded)
19+
callback?.()
20+
}
21+
22+
const closeRight = (callback?: Fn) => {
23+
tagsViewStore.delRightViews(unref(selectedTag) as RouteLocationNormalizedLoaded)
24+
callback?.()
25+
}
26+
27+
const closeOther = (callback?: Fn) => {
28+
tagsViewStore.delOthersViews(unref(selectedTag) as RouteLocationNormalizedLoaded)
29+
callback?.()
30+
}
31+
32+
const closeCurrent = (view?: RouteLocationNormalizedLoaded, callback?: Fn) => {
33+
if (view?.meta?.affix) return
34+
tagsViewStore.delView(view || unref(currentRoute))
35+
36+
callback?.()
37+
}
38+
39+
const refreshPage = async (view?: RouteLocationNormalizedLoaded, callback?: Fn) => {
40+
tagsViewStore.delCachedView()
41+
const { path, query } = view || unref(currentRoute)
42+
await nextTick()
43+
replace({
44+
path: '/redirect' + path,
45+
query: query
46+
})
47+
callback?.()
48+
}
49+
50+
const setTitle = (title: string, path?: string) => {
51+
tagsViewStore.setTitle(title, path)
52+
}
53+
54+
return {
55+
closeAll,
56+
closeLeft,
57+
closeRight,
58+
closeOther,
59+
closeCurrent,
60+
refreshPage,
61+
setTitle
62+
}
63+
}

0 commit comments

Comments
 (0)