| </div> |
| 9 | <div class="status-tabs"> |
| 10 | <button |
| 11 | v-for="tab in statusTabs" |
| 12 | :key="tab.value" |
| 13 | class="status-tab" |
| 14 | :class="{ active: statusFilter === tab.value }" |
| 15 | @click="statusFilter = tab.value" |
| 16 | > |
| 17 | <span class="status-dot" :class="tab.value"></span> |
| 18 | <span class="tab-label">{{ tab.label }}</span> |
| 19 | <span v-if="tab.count !== null" class="tab-count">{{ |
| 20 | tab.count |
| 21 | }}</span> |
| 22 | </button> |
| 23 | </div> |
| 24 | </div> |
| 25 |
| 26 | <div class="search-section"> |
| 27 | <el-input |
| 28 | v-model="searchText" |
| 29 | placeholder="Search clients..." |
| 30 | :prefix-icon="Search" |
| 31 | clearable |
| 32 | class="search-input" |
| 33 | /> |
| 34 | </div> |
| 35 | </div> |
| 36 |
| 37 | <div v-loading="loading" class="clients-content"> |
| 38 | <div v-if="clients.length > 0" class="clients-list"> |
| 39 | <ClientCard |
| 40 | v-for="client in clients" |
| 41 | :key="client.key" |
| 42 | :client="client" |
| 43 | /> |
| 44 | </div> |
| 45 | <div v-else-if="!loading" class="empty-state"> |
| 46 | <el-empty description="No clients found" /> |
| 47 | </div> |
| 48 | </div> |
| 49 |
| 50 | <div v-if="total > 0" class="pagination-section"> |
| 51 | <ElPagination |
| 52 | :current-page="page" |
| 53 | :page-size="pageSize" |
| 54 | :page-sizes="[10, 20, 50, 100]" |
| 55 | :total="total" |
| 56 | layout="total, sizes, prev, pager, next" |
| 57 | @current-change="onPageChange" |
| 58 | @size-change="onPageSizeChange" |
| 59 | /> |
| 60 | </div> |
| 61 | </div> |
| 62 | </template> |
| 63 |
| 64 | <script setup lang="ts"> |
| 65 | import { ref, computed, onMounted, onUnmounted, watch } from 'vue' |
| 66 | import { ElMessage, ElPagination } from 'element-plus' |
| 67 | import { Search } from '@element-plus/icons-vue' |
| 68 | import { Client } from '../utils/client' |
| 69 | import ClientCard from '../components/ClientCard.vue' |
| 70 | import { getClientsV2 } from '../api/client' |
| 71 |
| 72 | const clients = ref<Client[]>([]) |
| 73 | const loading = ref(false) |
| 74 | const searchText = ref('') |
| 75 | const statusFilter = ref<'all' | 'online' | 'offline'>('all') |
| 76 | const page = ref(1) |
| 77 | const pageSize = ref(10) |
| 78 | const total = ref(0) |
| 79 |
| 80 | let refreshTimer: number | null = null |
| 81 | let searchDebounceTimer: number | null = null |
| 82 | let requestSeq = 0 |
| 83 |
| 84 | const statusTabs = computed(() => [ |
| 85 | { |
| 86 | value: 'all' as const, |
| 87 | label: 'All', |
| 88 | count: statusFilter.value === 'all' ? total.value : null, |
| 89 | }, |
| 90 | { |
| 91 | value: 'online' as const, |
| 92 | label: 'Online', |
| 93 | count: statusFilter.value === 'online' ? total.value : null, |
| 94 | }, |
| 95 | { |
| 96 | value: 'offline' as const, |
| 97 | label: 'Offline', |
| 98 | count: statusFilter.value === 'offline' ? total.value : null, |
| 99 | }, |
| 100 | ]) |
| 101 |
| 102 | const fetchData = async (silent = false) => { |
| 103 | const seq = ++requestSeq |
| 104 | if (!silent) loading.value = true |
| 105 | try { |
| 106 | const data = await getClientsV2({ |
| 107 | page: page.value, |
| 108 | pageSize: pageSize.value, |
| 109 | status: statusFilter.value, |
| 110 | q: searchText.value.trim(), |
| 111 | }) |
| 112 | if (seq !== requestSeq) return |
| 113 |
| 114 | const maxPage = Math.max(1, Math.ceil(data.total / data.pageSize)) |
| 115 | if (data.items.length === 0 && data.total > 0 && data.page > maxPage) { |
| 116 | page.value = maxPage |
| 117 | await fetchData(silent) |
| 118 | return |
| 119 | } |
| 120 |
| 121 | clients.value = data.items.map((item) => new Client(item)) |
| 122 | total.value = data.total |
| 123 | page.value = data.page |
| 124 | pageSize.value = data.pageSize |
| 125 | } catch (error: any) { |
| 126 | if (seq !== requestSeq) return |
| 127 | ElMessage({ |
| 128 | showClose: true, |
| 129 | message: 'Failed to fetch clients: ' + error.message, |
| 130 | type: 'error', |
| 131 | }) |
| 132 | } finally { |
| 133 | if (seq === requestSeq) { |
| 134 | loading.value = false |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 |
| 139 | const clearSearchDebounce = () => { |
| 140 | if (searchDebounceTimer !== null) { |
| 141 | window.clearTimeout(searchDebounceTimer) |
| 142 | searchDebounceTimer = null |
| 143 | } |
| 144 | } |
| 145 |
| 146 | const resetPageAndFetch = () => { |
| 147 | clearSearchDebounce() |
| 148 | page.value = 1 |
| 149 | fetchData() |
| 150 | } |
| 151 |
| 152 | const onPageChange = (value: number) => { |
| 153 | clearSearchDebounce() |
| 154 | page.value = value |
| 155 | fetchData() |
| 156 | } |
| 157 |
| 158 | const onPageSizeChange = (value: number) => { |
| 159 | pageSize.value = value |
| 160 | resetPageAndFetch() |
| 161 | } |
| 162 |
| 163 | const startAutoRefresh = () => { |
| 164 | refreshTimer = window.setInterval(() => { |
| 165 | fetchData(true) |
| 166 | }, 5000) |
| 167 | } |
| 168 |
| 169 | const stopAutoRefresh = () => { |
| 170 | if (refreshTimer !== null) { |
| 171 | window.clearInterval(refreshTimer) |
| 172 | refreshTimer = null |
| 173 | } |
| 174 | } |
| 175 |
| 176 | watch(statusFilter, () => { |
| 177 | resetPageAndFetch() |
| 178 | }) |
| 179 |
| 180 | watch(searchText, () => { |
| 181 | clearSearchDebounce() |
| 182 | page.value = 1 |
| 183 | searchDebounceTimer = window.setTimeout(() => { |
| 184 | searchDebounceTimer = null |
| 185 | fetchData() |
| 186 | }, 300) |
| 187 | }) |
| 188 |
| 189 | onMounted(() => { |
| 190 | fetchData() |
| 191 | startAutoRefresh() |
| 192 | }) |
| 193 |
| 194 | onUnmounted(() => { |
| 195 | stopAutoRefresh() |
| 196 | clearSearchDebounce() |
| 197 | }) |
| 198 | </script> |
| 199 |
| 200 | <style scoped> |
| 201 | .clients-page { |
| 202 | display: flex; |
| 203 | flex-direction: column; |
| 204 | gap: 24px; |
| 205 | } |
| 206 |
| 207 | .page-header { |
| 208 | display: flex; |
| 209 | flex-direction: column; |
| 210 | gap: 24px; |
| 211 | } |
| 212 |
| 213 | .header-top { |
| 214 | display: flex; |
| 215 | justify-content: space-between; |
| 216 | align-items: flex-end; |
| 217 | gap: 20px; |
| 218 | flex-wrap: wrap; |
| 219 | } |
| 220 |
| 221 | .title-section { |
| 222 | display: flex; |
| 223 | flex-direction: column; |
| 224 | gap: 8px; |
| 225 | } |
| 226 |
| 227 | .page-title { |
| 228 | font-size: 28px; |
| 229 | font-weight: 600; |
| 230 | color: var(--el-text-color-primary); |
| 231 | margin: 0; |
| 232 | line-height: 1.2; |
| 233 | } |
| 234 |
| 235 | .page-subtitle { |
| 236 | font-size: 14px; |
| 237 | color: var(--el-text-color-secondary); |
| 238 | margin: 0; |
| 239 | } |
| 240 |
| 241 | .status-tabs { |
| 242 | display: flex; |
| 243 | gap: 12px; |
| 244 | } |
| 245 |
| 246 | .status-tab { |
| 247 | display: flex; |
| 248 | align-items: center; |
| 249 | gap: 8px; |
| 250 | padding: 8px 16px; |
| 251 | border: 1px solid var(--el-border-color); |
| 252 | border-radius: 20px; |
| 253 | background: var(--el-bg-color); |
| 254 | color: var(--el-text-color-regular); |
| 255 | font-size: 14px; |
| 256 | font-weight: 500; |
| 257 | cursor: pointer; |
| 258 | transition: all 0.2s; |
| 259 | } |
| 260 |
| 261 | .status-tab:hover { |
| 262 | border-color: var(--el-border-color-darker); |
| 263 | background: var(--el-fill-color-light); |
| 264 | } |
| 265 |
| 266 | .status-tab.active { |
| 267 | background: var(--el-fill-color-dark); |
| 268 | border-color: var(--el-text-color-primary); |
| 269 | color: var(--el-text-color-primary); |
| 270 | } |
| 271 |
| 272 | .status-dot { |
| 273 | width: 8px; |
| 274 | height: 8px; |
| 275 | border-radius: 50%; |
| 276 | background-color: var(--el-text-color-secondary); |
| 277 | } |
| 278 |
| 279 | .status-dot.online { |
| 280 | background-color: var(--el-color-success); |
| 281 | } |
| 282 |
| 283 | .status-dot.offline { |
| 284 | background-color: var(--el-text-color-placeholder); |
| 285 | } |
| 286 |
| 287 | .status-dot.all { |
| 288 | background-color: var(--el-text-color-regular); |
| 289 | } |
| 290 |
| 291 | .tab-count { |
| 292 | font-weight: 500; |
| 293 | opacity: 0.8; |
| 294 | } |
| 295 |
| 296 | .search-section { |
| 297 | width: 100%; |
| 298 | } |
| 299 |
| 300 | .search-input :deep(.el-input__wrapper) { |
| 301 | border-radius: 12px; |
| 302 | box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04); |
| 303 | padding: 8px 16px; |
| 304 | border: 1px solid var(--el-border-color); |
| 305 | transition: all 0.2s; |
| 306 | height: 48px; |
| 307 | font-size: 15px; |
| 308 | } |
| 309 |
| 310 | .search-input :deep(.el-input__wrapper:hover) { |
| 311 | border-color: var(--el-border-color-darker); |
| 312 | box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06); |
| 313 | } |
| 314 |
| 315 | .search-input :deep(.el-input__wrapper.is-focus) { |
| 316 | border-color: var(--el-color-primary); |
| 317 | box-shadow: 0 0 0 1px var(--el-color-primary); |
| 318 | } |
| 319 |
| 320 | .clients-content { |
| 321 | min-height: 200px; |
| 322 | } |
| 323 |
| 324 | .clients-list { |
| 325 | display: flex; |
| 326 | flex-direction: column; |
| 327 | gap: 16px; |
| 328 | } |
| 329 |
| 330 | .empty-state { |
| 331 | padding: 60px 0; |
| 332 | } |
| 333 |
| 334 | .pagination-section { |
| 335 | display: flex; |
| 336 | justify-content: flex-end; |
| 337 | } |
| 338 |
| 339 | /* Dark mode adjustments */ |
| 340 | html.dark .status-tab { |
| 341 | background: var(--el-bg-color-overlay); |
| 342 | } |
| 343 |
| 344 | html.dark .status-tab.active { |
| 345 | background: var(--el-fill-color); |
| 346 | } |
| 347 |
| 348 | @media (max-width: 640px) { |
| 349 | .header-top { |
| 350 | flex-direction: column; |
| 351 | align-items: flex-start; |
| 352 | } |
| 353 |
| 354 | .status-tabs { |
| 355 | width: 100%; |
| 356 | overflow-x: auto; |
| 357 | padding-bottom: 4px; |
| 358 | } |
| 359 |
| 360 | .status-tab { |
| 361 | flex-shrink: 0; |
| 362 | } |
| 363 |
| 364 | .pagination-section { |
| 365 | justify-content: center; |
| 366 | } |
| 367 | } |
| 368 | </style> |