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:53:37 +08:00
|
|
|
|
<!-- 使用panels数组渲染标签栏 -->
|
2025-11-05 13:04:46 +08:00
|
|
|
|
<div v-if="showTabs && panels && panels.length > 0" class="tab-header">
|
2025-11-05 10:42:22 +08:00
|
|
|
|
<div
|
2025-11-05 10:53:37 +08:00
|
|
|
|
v-for="(panel, index) in panels"
|
|
|
|
|
|
:key="panel.id"
|
2025-11-05 10:42:22 +08:00
|
|
|
|
:class="['tab-item', { 'active': activeTabIndex === index }]"
|
|
|
|
|
|
@click="setActiveTab(index)"
|
2025-11-06 14:57:30 +08:00
|
|
|
|
@mousedown="onTabDragStart(index, $event)"
|
2025-11-05 10:42:22 +08:00
|
|
|
|
>
|
2025-11-05 16:33:14 +08:00
|
|
|
|
<div class="flex items-center justify-between h-full px-3">
|
2025-11-05 16:18:58 +08:00
|
|
|
|
<span class="tab-title">{{ panel.title }}</span>
|
2025-11-06 14:57:30 +08:00
|
|
|
|
<!-- 当标签页未被激活时显示关闭按钮 -->
|
2025-11-05 16:18:58 +08:00
|
|
|
|
<button
|
2025-11-06 14:57:30 +08:00
|
|
|
|
v-if="activeTabIndex !== index"
|
2025-11-05 16:18:58 +08:00
|
|
|
|
class="button-icon p-[2px] rounded hover:opacity-100 opacity-80"
|
|
|
|
|
|
@click.stop="closeTab(panel.id)"
|
|
|
|
|
|
aria-label="关闭"
|
|
|
|
|
|
>
|
|
|
|
|
|
<svg width="11" height="11" viewBox="0 0 11 11" aria-hidden="true">
|
|
|
|
|
|
<line x1="2" y1="2" x2="9" y2="9" stroke="#e6efff" stroke-width="1" />
|
|
|
|
|
|
<line x1="2" y1="9" x2="9" y2="2" stroke="#e6efff" stroke-width="1" />
|
|
|
|
|
|
</svg>
|
|
|
|
|
|
</button>
|
2025-11-05 15:42:02 +08:00
|
|
|
|
</div>
|
2025-11-05 10:42:22 +08:00
|
|
|
|
</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:53:37 +08:00
|
|
|
|
<!-- 渲染slot内容(Panel组件) -->
|
|
|
|
|
|
<slot></slot>
|
2025-11-05 08:55:44 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2025-11-06 14:57:30 +08:00
|
|
|
|
import { defineProps, defineEmits, ref, onMounted } 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: '标签页' },
|
2025-11-05 10:53:37 +08:00
|
|
|
|
// 从父组件传入的面板数组
|
|
|
|
|
|
panels: {
|
2025-11-05 10:42:22 +08:00
|
|
|
|
type: Array,
|
|
|
|
|
|
default: () => []
|
2025-11-05 13:04:46 +08:00
|
|
|
|
},
|
|
|
|
|
|
// 是否显示页标签栏
|
|
|
|
|
|
showTabs: {
|
|
|
|
|
|
type: Boolean,
|
|
|
|
|
|
default: true
|
2025-11-05 10:42:22 +08:00
|
|
|
|
}
|
2025-11-05 08:55:44 +08:00
|
|
|
|
})
|
|
|
|
|
|
|
2025-11-06 14:57:30 +08:00
|
|
|
|
const emit = defineEmits(['tabChange', 'tabClose', 'tabAdd', 'tabDragStart', 'tabDragMove', 'tabDragEnd'])
|
2025-11-05 10:42:22 +08:00
|
|
|
|
|
|
|
|
|
|
// 当前激活的标签页索引
|
2025-11-06 14:57:30 +08:00
|
|
|
|
const activeTabIndex = ref(-1)
|
|
|
|
|
|
|
|
|
|
|
|
// 拖拽相关状态
|
|
|
|
|
|
let isDragging = false
|
|
|
|
|
|
let dragIndex = -1
|
2025-11-05 10:42:22 +08:00
|
|
|
|
|
|
|
|
|
|
// 设置激活的标签页
|
|
|
|
|
|
const setActiveTab = (index) => {
|
2025-11-06 14:57:30 +08:00
|
|
|
|
if (index >= 0 && index < props.panels.length) {
|
2025-11-05 10:42:22 +08:00
|
|
|
|
activeTabIndex.value = index
|
2025-11-06 14:57:30 +08:00
|
|
|
|
emit('tabChange', { index, tab: props.panels[index] })
|
2025-11-05 10:42:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-06 14:57:30 +08:00
|
|
|
|
// 组件挂载后,如果有面板且没有激活的标签,默认激活第一个
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
|
if (props.panels && props.panels.length > 0 && activeTabIndex.value === -1) {
|
|
|
|
|
|
setActiveTab(0)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2025-11-05 10:42:22 +08:00
|
|
|
|
// 关闭标签页
|
|
|
|
|
|
const closeTab = (tabId) => {
|
|
|
|
|
|
emit('tabClose', { id: tabId })
|
|
|
|
|
|
}
|
2025-11-06 14:57:30 +08:00
|
|
|
|
|
|
|
|
|
|
// 标签拖拽开始
|
|
|
|
|
|
const onTabDragStart = (index, event) => {
|
|
|
|
|
|
// 只有当点击的是标题文本区域(不是关闭按钮)时才触发拖拽
|
|
|
|
|
|
if (!event.target.closest('.button-icon') && !event.target.closest('button')) {
|
|
|
|
|
|
isDragging = true
|
|
|
|
|
|
dragIndex = index
|
|
|
|
|
|
|
|
|
|
|
|
// 传递标签页索引和鼠标位置
|
|
|
|
|
|
emit('tabDragStart', {
|
|
|
|
|
|
clientX: event.clientX,
|
|
|
|
|
|
clientY: event.clientY,
|
|
|
|
|
|
tabIndex: index,
|
|
|
|
|
|
tabId: props.panels[index].id
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// 防止文本选择和默认行为
|
|
|
|
|
|
event.preventDefault()
|
|
|
|
|
|
event.stopPropagation()
|
|
|
|
|
|
|
|
|
|
|
|
// 将鼠标移动和释放事件绑定到document,确保拖拽的连续性
|
|
|
|
|
|
document.addEventListener('mousemove', onTabDragMove)
|
|
|
|
|
|
document.addEventListener('mouseup', onTabDragEnd)
|
|
|
|
|
|
document.addEventListener('mouseleave', onTabDragEnd)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 标签拖拽移动
|
|
|
|
|
|
const onTabDragMove = (event) => {
|
|
|
|
|
|
if (isDragging) {
|
|
|
|
|
|
// 防止文本选择和默认行为
|
|
|
|
|
|
event.preventDefault()
|
|
|
|
|
|
event.stopPropagation()
|
|
|
|
|
|
emit('tabDragMove', {
|
|
|
|
|
|
clientX: event.clientX,
|
|
|
|
|
|
clientY: event.clientY,
|
|
|
|
|
|
tabIndex: dragIndex
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 标签拖拽结束
|
|
|
|
|
|
const onTabDragEnd = () => {
|
|
|
|
|
|
if (isDragging) {
|
|
|
|
|
|
isDragging = false
|
|
|
|
|
|
emit('tabDragEnd', { tabIndex: dragIndex })
|
|
|
|
|
|
dragIndex = -1
|
|
|
|
|
|
|
|
|
|
|
|
// 拖拽结束后移除事件监听器
|
|
|
|
|
|
document.removeEventListener('mousemove', onTabDragMove)
|
|
|
|
|
|
document.removeEventListener('mouseup', onTabDragEnd)
|
|
|
|
|
|
document.removeEventListener('mouseleave', onTabDragEnd)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-05 08:55:44 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
.tab-page {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
2025-11-05 13:01:36 +08:00
|
|
|
|
width: 100%;
|
|
|
|
|
|
height: 100%;
|
2025-11-05 12:24:19 +08:00
|
|
|
|
background: #5D6B99;
|
2025-11-05 15:04:08 +08:00
|
|
|
|
border: 0px solid #c7d2ea;
|
2025-11-05 10:42:22 +08:00
|
|
|
|
border-radius: 0;
|
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-05 11:09:29 +08:00
|
|
|
|
:root {
|
|
|
|
|
|
--vs-blue-top: #4f72b3;
|
|
|
|
|
|
--vs-blue-bottom: #3c5a99;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-05 10:42:22 +08:00
|
|
|
|
/* 标签栏样式 - 模仿Windows Forms */
|
|
|
|
|
|
.tab-header {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-wrap: nowrap;
|
|
|
|
|
|
height: 28px;
|
2025-11-05 13:01:36 +08:00
|
|
|
|
background: transparent;
|
2025-11-05 11:15:16 +08:00
|
|
|
|
border-bottom: none;
|
2025-11-05 10:42:22 +08:00
|
|
|
|
overflow-x: auto;
|
|
|
|
|
|
overflow-y: hidden;
|
|
|
|
|
|
padding-top: 2px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.tab-item {
|
|
|
|
|
|
height: 26px;
|
|
|
|
|
|
margin-left: 1px;
|
2025-11-05 11:09:29 +08:00
|
|
|
|
background: linear-gradient(to bottom, var(--vs-blue-top), var(--vs-blue-bottom));
|
2025-11-05 13:01:36 +08:00
|
|
|
|
border-bottom-color: #c7d2ea;
|
2025-11-05 10:42:22 +08:00
|
|
|
|
border-radius: 3px 3px 0 0;
|
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
white-space: nowrap;
|
2025-11-05 11:09:29 +08:00
|
|
|
|
color: white;
|
2025-11-05 10:42:22 +08:00
|
|
|
|
font-size: 12px;
|
|
|
|
|
|
user-select: none;
|
2025-11-05 16:33:14 +08:00
|
|
|
|
min-width: 60px;
|
2025-11-05 10:42:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-05 15:38:25 +08:00
|
|
|
|
.tab-title {
|
2025-11-05 16:18:58 +08:00
|
|
|
|
flex: 1;
|
2025-11-05 15:07:23 +08:00
|
|
|
|
text-align: left;
|
|
|
|
|
|
min-width: 0;
|
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
|
white-space: nowrap;
|
2025-11-05 16:18:58 +08:00
|
|
|
|
margin-right: 8px;
|
2025-11-05 15:25:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-05 10:42:22 +08:00
|
|
|
|
.tab-item.active {
|
2025-11-06 14:57:30 +08:00
|
|
|
|
background: #F5CC84;
|
2025-11-05 10:59:54 +08:00
|
|
|
|
border: 1px solid #c7d2ea;
|
2025-11-06 14:57:30 +08:00
|
|
|
|
border-bottom-color: #F5CC84;
|
2025-11-05 10:59:54 +08:00
|
|
|
|
border-top-width: 2px;
|
|
|
|
|
|
border-top-color: #0078d7;
|
2025-11-06 14:57:30 +08:00
|
|
|
|
color: #000000;
|
2025-11-05 10:42:22 +08:00
|
|
|
|
font-weight: 500;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.tab-item:hover {
|
2025-11-05 11:09:29 +08:00
|
|
|
|
background: linear-gradient(to bottom, #5a7db8, #4667a4);
|
2025-11-05 10:42:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.tab-item.active:hover {
|
2025-11-06 14:57:30 +08:00
|
|
|
|
background: #F5CC84;
|
|
|
|
|
|
color: #000000;
|
2025-11-05 10:42:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-05 16:18:58 +08:00
|
|
|
|
|
2025-11-05 16:13:03 +08:00
|
|
|
|
|
2025-11-05 14:53:57 +08:00
|
|
|
|
.button-icon {
|
|
|
|
|
|
background: transparent;
|
|
|
|
|
|
border: none;
|
2025-11-05 10:42:22 +08:00
|
|
|
|
cursor: pointer;
|
2025-11-05 14:53:57 +08:00
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: center;
|
2025-11-05 10:42:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-05 14:53:57 +08:00
|
|
|
|
/* 确保在活动标签页中的按钮样式正确 */
|
|
|
|
|
|
.tab-item.active .button-icon {
|
|
|
|
|
|
opacity: 0.6;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.tab-item.active .button-icon:hover {
|
|
|
|
|
|
opacity: 1;
|
|
|
|
|
|
background: #f3f4f6;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 确保在非活动标签页中的按钮样式正确 */
|
|
|
|
|
|
.tab-item:not(.active) .button-icon svg line {
|
|
|
|
|
|
stroke: #e6efff;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.tab-item:not(.active) .button-icon:hover svg line {
|
|
|
|
|
|
stroke: white;
|
2025-11-05 10:42:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.tab-placeholder {
|
|
|
|
|
|
background: transparent;
|
2025-11-05 13:01:36 +08:00
|
|
|
|
border: transparent;
|
|
|
|
|
|
border-bottom-color: #c7d2ea;
|
2025-11-05 10:42:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 内容区域样式 */
|
|
|
|
|
|
.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>
|