2021-09-16 20:11:45 +08:00
|
|
|
<template>
|
2021-09-17 08:31:49 +08:00
|
|
|
<div v-if="fixedHeaderAndTab && theme.navStyle.mode !== 'horizontal-mix'" class="multi-tab-height w-full"></div>
|
|
|
|
<div
|
2021-09-20 02:48:53 +08:00
|
|
|
class="multi-tab-height flex-center justify-between w-full px-10px"
|
|
|
|
:class="{ 'multi-tab-top absolute': fixedHeaderAndTab, 'bg-[#18181c]': theme.darkMode }"
|
2021-09-17 08:31:49 +08:00
|
|
|
:style="{ zIndex }"
|
2021-09-20 02:48:53 +08:00
|
|
|
:align="'center'"
|
|
|
|
justify="space-between"
|
|
|
|
:item-style="{ paddingTop: '0px', paddingBottom: '0px' }"
|
2021-09-17 08:31:49 +08:00
|
|
|
>
|
2021-09-20 02:48:53 +08:00
|
|
|
<n-space v-if="theme.multiTabStyle.mode === 'button'" :align="'center'" size="small" class="h-full">
|
|
|
|
<button-tab
|
2021-09-17 19:50:24 +08:00
|
|
|
v-for="item in app.multiTab.routes"
|
|
|
|
:key="item.path"
|
2021-09-20 02:48:53 +08:00
|
|
|
:active="app.multiTab.activeRoute === item.fullPath"
|
2021-09-17 23:44:28 +08:00
|
|
|
:closable="item.name !== ROUTE_HOME.name"
|
2021-09-17 19:50:24 +08:00
|
|
|
@click="handleClickTab(item.fullPath)"
|
2021-09-20 02:48:53 +08:00
|
|
|
@close="removeMultiTab(item.fullPath)"
|
2021-09-17 19:50:24 +08:00
|
|
|
>
|
|
|
|
{{ item.meta?.title }}
|
2021-09-20 02:48:53 +08:00
|
|
|
</button-tab>
|
|
|
|
</n-space>
|
|
|
|
<n-space v-if="theme.multiTabStyle.mode === 'browser'" :align="'flex-end'" :size="0" class="h-full px-16px">
|
|
|
|
<browser-tab
|
|
|
|
v-for="(item, index) in app.multiTab.routes"
|
|
|
|
:key="item.path"
|
|
|
|
v-model:hover-index="hoverIndex"
|
|
|
|
:current-index="index"
|
|
|
|
:active-index="app.activeMultiTabIndex"
|
|
|
|
:closable="item.name !== ROUTE_HOME.name"
|
|
|
|
@click="handleClickTab(item.fullPath)"
|
|
|
|
@close="removeMultiTab(item.fullPath)"
|
|
|
|
>
|
|
|
|
{{ item.meta?.title }}
|
|
|
|
</browser-tab>
|
2021-09-17 08:31:49 +08:00
|
|
|
</n-space>
|
2021-09-17 19:50:24 +08:00
|
|
|
<div class="flex-center w-32px h-32px bg-white cursor-pointer" @click="handleReload">
|
|
|
|
<icon-mdi-refresh class="text-16px" />
|
|
|
|
</div>
|
2021-09-17 08:31:49 +08:00
|
|
|
</div>
|
2021-09-16 20:11:45 +08:00
|
|
|
</template>
|
|
|
|
|
2021-09-17 08:31:49 +08:00
|
|
|
<script lang="ts" setup>
|
2021-09-20 02:48:53 +08:00
|
|
|
import { computed, ref, watch } from 'vue';
|
2021-09-17 19:50:24 +08:00
|
|
|
import { useRoute } from 'vue-router';
|
2021-09-20 02:48:53 +08:00
|
|
|
import { NSpace } from 'naive-ui';
|
2021-09-17 19:50:24 +08:00
|
|
|
import { useThemeStore, useAppStore } from '@/store';
|
2021-09-18 22:16:31 +08:00
|
|
|
import { useReloadInject } from '@/context';
|
2021-09-17 23:44:28 +08:00
|
|
|
import { ROUTE_HOME } from '@/router';
|
2021-09-20 02:48:53 +08:00
|
|
|
import { ButtonTab, BrowserTab } from './components';
|
2021-09-17 08:31:49 +08:00
|
|
|
|
|
|
|
defineProps({
|
|
|
|
zIndex: {
|
|
|
|
type: Number,
|
|
|
|
default: 0
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-09-17 19:50:24 +08:00
|
|
|
const route = useRoute();
|
2021-09-17 08:31:49 +08:00
|
|
|
const theme = useThemeStore();
|
2021-09-17 19:50:24 +08:00
|
|
|
const app = useAppStore();
|
2021-09-17 23:44:28 +08:00
|
|
|
const { initMultiTab, addMultiTab, removeMultiTab, setActiveMultiTab, handleClickTab } = useAppStore();
|
2021-09-20 02:48:53 +08:00
|
|
|
const { handleReload } = useReloadInject();
|
|
|
|
|
|
|
|
const hoverIndex = ref(NaN);
|
2021-09-17 08:31:49 +08:00
|
|
|
|
|
|
|
const fixedHeaderAndTab = computed(() => theme.fixedHeaderAndTab || theme.navStyle.mode === 'horizontal-mix');
|
|
|
|
const multiTabHeight = computed(() => {
|
|
|
|
const { height } = theme.multiTabStyle;
|
|
|
|
return `${height}px`;
|
|
|
|
});
|
|
|
|
const headerHeight = computed(() => {
|
|
|
|
const { height } = theme.headerStyle;
|
|
|
|
return `${height}px`;
|
|
|
|
});
|
2021-09-17 19:50:24 +08:00
|
|
|
|
|
|
|
function init() {
|
|
|
|
initMultiTab();
|
|
|
|
}
|
|
|
|
|
|
|
|
watch(
|
|
|
|
() => route.fullPath,
|
|
|
|
newValue => {
|
|
|
|
addMultiTab(route);
|
|
|
|
setActiveMultiTab(newValue);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
// 初始化
|
|
|
|
init();
|
2021-09-17 08:31:49 +08:00
|
|
|
</script>
|
|
|
|
<style scoped>
|
|
|
|
.multi-tab-height {
|
|
|
|
height: v-bind(multiTabHeight);
|
|
|
|
}
|
|
|
|
.multi-tab-top {
|
|
|
|
top: v-bind(headerHeight);
|
|
|
|
}
|
|
|
|
</style>
|