|
@@ -1,6 +1,7 @@
|
|
|
<template>
|
|
<template>
|
|
|
<div class="proxy-pool-container">
|
|
<div class="proxy-pool-container">
|
|
|
<el-row justify="end" class="mb-4">
|
|
<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-button type="primary" @click="fetchProxyList" :loading="loading">刷新列表</el-button>
|
|
|
</el-row>
|
|
</el-row>
|
|
|
|
|
|
|
@@ -77,6 +78,7 @@ import type { ProxyResponse, ProxyPostResponse } from '../api-types'
|
|
|
const apiBaseUrl = import.meta.env.VITE_API_BASE_URL || ''
|
|
const apiBaseUrl = import.meta.env.VITE_API_BASE_URL || ''
|
|
|
const proxyList = ref<ProxyResponse[]>([])
|
|
const proxyList = ref<ProxyResponse[]>([])
|
|
|
const loading = ref(false)
|
|
const loading = ref(false)
|
|
|
|
|
+const creating = ref(false)
|
|
|
const detailVisible = ref(false)
|
|
const detailVisible = ref(false)
|
|
|
const selectedProxy = ref<ProxyResponse | null>(null)
|
|
const selectedProxy = ref<ProxyResponse | null>(null)
|
|
|
|
|
|
|
@@ -154,6 +156,32 @@ const formatTime = (timestamp: number| undefined): string => {
|
|
|
const date = new Date(timestamp * 1000); // 转换为毫秒
|
|
const date = new Date(timestamp * 1000); // 转换为毫秒
|
|
|
return date.toLocaleString(); // 根据本地格式返回日期和时间
|
|
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()
|
|
fetchProxyList()
|
|
|
</script>
|
|
</script>
|