🐛 Fixed some issues
This commit is contained in:
@@ -35,10 +35,7 @@ const toggleAlwaysOnTop = async () => {
|
||||
|
||||
// 跳转到设置页面
|
||||
const goToSettings = () => {
|
||||
router.push({
|
||||
path: '/settings',
|
||||
query: { documentId: documentStore.currentDocumentId || undefined }
|
||||
});
|
||||
router.push('/settings');
|
||||
};
|
||||
|
||||
// 执行格式化
|
||||
|
@@ -4,7 +4,10 @@ import '@/assets/styles/index.css';
|
||||
import {createPinia} from 'pinia';
|
||||
import i18n from './i18n';
|
||||
import router from './router';
|
||||
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
|
||||
|
||||
const pinia = createPinia()
|
||||
pinia.use(piniaPluginPersistedstate)
|
||||
const app = createApp(App);
|
||||
app.use(pinia)
|
||||
app.use(i18n);
|
||||
|
@@ -12,15 +12,13 @@ const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
path: '/',
|
||||
name: 'Editor',
|
||||
component: Editor,
|
||||
props: route => ({ documentId: route.query.documentId ? Number(route.query.documentId) : null })
|
||||
component: Editor
|
||||
},
|
||||
{
|
||||
path: '/settings',
|
||||
name: 'Settings',
|
||||
redirect: '/settings/general',
|
||||
component: Settings,
|
||||
props: route => ({ returnDocumentId: route.query.documentId ? Number(route.query.documentId) : null }),
|
||||
children: [
|
||||
{
|
||||
path: 'general',
|
||||
|
@@ -190,10 +190,15 @@ export const useDocumentStore = defineStore('document', () => {
|
||||
try {
|
||||
await updateDocuments();
|
||||
|
||||
// 获取第一个文档ID并打开
|
||||
const firstDocId = await DocumentService.GetFirstDocumentID();
|
||||
if (firstDocId && documents.value[firstDocId]) {
|
||||
await openDocument(firstDocId);
|
||||
// 如果存在持久化的文档ID,尝试打开该文档
|
||||
if (currentDocumentId.value && documents.value[currentDocumentId.value]) {
|
||||
await openDocument(currentDocumentId.value);
|
||||
} else {
|
||||
// 否则获取第一个文档ID并打开
|
||||
const firstDocId = await DocumentService.GetFirstDocumentID();
|
||||
if (firstDocId && documents.value[firstDocId]) {
|
||||
await openDocument(firstDocId);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to initialize document store:', error);
|
||||
@@ -221,4 +226,10 @@ export const useDocumentStore = defineStore('document', () => {
|
||||
closeDialog,
|
||||
initialize,
|
||||
};
|
||||
}, {
|
||||
persist: {
|
||||
key: 'voidraft-document',
|
||||
storage: localStorage,
|
||||
pick: ['currentDocumentId']
|
||||
}
|
||||
});
|
@@ -6,11 +6,6 @@ import {useConfigStore} from '@/stores/configStore';
|
||||
import {createWheelZoomHandler} from './basic/wheelZoomExtension';
|
||||
import Toolbar from '@/components/toolbar/Toolbar.vue';
|
||||
|
||||
// 接收路由传入的文档ID
|
||||
const props = defineProps<{
|
||||
documentId?: number | null
|
||||
}>();
|
||||
|
||||
const editorStore = useEditorStore();
|
||||
const documentStore = useDocumentStore();
|
||||
const configStore = useConfigStore();
|
||||
@@ -26,13 +21,9 @@ const wheelHandler = createWheelZoomHandler(
|
||||
onMounted(async () => {
|
||||
if (!editorElement.value) return;
|
||||
|
||||
// 初始化文档存储,会自动使用持久化的文档ID
|
||||
await documentStore.initialize();
|
||||
|
||||
// 如果有指定文档ID,则打开该文档
|
||||
if (props.documentId) {
|
||||
await documentStore.openDocument(props.documentId);
|
||||
}
|
||||
|
||||
// 设置编辑器容器
|
||||
editorStore.setEditorContainer(editorElement.value);
|
||||
|
||||
@@ -46,13 +37,6 @@ onBeforeUnmount(() => {
|
||||
editorElement.value.removeEventListener('wheel', wheelHandler);
|
||||
}
|
||||
});
|
||||
|
||||
// 监听文档ID变化
|
||||
watch(() => props.documentId, async (newDocId) => {
|
||||
if (newDocId && documentStore.currentDocumentId !== newDocId) {
|
||||
await documentStore.openDocument(newDocId);
|
||||
}
|
||||
}, { immediate: true });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
@@ -8,11 +8,6 @@ const { t } = useI18n();
|
||||
const router = useRouter();
|
||||
const route = useRoute();
|
||||
|
||||
// 接收路由传入的参数
|
||||
const props = defineProps<{
|
||||
returnDocumentId?: number | null
|
||||
}>();
|
||||
|
||||
// 导航配置
|
||||
const navItems = [
|
||||
{ id: 'general', icon: '⚙️', route: '/settings/general' },
|
||||
@@ -33,15 +28,7 @@ const handleNavClick = (item: typeof navItems[0]) => {
|
||||
|
||||
// 返回编辑器
|
||||
const goBackToEditor = async () => {
|
||||
// 如果有返回文档ID,则传递参数
|
||||
if (props.returnDocumentId) {
|
||||
await router.push({
|
||||
path: '/',
|
||||
query: { documentId: props.returnDocumentId }
|
||||
});
|
||||
} else {
|
||||
await router.push('/');
|
||||
}
|
||||
await router.push('/');
|
||||
};
|
||||
|
||||
</script>
|
||||
|
Reference in New Issue
Block a user