Skip to content

Commit b355458

Browse files
authored
Merge pull request #5 from FreecellRaid/refactor-windowInstance
Refactor window instance
2 parents d67a312 + 4db94cc commit b355458

6 files changed

Lines changed: 213 additions & 279 deletions

File tree

src/components/workspace/ChunkView.vue

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<div
33
class="view"
44
:data-focus-id="effectiveWindowId"
5-
:class="{ 'is-active': windowStore.activeFocus === props.chunkId }"
6-
@pointerdown="windowStore.setFocus(props.chunkId)"
5+
:class="{ 'is-active': windowStore.activeFocus === effectiveWindowId }"
6+
@pointerdown="windowStore.setFocus(effectiveWindowId)"
77
>
88
<header class="view-header">
99
<div class="view-title">
@@ -54,7 +54,7 @@
5454
></div>
5555
<MessageItem
5656
:message="msg"
57-
:chunk-id="props.chunkId"
57+
:chunk-id="currentChunkId"
5858
:index="index"
5959
:is-selected="
6060
filterTool.selectedMessageIds.value.has(
@@ -90,7 +90,7 @@
9090

9191
<script setup lang="ts">
9292
import { FileText, X, SquareSplitHorizontal } from '@lucide/vue';
93-
import { computed, ref, onMounted } from 'vue';
93+
import { computed, ref } from 'vue';
9494
import { useLogStore } from '@/stores/logStore';
9595
import { useFilter } from '@/composables/useFilter';
9696
import { useMessageDragDrop } from '@/composables/useDragDrop';
@@ -102,10 +102,11 @@ import { useWindowStore } from '@/stores/windowStore';
102102
import type { Message } from '@/types/log';
103103
104104
const props = defineProps<{
105-
chunkId: string;
106-
windowId?: string;
105+
windowId: string;
106+
originalId: string;
107107
}>();
108-
const effectiveWindowId = computed(() => props.windowId ?? props.chunkId);
108+
const effectiveWindowId = computed(() => props.windowId);
109+
const currentChunkId = computed(() => props.originalId);
109110
const filterTool = useFilter(effectiveWindowId.value);
110111
const dragDropTool = useMessageDragDrop();
111112
const dropIndicatorIndex = ref<number | null>(null);
@@ -123,24 +124,26 @@ const canClose = computed(() => {
123124
);
124125
});
125126
126-
onMounted(() => {
127-
// 注册窗口时,显式传入 originalId
128-
// 将 split 窗口映射回原始 chunkId,从而共享选区
129-
windowStore.registerWindow({
130-
windowId: effectiveWindowId.value,
131-
windowName: 'chunkView',
132-
windowType: 'view',
133-
originalId: props.chunkId,
134-
});
135-
});
127+
// view的生命周期统一交给windowStore处理,不在组件层调用
128+
// onMounted(() => {
129+
// windowStore.registerWindow({
130+
// windowId: effectiveWindowId.value,
131+
// windowName: 'chunkView',
132+
// windowType: 'view',
133+
// originalId: currentChunkId.value,
134+
// });
135+
// });
136+
// onUnmounted(() => {
137+
// windowStore.unregisterWindow(effectiveWindowId.value);
138+
// });
136139
137140
function handleSplit() {
138-
windowStore.enterSplitMode('chunkView', props.chunkId);
141+
windowStore.enterSplitMode('chunkView', currentChunkId.value);
139142
}
140143
141144
function handleClose() {
142145
if (windowStore.splitMode === 'double') {
143-
windowStore.closePane();
146+
windowStore.closePane(effectiveWindowId.value);
144147
} else {
145148
windowStore.unregisterWindow(effectiveWindowId.value);
146149
// 如果还有其他打开的视图,聚焦到第一个可用的
@@ -157,10 +160,12 @@ function handleClose() {
157160
}
158161
}
159162
160-
const isViewFocused = computed(() => windowStore.activeFocus === props.chunkId);
163+
const isViewFocused = computed(
164+
() => windowStore.activeFocus === effectiveWindowId.value,
165+
);
161166
162167
const currentChunk = computed(function () {
163-
return logStore.findChunkById(props.chunkId) || undefined;
168+
return logStore.findChunkById(currentChunkId.value) || undefined;
164169
});
165170
166171
const messages = computed(function () {
@@ -177,7 +182,7 @@ function handleMessageSelect(event: MouseEvent, msgId: string, index: number) {
177182
}
178183
179184
function handleUpdateContent(messageId: string, newContent: string) {
180-
messageEditorStore.updateMessage(props.chunkId, messageId, {
185+
messageEditorStore.updateMessage(currentChunkId.value, messageId, {
181186
content: newContent,
182187
});
183188
}
@@ -226,25 +231,28 @@ function handleContainerDrop(event: DragEvent) {
226231
}
227232
228233
function handleActionInsert(msg: Message, index: number) {
229-
messageEditorStore.insertNewMessageAfter(props.chunkId, msg, index);
234+
messageEditorStore.insertNewMessageAfter(currentChunkId.value, msg, index);
230235
}
231236
232237
function handleActionMerge(msg: Message) {
233238
const selectedIds = filterTool.selectedMessageIds.value;
234239
if (selectedIds.has(msg.messageId) && selectedIds.size > 1) {
235240
messageEditorStore.mergeMessages(
236-
props.chunkId,
241+
currentChunkId.value,
237242
Array.from(selectedIds),
238243
msg.messageId,
239244
);
240245
filterTool.clearMessageSelection();
241246
} else {
242-
messageEditorStore.mergeWithNextMessage(props.chunkId, msg.messageId);
247+
messageEditorStore.mergeWithNextMessage(
248+
currentChunkId.value,
249+
msg.messageId,
250+
);
243251
}
244252
}
245253
246254
function handleActionSplit(msgId: string) {
247-
chunkEditorStore.splitChunk(props.chunkId, msgId);
255+
chunkEditorStore.splitChunk(currentChunkId.value, msgId);
248256
}
249257
250258
function handleActionDelete(msgId: string) {
@@ -253,7 +261,7 @@ function handleActionDelete(msgId: string) {
253261
messageEditorStore.batchDeleteMessages(selectedIds);
254262
filterTool.clearMessageSelection();
255263
} else {
256-
messageEditorStore.deleteMessage(props.chunkId, msgId);
264+
messageEditorStore.deleteMessage(currentChunkId.value, msgId);
257265
}
258266
}
259267
</script>

src/components/workspace/DefaultView.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ onMounted(() => {
4848
windowId: 'defaultView',
4949
windowName: 'defaultView',
5050
windowType: 'view',
51+
originalId: 'defaultView',
5152
});
5253
});
5354

src/components/workspace/ExportPreview.vue

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
:data-focus-id="effectiveWindowId"
55
:class="{
66
'preview-always-white': uiStore.exportPreviewAlwaysWhite,
7-
'is-active': windowStore.activeFocus === props.formatId,
7+
'is-active': isActive,
88
}"
9-
@pointerdown="windowStore.setFocus(props.formatId)"
9+
@pointerdown="windowStore.setFocus(props.windowId)"
1010
>
1111
<header class="view-header">
1212
<div class="view-title">
@@ -164,7 +164,7 @@
164164
</template>
165165

166166
<script setup lang="ts">
167-
import { computed, onMounted, onUnmounted } from 'vue';
167+
import { computed } from 'vue';
168168
import { Eye, X, SquareSplitHorizontal } from '@lucide/vue';
169169
import { useLogStore } from '@/stores/logStore';
170170
import { useStyleStore } from '@/stores/styleStore';
@@ -182,22 +182,25 @@ const uiStore = useUiStore();
182182
const windowStore = useWindowStore();
183183
const activeFormat = computed(() => exportStore.activeFormat);
184184
const props = defineProps<{
185-
formatId: string;
186-
windowId?: string;
185+
windowId: string;
186+
originalId: string;
187187
}>();
188-
const effectiveWindowId = computed(() => props.windowId ?? props.formatId);
188+
const effectiveWindowId = computed(() => props.windowId);
189+
const isActive = computed(() => windowStore.activeFocus === props.windowId);
189190
190-
onMounted(() => {
191-
windowStore.registerWindow({
192-
windowId: effectiveWindowId.value,
193-
windowName: 'exportPreview',
194-
windowType: 'view',
195-
});
196-
});
191+
// view的生命周期统一交给windowStore处理,不在组件层调用
192+
// onMounted(() => {
193+
// windowStore.registerWindow({
194+
// windowId: effectiveWindowId.value,
195+
// windowName: 'exportPreview',
196+
// windowType: 'view',
197+
// originalId: props.originalId,
198+
// });
199+
// });
197200
198-
onUnmounted(() => {
199-
windowStore.unregisterWindow(effectiveWindowId.value);
200-
});
201+
// onUnmounted(() => {
202+
// windowStore.unregisterWindow(effectiveWindowId.value);
203+
// });
201204
202205
const canClose = computed(() => {
203206
return (
@@ -208,12 +211,12 @@ const canClose = computed(() => {
208211
});
209212
210213
function handleSplit() {
211-
windowStore.enterSplitMode('exportPreview', props.formatId);
214+
windowStore.enterSplitMode('exportPreview', props.originalId);
212215
}
213216
214217
function handleClose() {
215218
if (windowStore.splitMode === 'double') {
216-
windowStore.closePane();
219+
windowStore.closePane(effectiveWindowId.value);
217220
} else {
218221
windowStore.unregisterWindow(effectiveWindowId.value);
219222

0 commit comments

Comments
 (0)