2025-11-05 08:55:44 +08:00
|
|
|
|
<template>
|
2025-11-05 09:13:15 +08:00
|
|
|
|
<div class="tab-page">
|
2025-11-05 10:49:28 +08:00
|
|
|
|
<!-- 当tabs为空时,不显示标签栏,直接渲染slot内容 -->
|
|
|
|
|
|
<div v-if="tabs.length > 0" class="tab-header">
|
2025-11-05 10:42:22 +08:00
|
|
|
|
<div
|
|
|
|
|
|
v-for="(tab, index) in tabs"
|
|
|
|
|
|
:key="tab.id"
|
|
|
|
|
|
:class="['tab-item', { 'active': activeTabIndex === index }]"
|
|
|
|
|
|
@click="setActiveTab(index)"
|
|
|
|
|
|
>
|
|
|
|
|
|
{{ tab.title }}
|
|
|
|
|
|
<span
|
|
|
|
|
|
v-if="tab.closable"
|
|
|
|
|
|
class="tab-close"
|
|
|
|
|
|
@click.stop="closeTab(tab.id)"
|
|
|
|
|
|
>×</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="tab-placeholder"></div>
|
|
|
|
|
|
</div>
|
2025-11-05 09:13:15 +08:00
|
|
|
|
<!-- Tab页内容区域 -->
|
2025-11-05 10:42:22 +08:00
|
|
|
|
<div class="tab-content">
|
2025-11-05 10:49:28 +08:00
|
|
|
|
<!-- 当有tabs时,渲染tabs内容 -->
|
|
|
|
|
|
<template v-if="tabs.length > 0">
|
|
|
|
|
|
<div v-for="(tab, index) in tabs" :key="tab.id" :class="['tab-panel', { 'active': activeTabIndex === index }]">
|
|
|
|
|
|
<component :is="tab.component" v-bind="tab.props"></component>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<!-- 当没有tabs或tabs为空时,渲染slot内容 -->
|
|
|
|
|
|
<template v-else>
|
|
|
|
|
|
<slot></slot>
|
|
|
|
|
|
</template>
|
2025-11-05 08:55:44 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2025-11-05 10:42:22 +08:00
|
|
|
|
import { defineProps, defineEmits, ref } from 'vue'
|
2025-11-05 08:55:44 +08:00
|
|
|
|
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
|
|
id: { type: String, required: true },
|
2025-11-05 10:42:22 +08:00
|
|
|
|
title: { type: String, default: '标签页' },
|
|
|
|
|
|
// 可选的标签页数组配置
|
|
|
|
|
|
tabs: {
|
|
|
|
|
|
type: Array,
|
|
|
|
|
|
default: () => []
|
|
|
|
|
|
},
|
|
|
|
|
|
// 默认激活的标签页索引
|
|
|
|
|
|
activeIndex: {
|
|
|
|
|
|
type: Number,
|
|
|
|
|
|
default: 0
|
|
|
|
|
|
}
|
2025-11-05 08:55:44 +08:00
|
|
|
|
})
|
|
|
|
|
|
|
2025-11-05 10:42:22 +08:00
|
|
|
|
const emit = defineEmits(['tabChange', 'tabClose', 'tabAdd'])
|
|
|
|
|
|
|
|
|
|
|
|
// 当前激活的标签页索引
|
|
|
|
|
|
const activeTabIndex = ref(props.activeIndex)
|
|
|
|
|
|
|
|
|
|
|
|
// 设置激活的标签页
|
|
|
|
|
|
const setActiveTab = (index) => {
|
|
|
|
|
|
if (index >= 0 && index < props.tabs.length) {
|
|
|
|
|
|
activeTabIndex.value = index
|
|
|
|
|
|
emit('tabChange', { index, tab: props.tabs[index] })
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 关闭标签页
|
|
|
|
|
|
const closeTab = (tabId) => {
|
|
|
|
|
|
emit('tabClose', { id: tabId })
|
|
|
|
|
|
}
|
2025-11-05 08:55:44 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
.tab-page {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
2025-11-05 09:13:15 +08:00
|
|
|
|
width: 100%;
|
|
|
|
|
|
height: 100%;
|
2025-11-05 08:55:44 +08:00
|
|
|
|
background: #ffffff;
|
2025-11-05 10:42:22 +08:00
|
|
|
|
border: 1px solid #c7d2ea;
|
|
|
|
|
|
border-radius: 0;
|
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 标签栏样式 - 模仿Windows Forms */
|
|
|
|
|
|
.tab-header {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-wrap: nowrap;
|
|
|
|
|
|
height: 28px;
|
|
|
|
|
|
background: #f0f0f0;
|
|
|
|
|
|
border-bottom: 1px solid #c7d2ea;
|
|
|
|
|
|
overflow-x: auto;
|
|
|
|
|
|
overflow-y: hidden;
|
|
|
|
|
|
padding-top: 2px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.tab-item {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
height: 26px;
|
|
|
|
|
|
padding: 0 16px;
|
|
|
|
|
|
margin-left: 1px;
|
|
|
|
|
|
background: #e8e8e8;
|
|
|
|
|
|
border: 1px solid #c7d2ea;
|
|
|
|
|
|
border-bottom-color: #c7d2ea;
|
|
|
|
|
|
border-radius: 3px 3px 0 0;
|
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
|
color: #333;
|
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
|
user-select: none;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.tab-item.active {
|
|
|
|
|
|
background: #ffffff;
|
|
|
|
|
|
border-bottom-color: #ffffff;
|
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.tab-item:hover {
|
|
|
|
|
|
background: #f5f5f5;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.tab-item.active:hover {
|
|
|
|
|
|
background: #ffffff;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.tab-close {
|
|
|
|
|
|
margin-left: 8px;
|
|
|
|
|
|
font-size: 16px;
|
|
|
|
|
|
color: #666;
|
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
padding: 0 2px;
|
|
|
|
|
|
border-radius: 1px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.tab-close:hover {
|
|
|
|
|
|
background: #ff6b6b;
|
|
|
|
|
|
color: white;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.tab-placeholder {
|
|
|
|
|
|
flex: 1;
|
|
|
|
|
|
background: transparent;
|
|
|
|
|
|
height: 26px;
|
|
|
|
|
|
margin-left: 1px;
|
|
|
|
|
|
border: 1px solid transparent;
|
|
|
|
|
|
border-bottom-color: #c7d2ea;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 内容区域样式 */
|
|
|
|
|
|
.tab-content {
|
|
|
|
|
|
flex: 1;
|
|
|
|
|
|
position: relative;
|
2025-11-05 08:55:44 +08:00
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-05 10:42:22 +08:00
|
|
|
|
.tab-panel {
|
|
|
|
|
|
position: absolute;
|
|
|
|
|
|
top: 0;
|
|
|
|
|
|
left: 0;
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
height: 100%;
|
|
|
|
|
|
padding: 12px;
|
2025-11-05 08:55:44 +08:00
|
|
|
|
overflow: auto;
|
2025-11-05 10:42:22 +08:00
|
|
|
|
background: #ffffff;
|
|
|
|
|
|
display: none;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.tab-panel.active {
|
|
|
|
|
|
display: block;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.tab-empty {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
height: 100%;
|
|
|
|
|
|
color: #999;
|
|
|
|
|
|
font-size: 14px;
|
2025-11-05 08:55:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 滚动条样式 */
|
2025-11-05 10:42:22 +08:00
|
|
|
|
.tab-header::-webkit-scrollbar {
|
|
|
|
|
|
height: 6px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.tab-header::-webkit-scrollbar-track {
|
|
|
|
|
|
background: #f0f0f0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.tab-header::-webkit-scrollbar-thumb {
|
|
|
|
|
|
background: #c7d2ea;
|
|
|
|
|
|
border-radius: 3px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.tab-panel::-webkit-scrollbar {
|
2025-11-05 08:55:44 +08:00
|
|
|
|
width: 12px;
|
|
|
|
|
|
height: 12px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-05 10:42:22 +08:00
|
|
|
|
.tab-panel::-webkit-scrollbar-track {
|
2025-11-05 08:55:44 +08:00
|
|
|
|
background: #f5f7fb;
|
|
|
|
|
|
border-left: 1px solid #c7d2ea;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-05 10:42:22 +08:00
|
|
|
|
.tab-panel::-webkit-scrollbar-thumb {
|
2025-11-05 08:55:44 +08:00
|
|
|
|
background: linear-gradient(to bottom, #d0d6ea, #c0c7e0);
|
|
|
|
|
|
border: 1px solid #b0b6d6;
|
|
|
|
|
|
border-radius: 6px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-05 10:42:22 +08:00
|
|
|
|
.tab-panel::-webkit-scrollbar-thumb:hover {
|
2025-11-05 08:55:44 +08:00
|
|
|
|
background: linear-gradient(to bottom, #c1c7e2, #b2b8d9);
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|