feat: add export settings for Word document generation
- Add export configuration (untranslated text color, page orientation) - Add second page header option for multi-page exports - Integrate export settings into main export flow - Separate export settings page with visual preview
This commit is contained in:
@@ -15,9 +15,19 @@ export interface AIConfig {
|
||||
model: string;
|
||||
}
|
||||
|
||||
export interface ExportConfig {
|
||||
// 未翻译文本的颜色 (hex)
|
||||
untranslatedColor: string;
|
||||
// 第二页是否显示表头
|
||||
secondPageHeader: boolean;
|
||||
// 页面方向: portrait | landscape
|
||||
orientation: "portrait" | "landscape";
|
||||
}
|
||||
|
||||
export interface AppConfig {
|
||||
db: DBConfig;
|
||||
ai: AIConfig;
|
||||
export: ExportConfig;
|
||||
}
|
||||
|
||||
// 配置文件路径(单一文件)
|
||||
@@ -101,6 +111,29 @@ export function getAIConfig(): AIConfig {
|
||||
return { apiKey, baseUrl, model };
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取导出配置
|
||||
* 优先级:config.json(没有环境变量)
|
||||
*/
|
||||
export function getExportConfig(): ExportConfig {
|
||||
const defaultConfig: ExportConfig = {
|
||||
untranslatedColor: "CC0000",
|
||||
secondPageHeader: false,
|
||||
orientation: "landscape",
|
||||
};
|
||||
|
||||
const fileConfig = readConfigFile();
|
||||
if (fileConfig.export) {
|
||||
return {
|
||||
untranslatedColor: fileConfig.export.untranslatedColor || defaultConfig.untranslatedColor,
|
||||
secondPageHeader: fileConfig.export.secondPageHeader ?? defaultConfig.secondPageHeader,
|
||||
orientation: fileConfig.export.orientation || defaultConfig.orientation,
|
||||
};
|
||||
}
|
||||
|
||||
return defaultConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取完整配置(兼容旧接口)
|
||||
*/
|
||||
@@ -108,6 +141,7 @@ export function getConfig(): AppConfig {
|
||||
return {
|
||||
db: getDBConfig(),
|
||||
ai: getAIConfig(),
|
||||
export: getExportConfig(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -129,6 +163,7 @@ export function saveDBConfig(config: Partial<DBConfig>): DBConfig {
|
||||
const fileConfig = readConfigFile();
|
||||
const updatedConfig: AppConfig = {
|
||||
ai: fileConfig.ai ?? { apiKey: "", baseUrl: "https://api.openai.com/v1", model: "gpt-3.5-turbo" },
|
||||
export: fileConfig.export ?? { untranslatedColor: "CC0000", secondPageHeader: false, orientation: "landscape" },
|
||||
db: newConfig,
|
||||
};
|
||||
writeConfigFile(updatedConfig);
|
||||
@@ -152,6 +187,7 @@ export function saveAIConfig(config: Partial<AIConfig>): AIConfig {
|
||||
const fileConfig = readConfigFile();
|
||||
const updatedConfig: AppConfig = {
|
||||
db: fileConfig.db ?? { host: "127.0.0.1", port: 3306, user: "root", password: "", database: "recipe_tools" },
|
||||
export: fileConfig.export ?? { untranslatedColor: "CC0000", secondPageHeader: false, orientation: "landscape" },
|
||||
ai: newConfig,
|
||||
};
|
||||
writeConfigFile(updatedConfig);
|
||||
@@ -159,6 +195,30 @@ export function saveAIConfig(config: Partial<AIConfig>): AIConfig {
|
||||
return newConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存导出配置
|
||||
*/
|
||||
export function saveExportConfig(config: Partial<ExportConfig>): ExportConfig {
|
||||
const current = getExportConfig();
|
||||
|
||||
const newConfig: ExportConfig = {
|
||||
untranslatedColor: config.untranslatedColor ?? current.untranslatedColor,
|
||||
secondPageHeader: config.secondPageHeader ?? current.secondPageHeader,
|
||||
orientation: config.orientation ?? current.orientation,
|
||||
};
|
||||
|
||||
// 读取现有配置,更新 export 部分
|
||||
const fileConfig = readConfigFile();
|
||||
const updatedConfig: AppConfig = {
|
||||
db: fileConfig.db ?? { host: "127.0.0.1", port: 3306, user: "root", password: "", database: "recipe_tools" },
|
||||
ai: fileConfig.ai ?? { apiKey: "", baseUrl: "https://api.openai.com/v1", model: "gpt-3.5-turbo" },
|
||||
export: newConfig,
|
||||
};
|
||||
writeConfigFile(updatedConfig);
|
||||
|
||||
return newConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存完整配置(兼容旧接口)
|
||||
*/
|
||||
@@ -169,5 +229,6 @@ export function saveConfig(config: Partial<AppConfig>): AppConfig {
|
||||
return {
|
||||
db: config.db ? saveDBConfig(config.db) : current.db,
|
||||
ai: config.ai ? saveAIConfig(config.ai) : current.ai,
|
||||
export: config.export ? saveExportConfig(config.export) : current.export,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user