diff --git a/packages/backend/src/repositories/appearance.repository.ts b/packages/backend/src/repositories/appearance.repository.ts index 6c69e47..c772ec8 100644 --- a/packages/backend/src/repositories/appearance.repository.ts +++ b/packages/backend/src/repositories/appearance.repository.ts @@ -49,6 +49,9 @@ let terminalTextStrokeEnabledFound = false; case 'terminalFontSize': settings.terminalFontSize = parseInt(row.value, 10); break; + case 'terminalFontSizeMobile': + settings.terminalFontSizeMobile = parseInt(row.value, 10); + break; case 'editorFontSize': settings.editorFontSize = parseInt(row.value, 10); break; @@ -117,6 +120,7 @@ case 'terminalTextStrokeEnabled': activeTerminalThemeId: settings.activeTerminalThemeId ?? defaults.activeTerminalThemeId, terminalFontFamily: settings.terminalFontFamily ?? defaults.terminalFontFamily, terminalFontSize: settings.terminalFontSize ?? defaults.terminalFontSize, + terminalFontSizeMobile: settings.terminalFontSizeMobile ?? defaults.terminalFontSizeMobile, editorFontSize: settings.editorFontSize ?? defaults.editorFontSize, editorFontFamily: settings.editorFontFamily ?? defaults.editorFontFamily, terminalBackgroundImage: settings.terminalBackgroundImage ?? defaults.terminalBackgroundImage, @@ -166,6 +170,7 @@ const getDefaultAppearanceSettings = (): Omit => { activeTerminalThemeId: null, // 初始默认应为 null terminalFontFamily: 'Consolas, "Courier New", monospace, "Microsoft YaHei", "微软雅黑"', terminalFontSize: 14, + terminalFontSizeMobile: 14, // 移动端默认字体大小 editorFontSize: 14, editorFontFamily: 'Consolas, "Noto Sans SC", "Microsoft YaHei"', terminalBackgroundImage: undefined, @@ -206,6 +211,7 @@ export const ensureDefaultSettingsExist = async (db: sqlite3.Database): Promise< { key: 'activeTerminalThemeId', value: null }, // 以 null 开始 { key: 'terminalFontFamily', value: defaults.terminalFontFamily }, { key: 'terminalFontSize', value: defaults.terminalFontSize }, + { key: 'terminalFontSizeMobile', value: defaults.terminalFontSizeMobile }, { key: 'editorFontSize', value: defaults.editorFontSize }, { key: 'editorFontFamily', value: defaults.editorFontFamily }, { key: 'terminalBackgroundImage', value: defaults.terminalBackgroundImage ?? '' }, // 数据库中使用空字符串 diff --git a/packages/backend/src/services/appearance.service.ts b/packages/backend/src/services/appearance.service.ts index f3d429d..ad82e08 100644 --- a/packages/backend/src/services/appearance.service.ts +++ b/packages/backend/src/services/appearance.service.ts @@ -94,6 +94,16 @@ export const updateSettings = async (settingsDto: UpdateAppearanceDto): Promise< settingsDto.terminalFontSize = size; } + // 验证 terminalFontSizeMobile (如果提供了) + if (settingsDto.terminalFontSizeMobile !== undefined && settingsDto.terminalFontSizeMobile !== null) { + const size = Number(settingsDto.terminalFontSizeMobile); + if (isNaN(size) || size <= 0) { + throw new Error(`无效的移动端终端字体大小: ${settingsDto.terminalFontSizeMobile}。必须是一个正数。`); + } + // 确保类型正确传递给仓库层 + settingsDto.terminalFontSizeMobile = size; + } + // 验证 editorFontSize (如果提供了) if (settingsDto.editorFontSize !== undefined && settingsDto.editorFontSize !== null) { const size = Number(settingsDto.editorFontSize); diff --git a/packages/backend/src/types/appearance.types.ts b/packages/backend/src/types/appearance.types.ts index 423e1e3..5d39ffb 100644 --- a/packages/backend/src/types/appearance.types.ts +++ b/packages/backend/src/types/appearance.types.ts @@ -13,6 +13,7 @@ export interface AppearanceSettings { activeTerminalThemeId?: number | null; // 修改为数字 ID 或 null terminalFontFamily?: string; // 终端字体列表字符串 terminalFontSize?: number; // 终端字体大小 (px) + terminalFontSizeMobile?: number; // 移动端终端字体大小 (px) terminalBackgroundImage?: string; // 终端背景图片 URL 或路径 pageBackgroundImage?: string; // 页面背景图片 URL 或路径 editorFontSize?: number; // 编辑器字体大小 (px)