Просмотр исходного кода

前后端完成新增随机代理

mrh 1 год назад
Родитель
Сommit
df6f7c2cec
2 измененных файлов с 36 добавлено и 0 удалено
  1. 8 0
      ui/backend/config.yaml
  2. 28 0
      ui/fontend/src/components/ProxyPool.vue

+ 8 - 0
ui/backend/config.yaml

@@ -13,6 +13,14 @@ sub:
       file_path: g:\code\upwork\zhang_crawl_bio\download\proxy_pool\temp\9662.yaml
       name: "\U0001F1F8\U0001F1EC\u4E9A\u9A6C\u900A\u65B0\u52A0\u5761"
       port: 9662
+    9664:
+      file_path: g:\code\upwork\zhang_crawl_bio\download\proxy_pool\temp\9664.yaml
+      name: "\U0001F1EF\U0001F1F5\u65E5\u672C\u4E13\u7EBF4"
+      port: 9664
+    9666:
+      file_path: g:\code\upwork\zhang_crawl_bio\download\proxy_pool\temp\9666.yaml
+      name: "\U0001F1EF\U0001F1F5\u4E9A\u9A6C\u900A\u65E5\u672C2"
+      port: 9666
   start_port: 9660
   temp_dir: g:\code\upwork\zhang_crawl_bio\download\proxy_pool\temp
   url: https://www.yfjc.xyz/api/v1/client/subscribe?token=b74f2207492053926f7511a8e474048f

+ 28 - 0
ui/fontend/src/components/ProxyPool.vue

@@ -1,6 +1,7 @@
 <template>
     <div class="proxy-pool-container">
       <el-row justify="end" class="mb-4">
+        <el-button type="success" @click="autoCreateProxy" :loading="creating">新增代理</el-button>
         <el-button type="primary" @click="fetchProxyList" :loading="loading">刷新列表</el-button>
       </el-row>
       
@@ -77,6 +78,7 @@ import type { ProxyResponse, ProxyPostResponse } from '../api-types'
 const apiBaseUrl = import.meta.env.VITE_API_BASE_URL || ''
 const proxyList = ref<ProxyResponse[]>([])
 const loading = ref(false)
+const creating = ref(false)
 const detailVisible = ref(false)
 const selectedProxy = ref<ProxyResponse | null>(null)
 
@@ -154,6 +156,32 @@ const formatTime = (timestamp: number| undefined): string => {
   const date = new Date(timestamp * 1000); // 转换为毫秒
   return date.toLocaleString(); // 根据本地格式返回日期和时间
 };
+const autoCreateProxy = async () => {
+    try {
+        creating.value = true
+        const response = await fetch(`${apiBaseUrl}/proxy/proxies`, {
+            method: 'POST',
+            headers: {
+                'Content-Type': 'application/json',
+            },
+            body: JSON.stringify({ auto: true }),
+        })
+        
+        if (!response.ok) throw new Error('自动创建代理失败')
+        const result: ProxyPostResponse = await response.json()
+        if (result.err === 0) {
+            await fetchProxyList()
+        } else {
+            alert(result.msg || "操作失败")
+        }
+    } catch (error) {
+        console.error(error)
+        alert(typeof error === 'string' ? error : (error as Error).message)
+    } finally {
+        creating.value = false
+    }
+}
+
 // 初始化时自动加载一次
 fetchProxyList()
 </script>