| </div> |
| 9 |
| 10 | <!-- Tabs --> |
| 11 | <div class="tab-bar"> |
| 12 | <div class="tab-buttons"> |
| 13 | <button class="tab-btn" :class="{ active: activeTab === 'status' }" @click="switchTab('status')">Status</button> |
| 14 | <button class="tab-btn" :class="{ active: activeTab === 'store' }" @click="switchTab('store')">Store</button> |
| 15 | </div> |
| 16 | <div class="tab-actions"> |
| 17 | <ActionButton variant="outline" size="small" @click="refreshData"> |
| 18 | <el-icon><Refresh /></el-icon> |
| 19 | </ActionButton> |
| 20 | <ActionButton v-if="activeTab === 'store' && proxyStore.storeEnabled" size="small" @click="handleCreate"> |
| 21 | + New Proxy |
| 22 | </ActionButton> |
| 23 | </div> |
| 24 | </div> |
| 25 |
| 26 | <!-- Status Tab Filters --> |
| 27 | <template v-if="activeTab === 'status'"> |
| 28 | <StatusPills v-if="!isMobile" :items="proxyStore.proxies" v-model="statusFilter" /> |
| 29 | <div class="filter-bar"> |
| 30 | <el-input v-model="searchText" placeholder="Search..." clearable class="search-input"> |
| 31 | <template #prefix><el-icon><Search /></el-icon></template> |
| 32 | </el-input> |
| 33 | <FilterDropdown v-model="sourceFilter" label="Source" :options="sourceOptions" :min-width="140" :is-mobile="isMobile" /> |
| 34 | <FilterDropdown v-model="typeFilter" label="Type" :options="typeOptions" :min-width="140" :is-mobile="isMobile" /> |
| 35 | </div> |
| 36 | </template> |
| 37 |
| 38 | <!-- Store Tab Filters --> |
| 39 | <template v-if="activeTab === 'store' && proxyStore.storeEnabled"> |
| 40 | <div class="filter-bar"> |
| 41 | <el-input v-model="storeSearch" placeholder="Search..." clearable class="search-input"> |
| 42 | <template #prefix><el-icon><Search /></el-icon></template> |
| 43 | </el-input> |
| 44 | <FilterDropdown v-model="storeTypeFilter" label="Type" :options="storeTypeOptions" :min-width="140" :is-mobile="isMobile" /> |
| 45 | </div> |
| 46 | </template> |
| 47 | </div> |
| 48 |
| 49 | <!-- Scrollable list area --> |
| 50 | <div class="page-content"> |
| 51 | <!-- Status Tab List --> |
| 52 | <div v-if="activeTab === 'status'" v-loading="proxyStore.loading"> |
| 53 | <div v-if="filteredStatus.length > 0" class="proxy-list"> |
| 54 | <ProxyCard |
| 55 | v-for="p in filteredStatus" |
| 56 | :key="p.name" |
| 57 | :proxy="p" |
| 58 | showSource |
| 59 | @click="goToDetail(p.name)" |
| 60 | /> |
| 61 | </div> |
| 62 | <div v-else-if="!proxyStore.loading" class="empty-state"> |
| 63 | <p class="empty-text">No proxies found</p> |
| 64 | <p class="empty-hint">Proxies will appear here once configured and connected.</p> |
| 65 | </div> |
| 66 | </div> |
| 67 |
| 68 | <!-- Store Tab List --> |
| 69 | <div v-if="activeTab === 'store'" v-loading="proxyStore.storeLoading"> |
| 70 | <div v-if="!proxyStore.storeEnabled" class="store-disabled"> |
| 71 | <p>Store is not enabled. Add the following to your frpc configuration:</p> |
| 72 | <pre class="config-hint">[store] |
| 73 | path = "./frpc_store.json"</pre> |
| 74 | </div> |
| 75 | <template v-else> |
| 76 | <div v-if="filteredStoreProxies.length > 0" class="proxy-list"> |
| 77 | <ProxyCard |
| 78 | v-for="p in filteredStoreProxies" |
| 79 | :key="p.name" |
| 80 | :proxy="proxyStore.storeProxyWithStatus(p)" |
| 81 | showActions |
| 82 | @click="goToDetail(p.name)" |
| 83 | @edit="handleEdit" |
| 84 | @toggle="handleToggleProxy" |
| 85 | @delete="handleDeleteProxy(p.name)" |
| 86 | /> |
| 87 | </div> |
| 88 | <div v-else class="empty-state"> |
| 89 | <p class="empty-text">No store proxies</p> |
| 90 | <p class="empty-hint">Click "New Proxy" to create one.</p> |
| 91 | </div> |
| 92 | </template> |
| 93 | </div> |
| 94 | </div> |
| 95 |
| 96 | <ConfirmDialog |
| 97 | v-model="deleteDialog.visible" |
| 98 | title="Delete Proxy" |
| 99 | :message="deleteDialog.message" |
| 100 | confirm-text="Delete" |
| 101 | danger |
| 102 | :loading="deleteDialog.loading" |
| 103 | :is-mobile="isMobile" |
| 104 | @confirm="doDelete" |
| 105 | /> |
| 106 | </div> |
| 107 | </template> |
| 108 |
| 109 | <script setup lang="ts"> |
| 110 | import { ref, computed, reactive, onMounted } from 'vue' |
| 111 | import { useRoute, useRouter } from 'vue-router' |
| 112 | import { ElMessage } from 'element-plus' |
| 113 | import { Search, Refresh } from '@element-plus/icons-vue' |
| 114 | import ActionButton from '@shared/components/ActionButton.vue' |
| 115 | import StatusPills from '../components/StatusPills.vue' |
| 116 | import FilterDropdown from '@shared/components/FilterDropdown.vue' |
| 117 | import ProxyCard from '../components/ProxyCard.vue' |
| 118 | import ConfirmDialog from '@shared/components/ConfirmDialog.vue' |
| 119 | import { useProxyStore } from '../stores/proxy' |
| 120 | import { useResponsive } from '../composables/useResponsive' |
| 121 | import type { ProxyStatus } from '../types' |
| 122 |
| 123 | const { isMobile } = useResponsive() |
| 124 |
| 125 | const route = useRoute() |
| 126 | const router = useRouter() |
| 127 | const proxyStore = useProxyStore() |
| 128 |
| 129 | // Tab |
| 130 | const activeTab = computed(() => { |
| 131 | const tab = route.query.tab as string |
| 132 | return tab === 'store' ? 'store' : 'status' |
| 133 | }) |
| 134 |
| 135 | const switchTab = (tab: string) => { |
| 136 | router.replace({ query: tab === 'status' ? {} : { tab } }) |
| 137 | } |
| 138 |
| 139 | // Filters (local UI state) |
| 140 | const statusFilter = ref('') |
| 141 | const typeFilter = ref('') |
| 142 | const sourceFilter = ref('') |
| 143 | const searchText = ref('') |
| 144 | const storeSearch = ref('') |
| 145 | const storeTypeFilter = ref('') |
| 146 |
| 147 | // Delete dialog |
| 148 | const deleteDialog = reactive({ |
| 149 | visible: false, |
| 150 | title: 'Delete Proxy', |
| 151 | message: '', |
| 152 | loading: false, |
| 153 | name: '', |
| 154 | }) |
| 155 |
| 156 | // Source handling |
| 157 | const displaySource = (proxy: ProxyStatus): string => { |
| 158 | return proxy.source === 'store' ? 'store' : 'config' |
| 159 | } |
| 160 |
| 161 | // Filter options |
| 162 | const sourceOptions = computed(() => { |
| 163 | const sources = new Set<string>() |
| 164 | sources.add('config') |
| 165 | sources.add('store') |
| 166 | proxyStore.proxies.forEach((p) => { |
| 167 | sources.add(displaySource(p)) |
| 168 | }) |
| 169 | return Array.from(sources) |
| 170 | .sort() |
| 171 | .map((s) => ({ label: s, value: s })) |
| 172 | }) |
| 173 |
| 174 | const PROXY_TYPE_ORDER = ['tcp', 'udp', 'http', 'https', 'tcpmux', 'stcp', 'sudp', 'xtcp'] |
| 175 |
| 176 | const sortByTypeOrder = (types: string[]) => { |
| 177 | return types.sort((a, b) => { |
| 178 | const ia = PROXY_TYPE_ORDER.indexOf(a) |
| 179 | const ib = PROXY_TYPE_ORDER.indexOf(b) |
| 180 | return (ia === -1 ? 999 : ia) - (ib === -1 ? 999 : ib) |
| 181 | }) |
| 182 | } |
| 183 |
| 184 | const typeOptions = computed(() => { |
| 185 | const types = new Set<string>() |
| 186 | proxyStore.proxies.forEach((p) => types.add(p.type)) |
| 187 | return sortByTypeOrder(Array.from(types)) |
| 188 | .map((t) => ({ label: t.toUpperCase(), value: t })) |
| 189 | }) |
| 190 |
| 191 | const storeTypeOptions = computed(() => { |
| 192 | const types = new Set<string>() |
| 193 | proxyStore.storeProxies.forEach((p) => types.add(p.type)) |
| 194 | return sortByTypeOrder(Array.from(types)) |
| 195 | .map((t) => ({ label: t.toUpperCase(), value: t })) |
| 196 | }) |
| 197 |
| 198 | // Filtered computeds — Status tab uses proxyStore.proxies (runtime only) |
| 199 | const filteredStatus = computed(() => { |
| 200 | let result = proxyStore.proxies as ProxyStatus[] |
| 201 |
| 202 | if (statusFilter.value) { |
| 203 | result = result.filter((p) => p.status === statusFilter.value) |
| 204 | } |
| 205 |
| 206 | if (typeFilter.value) { |
| 207 | result = result.filter((p) => p.type === typeFilter.value) |
| 208 | } |
| 209 |
| 210 | if (sourceFilter.value) { |
| 211 | result = result.filter((p) => displaySource(p) === sourceFilter.value) |
| 212 | } |
| 213 |
| 214 | if (searchText.value) { |
| 215 | const search = searchText.value.toLowerCase() |
| 216 | result = result.filter( |
| 217 | (p) => |
| 218 | p.name.toLowerCase().includes(search) || |
| 219 | p.type.toLowerCase().includes(search) || |
| 220 | p.local_addr.toLowerCase().includes(search) || |
| 221 | p.remote_addr.toLowerCase().includes(search), |
| 222 | ) |
| 223 | } |
| 224 |
| 225 | return result |
| 226 | }) |
| 227 |
| 228 | const filteredStoreProxies = computed(() => { |
| 229 | let list = proxyStore.storeProxies |
| 230 |
| 231 | if (storeTypeFilter.value) { |
| 232 | list = list.filter((p) => p.type === storeTypeFilter.value) |
| 233 | } |
| 234 |
| 235 | if (storeSearch.value) { |
| 236 | const q = storeSearch.value.toLowerCase() |
| 237 | list = list.filter((p) => p.name.toLowerCase().includes(q)) |
| 238 | } |
| 239 |
| 240 | return list |
| 241 | }) |
| 242 |
| 243 | // Data fetching |
| 244 | const refreshData = () => { |
| 245 | proxyStore.fetchStatus().catch((err: any) => { |
| 246 | ElMessage.error('Failed to get status: ' + err.message) |
| 247 | }) |
| 248 | proxyStore.fetchStoreProxies() |
| 249 | } |
| 250 |
| 251 | // Navigation |
| 252 | const goToDetail = (name: string) => { |
| 253 | router.push('/proxies/detail/' + encodeURIComponent(name)) |
| 254 | } |
| 255 |
| 256 | const handleCreate = () => { |
| 257 | router.push('/proxies/create') |
| 258 | } |
| 259 |
| 260 | const handleEdit = (proxy: ProxyStatus) => { |
| 261 | router.push('/proxies/' + encodeURIComponent(proxy.name) + '/edit') |
| 262 | } |
| 263 |
| 264 | const handleToggleProxy = async (proxy: ProxyStatus, enabled: boolean) => { |
| 265 | try { |
| 266 | await proxyStore.toggleProxy(proxy.name, enabled) |
| 267 | ElMessage.success(enabled ? 'Proxy enabled' : 'Proxy disabled') |
| 268 | } catch (err: any) { |
| 269 | ElMessage.error('Operation failed: ' + (err.message || 'Unknown error')) |
| 270 | } |
| 271 | } |
| 272 |
| 273 | const handleDeleteProxy = (name: string) => { |
| 274 | deleteDialog.name = name |
| 275 | deleteDialog.message = `Are you sure you want to delete "${name}"? This action cannot be undone.` |
| 276 | deleteDialog.visible = true |
| 277 | } |
| 278 |
| 279 | const doDelete = async () => { |
| 280 | deleteDialog.loading = true |
| 281 | try { |
| 282 | await proxyStore.deleteProxy(deleteDialog.name) |
| 283 | ElMessage.success('Proxy deleted') |
| 284 | deleteDialog.visible = false |
| 285 | proxyStore.fetchStatus() |
| 286 | } catch (err: any) { |
| 287 | ElMessage.error('Delete failed: ' + (err.message || 'Unknown error')) |
| 288 | } finally { |
| 289 | deleteDialog.loading = false |
| 290 | } |
| 291 | } |
| 292 |
| 293 | onMounted(() => { |
| 294 | refreshData() |
| 295 | }) |
| 296 | </script> |
| 297 |
| 298 | <style scoped lang="scss"> |
| 299 | .proxies-page { |
| 300 | display: flex; |
| 301 | flex-direction: column; |
| 302 | height: 100%; |
| 303 | max-width: 960px; |
| 304 | margin: 0 auto; |
| 305 | } |
| 306 |
| 307 | .page-top { |
| 308 | flex-shrink: 0; |
| 309 | padding: $spacing-xl 40px 0; |
| 310 | } |
| 311 |
| 312 | .page-content { |
| 313 | flex: 1; |
| 314 | overflow-y: auto; |
| 315 | padding: 0 40px $spacing-xl; |
| 316 | } |
| 317 |
| 318 | .page-header { |
| 319 | display: flex; |
| 320 | align-items: center; |
| 321 | justify-content: space-between; |
| 322 | margin-bottom: $spacing-xl; |
| 323 | } |
| 324 |
| 325 | .tab-bar { |
| 326 | display: flex; |
| 327 | align-items: center; |
| 328 | justify-content: space-between; |
| 329 | border-bottom: 1px solid $color-border-lighter; |
| 330 | margin-bottom: $spacing-xl; |
| 331 | } |
| 332 |
| 333 | .tab-buttons { |
| 334 | display: flex; |
| 335 | } |
| 336 |
| 337 | .tab-actions { |
| 338 | display: flex; |
| 339 | align-items: center; |
| 340 | gap: $spacing-sm; |
| 341 | } |
| 342 |
| 343 | .tab-btn { |
| 344 | background: none; |
| 345 | border: none; |
| 346 | padding: $spacing-sm $spacing-xl; |
| 347 | font-size: $font-size-md; |
| 348 | color: $color-text-muted; |
| 349 | cursor: pointer; |
| 350 | border-bottom: 2px solid transparent; |
| 351 | transition: all $transition-fast; |
| 352 |
| 353 | &:hover { color: $color-text-primary; } |
| 354 | &.active { |
| 355 | color: $color-text-primary; |
| 356 | border-bottom-color: $color-text-primary; |
| 357 | font-weight: $font-weight-medium; |
| 358 | } |
| 359 | } |
| 360 |
| 361 | .filter-bar { |
| 362 | display: flex; |
| 363 | align-items: center; |
| 364 | gap: $spacing-sm; |
| 365 | margin-top: $spacing-lg; |
| 366 | padding-bottom: $spacing-lg; |
| 367 |
| 368 | :deep(.search-input) { |
| 369 | flex: 1; |
| 370 | min-width: 150px; |
| 371 | } |
| 372 | } |
| 373 |
| 374 | .proxy-list { |
| 375 | display: flex; |
| 376 | flex-direction: column; |
| 377 | gap: $spacing-md; |
| 378 | } |
| 379 |
| 380 | .empty-state { |
| 381 | text-align: center; |
| 382 | padding: 60px $spacing-xl; |
| 383 | } |
| 384 |
| 385 | .empty-text { |
| 386 | font-size: $font-size-lg; |
| 387 | font-weight: $font-weight-medium; |
| 388 | color: $color-text-secondary; |
| 389 | margin: 0 0 $spacing-xs; |
| 390 | } |
| 391 |
| 392 | .empty-hint { |
| 393 | font-size: $font-size-sm; |
| 394 | color: $color-text-muted; |
| 395 | margin: 0; |
| 396 | } |
| 397 |
| 398 | .store-disabled { |
| 399 | padding: 32px; |
| 400 | text-align: center; |
| 401 | color: $color-text-muted; |
| 402 | } |
| 403 |
| 404 | .config-hint { |
| 405 | display: inline-block; |
| 406 | text-align: left; |
| 407 | background: $color-bg-hover; |
| 408 | padding: 12px 20px; |
| 409 | border-radius: $radius-sm; |
| 410 | font-size: $font-size-sm; |
| 411 | margin-top: $spacing-md; |
| 412 | } |
| 413 |
| 414 | @include mobile { |
| 415 | .page-top { |
| 416 | padding: $spacing-lg $spacing-lg 0; |
| 417 | } |
| 418 |
| 419 | .page-content { |
| 420 | padding: 0 $spacing-lg $spacing-lg; |
| 421 | } |
| 422 |
| 423 | .page-header { |
| 424 | flex-direction: column; |
| 425 | align-items: stretch; |
| 426 | gap: $spacing-md; |
| 427 | } |
| 428 |
| 429 | .header-actions { |
| 430 | justify-content: flex-end; |
| 431 | } |
| 432 |
| 433 | .filter-bar { |
| 434 | :deep(.search-input) { |
| 435 | flex: 1; |
| 436 | min-width: 0; |
| 437 | } |
| 438 | } |
| 439 | } |
| 440 | </style> |