From 3137669dfb0d6b88c0377c0071fb279184b2dbbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=8B=E7=94=B0=E5=BC=98?= <1240092443@qq.com> Date: Sat, 11 Jan 2025 18:38:57 +0800 Subject: [PATCH] =?UTF-8?q?add=EF=BC=9A=E5=AE=9E=E7=8E=B0frpc=E5=A2=9E?= =?UTF-8?q?=E5=88=A0=E6=94=B9=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/components/setting/NetProxy.vue | 105 +++++++++------ frontend/src/stores/proxy.ts | 130 ++++++++++++++++++- godo/proxy/frpc.go | 14 +- 3 files changed, 197 insertions(+), 52 deletions(-) diff --git a/frontend/src/components/setting/NetProxy.vue b/frontend/src/components/setting/NetProxy.vue index 2e125d7..733ebb2 100644 --- a/frontend/src/components/setting/NetProxy.vue +++ b/frontend/src/components/setting/NetProxy.vue @@ -2,9 +2,18 @@ import { useProxyStore } from "@/stores/proxy"; import { notifyError, notifySuccess } from "@/util/msg"; import { Plus } from "@element-plus/icons-vue"; - import { ref } from "vue"; + import { onMounted, ref } from "vue"; + import { useRoute } from "vue-router"; + const route = useRoute(); const proxyStore = useProxyStore(); + const { + proxies, + fetchProxies, + fetchProxyByName, + deleteProxyByName, + updateProxyByName, + } = proxyStore; const proxyDialogShow = ref(false); const isEditing = ref(false); @@ -24,20 +33,11 @@ const addProxy = () => { if (pwdRef.value.validate()) { - // const isNameDuplicate = proxyStore.proxies.some( - // (p) => p.name === proxyStore.proxyData.name - // ); - // if (isNameDuplicate) { - // notifyError("代理名称已存在"); - // return; - // } - // proxyStore.addProxy({ ...proxyStore.proxyData }); - // proxyDialogShow.value = false; - // proxyStore.resetProxyData(); - // 调用 store 中的 createFrpcConfig 方法 proxyStore .createFrpcConfig() .then(() => { + proxyDialogShow.value = false; + proxyStore.addProxy({ ...proxyStore.proxyData }); proxyDialogShow.value = false; proxyStore.resetProxyData(); notifySuccess("代理配置已成功创建"); @@ -48,24 +48,16 @@ } }; - const updateProxy = () => { + const updateProxy = async () => { if (pwdRef.value.validate()) { - const index = proxyStore.proxies.findIndex( - (p) => p.id === proxyStore.proxyData.id - ); - if (index !== -1) { - const isNameDuplicate = proxyStore.proxies.some( - (p, i) => - p.name === proxyStore.proxyData.name && i !== index - ); - if (isNameDuplicate) { - notifyError("代理名称已存在"); - return; - } - proxyStore.updateProxy({ ...proxyStore.proxyData }); + try { + await updateProxyByName(proxyStore.proxyData); + notifySuccess("编辑成功"); proxyDialogShow.value = false; proxyStore.resetProxyData(); isEditing.value = false; + } catch (error) { + notifyError(`编辑失败: ${error.message}`); } } }; @@ -120,6 +112,34 @@ } }); }; + + const loadProxies = async () => { + await fetchProxies(); + }; + + const editProxyBefore = async (proxy: any) => { + await fetchProxyByName(proxy.name); + proxyDialogShow.value = true; + isEditing.value = true; + }; + + const deleteProxy = async (name: string) => { + try { + await deleteProxyByName(name); + notifySuccess("删除成功"); + } catch (error) { + console.error("Error deleting proxy:", error); + notifyError(`删除失败: ${error.message}`); + } + }; + + onMounted(() => { + loadProxies(); + const name = route.query.name as string; + if (name) { + fetchProxyByName(name); + } + });