|
|
@@ -2,7 +2,7 @@
|
|
|
<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-button type="primary" @click="refreshProxyList" :loading="loading">刷新列表</el-button>
|
|
|
</el-row>
|
|
|
|
|
|
<el-table :data="proxyList" border stripe v-loading="loading">
|
|
|
@@ -75,7 +75,6 @@
|
|
|
import { ref } from 'vue'
|
|
|
import type { ProxyResponse, ProxyPostResponse } from '../api-types'
|
|
|
import { useProxyStore } from '../stores/proxyStore'
|
|
|
-import { log } from 'console'
|
|
|
const store = useProxyStore()
|
|
|
|
|
|
const apiBaseUrl = import.meta.env.VITE_API_BASE_URL || ''
|
|
|
@@ -88,18 +87,17 @@ const selectedProxy = ref<ProxyResponse | null>(null)
|
|
|
const fetchProxyList = async (useCatch=true) => {
|
|
|
try {
|
|
|
loading.value = true
|
|
|
- let response:Response
|
|
|
+ // let response:Response
|
|
|
let data: ProxyResponse[]
|
|
|
- if (useCatch) {
|
|
|
- const cacheKey = 'fetchProxyList'
|
|
|
+ const cacheKey = 'fetchProxyList'
|
|
|
+ if (!useCatch) {
|
|
|
+ localStorage.removeItem(cacheKey)
|
|
|
+ }
|
|
|
data = await store.cachedFetch(`${apiBaseUrl}/proxy/proxies`, cacheKey)
|
|
|
console.log(`useCatch ${cacheKey}: `, data)
|
|
|
- }
|
|
|
- else {
|
|
|
- response = await fetch(`${apiBaseUrl}/proxy/proxies`)
|
|
|
- if (!response.ok) throw new Error('获取代理列表失败')
|
|
|
- data = await response.json()
|
|
|
- }
|
|
|
+ // response = await fetch(`${apiBaseUrl}/proxy/proxies`)
|
|
|
+ // if (!response.ok) throw new Error('获取代理列表失败')
|
|
|
+ // data = await response.json()
|
|
|
|
|
|
proxyList.value = data.map((proxy: ProxyResponse) => ({
|
|
|
...proxy,
|
|
|
@@ -111,6 +109,9 @@ try {
|
|
|
loading.value = false
|
|
|
}
|
|
|
}
|
|
|
+const refreshProxyList = async () => {
|
|
|
+ await fetchProxyList(false)
|
|
|
+}
|
|
|
|
|
|
const showDetail = (proxy: ProxyResponse) => {
|
|
|
selectedProxy.value = proxy
|
|
|
@@ -140,8 +141,8 @@ try {
|
|
|
const closeProxy = async (proxy: ProxyResponse) => {
|
|
|
try {
|
|
|
proxy.isLoading = true
|
|
|
- const response = await fetch(`${apiBaseUrl}/proxy/proxies/${proxy.port}`, {
|
|
|
- method: 'DELETE'
|
|
|
+ const response = await fetch(`${apiBaseUrl}/proxy/proxies/${proxy.port}/stop`, {
|
|
|
+ method: 'POST'
|
|
|
})
|
|
|
if (!response.ok) throw new Error('关闭代理失败')
|
|
|
proxy.reachable = false
|