| <span class="breadcrumb-current">{{ proxyName }}</span> |
| 9 | </nav> |
| 10 |
| 11 | <template v-if="proxy"> |
| 12 | <div class="detail-header"> |
| 13 | <div> |
| 14 | <div class="header-title-row"> |
| 15 | <h2 class="detail-title">{{ proxy.name }}</h2> |
| 16 | <span class="status-pill" :class="statusClass"> |
| 17 | <span class="status-dot"></span> |
| 18 | {{ proxy.status }} |
| 19 | </span> |
| 20 | </div> |
| 21 | <p class="header-subtitle"> |
| 22 | Source: {{ displaySource }} · Type: |
| 23 | {{ proxy.type.toUpperCase() }} |
| 24 | </p> |
| 25 | </div> |
| 26 | <div v-if="isStore" class="header-actions"> |
| 27 | <ActionButton variant="outline" size="small" @click="handleEdit"> |
| 28 | Edit |
| 29 | </ActionButton> |
| 30 | </div> |
| 31 | </div> |
| 32 | </template> |
| 33 | </div> |
| 34 |
| 35 | <!-- Scrollable Content --> |
| 36 | <div v-if="notFound" class="not-found"> |
| 37 | <p class="empty-text">Proxy not found</p> |
| 38 | <p class="empty-hint">The proxy "{{ proxyName }}" does not exist.</p> |
| 39 | <ActionButton variant="outline" @click="router.push('/proxies')"> |
| 40 | Back to Proxies |
| 41 | </ActionButton> |
| 42 | </div> |
| 43 |
| 44 | <div v-else-if="proxy" v-loading="loading" class="detail-content"> |
| 45 | <!-- Error Banner --> |
| 46 | <div v-if="proxy.err" class="error-banner"> |
| 47 | <el-icon class="error-icon"><Warning /></el-icon> |
| 48 | <div> |
| 49 | <div class="error-title">Connection Error</div> |
| 50 | <div class="error-message">{{ proxy.err }}</div> |
| 51 | </div> |
| 52 | </div> |
| 53 |
| 54 | <!-- Config Sections --> |
| 55 | <ProxyFormLayout |
| 56 | v-if="formData" |
| 57 | :model-value="formData" |
| 58 | readonly |
| 59 | /> |
| 60 | </div> |
| 61 |
| 62 | <div v-else v-loading="loading" class="loading-area"></div> |
| 63 |
| 64 | </div> |
| 65 | </template> |
| 66 |
| 67 | <script setup lang="ts"> |
| 68 | import { ref, computed, onMounted } from 'vue' |
| 69 | import { useRoute, useRouter } from 'vue-router' |
| 70 | import { ElMessage } from 'element-plus' |
| 71 | import { Warning } from '@element-plus/icons-vue' |
| 72 | import ActionButton from '@shared/components/ActionButton.vue' |
| 73 | import ProxyFormLayout from '../components/proxy-form/ProxyFormLayout.vue' |
| 74 | import { getProxyConfig, getStoreProxy } from '../api/frpc' |
| 75 | import { useProxyStore } from '../stores/proxy' |
| 76 | import { storeProxyToForm } from '../types' |
| 77 | import type { ProxyStatus, ProxyDefinition, ProxyFormData } from '../types' |
| 78 |
| 79 | const route = useRoute() |
| 80 | const router = useRouter() |
| 81 | const proxyStore = useProxyStore() |
| 82 |
| 83 | const proxyName = route.params.name as string |
| 84 | const proxy = ref<ProxyStatus | null>(null) |
| 85 | const proxyConfig = ref<ProxyDefinition | null>(null) |
| 86 | const loading = ref(true) |
| 87 | const notFound = ref(false) |
| 88 | const isStore = ref(false) |
| 89 |
| 90 | onMounted(async () => { |
| 91 | try { |
| 92 | // Try status API first |
| 93 | await proxyStore.fetchStatus() |
| 94 | const found = proxyStore.proxies.find((p) => p.name === proxyName) |
| 95 |
| 96 | // Try config API (works for any source) |
| 97 | let configDef: ProxyDefinition | null = null |
| 98 | try { |
| 99 | configDef = await getProxyConfig(proxyName) |
| 100 | proxyConfig.value = configDef |
| 101 | } catch { |
| 102 | // Config not available |
| 103 | } |
| 104 |
| 105 | // Check if proxy is from the store (for Edit/Delete buttons) |
| 106 | try { |
| 107 | await getStoreProxy(proxyName) |
| 108 | isStore.value = true |
| 109 | } catch { |
| 110 | // Not a store proxy |
| 111 | } |
| 112 |
| 113 | if (found) { |
| 114 | proxy.value = found |
| 115 | } else if (configDef) { |
| 116 | // Proxy not in status (e.g. disabled), build from config definition |
| 117 | const block = (configDef as any)[configDef.type] |
| 118 | const localIP = block?.localIP || '127.0.0.1' |
| 119 | const localPort = block?.localPort |
| 120 | const enabled = block?.enabled !== false |
| 121 | proxy.value = { |
| 122 | name: configDef.name, |
| 123 | type: configDef.type, |
| 124 | status: enabled ? 'waiting' : 'disabled', |
| 125 | err: '', |
| 126 | local_addr: localPort != null ? `${localIP}:${localPort}` : '', |
| 127 | remote_addr: block?.remotePort != null ? `:${block.remotePort}` : '', |
| 128 | plugin: block?.plugin?.type || '', |
| 129 | } |
| 130 | } else { |
| 131 | notFound.value = true |
| 132 | } |
| 133 | } catch (err: any) { |
| 134 | ElMessage.error('Failed to load proxy: ' + err.message) |
| 135 | } finally { |
| 136 | loading.value = false |
| 137 | } |
| 138 | }) |
| 139 |
| 140 | const displaySource = computed(() => |
| 141 | isStore.value ? 'store' : 'config', |
| 142 | ) |
| 143 |
| 144 | const statusClass = computed(() => { |
| 145 | const s = proxy.value?.status |
| 146 | if (s === 'running') return 'running' |
| 147 | if (s === 'error') return 'error' |
| 148 | if (s === 'disabled') return 'disabled' |
| 149 | return 'waiting' |
| 150 | }) |
| 151 |
| 152 | const formData = computed((): ProxyFormData | null => { |
| 153 | if (!proxyConfig.value) return null |
| 154 | return storeProxyToForm(proxyConfig.value) |
| 155 | }) |
| 156 |
| 157 | const handleEdit = () => { |
| 158 | router.push('/proxies/' + encodeURIComponent(proxyName) + '/edit') |
| 159 | } |
| 160 |
| 161 | </script> |
| 162 |
| 163 | <style scoped lang="scss"> |
| 164 | .proxy-detail-page { |
| 165 | display: flex; |
| 166 | flex-direction: column; |
| 167 | height: 100%; |
| 168 | max-width: 960px; |
| 169 | margin: 0 auto; |
| 170 | } |
| 171 |
| 172 | .detail-top { |
| 173 | flex-shrink: 0; |
| 174 | padding: $spacing-xl 24px 0; |
| 175 | } |
| 176 |
| 177 | .detail-content { |
| 178 | flex: 1; |
| 179 | overflow-y: auto; |
| 180 | padding: 0 24px 160px; |
| 181 | } |
| 182 |
| 183 | .breadcrumb { |
| 184 | display: flex; |
| 185 | align-items: center; |
| 186 | gap: $spacing-sm; |
| 187 | font-size: $font-size-md; |
| 188 | margin-bottom: $spacing-lg; |
| 189 | } |
| 190 |
| 191 | .breadcrumb-link { |
| 192 | color: $color-text-secondary; |
| 193 | text-decoration: none; |
| 194 |
| 195 | &:hover { |
| 196 | color: $color-text-primary; |
| 197 | } |
| 198 | } |
| 199 |
| 200 | .breadcrumb-sep { |
| 201 | color: $color-text-light; |
| 202 | } |
| 203 |
| 204 | .breadcrumb-current { |
| 205 | color: $color-text-primary; |
| 206 | font-weight: $font-weight-medium; |
| 207 | } |
| 208 |
| 209 | .detail-header { |
| 210 | display: flex; |
| 211 | justify-content: space-between; |
| 212 | align-items: flex-start; |
| 213 | margin-bottom: $spacing-xl; |
| 214 | } |
| 215 |
| 216 | .header-title-row { |
| 217 | display: flex; |
| 218 | align-items: center; |
| 219 | gap: $spacing-md; |
| 220 | margin-bottom: $spacing-sm; |
| 221 | } |
| 222 |
| 223 | .detail-title { |
| 224 | margin: 0; |
| 225 | font-size: 22px; |
| 226 | font-weight: $font-weight-semibold; |
| 227 | color: $color-text-primary; |
| 228 | } |
| 229 |
| 230 | .header-subtitle { |
| 231 | font-size: $font-size-sm; |
| 232 | color: $color-text-muted; |
| 233 | margin: 0; |
| 234 | } |
| 235 |
| 236 | .header-actions { |
| 237 | display: flex; |
| 238 | gap: $spacing-sm; |
| 239 | } |
| 240 |
| 241 | .error-banner { |
| 242 | display: flex; |
| 243 | align-items: flex-start; |
| 244 | gap: $spacing-sm; |
| 245 | padding: 12px 16px; |
| 246 | background: var(--color-danger-light); |
| 247 | border: 1px solid rgba(245, 108, 108, 0.2); |
| 248 | border-radius: $radius-md; |
| 249 | margin-bottom: $spacing-xl; |
| 250 |
| 251 | .error-icon { |
| 252 | color: $color-danger; |
| 253 | font-size: 18px; |
| 254 | margin-top: 2px; |
| 255 | } |
| 256 |
| 257 | .error-title { |
| 258 | font-size: $font-size-md; |
| 259 | font-weight: $font-weight-medium; |
| 260 | color: $color-danger; |
| 261 | margin-bottom: 2px; |
| 262 | } |
| 263 |
| 264 | .error-message { |
| 265 | font-size: $font-size-sm; |
| 266 | color: $color-text-muted; |
| 267 | } |
| 268 | } |
| 269 |
| 270 | .not-found, |
| 271 | .loading-area { |
| 272 | text-align: center; |
| 273 | padding: 60px $spacing-xl; |
| 274 | } |
| 275 |
| 276 | .empty-text { |
| 277 | font-size: $font-size-lg; |
| 278 | font-weight: $font-weight-medium; |
| 279 | color: $color-text-secondary; |
| 280 | margin: 0 0 $spacing-xs; |
| 281 | } |
| 282 |
| 283 | .empty-hint { |
| 284 | font-size: $font-size-sm; |
| 285 | color: $color-text-muted; |
| 286 | margin: 0 0 $spacing-lg; |
| 287 | } |
| 288 |
| 289 | @include mobile { |
| 290 | .detail-top { |
| 291 | padding: $spacing-xl $spacing-lg 0; |
| 292 | } |
| 293 |
| 294 | .detail-content { |
| 295 | padding: 0 $spacing-lg $spacing-xl; |
| 296 | } |
| 297 |
| 298 | .detail-header { |
| 299 | flex-direction: column; |
| 300 | gap: $spacing-md; |
| 301 | } |
| 302 | } |
| 303 | </style> |