11<template >
22 <div class =" main-workspace" >
33 <FileImporter v-if =" isWorkspaceEmpty " />
4- <template v-else-if =" windowStore .splitMode === ' single' " >
5- <component
6- :is =" getViewComponent(currentActiveView.windowName)"
7- v-if =" currentActiveView"
8- :key =" currentActiveView.windowId"
9- v-bind =" getComponentProps(currentActiveView)"
10- />
11- <DefaultView v-else />
12- </template >
13-
144 <template v-else >
155 <div
166 class =" split-container"
177 :class =" {
188 'split-vertical': windowStore.splitDirection === 'vertical',
199 }"
2010 >
21- <div
22- class =" split-pane"
23- :style =" getPaneStyle(0)"
24- @pointerdown.capture =" handlePaneClick(0)"
25- >
26- <component
27- :is =" getViewComponent(leftPane.windowName)"
28- v-if =" leftPane"
29- :key =" leftPane.windowId"
30- v-bind =" getComponentProps(leftPane)"
31- />
32- </div >
33-
34- <div
35- v-if =" rightPane"
36- class =" split-resize-handle"
37- :class =" {
38- 'resize-vertical':
39- windowStore.splitDirection === 'vertical',
40- }"
41- @mousedown =" startResize"
42- ></div >
43-
44- <div
45- class =" split-pane"
46- :style =" getPaneStyle(1)"
47- @pointerdown.capture =" handlePaneClick(1)"
48- >
49- <component
50- :is =" getViewComponent(rightPane.windowName)"
51- v-if =" rightPane"
52- :key =" rightPane.windowId"
53- v-bind =" getComponentProps(rightPane)"
54- />
55- </div >
11+ <template v-for =" pane in workspacePanes " :key =" pane .paneIndex " >
12+ <div
13+ class =" split-pane"
14+ :style =" getPaneStyle(pane.paneIndex)"
15+ @pointerdown.capture =" handlePaneClick(pane.paneIndex)"
16+ >
17+ <component
18+ :is =" getViewComponent(pane.instance?.windowName)"
19+ v-if =" pane.instance"
20+ :key =" pane.instance.windowId"
21+ v-bind =" getComponentProps(pane.instance)"
22+ />
23+ <DefaultView v-else />
24+ </div >
25+
26+ <div
27+ v-if =" shouldRenderResizeHandle(pane.paneIndex)"
28+ class =" split-resize-handle"
29+ :class =" {
30+ 'resize-vertical':
31+ windowStore.splitDirection === 'vertical',
32+ }"
33+ @mousedown =" startResize"
34+ ></div >
35+ </template >
5636 </div >
5737 </template >
5838 </div >
5939</template >
6040
6141<script setup lang="ts">
62- import { computed , ref } from ' vue' ;
42+ import { computed } from ' vue' ;
6343import { useLogStore } from ' @/stores/logStore' ;
6444import { useWindowStore } from ' @/stores/windowStore' ;
6545import type { WindowInstance , WindowName } from ' @/types/window' ;
@@ -71,13 +51,7 @@ import DefaultView from './DefaultView.vue';
7151const logStore = useLogStore ();
7252const windowStore = useWindowStore ();
7353const isWorkspaceEmpty = computed (() => logStore .documents .length === 0 );
74- const currentActiveView = computed (() => windowStore .currentActiveView );
75-
76- // 分屏数据映射
77- const leftPane = computed (() => windowStore .splitPanes [0 ]);
78- const rightPane = computed (() => windowStore .splitPanes [1 ]);
79-
80- const splitSizes = ref <[number , number ]>(windowStore .splitSizes );
54+ const workspacePanes = computed (() => windowStore .workspacePanes );
8155
8256const viewComponentMap: Partial <Record <WindowName , any >> = {
8357 chunkView: ChunkView ,
@@ -86,7 +60,8 @@ const viewComponentMap: Partial<Record<WindowName, any>> = {
8660};
8761
8862// 根据 WindowName 获取对应的 Vue 组件
89- function getViewComponent(name : WindowName ) {
63+ function getViewComponent(name ? : WindowName ) {
64+ if (! name ) return DefaultView ;
9065 return viewComponentMap [name ] || DefaultView ;
9166}
9267
@@ -99,28 +74,35 @@ function getComponentProps(instance: WindowInstance) {
9974
10075function getPaneStyle(index : 0 | 1 ): Record <string , string > {
10176 const isHorizontal = windowStore .splitDirection === ' horizontal' ;
102- const size = splitSizes .value [index ];
77+ const size =
78+ workspacePanes .value .length === 1 ? 100 : windowStore .splitSizes [index ];
10379
10480 return isHorizontal
10581 ? { width: ` ${size }% ` , height: ' 100%' }
10682 : { width: ' 100%' , height: ` ${size }% ` };
10783}
10884
10985function handlePaneClick(paneIndex : 0 | 1 ) {
110- const pane = paneIndex === 0 ? leftPane .value : rightPane .value ;
111- if (pane ) {
112- windowStore .setFocus (pane .windowId );
86+ const pane = workspacePanes .value .find (
87+ (item ) => item .paneIndex === paneIndex ,
88+ );
89+ if (pane ?.instance ) {
90+ windowStore .setFocus (pane .instance .windowId );
11391 }
11492}
11593
94+ function shouldRenderResizeHandle(paneIndex : 0 | 1 ) {
95+ return paneIndex < workspacePanes .value .length - 1 ;
96+ }
97+
11698function startResize(e : MouseEvent ) {
11799 e .preventDefault ();
118100 const isHorizontal = windowStore .splitDirection === ' horizontal' ;
119101 const container = (e .target as HTMLElement ).parentElement ;
120102 if (! container ) return ;
121103
122104 const startPos = isHorizontal ? e .clientX : e .clientY ;
123- const startSizes = [... splitSizes . value ];
105+ const startSizes = [... windowStore . splitSizes ];
124106 const containerSize = isHorizontal
125107 ? container .clientWidth
126108 : container .clientHeight ;
@@ -136,8 +118,6 @@ function startResize(e: MouseEvent) {
136118 Math .max (20 , startSizes [0 ] + deltaPercent ),
137119 );
138120 const newRightSize = 100 - newLeftSize ;
139-
140- splitSizes .value = [newLeftSize , newRightSize ];
141121 windowStore .splitSizes = [newLeftSize , newRightSize ];
142122 }
143123
0 commit comments