✨ Add multi-window document functionality
This commit is contained in:
@@ -95,26 +95,40 @@ const CONFIG_LIMITS = {
|
||||
tabType: {values: [TabType.TabTypeSpaces, TabType.TabTypeTab], default: TabType.TabTypeSpaces}
|
||||
} as const;
|
||||
|
||||
// 常用字体选项
|
||||
export const FONT_OPTIONS = [
|
||||
// 创建获取翻译的函数
|
||||
export const createFontOptions = (t: (key: string) => string) => [
|
||||
{
|
||||
label: '鸿蒙字体',
|
||||
label: t('settings.fontFamilies.harmonyOS'),
|
||||
value: '"HarmonyOS Sans SC", "HarmonyOS Sans", "Microsoft YaHei", "PingFang SC", "Helvetica Neue", Arial, sans-serif'
|
||||
},
|
||||
{label: '微软雅黑', value: '"Microsoft YaHei", "PingFang SC", "Helvetica Neue", Arial, sans-serif'},
|
||||
{label: '苹方字体', value: '"PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif'},
|
||||
{
|
||||
label: 'JetBrains Mono',
|
||||
label: t('settings.fontFamilies.microsoftYahei'),
|
||||
value: '"Microsoft YaHei", "PingFang SC", "Helvetica Neue", Arial, sans-serif'
|
||||
},
|
||||
{
|
||||
label: t('settings.fontFamilies.pingfang'),
|
||||
value: '"PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif'
|
||||
},
|
||||
{
|
||||
label: t('settings.fontFamilies.jetbrainsMono'),
|
||||
value: '"JetBrains Mono", "Fira Code", "SF Mono", Monaco, Consolas, "Ubuntu Mono", monospace'
|
||||
},
|
||||
{label: 'Fira Code', value: '"Fira Code", "JetBrains Mono", "SF Mono", Monaco, Consolas, "Ubuntu Mono", monospace'},
|
||||
{label: 'Source Code Pro', value: '"Source Code Pro", "SF Mono", Monaco, Consolas, "Ubuntu Mono", monospace'},
|
||||
{label: 'Cascadia Code', value: '"Cascadia Code", "SF Mono", Monaco, Consolas, "Ubuntu Mono", monospace'},
|
||||
{
|
||||
label: '系统等宽字体',
|
||||
value: '"SF Mono", Monaco, "Cascadia Code", "Roboto Mono", Consolas, "Courier New", monospace'
|
||||
label: t('settings.fontFamilies.firaCode'),
|
||||
value: '"Fira Code", "JetBrains Mono", "SF Mono", Monaco, Consolas, "Ubuntu Mono", monospace'
|
||||
},
|
||||
{
|
||||
label: t('settings.fontFamilies.sourceCodePro'),
|
||||
value: '"Source Code Pro", "SF Mono", Monaco, Consolas, "Ubuntu Mono", monospace'
|
||||
},
|
||||
{
|
||||
label: t('settings.fontFamilies.cascadiaCode'),
|
||||
value: '"Cascadia Code", "SF Mono", Monaco, Consolas, "Ubuntu Mono", monospace'
|
||||
}
|
||||
] as const;
|
||||
];
|
||||
|
||||
// 常用字体选项
|
||||
export const FONT_OPTIONS = createFontOptions((key) => key);
|
||||
|
||||
// 获取浏览器的默认语言
|
||||
const getBrowserLanguage = (): SupportedLocaleType => {
|
||||
@@ -184,7 +198,7 @@ const DEFAULT_CONFIG: AppConfig = {
|
||||
|
||||
|
||||
export const useConfigStore = defineStore('config', () => {
|
||||
const {locale} = useI18n();
|
||||
const {locale, t} = useI18n();
|
||||
|
||||
// 响应式状态
|
||||
const state = reactive({
|
||||
@@ -192,6 +206,9 @@ export const useConfigStore = defineStore('config', () => {
|
||||
isLoading: false,
|
||||
configLoaded: false
|
||||
});
|
||||
|
||||
// 初始化FONT_OPTIONS国际化版本
|
||||
const localizedFontOptions = computed(() => createFontOptions(t));
|
||||
|
||||
// 计算属性 - 使用工厂函数简化
|
||||
const createLimitComputed = (key: NumberConfigKey) => computed(() => CONFIG_LIMITS[key]);
|
||||
@@ -394,7 +411,8 @@ export const useConfigStore = defineStore('config', () => {
|
||||
config: computed(() => state.config),
|
||||
configLoaded: computed(() => state.configLoaded),
|
||||
isLoading: computed(() => state.isLoading),
|
||||
|
||||
localizedFontOptions,
|
||||
|
||||
// 限制常量
|
||||
...limits,
|
||||
|
||||
|
@@ -1,6 +1,7 @@
|
||||
import {defineStore} from 'pinia';
|
||||
import {computed, ref} from 'vue';
|
||||
import {DocumentService} from '@/../bindings/voidraft/internal/services';
|
||||
import {OpenDocumentWindow} from '@/../bindings/voidraft/internal/services/windowservice';
|
||||
import {Document} from '@/../bindings/voidraft/internal/models/models';
|
||||
|
||||
const SCRATCH_DOCUMENT_ID = 1; // 默认草稿文档ID
|
||||
@@ -50,6 +51,17 @@ export const useDocumentStore = defineStore('document', () => {
|
||||
|
||||
// === 公共API ===
|
||||
|
||||
// 在新窗口中打开文档
|
||||
const openDocumentInNewWindow = async (docId: number): Promise<boolean> => {
|
||||
try {
|
||||
await OpenDocumentWindow(docId);
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Failed to open document in new window:', error);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// 更新文档列表
|
||||
const updateDocuments = async () => {
|
||||
try {
|
||||
@@ -186,12 +198,15 @@ export const useDocumentStore = defineStore('document', () => {
|
||||
};
|
||||
|
||||
// === 初始化 ===
|
||||
const initialize = async (): Promise<void> => {
|
||||
const initialize = async (urlDocumentId?: number): Promise<void> => {
|
||||
try {
|
||||
await updateDocuments();
|
||||
|
||||
// 如果存在持久化的文档ID,尝试打开该文档
|
||||
if (currentDocumentId.value && documents.value[currentDocumentId.value]) {
|
||||
// 优先使用URL参数中的文档ID
|
||||
if (urlDocumentId && documents.value[urlDocumentId]) {
|
||||
await openDocument(urlDocumentId);
|
||||
} else if (currentDocumentId.value && documents.value[currentDocumentId.value]) {
|
||||
// 如果URL中没有指定文档ID,则使用持久化的文档ID
|
||||
await openDocument(currentDocumentId.value);
|
||||
} else {
|
||||
// 否则获取第一个文档ID并打开
|
||||
@@ -218,6 +233,7 @@ export const useDocumentStore = defineStore('document', () => {
|
||||
// 方法
|
||||
updateDocuments,
|
||||
openDocument,
|
||||
openDocumentInNewWindow,
|
||||
createNewDocument,
|
||||
saveNewDocument,
|
||||
updateDocumentMetadata,
|
||||
@@ -232,4 +248,4 @@ export const useDocumentStore = defineStore('document', () => {
|
||||
storage: localStorage,
|
||||
pick: ['currentDocumentId']
|
||||
}
|
||||
});
|
||||
});
|
31
frontend/src/stores/windowStore.ts
Normal file
31
frontend/src/stores/windowStore.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import {computed} from 'vue';
|
||||
import {defineStore} from 'pinia';
|
||||
import {IsDocumentWindowOpen} from "@/../bindings/voidraft/internal/services/windowservice";
|
||||
|
||||
|
||||
export const useWindowStore = defineStore('window', () => {
|
||||
// 判断是否为主窗口
|
||||
const isMainWindow = computed(() => {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
return !urlParams.has('documentId');
|
||||
});
|
||||
|
||||
// 获取当前窗口的documentId
|
||||
const currentDocumentId = computed(() => {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
return urlParams.get('documentId');
|
||||
});
|
||||
/**
|
||||
* 判断文档窗口是否打开
|
||||
* @param documentId 文档ID
|
||||
*/
|
||||
async function isDocumentWindowOpen(documentId: number) {
|
||||
return IsDocumentWindowOpen(documentId);
|
||||
}
|
||||
|
||||
return {
|
||||
isMainWindow,
|
||||
currentDocumentId,
|
||||
isDocumentWindowOpen
|
||||
};
|
||||
});
|
Reference in New Issue
Block a user