Files
JoyD/AutoRobot/Windows/Robot/Web/src/DockLayout/Area.vue

1038 lines
30 KiB
Vue
Raw Normal View History

2025-10-31 21:58:33 +08:00
<template>
<div
2025-12-24 16:40:17 +08:00
ref="areaRef"
class="vs-area select-none"
:class="{ 'is-maximized': isMaximized, 'is-normal': !isMaximized }"
:style="areaStyle"
:data-area-id="id"
@dragover="handleDragOver"
@dragleave="handleDragLeave"
>
<!-- 调整大小的边框 -->
<div
2025-12-30 11:38:59 +08:00
v-if="resizable && !isMaximized && !isSinglePanel"
class="resize-handle resize-handle-nw"
@mousedown="onResizeStart('nw', $event)"
></div>
<div
2025-12-30 11:38:59 +08:00
v-if="resizable && !isMaximized && !isSinglePanel"
class="resize-handle resize-handle-ne"
@mousedown="onResizeStart('ne', $event)"
></div>
<div
2025-12-30 11:38:59 +08:00
v-if="resizable && !isMaximized && !isSinglePanel"
class="resize-handle resize-handle-sw"
@mousedown="onResizeStart('sw', $event)"
></div>
<div
2025-12-30 11:38:59 +08:00
v-if="resizable && !isMaximized && !isSinglePanel"
class="resize-handle resize-handle-se"
@mousedown="onResizeStart('se', $event)"
></div>
<div
2025-12-30 11:38:59 +08:00
v-if="resizable && !isMaximized && !isSinglePanel"
class="resize-handle resize-handle-n"
@mousedown="onResizeStart('n', $event)"
></div>
<div
2025-12-30 11:38:59 +08:00
v-if="resizable && !isMaximized && !isSinglePanel"
class="resize-handle resize-handle-e"
@mousedown="onResizeStart('e', $event)"
></div>
<div
2025-12-30 11:38:59 +08:00
v-if="resizable && !isMaximized && !isSinglePanel"
class="resize-handle resize-handle-s"
@mousedown="onResizeStart('s', $event)"
></div>
<div
2025-12-30 11:38:59 +08:00
v-if="resizable && !isMaximized && !isSinglePanel"
class="resize-handle resize-handle-w"
@mousedown="onResizeStart('w', $event)"
></div>
2025-11-03 17:26:28 +08:00
<!-- 顶部标题栏 -->
<div v-if="shouldShowTitleBar" class="vs-title-bar" :class="{ 'cursor-move': !isMaximized }" @mousedown="onDragStart">
2025-11-03 17:26:28 +08:00
<div class="vs-title-left">
<div class="vs-app-icon" aria-label="AppIcon">
<svg class="vs-icon" viewBox="0 0 22.4 22.4" aria-hidden="true">
2025-11-01 11:22:18 +08:00
<path
2025-11-03 17:26:28 +08:00
fill="#68217A"
2025-11-01 11:22:18 +08:00
fill-rule="evenodd"
clip-rule="evenodd"
2025-11-03 17:26:28 +08:00
style="shape-rendering: crispEdges;"
d="M0 4.2 L1.8 3.4 L5.8 6.6 L12.6 0 L16.6 1.8 L16.6 15 L12.4 16.6 L6 10.2 L1.8 13.4 L0 12.6 Z
M1.8 5.8 L4.2 8.4 L1.8 10.8 Z
M8.2 8.4 L12.6 5 L12.4 11.6 Z" />
</svg>
</div>
<span class="vs-title-text">{{ title || '面板区' }}</span>
</div>
<div class="vs-title-right title-bar-buttons flex items-center gap-0.5">
<button class="button-icon p-[2px] rounded hover:opacity-100 opacity-80"
:aria-label="isMaximized ? '还原' : '最大化'"
@click.stop="onToggleMaximize"
@mousedown.stop>
2025-11-03 17:26:28 +08:00
<svg v-if="!isMaximized" class="icon-square-svg" width="11" height="11" viewBox="0 0 11 11" aria-hidden="true">
<rect x="0.5" y="0.5" width="10" height="10" fill="#cbd6ff" stroke="#8ea3d8" stroke-width="1" />
<rect x="3" y="3" width="5" height="1" fill="#b8c6ff" />
<rect x="1" y="3" width="8.5" height="6.5" fill="#435d9c" />
</svg>
<svg v-else class="icon-square-svg" width="11" height="11" viewBox="0 0 11 11" aria-hidden="true">
<path
fill="#CED4DD"
fill-rule="evenodd"
clip-rule="evenodd"
d="M1 4 L4 4 L4 1 L11 1 L11 8 L8 8 L8 11 L1 11 Z
M5 4 L5 3 L10 3 L10 7 L8 7 L8 4 Z
M2 6 L12.6 5 L7 6 L7 10 L2 10 Z" />
2025-11-03 17:26:28 +08:00
</svg>
</button>
<button class="button-icon p-[2px] rounded hover:opacity-100 opacity-80"
aria-label="关闭"
@click.stop="onClose"
@mousedown.stop>
2025-11-03 17:26:28 +08:00
<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>
<line x1="2" y1="9" x2="9" y2="2" stroke="#e6efff" stroke-width="1"></line>
</svg>
</button>
</div>
2025-10-31 21:58:33 +08:00
</div>
<!-- 内容区域 -->
<div class="vs-content">
2025-12-29 09:05:37 +08:00
<!-- 使用Render组件渲染children配置 -->
<div v-for="child in Array.isArray(children) ? children : [children]" :key="child.id" style="width: 100%; height: 100%;">
<Render
:type="child.type"
:config="child"
/>
</div>
2025-11-03 17:26:28 +08:00
</div>
</div>
2025-10-31 21:58:33 +08:00
</template>
<script setup>
2025-12-29 09:05:37 +08:00
import { defineProps, computed, ref, onMounted, onUnmounted, watch, defineExpose } from 'vue'
2025-12-30 11:38:59 +08:00
import { emitEvent, onEvent, EVENT_TYPES } from './eventBus'
2025-11-17 10:59:46 +08:00
import TabPage from './TabPage.vue'
import Panel from './Panel.vue'
2025-12-29 09:05:37 +08:00
import Render from './Render.vue'
2025-12-25 13:53:52 +08:00
import { zIndexManager, Z_INDEX_LAYERS } from './dockLayers'
2025-10-31 21:58:33 +08:00
const props = defineProps({
id: { type: String, required: true },
2025-10-31 23:58:26 +08:00
title: { type: String, default: '面板区' },
resizable: { type: Boolean, default: true },
// 初始状态(支持中文值)
windowState: { type: String, default: '正常' },
// 默认尺寸
width: { type: Number, default: 300 },
2025-11-01 15:34:02 +07:00
height: { type: Number, default: 250 },
// 控制标题栏显示
showTitleBar: { type: Boolean, default: true },
// 位置属性,可选
left: { type: Number, default: undefined },
top: { type: Number, default: undefined },
2025-12-29 09:05:37 +08:00
draggable: { type: Boolean, default: true },
// 子组件配置
children: {
type: [Array, Object],
default: () => []
}
2025-10-31 21:58:33 +08:00
})
2025-10-31 23:58:26 +08:00
2025-12-24 16:40:17 +08:00
// 使用全局事件总线和拖拽管理器
// 本地状态
const localState = ref(props.windowState)
// 保存最大化前的位置和大小,用于还原
const maximizedFromPosition = ref(null)
2025-11-01 15:34:02 +07:00
2025-12-24 16:40:17 +08:00
// 组件引用
const areaRef = ref(null)
2025-12-30 11:38:59 +08:00
// 原始位置和大小(用于拖拽和调整大小)
const originalPosition = ref({
width: props.width,
height: props.height,
left: props.left || 0,
top: props.top || 0
})
// 调整大小相关状态
const isResizing = ref(false)
const resizeDirection = ref(null)
const resizeStartPos = ref({ x: 0, y: 0 })
const resizeStartSize = ref({ width: 0, height: 0 })
const resizeStartAreaPos = ref({ left: 0, top: 0 })
// 计算属性:是否是单面板场景
const isSinglePanel = computed(() => {
// 检查children配置
if (props.children) {
const childrenArray = Array.isArray(props.children) ? props.children : [props.children];
// 如果没有children不是单面板
if (childrenArray.length === 0) return false;
// 如果children不是TabPage不是单面板
const firstChild = childrenArray[0];
if (firstChild.type !== 'TabPage') return false;
// 检查TabPage的children
const tabPageChildren = firstChild.children;
if (!tabPageChildren) return false;
const tabPageChildrenArray = Array.isArray(tabPageChildren) ? tabPageChildren : [tabPageChildren];
// 如果TabPage只包含一个Panel是单面板
return tabPageChildrenArray.length === 1;
}
// 默认不是单面板
return false;
});
// 计算属性:是否显示标题栏
const shouldShowTitleBar = computed(() => {
// 基础条件props.showTitleBar为true
if (!props.showTitleBar) return false;
2025-12-30 11:38:59 +08:00
// 单面板场景不显示标题栏
if (isSinglePanel.value) return false;
2025-12-29 09:05:37 +08:00
// 检查children配置
if (props.children) {
const childrenArray = Array.isArray(props.children) ? props.children : [props.children];
2025-12-29 09:05:37 +08:00
// 如果没有children显示标题栏
if (childrenArray.length === 0) return true;
2025-12-29 09:05:37 +08:00
// 如果children不是TabPage显示标题栏
const firstChild = childrenArray[0];
if (firstChild.type !== 'TabPage') return true;
2025-12-29 09:05:37 +08:00
// 检查TabPage的children
const tabPageChildren = firstChild.children;
if (!tabPageChildren) return true;
const tabPageChildrenArray = Array.isArray(tabPageChildren) ? tabPageChildren : [tabPageChildren];
// 如果TabPage包含多个Panel显示标题栏
2025-12-29 09:05:37 +08:00
if (tabPageChildrenArray.length !== 1) return true;
// 如果TabPage只包含一个Panel不显示标题栏
return false;
}
// 默认显示标题栏
return true;
});
// 拖拽相关状态
const isDragging = ref(false)
const dragStartPos = ref({ x: 0, y: 0 })
const areaStartPos = ref({ x: 0, y: 0 })
2025-12-26 13:09:35 +08:00
const currentDragId = ref(null)
// 父容器引用
const parentContainer = ref(null)
2025-11-01 15:34:02 +07:00
// 根据本地状态计算是否最大化
const isMaximized = computed(() => localState.value === '最大化' || localState.value === 'maximized')
2025-10-31 23:58:26 +08:00
// 监听windowState变化同步更新localState
watch(() => props.windowState, (newState) => {
if (newState !== localState.value) {
localState.value = newState
// 如果是从外部设置为最大化,保存当前位置以便还原
if (newState === '最大化' || newState === 'maximized') {
maximizedFromPosition.value = {
2025-12-30 11:38:59 +08:00
width: props.width,
height: props.height,
left: props.left,
top: props.top
}
}
}
}, { immediate: true })
// 根据状态计算尺寸和位置样式
const areaStyle = computed(() => {
if (isMaximized.value) {
2025-11-19 13:57:51 +08:00
// 最大化时填充满父容器使用更高的z-index确保在最顶层
return {
width: '100%',
height: '100%',
position: 'absolute',
top: 0,
left: 0,
2025-11-19 13:57:51 +08:00
zIndex: Z_INDEX_LAYERS.CONTENT_ACTIVE, // 使用统一的z-index层级
margin: 0,
padding: 0
}
}
2025-12-30 11:38:59 +08:00
// 非最大化状态优先使用originalPosition的值实时响应拖拽变化
const style = {
width: `${originalPosition.value.width}px`,
2025-11-19 13:57:51 +08:00
height: `${originalPosition.value.height}px`,
2025-12-30 11:38:59 +08:00
left: `${originalPosition.value.left}px`,
top: `${originalPosition.value.top}px`,
2025-11-19 13:57:51 +08:00
zIndex: Z_INDEX_LAYERS.CONTENT // 使用统一的z-index层级
}
return style
})
2025-12-15 09:03:32 +08:00
// 使用事件总线替代直接emit
// 处理Panel的最大化事件
const onPanelMaximize = (panelId) => {
2025-11-19 16:06:50 +08:00
// // console.log('🔸 Area接收最大化事件 - Panel ID:', panelId)
2025-11-18 13:48:13 +08:00
// 检查内容区是否只有一个Panel
let isSinglePanel = false
2025-12-29 09:05:37 +08:00
// 检查children配置
if (props.children) {
const childrenArray = Array.isArray(props.children) ? props.children : [props.children]
// 查找TabPage组件
const tabPages = childrenArray.filter(child => child.type === 'TabPage')
if (tabPages.length === 1) {
// 检查TabPage的children
const tabPageChildren = tabPages[0].children
if (tabPageChildren) {
const tabPageChildrenArray = Array.isArray(tabPageChildren) ? tabPageChildren : [tabPageChildren]
// 如果TabPage只有一个Panel认为是单Panel模式
isSinglePanel = tabPageChildrenArray.length === 1
}
}
}
// // console.log('🔸 检查是否单Panel模式:', { tabPages: tabPages.length, isSinglePanel })
2025-11-18 13:48:13 +08:00
if (isSinglePanel) {
2025-11-19 16:06:50 +08:00
// // console.log('🔸 单Panel模式切换Area最大化状态')
onToggleMaximize()
2025-11-18 13:48:13 +08:00
} else {
2025-11-19 16:06:50 +08:00
// // console.log('🔸 非单Panel模式转发到父组件')
2025-11-18 13:48:13 +08:00
// 如果不是单Panel转发给父组件处理
2025-12-26 13:09:35 +08:00
emitEvent(EVENT_TYPES.PANEL_MAXIMIZE, { panelId, areaId: props.id }, {
source: { component: 'Area', areaId: props.id }
})
}
}
// 处理拖拽悬停事件
const handleDragOver = (event) => {
2025-12-26 13:09:35 +08:00
emitEvent(EVENT_TYPES.AREA_DRAG_OVER, { event, areaId: props.id }, {
source: { component: 'Area', areaId: props.id }
})
}
// 处理拖拽离开事件
const handleDragLeave = (event) => {
2025-12-26 13:09:35 +08:00
emitEvent(EVENT_TYPES.AREA_DRAG_LEAVE, { event, areaId: props.id }, {
source: { component: 'Area', areaId: props.id }
})
}
// 拖拽开始
const onDragStart = (e) => {
// 最大化状态下不允许拖拽
if (isMaximized.value) return
isDragging.value = true
dragStartPos.value = {
x: e.clientX,
y: e.clientY
}
areaStartPos.value = {
x: originalPosition.value.left || 0,
y: originalPosition.value.top || 0
}
2025-12-26 13:09:35 +08:00
// 生成统一的 dragId
currentDragId.value = `area_${props.id}_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`
// 使用事件总线通知拖拽开始,包含 dragId 和标准化数据格式
2025-12-15 09:03:32 +08:00
emitEvent(EVENT_TYPES.AREA_DRAG_START, {
2025-12-26 13:09:35 +08:00
dragId: currentDragId.value,
areaId: props.id,
2025-12-24 16:40:17 +08:00
position: { x: e.clientX, y: e.clientY },
startLeft: originalPosition.value.left || 0,
2025-12-26 13:09:35 +08:00
startTop: originalPosition.value.top || 0,
timestamp: Date.now()
}, {
source: { component: 'Area', areaId: props.id, dragId: currentDragId.value }
})
// 防止文本选择
e.preventDefault()
}
2025-12-30 11:38:59 +08:00
// 拖拽移动 - 处理事件总线的area.drag.move事件
const onDragMove = (eventData) => {
// 从事件数据中获取位置信息
const { left, top, dragId } = eventData
2025-12-30 11:38:59 +08:00
// 只使用明确提供的left和top值不直接使用position.x和position.y
if (left !== undefined) {
originalPosition.value.left = left
}
if (top !== undefined) {
originalPosition.value.top = top
}
2025-12-30 11:38:59 +08:00
// 发送位置更新事件
2025-12-26 13:09:35 +08:00
emitEvent(EVENT_TYPES.AREA_POSITION_UPDATE, {
2025-12-30 11:38:59 +08:00
dragId: dragId || currentDragId.value,
2025-12-26 13:09:35 +08:00
areaId: props.id,
2025-12-30 11:38:59 +08:00
left: originalPosition.value.left,
top: originalPosition.value.top
2025-12-26 13:09:35 +08:00
}, {
2025-12-30 11:38:59 +08:00
source: { component: 'Area', areaId: props.id, dragId: dragId || currentDragId.value }
2025-12-26 13:09:35 +08:00
})
}
2025-12-30 11:38:59 +08:00
// 拖拽结束 - 处理事件总线的area.drag.end事件
const onDragEnd = (eventData) => {
const { dragId, finalPosition } = eventData
2025-12-26 13:09:35 +08:00
2025-12-30 11:38:59 +08:00
// 如果提供了finalPosition更新位置
if (finalPosition) {
originalPosition.value.left = finalPosition.x
originalPosition.value.top = finalPosition.y
}
2025-12-30 11:38:59 +08:00
// 清理拖拽状态
isDragging.value = false
2025-12-26 13:09:35 +08:00
currentDragId.value = null
2025-12-30 11:38:59 +08:00
// 发送位置更新事件
emitEvent(EVENT_TYPES.AREA_POSITION_UPDATE, {
dragId: dragId || currentDragId.value,
areaId: props.id,
left: originalPosition.value.left,
top: originalPosition.value.top
}, {
source: { component: 'Area', areaId: props.id, dragId: dragId || currentDragId.value }
})
}
// 处理事件总线的area.resize.move事件
const onAreaResizeMove = (eventData) => {
2025-12-31 10:51:47 +08:00
console.log(`[Area:${props.id}] 收到AREA_RESIZE_MOVE事件:`, eventData) // 添加调试日志
2025-12-30 11:38:59 +08:00
const { areaId, size, position, direction } = eventData
2025-12-31 10:51:47 +08:00
if (areaId !== props.id) {
console.log(`[Area:${props.id}] areaId不匹配期望: ${props.id}, 实际: ${areaId}`) // 添加调试日志
return
}
2025-12-30 11:38:59 +08:00
2025-12-31 10:51:47 +08:00
console.log(`[Area:${props.id}] 更新前originalPosition:`, originalPosition.value) // 添加调试日志
2025-12-30 11:38:59 +08:00
if (direction.includes('right') || direction.includes('left')) {
originalPosition.value.width = size.width
if (direction.includes('left')) {
originalPosition.value.left = position.left
}
}
if (direction.includes('bottom') || direction.includes('top')) {
originalPosition.value.height = size.height
if (direction.includes('top')) {
originalPosition.value.top = position.top
}
}
2025-12-31 10:51:47 +08:00
console.log(`[Area:${props.id}] 更新后originalPosition:`, originalPosition.value) // 添加调试日志
2025-12-30 11:38:59 +08:00
emitEvent(EVENT_TYPES.AREA_POSITION_UPDATE, {
areaId: props.id,
left: originalPosition.value.left,
top: originalPosition.value.top
}, {
source: { component: 'Area', areaId: props.id }
})
}
2025-10-31 23:58:26 +08:00
// 调整大小开始
const onResizeStart = (direction, e) => {
if (isMaximized.value) return
isResizing.value = true
resizeDirection.value = direction
resizeStartPos.value = {
x: e.clientX,
y: e.clientY
}
resizeStartSize.value = {
width: originalPosition.value.width,
height: originalPosition.value.height
}
resizeStartAreaPos.value = {
left: originalPosition.value.left,
top: originalPosition.value.top
}
// 防止文本选择
e.preventDefault()
e.stopPropagation()
}
// 调整大小移动
2025-12-29 13:18:13 +08:00
const onResizeMove = (e) => {
if (!isResizing.value) return
const deltaX = e.clientX - resizeStartPos.value.x
const deltaY = e.clientY - resizeStartPos.value.y
let newWidth = resizeStartSize.value.width
let newHeight = resizeStartSize.value.height
let newLeft = resizeStartAreaPos.value.left
let newTop = resizeStartAreaPos.value.top
// 根据方向调整大小
switch (resizeDirection.value) {
case 'nw':
newWidth = Math.max(200, resizeStartSize.value.width - deltaX)
newHeight = Math.max(150, resizeStartSize.value.height - deltaY)
newLeft = resizeStartAreaPos.value.left + deltaX
newTop = resizeStartAreaPos.value.top + deltaY
break
case 'ne':
newWidth = Math.max(200, resizeStartSize.value.width + deltaX)
newHeight = Math.max(150, resizeStartSize.value.height - deltaY)
newTop = resizeStartAreaPos.value.top + deltaY
break
case 'sw':
newWidth = Math.max(200, resizeStartSize.value.width - deltaX)
newHeight = Math.max(150, resizeStartSize.value.height + deltaY)
newLeft = resizeStartAreaPos.value.left + deltaX
break
case 'se':
newWidth = Math.max(200, resizeStartSize.value.width + deltaX)
newHeight = Math.max(150, resizeStartSize.value.height + deltaY)
break
case 'n':
// 拖动上边框时Area向上边扩展
newHeight = Math.max(150, resizeStartSize.value.height - deltaY)
// 当deltaY为负时鼠标向上移动增加高度并向上移动位置
newTop = resizeStartAreaPos.value.top + deltaY
break
case 'e':
newWidth = Math.max(200, resizeStartSize.value.width + deltaX)
break
case 's':
newHeight = Math.max(150, resizeStartSize.value.height + deltaY)
break
case 'w':
// 拖动左边框时Area向左边扩展
newWidth = Math.max(200, resizeStartSize.value.width - deltaX)
// 当deltaX为负时鼠标向左移动增加宽度并向左移动位置
newLeft = resizeStartAreaPos.value.left + deltaX
break
}
// 确保不超出父容器边界
if (parentContainer.value) {
const parentRect = parentContainer.value.getBoundingClientRect()
// 右边界检查
if (newLeft + newWidth > parentRect.width) {
newWidth = parentRect.width - newLeft
}
// 下边界检查
if (newTop + newHeight > parentRect.height) {
newHeight = parentRect.height - newTop
}
// 左边界检查
if (newLeft < 0) {
newWidth += newLeft
newLeft = 0
}
// 上边界检查
if (newTop < 0) {
newHeight += newTop
newTop = 0
}
}
// 更新位置和大小
originalPosition.value.width = newWidth
originalPosition.value.height = newHeight
originalPosition.value.left = newLeft
originalPosition.value.top = newTop
2025-12-24 16:40:17 +08:00
// 使用事件总线通知位置变化
2025-12-15 09:03:32 +08:00
emitEvent(EVENT_TYPES.AREA_POSITION_UPDATE, {
areaId: props.id,
left: newLeft,
top: newTop
2025-12-26 13:09:35 +08:00
}, {
source: { component: 'Area', areaId: props.id }
})
// 防止文本选择
e.preventDefault()
}
// 调整大小结束
const onResizeEnd = () => {
isResizing.value = false
resizeDirection.value = null
}
2025-10-31 23:58:26 +08:00
const onToggleMaximize = () => {
const next = isMaximized.value ? '正常' : '最大化'
if (!isMaximized.value) {
// 切换到最大化状态前,保存当前位置和大小
maximizedFromPosition.value = {
2025-12-30 11:38:59 +08:00
width: props.width,
height: props.height,
left: props.left,
top: props.top
}
}
2025-11-01 15:34:02 +07:00
localState.value = next
2025-12-15 09:03:32 +08:00
emitEvent(EVENT_TYPES.WINDOW_STATE_CHANGE, {
areaId: props.id,
2025-12-30 11:38:59 +08:00
state: next,
// 从最大化状态还原时,传递原始位置信息
position: isMaximized.value && maximizedFromPosition.value ? maximizedFromPosition.value : undefined
2025-12-26 13:09:35 +08:00
}, {
source: { component: 'Area', areaId: props.id }
2025-12-15 09:03:32 +08:00
})
2025-10-31 23:58:26 +08:00
}
2025-12-15 09:03:32 +08:00
const onClose = () => emitEvent(EVENT_TYPES.PANEL_CLOSE_REQUEST, {
areaId: props.id
2025-12-26 13:09:35 +08:00
}, {
source: { component: 'Area', areaId: props.id }
2025-12-15 09:03:32 +08:00
})
// 组件挂载后获取父容器引用并初始化位置
onMounted(() => {
parentContainer.value = document.querySelector('.dock-layout') || window
// 如果没有指定left或top自动居中定位
2025-12-30 11:38:59 +08:00
if (props.left === undefined || props.top === undefined) {
let parentWidth, parentHeight
if (parentContainer.value === window) {
parentWidth = window.innerWidth
parentHeight = window.innerHeight
} else if (parentContainer.value) {
const parentRect = parentContainer.value.getBoundingClientRect()
parentWidth = parentRect.width
parentHeight = parentRect.height
} else {
// 默认值,防止出错
parentWidth = 800
parentHeight = 600
}
2025-12-30 11:38:59 +08:00
const areaWidth = props.width || 300
const areaHeight = props.height || 250
// 计算居中位置
2025-12-30 11:38:59 +08:00
const centerLeft = Math.floor((parentWidth - areaWidth) / 2)
const centerTop = Math.floor((parentHeight - areaHeight) / 2)
// 更新originalPosition
originalPosition.value.left = centerLeft
originalPosition.value.top = centerTop
// 通知父组件位置变化
2025-12-15 09:03:32 +08:00
emitEvent(EVENT_TYPES.AREA_POSITION_UPDATE, {
areaId: props.id,
2025-12-30 11:38:59 +08:00
left: centerLeft,
top: centerTop
2025-12-26 13:09:35 +08:00
}, {
source: { component: 'Area', areaId: props.id }
})
2025-12-30 11:38:59 +08:00
} else {
// 使用props初始化originalPosition
originalPosition.value.left = props.left
originalPosition.value.top = props.top
originalPosition.value.width = props.width
originalPosition.value.height = props.height
}
2025-12-30 11:38:59 +08:00
// 监听区域拖拽事件
onEvent(EVENT_TYPES.AREA_DRAG_MOVE, onDragMove, { componentId: `area-${props.id}` })
onEvent(EVENT_TYPES.AREA_DRAG_END, onDragEnd, { componentId: `area-${props.id}` })
// 监听区域resize事件 - 同时监听两种事件类型,确保兼容性
onEvent(EVENT_TYPES.AREA_RESIZE_MOVE, onAreaResizeMove, { componentId: `area-${props.id}` })
onEvent(EVENT_TYPES.AREA_RESIZE, onAreaResizeMove, { componentId: `area-${props.id}` })
})
2025-11-17 10:59:46 +08:00
2025-12-29 13:18:13 +08:00
// 组件卸载时清理状态
onUnmounted(() => {
2025-12-29 13:18:13 +08:00
// 清理拖拽和调整大小状态
isDragging.value = false
currentDragId.value = null
isResizing.value = false
resizeDirection.value = null
})
2025-11-17 16:55:03 +08:00
2025-11-19 16:06:50 +08:00
// 处理Area合并内容
2025-11-17 16:55:03 +08:00
const mergeAreaContent = (sourceArea) => {
2025-11-19 16:06:50 +08:00
// console.log(`[Area] ${props.id} 接收到Area合并请求:`, sourceArea)
2025-11-17 10:59:46 +08:00
if (!sourceArea) {
2025-11-19 16:06:50 +08:00
// console.warn('[Area] 源Area为空无法合并内容')
2025-11-17 10:59:46 +08:00
return false
}
try {
// 发送合并请求事件,让父组件处理配置修改
emitEvent(EVENT_TYPES.AREA_MERGE_REQUEST, {
sourceArea: sourceArea,
targetAreaId: props.id
}, {
source: { component: 'Area', areaId: props.id }
})
2025-11-17 10:59:46 +08:00
// 触发事件通知父组件将源Area保存到隐藏列表
emitEvent(EVENT_TYPES.AREA_MERGED, {
sourceArea: sourceArea,
targetAreaId: props.id,
targetAreaHasContent: false, // 简化处理,由父组件判断
operation: 'merge-children',
sourceTabPages: sourceArea.children ? [sourceArea.children] : []
}, {
source: { component: 'Area', areaId: props.id }
})
return true
2025-11-17 10:59:46 +08:00
} catch (error) {
2025-11-19 16:06:50 +08:00
// console.error('[Area] 合并Area内容时出错:', error)
2025-11-17 10:59:46 +08:00
return false
}
}
// 暴露方法给父组件调用
defineExpose({
2025-11-17 16:55:03 +08:00
mergeAreaContent, // 合并Area内容的方法
2025-11-17 10:59:46 +08:00
id: props.id,
title: props.title,
isMaximized: isMaximized.value
})
2025-10-31 21:58:33 +08:00
</script>
<style scoped>
:root { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; }
/* 颜色(贴近 VS 蓝色主题) */
.vs-area {
--vs-blue-top: #4f72b3;
--vs-blue-bottom: #3c5a99;
--vs-blue-deep: #2c3e7a;
--vs-tab-blue: #4869a8;
--vs-border: #c7d2ea;
--vs-bg: #f5f7fb;
--vs-panel: #ffffff;
--vs-muted: #6b7aa9;
--vs-accent: #f0a000;
}
/* 容器 */
.vs-area-wrapper {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
position: relative;
}
2025-10-31 21:58:33 +08:00
.vs-area {
display: flex;
flex-direction: column;
background: var(--vs-bg);
border: 1px solid var(--vs-border);
min-width: 300px;
min-height: 250px;
2025-10-31 21:58:33 +08:00
}
/* 正常状态样式 */
.vs-area.is-normal {
position: absolute;
z-index: 10;
}
/* 最大化状态样式 */
.vs-area.is-maximized {
width: 100% !important;
height: 100% !important;
position: absolute !important;
top: 0 !important;
left: 0 !important;
z-index: 100 !important;
margin: 0;
padding: 0;
}
2025-10-31 21:58:33 +08:00
/* 标题栏 */
.vs-title-bar {
height: 28px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 10px;
color: #ffffff;
background: linear-gradient(to bottom, var(--vs-blue-top), var(--vs-blue-bottom));
border-bottom: 1px solid var(--vs-blue-deep);
z-index: 15; /* 确保标题栏在调整手柄之上 */
position: relative; /* 为z-index生效 */
2025-10-31 21:58:33 +08:00
}
.vs-title-left { display: flex; align-items: center; gap: 6px; }
.vs-app-icon { font-size: 12px; opacity: 0.9; }
.vs-title-text { font-size: 13px; }
.vs-title-right { display: flex; align-items: center; gap: 6px; }
.vs-btn {
width: 22px; height: 18px; line-height: 18px;
color: #ffffff; background: transparent; border: none; padding: 0; cursor: default;
position: relative; /* 确保按钮层级生效 */
z-index: 16; /* 确保按钮在最上层 */
2025-10-31 21:58:33 +08:00
}
.vs-btn:hover { background: rgba(255,255,255,0.12); }
.vs-close:hover { background: #e81123; }
/* 面板标题行(左右) */
.vs-pane-headers {
display: flex; align-items: center;
height: 26px; background: var(--vs-tab-blue);
border-bottom: 1px solid var(--vs-blue-deep);
color: #eaf1ff;
padding: 0 6px;
}
.vs-pane-header {
display: flex; align-items: center; gap: 8px;
height: 100%; padding: 0 10px;
}
.vs-pane-sep {
width: 1px; height: 18px; background: rgba(255,255,255,0.3);
margin: 0 8px;
}
.hdr-text { font-size: 12px; }
.hdr-icon { font-size: 10px; opacity: 0.9; }
.hdr-close { font-size: 12px; opacity: 0.9; }
.hdr-close:hover { opacity: 1; }
/* 内容区域 */
.vs-content {
display: flex;
flex: 1;
overflow: visible;
2025-11-17 09:35:52 +08:00
background-color: #C7D3FF;
position: relative;
width: 100%;
height: 100%;
min-width: 0;
min-height: 0;
}
2025-10-31 21:58:33 +08:00
/* 调整大小的手柄样式 */
.resize-handle {
position: absolute;
z-index: 14; /* 调整手柄应该在标题栏之下,但在正常区域内 */
background: transparent;
pointer-events: auto;
}
/* 四个角 */
.resize-handle-nw {
width: 12px;
height: 12px;
top: -6px;
left: -6px;
cursor: nwse-resize;
}
.resize-handle-ne {
width: 12px;
height: 12px;
top: -6px;
right: -6px;
cursor: nesw-resize;
}
.resize-handle-sw {
width: 12px;
height: 12px;
bottom: -6px;
left: -6px;
cursor: nesw-resize;
}
.resize-handle-se {
width: 12px;
height: 12px;
bottom: -6px;
right: -6px;
cursor: nwse-resize;
}
/* 四条边 */
.resize-handle-n {
height: 12px;
top: -6px;
left: 12px;
right: 12px;
cursor: ns-resize;
}
.resize-handle-e {
2025-12-30 11:38:59 +08:00
width: 3px;
right: -1.5px;
top: 12px;
bottom: 12px;
cursor: ew-resize;
}
.resize-handle-s {
2025-12-30 11:38:59 +08:00
height: 3px;
bottom: -1.5px;
left: 12px;
right: 12px;
cursor: ns-resize;
}
.resize-handle-w {
2025-12-30 11:38:59 +08:00
width: 3px;
left: -1.5px;
top: 12px;
bottom: 12px;
cursor: ew-resize;
}
/* 鼠标悬停在边框上时的样式提示 */
.vs-area.is-normal:not(:hover) .resize-handle {
opacity: 0;
}
.vs-area.is-normal:hover .resize-handle {
opacity: 0.5;
}
2025-10-31 21:58:33 +08:00
/* 左侧输出 */
.vs-left { flex: 1; background: var(--vs-panel); display: flex; }
.left-blank { flex: 1; background: #eef1f9; border-right: 1px solid var(--vs-border); }
/* 中间分割线 */
.vs-divider { width: 1px; background: var(--vs-border); }
/* 右侧 Git 更改 */
.vs-right { flex: 1; background: #f5f7fb; padding: 0; }
.sec-text { margin-bottom: 8px; }
.vs-card {
display: inline-flex; align-items: center; gap: 8px;
background: #fff; border: 1px solid var(--vs-border);
padding: 6px 8px; border-radius: 2px; margin-bottom: 10px;
box-shadow: 0 1px 0 rgba(0,0,0,0.04);
}
.card-icon { color: var(--vs-accent); }
.card-text { color: #000; }
.hint-text { color: #666; }
/* 滚动条(接近 VS */
:deep(::-webkit-scrollbar) { width: 12px; height: 12px; }
:deep(::-webkit-scrollbar-track) { background: var(--vs-bg); border-left: 1px solid var(--vs-border); }
:deep(::-webkit-scrollbar-thumb) {
background: linear-gradient(to bottom, #d0d6ea, #c0c7e0);
border: 1px solid #b0b6d6; border-radius: 6px;
}
:deep(::-webkit-scrollbar-thumb:hover) { background: linear-gradient(to bottom, #c1c7e2, #b2b8d9); }
:deep(*) { box-sizing: border-box; }
.vs-area.is-maximized {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
z-index: 100;
}
2025-10-31 23:58:26 +08:00
.vs-icon-stage { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; background: transparent; overflow: auto; }
.vs-app-icon--x200 { width: 2800px; height: 2800px; }
.vs-app-icon { width: 14px; height: 14px; display: inline-block; background: transparent; opacity: 0.95; }
.vs-icon { width: 100%; height: 100%; shape-rendering: crispEdges; }
.vs-app-icon svg { display: block; }
/* 外层包裹,确保最大化时填充父容器,非最大化时居中 */
.vs-area-wrapper {
width: 100%;
height: 100%;
position: relative;
display: flex;
align-items: center;
justify-content: center;
}
/* 最大化状态时wrapper不居中 */
.vs-area-wrapper.is-maximized {
align-items: stretch;
justify-content: stretch;
}
2025-11-17 10:59:46 +08:00
/* 接收到的外部内容样式 */
.received-content {
width: 100%;
height: 100%;
overflow: auto;
background: #f8f9ff;
border: 1px solid #e0e6f0;
border-radius: 4px;
}
.received-item {
background: white;
border: 1px solid #d0d7e2;
border-radius: 6px;
margin: 8px;
padding: 12px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
transition: box-shadow 0.2s ease;
}
.received-item:hover {
box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}
.received-title {
font-size: 13px;
font-weight: 600;
color: #2c3e7a;
margin-bottom: 8px;
padding-bottom: 6px;
border-bottom: 1px solid #e8edf7;
}
.received-body {
min-height: 60px;
}
/* TabPage和Panel容器样式 */
.tab-page-container,
.area-container {
width: 100%;
height: 100%;
border: 1px dashed #c7d2ea;
border-radius: 4px;
padding: 12px;
background: #fafbff;
color: #6b7aa9;
text-align: center;
font-style: italic;
}
2025-10-31 21:58:33 +08:00
</style>