/** * 代理配置组件 */ app.component('proxy-config-page', { props: ['config'], emits: ['save'], setup(props, { emit }) { const { ref, reactive, watch } = Vue; // 表单数据 const form = reactive({ enabled: false, http: '', https: '', no_proxy: [], auto_detect: true }); // 新的排除项 const newNoProxy = ref(''); // 监听 props 变化 watch(() => props.config, (newVal) => { if (newVal) { Object.assign(form, { ...newVal, no_proxy: newVal.no_proxy || [] }); } }, { immediate: true, deep: true }); // 添加排除项 function addNoProxy() { if (newNoProxy.value && !form.no_proxy.includes(newNoProxy.value)) { form.no_proxy.push(newNoProxy.value); newNoProxy.value = ''; } } // 删除排除项 function removeNoProxy(item) { const idx = form.no_proxy.indexOf(item); if (idx > -1) { form.no_proxy.splice(idx, 1); } } // 测试代理 const testing = ref(false); async function testProxy() { testing.value = true; try { const res = await fetch('/api/proxy/test', { method: 'POST' }); const data = await res.json(); if (data.success) { ElementPlus.ElMessage.success('代理连接正常'); } else { ElementPlus.ElMessage.error('代理连接失败: ' + data.error); } } catch (e) { ElementPlus.ElMessage.error('测试失败: ' + e.message); } testing.value = false; } // 自动检测代理 async function detectProxy() { try { const res = await fetch('/api/proxy/detect', { method: 'POST' }); const data = await res.json(); if (data.detected) { form.http = data.http || ''; form.https = data.https || ''; ElementPlus.ElMessage.success('检测到代理: ' + (data.http || data.https)); } else { ElementPlus.ElMessage.warning('未检测到可用代理'); } } catch (e) { ElementPlus.ElMessage.error('检测失败: ' + e.message); } } // 保存配置 function handleSave() { emit('save', { ...form }); } return { form, newNoProxy, testing, addNoProxy, removeNoProxy, testProxy, detectProxy, handleSave }; }, template: `
境外 LLM 服务(Anthropic、OpenAI、Gemini)需要通过代理访问。 国内服务(DeepSeek、智谱、MiniMax、Moonshot)无需代理。 检测本地代理
{{ item }}

点击下方按钮测试代理是否能正常访问境外服务。

测试代理连接
保存配置
` });