🎨 Optimize code & Upgrade dependencies

This commit is contained in:
2026-01-01 02:27:21 +08:00
parent 9ec22add55
commit 76f6c30b9d
17 changed files with 316 additions and 1247 deletions

View File

@@ -7,7 +7,7 @@
v-for="tab in tabStore.tabs"
:key="tab.documentId"
:tab="tab"
:isActive="tab.documentId === tabStore.currentDocumentId"
:isActive="tab.documentId === documentStore.currentDocumentId"
:canClose="tabStore.canCloseTab"
@click="switchToTab"
@close="closeTab"
@@ -35,8 +35,12 @@ import { ref, onMounted, onUnmounted, watch, nextTick } from 'vue';
import TabItem from './TabItem.vue';
import TabContextMenu from './TabContextMenu.vue';
import { useTabStore } from '@/stores/tabStore';
import { useDocumentStore } from '@/stores/documentStore';
import { useEditorStore } from '@/stores/editorStore';
const tabStore = useTabStore();
const documentStore = useDocumentStore();
const editorStore = useEditorStore();
// DOM 引用
const tabBarRef = ref<HTMLElement>();
@@ -50,8 +54,17 @@ const contextMenuTargetId = ref<number | null>(null);
// 标签页操作
const switchToTab = (documentId: number) => {
tabStore.switchToTabAndDocument(documentId);
const switchToTab = async (documentId: number) => {
await tabStore.switchToTabAndDocument(documentId);
const doc = documentStore.currentDocument;
if (doc && doc.id !== undefined && editorStore.hasContainer) {
await editorStore.loadEditor(doc.id, doc.content || '');
}
if (doc && tabStore.isTabsEnabled) {
tabStore.addOrActivateTab(doc);
}
};
const closeTab = (documentId: number) => {
@@ -150,7 +163,7 @@ onUnmounted(() => {
});
// 监听当前活跃标签页的变化
watch(() => tabStore.currentDocumentId, () => {
watch(() => documentStore.currentDocumentId, () => {
scrollToActiveTab();
});

View File

@@ -2,6 +2,7 @@
import {computed, nextTick, reactive, ref, watch} from 'vue';
import {useDocumentStore} from '@/stores/documentStore';
import {useTabStore} from '@/stores/tabStore';
import {useEditorStore} from '@/stores/editorStore';
import {useWindowStore} from '@/stores/windowStore';
import {useI18n} from 'vue-i18n';
import {useConfirm} from '@/composables';
@@ -16,6 +17,7 @@ interface DocumentItem extends Document {
const documentStore = useDocumentStore();
const tabStore = useTabStore();
const editorStore = useEditorStore();
const windowStore = useWindowStore();
const {t} = useI18n();
@@ -103,13 +105,20 @@ const selectDoc = async (doc: Document) => {
return;
}
const success = await documentStore.openDocument(doc.id);
if (success) {
if (tabStore.isTabsEnabled) {
tabStore.addOrActivateTab(doc);
}
closeMenu();
if (!success) return;
const fullDoc = documentStore.currentDocument;
if (fullDoc && editorStore.hasContainer) {
await editorStore.loadEditor(fullDoc.id!, fullDoc.content || '');
}
if (fullDoc && tabStore.isTabsEnabled) {
tabStore.addOrActivateTab(fullDoc);
}
closeMenu();
};
const createDoc = async (title: string) => {
@@ -190,6 +199,10 @@ const openInNewWindow = async (doc: Document, event: Event) => {
event.stopPropagation();
if (doc.id === undefined) return;
try {
// 在打开新窗口前,如果启用了标签且该文档有标签,先关闭标签
if (tabStore.isTabsEnabled && tabStore.hasTab(doc.id)) {
await tabStore.closeTab(doc.id);
}
await documentStore.openDocumentInNewWindow(doc.id);
} catch (error) {
console.error('Failed to open document in new window:', error);