|
|
@@ -1,97 +1,72 @@
|
|
|
<template>
|
|
|
- <div>
|
|
|
- <el-row justify="center">
|
|
|
- <el-radio-group @change="proxy_change" v-model="proxy_choice">
|
|
|
- <el-radio value="system" @change="get_sys_proxy" border>系统</el-radio>
|
|
|
- <el-radio value="poll" @change="get_sub_url" border>代理池</el-radio>
|
|
|
- </el-radio-group>
|
|
|
- </el-row>
|
|
|
-
|
|
|
- <el-row v-if="proxy_choice=='system'" justify="center" class="mt-4">
|
|
|
- <el-descriptions title="系统代理状态" direction="vertical" :column="1" border>
|
|
|
- <el-descriptions-item label="代理状态">
|
|
|
- {{ sys_proxy.sys_open ? '已启用' : '未启用' }}
|
|
|
- </el-descriptions-item>
|
|
|
- <el-descriptions-item label="代理地址">
|
|
|
- {{ sys_proxy.proxy_server || '未设置' }}
|
|
|
- </el-descriptions-item>
|
|
|
- <el-descriptions-item label="说明">
|
|
|
- 如果选择系统代理,程序会自动跟随系统默认。
|
|
|
- </el-descriptions-item>
|
|
|
- </el-descriptions>
|
|
|
- </el-row>
|
|
|
- <el-row v-else justify="center" class="mt-4">
|
|
|
- <ProxyPool />
|
|
|
- </el-row>
|
|
|
- </div>
|
|
|
+ <div>
|
|
|
+ <el-row justify="center">
|
|
|
+ <el-radio-group @change="proxy_change" v-model="proxy_choice">
|
|
|
+ <el-radio value="system" @change="get_sys_proxy" border>系统</el-radio>
|
|
|
+ <el-radio value="poll" @change="get_sub_url" border>代理池</el-radio>
|
|
|
+ </el-radio-group>
|
|
|
+ </el-row>
|
|
|
+
|
|
|
+ <el-row v-if="proxy_choice === 'system'" justify="center" class="mt-4">
|
|
|
+ <el-descriptions title="系统代理状态" direction="vertical" :column="1" border>
|
|
|
+ <el-descriptions-item label="代理状态">
|
|
|
+ {{ store.sysProxyCache?.data?.sys_open ? '已启用' : '未启用' }}
|
|
|
+ </el-descriptions-item>
|
|
|
+ <el-descriptions-item label="代理地址">
|
|
|
+ {{ store.sysProxyCache?.data?.proxy_server || '未设置' }}
|
|
|
+ </el-descriptions-item>
|
|
|
+ <el-descriptions-item label="说明">
|
|
|
+ 如果选择系统代理,程序会自动跟随系统默认。
|
|
|
+ </el-descriptions-item>
|
|
|
+ </el-descriptions>
|
|
|
+ </el-row>
|
|
|
+ <el-row v-else justify="center" class="mt-4">
|
|
|
+ <ProxyPool />
|
|
|
+ </el-row>
|
|
|
+ </div>
|
|
|
</template>
|
|
|
-
|
|
|
+
|
|
|
<script setup lang="ts">
|
|
|
-import { ref } from 'vue'
|
|
|
-import { onMounted } from 'vue'
|
|
|
+import { ref, onMounted } from 'vue' // 确保导入onMounted
|
|
|
import ProxyPool from './ProxyPool.vue'
|
|
|
-
|
|
|
import { useProxyStore } from '../stores/proxyStore'
|
|
|
+import { ElMessage } from 'element-plus'
|
|
|
+
|
|
|
const store = useProxyStore()
|
|
|
const proxy_choice = ref<string>(store.selectedProxy)
|
|
|
const apiBaseUrl = import.meta.env.VITE_API_BASE_URL || ''
|
|
|
-const sys_proxy = ref<{sys_open: boolean, proxy_server: string}>({
|
|
|
- sys_open: false,
|
|
|
- proxy_server: ''
|
|
|
+
|
|
|
+// 在组件挂载时获取初始数据
|
|
|
+onMounted(() => {
|
|
|
+ Promise.all([get_sys_proxy(), get_sub_url()]).catch((error) =>
|
|
|
+ console.error('初始化失败:', error)
|
|
|
+ )
|
|
|
})
|
|
|
-const subUrl = ref('')
|
|
|
|
|
|
-// 获取订阅链接(带缓存)
|
|
|
const get_sub_url = async () => {
|
|
|
try {
|
|
|
- const cacheKey = 'sub_url_cache'
|
|
|
- const data = await store.cachedFetch(`${apiBaseUrl}/proxy/subs`, cacheKey)
|
|
|
- subUrl.value = data.msg?.url || ''
|
|
|
+ await store.cachedFetch(`${apiBaseUrl}/proxy/subs`, store.CACHE_KEYS.SUB_URL)
|
|
|
} catch (error) {
|
|
|
console.error('获取订阅链接失败:', error)
|
|
|
ElMessage.error('获取订阅信息失败')
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// 获取系统代理信息(带缓存)
|
|
|
const get_sys_proxy = async () => {
|
|
|
try {
|
|
|
- const cacheKey = 'sys_proxy_cache'
|
|
|
- const data = await store.cachedFetch(`${apiBaseUrl}/proxy/sys`, cacheKey)
|
|
|
- sys_proxy.value = data
|
|
|
- store.setProxyData(data) // 保持store数据同步
|
|
|
+ const data= await store.cachedFetch(`${apiBaseUrl}/proxy/sys`, store.CACHE_KEYS.SYS_PROXY)
|
|
|
+ console.log('get_sys_proxy data:', data)
|
|
|
} catch (error) {
|
|
|
console.error('获取代理信息失败:', error)
|
|
|
ElMessage.error('获取代理信息失败')
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// 初始化时自动获取并启动后台轮询
|
|
|
-onMounted(async () => {
|
|
|
- store.startBackgroundPolling()
|
|
|
- try {
|
|
|
- await Promise.all([get_sys_proxy(), get_sub_url()])
|
|
|
- } catch (error) {
|
|
|
- console.error('初始化失败:', error)
|
|
|
- }
|
|
|
-})
|
|
|
-
|
|
|
-// 切换代理类型时强制刷新
|
|
|
-const proxy_change = async (value: any) => {
|
|
|
+const proxy_change = (value: string) => {
|
|
|
store.setSelectedProxy(value)
|
|
|
- if (value === 'system') {
|
|
|
- await store.cachedFetch(`${apiBaseUrl}/proxy/sys`, 'sys_proxy_cache', true)
|
|
|
- store.setProxyData(sys_proxy.value)
|
|
|
- } else if (value === 'poll') {
|
|
|
- await store.cachedFetch(`${apiBaseUrl}/proxy/subs`, 'sub_url_cache', true)
|
|
|
- }
|
|
|
- // 立即更新显示数据
|
|
|
- sys_proxy.value = { ...store.sysProxyData }
|
|
|
}
|
|
|
-
|
|
|
</script>
|
|
|
|
|
|
<style scoped>
|
|
|
-
|
|
|
-</style>
|
|
|
-
|
|
|
+/* 样式保持不变 */
|
|
|
+</style>
|