diff --git a/src/App.vue b/src/App.vue index 60d736e..5d2bfcd 100644 --- a/src/App.vue +++ b/src/App.vue @@ -28,7 +28,11 @@ import { LayoutDashboard, Focus, Target, - Map + Map, + Link as LinkIcon, + Shield, + Key, + Activity } from 'lucide-vue-next' import { VueFlow, useVueFlow, Position, MarkerType, Handle } from '@vue-flow/core' import { Background, BackgroundVariant } from '@vue-flow/background' @@ -43,7 +47,53 @@ import '@vue-flow/minimap/dist/style.css' import '@vue-flow/controls/dist/style.css' // API 配置 -const API_KEY = import.meta.env.VITE_ZHIPU_AI_API_KEY +const API_KEY = '' + +// API 详情配置 +const apiConfig = reactive({ + mode: localStorage.getItem('api_mode') || 'default', // 'default' | 'custom' + chat: { + baseUrl: localStorage.getItem('chat_baseUrl') || '', + model: localStorage.getItem('chat_model') || '', + apiKey: localStorage.getItem('chat_apiKey') || '' + }, + image: { + baseUrl: localStorage.getItem('image_baseUrl') || '', + model: localStorage.getItem('image_model') || '', + apiKey: localStorage.getItem('image_apiKey') || '' + } +}) + +// 默认配置常量 +const DEFAULT_CONFIG = { + chat: { + baseUrl: 'https://thinkflow.lz-t.top/chat/completions', + model: 'glm-4-flash', + apiKey: '' + }, + image: { + baseUrl: 'https://thinkflow.lz-t.top/images/generations', + model: 'cogview-3-flash', + apiKey: '' + } +} + +// 监听配置变化并保存 +watch( + () => apiConfig, + newVal => { + localStorage.setItem('api_mode', newVal.mode) + localStorage.setItem('chat_baseUrl', newVal.chat.baseUrl) + localStorage.setItem('chat_model', newVal.chat.model) + localStorage.setItem('chat_apiKey', newVal.chat.apiKey) + localStorage.setItem('image_baseUrl', newVal.image.baseUrl) + localStorage.setItem('image_model', newVal.image.model) + localStorage.setItem('image_apiKey', newVal.image.apiKey) + }, + { deep: true } +) + +const showSettings = ref(false) // VueFlow 实例 const { addNodes, addEdges, onConnect, setNodes, setEdges, nodes: flowNodes, edges: flowEdges, updateNode, fitView, onNodeDragStart, onNodeDragStop } = useVueFlow() @@ -265,15 +315,19 @@ const generateNodeImage = async (nodeId: string, prompt: string) => { updateNode(nodeId, { data: { ...node.data, isImageLoading: true } }) + const useConfig = apiConfig.mode === 'default' ? DEFAULT_CONFIG.image : apiConfig.image + // 自定义模式下完全使用用户输入,不进行项目 Key 兜底 + const finalApiKey = apiConfig.mode === 'default' ? useConfig.apiKey || API_KEY : useConfig.apiKey + try { - const response = await fetch('https://open.bigmodel.cn/api/paas/v4/images/generations', { + const response = await fetch(useConfig.baseUrl, { method: 'POST', headers: { 'Content-Type': 'application/json', - Authorization: `Bearer ${API_KEY}` + Authorization: `Bearer ${finalApiKey}` }, body: JSON.stringify({ - model: 'cogview-3-flash', + model: useConfig.model, prompt: `生成一张图片,表现主题:${prompt}。要求:构图简洁,色彩明快,适合作为思维导图的视觉辅助。` }) }) @@ -360,15 +414,19 @@ const expandIdea = async (param?: any, customInput?: string) => { userMessage = `核心想法: ${text}` } + const useConfig = apiConfig.mode === 'default' ? DEFAULT_CONFIG.chat : apiConfig.chat + // 自定义模式下完全使用用户输入,不进行项目 Key 兜底 + const finalApiKey = apiConfig.mode === 'default' ? useConfig.apiKey || API_KEY : useConfig.apiKey + try { - const response = await fetch('https://open.bigmodel.cn/api/paas/v4/chat/completions', { + const response = await fetch(useConfig.baseUrl, { method: 'POST', headers: { 'Content-Type': 'application/json', - Authorization: `Bearer ${API_KEY}` + Authorization: `Bearer ${finalApiKey}` }, body: JSON.stringify({ - model: 'glm-4-flash', + model: useConfig.model, messages: [ { role: 'system', content: systemPrompt }, { role: 'user', content: userMessage } @@ -537,6 +595,14 @@ const startNewSession = () => { EXPORT + +
+ + + @@ -705,6 +771,156 @@ const startNewSession = () => {
+ +
+
+
+
+
+ +
+
+

API Settings

+

Configure your AI endpoints

+
+
+ +
+ +
+ +
+ + +
+ + +
+
+ + Text Generation (Chat) +
+
+
+ + +
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + Image Generation +
+
+
+ + +
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ +
+
+

Using Default Endpoint

+

Requests are currently being routed through the system's optimized default API service.

+
+
+
+ +
+ +
+
+
+