File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed
layouts/components/Topbar/Tabbar Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -30,10 +30,20 @@ const tabRef = useTemplateRef<HTMLElement[]>('tabRef')
3030
3131watch (() => route , (val ) => {
3232 if (settingsStore .settings .tabbar .enable ) {
33- tabbarStore .add (val ).then (() => {
33+ tabbarStore .add (val )
34+ nextTick (() => {
3435 const index = tabbarStore .list .findIndex (item => item .tabId === activedTabId .value )
3536 if (index !== - 1 ) {
36- tabRef .value && tabsRef .value ?.scrollTo (tabRef .value [index ].offsetLeft - tabsRef .value .ref ?.$el .clientWidth * 0.4 )
37+ const tabEl = tabRef .value ?.find (item => Number .parseInt (item .dataset .index ! ) === index )
38+ const containerEl = tabsRef .value ?.ref ?.$el
39+ if (tabEl && containerEl ) {
40+ const tabLeft = tabEl .offsetLeft
41+ const tabWidth = tabEl .offsetWidth
42+ const containerWidth = containerEl .clientWidth
43+ // 计算滚动位置,使标签页居中
44+ const scrollLeft = tabLeft - (containerWidth - tabWidth ) / 2
45+ tabsRef .value ?.scrollTo (scrollLeft )
46+ }
3747 tabbarScrollTip ()
3848 }
3949 })
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ const useTabbarStore = defineStore(
1212 const leaveIndex = ref ( - 1 )
1313
1414 // 添加标签页
15- async function add ( route : RouteLocationNormalized ) {
15+ function add ( route : RouteLocationNormalized ) {
1616 const names : string [ ] = [ ]
1717 route . matched . forEach ( ( v , i ) => {
1818 if ( i > 0 ) {
You can’t perform that action at this time.
0 commit comments