1515 :title =" (item.meta?.title as string)"
1616 :closable =" Boolean(!item.meta?.affix)"
1717 >
18+ <template #title >
19+ <a-dropdown trigger =" contextMenu" >
20+ <span @contextmenu =" (e) => handleContextMenu(e, item.path)" >
21+ {{ item.meta?.title }}
22+ </span >
23+
24+ <template #content >
25+ <a-doption @click =" tabsStore.closeCurrent(currentContextPath)" >
26+ <template #icon >
27+ <icon-close />
28+ </template >
29+ <template #default >关闭当前</template >
30+ </a-doption >
31+ <a-doption @click =" tabsStore.closeRight(currentContextPath)" >
32+ <template #icon >
33+ <icon-close />
34+ </template >
35+ <template #default >关闭右侧</template >
36+ </a-doption >
37+ <a-doption @click =" tabsStore.closeOther(currentContextPath)" >
38+ <template #icon >
39+ <icon-eraser />
40+ </template >
41+ <template #default >关闭其他</template >
42+ </a-doption >
43+ <a-doption @click =" tabsStore.closeAll" >
44+ <template #icon >
45+ <icon-minus />
46+ </template >
47+ <template #default >关闭全部</template >
48+ </a-doption >
49+ </template >
50+ </a-dropdown >
51+ </template >
1852 </a-tab-pane >
1953 <template #extra >
2054 <a-dropdown trigger =" hover" >
21- <MagicIcon class =" gi_mr" ></MagicIcon >
55+ <a-button type =" text" >
56+ <template #icon >
57+ <icon-more-vertical />
58+ </template >
59+ </a-button >
2260 <template #content >
2361 <a-doption @click =" tabsStore.closeCurrent(route.path)" >
24- <template #icon ><icon-close /></template >
62+ <template #icon >
63+ <icon-close />
64+ </template >
2565 <template #default >关闭当前</template >
2666 </a-doption >
2767 <a-doption @click =" tabsStore.closeRight(route.path)" >
28- <template #icon ><icon-close /></template >
68+ <template #icon >
69+ <icon-close />
70+ </template >
2971 <template #default >关闭右侧</template >
3072 </a-doption >
3173 <a-doption @click =" tabsStore.closeOther(route.path)" >
32- <template #icon ><icon-eraser /></template >
74+ <template #icon >
75+ <icon-eraser />
76+ </template >
3377 <template #default >关闭其他</template >
3478 </a-doption >
3579 <a-doption @click =" tabsStore.closeAll" >
36- <template #icon ><icon-minus /></template >
80+ <template #icon >
81+ <icon-minus />
82+ </template >
3783 <template #default >关闭全部</template >
3884 </a-doption >
3985 </template >
4591
4692<script setup lang="ts">
4793import type { RouteLocationNormalized } from ' vue-router'
48- import MagicIcon from ' ./MagicIcon.vue'
4994import { useAppStore , useTabsStore } from ' @/stores'
5095
5196defineOptions ({ name: ' Tabs' })
97+
5298const route = useRoute ()
5399const router = useRouter ()
54100const appStore = useAppStore ()
55101const tabsStore = useTabsStore ()
56102
57- // 重置, 同时把 affix: true 的路由筛选出来
103+ // 菜单获取的路径
104+ const currentContextPath = ref (' ' )
105+
106+ // Initialize tabs
58107tabsStore .init ()
59108
60- // 路由发生改变触发
61109const handleRouteChange = () => {
62110 const item = { ... route } as unknown as RouteLocationNormalized
63111 tabsStore .addTabItem (toRaw (item ))
64112 tabsStore .addCacheItem (toRaw (item ))
65- // console.log('路由对象', toRaw(item))
66- // console.log('tagList', toRaw(tabsStore.tabList))
67- // console.log('cacheList', toRaw(tabsStore.cacheList))
68113}
114+
69115handleRouteChange ()
70116
71- // 监听路由变化
72117watch (
73118 () => route .fullPath ,
74119 () => {
75120 handleRouteChange ()
76121 },
77122)
78123
79- // 点击页签
80- const handleTabClick = (key : string ) => {
124+ const handleTabClick = (key : string | number ) => {
81125 const obj = tabsStore .tabList .find ((i ) => i .path === key )
82- obj ? router .push (obj .fullPath || obj .path ) : router .push (key )
126+ obj ? router .push (obj .fullPath || obj .path ) : router .push (String (key ))
127+ }
128+
129+ const handleContextMenu = (e : MouseEvent , path : string ) => {
130+ if (! path ) return
131+ e .preventDefault ()
132+ currentContextPath .value = path
83133}
84134 </script >
85135
86136<style lang="scss" scoped>
87137:deep(.arco-tabs-nav-tab ) {
88138 .arco-tabs-tab {
89- border-bottom-color : transparent !important ;
90139 svg {
91140 width : 0 ;
92141 transition : all 0.15s ;
93142 }
143+
94144 & :hover {
95145 svg {
96146 width : 1em ;
97147 }
98148 }
99149 }
150+
100151 & :not (.arco-tabs-nav-tab-scroll ) {
101152 .arco-tabs-tab :first-child {
102153 border-left : 0 ;
@@ -111,5 +162,6 @@ const handleTabClick = (key: string) => {
111162.tabs {
112163 padding-top : 5px ;
113164 background-color : var (--color-bg-1 );
165+ position : relative ;
114166}
115167 </style >
0 commit comments