Skip to content

Commit afd7aeb

Browse files
committed
fix: 修复了导出预览固定显示activeFormat的问题
1 parent 4a9ed82 commit afd7aeb

3 files changed

Lines changed: 35 additions & 23 deletions

File tree

src/components/panels/ExportFormatPanel.vue

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@
7171
class="icon-button"
7272
:class="{
7373
'is-active':
74-
windowStore.activeFocus ===
75-
fmt.formatId,
74+
previewedFormatIds.has(fmt.formatId),
7675
}"
7776
@click.stop="handleTogglePreview(fmt.formatId)"
7877
title="预览模板效果"
@@ -152,17 +151,28 @@
152151
</template>
153152

154153
<script setup lang="ts">
155-
import { ref } from 'vue';
154+
import { computed, ref } from 'vue';
156155
import { Plus, ChevronRight, Trash2, Check, Eye } from '@lucide/vue';
157-
import { useExportStore } from '@/stores/exportStore';
156+
import { EXPORT_PRESET_IDS, useExportStore } from '@/stores/exportStore';
158157
import { useWindowStore } from '@/stores/windowStore';
159158
160159
const exportStore = useExportStore();
161160
const windowStore = useWindowStore();
162161
const expandedId = ref<string | null>(exportStore.activeFormatId);
162+
const previewedFormatIds = computed(() => {
163+
const ids = new Set<string>();
164+
165+
for (const win of windowStore.openWindows.values()) {
166+
if (win.windowName === 'exportPreview') {
167+
ids.add(win.originalId);
168+
}
169+
}
170+
171+
return ids;
172+
});
163173
164174
function handleTogglePreview(formatId: string) {
165-
exportStore.activeFormatId = formatId;
175+
exportStore.setActive(formatId);
166176
windowStore.openExportPreview(formatId);
167177
}
168178
@@ -171,7 +181,7 @@ function toggleExpand(id: string) {
171181
}
172182
173183
function isPreset(id: string) {
174-
return ['standard', 'magic'].includes(id);
184+
return EXPORT_PRESET_IDS.includes(id as (typeof EXPORT_PRESET_IDS)[number]);
175185
}
176186
177187
function handleCreateFormat() {

src/components/workspace/ExportPreview.vue

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -180,27 +180,15 @@ const styleStore = useStyleStore();
180180
const exportStore = useExportStore();
181181
const uiStore = useUiStore();
182182
const windowStore = useWindowStore();
183-
const activeFormat = computed(() => exportStore.activeFormat);
184183
const props = defineProps<{
185184
windowId: string;
186185
originalId: string;
187186
}>();
188187
const effectiveWindowId = computed(() => props.windowId);
189188
const isActive = computed(() => windowStore.activeFocus === props.windowId);
190-
191-
// view的生命周期统一交给windowStore处理,不在组件层调用
192-
// onMounted(() => {
193-
// windowStore.registerWindow({
194-
// windowId: effectiveWindowId.value,
195-
// windowName: 'exportPreview',
196-
// windowType: 'view',
197-
// originalId: props.originalId,
198-
// });
199-
// });
200-
201-
// onUnmounted(() => {
202-
// windowStore.unregisterWindow(effectiveWindowId.value);
203-
// });
189+
const activeFormat = computed(
190+
() => exportStore.formatById(props.originalId) || exportStore.activeFormat,
191+
);
204192
205193
const canClose = computed(() => {
206194
return (

src/stores/exportStore.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@ import { defineStore } from 'pinia';
22
import type { ExportFormat } from '@/types/export';
33
import { generateId } from '@/utils/id';
44

5-
const PRESETS: ExportFormat[] = [
5+
export const EXPORT_PRESET_IDS = [
6+
'magic',
7+
'standard',
8+
'markdown',
9+
'classicTrpgLog',
10+
'hangingIndent',
11+
'echoWorkshop',
12+
] as const;
13+
14+
export const PRESETS: ExportFormat[] = [
615
{
716
formatId: 'magic',
817
formatName: '神人格式',
@@ -96,6 +105,10 @@ export const useExportStore = defineStore('export', {
96105
) || state.formats[0]
97106
);
98107
},
108+
formatById(state) {
109+
return (id: string): ExportFormat | undefined =>
110+
state.formats.find((f: ExportFormat) => f.formatId === id);
111+
},
99112
},
100113
actions: {
101114
createFormat() {
@@ -132,7 +145,8 @@ export const useExportStore = defineStore('export', {
132145
this.saveToLocal();
133146
},
134147
deleteFormat(id: string) {
135-
if (id === 'standard' || id === 'magic') return;
148+
if (EXPORT_PRESET_IDS.includes(id as (typeof EXPORT_PRESET_IDS)[number]))
149+
return;
136150
this.formats = this.formats.filter(
137151
(f: ExportFormat) => f.formatId !== id,
138152
);

0 commit comments

Comments
 (0)