feat: 重构布局与模型配置

- 写作范式分析页面改为左中右三栏布局
- 范式分段写作页面改为左中右三栏布局
- 模型设置移至设置中心,支持多服务商选择
- API 配置通过 .env 文件管理,提升安全性
- 支持 DeepSeek、OpenAI、Claude、自定义服务商
This commit is contained in:
empty
2026-01-11 22:05:28 +08:00
parent d1c9a4a5dd
commit a6efb5a7e7
12 changed files with 2030 additions and 368 deletions

View File

@@ -1,9 +1,61 @@
// 环境变量配置
// 模型服务商配置列表
export const modelProviders = {
deepseek: {
id: 'deepseek',
name: 'DeepSeek',
description: '深度求索',
apiUrl: import.meta.env.VITE_DEEPSEEK_API_URL || 'https://api.deepseek.com/chat/completions',
apiKey: import.meta.env.VITE_DEEPSEEK_API_KEY || '',
model: import.meta.env.VITE_DEEPSEEK_MODEL || 'deepseek-chat'
},
openai: {
id: 'openai',
name: 'OpenAI',
description: 'GPT 系列',
apiUrl: import.meta.env.VITE_OPENAI_API_URL || 'https://api.openai.com/v1/chat/completions',
apiKey: import.meta.env.VITE_OPENAI_API_KEY || '',
model: import.meta.env.VITE_OPENAI_MODEL || 'gpt-4o'
},
claude: {
id: 'claude',
name: 'Claude',
description: 'Anthropic Claude',
apiUrl: import.meta.env.VITE_CLAUDE_API_URL || 'https://api.anthropic.com/v1/messages',
apiKey: import.meta.env.VITE_CLAUDE_API_KEY || '',
model: import.meta.env.VITE_CLAUDE_MODEL || 'claude-3-5-sonnet'
},
custom: {
id: 'custom',
name: '自定义',
description: '自定义 API 端点',
apiUrl: import.meta.env.VITE_CUSTOM_API_URL || '',
apiKey: import.meta.env.VITE_CUSTOM_API_KEY || '',
model: import.meta.env.VITE_CUSTOM_MODEL || ''
}
}
// 获取已配置的服务商列表(有 API Key 的)
export const getConfiguredProviders = () => {
return Object.values(modelProviders).filter(p => p.apiKey && p.apiKey.length > 0)
}
// 获取默认服务商
export const getDefaultProvider = () => {
const configured = getConfiguredProviders()
return configured.length > 0 ? configured[0] : modelProviders.deepseek
}
// 兼容旧版配置
export const config = {
// API 配置
apiUrl: import.meta.env.VITE_API_URL || 'https://api.deepseek.com/chat/completions',
apiKey: import.meta.env.VITE_API_KEY || 'YOUR_KEY',
// 向后兼容:使用第一个已配置的服务商
get apiUrl() {
return getDefaultProvider().apiUrl
},
get apiKey() {
return getDefaultProvider().apiKey
},
// 应用配置
appVersion: '1.0.0',
isDev: import.meta.env.DEV,
@@ -13,23 +65,20 @@ export const config = {
// 验证必需的环境变量
export const validateConfig = () => {
const errors = []
if (!config.apiUrl) {
errors.push('API URL 未配置')
const configured = getConfiguredProviders()
if (configured.length === 0) {
errors.push('未配置任何模型服务商的 API Key')
}
if (!config.apiKey || config.apiKey === 'YOUR_KEY') {
errors.push('API Key 未配置或使用默认值')
}
return errors
}
// 获取配置摘要(用于调试)
export const getConfigSummary = () => {
return {
apiUrl: config.apiUrl,
hasApiKey: config.apiKey !== 'YOUR_KEY',
configuredProviders: getConfiguredProviders().map(p => p.name),
defaultProvider: getDefaultProvider().name,
mode: config.mode,
isDev: config.isDev
}