| <router-link to="/clients" class="breadcrumb-item">Clients</router-link> |
| 9 | <span class="breadcrumb-separator">/</span> |
| 10 | <span class="breadcrumb-current">{{ |
| 11 | client?.displayName || route.params.key |
| 12 | }}</span> |
| 13 | </nav> |
| 14 |
| 15 | <div v-loading="loading" class="detail-content"> |
| 16 | <template v-if="client"> |
| 17 | <!-- Header Card --> |
| 18 | <div class="header-card"> |
| 19 | <div class="header-main"> |
| 20 | <div class="header-left"> |
| 21 | <div class="client-avatar"> |
| 22 | {{ client.displayName.charAt(0).toUpperCase() }} |
| 23 | </div> |
| 24 | <div class="client-info"> |
| 25 | <div class="client-name-row"> |
| 26 | <h1 class="client-name">{{ client.displayName }}</h1> |
| 27 | <el-tag v-if="client.version" size="small" type="success" |
| 28 | >v{{ client.version }}</el-tag |
| 29 | > |
| 30 | <el-tag v-if="client.wireProtocolLabel" size="small" type="info"> |
| 31 | {{ client.wireProtocolLabel }} |
| 32 | </el-tag> |
| 33 | </div> |
| 34 | <div class="client-meta"> |
| 35 | <span v-if="client.ip" class="meta-item">{{ |
| 36 | client.ip |
| 37 | }}</span> |
| 38 | <span v-if="client.hostname" class="meta-item">{{ |
| 39 | client.hostname |
| 40 | }}</span> |
| 41 | </div> |
| 42 | </div> |
| 43 | </div> |
| 44 | <div class="header-right"> |
| 45 | <span |
| 46 | class="status-badge" |
| 47 | :class="client.online ? 'online' : 'offline'" |
| 48 | > |
| 49 | {{ client.online ? 'Online' : 'Offline' }} |
| 50 | </span> |
| 51 | </div> |
| 52 | </div> |
| 53 |
| 54 | <!-- Info Section --> |
| 55 | <div class="info-section"> |
| 56 | <div class="info-item"> |
| 57 | <span class="info-label">Connections</span> |
| 58 | <span class="info-value">{{ client.status.curConns }}</span> |
| 59 | </div> |
| 60 | <div class="info-item"> |
| 61 | <span class="info-label">Run ID</span> |
| 62 | <span class="info-value">{{ client.runID }}</span> |
| 63 | </div> |
| 64 | <div v-if="client.wireProtocol" class="info-item"> |
| 65 | <span class="info-label">Protocol</span> |
| 66 | <span class="info-value">{{ client.wireProtocol }}</span> |
| 67 | </div> |
| 68 | <div class="info-item"> |
| 69 | <span class="info-label">First Connected</span> |
| 70 | <span class="info-value">{{ client.firstConnectedAgo }}</span> |
| 71 | </div> |
| 72 | <div class="info-item"> |
| 73 | <span class="info-label">{{ |
| 74 | client.online ? 'Connected' : 'Disconnected' |
| 75 | }}</span> |
| 76 | <span class="info-value">{{ |
| 77 | client.online ? client.lastConnectedAgo : client.disconnectedAgo |
| 78 | }}</span> |
| 79 | </div> |
| 80 | </div> |
| 81 | </div> |
| 82 |
| 83 | <!-- Proxies Card --> |
| 84 | <div class="proxies-card"> |
| 85 | <div class="proxies-header"> |
| 86 | <div class="proxies-title"> |
| 87 | <h2>Proxies</h2> |
| 88 | <span class="proxies-count">{{ total }}</span> |
| 89 | </div> |
| 90 | <el-input |
| 91 | v-model="proxySearch" |
| 92 | placeholder="Search proxies..." |
| 93 | :prefix-icon="Search" |
| 94 | clearable |
| 95 | class="proxy-search" |
| 96 | /> |
| 97 | </div> |
| 98 | <div class="proxies-body"> |
| 99 | <div v-if="proxiesLoading" class="loading-state"> |
| 100 | <el-icon class="is-loading"><Loading /></el-icon> |
| 101 | <span>Loading...</span> |
| 102 | </div> |
| 103 | <div v-else-if="proxies.length > 0" class="proxies-list"> |
| 104 | <ProxyCard |
| 105 | v-for="proxy in proxies" |
| 106 | :key="`${proxy.type}:${proxy.name}`" |
| 107 | :proxy="proxy" |
| 108 | show-type |
| 109 | /> |
| 110 | </div> |
| 111 | <div v-else-if="proxySearch.trim()" class="empty-state"> |
| 112 | <p>No proxies match "{{ proxySearch }}"</p> |
| 113 | </div> |
| 114 | <div v-else class="empty-state"> |
| 115 | <p>No proxies found</p> |
| 116 | </div> |
| 117 | </div> |
| 118 | <div v-if="total > 0" class="pagination-section"> |
| 119 | <ElPagination |
| 120 | :current-page="page" |
| 121 | :page-size="pageSize" |
| 122 | :page-sizes="[10, 20, 50, 100]" |
| 123 | :total="total" |
| 124 | layout="total, sizes, prev, pager, next" |
| 125 | @current-change="onPageChange" |
| 126 | @size-change="onPageSizeChange" |
| 127 | /> |
| 128 | </div> |
| 129 | </div> |
| 130 | </template> |
| 131 |
| 132 | <div v-else-if="!loading" class="not-found"> |
| 133 | <h2>Client not found</h2> |
| 134 | <p>The client doesn't exist or has been removed.</p> |
| 135 | <router-link to="/clients"> |
| 136 | <el-button type="primary">Back to Clients</el-button> |
| 137 | </router-link> |
| 138 | </div> |
| 139 | </div> |
| 140 | </div> |
| 141 | </template> |
| 142 |
| 143 | <script setup lang="ts"> |
| 144 | import { ref, onMounted, onUnmounted, watch } from 'vue' |
| 145 | import { useRoute, useRouter } from 'vue-router' |
| 146 | import { ElMessage, ElPagination } from 'element-plus' |
| 147 | import { ArrowLeft, Loading, Search } from '@element-plus/icons-vue' |
| 148 | import { Client } from '../utils/client' |
| 149 | import { getClientV2 } from '../api/client' |
| 150 | import { getProxiesV2 } from '../api/proxy' |
| 151 | import { |
| 152 | BaseProxy, |
| 153 | TCPProxy, |
| 154 | UDPProxy, |
| 155 | HTTPProxy, |
| 156 | HTTPSProxy, |
| 157 | TCPMuxProxy, |
| 158 | STCPProxy, |
| 159 | SUDPProxy, |
| 160 | } from '../utils/proxy' |
| 161 | import { getServerInfo } from '../api/server' |
| 162 | import ProxyCard from '../components/ProxyCard.vue' |
| 163 | import type { ProxyStatsInfo } from '../types/proxy' |
| 164 | import type { ServerInfo } from '../types/server' |
| 165 |
| 166 | const route = useRoute() |
| 167 | const router = useRouter() |
| 168 | const client = ref<Client | null>(null) |
| 169 | const loading = ref(true) |
| 170 |
| 171 | const goBack = () => { |
| 172 | if (window.history.length > 1) { |
| 173 | router.back() |
| 174 | } else { |
| 175 | router.push('/clients') |
| 176 | } |
| 177 | } |
| 178 | const proxiesLoading = ref(false) |
| 179 | const proxies = ref<BaseProxy[]>([]) |
| 180 | const proxySearch = ref('') |
| 181 | const page = ref(1) |
| 182 | const pageSize = ref(10) |
| 183 | const total = ref(0) |
| 184 | let requestSeq = 0 |
| 185 | let searchDebounceTimer: number | null = null |
| 186 |
| 187 | let serverInfoPromise: Promise<ServerInfo> | null = null |
| 188 |
| 189 | const fetchServerInfo = (): Promise<ServerInfo> => { |
| 190 | if (!serverInfoPromise) { |
| 191 | serverInfoPromise = getServerInfo().catch((err) => { |
| 192 | serverInfoPromise = null |
| 193 | throw err |
| 194 | }) |
| 195 | } |
| 196 | return serverInfoPromise |
| 197 | } |
| 198 |
| 199 | const fetchClient = async (): Promise<boolean> => { |
| 200 | const key = route.params.key as string |
| 201 | if (!key) { |
| 202 | loading.value = false |
| 203 | return false |
| 204 | } |
| 205 | try { |
| 206 | const data = await getClientV2(key) |
| 207 | client.value = new Client(data) |
| 208 | return true |
| 209 | } catch (error: any) { |
| 210 | ElMessage.error('Failed to fetch client: ' + error.message) |
| 211 | return false |
| 212 | } finally { |
| 213 | loading.value = false |
| 214 | } |
| 215 | } |
| 216 |
| 217 | const convertProxy = async ( |
| 218 | proxy: ProxyStatsInfo, |
| 219 | ): Promise<BaseProxy | null> => { |
| 220 | const type = proxy.type || '' |
| 221 | if (type === 'tcp') { |
| 222 | return new TCPProxy(proxy) |
| 223 | } |
| 224 | if (type === 'udp') { |
| 225 | return new UDPProxy(proxy) |
| 226 | } |
| 227 | if (type === 'http') { |
| 228 | const info = await fetchServerInfo() |
| 229 | if (info && info.config.vhostHTTPPort) { |
| 230 | return new HTTPProxy( |
| 231 | proxy, |
| 232 | info.config.vhostHTTPPort, |
| 233 | info.config.subdomainHost, |
| 234 | ) |
| 235 | } |
| 236 | return null |
| 237 | } |
| 238 | if (type === 'https') { |
| 239 | const info = await fetchServerInfo() |
| 240 | if (info && info.config.vhostHTTPSPort) { |
| 241 | return new HTTPSProxy( |
| 242 | proxy, |
| 243 | info.config.vhostHTTPSPort, |
| 244 | info.config.subdomainHost, |
| 245 | ) |
| 246 | } |
| 247 | return null |
| 248 | } |
| 249 | if (type === 'tcpmux') { |
| 250 | const info = await fetchServerInfo() |
| 251 | if (info && info.config.tcpmuxHTTPConnectPort) { |
| 252 | return new TCPMuxProxy( |
| 253 | proxy, |
| 254 | info.config.tcpmuxHTTPConnectPort, |
| 255 | info.config.subdomainHost, |
| 256 | ) |
| 257 | } |
| 258 | return null |
| 259 | } |
| 260 | if (type === 'stcp') { |
| 261 | return new STCPProxy(proxy) |
| 262 | } |
| 263 | if (type === 'sudp') { |
| 264 | return new SUDPProxy(proxy) |
| 265 | } |
| 266 |
| 267 | const bp = new BaseProxy(proxy) |
| 268 | bp.type = type |
| 269 | return bp |
| 270 | } |
| 271 |
| 272 | const convertProxies = async (items: ProxyStatsInfo[]): Promise<BaseProxy[]> => { |
| 273 | const converted = await Promise.all(items.map((item) => convertProxy(item))) |
| 274 | return converted.filter((item): item is BaseProxy => item !== null) |
| 275 | } |
| 276 |
| 277 | const fetchProxies = async () => { |
| 278 | if (!client.value) return |
| 279 | const seq = ++requestSeq |
| 280 | proxiesLoading.value = true |
| 281 |
| 282 | try { |
| 283 | const q = proxySearch.value.trim() |
| 284 | const data = await getProxiesV2({ |
| 285 | page: page.value, |
| 286 | pageSize: pageSize.value, |
| 287 | q: q || undefined, |
| 288 | clientID: client.value.clientID, |
| 289 | user: client.value.user, |
| 290 | }) |
| 291 | if (seq !== requestSeq) return |
| 292 |
| 293 | const maxPage = Math.max(1, Math.ceil(data.total / data.pageSize)) |
| 294 | if (data.items.length === 0 && data.total > 0 && data.page > maxPage) { |
| 295 | page.value = maxPage |
| 296 | await fetchProxies() |
| 297 | return |
| 298 | } |
| 299 |
| 300 | const converted = await convertProxies(data.items) |
| 301 | if (seq !== requestSeq) return |
| 302 |
| 303 | proxies.value = converted |
| 304 | total.value = data.total |
| 305 | page.value = data.page |
| 306 | pageSize.value = data.pageSize |
| 307 | } catch (error: any) { |
| 308 | if (seq !== requestSeq) return |
| 309 | ElMessage.error('Failed to fetch proxies: ' + error.message) |
| 310 | } finally { |
| 311 | if (seq === requestSeq) { |
| 312 | proxiesLoading.value = false |
| 313 | } |
| 314 | } |
| 315 | } |
| 316 |
| 317 | const clearSearchDebounce = () => { |
| 318 | if (searchDebounceTimer !== null) { |
| 319 | window.clearTimeout(searchDebounceTimer) |
| 320 | searchDebounceTimer = null |
| 321 | } |
| 322 | } |
| 323 |
| 324 | const invalidateProxyRequests = () => { |
| 325 | requestSeq++ |
| 326 | proxiesLoading.value = false |
| 327 | } |
| 328 |
| 329 | const resetPageAndFetch = () => { |
| 330 | clearSearchDebounce() |
| 331 | page.value = 1 |
| 332 | fetchProxies() |
| 333 | } |
| 334 |
| 335 | const onPageChange = (value: number) => { |
| 336 | clearSearchDebounce() |
| 337 | page.value = value |
| 338 | fetchProxies() |
| 339 | } |
| 340 |
| 341 | const onPageSizeChange = (value: number) => { |
| 342 | pageSize.value = value |
| 343 | resetPageAndFetch() |
| 344 | } |
| 345 |
| 346 | watch(proxySearch, () => { |
| 347 | clearSearchDebounce() |
| 348 | invalidateProxyRequests() |
| 349 | page.value = 1 |
| 350 | searchDebounceTimer = window.setTimeout(() => { |
| 351 | searchDebounceTimer = null |
| 352 | fetchProxies() |
| 353 | }, 300) |
| 354 | }) |
| 355 |
| 356 | onUnmounted(() => { |
| 357 | clearSearchDebounce() |
| 358 | }) |
| 359 |
| 360 | onMounted(async () => { |
| 361 | const ok = await fetchClient() |
| 362 | if (!ok || !client.value) return |
| 363 |
| 364 | fetchProxies() |
| 365 | }) |
| 366 | </script> |
| 367 |
| 368 | <style scoped> |
| 369 | .client-detail-page { |
| 370 | } |
| 371 |
| 372 | /* Breadcrumb */ |
| 373 | .breadcrumb { |
| 374 | display: flex; |
| 375 | align-items: center; |
| 376 | gap: 8px; |
| 377 | font-size: 14px; |
| 378 | margin-bottom: 24px; |
| 379 | } |
| 380 |
| 381 | .breadcrumb-link { |
| 382 | display: flex; |
| 383 | align-items: center; |
| 384 | color: var(--text-secondary); |
| 385 | cursor: pointer; |
| 386 | transition: color 0.2s; |
| 387 | margin-right: 4px; |
| 388 | } |
| 389 |
| 390 | .breadcrumb-link:hover { |
| 391 | color: var(--text-primary); |
| 392 | } |
| 393 |
| 394 | .breadcrumb-item { |
| 395 | color: var(--text-secondary); |
| 396 | text-decoration: none; |
| 397 | transition: color 0.2s; |
| 398 | } |
| 399 |
| 400 | .breadcrumb-item:hover { |
| 401 | color: var(--el-color-primary); |
| 402 | } |
| 403 |
| 404 | .breadcrumb-separator { |
| 405 | color: var(--el-border-color); |
| 406 | } |
| 407 |
| 408 | .breadcrumb-current { |
| 409 | color: var(--text-primary); |
| 410 | font-weight: 500; |
| 411 | } |
| 412 |
| 413 | /* Card Base */ |
| 414 | .header-card, |
| 415 | .proxies-card { |
| 416 | background: var(--el-bg-color); |
| 417 | border: 1px solid var(--header-border); |
| 418 | border-radius: 12px; |
| 419 | margin-bottom: 16px; |
| 420 | } |
| 421 |
| 422 | /* Header Card */ |
| 423 | .header-main { |
| 424 | display: flex; |
| 425 | justify-content: space-between; |
| 426 | align-items: flex-start; |
| 427 | padding: 24px; |
| 428 | } |
| 429 |
| 430 | .header-left { |
| 431 | display: flex; |
| 432 | gap: 16px; |
| 433 | align-items: center; |
| 434 | } |
| 435 |
| 436 | .client-avatar { |
| 437 | width: 48px; |
| 438 | height: 48px; |
| 439 | border-radius: 12px; |
| 440 | background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); |
| 441 | color: white; |
| 442 | display: flex; |
| 443 | align-items: center; |
| 444 | justify-content: center; |
| 445 | font-size: 20px; |
| 446 | font-weight: 500; |
| 447 | flex-shrink: 0; |
| 448 | } |
| 449 |
| 450 | .client-info { |
| 451 | min-width: 0; |
| 452 | } |
| 453 |
| 454 | .client-name-row { |
| 455 | display: flex; |
| 456 | align-items: center; |
| 457 | gap: 10px; |
| 458 | margin-bottom: 4px; |
| 459 | } |
| 460 |
| 461 | .client-name { |
| 462 | font-size: 20px; |
| 463 | font-weight: 500; |
| 464 | color: var(--text-primary); |
| 465 | margin: 0; |
| 466 | line-height: 1.3; |
| 467 | } |
| 468 |
| 469 | .client-meta { |
| 470 | display: flex; |
| 471 | gap: 12px; |
| 472 | font-size: 14px; |
| 473 | color: var(--text-secondary); |
| 474 | } |
| 475 |
| 476 | .status-badge { |
| 477 | padding: 6px 12px; |
| 478 | border-radius: 6px; |
| 479 | font-size: 13px; |
| 480 | font-weight: 500; |
| 481 | } |
| 482 |
| 483 | .status-badge.online { |
| 484 | background: rgba(34, 197, 94, 0.1); |
| 485 | color: #16a34a; |
| 486 | } |
| 487 |
| 488 | .status-badge.offline { |
| 489 | background: var(--hover-bg); |
| 490 | color: var(--text-secondary); |
| 491 | } |
| 492 |
| 493 | html.dark .status-badge.online { |
| 494 | background: rgba(34, 197, 94, 0.15); |
| 495 | color: #4ade80; |
| 496 | } |
| 497 |
| 498 | /* Info Section */ |
| 499 | .info-section { |
| 500 | display: flex; |
| 501 | flex-wrap: wrap; |
| 502 | gap: 16px 32px; |
| 503 | padding: 16px 24px; |
| 504 | } |
| 505 |
| 506 | .info-item { |
| 507 | display: flex; |
| 508 | align-items: baseline; |
| 509 | gap: 8px; |
| 510 | } |
| 511 |
| 512 | .info-label { |
| 513 | font-size: 13px; |
| 514 | color: var(--text-secondary); |
| 515 | } |
| 516 |
| 517 | .info-label::after { |
| 518 | content: ':'; |
| 519 | } |
| 520 |
| 521 | .info-value { |
| 522 | font-size: 13px; |
| 523 | color: var(--text-primary); |
| 524 | font-weight: 500; |
| 525 | word-break: break-all; |
| 526 | } |
| 527 |
| 528 | /* Proxies Card */ |
| 529 | .proxies-header { |
| 530 | display: flex; |
| 531 | justify-content: space-between; |
| 532 | align-items: center; |
| 533 | padding: 16px 20px; |
| 534 | gap: 16px; |
| 535 | } |
| 536 |
| 537 | .proxies-title { |
| 538 | display: flex; |
| 539 | align-items: center; |
| 540 | gap: 8px; |
| 541 | } |
| 542 |
| 543 | .proxies-title h2 { |
| 544 | font-size: 15px; |
| 545 | font-weight: 500; |
| 546 | color: var(--text-primary); |
| 547 | margin: 0; |
| 548 | } |
| 549 |
| 550 | .proxies-count { |
| 551 | font-size: 13px; |
| 552 | font-weight: 500; |
| 553 | color: var(--text-secondary); |
| 554 | background: var(--hover-bg); |
| 555 | padding: 4px 10px; |
| 556 | border-radius: 6px; |
| 557 | } |
| 558 |
| 559 | .proxy-search { |
| 560 | width: 200px; |
| 561 | } |
| 562 |
| 563 | .proxy-search :deep(.el-input__wrapper) { |
| 564 | border-radius: 6px; |
| 565 | } |
| 566 |
| 567 | .proxies-body { |
| 568 | padding: 16px; |
| 569 | } |
| 570 |
| 571 | .pagination-section { |
| 572 | display: flex; |
| 573 | justify-content: center; |
| 574 | padding: 0 20px 20px; |
| 575 | } |
| 576 |
| 577 | .proxies-list { |
| 578 | display: flex; |
| 579 | flex-direction: column; |
| 580 | gap: 12px; |
| 581 | } |
| 582 |
| 583 | .loading-state { |
| 584 | display: flex; |
| 585 | align-items: center; |
| 586 | justify-content: center; |
| 587 | gap: 8px; |
| 588 | padding: 40px; |
| 589 | color: var(--text-secondary); |
| 590 | } |
| 591 |
| 592 | .empty-state { |
| 593 | text-align: center; |
| 594 | padding: 40px; |
| 595 | color: var(--text-secondary); |
| 596 | } |
| 597 |
| 598 | .empty-state p { |
| 599 | margin: 0; |
| 600 | } |
| 601 |
| 602 | /* Not Found */ |
| 603 | .not-found { |
| 604 | text-align: center; |
| 605 | padding: 60px 20px; |
| 606 | } |
| 607 |
| 608 | .not-found h2 { |
| 609 | font-size: 18px; |
| 610 | font-weight: 500; |
| 611 | color: var(--text-primary); |
| 612 | margin: 0 0 8px; |
| 613 | } |
| 614 |
| 615 | .not-found p { |
| 616 | font-size: 14px; |
| 617 | color: var(--text-secondary); |
| 618 | margin: 0 0 20px; |
| 619 | } |
| 620 |
| 621 | /* Responsive */ |
| 622 | @media (max-width: 640px) { |
| 623 | .header-main { |
| 624 | flex-direction: column; |
| 625 | gap: 16px; |
| 626 | } |
| 627 |
| 628 | .header-right { |
| 629 | align-self: flex-start; |
| 630 | } |
| 631 | } |
| 632 | </style> |