| <!-- Tab bar --> |
| 9 | <div class="tab-bar"> |
| 10 | <div class="tab-buttons"> |
| 11 | <button class="tab-btn active">Store</button> |
| 12 | </div> |
| 13 | <div class="tab-actions"> |
| 14 | <ActionButton variant="outline" size="small" @click="fetchData"> |
| 15 | <el-icon><Refresh /></el-icon> |
| 16 | </ActionButton> |
| 17 | <ActionButton v-if="visitorStore.storeEnabled" size="small" @click="handleCreate"> |
| 18 | + New Visitor |
| 19 | </ActionButton> |
| 20 | </div> |
| 21 | </div> |
| 22 |
| 23 | <div v-loading="visitorStore.loading"> |
| 24 | <div v-if="!visitorStore.storeEnabled" class="store-disabled"> |
| 25 | <p>Store is not enabled. Add the following to your frpc configuration:</p> |
| 26 | <pre class="config-hint">[store] |
| 27 | path = "./frpc_store.json"</pre> |
| 28 | </div> |
| 29 |
| 30 | <template v-else> |
| 31 | <div class="filter-bar"> |
| 32 | <el-input v-model="searchText" placeholder="Search..." clearable class="search-input"> |
| 33 | <template #prefix><el-icon><Search /></el-icon></template> |
| 34 | </el-input> |
| 35 | <FilterDropdown v-model="typeFilter" label="Type" :options="typeOptions" :min-width="140" :is-mobile="isMobile" /> |
| 36 | </div> |
| 37 |
| 38 | <div v-if="filteredVisitors.length > 0" class="visitor-list"> |
| 39 | <div v-for="v in filteredVisitors" :key="v.name" class="visitor-card" @click="goToDetail(v.name)"> |
| 40 | <div class="card-left"> |
| 41 | <div class="card-header"> |
| 42 | <span class="visitor-name">{{ v.name }}</span> |
| 43 | <span class="type-tag">{{ v.type.toUpperCase() }}</span> |
| 44 | </div> |
| 45 | <div v-if="getServerName(v)" class="card-meta">{{ getServerName(v) }}</div> |
| 46 | </div> |
| 47 | <div class="card-right"> |
| 48 | <div @click.stop> |
| 49 | <PopoverMenu :width="120" placement="bottom-end"> |
| 50 | <template #trigger> |
| 51 | <ActionButton variant="outline" size="small"> |
| 52 | <el-icon><MoreFilled /></el-icon> |
| 53 | </ActionButton> |
| 54 | </template> |
| 55 | <PopoverMenuItem @click="handleEdit(v)"> |
| 56 | <el-icon><Edit /></el-icon> |
| 57 | Edit |
| 58 | </PopoverMenuItem> |
| 59 | <PopoverMenuItem danger @click="handleDelete(v.name)"> |
| 60 | <el-icon><Delete /></el-icon> |
| 61 | Delete |
| 62 | </PopoverMenuItem> |
| 63 | </PopoverMenu> |
| 64 | </div> |
| 65 | </div> |
| 66 | </div> |
| 67 | </div> |
| 68 | <div v-else class="empty-state"> |
| 69 | <p class="empty-text">No visitors found</p> |
| 70 | <p class="empty-hint">Click "New Visitor" to create one.</p> |
| 71 | </div> |
| 72 | </template> |
| 73 | </div> |
| 74 |
| 75 | <ConfirmDialog v-model="deleteDialog.visible" title="Delete Visitor" |
| 76 | :message="deleteDialog.message" confirm-text="Delete" danger |
| 77 | :loading="deleteDialog.loading" :is-mobile="isMobile" @confirm="doDelete" /> |
| 78 | </div> |
| 79 | </template> |
| 80 |
| 81 | <script setup lang="ts"> |
| 82 | import { ref, computed, reactive, onMounted } from 'vue' |
| 83 | import { useRouter } from 'vue-router' |
| 84 | import { ElMessage } from 'element-plus' |
| 85 | import { Search, Refresh, MoreFilled, Edit, Delete } from '@element-plus/icons-vue' |
| 86 | import ActionButton from '@shared/components/ActionButton.vue' |
| 87 | import FilterDropdown from '@shared/components/FilterDropdown.vue' |
| 88 | import PopoverMenu from '@shared/components/PopoverMenu.vue' |
| 89 | import PopoverMenuItem from '@shared/components/PopoverMenuItem.vue' |
| 90 | import ConfirmDialog from '@shared/components/ConfirmDialog.vue' |
| 91 | import { useVisitorStore } from '../stores/visitor' |
| 92 | import { useResponsive } from '../composables/useResponsive' |
| 93 | import type { VisitorDefinition } from '../types' |
| 94 |
| 95 | const { isMobile } = useResponsive() |
| 96 | const router = useRouter() |
| 97 | const visitorStore = useVisitorStore() |
| 98 |
| 99 | const searchText = ref('') |
| 100 | const typeFilter = ref('') |
| 101 |
| 102 | const deleteDialog = reactive({ |
| 103 | visible: false, |
| 104 | message: '', |
| 105 | loading: false, |
| 106 | name: '', |
| 107 | }) |
| 108 |
| 109 | const typeOptions = computed(() => { |
| 110 | return [ |
| 111 | { label: 'STCP', value: 'stcp' }, |
| 112 | { label: 'SUDP', value: 'sudp' }, |
| 113 | { label: 'XTCP', value: 'xtcp' }, |
| 114 | ] |
| 115 | }) |
| 116 |
| 117 | const filteredVisitors = computed(() => { |
| 118 | let list = visitorStore.storeVisitors |
| 119 |
| 120 | if (typeFilter.value) { |
| 121 | list = list.filter((v) => v.type === typeFilter.value) |
| 122 | } |
| 123 |
| 124 | if (searchText.value) { |
| 125 | const q = searchText.value.toLowerCase() |
| 126 | list = list.filter((v) => v.name.toLowerCase().includes(q)) |
| 127 | } |
| 128 |
| 129 | return list |
| 130 | }) |
| 131 |
| 132 | const getServerName = (v: VisitorDefinition): string => { |
| 133 | const block = (v as any)[v.type] |
| 134 | return block?.serverName || '' |
| 135 | } |
| 136 |
| 137 | const fetchData = () => { |
| 138 | visitorStore.fetchStoreVisitors() |
| 139 | } |
| 140 |
| 141 | const handleCreate = () => { |
| 142 | router.push('/visitors/create') |
| 143 | } |
| 144 |
| 145 | const handleEdit = (v: VisitorDefinition) => { |
| 146 | router.push('/visitors/' + encodeURIComponent(v.name) + '/edit') |
| 147 | } |
| 148 |
| 149 | const goToDetail = (name: string) => { |
| 150 | router.push('/visitors/detail/' + encodeURIComponent(name)) |
| 151 | } |
| 152 |
| 153 | const handleDelete = (name: string) => { |
| 154 | deleteDialog.name = name |
| 155 | deleteDialog.message = `Are you sure you want to delete visitor "${name}"? This action cannot be undone.` |
| 156 | deleteDialog.visible = true |
| 157 | } |
| 158 |
| 159 | const doDelete = async () => { |
| 160 | deleteDialog.loading = true |
| 161 | try { |
| 162 | await visitorStore.deleteVisitor(deleteDialog.name) |
| 163 | ElMessage.success('Visitor deleted') |
| 164 | deleteDialog.visible = false |
| 165 | fetchData() |
| 166 | } catch (err: any) { |
| 167 | ElMessage.error('Delete failed: ' + (err.message || 'Unknown error')) |
| 168 | } finally { |
| 169 | deleteDialog.loading = false |
| 170 | } |
| 171 | } |
| 172 |
| 173 | onMounted(() => { |
| 174 | fetchData() |
| 175 | }) |
| 176 | </script> |
| 177 |
| 178 | <style scoped lang="scss"> |
| 179 | .visitors-page { |
| 180 | height: 100%; |
| 181 | overflow-y: auto; |
| 182 | padding: $spacing-xl 40px; |
| 183 | max-width: 960px; |
| 184 | margin: 0 auto; |
| 185 | } |
| 186 |
| 187 | .page-header { |
| 188 | display: flex; |
| 189 | align-items: center; |
| 190 | justify-content: space-between; |
| 191 | margin-bottom: $spacing-xl; |
| 192 | } |
| 193 |
| 194 | .tab-bar { |
| 195 | display: flex; |
| 196 | align-items: center; |
| 197 | justify-content: space-between; |
| 198 | border-bottom: 1px solid $color-border-lighter; |
| 199 | margin-bottom: $spacing-xl; |
| 200 | } |
| 201 |
| 202 | .tab-buttons { |
| 203 | display: flex; |
| 204 | } |
| 205 |
| 206 | .tab-btn { |
| 207 | background: none; |
| 208 | border: none; |
| 209 | padding: $spacing-sm $spacing-xl; |
| 210 | font-size: $font-size-md; |
| 211 | color: $color-text-muted; |
| 212 | cursor: pointer; |
| 213 | border-bottom: 2px solid transparent; |
| 214 | transition: all $transition-fast; |
| 215 |
| 216 | &:hover { |
| 217 | color: $color-text-primary; |
| 218 | } |
| 219 |
| 220 | &.active { |
| 221 | color: $color-text-primary; |
| 222 | border-bottom-color: $color-text-primary; |
| 223 | font-weight: $font-weight-medium; |
| 224 | } |
| 225 | } |
| 226 |
| 227 | .tab-actions { |
| 228 | display: flex; |
| 229 | align-items: center; |
| 230 | gap: $spacing-sm; |
| 231 | } |
| 232 |
| 233 | .filter-bar { |
| 234 | display: flex; |
| 235 | align-items: center; |
| 236 | gap: $spacing-sm; |
| 237 | margin-bottom: $spacing-xl; |
| 238 |
| 239 | :deep(.search-input) { |
| 240 | flex: 1; |
| 241 | min-width: 150px; |
| 242 | } |
| 243 | } |
| 244 |
| 245 | .visitor-list { |
| 246 | display: flex; |
| 247 | flex-direction: column; |
| 248 | gap: $spacing-md; |
| 249 | } |
| 250 |
| 251 | .visitor-card { |
| 252 | display: flex; |
| 253 | justify-content: space-between; |
| 254 | align-items: center; |
| 255 | background: $color-bg-primary; |
| 256 | border: 1px solid $color-border-lighter; |
| 257 | border-radius: $radius-md; |
| 258 | padding: 14px 20px; |
| 259 | cursor: pointer; |
| 260 | transition: all $transition-medium; |
| 261 |
| 262 | &:hover { |
| 263 | box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04); |
| 264 | border-color: $color-border; |
| 265 | } |
| 266 | } |
| 267 |
| 268 | .card-left { |
| 269 | @include flex-column; |
| 270 | gap: $spacing-sm; |
| 271 | flex: 1; |
| 272 | min-width: 0; |
| 273 | } |
| 274 |
| 275 | .card-header { |
| 276 | display: flex; |
| 277 | align-items: center; |
| 278 | gap: $spacing-sm; |
| 279 | } |
| 280 |
| 281 | .visitor-name { |
| 282 | font-size: $font-size-lg; |
| 283 | font-weight: $font-weight-semibold; |
| 284 | color: $color-text-primary; |
| 285 | } |
| 286 |
| 287 | .type-tag { |
| 288 | font-size: $font-size-xs; |
| 289 | font-weight: $font-weight-medium; |
| 290 | padding: 2px 8px; |
| 291 | border-radius: 4px; |
| 292 | background: $color-bg-muted; |
| 293 | color: $color-text-secondary; |
| 294 | } |
| 295 |
| 296 | .card-meta { |
| 297 | font-size: $font-size-sm; |
| 298 | color: $color-text-muted; |
| 299 | } |
| 300 |
| 301 | .card-right { |
| 302 | display: flex; |
| 303 | align-items: center; |
| 304 | gap: $spacing-md; |
| 305 | flex-shrink: 0; |
| 306 | } |
| 307 |
| 308 |
| 309 |
| 310 | .store-disabled { |
| 311 | padding: 32px; |
| 312 | text-align: center; |
| 313 | color: $color-text-muted; |
| 314 | } |
| 315 |
| 316 | .config-hint { |
| 317 | display: inline-block; |
| 318 | text-align: left; |
| 319 | background: $color-bg-hover; |
| 320 | padding: 12px 20px; |
| 321 | border-radius: $radius-sm; |
| 322 | font-size: $font-size-sm; |
| 323 | margin-top: $spacing-md; |
| 324 | } |
| 325 |
| 326 | .empty-state { |
| 327 | text-align: center; |
| 328 | padding: 60px $spacing-xl; |
| 329 | } |
| 330 |
| 331 | .empty-text { |
| 332 | font-size: $font-size-lg; |
| 333 | font-weight: $font-weight-medium; |
| 334 | color: $color-text-secondary; |
| 335 | margin: 0 0 $spacing-xs; |
| 336 | } |
| 337 |
| 338 | .empty-hint { |
| 339 | font-size: $font-size-sm; |
| 340 | color: $color-text-muted; |
| 341 | margin: 0; |
| 342 | } |
| 343 |
| 344 | @include mobile { |
| 345 | .visitors-page { |
| 346 | padding: $spacing-lg; |
| 347 | } |
| 348 |
| 349 | .page-header { |
| 350 | flex-direction: column; |
| 351 | align-items: stretch; |
| 352 | gap: $spacing-md; |
| 353 | } |
| 354 |
| 355 | .filter-bar { |
| 356 | flex-wrap: wrap; |
| 357 |
| 358 | :deep(.search-input) { |
| 359 | flex: 1 1 100%; |
| 360 | } |
| 361 | } |
| 362 |
| 363 | .visitor-card { |
| 364 | flex-direction: column; |
| 365 | align-items: stretch; |
| 366 | gap: $spacing-sm; |
| 367 | } |
| 368 |
| 369 | .card-right { |
| 370 | justify-content: flex-end; |
| 371 | } |
| 372 | } |
| 373 | </style> |