2025-10-31 23:58:26 +08:00
|
|
|
|
<template>
|
2025-11-04 09:45:51 +08:00
|
|
|
|
<div class="dock-layout" ref="dockLayoutRef">
|
2025-11-02 17:19:53 +07:00
|
|
|
|
<!-- 浮动区域列表 -->
|
2025-11-03 17:26:28 +08:00
|
|
|
|
<Area
|
2025-11-02 17:19:53 +07:00
|
|
|
|
v-for="area in floatingAreas"
|
|
|
|
|
|
:key="area.id"
|
2025-11-03 17:26:28 +08:00
|
|
|
|
:id="area.id"
|
|
|
|
|
|
:title="area.title"
|
2025-11-04 09:10:15 +08:00
|
|
|
|
v-model:WindowState="area.WindowState"
|
2025-11-04 15:02:03 +08:00
|
|
|
|
:showTitleBar="area.panels && area.panels.length === 1"
|
2025-11-03 17:26:28 +08:00
|
|
|
|
:width="area.width"
|
|
|
|
|
|
:height="area.height"
|
2025-11-04 09:10:15 +08:00
|
|
|
|
:left="area.WindowState !== '最大化' ? area.x : undefined"
|
|
|
|
|
|
:top="area.WindowState !== '最大化' ? area.y : undefined"
|
|
|
|
|
|
:style="area.WindowState !== '最大化' ? {
|
2025-11-03 17:26:28 +08:00
|
|
|
|
position: 'absolute',
|
|
|
|
|
|
zIndex: 10
|
2025-11-04 09:10:15 +08:00
|
|
|
|
} : {
|
|
|
|
|
|
zIndex: 100
|
2025-11-02 17:19:53 +07:00
|
|
|
|
}"
|
2025-11-03 17:26:28 +08:00
|
|
|
|
@close="onCloseFloatingArea(area.id)"
|
2025-11-04 09:45:51 +08:00
|
|
|
|
@update:position="onUpdatePosition(area.id, $event)"
|
2025-11-04 10:53:22 +08:00
|
|
|
|
>
|
|
|
|
|
|
<!-- 每个Area内渲染其包含的Panels -->
|
|
|
|
|
|
<Panel
|
|
|
|
|
|
v-for="panel in area.panels"
|
|
|
|
|
|
:key="panel.id"
|
|
|
|
|
|
:id="panel.id"
|
|
|
|
|
|
:title="panel.title"
|
|
|
|
|
|
:collapsed="panel.collapsed"
|
|
|
|
|
|
:toolbarExpanded="panel.toolbarExpanded"
|
|
|
|
|
|
@toggleCollapse="onToggleCollapse"
|
|
|
|
|
|
@maximize="onMaximize"
|
|
|
|
|
|
@close="onClosePanel(area.id, panel.id)"
|
|
|
|
|
|
@toggleToolbar="onToggleToolbar"
|
2025-11-04 11:05:12 +08:00
|
|
|
|
@dragStart="onPanelDragStart(area.id, $event)"
|
|
|
|
|
|
@dragMove="onPanelDragMove(area.id, $event)"
|
|
|
|
|
|
@dragEnd="onPanelDragEnd"
|
2025-11-04 10:53:22 +08:00
|
|
|
|
/>
|
|
|
|
|
|
</Area>
|
2025-11-04 09:10:15 +08:00
|
|
|
|
|
|
|
|
|
|
<!-- 主区域 -->
|
|
|
|
|
|
<Area
|
|
|
|
|
|
:WindowState="windowState"
|
|
|
|
|
|
:showTitleBar="false"
|
|
|
|
|
|
title="主区域"
|
|
|
|
|
|
:style="{ position: 'relative', zIndex: 1 }"
|
|
|
|
|
|
/>
|
2025-11-02 17:19:53 +07:00
|
|
|
|
</div>
|
2025-10-31 23:58:26 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2025-11-04 09:45:51 +08:00
|
|
|
|
import { ref, defineExpose, nextTick } from 'vue'
|
2025-10-31 23:58:26 +08:00
|
|
|
|
import Area from './Area.vue';
|
2025-11-02 17:06:40 +07:00
|
|
|
|
import Panel from './Panel.vue';
|
|
|
|
|
|
|
|
|
|
|
|
// 主区域状态
|
2025-11-01 14:23:35 +07:00
|
|
|
|
const windowState = ref('最大化')
|
2025-11-02 17:06:40 +07:00
|
|
|
|
|
2025-11-04 10:53:22 +08:00
|
|
|
|
// 浮动区域列表 - 每个area包含panels数组
|
2025-11-02 17:06:40 +07:00
|
|
|
|
const floatingAreas = ref([])
|
|
|
|
|
|
|
2025-11-04 09:45:51 +08:00
|
|
|
|
// 容器引用
|
|
|
|
|
|
const dockLayoutRef = ref(null)
|
|
|
|
|
|
|
2025-11-02 17:06:40 +07:00
|
|
|
|
// 区域ID计数器
|
|
|
|
|
|
let areaIdCounter = 1
|
|
|
|
|
|
|
2025-11-04 11:05:12 +08:00
|
|
|
|
// Panel拖拽相关状态
|
|
|
|
|
|
const panelDragState = ref({
|
|
|
|
|
|
isDragging: false,
|
|
|
|
|
|
currentAreaId: null,
|
|
|
|
|
|
startClientPos: { x: 0, y: 0 },
|
|
|
|
|
|
startAreaPos: { x: 0, y: 0 }
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2025-11-04 10:31:12 +08:00
|
|
|
|
// 添加新的浮动面板
|
|
|
|
|
|
const addFloatingPanel = () => {
|
2025-11-04 09:45:51 +08:00
|
|
|
|
// 获取父容器尺寸以计算居中位置
|
|
|
|
|
|
let x = 50 + (areaIdCounter - 2) * 20
|
|
|
|
|
|
let y = 50 + (areaIdCounter - 2) * 20
|
|
|
|
|
|
|
|
|
|
|
|
// 如果容器已渲染,计算居中位置
|
|
|
|
|
|
if (dockLayoutRef.value) {
|
|
|
|
|
|
const containerRect = dockLayoutRef.value.getBoundingClientRect()
|
|
|
|
|
|
const width = 300
|
|
|
|
|
|
const height = 250
|
|
|
|
|
|
x = Math.floor((containerRect.width - width) / 2)
|
|
|
|
|
|
y = Math.floor((containerRect.height - height) / 2)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-03 17:26:28 +08:00
|
|
|
|
// 创建新的Area组件配置
|
2025-11-02 17:06:40 +07:00
|
|
|
|
const newArea = {
|
|
|
|
|
|
id: `floating-area-${areaIdCounter++}`,
|
|
|
|
|
|
title: `浮动区域 ${areaIdCounter - 1}`,
|
2025-11-04 09:45:51 +08:00
|
|
|
|
x: x,
|
|
|
|
|
|
y: y,
|
2025-11-02 17:06:40 +07:00
|
|
|
|
width: 300,
|
2025-11-04 09:45:51 +08:00
|
|
|
|
height: 250,
|
2025-11-03 17:26:28 +08:00
|
|
|
|
WindowState: '正常',
|
2025-11-04 10:53:22 +08:00
|
|
|
|
showTitleBar: true,
|
|
|
|
|
|
// 添加一个Panel,填充满父容器
|
|
|
|
|
|
panels: [
|
2025-11-04 11:30:51 +08:00
|
|
|
|
{
|
|
|
|
|
|
id: `panel-${areaIdCounter - 1}-1`,
|
|
|
|
|
|
title: `面板 1`,
|
|
|
|
|
|
x: 0,
|
|
|
|
|
|
y: 0,
|
|
|
|
|
|
width: 100,
|
|
|
|
|
|
height: 100,
|
|
|
|
|
|
collapsed: false,
|
|
|
|
|
|
toolbarExpanded: false
|
|
|
|
|
|
}
|
|
|
|
|
|
]
|
2025-11-02 17:06:40 +07:00
|
|
|
|
}
|
|
|
|
|
|
floatingAreas.value.push(newArea)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-04 09:45:51 +08:00
|
|
|
|
// 更新区域位置
|
|
|
|
|
|
const onUpdatePosition = (id, position) => {
|
|
|
|
|
|
const area = floatingAreas.value.find(a => a.id === id)
|
|
|
|
|
|
if (area) {
|
|
|
|
|
|
area.x = position.left
|
|
|
|
|
|
area.y = position.top
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-02 17:06:40 +07:00
|
|
|
|
// 切换折叠状态
|
|
|
|
|
|
const onToggleCollapse = (id) => {
|
|
|
|
|
|
const area = floatingAreas.value.find(a => a.id === id)
|
|
|
|
|
|
if (area) {
|
|
|
|
|
|
area.collapsed = !area.collapsed
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 最大化/还原
|
2025-11-04 14:43:19 +08:00
|
|
|
|
const onMaximize = (panelId) => {
|
|
|
|
|
|
// 查找包含该面板的区域
|
|
|
|
|
|
for (const area of floatingAreas.value) {
|
|
|
|
|
|
if (area.panels && area.panels.length === 1 && area.panels[0].id === panelId) {
|
2025-11-04 15:17:37 +08:00
|
|
|
|
// 当区域只包含一个Panel时,切换Area和Panel的最大化状态
|
2025-11-04 16:16:22 +08:00
|
|
|
|
const isCurrentlyMaximized = area.WindowState === '最大化' || area.WindowState === 'maximized'
|
|
|
|
|
|
|
|
|
|
|
|
// 使用Vue推荐的方式更新响应式数据
|
|
|
|
|
|
if (isCurrentlyMaximized) {
|
|
|
|
|
|
// 切换为正常状态
|
2025-11-04 14:43:19 +08:00
|
|
|
|
area.WindowState = '正常'
|
2025-11-04 16:16:22 +08:00
|
|
|
|
// 确保Panel也恢复正常状态 - 使用展开运算符创建新对象确保响应式
|
|
|
|
|
|
area.panels[0] = { ...area.panels[0], maximized: false }
|
2025-11-04 14:43:19 +08:00
|
|
|
|
} else {
|
2025-11-04 16:16:22 +08:00
|
|
|
|
// 切换为最大化状态
|
2025-11-04 14:43:19 +08:00
|
|
|
|
area.WindowState = '最大化'
|
2025-11-04 16:16:22 +08:00
|
|
|
|
// 同时最大化Panel - 使用展开运算符创建新对象确保响应式
|
|
|
|
|
|
area.panels[0] = { ...area.panels[0], maximized: true }
|
2025-11-04 14:43:19 +08:00
|
|
|
|
}
|
2025-11-04 16:16:22 +08:00
|
|
|
|
|
2025-11-04 14:43:19 +08:00
|
|
|
|
console.log('Panel最大化按钮触发,切换Area状态:', area.WindowState)
|
2025-11-04 16:16:22 +08:00
|
|
|
|
console.log('Panel最大化状态:', area.panels[0].maximized)
|
2025-11-04 14:43:19 +08:00
|
|
|
|
break
|
|
|
|
|
|
}
|
2025-11-02 17:06:40 +07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-04 15:26:50 +08:00
|
|
|
|
// 关闭浮动区域 - 同时移除内容区的Panel
|
2025-11-02 17:06:40 +07:00
|
|
|
|
const onCloseFloatingArea = (id) => {
|
|
|
|
|
|
const index = floatingAreas.value.findIndex(a => a.id === id)
|
|
|
|
|
|
if (index !== -1) {
|
2025-11-04 15:26:50 +08:00
|
|
|
|
// 获取要移除的Area
|
|
|
|
|
|
const areaToRemove = floatingAreas.value[index]
|
|
|
|
|
|
|
|
|
|
|
|
// 清理Panel引用,确保Panel被正确移除
|
|
|
|
|
|
if (areaToRemove.panels) {
|
|
|
|
|
|
// 这里可以添加任何需要的Panel清理逻辑
|
|
|
|
|
|
console.log('移除Area时同步移除Panel:', areaToRemove.panels.map(p => p.id))
|
|
|
|
|
|
// 清空panels数组,确保Panel被正确移除
|
|
|
|
|
|
areaToRemove.panels = []
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 从数组中移除Area
|
2025-11-02 17:06:40 +07:00
|
|
|
|
floatingAreas.value.splice(index, 1)
|
2025-11-04 15:26:50 +08:00
|
|
|
|
console.log('成功关闭Area:', id)
|
2025-11-02 17:06:40 +07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-04 10:53:22 +08:00
|
|
|
|
// 关闭面板
|
|
|
|
|
|
const onClosePanel = (areaId, panelId) => {
|
|
|
|
|
|
const area = floatingAreas.value.find(a => a.id === areaId)
|
|
|
|
|
|
if (area && area.panels) {
|
|
|
|
|
|
const panelIndex = area.panels.findIndex(p => p.id === panelId)
|
|
|
|
|
|
if (panelIndex !== -1) {
|
|
|
|
|
|
area.panels.splice(panelIndex, 1)
|
|
|
|
|
|
|
|
|
|
|
|
// 如果区域内没有面板了,可以考虑关闭整个区域
|
|
|
|
|
|
if (area.panels.length === 0) {
|
|
|
|
|
|
onCloseFloatingArea(areaId)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-02 17:06:40 +07:00
|
|
|
|
// 切换工具栏
|
|
|
|
|
|
const onToggleToolbar = (id) => {
|
|
|
|
|
|
const area = floatingAreas.value.find(a => a.id === id)
|
|
|
|
|
|
if (area) {
|
|
|
|
|
|
area.toolbarExpanded = !area.toolbarExpanded
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-02 17:12:40 +07:00
|
|
|
|
|
2025-11-04 11:05:12 +08:00
|
|
|
|
// Panel拖拽开始
|
|
|
|
|
|
const onPanelDragStart = (areaId, event) => {
|
|
|
|
|
|
const area = floatingAreas.value.find(a => a.id === areaId)
|
|
|
|
|
|
// 只有当Area中只有一个Panel时才允许通过Panel标题栏移动Area
|
|
|
|
|
|
if (area && area.panels.length === 1) {
|
|
|
|
|
|
panelDragState.value.isDragging = true
|
|
|
|
|
|
panelDragState.value.currentAreaId = areaId
|
|
|
|
|
|
panelDragState.value.startClientPos = {
|
|
|
|
|
|
x: event.clientX,
|
|
|
|
|
|
y: event.clientY
|
|
|
|
|
|
}
|
|
|
|
|
|
panelDragState.value.startAreaPos = {
|
|
|
|
|
|
x: area.x,
|
|
|
|
|
|
y: area.y
|
|
|
|
|
|
}
|
2025-11-04 14:34:40 +08:00
|
|
|
|
console.log('Panel拖拽开始,移动Area:', areaId)
|
2025-11-04 11:05:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Panel拖拽移动
|
|
|
|
|
|
const onPanelDragMove = (areaId, event) => {
|
|
|
|
|
|
if (panelDragState.value.isDragging && panelDragState.value.currentAreaId === areaId) {
|
|
|
|
|
|
const area = floatingAreas.value.find(a => a.id === areaId)
|
|
|
|
|
|
if (area) {
|
|
|
|
|
|
// 计算移动距离
|
|
|
|
|
|
const deltaX = event.clientX - panelDragState.value.startClientPos.x
|
|
|
|
|
|
const deltaY = event.clientY - panelDragState.value.startClientPos.y
|
|
|
|
|
|
|
|
|
|
|
|
// 计算新位置
|
|
|
|
|
|
let newLeft = panelDragState.value.startAreaPos.x + deltaX
|
|
|
|
|
|
let newTop = panelDragState.value.startAreaPos.y + deltaY
|
|
|
|
|
|
|
|
|
|
|
|
// 确保不超出父容器边界
|
|
|
|
|
|
if (dockLayoutRef.value) {
|
|
|
|
|
|
const parentRect = dockLayoutRef.value.getBoundingClientRect()
|
|
|
|
|
|
|
|
|
|
|
|
// 严格边界检查
|
|
|
|
|
|
newLeft = Math.max(0, Math.min(newLeft, parentRect.width - area.width))
|
|
|
|
|
|
newTop = Math.max(0, Math.min(newTop, parentRect.height - area.height))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 更新位置
|
|
|
|
|
|
area.x = newLeft
|
|
|
|
|
|
area.y = newTop
|
2025-11-04 14:34:40 +08:00
|
|
|
|
|
|
|
|
|
|
// 调试信息
|
|
|
|
|
|
console.log('Panel拖拽移动,Area新位置:', { x: newLeft, y: newTop })
|
2025-11-04 11:05:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Panel拖拽结束
|
|
|
|
|
|
const onPanelDragEnd = () => {
|
2025-11-04 14:34:40 +08:00
|
|
|
|
console.log('Panel拖拽结束')
|
2025-11-04 11:05:12 +08:00
|
|
|
|
panelDragState.value.isDragging = false
|
|
|
|
|
|
panelDragState.value.currentAreaId = null
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-02 17:12:40 +07:00
|
|
|
|
// 暴露方法给父组件
|
|
|
|
|
|
defineExpose({
|
2025-11-04 10:31:12 +08:00
|
|
|
|
addFloatingPanel
|
2025-11-02 17:12:40 +07:00
|
|
|
|
})
|
2025-11-02 17:06:40 +07:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
.dock-layout {
|
|
|
|
|
|
position: relative;
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
height: 100%;
|
2025-11-04 09:10:15 +08:00
|
|
|
|
overflow: visible;
|
2025-11-02 17:06:40 +07:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-03 17:26:28 +08:00
|
|
|
|
/* 浮动区域样式已直接应用到Area组件 */
|
2025-11-02 17:19:53 +07:00
|
|
|
|
|
2025-11-02 17:06:40 +07:00
|
|
|
|
/* 添加浮动区域按钮样式 */
|
|
|
|
|
|
.add-floating-btn {
|
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
user-select: none;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.add-floating-btn:active {
|
|
|
|
|
|
transform: scale(0.98);
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|