Files
aiot-platform-ui/packages/effects/layouts/src/basic/tabbar/tabbar.vue

106 lines
2.6 KiB
Vue
Raw Normal View History

2024-05-19 21:20:42 +08:00
<script lang="ts" setup>
import { computed, onMounted } from 'vue';
2024-07-10 00:50:41 +08:00
import { useRoute } from 'vue-router';
import { useContentMaximize, useTabs } from '@vben/hooks';
import { preferences } from '@vben/preferences';
2024-07-30 21:10:28 +08:00
import { useTabbarStore } from '@vben/stores';
import {
TabsToolMore,
TabsToolRefresh,
TabsToolScreen,
TabsView,
} from '@vben-core/tabs-ui';
2024-05-19 21:20:42 +08:00
import { ChevronLeftIcon, ChevronRightIcon } from '@radix-icons/vue';
import { useTabViewScroll } from './use-tab-view-scroll';
import { useTabbar } from './use-tabbar';
2024-05-19 21:20:42 +08:00
defineOptions({
2024-06-09 15:39:11 +08:00
name: 'LayoutTabbar',
2024-05-19 21:20:42 +08:00
});
2024-07-16 23:13:03 +08:00
defineProps<{ showIcon?: boolean; theme?: string }>();
2024-05-19 21:20:42 +08:00
const route = useRoute();
2024-07-30 21:10:28 +08:00
const tabbarStore = useTabbarStore();
const { toggleMaximize } = useContentMaximize();
const { refreshTab, unpinTab } = useTabs();
2024-05-19 21:20:42 +08:00
const {
createContextMenus,
currentActive,
currentTabs,
handleClick,
handleClose,
} = useTabbar();
2024-07-10 00:50:41 +08:00
const menus = computed(() => {
2024-07-30 21:10:28 +08:00
const tab = tabbarStore.getTabByPath(currentActive.value);
const menus = createContextMenus(tab);
return menus.map((item) => {
return {
...item,
label: item.text,
value: item.key,
};
});
});
2024-07-10 00:50:41 +08:00
// 刷新后如果不保持tab状态关闭其他tab
if (!preferences.tabbar.persist) {
2024-07-30 21:10:28 +08:00
tabbarStore.closeOtherTabs(route);
2024-07-10 00:50:41 +08:00
}
const { scrollDirection, setScrollBarEl, setScrollViewEl } = useTabViewScroll();
onMounted(() => {
const scrollBarEl: HTMLElement | null =
document.querySelector('#tabs-scrollbar');
const scrollViewportEl: HTMLElement | null | undefined =
scrollBarEl?.querySelector('div[data-radix-scroll-area-viewport]');
setScrollBarEl(scrollBarEl);
setScrollViewEl(scrollViewportEl);
});
2024-05-19 21:20:42 +08:00
</script>
<template>
<ChevronLeftIcon
class="mx-2 h-full cursor-pointer"
@click="scrollDirection('left')"
/>
2024-05-19 21:20:42 +08:00
<TabsView
2024-06-09 13:31:43 +08:00
:active="currentActive"
2024-07-16 23:13:03 +08:00
:class="theme"
:context-menus="createContextMenus"
:dragable="preferences.tabbar.dragable"
2024-05-19 21:20:42 +08:00
:show-icon="showIcon"
:style-type="preferences.tabbar.styleType"
2024-05-19 21:20:42 +08:00
:tabs="currentTabs"
@close="handleClose"
2024-07-30 21:10:28 +08:00
@sort-tabs="tabbarStore.sortTabs"
@unpin="unpinTab"
2024-06-09 13:31:43 +08:00
@update:active="handleClick"
2024-05-19 21:20:42 +08:00
/>
<div class="flex-center h-full">
<ChevronRightIcon
class="mx-2 h-full cursor-pointer"
@click="scrollDirection('right')"
/>
<TabsToolRefresh
v-if="preferences.tabbar.showRefresh"
@refresh="refreshTab"
/>
<TabsToolMore v-if="preferences.tabbar.showMore" :menus="menus" />
<TabsToolScreen
v-if="preferences.tabbar.showMaximize"
:screen="preferences.sidebar.hidden"
@change="toggleMaximize"
@update:screen="toggleMaximize"
/>
</div>
2024-05-19 21:20:42 +08:00
</template>