2021-10-20 14:32:09 +08:00
|
|
|
<template>
|
|
|
|
<div :class="getWrapClass">
|
2022-09-22 14:06:18 +08:00
|
|
|
<Tabs
|
|
|
|
type="editable-card"
|
|
|
|
size="small"
|
|
|
|
:animated="false"
|
|
|
|
:hideAdd="true"
|
|
|
|
:tabBarGutter="3"
|
|
|
|
:activeKey="activeKeyRef"
|
|
|
|
@change="handleChange"
|
|
|
|
@edit="handleEdit"
|
|
|
|
>
|
2021-10-20 14:32:09 +08:00
|
|
|
<template v-for="item in getTabsState" :key="item.query ? item.fullPath : item.path">
|
|
|
|
<TabPane :closable="!(item && item.meta && item.meta.affix)">
|
|
|
|
<template #tab>
|
|
|
|
<TabContent :tabItem="item" />
|
|
|
|
</template>
|
|
|
|
</TabPane>
|
|
|
|
</template>
|
|
|
|
|
2022-09-22 14:06:18 +08:00
|
|
|
<template #rightExtra v-if="getShowRedo || getShowQuick">
|
2021-10-20 14:32:09 +08:00
|
|
|
<TabRedo v-if="getShowRedo" />
|
|
|
|
<TabContent isExtra :tabItem="$route" v-if="getShowQuick" />
|
|
|
|
<FoldButton v-if="getShowFold" />
|
|
|
|
</template>
|
|
|
|
</Tabs>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script lang="ts">
|
|
|
|
import type { RouteLocationNormalized, RouteMeta } from 'vue-router';
|
|
|
|
|
|
|
|
import { defineComponent, computed, unref, ref } from 'vue';
|
|
|
|
|
|
|
|
import { Tabs } from 'ant-design-vue';
|
|
|
|
import TabContent from './components/TabContent.vue';
|
|
|
|
import FoldButton from './components/FoldButton.vue';
|
|
|
|
import TabRedo from './components/TabRedo.vue';
|
|
|
|
|
|
|
|
import { useGo } from '/@/hooks/web/usePage';
|
|
|
|
|
|
|
|
import { useMultipleTabStore } from '/@/store/modules/multipleTab';
|
|
|
|
import { useUserStore } from '/@/store/modules/user';
|
|
|
|
|
|
|
|
import { initAffixTabs, useTabsDrag } from './useMultipleTabs';
|
|
|
|
import { useDesign } from '/@/hooks/web/useDesign';
|
|
|
|
import { useMultipleTabSetting } from '/@/hooks/setting/useMultipleTabSetting';
|
|
|
|
|
|
|
|
import { REDIRECT_NAME } from '/@/router/constant';
|
|
|
|
import { listenerRouteChange } from '/@/logics/mitt/routeChange';
|
|
|
|
|
|
|
|
import { useRouter } from 'vue-router';
|
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
name: 'MultipleTabs',
|
|
|
|
components: {
|
|
|
|
TabRedo,
|
|
|
|
FoldButton,
|
|
|
|
Tabs,
|
|
|
|
TabPane: Tabs.TabPane,
|
|
|
|
TabContent,
|
|
|
|
},
|
|
|
|
setup() {
|
|
|
|
const affixTextList = initAffixTabs();
|
|
|
|
const activeKeyRef = ref('');
|
|
|
|
|
|
|
|
useTabsDrag(affixTextList);
|
|
|
|
const tabStore = useMultipleTabStore();
|
|
|
|
const userStore = useUserStore();
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
|
|
const { prefixCls } = useDesign('multiple-tabs');
|
|
|
|
const go = useGo();
|
2022-03-10 09:47:29 +08:00
|
|
|
const { getShowQuick, getShowRedo, getShowFold, getTabsTheme } = useMultipleTabSetting();
|
2021-10-20 14:32:09 +08:00
|
|
|
|
|
|
|
const getTabsState = computed(() => {
|
|
|
|
return tabStore.getTabList.filter((item) => !item.meta?.hideTab);
|
|
|
|
});
|
|
|
|
|
|
|
|
const unClose = computed(() => unref(getTabsState).length === 1);
|
|
|
|
|
|
|
|
const getWrapClass = computed(() => {
|
|
|
|
return [
|
|
|
|
prefixCls,
|
|
|
|
{
|
|
|
|
[`${prefixCls}--hide-close`]: unref(unClose),
|
|
|
|
},
|
2022-03-10 09:47:29 +08:00
|
|
|
`${prefixCls}--theme-${unref(getTabsTheme)}`,
|
2021-10-20 14:32:09 +08:00
|
|
|
];
|
|
|
|
});
|
|
|
|
|
|
|
|
listenerRouteChange((route) => {
|
|
|
|
const { name } = route;
|
|
|
|
if (name === REDIRECT_NAME || !route || !userStore.getToken) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { path, fullPath, meta = {} } = route;
|
|
|
|
const { currentActiveMenu, hideTab } = meta as RouteMeta;
|
|
|
|
const isHide = !hideTab ? null : currentActiveMenu;
|
|
|
|
const p = isHide || fullPath || path;
|
|
|
|
if (activeKeyRef.value !== p) {
|
|
|
|
activeKeyRef.value = p as string;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isHide) {
|
2022-06-10 10:44:44 +08:00
|
|
|
const findParentRoute = router.getRoutes().find((item) => item.path === currentActiveMenu);
|
2021-10-20 14:32:09 +08:00
|
|
|
|
|
|
|
findParentRoute && tabStore.addTab(findParentRoute as unknown as RouteLocationNormalized);
|
|
|
|
} else {
|
|
|
|
tabStore.addTab(unref(route));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function handleChange(activeKey: any) {
|
|
|
|
activeKeyRef.value = activeKey;
|
|
|
|
go(activeKey, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Close the current tab
|
|
|
|
function handleEdit(targetKey: string) {
|
|
|
|
// Added operation to hide, currently only use delete operation
|
|
|
|
if (unref(unClose)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tabStore.closeTabByKey(targetKey, router);
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
prefixCls,
|
|
|
|
unClose,
|
|
|
|
getWrapClass,
|
|
|
|
handleEdit,
|
|
|
|
handleChange,
|
|
|
|
activeKeyRef,
|
|
|
|
getTabsState,
|
|
|
|
getShowQuick,
|
|
|
|
getShowRedo,
|
|
|
|
getShowFold,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
<style lang="less">
|
|
|
|
@import './index.less';
|
2022-03-10 09:47:29 +08:00
|
|
|
@import './tabs.theme.card.less';
|
|
|
|
@import './tabs.theme.smooth.less';
|
2021-10-20 14:32:09 +08:00
|
|
|
</style>
|
2023-12-29 21:41:35 +08:00
|
|
|
<style lang="less" scoped>
|
|
|
|
@prefix-cls: ~'@{namespace}-multiple-tabs';
|
|
|
|
.@{prefix-cls} {
|
|
|
|
:deep(.anticon) {
|
|
|
|
display: inline-block;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|