Spaces:
Paused
Paused
Update public/index.html
Browse files- public/index.html +750 -1338
public/index.html
CHANGED
|
@@ -2,442 +2,279 @@
|
|
| 2 |
<html lang="zh">
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
| 6 |
<title>HF Space Manager</title>
|
|
|
|
| 7 |
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.7/dist/chart.umd.min.js"></script>
|
| 8 |
-
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23fff'%3E%3Cpath d='M13 21h-2v-11h2v11zm4 0h-2v-7h2v7zm4 0h-2v-4h2v4zm-16 0h-2v-14h2v14zm4 0h-2v-18h2v18z'/%3E%3C/svg%3E" type="image/svg+xml">
|
| 9 |
-
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap">
|
| 10 |
<style>
|
| 11 |
* {
|
| 12 |
margin: 0;
|
| 13 |
padding: 0;
|
| 14 |
box-sizing: border-box;
|
| 15 |
}
|
| 16 |
-
|
| 17 |
body {
|
| 18 |
-
font-family:
|
| 19 |
background: var(--background-color);
|
| 20 |
color: var(--text-color);
|
| 21 |
-
padding:
|
| 22 |
min-height: 100vh;
|
| 23 |
transition: background 0.3s ease, color 0.3s ease;
|
| 24 |
-
line-height: 1.6;
|
| 25 |
}
|
| 26 |
-
|
| 27 |
:root {
|
|
|
|
| 28 |
--background-color: #0a0a0a;
|
| 29 |
-
--text-color: #
|
| 30 |
-
--card-background: #
|
| 31 |
-
--card-border: rgba(255, 255, 255, 0.
|
| 32 |
-
--metric-background: #
|
| 33 |
--metric-border: rgba(255, 255, 255, 0.05);
|
| 34 |
-
--metric-hover: #
|
| 35 |
-
--secondary-text: #
|
| 36 |
-
--label-color: #
|
| 37 |
-
--network-background: rgba(255, 255, 255, 0.
|
| 38 |
--action-button-bg: #3a3a3a;
|
| 39 |
--action-button-hover: #4a4a4a;
|
| 40 |
-
--action-button-text: #e0e0e0;
|
| 41 |
-
--accent-color: #4CAF50;
|
| 42 |
-
--error-color: #f44336;
|
| 43 |
-
--warning-color: #ffa500;
|
| 44 |
-
--success-color: #4CAF50;
|
| 45 |
-
--overlay-background: rgba(0, 0, 0, 0.8);
|
| 46 |
}
|
| 47 |
-
|
| 48 |
[data-theme="light"] {
|
| 49 |
-
|
|
|
|
| 50 |
--text-color: #333;
|
| 51 |
-
--card-background: #
|
| 52 |
--card-border: rgba(0, 0, 0, 0.1);
|
| 53 |
-
--metric-background: #
|
| 54 |
--metric-border: rgba(0, 0, 0, 0.05);
|
| 55 |
-
--metric-hover: #
|
| 56 |
-
--secondary-text: #
|
| 57 |
-
--label-color: #
|
| 58 |
-
--network-background: rgba(0, 0, 0, 0.
|
| 59 |
-
--action-button-bg: #
|
| 60 |
-
--action-button-hover: #
|
| 61 |
-
--action-button-text: #333;
|
| 62 |
-
--accent-color: #4CAF50;
|
| 63 |
-
--error-color: #f44336;
|
| 64 |
-
--warning-color: #ffa500;
|
| 65 |
-
--success-color: #4CAF50;
|
| 66 |
-
--overlay-background: rgba(0, 0, 0, 0.5);
|
| 67 |
}
|
| 68 |
-
|
| 69 |
.container {
|
| 70 |
-
max-width:
|
| 71 |
margin: 0 auto;
|
| 72 |
-
animation: fadeIn 0.
|
| 73 |
padding: 0 15px;
|
| 74 |
}
|
| 75 |
-
|
| 76 |
.overview {
|
| 77 |
background: var(--card-background);
|
| 78 |
-
border-radius:
|
| 79 |
-
padding:
|
| 80 |
-
margin-bottom:
|
| 81 |
border: 1px solid var(--card-border);
|
| 82 |
-
|
| 83 |
-
transition: background 0.3s ease, border 0.3s ease, box-shadow 0.3s ease;
|
| 84 |
}
|
| 85 |
-
|
| 86 |
.overview-title {
|
| 87 |
-
font-size:
|
| 88 |
-
font-weight: 600;
|
| 89 |
display: flex;
|
| 90 |
align-items: center;
|
| 91 |
gap: 10px;
|
| 92 |
-
margin-bottom:
|
| 93 |
color: var(--text-color);
|
| 94 |
}
|
| 95 |
-
|
| 96 |
-
.header-container {
|
| 97 |
-
display: flex;
|
| 98 |
-
justify-content: space-between;
|
| 99 |
-
align-items: center;
|
| 100 |
-
margin-bottom: 20px;
|
| 101 |
-
flex-wrap: wrap;
|
| 102 |
-
gap: 15px;
|
| 103 |
-
}
|
| 104 |
-
|
| 105 |
-
.auth-buttons {
|
| 106 |
-
display: flex;
|
| 107 |
-
gap: 10px;
|
| 108 |
-
}
|
| 109 |
-
|
| 110 |
.theme-toggle {
|
| 111 |
display: flex;
|
| 112 |
align-items: center;
|
| 113 |
-
gap:
|
| 114 |
-
margin-bottom:
|
| 115 |
font-size: 14px;
|
| 116 |
color: var(--secondary-text);
|
| 117 |
}
|
| 118 |
-
|
| 119 |
-
.theme-toggle span {
|
| 120 |
-
font-weight: 500;
|
| 121 |
-
margin-right: 4px;
|
| 122 |
-
}
|
| 123 |
-
|
| 124 |
.theme-toggle button {
|
| 125 |
background: var(--metric-background);
|
| 126 |
border: 1px solid var(--metric-border);
|
| 127 |
color: var(--text-color);
|
| 128 |
-
padding:
|
| 129 |
-
border-radius:
|
| 130 |
cursor: pointer;
|
| 131 |
display: flex;
|
| 132 |
align-items: center;
|
| 133 |
justify-content: center;
|
| 134 |
-
width:
|
| 135 |
-
height:
|
| 136 |
-
transition: background 0.2s ease, transform 0.2s ease
|
| 137 |
-
outline: none;
|
| 138 |
}
|
| 139 |
-
|
| 140 |
.theme-toggle button:hover {
|
| 141 |
background: var(--metric-hover);
|
| 142 |
-
|
| 143 |
-
transform: translateY(-1px);
|
| 144 |
-
}
|
| 145 |
-
|
| 146 |
-
.theme-toggle button:active {
|
| 147 |
-
transform: translateY(0);
|
| 148 |
}
|
| 149 |
-
|
| 150 |
-
.theme-toggle button:focus-visible {
|
| 151 |
-
outline: 2px solid var(--accent-color);
|
| 152 |
-
outline-offset: 2px;
|
| 153 |
-
}
|
| 154 |
-
|
| 155 |
.theme-toggle svg {
|
| 156 |
width: 18px;
|
| 157 |
height: 18px;
|
| 158 |
-
fill: var(--
|
| 159 |
-
transition: fill 0.3s ease;
|
| 160 |
-
}
|
| 161 |
-
|
| 162 |
-
.theme-toggle button[data-active="true"] {
|
| 163 |
-
background: var(--accent-color);
|
| 164 |
-
border-color: var(--accent-color);
|
| 165 |
-
}
|
| 166 |
-
|
| 167 |
-
.theme-toggle button[data-active="true"] svg {
|
| 168 |
-
fill: #fff;
|
| 169 |
}
|
| 170 |
-
|
| 171 |
#summary {
|
| 172 |
display: grid;
|
| 173 |
-
grid-template-columns: repeat(
|
| 174 |
-
gap:
|
| 175 |
}
|
| 176 |
-
|
| 177 |
#summary div {
|
| 178 |
background: var(--metric-background);
|
| 179 |
-
padding:
|
| 180 |
border-radius: 8px;
|
| 181 |
border: 1px solid var(--metric-border);
|
| 182 |
transition: background 0.3s ease, border 0.3s ease;
|
| 183 |
-
display: flex;
|
| 184 |
-
flex-direction: column;
|
| 185 |
-
align-items: flex-start;
|
| 186 |
}
|
| 187 |
-
|
| 188 |
#summary div {
|
| 189 |
font-size: 13px;
|
| 190 |
color: var(--secondary-text);
|
| 191 |
}
|
| 192 |
-
|
| 193 |
#summary span {
|
| 194 |
display: block;
|
| 195 |
-
font-size:
|
| 196 |
-
font-weight:
|
| 197 |
-
margin-top:
|
| 198 |
color: var(--text-color);
|
| 199 |
overflow: hidden;
|
| 200 |
text-overflow: ellipsis;
|
| 201 |
white-space: nowrap;
|
| 202 |
-
width: 100%;
|
| 203 |
}
|
| 204 |
-
|
| 205 |
.stats-container {
|
| 206 |
-
display:
|
| 207 |
-
|
| 208 |
-
gap:
|
| 209 |
-
margin-top:
|
| 210 |
}
|
| 211 |
-
|
| 212 |
.user-group {
|
| 213 |
background: var(--card-background);
|
| 214 |
-
border-radius:
|
| 215 |
border: 1px solid var(--card-border);
|
| 216 |
overflow: hidden;
|
| 217 |
transition: background 0.3s ease, border 0.3s ease;
|
| 218 |
}
|
| 219 |
-
|
| 220 |
.user-group summary {
|
| 221 |
-
padding:
|
| 222 |
-
font-weight:
|
| 223 |
cursor: pointer;
|
| 224 |
color: var(--text-color);
|
| 225 |
background: var(--metric-background);
|
| 226 |
transition: background 0.2s ease;
|
| 227 |
-
display: flex;
|
| 228 |
-
align-items: center;
|
| 229 |
-
justify-content: space-between;
|
| 230 |
-
width: 100%;
|
| 231 |
}
|
| 232 |
-
|
| 233 |
.user-group summary:hover {
|
| 234 |
background: var(--metric-hover);
|
| 235 |
}
|
| 236 |
-
|
| 237 |
-
.user-group summary::marker,
|
| 238 |
.user-group summary::-webkit-details-marker {
|
| 239 |
-
|
| 240 |
-
}
|
| 241 |
-
|
| 242 |
-
.user-group summary::after {
|
| 243 |
-
content: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="%23b0b0b0"><path d="M18.59 10.59L12 17.17 5.41 10.59 4 12l8 8 8-8z"/></svg>');
|
| 244 |
-
display: inline-block;
|
| 245 |
-
margin-left: 10px;
|
| 246 |
-
transform: rotate(0deg);
|
| 247 |
-
transition: transform 0.2s ease;
|
| 248 |
-
fill: var(--secondary-text);
|
| 249 |
-
}
|
| 250 |
-
|
| 251 |
-
.user-group[open] summary::after {
|
| 252 |
-
transform: rotate(180deg);
|
| 253 |
-
}
|
| 254 |
-
|
| 255 |
-
[data-theme="light"] .user-group summary::after {
|
| 256 |
-
content: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="%23555"><path d="M18.59 10.59L12 17.17 5.41 10.59 4 12l8 8 8-8z"/></svg>');
|
| 257 |
}
|
| 258 |
-
|
| 259 |
.user-servers {
|
| 260 |
display: grid;
|
| 261 |
-
grid-template-columns: repeat(
|
| 262 |
gap: 15px;
|
| 263 |
-
padding:
|
| 264 |
}
|
| 265 |
-
|
| 266 |
.server-card {
|
| 267 |
background: var(--metric-background);
|
| 268 |
-
border-radius:
|
| 269 |
-
padding:
|
| 270 |
border: 1px solid var(--metric-border);
|
| 271 |
transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.3s ease, border 0.3s ease;
|
| 272 |
-
min-height:
|
| 273 |
display: flex;
|
| 274 |
flex-direction: column;
|
| 275 |
-
justify-content: space-between;
|
| 276 |
}
|
| 277 |
-
|
|
|
|
|
|
|
| 278 |
.server-card:hover {
|
| 279 |
-
transform: translateY(-
|
| 280 |
-
box-shadow: 0
|
| 281 |
}
|
| 282 |
-
|
| 283 |
.server-header {
|
| 284 |
display: flex;
|
| 285 |
justify-content: space-between;
|
| 286 |
align-items: center;
|
| 287 |
-
margin-bottom:
|
| 288 |
-
font-size:
|
| 289 |
-
flex-wrap: wrap;
|
| 290 |
-
gap: 10px;
|
| 291 |
}
|
| 292 |
-
|
| 293 |
.server-name {
|
| 294 |
display: flex;
|
| 295 |
align-items: center;
|
| 296 |
-
gap:
|
| 297 |
flex: 1;
|
| 298 |
-
min-width: 0;
|
| 299 |
-
font-weight: 600;
|
| 300 |
-
color: var(--text-color);
|
| 301 |
}
|
| 302 |
-
|
| 303 |
.server-name div {
|
| 304 |
overflow: hidden;
|
| 305 |
text-overflow: ellipsis;
|
| 306 |
white-space: nowrap;
|
| 307 |
-
max-width: 100%;
|
| 308 |
}
|
| 309 |
-
|
| 310 |
.server-flag {
|
| 311 |
width: 20px;
|
| 312 |
height: 20px;
|
| 313 |
border-radius: 4px;
|
| 314 |
-
border: 1px solid rgba(0, 0, 0, 0.1);
|
| 315 |
flex-shrink: 0;
|
| 316 |
-
fill: var(--label-color);
|
| 317 |
}
|
| 318 |
-
|
| 319 |
.metric-grid {
|
| 320 |
display: grid;
|
| 321 |
-
grid-template-columns: repeat(
|
| 322 |
gap: 10px;
|
| 323 |
-
margin-top:
|
| 324 |
-
}
|
| 325 |
-
|
| 326 |
-
@media (max-width: 400px) {
|
| 327 |
-
.metric-grid {
|
| 328 |
-
grid-template-columns: repeat(2, 1fr);
|
| 329 |
-
}
|
| 330 |
}
|
| 331 |
-
|
| 332 |
.metric-item {
|
| 333 |
background: var(--card-background);
|
| 334 |
-
padding:
|
| 335 |
border-radius: 6px;
|
| 336 |
border: 1px solid var(--metric-border);
|
| 337 |
-
transition: background 0.3s ease
|
| 338 |
-
overflow: hidden;
|
| 339 |
}
|
| 340 |
-
|
| 341 |
.metric-item:hover {
|
| 342 |
background: var(--metric-hover);
|
| 343 |
}
|
| 344 |
-
|
| 345 |
.metric-label {
|
| 346 |
color: var(--label-color);
|
| 347 |
font-size: 12px;
|
| 348 |
-
margin-bottom:
|
| 349 |
white-space: nowrap;
|
| 350 |
-
font-weight: 500;
|
| 351 |
}
|
| 352 |
-
|
| 353 |
.metric-value {
|
| 354 |
-
font-size:
|
| 355 |
-
font-weight:
|
| 356 |
-
color: var(--text-color);
|
| 357 |
overflow: hidden;
|
| 358 |
text-overflow: ellipsis;
|
| 359 |
white-space: nowrap;
|
| 360 |
-
max-width: 100%;
|
| 361 |
-
}
|
| 362 |
-
|
| 363 |
-
.metric-value.status-running {
|
| 364 |
-
color: var(--success-color);
|
| 365 |
-
}
|
| 366 |
-
|
| 367 |
-
.metric-value.status-sleeping {
|
| 368 |
-
color: var(--warning-color);
|
| 369 |
-
}
|
| 370 |
-
|
| 371 |
-
.metric-value.status-stopped {
|
| 372 |
-
color: var(--error-color);
|
| 373 |
}
|
| 374 |
-
|
| 375 |
.status-dot {
|
| 376 |
display: inline-block;
|
| 377 |
border-radius: 50%;
|
|
|
|
| 378 |
width: 10px;
|
| 379 |
height: 10px;
|
| 380 |
flex-shrink: 0;
|
| 381 |
-
margin-right: 5px;
|
| 382 |
}
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
animation: pulse 2s infinite;
|
| 387 |
-
box-shadow: 0 0 0 rgba(76, 175, 80, 0.4);
|
| 388 |
}
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
}
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
animation: none;
|
| 397 |
}
|
| 398 |
-
|
| 399 |
-
@keyframes pulse {
|
| 400 |
-
0% { box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.4); }
|
| 401 |
-
70% { box-shadow: 0 0 0 10px rgba(76, 175, 80, 0); }
|
| 402 |
-
100% { box-shadow: 0 0 0 0 rgba(76, 175, 80, 0); }
|
| 403 |
-
}
|
| 404 |
-
|
| 405 |
.action-buttons {
|
| 406 |
display: flex;
|
| 407 |
-
gap:
|
| 408 |
-
margin-top:
|
| 409 |
-
padding-top: 15px;
|
| 410 |
-
border-top: 1px solid var(--metric-border);
|
| 411 |
}
|
| 412 |
-
|
| 413 |
.action-button {
|
| 414 |
background: var(--action-button-bg);
|
| 415 |
-
color: var(--
|
| 416 |
border: none;
|
| 417 |
-
padding:
|
| 418 |
-
border-radius:
|
| 419 |
cursor: pointer;
|
| 420 |
font-size: 13px;
|
| 421 |
-
|
| 422 |
-
transition: background 0.2s ease, transform 0.1s ease;
|
| 423 |
-
outline: none;
|
| 424 |
-
flex-shrink: 0;
|
| 425 |
}
|
| 426 |
-
|
| 427 |
.action-button:hover {
|
| 428 |
background: var(--action-button-hover);
|
| 429 |
-
transform: translateY(-1px);
|
| 430 |
-
}
|
| 431 |
-
|
| 432 |
-
.action-button:active {
|
| 433 |
-
transform: translateY(0);
|
| 434 |
}
|
| 435 |
-
|
| 436 |
-
.action-button:focus-visible {
|
| 437 |
-
outline: 2px solid var(--accent-color);
|
| 438 |
-
outline-offset: 2px;
|
| 439 |
-
}
|
| 440 |
-
|
| 441 |
.network-stats {
|
| 442 |
background: var(--network-background);
|
| 443 |
border: 1px solid var(--metric-border);
|
|
@@ -445,500 +282,269 @@
|
|
| 445 |
padding: 15px;
|
| 446 |
border-radius: 8px;
|
| 447 |
transition: background 0.3s ease, border 0.3s ease;
|
|
|
|
|
|
|
| 448 |
font-size: 14px;
|
| 449 |
color: var(--secondary-text);
|
| 450 |
-
display: flex;
|
| 451 |
-
gap: 20px;
|
| 452 |
-
flex-wrap: wrap;
|
| 453 |
-
}
|
| 454 |
-
|
| 455 |
-
.network-stats strong {
|
| 456 |
-
color: var(--text-color);
|
| 457 |
-
font-weight: 600;
|
| 458 |
-
margin-right: 5px;
|
| 459 |
}
|
| 460 |
-
|
| 461 |
@keyframes fadeIn {
|
| 462 |
from { opacity: 0; transform: translateY(20px); }
|
| 463 |
to { opacity: 1; transform: translateY(0); }
|
| 464 |
}
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
.overview {
|
| 472 |
-
padding: 20px;
|
| 473 |
-
margin-bottom: 20px;
|
| 474 |
-
}
|
| 475 |
-
|
| 476 |
-
.overview-title {
|
| 477 |
-
font-size: 20px;
|
| 478 |
-
margin-bottom: 15px;
|
| 479 |
-
}
|
| 480 |
-
|
| 481 |
-
.header-container {
|
| 482 |
-
flex-direction: column;
|
| 483 |
-
align-items: flex-start;
|
| 484 |
-
}
|
| 485 |
-
|
| 486 |
-
.auth-buttons {
|
| 487 |
-
width: 100%;
|
| 488 |
-
justify-content: flex-end;
|
| 489 |
-
}
|
| 490 |
-
|
| 491 |
-
.theme-toggle {
|
| 492 |
-
margin-bottom: 15px;
|
| 493 |
-
}
|
| 494 |
-
|
| 495 |
#summary {
|
| 496 |
-
grid-template-columns:
|
| 497 |
-
gap:
|
| 498 |
}
|
| 499 |
-
|
| 500 |
#summary div {
|
| 501 |
-
padding:
|
| 502 |
}
|
| 503 |
-
|
| 504 |
#summary span {
|
| 505 |
-
font-size: 20px;
|
| 506 |
-
}
|
| 507 |
-
|
| 508 |
-
.user-group summary {
|
| 509 |
-
padding: 15px 20px;
|
| 510 |
}
|
| 511 |
-
|
| 512 |
.user-servers {
|
| 513 |
-
grid-template-columns:
|
| 514 |
-
gap: 12px;
|
| 515 |
-
padding: 15px 20px 20px;
|
| 516 |
-
}
|
| 517 |
-
|
| 518 |
-
.server-card {
|
| 519 |
-
padding: 15px;
|
| 520 |
}
|
| 521 |
-
|
| 522 |
-
.server-header {
|
| 523 |
-
font-size: 14px;
|
| 524 |
-
margin-bottom: 10px;
|
| 525 |
-
}
|
| 526 |
-
|
| 527 |
.metric-grid {
|
|
|
|
| 528 |
gap: 8px;
|
| 529 |
}
|
| 530 |
-
|
| 531 |
.metric-item {
|
| 532 |
-
padding:
|
| 533 |
-
}
|
| 534 |
-
|
| 535 |
-
.metric-label {
|
| 536 |
-
font-size: 11px;
|
| 537 |
}
|
| 538 |
-
|
| 539 |
.metric-value {
|
| 540 |
-
font-size:
|
| 541 |
}
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
}
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
|
|
|
|
|
|
| 551 |
}
|
| 552 |
}
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
display: flex;
|
| 561 |
-
flex-wrap: wrap;
|
| 562 |
-
gap: 15px;
|
| 563 |
align-items: center;
|
| 564 |
-
|
| 565 |
-
|
|
|
|
| 566 |
}
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
| 572 |
-
|
| 573 |
-
|
| 574 |
-
min-width: 200px;
|
| 575 |
-
flex-basis: calc(50% - 10px);
|
| 576 |
-
flex-grow: 1;
|
| 577 |
-
max-width: 300px;
|
| 578 |
}
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
|
| 587 |
-
|
| 588 |
-
|
| 589 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 590 |
}
|
| 591 |
-
|
| 592 |
.filter-sort-group label {
|
| 593 |
white-space: nowrap;
|
| 594 |
color: var(--secondary-text);
|
| 595 |
font-weight: 500;
|
| 596 |
-
min-width: 60px;
|
| 597 |
}
|
| 598 |
-
|
| 599 |
.filter-sort-group select {
|
| 600 |
flex: 1;
|
| 601 |
background: var(--metric-background);
|
| 602 |
border: 1px solid var(--metric-border);
|
| 603 |
color: var(--text-color);
|
| 604 |
-
padding:
|
| 605 |
border-radius: 6px;
|
| 606 |
cursor: pointer;
|
| 607 |
font-size: 14px;
|
| 608 |
-
|
| 609 |
-
transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
|
| 610 |
outline: none;
|
| 611 |
-
appearance: none;
|
| 612 |
-
background-image: url("data:image/svg+xml;utf8,<svg fill='%
|
| 613 |
background-repeat: no-repeat;
|
| 614 |
background-position: right 10px center;
|
| 615 |
-
padding-right: 36px;
|
| 616 |
}
|
| 617 |
-
|
| 618 |
[data-theme="light"] .filter-sort-group select {
|
| 619 |
-
background-image: url("data:image/svg+xml;utf8,<svg fill='%
|
| 620 |
}
|
| 621 |
-
|
| 622 |
.filter-sort-group select:hover {
|
| 623 |
background-color: var(--metric-hover);
|
| 624 |
-
border-color: rgba(255, 255, 255, 0.15);
|
| 625 |
}
|
| 626 |
-
|
| 627 |
.filter-sort-group select:focus {
|
| 628 |
-
border-color:
|
| 629 |
box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.3);
|
| 630 |
}
|
| 631 |
-
|
| 632 |
.refresh-button {
|
| 633 |
-
background: var(--
|
| 634 |
border: none;
|
| 635 |
-
color:
|
| 636 |
-
padding:
|
| 637 |
border-radius: 6px;
|
| 638 |
cursor: pointer;
|
| 639 |
font-size: 14px;
|
| 640 |
-
|
| 641 |
-
transition: background 0.2s ease, transform 0.2s ease, opacity 0.2s ease;
|
| 642 |
display: flex;
|
| 643 |
align-items: center;
|
| 644 |
gap: 8px;
|
| 645 |
height: 40px;
|
| 646 |
-
outline: none;
|
| 647 |
}
|
| 648 |
-
|
| 649 |
-
|
| 650 |
-
opacity: 0.6;
|
| 651 |
-
cursor: not-allowed;
|
| 652 |
-
}
|
| 653 |
-
|
| 654 |
-
.refresh-button:hover:not(:disabled) {
|
| 655 |
-
background: #3a8d40;
|
| 656 |
transform: translateY(-1px);
|
| 657 |
}
|
| 658 |
-
|
| 659 |
-
.refresh-button:active:not(:disabled) {
|
| 660 |
-
transform: translateY(0);
|
| 661 |
-
}
|
| 662 |
-
|
| 663 |
-
.refresh-button:focus-visible:not(:disabled) {
|
| 664 |
-
outline: 2px solid #fff;
|
| 665 |
-
outline-offset: 2px;
|
| 666 |
-
}
|
| 667 |
-
|
| 668 |
.refresh-icon {
|
| 669 |
width: 16px;
|
| 670 |
height: 16px;
|
| 671 |
fill: currentColor;
|
| 672 |
}
|
| 673 |
-
|
| 674 |
-
|
| 675 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 676 |
}
|
| 677 |
-
|
| 678 |
.chart-container {
|
| 679 |
-
display: none;
|
| 680 |
margin-top: 15px;
|
| 681 |
-
background: var(--
|
| 682 |
-
border: 1px solid var(--
|
| 683 |
border-radius: 8px;
|
| 684 |
-
padding:
|
| 685 |
-
height:
|
| 686 |
transition: background 0.3s ease, border 0.3s ease;
|
| 687 |
}
|
| 688 |
-
|
| 689 |
-
.server-card.expanded .chart-container {
|
| 690 |
-
display: block;
|
| 691 |
-
}
|
| 692 |
-
|
| 693 |
-
canvas {
|
| 694 |
-
width: 100% !important;
|
| 695 |
-
height: 100% !important;
|
| 696 |
-
}
|
| 697 |
-
|
| 698 |
-
@media (max-width: 600px) {
|
| 699 |
-
.chart-container {
|
| 700 |
-
height: 220px;
|
| 701 |
-
}
|
| 702 |
-
}
|
| 703 |
-
|
| 704 |
.chart-toggle-button {
|
| 705 |
background: var(--action-button-bg);
|
| 706 |
-
color: var(--
|
| 707 |
border: none;
|
| 708 |
padding: 6px 12px;
|
| 709 |
border-radius: 4px;
|
| 710 |
cursor: pointer;
|
| 711 |
-
font-size:
|
| 712 |
-
transition: background 0.2s ease
|
| 713 |
margin-left: auto;
|
| 714 |
white-space: nowrap;
|
| 715 |
-
outline: none;
|
| 716 |
}
|
| 717 |
-
|
| 718 |
.chart-toggle-button:hover {
|
| 719 |
background: var(--action-button-hover);
|
| 720 |
-
transform: translateY(-1px);
|
| 721 |
-
}
|
| 722 |
-
|
| 723 |
-
.chart-toggle-button:active {
|
| 724 |
-
transform: translateY(0);
|
| 725 |
-
}
|
| 726 |
-
|
| 727 |
-
.chart-toggle-button:focus-visible {
|
| 728 |
-
outline: 2px solid var(--accent-color);
|
| 729 |
-
outline-offset: 2px;
|
| 730 |
-
}
|
| 731 |
-
|
| 732 |
-
.login-overlay, .confirm-overlay, .loading-overlay {
|
| 733 |
-
position: fixed;
|
| 734 |
-
top: 0;
|
| 735 |
-
left: 0;
|
| 736 |
-
width: 100%;
|
| 737 |
-
height: 100%;
|
| 738 |
-
background: var(--overlay-background);
|
| 739 |
-
display: flex;
|
| 740 |
-
align-items: center;
|
| 741 |
-
justify-content: center;
|
| 742 |
-
z-index: 1000;
|
| 743 |
-
visibility: hidden;
|
| 744 |
-
opacity: 0;
|
| 745 |
-
transition: opacity 0.3s ease, visibility 0.3s ease;
|
| 746 |
-
}
|
| 747 |
-
|
| 748 |
-
.login-overlay.visible, .confirm-overlay.visible, .loading-overlay.visible {
|
| 749 |
-
visibility: visible;
|
| 750 |
-
opacity: 1;
|
| 751 |
-
}
|
| 752 |
-
|
| 753 |
-
.login-box, .confirm-box {
|
| 754 |
-
background: var(--card-background);
|
| 755 |
-
padding: 30px;
|
| 756 |
-
border-radius: 10px;
|
| 757 |
-
border: 1px solid var(--card-border);
|
| 758 |
-
width: 90%;
|
| 759 |
-
max-width: 380px;
|
| 760 |
-
text-align: center;
|
| 761 |
-
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
|
| 762 |
-
transform: scale(0.95);
|
| 763 |
-
transition: transform 0.3s ease;
|
| 764 |
-
}
|
| 765 |
-
|
| 766 |
-
.login-overlay.visible .login-box,
|
| 767 |
-
.confirm-overlay.visible .confirm-box {
|
| 768 |
-
transform: scale(1);
|
| 769 |
-
}
|
| 770 |
-
|
| 771 |
-
.login-box h2, .confirm-box h2 {
|
| 772 |
-
margin-bottom: 25px;
|
| 773 |
-
color: var(--text-color);
|
| 774 |
-
font-size: 20px;
|
| 775 |
-
font-weight: 600;
|
| 776 |
-
}
|
| 777 |
-
|
| 778 |
-
.login-box input {
|
| 779 |
-
width: 100%;
|
| 780 |
-
padding: 12px;
|
| 781 |
-
margin: 8px 0;
|
| 782 |
-
border: 1px solid var(--metric-border);
|
| 783 |
-
border-radius: 6px;
|
| 784 |
-
background: var(--metric-background);
|
| 785 |
-
color: var(--text-color);
|
| 786 |
-
font-size: 15px;
|
| 787 |
-
transition: border-color 0.2s ease, box-shadow 0.2s ease;
|
| 788 |
-
outline: none;
|
| 789 |
-
}
|
| 790 |
-
|
| 791 |
-
.login-box input::placeholder {
|
| 792 |
-
color: var(--secondary-text);
|
| 793 |
-
opacity: 0.7;
|
| 794 |
-
}
|
| 795 |
-
|
| 796 |
-
.login-box input:focus {
|
| 797 |
-
border-color: var(--accent-color);
|
| 798 |
-
box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.3);
|
| 799 |
-
}
|
| 800 |
-
|
| 801 |
-
.login-box .button-group, .confirm-box .button-group {
|
| 802 |
-
display: flex;
|
| 803 |
-
justify-content: space-between;
|
| 804 |
-
gap: 10px;
|
| 805 |
-
margin-top: 20px;
|
| 806 |
-
}
|
| 807 |
-
|
| 808 |
-
.login-box button, .confirm-box button {
|
| 809 |
-
flex: 1;
|
| 810 |
-
padding: 12px;
|
| 811 |
-
background: var(--action-button-bg);
|
| 812 |
-
border: none;
|
| 813 |
-
border-radius: 6px;
|
| 814 |
-
color: var(--action-button-text);
|
| 815 |
-
cursor: pointer;
|
| 816 |
-
font-size: 15px;
|
| 817 |
-
font-weight: 500;
|
| 818 |
-
transition: background 0.2s ease, transform 0.1s ease;
|
| 819 |
-
outline: none;
|
| 820 |
-
}
|
| 821 |
-
|
| 822 |
-
.confirm-box button:first-child {
|
| 823 |
-
background: var(--accent-color);
|
| 824 |
-
color: #fff;
|
| 825 |
-
}
|
| 826 |
-
|
| 827 |
-
.confirm-box button:first-child:hover {
|
| 828 |
-
background: #3a8d40;
|
| 829 |
-
}
|
| 830 |
-
|
| 831 |
-
.login-box button:hover, .confirm-box button:hover {
|
| 832 |
-
background: var(--action-button-hover);
|
| 833 |
-
transform: translateY(-1px);
|
| 834 |
-
}
|
| 835 |
-
|
| 836 |
-
.login-box button:active, .confirm-box button:active {
|
| 837 |
-
transform: translateY(0);
|
| 838 |
-
}
|
| 839 |
-
|
| 840 |
-
.login-box button:focus-visible, .confirm-box button:focus-visible {
|
| 841 |
-
outline: 2px solid var(--accent-color);
|
| 842 |
-
outline-offset: 2px;
|
| 843 |
-
}
|
| 844 |
-
|
| 845 |
-
.login-error {
|
| 846 |
-
color: var(--error-color);
|
| 847 |
-
margin-top: 15px;
|
| 848 |
-
font-size: 14px;
|
| 849 |
-
min-height: 20px;
|
| 850 |
-
}
|
| 851 |
-
|
| 852 |
-
.login-button, .logout-button {
|
| 853 |
-
background: var(--card-background);
|
| 854 |
-
border: 1px solid var(--card-border);
|
| 855 |
-
color: var(--text-color);
|
| 856 |
-
padding: 8px 14px;
|
| 857 |
-
border-radius: 6px;
|
| 858 |
-
cursor: pointer;
|
| 859 |
-
font-size: 14px;
|
| 860 |
-
font-weight: 500;
|
| 861 |
-
transition: background 0.2s ease, transform 0.1s ease, border-color 0.2s ease;
|
| 862 |
-
outline: none;
|
| 863 |
-
}
|
| 864 |
-
|
| 865 |
-
.login-button:hover, .logout-button:hover {
|
| 866 |
-
background: var(--metric-hover);
|
| 867 |
-
border-color: var(--metric-border);
|
| 868 |
-
transform: translateY(-1px);
|
| 869 |
}
|
| 870 |
-
|
| 871 |
-
|
| 872 |
-
transform: translateY(0);
|
| 873 |
-
}
|
| 874 |
-
|
| 875 |
-
.login-button:focus-visible, .logout-button:focus-visible {
|
| 876 |
-
outline: 2px solid var(--accent-color);
|
| 877 |
-
outline-offset: 2px;
|
| 878 |
-
}
|
| 879 |
-
|
| 880 |
-
.loader {
|
| 881 |
-
border: 5px solid rgba(255, 255, 255, 0.3);
|
| 882 |
-
border-top: 5px solid #fff;
|
| 883 |
-
border-radius: 50%;
|
| 884 |
-
width: 50px;
|
| 885 |
-
height: 50px;
|
| 886 |
-
animation: spin 0.8s linear infinite;
|
| 887 |
-
}
|
| 888 |
-
|
| 889 |
-
.confirm-box p {
|
| 890 |
-
line-height: 1.5;
|
| 891 |
-
font-size: 15px;
|
| 892 |
-
color: var(--secondary-text);
|
| 893 |
-
}
|
| 894 |
-
|
| 895 |
-
@keyframes spin {
|
| 896 |
-
0% { transform: rotate(0deg); }
|
| 897 |
-
100% { transform: rotate(360deg); }
|
| 898 |
-
}
|
| 899 |
-
|
| 900 |
-
/* Toast Notification Styles */
|
| 901 |
-
.toast-container {
|
| 902 |
-
position: fixed;
|
| 903 |
-
top: 20px;
|
| 904 |
-
right: 20px;
|
| 905 |
-
z-index: 1001;
|
| 906 |
-
display: flex;
|
| 907 |
-
flex-direction: column;
|
| 908 |
-
gap: 10px;
|
| 909 |
-
max-width: 300px;
|
| 910 |
-
}
|
| 911 |
-
|
| 912 |
-
.toast {
|
| 913 |
-
background: var(--card-background);
|
| 914 |
-
border: 1px solid var(--card-border);
|
| 915 |
-
color: var(--text-color);
|
| 916 |
-
padding: 15px;
|
| 917 |
-
border-radius: 8px;
|
| 918 |
-
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
| 919 |
-
display: flex;
|
| 920 |
-
align-items: center;
|
| 921 |
-
gap: 10px;
|
| 922 |
-
opacity: 0;
|
| 923 |
-
transform: translateY(-10px);
|
| 924 |
-
transition: opacity 0.3s ease, transform 0.3s ease;
|
| 925 |
-
}
|
| 926 |
-
|
| 927 |
-
.toast.show {
|
| 928 |
-
opacity: 1;
|
| 929 |
-
transform: translateY(0);
|
| 930 |
-
}
|
| 931 |
-
|
| 932 |
-
.toast.success {
|
| 933 |
-
border-left: 4px solid var(--success-color);
|
| 934 |
}
|
| 935 |
-
|
| 936 |
-
|
| 937 |
-
|
| 938 |
}
|
| 939 |
-
|
| 940 |
-
|
| 941 |
-
|
|
|
|
| 942 |
}
|
| 943 |
</style>
|
| 944 |
</head>
|
|
@@ -953,7 +559,7 @@
|
|
| 953 |
</div>
|
| 954 |
</div>
|
| 955 |
<div class="theme-toggle">
|
| 956 |
-
|
| 957 |
<button onclick="toggleTheme('system')" title="跟随系统">
|
| 958 |
<svg width="24" height="24" viewBox="0 0 24 24" fill="currentColor">
|
| 959 |
<path d="M3 5h18c1.1 0 2 .9 2 2v10c0 1.1-.9 2-2 2H3c-1.1 0-2-.9-2-2V7c0-1.1.9-2 2-2zm0 12h18V7H3v10zm2-8h2v2H5V9zm0 4h2v2H5v-2zm4-4h10v2H9V9zm0 4h10v2H9v-2z"/>
|
|
@@ -971,18 +577,15 @@
|
|
| 971 |
</button>
|
| 972 |
</div>
|
| 973 |
<div id="summary">
|
| 974 |
-
<div>总用户数 <span id="totalUsers">0</span></div>
|
| 975 |
-
<div>总实例数 <span id="totalServers">0</span></div>
|
| 976 |
-
<div>在线实例 <span id="onlineServers">0</span></div>
|
| 977 |
-
<div>离线实例 <span id="offlineServers">0</span></div>
|
| 978 |
-
<div>总上传 <span id="totalUpload">0 B/s</span></div>
|
| 979 |
-
<div>总下载 <span id="totalDownload">0 B/s</span></div>
|
| 980 |
-
</div>
|
| 981 |
-
<div class="network-stats">
|
| 982 |
-
目前总上传速度: <strong id="totalUpload2">0 B/s</strong>
|
| 983 |
-
目前总下载速度: <strong id="totalDownload2">0 B/s</strong>
|
| 984 |
</div>
|
| 985 |
</div>
|
|
|
|
| 986 |
<div class="filter-sort-panel">
|
| 987 |
<div class="filter-sort-group">
|
| 988 |
<label for="statusFilter">过滤状态:</label>
|
|
@@ -1008,7 +611,7 @@
|
|
| 1008 |
<option value="status-desc">状态 (停止-运行)</option>
|
| 1009 |
</select>
|
| 1010 |
</div>
|
| 1011 |
-
<button class="refresh-button"
|
| 1012 |
<svg class="refresh-icon" viewBox="0 0 24 24" fill="currentColor">
|
| 1013 |
<path d="M17.65 6.35A7.958 7.958 0 0012 4c-4.42 0-7.99 3.58-7.99 8s3.57 8 7.99 8c3.73 0 6.84-2.55 7.73-6h-2.08A5.99 5.99 0 0112 18c-3.31 0-6-2.69-6-6s2.69-6 6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z"/>
|
| 1014 |
</svg>
|
|
@@ -1018,69 +621,62 @@
|
|
| 1018 |
<div id="servers" class="stats-container">
|
| 1019 |
</div>
|
| 1020 |
</div>
|
|
|
|
| 1021 |
<div id="loginOverlay" class="login-overlay">
|
| 1022 |
<div class="login-box">
|
| 1023 |
<h2>登录</h2>
|
| 1024 |
-
<input type="text" id="username" placeholder="用户名"
|
| 1025 |
-
<input type="password" id="password" placeholder="密码"
|
| 1026 |
-
<div
|
| 1027 |
<button onclick="login()">登录</button>
|
| 1028 |
<button onclick="hideLoginForm()">取消</button>
|
| 1029 |
</div>
|
| 1030 |
<div id="loginError" class="login-error" style="display: none;"></div>
|
| 1031 |
</div>
|
| 1032 |
</div>
|
|
|
|
| 1033 |
<div id="confirmOverlay" class="confirm-overlay">
|
| 1034 |
<div class="confirm-box">
|
| 1035 |
<h2 id="confirmTitle">确认操作</h2>
|
| 1036 |
-
<p id="confirmMessage" style="margin-bottom: 20px; color: var(--
|
| 1037 |
-
<
|
| 1038 |
-
|
| 1039 |
-
<button onclick="cancelAction()">取消</button>
|
| 1040 |
-
</div>
|
| 1041 |
</div>
|
| 1042 |
</div>
|
|
|
|
| 1043 |
<div id="loadingOverlay" class="loading-overlay">
|
| 1044 |
<div class="loader"></div>
|
| 1045 |
</div>
|
| 1046 |
-
<div class="toast-container" id="toastContainer"></div>
|
| 1047 |
|
| 1048 |
<script>
|
| 1049 |
-
//
|
| 1050 |
function setTheme(theme) {
|
| 1051 |
-
const htmlElement = document.documentElement;
|
| 1052 |
-
const themeToggleButtons = document.querySelectorAll('.theme-toggle button');
|
| 1053 |
-
|
| 1054 |
-
themeToggleButtons.forEach(button => {
|
| 1055 |
-
button.removeAttribute('data-active');
|
| 1056 |
-
});
|
| 1057 |
-
|
| 1058 |
if (theme === 'system') {
|
| 1059 |
localStorage.removeItem('theme');
|
| 1060 |
const systemPrefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
| 1061 |
-
|
| 1062 |
-
document.querySelector('.theme-toggle button[title="跟随系统"]').setAttribute('data-active', 'true');
|
| 1063 |
} else {
|
| 1064 |
localStorage.setItem('theme', theme);
|
| 1065 |
-
|
| 1066 |
-
document.querySelector(`.theme-toggle button[title="${theme === 'light' ? '浅色模式' : '深色模式'}"]`).setAttribute('data-active', 'true');
|
| 1067 |
}
|
| 1068 |
-
updateChartTheme();
|
| 1069 |
}
|
| 1070 |
|
| 1071 |
function toggleTheme(theme) {
|
| 1072 |
setTheme(theme);
|
| 1073 |
}
|
| 1074 |
|
|
|
|
| 1075 |
function initTheme() {
|
| 1076 |
const savedTheme = localStorage.getItem('theme');
|
| 1077 |
if (savedTheme) {
|
| 1078 |
setTheme(savedTheme);
|
| 1079 |
} else {
|
| 1080 |
-
|
|
|
|
| 1081 |
}
|
| 1082 |
}
|
| 1083 |
|
|
|
|
| 1084 |
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
|
| 1085 |
if (!localStorage.getItem('theme')) {
|
| 1086 |
setTheme('system');
|
|
@@ -1088,44 +684,37 @@
|
|
| 1088 |
});
|
| 1089 |
|
| 1090 |
initTheme();
|
| 1091 |
-
// ==================== 主题切换 END ====================
|
| 1092 |
|
| 1093 |
-
//
|
| 1094 |
let isLoggedIn = false;
|
| 1095 |
-
let allInstances = [];
|
| 1096 |
-
const serverStatus = new Map();
|
| 1097 |
-
const instanceMap = new Map();
|
| 1098 |
-
const chartInstances = new Map();
|
| 1099 |
|
|
|
|
| 1100 |
function showLoading() {
|
| 1101 |
-
document.getElementById('loadingOverlay').
|
| 1102 |
-
document.getElementById('refreshButton').classList.add('loading');
|
| 1103 |
-
document.getElementById('refreshButton').disabled = true;
|
| 1104 |
}
|
| 1105 |
|
| 1106 |
function hideLoading() {
|
| 1107 |
-
document.getElementById('loadingOverlay').
|
| 1108 |
-
document.getElementById('refreshButton').classList.remove('loading');
|
| 1109 |
-
document.getElementById('refreshButton').disabled = false;
|
| 1110 |
}
|
| 1111 |
-
// ==================== 全局状态与控制 END ====================
|
| 1112 |
|
| 1113 |
-
//
|
| 1114 |
-
|
| 1115 |
const token = localStorage.getItem('authToken');
|
| 1116 |
const loginButton = document.getElementById('loginButton');
|
| 1117 |
const logoutButton = document.getElementById('logoutButton');
|
| 1118 |
|
| 1119 |
if (token) {
|
| 1120 |
-
console.log('本地存储中找到 token,尝试验证...');
|
| 1121 |
showLoading();
|
| 1122 |
-
|
| 1123 |
-
|
| 1124 |
-
|
| 1125 |
-
|
| 1126 |
-
|
| 1127 |
-
})
|
| 1128 |
-
|
|
|
|
|
|
|
| 1129 |
hideLoading();
|
| 1130 |
if (data.success) {
|
| 1131 |
console.log('Token 验证成功,用户已登录');
|
|
@@ -1133,67 +722,61 @@
|
|
| 1133 |
loginButton.style.display = 'none';
|
| 1134 |
logoutButton.style.display = 'block';
|
| 1135 |
updateActionButtons(true);
|
| 1136 |
-
return true;
|
| 1137 |
} else {
|
| 1138 |
-
console.log('Token 验证失败
|
| 1139 |
localStorage.removeItem('authToken');
|
| 1140 |
isLoggedIn = false;
|
| 1141 |
loginButton.style.display = 'block';
|
| 1142 |
logoutButton.style.display = 'none';
|
| 1143 |
updateActionButtons(false);
|
| 1144 |
-
return false;
|
| 1145 |
}
|
| 1146 |
-
|
|
|
|
|
|
|
| 1147 |
hideLoading();
|
| 1148 |
-
console.error('验证 token
|
| 1149 |
localStorage.removeItem('authToken');
|
| 1150 |
isLoggedIn = false;
|
| 1151 |
loginButton.style.display = 'block';
|
| 1152 |
logoutButton.style.display = 'none';
|
| 1153 |
updateActionButtons(false);
|
| 1154 |
return false;
|
| 1155 |
-
}
|
| 1156 |
} else {
|
| 1157 |
console.log('本地存储中无 token,显示未登录状态');
|
| 1158 |
isLoggedIn = false;
|
| 1159 |
loginButton.style.display = 'block';
|
| 1160 |
logoutButton.style.display = 'none';
|
| 1161 |
updateActionButtons(false);
|
| 1162 |
-
return false;
|
| 1163 |
}
|
| 1164 |
}
|
| 1165 |
|
| 1166 |
function showLoginForm() {
|
| 1167 |
-
document.getElementById('loginOverlay').
|
| 1168 |
document.getElementById('username').value = '';
|
| 1169 |
document.getElementById('password').value = '';
|
| 1170 |
document.getElementById('loginError').style.display = 'none';
|
| 1171 |
}
|
| 1172 |
|
| 1173 |
function hideLoginForm() {
|
| 1174 |
-
document.getElementById('loginOverlay').
|
| 1175 |
}
|
| 1176 |
|
| 1177 |
-
|
| 1178 |
const username = document.getElementById('username').value;
|
| 1179 |
const password = document.getElementById('password').value;
|
| 1180 |
const loginError = document.getElementById('loginError');
|
| 1181 |
-
loginError.style.display = 'none';
|
| 1182 |
-
|
| 1183 |
-
if (!username || !password) {
|
| 1184 |
-
loginError.textContent = '请输入用户名和密码';
|
| 1185 |
-
loginError.style.display = 'block';
|
| 1186 |
-
return;
|
| 1187 |
-
}
|
| 1188 |
-
|
| 1189 |
showLoading();
|
| 1190 |
-
|
| 1191 |
-
|
| 1192 |
-
|
| 1193 |
-
|
| 1194 |
-
|
| 1195 |
-
})
|
| 1196 |
-
|
|
|
|
|
|
|
| 1197 |
hideLoading();
|
| 1198 |
if (data.success) {
|
| 1199 |
console.log('登录成功,保存 token');
|
|
@@ -1203,93 +786,104 @@
|
|
| 1203 |
document.getElementById('loginButton').style.display = 'none';
|
| 1204 |
document.getElementById('logoutButton').style.display = 'block';
|
| 1205 |
updateActionButtons(true);
|
| 1206 |
-
refreshData();
|
| 1207 |
-
showToast('success', '登录成功');
|
| 1208 |
} else {
|
| 1209 |
console.log('登录失败:', data.message);
|
| 1210 |
-
loginError.textContent = data.message || '登录失败
|
| 1211 |
loginError.style.display = 'block';
|
| 1212 |
}
|
| 1213 |
-
}
|
|
|
|
| 1214 |
hideLoading();
|
| 1215 |
console.error('登录请求失败:', error);
|
| 1216 |
-
loginError.textContent = '登录请求失败,请
|
| 1217 |
loginError.style.display = 'block';
|
| 1218 |
-
}
|
| 1219 |
}
|
| 1220 |
|
| 1221 |
-
|
| 1222 |
const token = localStorage.getItem('authToken');
|
| 1223 |
if (token) {
|
| 1224 |
showLoading();
|
| 1225 |
-
|
| 1226 |
-
|
| 1227 |
-
|
| 1228 |
-
|
| 1229 |
-
|
| 1230 |
-
})
|
| 1231 |
-
|
| 1232 |
-
|
| 1233 |
-
|
| 1234 |
-
} finally {
|
| 1235 |
hideLoading();
|
|
|
|
| 1236 |
localStorage.removeItem('authToken');
|
| 1237 |
isLoggedIn = false;
|
| 1238 |
document.getElementById('loginButton').style.display = 'block';
|
| 1239 |
document.getElementById('logoutButton').style.display = 'none';
|
| 1240 |
updateActionButtons(false);
|
| 1241 |
-
refreshData();
|
| 1242 |
-
|
| 1243 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1244 |
} else {
|
| 1245 |
-
console.log('本地无 token,直接设置为未登录
|
| 1246 |
isLoggedIn = false;
|
| 1247 |
document.getElementById('loginButton').style.display = 'block';
|
| 1248 |
document.getElementById('logoutButton').style.display = 'none';
|
| 1249 |
updateActionButtons(false);
|
| 1250 |
-
refreshData();
|
| 1251 |
}
|
| 1252 |
}
|
| 1253 |
|
| 1254 |
function updateActionButtons(loggedIn) {
|
| 1255 |
console.log('更新操作按钮状态,是否已登录:', loggedIn);
|
|
|
|
| 1256 |
const cards = document.querySelectorAll('.server-card');
|
| 1257 |
cards.forEach(card => {
|
| 1258 |
const buttons = card.querySelector('.action-buttons');
|
| 1259 |
if (buttons) {
|
| 1260 |
buttons.style.display = loggedIn ? 'flex' : 'none';
|
| 1261 |
}
|
| 1262 |
-
|
| 1263 |
-
|
| 1264 |
-
|
| 1265 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1266 |
});
|
| 1267 |
}
|
| 1268 |
|
|
|
|
| 1269 |
window.onload = async function() {
|
| 1270 |
-
console.log('页面加载完成,开始
|
| 1271 |
-
|
| 1272 |
-
console.log('初始化数据
|
| 1273 |
await initialize();
|
| 1274 |
-
updateActionButtons(loggedIn);
|
| 1275 |
};
|
| 1276 |
-
// ==================== 登录/登出 END ====================
|
| 1277 |
|
| 1278 |
-
//
|
| 1279 |
let pendingAction = null;
|
| 1280 |
let pendingRepoId = null;
|
| 1281 |
|
| 1282 |
function showConfirmDialog(action, repoId, title, message) {
|
| 1283 |
-
if (!isLoggedIn) {
|
| 1284 |
-
showToast('error', '请先登录以执行此操作');
|
| 1285 |
-
showLoginForm();
|
| 1286 |
-
return;
|
| 1287 |
-
}
|
| 1288 |
pendingAction = action;
|
| 1289 |
pendingRepoId = repoId;
|
| 1290 |
document.getElementById('confirmTitle').textContent = title;
|
| 1291 |
document.getElementById('confirmMessage').textContent = message;
|
| 1292 |
-
document.getElementById('confirmOverlay').
|
| 1293 |
}
|
| 1294 |
|
| 1295 |
function confirmAction() {
|
|
@@ -1304,32 +898,25 @@
|
|
| 1304 |
function cancelAction() {
|
| 1305 |
pendingAction = null;
|
| 1306 |
pendingRepoId = null;
|
| 1307 |
-
document.getElementById('confirmOverlay').
|
| 1308 |
}
|
| 1309 |
-
// ==================== 二次确认弹窗 END ====================
|
| 1310 |
|
| 1311 |
-
// ==================== 数据获取与渲染 START ====================
|
| 1312 |
async function getUsernames() {
|
| 1313 |
try {
|
|
|
|
| 1314 |
const token = localStorage.getItem('authToken');
|
| 1315 |
const headers = {};
|
| 1316 |
if (token) {
|
| 1317 |
headers['Authorization'] = `Bearer ${token}`;
|
|
|
|
| 1318 |
}
|
| 1319 |
const response = await fetch('/api/config', { headers });
|
| 1320 |
-
if (!response.ok) {
|
| 1321 |
-
if (response.status === 401) {
|
| 1322 |
-
console.warn('获取配置失败: 未授权 (可能是 token 过期)');
|
| 1323 |
-
} else {
|
| 1324 |
-
console.error(`获取配置失败: ${response.status} ${response.statusText}`);
|
| 1325 |
-
}
|
| 1326 |
-
return [];
|
| 1327 |
-
}
|
| 1328 |
const config = await response.json();
|
|
|
|
| 1329 |
const usernamesList = config.usernames ? config.usernames.split(',').map(name => name.trim()).filter(name => name) : [];
|
| 1330 |
document.getElementById('totalUsers').textContent = usernamesList.length;
|
|
|
|
| 1331 |
const userFilter = document.getElementById('userFilter');
|
| 1332 |
-
const currentUserFilterValue = userFilter.value;
|
| 1333 |
userFilter.innerHTML = '<option value="all">全部用户</option>';
|
| 1334 |
usernamesList.forEach(username => {
|
| 1335 |
const option = document.createElement('option');
|
|
@@ -1337,58 +924,38 @@
|
|
| 1337 |
option.textContent = username;
|
| 1338 |
userFilter.appendChild(option);
|
| 1339 |
});
|
| 1340 |
-
if (usernamesList.includes(currentUserFilterValue)) {
|
| 1341 |
-
userFilter.value = currentUserFilterValue;
|
| 1342 |
-
} else {
|
| 1343 |
-
userFilter.value = 'all';
|
| 1344 |
-
}
|
| 1345 |
return usernamesList;
|
| 1346 |
} catch (error) {
|
| 1347 |
-
|
|
|
|
| 1348 |
document.getElementById('totalUsers').textContent = 0;
|
| 1349 |
-
const userFilter = document.getElementById('userFilter');
|
| 1350 |
-
userFilter.innerHTML = '<option value="all">全部用户</option>';
|
| 1351 |
return [];
|
| 1352 |
}
|
| 1353 |
}
|
| 1354 |
|
| 1355 |
async function fetchInstances() {
|
| 1356 |
try {
|
|
|
|
| 1357 |
const token = localStorage.getItem('authToken');
|
| 1358 |
const headers = {};
|
| 1359 |
if (token) {
|
| 1360 |
headers['Authorization'] = `Bearer ${token}`;
|
| 1361 |
-
console.log('fetchInstances 请求中附加 Token');
|
| 1362 |
} else {
|
| 1363 |
console.log('无可用 Token,未附加 Authorization 头');
|
| 1364 |
}
|
| 1365 |
const response = await fetch('/api/proxy/spaces', { headers });
|
| 1366 |
-
if (!response.ok) {
|
| 1367 |
-
const errorBody = await response.json().catch(() => ({}));
|
| 1368 |
-
if (response.status === 401) {
|
| 1369 |
-
console.warn('获取实例列表失败: 未授权 (可能是 token 过期)');
|
| 1370 |
-
localStorage.removeItem('authToken');
|
| 1371 |
-
isLoggedIn = false;
|
| 1372 |
-
updateActionButtons(false);
|
| 1373 |
-
document.getElementById('loginButton').style.display = 'block';
|
| 1374 |
-
document.getElementById('logoutButton').style.display = 'none';
|
| 1375 |
-
showToast('error', '登录已过期,请重新登录');
|
| 1376 |
-
showLoginForm();
|
| 1377 |
-
} else {
|
| 1378 |
-
showToast('error', `获取实例列表失败: ${errorBody.error || '未知服务器错误'}`);
|
| 1379 |
-
console.error(`获取实例列表失败: ${response.status} ${response.statusText}`, errorBody);
|
| 1380 |
-
}
|
| 1381 |
-
return [];
|
| 1382 |
-
}
|
| 1383 |
const instances = await response.json();
|
| 1384 |
console.log('从后端获取的实例列表:', instances);
|
|
|
|
| 1385 |
if (instances.length === 0) {
|
| 1386 |
-
|
| 1387 |
}
|
| 1388 |
return instances;
|
| 1389 |
} catch (error) {
|
|
|
|
| 1390 |
console.error("获取实例列表失败:", error);
|
| 1391 |
-
|
| 1392 |
return [];
|
| 1393 |
}
|
| 1394 |
}
|
|
@@ -1396,51 +963,39 @@
|
|
| 1396 |
class MetricsStreamManager {
|
| 1397 |
constructor() {
|
| 1398 |
this.eventSource = null;
|
| 1399 |
-
this.subscribedInstances = [];
|
| 1400 |
}
|
| 1401 |
|
| 1402 |
connect(subscribedInstances = []) {
|
| 1403 |
-
if (this.eventSource
|
| 1404 |
-
|
| 1405 |
-
return;
|
| 1406 |
-
}
|
| 1407 |
-
|
| 1408 |
-
this.disconnect();
|
| 1409 |
-
|
| 1410 |
-
this.subscribedInstances = subscribedInstances;
|
| 1411 |
-
|
| 1412 |
-
if (subscribedInstances.length === 0) {
|
| 1413 |
-
console.log('没有需要监控的实例,不建立 SSE 连接');
|
| 1414 |
-
return;
|
| 1415 |
}
|
| 1416 |
|
| 1417 |
const instancesParam = subscribedInstances.join(',');
|
| 1418 |
-
const token = localStorage.getItem('authToken')
|
| 1419 |
-
|
| 1420 |
-
|
|
|
|
| 1421 |
this.eventSource = new EventSource(url);
|
| 1422 |
|
| 1423 |
-
this.eventSource.onopen = () => {
|
| 1424 |
-
console.log('SSE 连接已成功建立');
|
| 1425 |
-
};
|
| 1426 |
-
|
| 1427 |
this.eventSource.addEventListener("metric", (event) => {
|
| 1428 |
try {
|
| 1429 |
const data = JSON.parse(event.data);
|
| 1430 |
const { repoId, metrics } = data;
|
| 1431 |
-
|
| 1432 |
-
updateServerCard(metrics, repoId);
|
| 1433 |
-
}
|
| 1434 |
} catch (error) {
|
| 1435 |
-
console.
|
| 1436 |
}
|
| 1437 |
});
|
| 1438 |
|
| 1439 |
this.eventSource.onerror = (error) => {
|
| 1440 |
console.error(`SSE 连接错误:`, error);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1441 |
};
|
| 1442 |
|
| 1443 |
-
console.log(`SSE 连接已建立,订阅实例: ${instancesParam}`);
|
| 1444 |
}
|
| 1445 |
|
| 1446 |
disconnect() {
|
|
@@ -1449,51 +1004,217 @@
|
|
| 1449 |
this.eventSource = null;
|
| 1450 |
console.log(`SSE 连接已断开`);
|
| 1451 |
}
|
| 1452 |
-
this.subscribedInstances = [];
|
| 1453 |
}
|
| 1454 |
}
|
| 1455 |
|
| 1456 |
const metricsStreamManager = new MetricsStreamManager();
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1457 |
|
| 1458 |
async function initialize() {
|
| 1459 |
-
showLoading();
|
| 1460 |
await getUsernames();
|
| 1461 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1462 |
chartInstances.forEach(chart => {
|
| 1463 |
if (chart) {
|
| 1464 |
chart.destroy();
|
| 1465 |
}
|
| 1466 |
});
|
| 1467 |
-
chartInstances.clear();
|
| 1468 |
-
|
| 1469 |
-
|
| 1470 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1471 |
}
|
| 1472 |
|
| 1473 |
-
|
| 1474 |
-
|
| 1475 |
-
|
| 1476 |
-
|
| 1477 |
-
|
| 1478 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1479 |
}
|
| 1480 |
|
| 1481 |
function renderInstanceCard(instance, container) {
|
| 1482 |
const instanceId = instance.repo_id;
|
| 1483 |
-
if (instance.private && !isLoggedIn) {
|
| 1484 |
-
const existingCard = document.getElementById(`instance-${instanceId}`);
|
| 1485 |
-
if (existingCard) {
|
| 1486 |
-
existingCard.remove();
|
| 1487 |
-
instanceMap.delete(instanceId);
|
| 1488 |
-
serverStatus.delete(instanceId);
|
| 1489 |
-
if (chartInstances.has(instanceId)) {
|
| 1490 |
-
chartInstances.get(instanceId).destroy();
|
| 1491 |
-
chartInstances.delete(instanceId);
|
| 1492 |
-
}
|
| 1493 |
-
}
|
| 1494 |
-
return;
|
| 1495 |
-
}
|
| 1496 |
-
|
| 1497 |
instanceMap.set(instanceId, instance);
|
| 1498 |
|
| 1499 |
const cardId = `instance-${instanceId}`;
|
|
@@ -1502,16 +1223,24 @@
|
|
| 1502 |
card = document.createElement('div');
|
| 1503 |
card.id = cardId;
|
| 1504 |
card.className = 'server-card';
|
| 1505 |
-
|
| 1506 |
-
|
| 1507 |
-
|
| 1508 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1509 |
card.innerHTML = `
|
| 1510 |
<div class="server-header">
|
| 1511 |
<div class="server-name">
|
| 1512 |
-
<
|
| 1513 |
${iconSvg}
|
| 1514 |
-
<div>${instance.name}</div>
|
| 1515 |
</div>
|
| 1516 |
<div>
|
| 1517 |
<button class="chart-toggle-button" onclick="toggleChart('${instanceId}')">查看图表</button>
|
|
@@ -1540,8 +1269,8 @@
|
|
| 1540 |
</div>
|
| 1541 |
</div>
|
| 1542 |
<div class="action-buttons" style="display: ${isLoggedIn ? 'flex' : 'none'};">
|
| 1543 |
-
<button class="action-button" onclick="viewInstance('${instance.url}')">查看
|
| 1544 |
-
<button class="action-button" onclick="manageInstance('${instance.repo_id}')">管理
|
| 1545 |
<button class="action-button" onclick="showConfirmDialog('restart', '${instance.repo_id}', '确认重启', '您确定要重启实例 ${instance.name} (${instance.repo_id}) 吗?')">重启</button>
|
| 1546 |
<button class="action-button" onclick="showConfirmDialog('rebuild', '${instance.repo_id}', '确认重建', '您确定要重建实例 ${instance.name} (${instance.repo_id}) 吗?')">重建</button>
|
| 1547 |
</div>
|
|
@@ -1550,159 +1279,96 @@
|
|
| 1550 |
</div>
|
| 1551 |
`;
|
| 1552 |
container.appendChild(card);
|
| 1553 |
-
} else {
|
| 1554 |
-
card.querySelector('.metric-value.status').textContent = instance.status;
|
| 1555 |
-
const statusDot = card.querySelector('.status-dot');
|
| 1556 |
-
const currentStatus = instance.status.toLowerCase();
|
| 1557 |
-
if (currentStatus === 'running') {
|
| 1558 |
-
statusDot.className = 'status-dot status-online';
|
| 1559 |
-
} else if (currentStatus === 'sleeping') {
|
| 1560 |
-
statusDot.className = 'status-dot status-sleep';
|
| 1561 |
-
} else {
|
| 1562 |
-
statusDot.className = 'status-dot status-offline';
|
| 1563 |
-
}
|
| 1564 |
-
const buttons = card.querySelector('.action-buttons');
|
| 1565 |
-
if (buttons) {
|
| 1566 |
-
buttons.style.display = isLoggedIn ? 'flex' : 'none';
|
| 1567 |
-
}
|
| 1568 |
}
|
| 1569 |
-
|
| 1570 |
-
|
| 1571 |
-
|
| 1572 |
-
|
| 1573 |
-
|
| 1574 |
-
|
| 1575 |
-
|
| 1576 |
-
|
| 1577 |
-
|
| 1578 |
-
const chartToggleButton = card.querySelector('.chart-toggle-button');
|
| 1579 |
-
if (chartToggleButton) {
|
| 1580 |
-
chartToggleButton.style.display = 'inline-block';
|
| 1581 |
}
|
|
|
|
| 1582 |
}
|
| 1583 |
|
| 1584 |
-
|
| 1585 |
-
|
| 1586 |
-
const
|
| 1587 |
-
const
|
| 1588 |
-
|
| 1589 |
-
|
| 1590 |
-
userGroupsContainer.innerHTML = '';
|
| 1591 |
-
|
| 1592 |
-
const userGroups = {};
|
| 1593 |
-
instancesToRender.forEach(instance => {
|
| 1594 |
-
if (!userGroups[instance.owner]) {
|
| 1595 |
-
userGroups[instance.owner] = [];
|
| 1596 |
-
}
|
| 1597 |
-
userGroups[instance.owner].push(instance);
|
| 1598 |
-
});
|
| 1599 |
-
|
| 1600 |
-
Object.keys(userGroups).forEach(owner => {
|
| 1601 |
-
let userGroup = document.createElement('details');
|
| 1602 |
-
userGroup.className = 'user-group';
|
| 1603 |
-
userGroup.id = `user-${owner}`;
|
| 1604 |
-
userGroup.setAttribute('open', '');
|
| 1605 |
-
|
| 1606 |
-
const summary = document.createElement('summary');
|
| 1607 |
-
summary.textContent = `用户: ${owner} (${userGroups[owner].length} 个实例)`;
|
| 1608 |
-
userGroup.appendChild(summary);
|
| 1609 |
-
|
| 1610 |
-
const userServers = document.createElement('div');
|
| 1611 |
-
userServers.className = 'user-servers';
|
| 1612 |
-
userGroup.appendChild(userServers);
|
| 1613 |
-
|
| 1614 |
-
userGroupsContainer.appendChild(userGroup);
|
| 1615 |
-
|
| 1616 |
-
userGroups[owner].forEach(instance => {
|
| 1617 |
-
renderInstanceCard(instance, userServers);
|
| 1618 |
-
});
|
| 1619 |
-
});
|
| 1620 |
|
| 1621 |
-
|
| 1622 |
-
|
| 1623 |
-
|
| 1624 |
-
|
| 1625 |
-
|
| 1626 |
-
|
| 1627 |
-
|
| 1628 |
-
|
|
|
|
| 1629 |
}
|
| 1630 |
-
}
|
| 1631 |
-
|
| 1632 |
-
const runningInstancesInView = instancesToRender
|
| 1633 |
-
.filter(instance => instance.status.toLowerCase() === 'running')
|
| 1634 |
-
.map(instance => instance.repo_id);
|
| 1635 |
-
metricsStreamManager.connect(runningInstancesInView);
|
| 1636 |
-
|
| 1637 |
-
updateSummary();
|
| 1638 |
}
|
| 1639 |
|
| 1640 |
-
function updateServerCard(data, instanceId) {
|
| 1641 |
-
const
|
|
|
|
| 1642 |
const instance = instanceMap.get(instanceId);
|
| 1643 |
-
|
| 1644 |
-
if (!card
|
|
|
|
| 1645 |
return;
|
| 1646 |
}
|
| 1647 |
|
| 1648 |
-
|
| 1649 |
-
|
| 1650 |
-
|
| 1651 |
-
|
| 1652 |
-
|
| 1653 |
-
|
| 1654 |
-
|
| 1655 |
-
|
| 1656 |
-
|
| 1657 |
-
|
| 1658 |
-
|
| 1659 |
-
|
| 1660 |
-
|
| 1661 |
-
|
| 1662 |
-
card.querySelector('.memory-usage').textContent = `${memoryPct}%`;
|
| 1663 |
-
card.querySelector('.upload').textContent = `${formatBytes(data.tx_bps)}/s`;
|
| 1664 |
-
card.querySelector('.download').textContent = `${formatBytes(data.rx_bps)}/s`;
|
| 1665 |
-
|
| 1666 |
-
const chartContainer = document.getElementById(`chart-container-${instanceId}`);
|
| 1667 |
-
if (chartContainer && chartContainer.parentElement.classList.contains('expanded')) {
|
| 1668 |
updateChart(instanceId, data);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1669 |
}
|
| 1670 |
-
} else {
|
| 1671 |
-
card.querySelector('.cpu-usage').textContent = 'N/A';
|
| 1672 |
-
card.querySelector('.memory-usage').textContent = 'N/A';
|
| 1673 |
-
card.querySelector('.upload').textContent = 'N/A';
|
| 1674 |
-
card.querySelector('.download').textContent = 'N/A';
|
| 1675 |
-
}
|
| 1676 |
-
|
| 1677 |
-
statusDot.className = 'status-dot';
|
| 1678 |
-
statusTextElement.className = 'metric-value status';
|
| 1679 |
-
if (currentStatus === 'running') {
|
| 1680 |
-
statusDot.classList.add('status-online');
|
| 1681 |
-
statusTextElement.classList.add('status-running');
|
| 1682 |
-
} else if (currentStatus === 'sleeping') {
|
| 1683 |
-
statusDot.classList.add('status-sleep');
|
| 1684 |
-
statusTextElement.classList.add('status-sleeping');
|
| 1685 |
-
} else {
|
| 1686 |
-
statusDot.classList.add('status-offline');
|
| 1687 |
-
statusTextElement.classList.add('status-stopped');
|
| 1688 |
-
}
|
| 1689 |
|
| 1690 |
-
|
| 1691 |
-
|
| 1692 |
-
|
| 1693 |
-
|
| 1694 |
-
data: data || null,
|
| 1695 |
-
status: instance.status
|
| 1696 |
-
});
|
| 1697 |
|
| 1698 |
-
|
|
|
|
|
|
|
| 1699 |
}
|
| 1700 |
|
| 1701 |
async function restartSpace(repoId) {
|
| 1702 |
try {
|
| 1703 |
const token = localStorage.getItem('authToken');
|
| 1704 |
if (!token || !isLoggedIn) {
|
| 1705 |
-
|
| 1706 |
showLoginForm();
|
| 1707 |
return;
|
| 1708 |
}
|
|
@@ -1710,17 +1376,19 @@
|
|
| 1710 |
const encodedRepoId = encodeURIComponent(repoId);
|
| 1711 |
const response = await fetch(`/api/proxy/restart/${encodedRepoId}`, {
|
| 1712 |
method: 'POST',
|
| 1713 |
-
headers: {
|
|
|
|
|
|
|
| 1714 |
});
|
| 1715 |
const result = await response.json();
|
| 1716 |
hideLoading();
|
| 1717 |
if (result.success) {
|
| 1718 |
-
|
| 1719 |
-
|
| 1720 |
refreshData();
|
| 1721 |
} else {
|
| 1722 |
if (response.status === 401) {
|
| 1723 |
-
|
| 1724 |
localStorage.removeItem('authToken');
|
| 1725 |
isLoggedIn = false;
|
| 1726 |
document.getElementById('loginButton').style.display = 'block';
|
|
@@ -1728,14 +1396,14 @@
|
|
| 1728 |
updateActionButtons(false);
|
| 1729 |
showLoginForm();
|
| 1730 |
} else {
|
| 1731 |
-
|
| 1732 |
console.error(`重启失败 (${repoId}):`, result.error, result.details);
|
| 1733 |
}
|
| 1734 |
}
|
| 1735 |
} catch (error) {
|
| 1736 |
hideLoading();
|
| 1737 |
-
console.error(`重启
|
| 1738 |
-
|
| 1739 |
}
|
| 1740 |
}
|
| 1741 |
|
|
@@ -1743,7 +1411,7 @@
|
|
| 1743 |
try {
|
| 1744 |
const token = localStorage.getItem('authToken');
|
| 1745 |
if (!token || !isLoggedIn) {
|
| 1746 |
-
|
| 1747 |
showLoginForm();
|
| 1748 |
return;
|
| 1749 |
}
|
|
@@ -1751,17 +1419,19 @@
|
|
| 1751 |
const encodedRepoId = encodeURIComponent(repoId);
|
| 1752 |
const response = await fetch(`/api/proxy/rebuild/${encodedRepoId}`, {
|
| 1753 |
method: 'POST',
|
| 1754 |
-
headers: {
|
|
|
|
|
|
|
| 1755 |
});
|
| 1756 |
const result = await response.json();
|
| 1757 |
hideLoading();
|
| 1758 |
if (result.success) {
|
| 1759 |
-
|
| 1760 |
-
|
| 1761 |
refreshData();
|
| 1762 |
} else {
|
| 1763 |
if (response.status === 401) {
|
| 1764 |
-
|
| 1765 |
localStorage.removeItem('authToken');
|
| 1766 |
isLoggedIn = false;
|
| 1767 |
document.getElementById('loginButton').style.display = 'block';
|
|
@@ -1769,380 +1439,122 @@
|
|
| 1769 |
updateActionButtons(false);
|
| 1770 |
showLoginForm();
|
| 1771 |
} else {
|
| 1772 |
-
|
| 1773 |
console.error(`重建失败 (${repoId}):`, result.error, result.details);
|
| 1774 |
}
|
| 1775 |
}
|
| 1776 |
} catch (error) {
|
| 1777 |
hideLoading();
|
| 1778 |
-
console.error(`重建
|
| 1779 |
-
|
| 1780 |
}
|
| 1781 |
}
|
| 1782 |
|
| 1783 |
function updateSummary() {
|
| 1784 |
let online = 0;
|
| 1785 |
let offline = 0;
|
| 1786 |
-
let
|
| 1787 |
-
let
|
| 1788 |
|
| 1789 |
serverStatus.forEach((status, instanceId) => {
|
| 1790 |
-
|
|
|
|
| 1791 |
online++;
|
| 1792 |
if (status.data) {
|
| 1793 |
-
|
| 1794 |
-
|
| 1795 |
}
|
| 1796 |
} else {
|
| 1797 |
offline++;
|
| 1798 |
}
|
| 1799 |
});
|
| 1800 |
|
| 1801 |
-
document.getElementById('totalServers').textContent =
|
| 1802 |
document.getElementById('onlineServers').textContent = online;
|
| 1803 |
document.getElementById('offlineServers').textContent = offline;
|
| 1804 |
-
document.getElementById('totalUpload').textContent = `${formatBytes(
|
| 1805 |
-
document.getElementById('totalDownload').textContent = `${formatBytes(
|
| 1806 |
-
|
| 1807 |
-
const totalAllUpload = Array.from(serverStatus.values()).reduce((sum, status) => sum + (status.data?.tx_bps || 0), 0);
|
| 1808 |
-
const totalAllDownload = Array.from(serverStatus.values()).reduce((sum, status) => sum + (status.data?.rx_bps || 0), 0);
|
| 1809 |
-
|
| 1810 |
-
document.getElementById('totalUpload2').textContent = `${formatBytes(totalAllUpload)}/s`;
|
| 1811 |
-
document.getElementById('totalDownload2').textContent = `${formatBytes(totalAllDownload)}/s`;
|
| 1812 |
}
|
| 1813 |
|
| 1814 |
-
function formatBytes(bytes
|
| 1815 |
-
if (bytes === null || bytes === undefined) return 'N/A';
|
| 1816 |
if (bytes === 0) return '0 B';
|
| 1817 |
-
const
|
| 1818 |
-
const
|
| 1819 |
-
const i = Math.floor(Math.log(bytes) / Math.log(
|
| 1820 |
-
return parseFloat((bytes / Math.pow(
|
| 1821 |
}
|
| 1822 |
|
|
|
|
|
|
|
| 1823 |
setInterval(async () => {
|
| 1824 |
-
|
| 1825 |
-
|
| 1826 |
-
await refreshData();
|
| 1827 |
-
} else {
|
| 1828 |
-
console.log('正在手动刷新中,跳过定时刷新');
|
| 1829 |
-
}
|
| 1830 |
}, 300000);
|
| 1831 |
|
|
|
|
| 1832 |
function applyFiltersAndSort() {
|
| 1833 |
const statusFilter = document.getElementById('statusFilter').value;
|
| 1834 |
const userFilter = document.getElementById('userFilter').value;
|
| 1835 |
const sortBy = document.getElementById('sortBy').value;
|
| 1836 |
|
| 1837 |
-
|
| 1838 |
-
|
| 1839 |
-
|
| 1840 |
-
|
| 1841 |
-
|
| 1842 |
-
|
|
|
|
|
|
|
| 1843 |
|
|
|
|
| 1844 |
filteredInstances.sort((a, b) => {
|
| 1845 |
if (sortBy === 'name-asc') {
|
| 1846 |
return a.name.localeCompare(b.name);
|
| 1847 |
} else if (sortBy === 'name-desc') {
|
| 1848 |
return b.name.localeCompare(a.name);
|
| 1849 |
} else if (sortBy === 'status-asc') {
|
| 1850 |
-
const statusOrder = { 'running': 0, 'sleeping': 1, 'stopped': 2
|
| 1851 |
-
|
| 1852 |
-
const statusB = statusOrder[b.status?.toLowerCase()] || 6;
|
| 1853 |
-
if (statusA !== statusB) {
|
| 1854 |
-
return statusA - statusB;
|
| 1855 |
-
}
|
| 1856 |
-
return a.name.localeCompare(b.name);
|
| 1857 |
} else if (sortBy === 'status-desc') {
|
| 1858 |
-
const statusOrder = { 'running':
|
| 1859 |
-
|
| 1860 |
-
const statusB = statusOrder[b.status?.toLowerCase()] || -1;
|
| 1861 |
-
if (statusA !== statusB) {
|
| 1862 |
-
return statusB - statusA;
|
| 1863 |
-
}
|
| 1864 |
-
return b.name.localeCompare(a.name);
|
| 1865 |
}
|
| 1866 |
return 0;
|
| 1867 |
});
|
| 1868 |
|
| 1869 |
-
|
| 1870 |
-
|
| 1871 |
-
|
| 1872 |
-
|
| 1873 |
-
|
| 1874 |
-
|
| 1875 |
-
|
| 1876 |
-
|
| 1877 |
-
const canvas = document.getElementById(canvasId);
|
| 1878 |
-
if (!canvas) {
|
| 1879 |
-
console.error(`Canvas element not found for instanceId: ${instanceId}`);
|
| 1880 |
-
return null;
|
| 1881 |
-
}
|
| 1882 |
-
if (canvas.chart) {
|
| 1883 |
-
console.warn(`Chart already exists for canvasId: ${canvasId}, destroying old one.`);
|
| 1884 |
-
canvas.chart.destroy();
|
| 1885 |
-
}
|
| 1886 |
-
|
| 1887 |
-
const isDarkMode = document.documentElement.getAttribute('data-theme') === 'dark';
|
| 1888 |
-
const gridColor = isDarkMode ? 'rgba(255, 255, 255, 0.08)' : 'rgba(0, 0, 0, 0.08)';
|
| 1889 |
-
const textColor = isDarkMode ? '#e0e0e0' : '#333';
|
| 1890 |
-
|
| 1891 |
-
const ctx = canvas.getContext('2d');
|
| 1892 |
-
const chart = new Chart(ctx, {
|
| 1893 |
-
type: 'line',
|
| 1894 |
-
data: {
|
| 1895 |
-
labels: Array(30).fill(''),
|
| 1896 |
-
datasets: [
|
| 1897 |
-
{
|
| 1898 |
-
label: 'CPU (%)',
|
| 1899 |
-
data: [],
|
| 1900 |
-
borderColor: '#4CAF50',
|
| 1901 |
-
backgroundColor: 'rgba(76, 175, 80, 0.1)',
|
| 1902 |
-
tension: 0.3,
|
| 1903 |
-
fill: true,
|
| 1904 |
-
pointRadius: 0,
|
| 1905 |
-
hitRadius: 10,
|
| 1906 |
-
pointHoverRadius: 5,
|
| 1907 |
-
},
|
| 1908 |
-
{
|
| 1909 |
-
label: '内存 (%)',
|
| 1910 |
-
data: [],
|
| 1911 |
-
borderColor: '#2196F3',
|
| 1912 |
-
backgroundColor: 'rgba(33, 150, 243, 0.1)',
|
| 1913 |
-
tension: 0.3,
|
| 1914 |
-
fill: true,
|
| 1915 |
-
pointRadius: 0,
|
| 1916 |
-
hitRadius: 10,
|
| 1917 |
-
pointHoverRadius: 5,
|
| 1918 |
-
},
|
| 1919 |
-
{
|
| 1920 |
-
label: '上传 (KB/s)',
|
| 1921 |
-
data: [],
|
| 1922 |
-
borderColor: '#FF9800',
|
| 1923 |
-
backgroundColor: 'rgba(255, 152, 0, 0.1)',
|
| 1924 |
-
tension: 0.3,
|
| 1925 |
-
fill: true,
|
| 1926 |
-
pointRadius: 0,
|
| 1927 |
-
hitRadius: 10,
|
| 1928 |
-
pointHoverRadius: 5,
|
| 1929 |
-
},
|
| 1930 |
-
{
|
| 1931 |
-
label: '下载 (KB/s)',
|
| 1932 |
-
data: [],
|
| 1933 |
-
borderColor: '#9C27B0',
|
| 1934 |
-
backgroundColor: 'rgba(156, 39, 176, 0.1)',
|
| 1935 |
-
tension: 0.3,
|
| 1936 |
-
fill: true,
|
| 1937 |
-
pointRadius: 0,
|
| 1938 |
-
hitRadius: 10,
|
| 1939 |
-
pointHoverRadius: 5,
|
| 1940 |
-
},
|
| 1941 |
-
]
|
| 1942 |
-
},
|
| 1943 |
-
options: {
|
| 1944 |
-
responsive: true,
|
| 1945 |
-
maintainAspectRatio: false,
|
| 1946 |
-
animation: false,
|
| 1947 |
-
plugins: {
|
| 1948 |
-
legend: {
|
| 1949 |
-
labels: {
|
| 1950 |
-
color: textColor,
|
| 1951 |
-
font: { size: 11 }
|
| 1952 |
-
}
|
| 1953 |
-
},
|
| 1954 |
-
tooltip: {
|
| 1955 |
-
mode: 'index',
|
| 1956 |
-
intersect: false,
|
| 1957 |
-
callbacks: {
|
| 1958 |
-
label: function(context) {
|
| 1959 |
-
let label = context.dataset.label || '';
|
| 1960 |
-
if (label) {
|
| 1961 |
-
label += ': ';
|
| 1962 |
-
}
|
| 1963 |
-
if (context.parsed.y !== null) {
|
| 1964 |
-
label += context.parsed.y.toFixed(2);
|
| 1965 |
-
if (label.includes('CPU (%)') || label.includes('内存 (%)')) {
|
| 1966 |
-
label += '%';
|
| 1967 |
-
}
|
| 1968 |
-
}
|
| 1969 |
-
return label;
|
| 1970 |
-
}
|
| 1971 |
-
},
|
| 1972 |
-
titleFont: { size: 12 },
|
| 1973 |
-
bodyFont: { size: 11 },
|
| 1974 |
-
padding: 10,
|
| 1975 |
-
displayColors: true,
|
| 1976 |
-
boxPadding: 4,
|
| 1977 |
-
}
|
| 1978 |
-
},
|
| 1979 |
-
scales: {
|
| 1980 |
-
y: {
|
| 1981 |
-
beginAtZero: true,
|
| 1982 |
-
max: 100,
|
| 1983 |
-
grid: { color: gridColor, drawBorder: false },
|
| 1984 |
-
ticks: {
|
| 1985 |
-
color: textColor,
|
| 1986 |
-
font: { size: 10 },
|
| 1987 |
-
callback: function(value) {
|
| 1988 |
-
return value + '%';
|
| 1989 |
-
}
|
| 1990 |
-
},
|
| 1991 |
-
title: {
|
| 1992 |
-
display: true,
|
| 1993 |
-
text: '使用率 (%) / 流量 (KB/s)',
|
| 1994 |
-
color: textColor,
|
| 1995 |
-
font: { size: 11, weight: 'bold' },
|
| 1996 |
-
padding: { top: 0, bottom: 10 }
|
| 1997 |
-
}
|
| 1998 |
-
},
|
| 1999 |
-
x: {
|
| 2000 |
-
grid: { color: gridColor, drawBorder: false },
|
| 2001 |
-
ticks: {
|
| 2002 |
-
color: textColor,
|
| 2003 |
-
font: { size: 10 },
|
| 2004 |
-
maxRotation: 0,
|
| 2005 |
-
minRotation: 0,
|
| 2006 |
-
autoSkip: true,
|
| 2007 |
-
autoSkipPadding: 15,
|
| 2008 |
-
callback: function(value, index, values) {
|
| 2009 |
-
return '';
|
| 2010 |
-
}
|
| 2011 |
-
}
|
| 2012 |
-
}
|
| 2013 |
-
},
|
| 2014 |
-
hover: {
|
| 2015 |
-
mode: 'nearest',
|
| 2016 |
-
intersect: true
|
| 2017 |
-
}
|
| 2018 |
-
}
|
| 2019 |
-
});
|
| 2020 |
-
canvas.chart = chart;
|
| 2021 |
-
chartInstances.set(instanceId, chart);
|
| 2022 |
-
return chart;
|
| 2023 |
-
}
|
| 2024 |
-
|
| 2025 |
-
function updateChart(instanceId, data) {
|
| 2026 |
-
let chart = chartInstances.get(instanceId);
|
| 2027 |
-
const chartContainer = document.getElementById(`chart-container-${instanceId}`);
|
| 2028 |
-
if (!chartContainer || !chartContainer.parentElement.classList.contains('expanded')) {
|
| 2029 |
-
return;
|
| 2030 |
-
}
|
| 2031 |
-
|
| 2032 |
-
if (!chart) {
|
| 2033 |
-
chart = createChart(instanceId);
|
| 2034 |
-
if (!chart) return;
|
| 2035 |
-
console.log(`Instance ${instanceId}: Chart created.`);
|
| 2036 |
-
}
|
| 2037 |
-
|
| 2038 |
-
const cpuDataset = chart.data.datasets[0].data;
|
| 2039 |
-
const memoryDataset = chart.data.datasets[1].data;
|
| 2040 |
-
const uploadDataset = chart.data.datasets[2].data;
|
| 2041 |
-
const downloadDataset = chart.data.datasets[3].data;
|
| 2042 |
-
|
| 2043 |
-
cpuDataset.push(data.cpu_usage_pct?.toFixed(2) || NaN);
|
| 2044 |
-
const memoryPct = (data.memory_total_bytes > 0) ? ((data.memory_used_bytes / data.memory_total_bytes) * 100).toFixed(2) : NaN;
|
| 2045 |
-
memoryDataset.push(memoryPct);
|
| 2046 |
-
uploadDataset.push((data.tx_bps / 1024).toFixed(2));
|
| 2047 |
-
downloadDataset.push((data.rx_bps / 1024).toFixed(2));
|
| 2048 |
-
|
| 2049 |
-
const maxDataPoints = 30;
|
| 2050 |
-
if (cpuDataset.length > maxDataPoints) {
|
| 2051 |
-
cpuDataset.shift();
|
| 2052 |
-
memoryDataset.shift();
|
| 2053 |
-
uploadDataset.shift();
|
| 2054 |
-
downloadDataset.shift();
|
| 2055 |
-
}
|
| 2056 |
-
|
| 2057 |
-
chart.update('quiet');
|
| 2058 |
-
}
|
| 2059 |
-
|
| 2060 |
-
function toggleChart(instanceId) {
|
| 2061 |
-
const card = document.getElementById(`instance-${instanceId}`);
|
| 2062 |
-
const chartContainer = document.getElementById(`chart-container-${instanceId}`);
|
| 2063 |
-
const toggleButton = card.querySelector('.chart-toggle-button');
|
| 2064 |
-
if (!card || !chartContainer) return;
|
| 2065 |
-
|
| 2066 |
-
if (card.classList.contains('expanded')) {
|
| 2067 |
-
card.classList.remove('expanded');
|
| 2068 |
-
toggleButton.textContent = '查看图表';
|
| 2069 |
-
} else {
|
| 2070 |
-
card.classList.add('expanded');
|
| 2071 |
-
toggleButton.textContent = '收起图表';
|
| 2072 |
-
if (!chartInstances.has(instanceId)) {
|
| 2073 |
-
createChart(instanceId);
|
| 2074 |
-
const status = serverStatus.get(instanceId);
|
| 2075 |
-
if (status && status.data) {
|
| 2076 |
-
console.log(`Instance ${instanceId}: Chart created on show, waiting for SSE data.`);
|
| 2077 |
-
}
|
| 2078 |
}
|
| 2079 |
-
updateChartThemeForInstance(instanceId);
|
| 2080 |
-
}
|
| 2081 |
-
}
|
| 2082 |
-
|
| 2083 |
-
function updateChartTheme() {
|
| 2084 |
-
const isDarkMode = document.documentElement.getAttribute('data-theme') === 'dark';
|
| 2085 |
-
const gridColor = isDarkMode ? 'rgba(255, 255, 255, 0.08)' : 'rgba(0, 0, 0, 0.08)';
|
| 2086 |
-
const textColor = isDarkMode ? '#e0e0e0' : '#333';
|
| 2087 |
-
|
| 2088 |
-
chartInstances.forEach((chart, instanceId) => {
|
| 2089 |
-
updateChartThemeForInstance(instanceId, gridColor, textColor);
|
| 2090 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2091 |
}
|
| 2092 |
|
| 2093 |
-
|
| 2094 |
-
const chart = chartInstances.get(instanceId);
|
| 2095 |
-
if (!chart) return;
|
| 2096 |
-
|
| 2097 |
-
if (gridColor === null || textColor === null) {
|
| 2098 |
-
const isDarkMode = document.documentElement.getAttribute('data-theme') === 'dark';
|
| 2099 |
-
gridColor = isDarkMode ? 'rgba(255, 255, 255, 0.08)' : 'rgba(0, 0, 0, 0.08)';
|
| 2100 |
-
textColor = isDarkMode ? '#e0e0e0' : '#333';
|
| 2101 |
-
}
|
| 2102 |
-
|
| 2103 |
-
chart.options.scales.y.grid.color = gridColor;
|
| 2104 |
-
chart.options.scales.y.ticks.color = textColor;
|
| 2105 |
-
chart.options.scales.y.title.color = textColor;
|
| 2106 |
-
chart.options.scales.x.grid.color = gridColor;
|
| 2107 |
-
chart.options.scales.x.ticks.color = textColor;
|
| 2108 |
-
chart.options.plugins.legend.labels.color = textColor;
|
| 2109 |
-
chart.update('none');
|
| 2110 |
-
}
|
| 2111 |
-
// ==================== 图表功能 END ====================
|
| 2112 |
-
|
| 2113 |
-
// ==================== 实例操作 START ====================
|
| 2114 |
function viewInstance(url) {
|
| 2115 |
-
|
| 2116 |
-
window.open(url, '_blank');
|
| 2117 |
-
} else {
|
| 2118 |
-
showToast('error', '该实例没有可用的 public URL。');
|
| 2119 |
-
}
|
| 2120 |
}
|
| 2121 |
|
|
|
|
| 2122 |
function manageInstance(repoId) {
|
| 2123 |
const manageUrl = `https://huggingface.co/spaces/${repoId}`;
|
| 2124 |
window.open(manageUrl, '_blank');
|
| 2125 |
}
|
| 2126 |
-
// ==================== 实例操作 END ====================
|
| 2127 |
-
|
| 2128 |
-
// ==================== Toast Notification START ====================
|
| 2129 |
-
function showToast(type, message, duration = 3000) {
|
| 2130 |
-
const toastContainer = document.getElementById('toastContainer');
|
| 2131 |
-
const toast = document.createElement('div');
|
| 2132 |
-
toast.className = `toast ${type}`;
|
| 2133 |
-
toast.innerHTML = `
|
| 2134 |
-
<span class="toast-icon">${type === 'success' ? '✓' : '✗'}</span>
|
| 2135 |
-
<span>${message}</span>
|
| 2136 |
-
`;
|
| 2137 |
-
toastContainer.appendChild(toast);
|
| 2138 |
-
|
| 2139 |
-
setTimeout(() => toast.classList.add('show'), 100);
|
| 2140 |
-
setTimeout(() => {
|
| 2141 |
-
toast.classList.remove('show');
|
| 2142 |
-
setTimeout(() => toast.remove(), 300);
|
| 2143 |
-
}, duration);
|
| 2144 |
-
}
|
| 2145 |
-
// ==================== Toast Notification END ====================
|
| 2146 |
</script>
|
| 2147 |
</body>
|
| 2148 |
</html>
|
|
|
|
| 2 |
<html lang="zh">
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> <!-- 确保 viewport 设置正确,防止缩放问题 -->
|
| 6 |
<title>HF Space Manager</title>
|
| 7 |
+
<!-- 引入 Chart.js CDN -->
|
| 8 |
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.7/dist/chart.umd.min.js"></script>
|
|
|
|
|
|
|
| 9 |
<style>
|
| 10 |
* {
|
| 11 |
margin: 0;
|
| 12 |
padding: 0;
|
| 13 |
box-sizing: border-box;
|
| 14 |
}
|
|
|
|
| 15 |
body {
|
| 16 |
+
font-family: "Inter", "SF Pro Display", -apple-system, BlinkMacSystemFont, sans-serif;
|
| 17 |
background: var(--background-color);
|
| 18 |
color: var(--text-color);
|
| 19 |
+
padding: 20px;
|
| 20 |
min-height: 100vh;
|
| 21 |
transition: background 0.3s ease, color 0.3s ease;
|
|
|
|
| 22 |
}
|
|
|
|
| 23 |
:root {
|
| 24 |
+
/* 深色模式变量(默认) */
|
| 25 |
--background-color: #0a0a0a;
|
| 26 |
+
--text-color: #fff;
|
| 27 |
+
--card-background: #1a1a1a;
|
| 28 |
+
--card-border: rgba(255, 255, 255, 0.1);
|
| 29 |
+
--metric-background: #141414;
|
| 30 |
--metric-border: rgba(255, 255, 255, 0.05);
|
| 31 |
+
--metric-hover: #202020;
|
| 32 |
+
--secondary-text: #888;
|
| 33 |
+
--label-color: #666;
|
| 34 |
+
--network-background: rgba(255, 255, 255, 0.07);
|
| 35 |
--action-button-bg: #3a3a3a;
|
| 36 |
--action-button-hover: #4a4a4a;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
}
|
|
|
|
| 38 |
[data-theme="light"] {
|
| 39 |
+
/* 浅色模式变量 */
|
| 40 |
+
--background-color: #f5f5f5;
|
| 41 |
--text-color: #333;
|
| 42 |
+
--card-background: #fff;
|
| 43 |
--card-border: rgba(0, 0, 0, 0.1);
|
| 44 |
+
--metric-background: #f9f9f9;
|
| 45 |
--metric-border: rgba(0, 0, 0, 0.05);
|
| 46 |
+
--metric-hover: #eaeaea;
|
| 47 |
+
--secondary-text: #666;
|
| 48 |
+
--label-color: #999;
|
| 49 |
+
--network-background: rgba(0, 0, 0, 0.07);
|
| 50 |
+
--action-button-bg: #e0e0e0;
|
| 51 |
+
--action-button-hover: #d0d0d0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
}
|
|
|
|
| 53 |
.container {
|
| 54 |
+
max-width: 1400px;
|
| 55 |
margin: 0 auto;
|
| 56 |
+
animation: fadeIn 0.5s ease;
|
| 57 |
padding: 0 15px;
|
| 58 |
}
|
|
|
|
| 59 |
.overview {
|
| 60 |
background: var(--card-background);
|
| 61 |
+
border-radius: 15px;
|
| 62 |
+
padding: 20px;
|
| 63 |
+
margin-bottom: 25px;
|
| 64 |
border: 1px solid var(--card-border);
|
| 65 |
+
transition: background 0.3s ease, border 0.3s ease;
|
|
|
|
| 66 |
}
|
|
|
|
| 67 |
.overview-title {
|
| 68 |
+
font-size: 18px;
|
|
|
|
| 69 |
display: flex;
|
| 70 |
align-items: center;
|
| 71 |
gap: 10px;
|
| 72 |
+
margin-bottom: 15px;
|
| 73 |
color: var(--text-color);
|
| 74 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
.theme-toggle {
|
| 76 |
display: flex;
|
| 77 |
align-items: center;
|
| 78 |
+
gap: 10px;
|
| 79 |
+
margin-bottom: 15px;
|
| 80 |
font-size: 14px;
|
| 81 |
color: var(--secondary-text);
|
| 82 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
.theme-toggle button {
|
| 84 |
background: var(--metric-background);
|
| 85 |
border: 1px solid var(--metric-border);
|
| 86 |
color: var(--text-color);
|
| 87 |
+
padding: 6px;
|
| 88 |
+
border-radius: 6px;
|
| 89 |
cursor: pointer;
|
| 90 |
display: flex;
|
| 91 |
align-items: center;
|
| 92 |
justify-content: center;
|
| 93 |
+
width: 32px;
|
| 94 |
+
height: 32px;
|
| 95 |
+
transition: background 0.2s ease, transform 0.2s ease;
|
|
|
|
| 96 |
}
|
|
|
|
| 97 |
.theme-toggle button:hover {
|
| 98 |
background: var(--metric-hover);
|
| 99 |
+
transform: scale(1.05);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
.theme-toggle svg {
|
| 102 |
width: 18px;
|
| 103 |
height: 18px;
|
| 104 |
+
fill: var(--text-color);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
}
|
|
|
|
| 106 |
#summary {
|
| 107 |
display: grid;
|
| 108 |
+
grid-template-columns: repeat(6, 1fr);
|
| 109 |
+
gap: 12px;
|
| 110 |
}
|
|
|
|
| 111 |
#summary div {
|
| 112 |
background: var(--metric-background);
|
| 113 |
+
padding: 12px;
|
| 114 |
border-radius: 8px;
|
| 115 |
border: 1px solid var(--metric-border);
|
| 116 |
transition: background 0.3s ease, border 0.3s ease;
|
|
|
|
|
|
|
|
|
|
| 117 |
}
|
|
|
|
| 118 |
#summary div {
|
| 119 |
font-size: 13px;
|
| 120 |
color: var(--secondary-text);
|
| 121 |
}
|
|
|
|
| 122 |
#summary span {
|
| 123 |
display: block;
|
| 124 |
+
font-size: 22px;
|
| 125 |
+
font-weight: bold;
|
| 126 |
+
margin-top: 5px;
|
| 127 |
color: var(--text-color);
|
| 128 |
overflow: hidden;
|
| 129 |
text-overflow: ellipsis;
|
| 130 |
white-space: nowrap;
|
|
|
|
| 131 |
}
|
|
|
|
| 132 |
.stats-container {
|
| 133 |
+
display: grid;
|
| 134 |
+
grid-template-columns: 1fr;
|
| 135 |
+
gap: 20px;
|
| 136 |
+
margin-top: 20px;
|
| 137 |
}
|
|
|
|
| 138 |
.user-group {
|
| 139 |
background: var(--card-background);
|
| 140 |
+
border-radius: 10px;
|
| 141 |
border: 1px solid var(--card-border);
|
| 142 |
overflow: hidden;
|
| 143 |
transition: background 0.3s ease, border 0.3s ease;
|
| 144 |
}
|
|
|
|
| 145 |
.user-group summary {
|
| 146 |
+
padding: 15px;
|
| 147 |
+
font-weight: bold;
|
| 148 |
cursor: pointer;
|
| 149 |
color: var(--text-color);
|
| 150 |
background: var(--metric-background);
|
| 151 |
transition: background 0.2s ease;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
}
|
|
|
|
| 153 |
.user-group summary:hover {
|
| 154 |
background: var(--metric-hover);
|
| 155 |
}
|
|
|
|
|
|
|
| 156 |
.user-group summary::-webkit-details-marker {
|
| 157 |
+
color: var(--text-color);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
}
|
|
|
|
| 159 |
.user-servers {
|
| 160 |
display: grid;
|
| 161 |
+
grid-template-columns: repeat(2, 1fr);
|
| 162 |
gap: 15px;
|
| 163 |
+
padding: 15px;
|
| 164 |
}
|
|
|
|
| 165 |
.server-card {
|
| 166 |
background: var(--metric-background);
|
| 167 |
+
border-radius: 8px;
|
| 168 |
+
padding: 15px;
|
| 169 |
border: 1px solid var(--metric-border);
|
| 170 |
transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.3s ease, border 0.3s ease;
|
| 171 |
+
min-height: 150px; /* 登录状态下的最小高度,适配有操作按钮的情况 */
|
| 172 |
display: flex;
|
| 173 |
flex-direction: column;
|
|
|
|
| 174 |
}
|
| 175 |
+
.server-card.not-logged-in {
|
| 176 |
+
min-height: 120px; /* 未登录状态下的最小高度,减少空白 */
|
| 177 |
+
}
|
| 178 |
.server-card:hover {
|
| 179 |
+
transform: translateY(-2px);
|
| 180 |
+
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
|
| 181 |
}
|
|
|
|
| 182 |
.server-header {
|
| 183 |
display: flex;
|
| 184 |
justify-content: space-between;
|
| 185 |
align-items: center;
|
| 186 |
+
margin-bottom: 10px;
|
| 187 |
+
font-size: 14px;
|
|
|
|
|
|
|
| 188 |
}
|
|
|
|
| 189 |
.server-name {
|
| 190 |
display: flex;
|
| 191 |
align-items: center;
|
| 192 |
+
gap: 8px;
|
| 193 |
flex: 1;
|
| 194 |
+
min-width: 0; /* 防止内容溢出 */
|
|
|
|
|
|
|
| 195 |
}
|
|
|
|
| 196 |
.server-name div {
|
| 197 |
overflow: hidden;
|
| 198 |
text-overflow: ellipsis;
|
| 199 |
white-space: nowrap;
|
| 200 |
+
max-width: 100%; /* 限制名称的最大宽度 */
|
| 201 |
}
|
|
|
|
| 202 |
.server-flag {
|
| 203 |
width: 20px;
|
| 204 |
height: 20px;
|
| 205 |
border-radius: 4px;
|
|
|
|
| 206 |
flex-shrink: 0;
|
|
|
|
| 207 |
}
|
|
|
|
| 208 |
.metric-grid {
|
| 209 |
display: grid;
|
| 210 |
+
grid-template-columns: repeat(5, 1fr);
|
| 211 |
gap: 10px;
|
| 212 |
+
margin-top: 10px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
}
|
|
|
|
| 214 |
.metric-item {
|
| 215 |
background: var(--card-background);
|
| 216 |
+
padding: 8px;
|
| 217 |
border-radius: 6px;
|
| 218 |
border: 1px solid var(--metric-border);
|
| 219 |
+
transition: background 0.3s ease;
|
| 220 |
+
overflow: hidden; /* 防止内容溢出 */
|
| 221 |
}
|
|
|
|
| 222 |
.metric-item:hover {
|
| 223 |
background: var(--metric-hover);
|
| 224 |
}
|
|
|
|
| 225 |
.metric-label {
|
| 226 |
color: var(--label-color);
|
| 227 |
font-size: 12px;
|
| 228 |
+
margin-bottom: 3px;
|
| 229 |
white-space: nowrap;
|
|
|
|
| 230 |
}
|
|
|
|
| 231 |
.metric-value {
|
| 232 |
+
font-size: 14px;
|
| 233 |
+
font-weight: 500;
|
|
|
|
| 234 |
overflow: hidden;
|
| 235 |
text-overflow: ellipsis;
|
| 236 |
white-space: nowrap;
|
| 237 |
+
max-width: 100%; /* 限制指标值的宽度 */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
}
|
|
|
|
| 239 |
.status-dot {
|
| 240 |
display: inline-block;
|
| 241 |
border-radius: 50%;
|
| 242 |
+
animation: pulse 2s infinite;
|
| 243 |
width: 10px;
|
| 244 |
height: 10px;
|
| 245 |
flex-shrink: 0;
|
|
|
|
| 246 |
}
|
| 247 |
+
.status-online {
|
| 248 |
+
background-color: #4CAF50;
|
| 249 |
+
color: #4CAF50;
|
|
|
|
|
|
|
| 250 |
}
|
| 251 |
+
.status-offline {
|
| 252 |
+
background-color: #f44336;
|
| 253 |
+
color: #f44336;
|
| 254 |
}
|
| 255 |
+
.status-sleep {
|
| 256 |
+
background-color: #ffa500;
|
| 257 |
+
color: #ffa500;
|
| 258 |
animation: none;
|
| 259 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
.action-buttons {
|
| 261 |
display: flex;
|
| 262 |
+
gap: 10px;
|
| 263 |
+
margin-top: 10px;
|
|
|
|
|
|
|
| 264 |
}
|
|
|
|
| 265 |
.action-button {
|
| 266 |
background: var(--action-button-bg);
|
| 267 |
+
color: var(--text-color);
|
| 268 |
border: none;
|
| 269 |
+
padding: 6px 12px;
|
| 270 |
+
border-radius: 4px;
|
| 271 |
cursor: pointer;
|
| 272 |
font-size: 13px;
|
| 273 |
+
transition: background 0.2s ease;
|
|
|
|
|
|
|
|
|
|
| 274 |
}
|
|
|
|
| 275 |
.action-button:hover {
|
| 276 |
background: var(--action-button-hover);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 277 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 278 |
.network-stats {
|
| 279 |
background: var(--network-background);
|
| 280 |
border: 1px solid var(--metric-border);
|
|
|
|
| 282 |
padding: 15px;
|
| 283 |
border-radius: 8px;
|
| 284 |
transition: background 0.3s ease, border 0.3s ease;
|
| 285 |
+
}
|
| 286 |
+
.network-item {
|
| 287 |
font-size: 14px;
|
| 288 |
color: var(--secondary-text);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 289 |
}
|
|
|
|
| 290 |
@keyframes fadeIn {
|
| 291 |
from { opacity: 0; transform: translateY(20px); }
|
| 292 |
to { opacity: 1; transform: translateY(0); }
|
| 293 |
}
|
| 294 |
+
@keyframes pulse {
|
| 295 |
+
0% { box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.4); }
|
| 296 |
+
70% { box-shadow: 0 0 0 10px rgba(76, 175, 80, 0); }
|
| 297 |
+
100% { box-shadow: 0 0 0 0 rgba(76, 175, 80, 0); }
|
| 298 |
+
}
|
| 299 |
+
@media (max-width: 600px) { /* 降低阈值,确保覆盖更多小屏幕设备如 iPhone */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 300 |
#summary {
|
| 301 |
+
grid-template-columns: 1fr; /* 小屏幕单列显示 */
|
| 302 |
+
gap: 10px;
|
| 303 |
}
|
|
|
|
| 304 |
#summary div {
|
| 305 |
+
padding: 10px;
|
| 306 |
}
|
|
|
|
| 307 |
#summary span {
|
| 308 |
+
font-size: 20px; /* 小屏幕字体略小 */
|
|
|
|
|
|
|
|
|
|
|
|
|
| 309 |
}
|
|
|
|
| 310 |
.user-servers {
|
| 311 |
+
grid-template-columns: 1fr !important; /* 小屏幕强制单列显示实例卡片,使用 !important 提高优先级 */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 312 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 313 |
.metric-grid {
|
| 314 |
+
grid-template-columns: repeat(2, 1fr); /* 小屏幕指标网格改为2列 */
|
| 315 |
gap: 8px;
|
| 316 |
}
|
|
|
|
| 317 |
.metric-item {
|
| 318 |
+
padding: 6px;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 319 |
}
|
|
|
|
| 320 |
.metric-value {
|
| 321 |
+
font-size: 13px; /* 小屏幕字体略小 */
|
| 322 |
}
|
| 323 |
+
.server-header {
|
| 324 |
+
flex-direction: row;
|
| 325 |
+
flex-wrap: wrap;
|
| 326 |
+
gap: 8px; /* 小屏幕避免标题和按钮过于紧密 */
|
| 327 |
}
|
| 328 |
+
.container {
|
| 329 |
+
padding: 0 10px; /* 小屏幕减少整体边距 */
|
| 330 |
+
}
|
| 331 |
+
.overview {
|
| 332 |
+
padding: 15px;
|
| 333 |
+
margin-bottom: 20px;
|
| 334 |
}
|
| 335 |
}
|
| 336 |
+
.login-overlay, .confirm-overlay, .loading-overlay {
|
| 337 |
+
position: fixed;
|
| 338 |
+
top: 0;
|
| 339 |
+
left: 0;
|
| 340 |
+
width: 100%;
|
| 341 |
+
height: 100%;
|
| 342 |
+
background: rgba(0, 0, 0, 0.6);
|
| 343 |
display: flex;
|
|
|
|
|
|
|
| 344 |
align-items: center;
|
| 345 |
+
justify-content: center;
|
| 346 |
+
z-index: 1000;
|
| 347 |
+
display: none;
|
| 348 |
}
|
| 349 |
+
.login-box, .confirm-box {
|
| 350 |
+
background: var(--card-background);
|
| 351 |
+
padding: 30px;
|
| 352 |
+
border-radius: 10px;
|
| 353 |
+
border: 1px solid var(--card-border);
|
| 354 |
+
width: 300px;
|
| 355 |
+
text-align: center;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 356 |
}
|
| 357 |
+
.login-box h2, .confirm-box h2 {
|
| 358 |
+
margin-bottom: 20px;
|
| 359 |
+
color: var(--text-color);
|
| 360 |
+
}
|
| 361 |
+
.login-box input {
|
| 362 |
+
width: 100%;
|
| 363 |
+
padding: 10px;
|
| 364 |
+
margin: 10px 0;
|
| 365 |
+
border: 1px solid var(--metric-border);
|
| 366 |
+
border-radius: 5px;
|
| 367 |
+
background: var(--metric-background);
|
| 368 |
+
color: var(--text-color);
|
| 369 |
+
}
|
| 370 |
+
.login-box button, .confirm-box button {
|
| 371 |
+
width: 48%;
|
| 372 |
+
padding: 10px;
|
| 373 |
+
background: var(--action-button-bg);
|
| 374 |
+
border: none;
|
| 375 |
+
border-radius: 5px;
|
| 376 |
+
color: var(--text-color);
|
| 377 |
+
cursor: pointer;
|
| 378 |
+
transition: background 0.2s ease;
|
| 379 |
+
margin: 5px 1%;
|
| 380 |
+
}
|
| 381 |
+
.login-box button:hover, .confirm-box button:hover {
|
| 382 |
+
background: var(--action-button-hover);
|
| 383 |
+
}
|
| 384 |
+
.login-error {
|
| 385 |
+
color: #f44336;
|
| 386 |
+
margin-top: 10px;
|
| 387 |
+
font-size: 14px;
|
| 388 |
+
}
|
| 389 |
+
.login-button, .logout-button {
|
| 390 |
+
background: var(--action-button-bg);
|
| 391 |
+
border: none;
|
| 392 |
+
color: var(--text-color);
|
| 393 |
+
padding: 6px 12px;
|
| 394 |
+
border-radius: 4px;
|
| 395 |
+
cursor: pointer;
|
| 396 |
+
font-size: 13px;
|
| 397 |
+
transition: background 0.2s ease;
|
| 398 |
+
}
|
| 399 |
+
.login-button:hover, .logout-button:hover {
|
| 400 |
+
background: var(--action-button-hover);
|
| 401 |
+
}
|
| 402 |
+
.header-container {
|
| 403 |
+
display: flex;
|
| 404 |
+
justify-content: space-between;
|
| 405 |
+
align-items: center;
|
| 406 |
+
margin-bottom: 15px;
|
| 407 |
+
}
|
| 408 |
+
.auth-buttons {
|
| 409 |
+
display: flex;
|
| 410 |
+
gap: 10px;
|
| 411 |
+
}
|
| 412 |
+
/* 加载状态指示器样式 */
|
| 413 |
+
.loader {
|
| 414 |
+
border: 5px solid var(--card-background);
|
| 415 |
+
border-top: 5px solid #4CAF50;
|
| 416 |
+
border-radius: 50%;
|
| 417 |
+
width: 50px;
|
| 418 |
+
height: 50px;
|
| 419 |
+
animation: spin 1s linear infinite;
|
| 420 |
+
}
|
| 421 |
+
@keyframes spin {
|
| 422 |
+
0% { transform: rotate(0deg); }
|
| 423 |
+
100% { transform: rotate(360deg); }
|
| 424 |
+
}
|
| 425 |
+
/* 优化后的过滤与排序控件样式 */
|
| 426 |
+
.filter-sort-panel {
|
| 427 |
+
background: var(--card-background);
|
| 428 |
+
border: 1px solid var(--card-border);
|
| 429 |
+
border-radius: 10px;
|
| 430 |
+
padding: 15px;
|
| 431 |
+
margin-bottom: 20px;
|
| 432 |
+
display: flex;
|
| 433 |
+
flex-wrap: wrap;
|
| 434 |
+
gap: 15px;
|
| 435 |
+
align-items: center;
|
| 436 |
+
transition: background 0.3s ease, border 0.3s ease;
|
| 437 |
+
}
|
| 438 |
+
.filter-sort-group {
|
| 439 |
+
display: flex;
|
| 440 |
+
align-items: center;
|
| 441 |
+
gap: 10px;
|
| 442 |
+
font-size: 14px;
|
| 443 |
+
color: var(--text-color);
|
| 444 |
+
min-width: 200px; /* 确保控件有足够的宽度 */
|
| 445 |
}
|
|
|
|
| 446 |
.filter-sort-group label {
|
| 447 |
white-space: nowrap;
|
| 448 |
color: var(--secondary-text);
|
| 449 |
font-weight: 500;
|
|
|
|
| 450 |
}
|
|
|
|
| 451 |
.filter-sort-group select {
|
| 452 |
flex: 1;
|
| 453 |
background: var(--metric-background);
|
| 454 |
border: 1px solid var(--metric-border);
|
| 455 |
color: var(--text-color);
|
| 456 |
+
padding: 8px 12px;
|
| 457 |
border-radius: 6px;
|
| 458 |
cursor: pointer;
|
| 459 |
font-size: 14px;
|
| 460 |
+
transition: background 0.2s ease, border 0.2s ease;
|
|
|
|
| 461 |
outline: none;
|
| 462 |
+
appearance: none; /* 移除默认的下拉箭头 */
|
| 463 |
+
background-image: url("data:image/svg+xml;utf8,<svg fill='%23fff' height='24' viewBox='0 0 24 24' width='24' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/><path d='M0 0h24v24H0z' fill='none'/></svg>");
|
| 464 |
background-repeat: no-repeat;
|
| 465 |
background-position: right 10px center;
|
| 466 |
+
padding-right: 36px; /* 为箭头留出空间 */
|
| 467 |
}
|
|
|
|
| 468 |
[data-theme="light"] .filter-sort-group select {
|
| 469 |
+
background-image: url("data:image/svg+xml;utf8,<svg fill='%23333' height='24' viewBox='0 0 24 24' width='24' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/><path d='M0 0h24v24H0z' fill='none'/></svg>");
|
| 470 |
}
|
|
|
|
| 471 |
.filter-sort-group select:hover {
|
| 472 |
background-color: var(--metric-hover);
|
| 473 |
+
border-color: rgba(255, 255, 255, 0.15); /* 微调 hover 时的边框 */
|
| 474 |
}
|
|
|
|
| 475 |
.filter-sort-group select:focus {
|
| 476 |
+
border-color: #4CAF50;
|
| 477 |
box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.3);
|
| 478 |
}
|
|
|
|
| 479 |
.refresh-button {
|
| 480 |
+
background: var(--action-button-bg);
|
| 481 |
border: none;
|
| 482 |
+
color: var(--text-color);
|
| 483 |
+
padding: 8px 16px;
|
| 484 |
border-radius: 6px;
|
| 485 |
cursor: pointer;
|
| 486 |
font-size: 14px;
|
| 487 |
+
transition: background 0.2s ease, transform 0.2s ease;
|
|
|
|
| 488 |
display: flex;
|
| 489 |
align-items: center;
|
| 490 |
gap: 8px;
|
| 491 |
height: 40px;
|
|
|
|
| 492 |
}
|
| 493 |
+
.refresh-button:hover {
|
| 494 |
+
background: var(--action-button-hover);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 495 |
transform: translateY(-1px);
|
| 496 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 497 |
.refresh-icon {
|
| 498 |
width: 16px;
|
| 499 |
height: 16px;
|
| 500 |
fill: currentColor;
|
| 501 |
}
|
| 502 |
+
@media (max-width: 600px) {
|
| 503 |
+
.filter-sort-group {
|
| 504 |
+
min-width: 100%; /* 小屏时控件占满一行 */
|
| 505 |
+
}
|
| 506 |
+
.filter-sort-panel {
|
| 507 |
+
gap: 12px; /* 小屏时减少间距 */
|
| 508 |
+
padding: 12px;
|
| 509 |
+
}
|
| 510 |
}
|
| 511 |
+
/* 图表相关样式 */
|
| 512 |
.chart-container {
|
| 513 |
+
display: none; /* 默认隐藏 */
|
| 514 |
margin-top: 15px;
|
| 515 |
+
background: var(--card-background);
|
| 516 |
+
border: 1px solid var(--card-border);
|
| 517 |
border-radius: 8px;
|
| 518 |
+
padding: 10px;
|
| 519 |
+
height: 300px;
|
| 520 |
transition: background 0.3s ease, border 0.3s ease;
|
| 521 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 522 |
.chart-toggle-button {
|
| 523 |
background: var(--action-button-bg);
|
| 524 |
+
color: var(--text-color);
|
| 525 |
border: none;
|
| 526 |
padding: 6px 12px;
|
| 527 |
border-radius: 4px;
|
| 528 |
cursor: pointer;
|
| 529 |
+
font-size: 13px;
|
| 530 |
+
transition: background 0.2s ease;
|
| 531 |
margin-left: auto;
|
| 532 |
white-space: nowrap;
|
|
|
|
| 533 |
}
|
|
|
|
| 534 |
.chart-toggle-button:hover {
|
| 535 |
background: var(--action-button-hover);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 536 |
}
|
| 537 |
+
.expanded .chart-container {
|
| 538 |
+
display: block;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 539 |
}
|
| 540 |
+
canvas {
|
| 541 |
+
width: 100% !important;
|
| 542 |
+
height: auto !important;
|
| 543 |
}
|
| 544 |
+
@media (max-width: 600px) {
|
| 545 |
+
.chart-container {
|
| 546 |
+
height: 250px; /* 小屏幕图表高度略减 */
|
| 547 |
+
}
|
| 548 |
}
|
| 549 |
</style>
|
| 550 |
</head>
|
|
|
|
| 559 |
</div>
|
| 560 |
</div>
|
| 561 |
<div class="theme-toggle">
|
| 562 |
+
主题:
|
| 563 |
<button onclick="toggleTheme('system')" title="跟随系统">
|
| 564 |
<svg width="24" height="24" viewBox="0 0 24 24" fill="currentColor">
|
| 565 |
<path d="M3 5h18c1.1 0 2 .9 2 2v10c0 1.1-.9 2-2 2H3c-1.1 0-2-.9-2-2V7c0-1.1.9-2 2-2zm0 12h18V7H3v10zm2-8h2v2H5V9zm0 4h2v2H5v-2zm4-4h10v2H9V9zm0 4h10v2H9v-2z"/>
|
|
|
|
| 577 |
</button>
|
| 578 |
</div>
|
| 579 |
<div id="summary">
|
| 580 |
+
<div>总用户数: <span id="totalUsers">0</span></div>
|
| 581 |
+
<div>总实例数: <span id="totalServers">0</span></div>
|
| 582 |
+
<div>在线实例: <span id="onlineServers">0</span></div>
|
| 583 |
+
<div>离线实例: <span id="offlineServers">0</span></div>
|
| 584 |
+
<div>总上传: <span id="totalUpload">0 B/s</span></div>
|
| 585 |
+
<div>总下载: <span id="totalDownload">0 B/s</span></div>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 586 |
</div>
|
| 587 |
</div>
|
| 588 |
+
<!-- 优化后的过滤与排序面板 -->
|
| 589 |
<div class="filter-sort-panel">
|
| 590 |
<div class="filter-sort-group">
|
| 591 |
<label for="statusFilter">过滤状态:</label>
|
|
|
|
| 611 |
<option value="status-desc">状态 (停止-运行)</option>
|
| 612 |
</select>
|
| 613 |
</div>
|
| 614 |
+
<button class="refresh-button" onclick="refreshData()">
|
| 615 |
<svg class="refresh-icon" viewBox="0 0 24 24" fill="currentColor">
|
| 616 |
<path d="M17.65 6.35A7.958 7.958 0 0012 4c-4.42 0-7.99 3.58-7.99 8s3.57 8 7.99 8c3.73 0 6.84-2.55 7.73-6h-2.08A5.99 5.99 0 0112 18c-3.31 0-6-2.69-6-6s2.69-6 6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z"/>
|
| 617 |
</svg>
|
|
|
|
| 621 |
<div id="servers" class="stats-container">
|
| 622 |
</div>
|
| 623 |
</div>
|
| 624 |
+
<!-- 登录弹窗 -->
|
| 625 |
<div id="loginOverlay" class="login-overlay">
|
| 626 |
<div class="login-box">
|
| 627 |
<h2>登录</h2>
|
| 628 |
+
<input type="text" id="username" placeholder="用户名">
|
| 629 |
+
<input type="password" id="password" placeholder="密码">
|
| 630 |
+
<div style="display: flex; justify-content: center; gap: 10px; margin-top: 20px;">
|
| 631 |
<button onclick="login()">登录</button>
|
| 632 |
<button onclick="hideLoginForm()">取消</button>
|
| 633 |
</div>
|
| 634 |
<div id="loginError" class="login-error" style="display: none;"></div>
|
| 635 |
</div>
|
| 636 |
</div>
|
| 637 |
+
<!-- 确认弹窗 -->
|
| 638 |
<div id="confirmOverlay" class="confirm-overlay">
|
| 639 |
<div class="confirm-box">
|
| 640 |
<h2 id="confirmTitle">确认操作</h2>
|
| 641 |
+
<p id="confirmMessage" style="margin-bottom: 20px; color: var(--text-color);"></p>
|
| 642 |
+
<button onclick="confirmAction()">确认</button>
|
| 643 |
+
<button onclick="cancelAction()">取消</button>
|
|
|
|
|
|
|
| 644 |
</div>
|
| 645 |
</div>
|
| 646 |
+
<!-- 加载状态覆盖层 -->
|
| 647 |
<div id="loadingOverlay" class="loading-overlay">
|
| 648 |
<div class="loader"></div>
|
| 649 |
</div>
|
|
|
|
| 650 |
|
| 651 |
<script>
|
| 652 |
+
// 主题切换功能
|
| 653 |
function setTheme(theme) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 654 |
if (theme === 'system') {
|
| 655 |
localStorage.removeItem('theme');
|
| 656 |
const systemPrefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
| 657 |
+
document.documentElement.setAttribute('data-theme', systemPrefersDark ? 'dark' : 'light');
|
|
|
|
| 658 |
} else {
|
| 659 |
localStorage.setItem('theme', theme);
|
| 660 |
+
document.documentElement.setAttribute('data-theme', theme);
|
|
|
|
| 661 |
}
|
|
|
|
| 662 |
}
|
| 663 |
|
| 664 |
function toggleTheme(theme) {
|
| 665 |
setTheme(theme);
|
| 666 |
}
|
| 667 |
|
| 668 |
+
// 初始化主题
|
| 669 |
function initTheme() {
|
| 670 |
const savedTheme = localStorage.getItem('theme');
|
| 671 |
if (savedTheme) {
|
| 672 |
setTheme(savedTheme);
|
| 673 |
} else {
|
| 674 |
+
const systemPrefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
| 675 |
+
setTheme(systemPrefersDark ? 'dark' : 'light');
|
| 676 |
}
|
| 677 |
}
|
| 678 |
|
| 679 |
+
// 监听系统主题变化
|
| 680 |
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
|
| 681 |
if (!localStorage.getItem('theme')) {
|
| 682 |
setTheme('system');
|
|
|
|
| 684 |
});
|
| 685 |
|
| 686 |
initTheme();
|
|
|
|
| 687 |
|
| 688 |
+
// 全局变量,表示当前是否已登录
|
| 689 |
let isLoggedIn = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 690 |
|
| 691 |
+
// 加载状态控制函数
|
| 692 |
function showLoading() {
|
| 693 |
+
document.getElementById('loadingOverlay').style.display = 'flex';
|
|
|
|
|
|
|
| 694 |
}
|
| 695 |
|
| 696 |
function hideLoading() {
|
| 697 |
+
document.getElementById('loadingOverlay').style.display = 'none';
|
|
|
|
|
|
|
| 698 |
}
|
|
|
|
| 699 |
|
| 700 |
+
// 登录状态管理
|
| 701 |
+
function checkLoginStatus() {
|
| 702 |
const token = localStorage.getItem('authToken');
|
| 703 |
const loginButton = document.getElementById('loginButton');
|
| 704 |
const logoutButton = document.getElementById('logoutButton');
|
| 705 |
|
| 706 |
if (token) {
|
| 707 |
+
console.log('本地存储中找到 token,尝试验证:', token.slice(0, 8) + '...');
|
| 708 |
showLoading();
|
| 709 |
+
return fetch('/api/verify-token', {
|
| 710 |
+
method: 'POST',
|
| 711 |
+
headers: {
|
| 712 |
+
'Content-Type': 'application/json',
|
| 713 |
+
},
|
| 714 |
+
body: JSON.stringify({ token })
|
| 715 |
+
})
|
| 716 |
+
.then(response => response.json())
|
| 717 |
+
.then(data => {
|
| 718 |
hideLoading();
|
| 719 |
if (data.success) {
|
| 720 |
console.log('Token 验证成功,用户已登录');
|
|
|
|
| 722 |
loginButton.style.display = 'none';
|
| 723 |
logoutButton.style.display = 'block';
|
| 724 |
updateActionButtons(true);
|
|
|
|
| 725 |
} else {
|
| 726 |
+
console.log('Token 验证失败,清除本地存储:', data.message);
|
| 727 |
localStorage.removeItem('authToken');
|
| 728 |
isLoggedIn = false;
|
| 729 |
loginButton.style.display = 'block';
|
| 730 |
logoutButton.style.display = 'none';
|
| 731 |
updateActionButtons(false);
|
|
|
|
| 732 |
}
|
| 733 |
+
return data.success;
|
| 734 |
+
})
|
| 735 |
+
.catch(error => {
|
| 736 |
hideLoading();
|
| 737 |
+
console.error('验证 token 失败,清除本地存储:', error);
|
| 738 |
localStorage.removeItem('authToken');
|
| 739 |
isLoggedIn = false;
|
| 740 |
loginButton.style.display = 'block';
|
| 741 |
logoutButton.style.display = 'none';
|
| 742 |
updateActionButtons(false);
|
| 743 |
return false;
|
| 744 |
+
});
|
| 745 |
} else {
|
| 746 |
console.log('本地存储中无 token,显示未登录状态');
|
| 747 |
isLoggedIn = false;
|
| 748 |
loginButton.style.display = 'block';
|
| 749 |
logoutButton.style.display = 'none';
|
| 750 |
updateActionButtons(false);
|
| 751 |
+
return Promise.resolve(false);
|
| 752 |
}
|
| 753 |
}
|
| 754 |
|
| 755 |
function showLoginForm() {
|
| 756 |
+
document.getElementById('loginOverlay').style.display = 'flex';
|
| 757 |
document.getElementById('username').value = '';
|
| 758 |
document.getElementById('password').value = '';
|
| 759 |
document.getElementById('loginError').style.display = 'none';
|
| 760 |
}
|
| 761 |
|
| 762 |
function hideLoginForm() {
|
| 763 |
+
document.getElementById('loginOverlay').style.display = 'none';
|
| 764 |
}
|
| 765 |
|
| 766 |
+
function login() {
|
| 767 |
const username = document.getElementById('username').value;
|
| 768 |
const password = document.getElementById('password').value;
|
| 769 |
const loginError = document.getElementById('loginError');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 770 |
showLoading();
|
| 771 |
+
fetch('/api/login', {
|
| 772 |
+
method: 'POST',
|
| 773 |
+
headers: {
|
| 774 |
+
'Content-Type': 'application/json',
|
| 775 |
+
},
|
| 776 |
+
body: JSON.stringify({ username, password })
|
| 777 |
+
})
|
| 778 |
+
.then(response => response.json())
|
| 779 |
+
.then(data => {
|
| 780 |
hideLoading();
|
| 781 |
if (data.success) {
|
| 782 |
console.log('登录成功,保存 token');
|
|
|
|
| 786 |
document.getElementById('loginButton').style.display = 'none';
|
| 787 |
document.getElementById('logoutButton').style.display = 'block';
|
| 788 |
updateActionButtons(true);
|
| 789 |
+
refreshData(); // 登录成功后刷新数据以显示所有实例包括 private
|
|
|
|
| 790 |
} else {
|
| 791 |
console.log('登录失败:', data.message);
|
| 792 |
+
loginError.textContent = data.message || '登录失败';
|
| 793 |
loginError.style.display = 'block';
|
| 794 |
}
|
| 795 |
+
})
|
| 796 |
+
.catch(error => {
|
| 797 |
hideLoading();
|
| 798 |
console.error('登录请求失败:', error);
|
| 799 |
+
loginError.textContent = '登录请求失败,请稍后重试';
|
| 800 |
loginError.style.display = 'block';
|
| 801 |
+
});
|
| 802 |
}
|
| 803 |
|
| 804 |
+
function logout() {
|
| 805 |
const token = localStorage.getItem('authToken');
|
| 806 |
if (token) {
|
| 807 |
showLoading();
|
| 808 |
+
fetch('/api/logout', {
|
| 809 |
+
method: 'POST',
|
| 810 |
+
headers: {
|
| 811 |
+
'Content-Type': 'application/json',
|
| 812 |
+
},
|
| 813 |
+
body: JSON.stringify({ token })
|
| 814 |
+
})
|
| 815 |
+
.then(response => response.json())
|
| 816 |
+
.then(data => {
|
|
|
|
| 817 |
hideLoading();
|
| 818 |
+
console.log('登出成功,清除 token');
|
| 819 |
localStorage.removeItem('authToken');
|
| 820 |
isLoggedIn = false;
|
| 821 |
document.getElementById('loginButton').style.display = 'block';
|
| 822 |
document.getElementById('logoutButton').style.display = 'none';
|
| 823 |
updateActionButtons(false);
|
| 824 |
+
refreshData(); // 登出后刷新数据以隐藏 private 实例
|
| 825 |
+
})
|
| 826 |
+
.catch(error => {
|
| 827 |
+
hideLoading();
|
| 828 |
+
console.error('登出失败,但仍清除 token:', error);
|
| 829 |
+
localStorage.removeItem('authToken');
|
| 830 |
+
isLoggedIn = false;
|
| 831 |
+
document.getElementById('loginButton').style.display = 'block';
|
| 832 |
+
document.getElementById('logoutButton').style.display = 'none';
|
| 833 |
+
updateActionButtons(false);
|
| 834 |
+
refreshData(); // 登出后刷新数据以隐藏 private 实例
|
| 835 |
+
});
|
| 836 |
} else {
|
| 837 |
+
console.log('本地无 token,直接设置为未登录');
|
| 838 |
isLoggedIn = false;
|
| 839 |
document.getElementById('loginButton').style.display = 'block';
|
| 840 |
document.getElementById('logoutButton').style.display = 'none';
|
| 841 |
updateActionButtons(false);
|
| 842 |
+
refreshData(); // 登出后刷新数据以隐藏 private 实例
|
| 843 |
}
|
| 844 |
}
|
| 845 |
|
| 846 |
function updateActionButtons(loggedIn) {
|
| 847 |
console.log('更新操作按钮状态,是否已登录:', loggedIn);
|
| 848 |
+
isLoggedIn = loggedIn;
|
| 849 |
const cards = document.querySelectorAll('.server-card');
|
| 850 |
cards.forEach(card => {
|
| 851 |
const buttons = card.querySelector('.action-buttons');
|
| 852 |
if (buttons) {
|
| 853 |
buttons.style.display = loggedIn ? 'flex' : 'none';
|
| 854 |
}
|
| 855 |
+
// 动态添加或去除 not-logged-in 类以调整卡片高度
|
| 856 |
+
if (loggedIn) {
|
| 857 |
+
card.classList.remove('not-logged-in');
|
| 858 |
+
} else {
|
| 859 |
+
card.classList.add('not-logged-in');
|
| 860 |
+
}
|
| 861 |
+
// 确保图表切换按钮总是可见,不管是否登录
|
| 862 |
+
const chartToggleButton = card.querySelector('.chart-toggle-button');
|
| 863 |
+
if (chartToggleButton) {
|
| 864 |
+
chartToggleButton.style.display = 'inline-block';
|
| 865 |
+
}
|
| 866 |
});
|
| 867 |
}
|
| 868 |
|
| 869 |
+
// 使用 window.onload 确保页面完全加载后检查登录状态
|
| 870 |
window.onload = async function() {
|
| 871 |
+
console.log('页面加载完成,开始检查登录状态');
|
| 872 |
+
await checkLoginStatus();
|
| 873 |
+
console.log('登录状态检查完成,初始化数据');
|
| 874 |
await initialize();
|
|
|
|
| 875 |
};
|
|
|
|
| 876 |
|
| 877 |
+
// 二次确认弹窗逻辑
|
| 878 |
let pendingAction = null;
|
| 879 |
let pendingRepoId = null;
|
| 880 |
|
| 881 |
function showConfirmDialog(action, repoId, title, message) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 882 |
pendingAction = action;
|
| 883 |
pendingRepoId = repoId;
|
| 884 |
document.getElementById('confirmTitle').textContent = title;
|
| 885 |
document.getElementById('confirmMessage').textContent = message;
|
| 886 |
+
document.getElementById('confirmOverlay').style.display = 'flex';
|
| 887 |
}
|
| 888 |
|
| 889 |
function confirmAction() {
|
|
|
|
| 898 |
function cancelAction() {
|
| 899 |
pendingAction = null;
|
| 900 |
pendingRepoId = null;
|
| 901 |
+
document.getElementById('confirmOverlay').style.display = 'none';
|
| 902 |
}
|
|
|
|
| 903 |
|
|
|
|
| 904 |
async function getUsernames() {
|
| 905 |
try {
|
| 906 |
+
showLoading();
|
| 907 |
const token = localStorage.getItem('authToken');
|
| 908 |
const headers = {};
|
| 909 |
if (token) {
|
| 910 |
headers['Authorization'] = `Bearer ${token}`;
|
| 911 |
+
console.log('getUsernames 请求中附加 Token:', token.slice(0, 8) + '...');
|
| 912 |
}
|
| 913 |
const response = await fetch('/api/config', { headers });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 914 |
const config = await response.json();
|
| 915 |
+
hideLoading();
|
| 916 |
const usernamesList = config.usernames ? config.usernames.split(',').map(name => name.trim()).filter(name => name) : [];
|
| 917 |
document.getElementById('totalUsers').textContent = usernamesList.length;
|
| 918 |
+
// 更新用户过滤下拉菜单
|
| 919 |
const userFilter = document.getElementById('userFilter');
|
|
|
|
| 920 |
userFilter.innerHTML = '<option value="all">全部用户</option>';
|
| 921 |
usernamesList.forEach(username => {
|
| 922 |
const option = document.createElement('option');
|
|
|
|
| 924 |
option.textContent = username;
|
| 925 |
userFilter.appendChild(option);
|
| 926 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 927 |
return usernamesList;
|
| 928 |
} catch (error) {
|
| 929 |
+
hideLoading();
|
| 930 |
+
console.error('Failed to fetch usernames:', error);
|
| 931 |
document.getElementById('totalUsers').textContent = 0;
|
|
|
|
|
|
|
| 932 |
return [];
|
| 933 |
}
|
| 934 |
}
|
| 935 |
|
| 936 |
async function fetchInstances() {
|
| 937 |
try {
|
| 938 |
+
showLoading();
|
| 939 |
const token = localStorage.getItem('authToken');
|
| 940 |
const headers = {};
|
| 941 |
if (token) {
|
| 942 |
headers['Authorization'] = `Bearer ${token}`;
|
| 943 |
+
console.log('fetchInstances 请求中附加 Token:', token.slice(0, 8) + '...');
|
| 944 |
} else {
|
| 945 |
console.log('无可用 Token,未附加 Authorization 头');
|
| 946 |
}
|
| 947 |
const response = await fetch('/api/proxy/spaces', { headers });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 948 |
const instances = await response.json();
|
| 949 |
console.log('从后端获取的实例列表:', instances);
|
| 950 |
+
hideLoading();
|
| 951 |
if (instances.length === 0) {
|
| 952 |
+
alert('未获取到实例数据,可能是网络问题或数据暂不可用。');
|
| 953 |
}
|
| 954 |
return instances;
|
| 955 |
} catch (error) {
|
| 956 |
+
hideLoading();
|
| 957 |
console.error("获取实例列表失败:", error);
|
| 958 |
+
alert('获取实例列表失败,请稍后重试。');
|
| 959 |
return [];
|
| 960 |
}
|
| 961 |
}
|
|
|
|
| 963 |
class MetricsStreamManager {
|
| 964 |
constructor() {
|
| 965 |
this.eventSource = null;
|
|
|
|
| 966 |
}
|
| 967 |
|
| 968 |
connect(subscribedInstances = []) {
|
| 969 |
+
if (this.eventSource) {
|
| 970 |
+
this.eventSource.close();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 971 |
}
|
| 972 |
|
| 973 |
const instancesParam = subscribedInstances.join(',');
|
| 974 |
+
const token = localStorage.getItem('authToken');
|
| 975 |
+
// 由于 EventSource 不支持直接设置 Authorization 头,这里通过查询参数传递 token
|
| 976 |
+
const url = `/api/proxy/live-metrics-stream?instances=${encodeURIComponent(instancesParam)}&token=${encodeURIComponent(token || '')}`;
|
| 977 |
+
console.log('SSE 连接 URL:', url.split('&token=')[0] + (token ? '&token=... (隐藏)' : '&token=空'));
|
| 978 |
this.eventSource = new EventSource(url);
|
| 979 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 980 |
this.eventSource.addEventListener("metric", (event) => {
|
| 981 |
try {
|
| 982 |
const data = JSON.parse(event.data);
|
| 983 |
const { repoId, metrics } = data;
|
| 984 |
+
updateServerCard(metrics, repoId);
|
|
|
|
|
|
|
| 985 |
} catch (error) {
|
| 986 |
+
console.error(`解析监控数据失败:`, error);
|
| 987 |
}
|
| 988 |
});
|
| 989 |
|
| 990 |
this.eventSource.onerror = (error) => {
|
| 991 |
console.error(`SSE 连接错误:`, error);
|
| 992 |
+
this.eventSource.close();
|
| 993 |
+
this.eventSource = null;
|
| 994 |
+
// 可选:尝试重新连接
|
| 995 |
+
setTimeout(() => this.connect(subscribedInstances), 5000);
|
| 996 |
};
|
| 997 |
|
| 998 |
+
console.log(`SSE 连接已建立,订阅实例: ${instancesParam || '无'}`);
|
| 999 |
}
|
| 1000 |
|
| 1001 |
disconnect() {
|
|
|
|
| 1004 |
this.eventSource = null;
|
| 1005 |
console.log(`SSE 连接已断开`);
|
| 1006 |
}
|
|
|
|
| 1007 |
}
|
| 1008 |
}
|
| 1009 |
|
| 1010 |
const metricsStreamManager = new MetricsStreamManager();
|
| 1011 |
+
const instanceMap = new Map();
|
| 1012 |
+
const serverStatus = new Map();
|
| 1013 |
+
let allInstances = []; // 存储所有实例数据,用于过滤和排序
|
| 1014 |
+
const chartInstances = new Map(); // 存储每个实例的图表实例
|
| 1015 |
|
| 1016 |
async function initialize() {
|
|
|
|
| 1017 |
await getUsernames();
|
| 1018 |
+
const instances = await fetchInstances();
|
| 1019 |
+
allInstances = instances;
|
| 1020 |
+
renderInstances(allInstances);
|
| 1021 |
+
|
| 1022 |
+
// 默认只监控状态为 running 的实例
|
| 1023 |
+
const runningInstances = instances
|
| 1024 |
+
.filter(instance => instance.status.toLowerCase() === 'running')
|
| 1025 |
+
.map(instance => instance.repo_id);
|
| 1026 |
+
|
| 1027 |
+
metricsStreamManager.connect(runningInstances);
|
| 1028 |
+
|
| 1029 |
+
updateSummary();
|
| 1030 |
+
updateActionButtons(isLoggedIn);
|
| 1031 |
+
}
|
| 1032 |
+
|
| 1033 |
+
// 手动刷新数据函数
|
| 1034 |
+
async function refreshData() {
|
| 1035 |
+
metricsStreamManager.disconnect();
|
| 1036 |
+
// 销毁所有图表实例
|
| 1037 |
chartInstances.forEach(chart => {
|
| 1038 |
if (chart) {
|
| 1039 |
chart.destroy();
|
| 1040 |
}
|
| 1041 |
});
|
| 1042 |
+
chartInstances.clear();
|
| 1043 |
+
await initialize();
|
| 1044 |
+
applyFiltersAndSort(); // 确保刷新后重新应用过滤和排序
|
| 1045 |
+
}
|
| 1046 |
+
|
| 1047 |
+
function renderInstances(instances) {
|
| 1048 |
+
const serversContainer = document.getElementById('servers');
|
| 1049 |
+
serversContainer.innerHTML = ''; // 清空现有内容
|
| 1050 |
+
const userGroups = {};
|
| 1051 |
+
|
| 1052 |
+
// 按用户分组
|
| 1053 |
+
instances.forEach(instance => {
|
| 1054 |
+
if (!userGroups[instance.owner]) {
|
| 1055 |
+
userGroups[instance.owner] = [];
|
| 1056 |
+
}
|
| 1057 |
+
userGroups[instance.owner].push(instance);
|
| 1058 |
+
});
|
| 1059 |
+
|
| 1060 |
+
// 渲染每个用户组
|
| 1061 |
+
Object.keys(userGroups).forEach(owner => {
|
| 1062 |
+
let userGroup = document.createElement('details');
|
| 1063 |
+
userGroup.className = 'user-group';
|
| 1064 |
+
userGroup.id = `user-${owner}`;
|
| 1065 |
+
userGroup.setAttribute('open', '');
|
| 1066 |
+
|
| 1067 |
+
const summary = document.createElement('summary');
|
| 1068 |
+
summary.textContent = `用户: ${owner}`;
|
| 1069 |
+
userGroup.appendChild(summary);
|
| 1070 |
+
|
| 1071 |
+
const userServers = document.createElement('div');
|
| 1072 |
+
userServers.className = 'user-servers';
|
| 1073 |
+
userGroup.appendChild(userServers);
|
| 1074 |
+
|
| 1075 |
+
serversContainer.appendChild(userGroup);
|
| 1076 |
+
|
| 1077 |
+
// 渲染该用户下的实例
|
| 1078 |
+
userGroups[owner].forEach(instance => {
|
| 1079 |
+
renderInstanceCard(instance, userServers);
|
| 1080 |
+
});
|
| 1081 |
+
});
|
| 1082 |
+
}
|
| 1083 |
+
|
| 1084 |
+
// 图表配置函数
|
| 1085 |
+
function createChart(instanceId) {
|
| 1086 |
+
const canvasId = `chart-${instanceId}`;
|
| 1087 |
+
const canvas = document.getElementById(canvasId);
|
| 1088 |
+
if (!canvas) return null;
|
| 1089 |
+
|
| 1090 |
+
// 根据当前主题设置图表样式
|
| 1091 |
+
const isDarkMode = document.documentElement.getAttribute('data-theme') === 'dark';
|
| 1092 |
+
const gridColor = isDarkMode ? 'rgba(255, 255, 255, 0.1)' : 'rgba(0, 0, 0, 0.1)';
|
| 1093 |
+
const textColor = isDarkMode ? '#fff' : '#333';
|
| 1094 |
+
|
| 1095 |
+
const ctx = canvas.getContext('2d');
|
| 1096 |
+
const chart = new Chart(ctx, {
|
| 1097 |
+
type: 'line',
|
| 1098 |
+
data: {
|
| 1099 |
+
labels: Array(30).fill(''), // 初始为空标签,最多30个数据点
|
| 1100 |
+
datasets: [
|
| 1101 |
+
{
|
| 1102 |
+
label: 'CPU 使用率 (%)',
|
| 1103 |
+
data: [],
|
| 1104 |
+
borderColor: '#4CAF50', // 绿色
|
| 1105 |
+
backgroundColor: 'rgba(76, 175, 80, 0.2)',
|
| 1106 |
+
tension: 0.4,
|
| 1107 |
+
fill: true,
|
| 1108 |
+
},
|
| 1109 |
+
{
|
| 1110 |
+
label: '内存使用率 (%)',
|
| 1111 |
+
data: [],
|
| 1112 |
+
borderColor: '#2196F3', // 蓝色
|
| 1113 |
+
backgroundColor: 'rgba(33, 150, 243, 0.2)',
|
| 1114 |
+
tension: 0.4,
|
| 1115 |
+
fill: true,
|
| 1116 |
+
},
|
| 1117 |
+
{
|
| 1118 |
+
label: '上传速度 (KB/s)',
|
| 1119 |
+
data: [],
|
| 1120 |
+
borderColor: '#F44336', // 红色
|
| 1121 |
+
backgroundColor: 'rgba(244, 67, 54, 0.2)',
|
| 1122 |
+
tension: 0.4,
|
| 1123 |
+
fill: true,
|
| 1124 |
+
},
|
| 1125 |
+
{
|
| 1126 |
+
label: '下载速度 (KB/s)',
|
| 1127 |
+
data: [],
|
| 1128 |
+
borderColor: '#FF9800', // 橙色
|
| 1129 |
+
backgroundColor: 'rgba(255, 152, 0, 0.2)',
|
| 1130 |
+
tension: 0.4,
|
| 1131 |
+
fill: true,
|
| 1132 |
+
},
|
| 1133 |
+
]
|
| 1134 |
+
},
|
| 1135 |
+
options: {
|
| 1136 |
+
responsive: true,
|
| 1137 |
+
maintainAspectRatio: false,
|
| 1138 |
+
plugins: {
|
| 1139 |
+
legend: {
|
| 1140 |
+
labels: {
|
| 1141 |
+
color: textColor,
|
| 1142 |
+
font: { size: 12 }
|
| 1143 |
+
}
|
| 1144 |
+
},
|
| 1145 |
+
tooltip: {
|
| 1146 |
+
mode: 'index',
|
| 1147 |
+
intersect: false,
|
| 1148 |
+
}
|
| 1149 |
+
},
|
| 1150 |
+
scales: {
|
| 1151 |
+
y: {
|
| 1152 |
+
beginAtZero: true,
|
| 1153 |
+
grid: { color: gridColor },
|
| 1154 |
+
ticks: {
|
| 1155 |
+
color: textColor,
|
| 1156 |
+
font: { size: 11 }
|
| 1157 |
+
}
|
| 1158 |
+
},
|
| 1159 |
+
x: {
|
| 1160 |
+
grid: { color: gridColor },
|
| 1161 |
+
ticks: {
|
| 1162 |
+
color: textColor,
|
| 1163 |
+
font: { size: 11 },
|
| 1164 |
+
maxRotation: 0,
|
| 1165 |
+
minRotation: 0,
|
| 1166 |
+
autoSkip: true,
|
| 1167 |
+
autoSkipPadding: 10
|
| 1168 |
+
}
|
| 1169 |
+
}
|
| 1170 |
+
},
|
| 1171 |
+
elements: {
|
| 1172 |
+
point: {
|
| 1173 |
+
radius: 0, // 隐藏数据点
|
| 1174 |
+
hitRadius: 5 // 确保悬停仍有效
|
| 1175 |
+
}
|
| 1176 |
+
},
|
| 1177 |
+
animation: false // 关闭动画,提升性能
|
| 1178 |
+
}
|
| 1179 |
+
});
|
| 1180 |
+
chartInstances.set(instanceId, chart);
|
| 1181 |
+
return chart;
|
| 1182 |
}
|
| 1183 |
|
| 1184 |
+
// 更新图表数据
|
| 1185 |
+
function updateChart(instanceId, data) {
|
| 1186 |
+
let chart = chartInstances.get(instanceId);
|
| 1187 |
+
if (!chart) {
|
| 1188 |
+
chart = createChart(instanceId);
|
| 1189 |
+
if (!chart) return; // 如果图表未创建成功,直接返回
|
| 1190 |
+
}
|
| 1191 |
+
|
| 1192 |
+
// 获取当前数据集
|
| 1193 |
+
const cpuData = chart.data.datasets[0].data;
|
| 1194 |
+
const memoryData = chart.data.datasets[1].data;
|
| 1195 |
+
const uploadData = chart.data.datasets[2].data;
|
| 1196 |
+
const downloadData = chart.data.datasets[3].data;
|
| 1197 |
+
|
| 1198 |
+
// 追加新数据
|
| 1199 |
+
cpuData.push(data.cpu_usage_pct);
|
| 1200 |
+
memoryData.push(((data.memory_used_bytes / data.memory_total_bytes) * 100).toFixed(2));
|
| 1201 |
+
uploadData.push((data.tx_bps / 1024).toFixed(2)); // 转换为 KB/s
|
| 1202 |
+
downloadData.push((data.rx_bps / 1024).toFixed(2)); // 转换为 KB/s
|
| 1203 |
+
|
| 1204 |
+
// 限制数据点数量为 30 个
|
| 1205 |
+
if (cpuData.length > 30) {
|
| 1206 |
+
cpuData.shift();
|
| 1207 |
+
memoryData.shift();
|
| 1208 |
+
uploadData.shift();
|
| 1209 |
+
downloadData.shift();
|
| 1210 |
+
}
|
| 1211 |
+
|
| 1212 |
+
// 更新图表
|
| 1213 |
+
chart.update();
|
| 1214 |
}
|
| 1215 |
|
| 1216 |
function renderInstanceCard(instance, container) {
|
| 1217 |
const instanceId = instance.repo_id;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1218 |
instanceMap.set(instanceId, instance);
|
| 1219 |
|
| 1220 |
const cardId = `instance-${instanceId}`;
|
|
|
|
| 1223 |
card = document.createElement('div');
|
| 1224 |
card.id = cardId;
|
| 1225 |
card.className = 'server-card';
|
| 1226 |
+
if (!isLoggedIn) {
|
| 1227 |
+
card.classList.add('not-logged-in'); // 未登录时添加类以调整高度
|
| 1228 |
+
}
|
| 1229 |
+
// 根据 instance.private 属性选择不同的图标
|
| 1230 |
+
const iconSvg = instance.private
|
| 1231 |
+
? `<svg class="server-flag" width="20" height="20" viewBox="0 0 24 24" fill="currentColor">
|
| 1232 |
+
<path d="M18 8v-3c0-1.656-1.344-3-3-3h-6c-1.656 0-3 1.344-3 3v3h-3v14h18v-14h-3zm-10-1.5c0-.828.672-1.5 1.5-1.5h5c.828 0 1.5.672 1.5 1.5v2.5h-8v-2.5zm4 11.5c-1.105 0-2-.895-2-2s.895-2 2-2 2 .895 2 2-.895 2-2 2z"/>
|
| 1233 |
+
</svg>` // 锁图标,表示 private 实例
|
| 1234 |
+
: `<svg class="server-flag" width="20" height="20" viewBox="0 0 24 24" fill="currentColor">
|
| 1235 |
+
<path d="M21 3H3C1.9 3 1 3.9 1 5v3c0 1.1.9 2 2 2h18c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-1 5H4V6h16v2zm1 4H3c-1.1 0-2 .9-2 2v3c0 1.1.9 2 2 2h18c1.1 0 2-.9 2-2v-3c0-1.1-.9-2-2-2zm-1 5H4v-2h16v2zm1 4H3c-1.1 0-2 .9-2 2v3c0 1.1.9 2 2 2h18c1.1 0 2-.9 2-2v-3c0-1.1-.9-2-2-2zm-1 5H4v-2h16v2z"/>
|
| 1236 |
+
</svg>`; // 服务器图标,表示非 private 实例
|
| 1237 |
+
|
| 1238 |
card.innerHTML = `
|
| 1239 |
<div class="server-header">
|
| 1240 |
<div class="server-name">
|
| 1241 |
+
<div class="status-dot status-sleep"></div>
|
| 1242 |
${iconSvg}
|
| 1243 |
+
<div>${instance.name} </div>
|
| 1244 |
</div>
|
| 1245 |
<div>
|
| 1246 |
<button class="chart-toggle-button" onclick="toggleChart('${instanceId}')">查看图表</button>
|
|
|
|
| 1269 |
</div>
|
| 1270 |
</div>
|
| 1271 |
<div class="action-buttons" style="display: ${isLoggedIn ? 'flex' : 'none'};">
|
| 1272 |
+
<button class="action-button view-button" onclick="viewInstance('${instance.url}')">查看</button>
|
| 1273 |
+
<button class="action-button" onclick="manageInstance('${instance.repo_id}')">管理</button>
|
| 1274 |
<button class="action-button" onclick="showConfirmDialog('restart', '${instance.repo_id}', '确认重启', '您确定要重启实例 ${instance.name} (${instance.repo_id}) 吗?')">重启</button>
|
| 1275 |
<button class="action-button" onclick="showConfirmDialog('rebuild', '${instance.repo_id}', '确认重建', '您确定要重建实例 ${instance.name} (${instance.repo_id}) 吗?')">重建</button>
|
| 1276 |
</div>
|
|
|
|
| 1279 |
</div>
|
| 1280 |
`;
|
| 1281 |
container.appendChild(card);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1282 |
}
|
| 1283 |
+
const statusDot = card.querySelector('.status-dot');
|
| 1284 |
+
const initialStatus = instance.status.toLowerCase();
|
| 1285 |
+
if (initialStatus === 'running') {
|
| 1286 |
+
statusDot.className = 'status-dot status-online';
|
| 1287 |
+
} else if (initialStatus === 'sleeping') {
|
| 1288 |
+
statusDot.className = 'status-dot status-sleep';
|
| 1289 |
+
} else {
|
| 1290 |
+
statusDot.className = 'status-dot status-offline';
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1291 |
}
|
| 1292 |
+
serverStatus.set(instanceId, { lastSeen: Date.now(), isOnline: initialStatus === 'running', isSleep: initialStatus === 'sleeping', data: null, status: instance.status });
|
| 1293 |
}
|
| 1294 |
|
| 1295 |
+
// 切换图表显示/隐藏
|
| 1296 |
+
function toggleChart(instanceId) {
|
| 1297 |
+
const card = document.getElementById(`instance-${instanceId}`);
|
| 1298 |
+
const chartContainer = document.getElementById(`chart-container-${instanceId}`);
|
| 1299 |
+
const toggleButton = card.querySelector('.chart-toggle-button');
|
| 1300 |
+
if (!card || !chartContainer) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1301 |
|
| 1302 |
+
if (card.classList.contains('expanded')) {
|
| 1303 |
+
card.classList.remove('expanded');
|
| 1304 |
+
toggleButton.textContent = '查看图表';
|
| 1305 |
+
} else {
|
| 1306 |
+
card.classList.add('expanded');
|
| 1307 |
+
toggleButton.textContent = '收起图表';
|
| 1308 |
+
// 如果图表未初始化,则创建
|
| 1309 |
+
if (!chartInstances.has(instanceId)) {
|
| 1310 |
+
createChart(instanceId);
|
| 1311 |
}
|
| 1312 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1313 |
}
|
| 1314 |
|
| 1315 |
+
function updateServerCard(data, instanceId, isSleep = false) {
|
| 1316 |
+
const cardId = `instance-${instanceId}`;
|
| 1317 |
+
let card = document.getElementById(cardId);
|
| 1318 |
const instance = instanceMap.get(instanceId);
|
| 1319 |
+
|
| 1320 |
+
if (!card && instance) {
|
| 1321 |
+
// 如果卡片不存在,但实例存在,说明可能被过滤掉了,不渲染
|
| 1322 |
return;
|
| 1323 |
}
|
| 1324 |
|
| 1325 |
+
if (card) {
|
| 1326 |
+
const statusDot = card.querySelector('.status-dot');
|
| 1327 |
+
let upload = 'N/A', download = 'N/A', cpuUsage = 'N/A', memoryUsage = 'N/A';
|
| 1328 |
+
let isOnline = false;
|
| 1329 |
+
|
| 1330 |
+
if (data) {
|
| 1331 |
+
cpuUsage = `${data.cpu_usage_pct}%`;
|
| 1332 |
+
memoryUsage = `${((data.memory_used_bytes / data.memory_total_bytes) * 100).toFixed(2)}%`;
|
| 1333 |
+
upload = `${formatBytes(data.tx_bps)}/s`;
|
| 1334 |
+
download = `${formatBytes(data.rx_bps)}/s`;
|
| 1335 |
+
statusDot.className = 'status-dot status-online';
|
| 1336 |
+
isOnline = true;
|
| 1337 |
+
isSleep = false;
|
| 1338 |
+
// 更新图表数据
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1339 |
updateChart(instanceId, data);
|
| 1340 |
+
} else {
|
| 1341 |
+
const currentStatus = instance?.status.toLowerCase() || 'unknown';
|
| 1342 |
+
if (currentStatus === 'running') {
|
| 1343 |
+
statusDot.className = 'status-dot status-online';
|
| 1344 |
+
isOnline = true;
|
| 1345 |
+
isSleep = false;
|
| 1346 |
+
} else if (currentStatus === 'sleeping') {
|
| 1347 |
+
statusDot.className = 'status-dot status-sleep';
|
| 1348 |
+
isOnline = false;
|
| 1349 |
+
isSleep = true;
|
| 1350 |
+
} else {
|
| 1351 |
+
statusDot.className = 'status-dot status-offline';
|
| 1352 |
+
isOnline = false;
|
| 1353 |
+
isSleep = false;
|
| 1354 |
+
}
|
| 1355 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1356 |
|
| 1357 |
+
card.querySelector('.cpu-usage').textContent = cpuUsage;
|
| 1358 |
+
card.querySelector('.memory-usage').textContent = memoryUsage;
|
| 1359 |
+
card.querySelector('.upload').textContent = upload;
|
| 1360 |
+
card.querySelector('.download').textContent = download;
|
|
|
|
|
|
|
|
|
|
| 1361 |
|
| 1362 |
+
serverStatus.set(instanceId, { lastSeen: Date.now(), isOnline, isSleep, data: data || null, status: instance?.status || 'unknown' });
|
| 1363 |
+
updateSummary();
|
| 1364 |
+
}
|
| 1365 |
}
|
| 1366 |
|
| 1367 |
async function restartSpace(repoId) {
|
| 1368 |
try {
|
| 1369 |
const token = localStorage.getItem('authToken');
|
| 1370 |
if (!token || !isLoggedIn) {
|
| 1371 |
+
alert('请先登录以执行此操作');
|
| 1372 |
showLoginForm();
|
| 1373 |
return;
|
| 1374 |
}
|
|
|
|
| 1376 |
const encodedRepoId = encodeURIComponent(repoId);
|
| 1377 |
const response = await fetch(`/api/proxy/restart/${encodedRepoId}`, {
|
| 1378 |
method: 'POST',
|
| 1379 |
+
headers: {
|
| 1380 |
+
'Authorization': `Bearer ${token}`
|
| 1381 |
+
}
|
| 1382 |
});
|
| 1383 |
const result = await response.json();
|
| 1384 |
hideLoading();
|
| 1385 |
if (result.success) {
|
| 1386 |
+
alert(`重启成功: ${repoId}`);
|
| 1387 |
+
// 操作成功后立即刷新数据
|
| 1388 |
refreshData();
|
| 1389 |
} else {
|
| 1390 |
if (response.status === 401) {
|
| 1391 |
+
alert('登录已过期,请重新登录');
|
| 1392 |
localStorage.removeItem('authToken');
|
| 1393 |
isLoggedIn = false;
|
| 1394 |
document.getElementById('loginButton').style.display = 'block';
|
|
|
|
| 1396 |
updateActionButtons(false);
|
| 1397 |
showLoginForm();
|
| 1398 |
} else {
|
| 1399 |
+
alert(`重启失败: ${result.error || '未知错误'}`);
|
| 1400 |
console.error(`重启失败 (${repoId}):`, result.error, result.details);
|
| 1401 |
}
|
| 1402 |
}
|
| 1403 |
} catch (error) {
|
| 1404 |
hideLoading();
|
| 1405 |
+
console.error(`重启失败 (${repoId}):`, error);
|
| 1406 |
+
alert(`重启失败: ${error.message}`);
|
| 1407 |
}
|
| 1408 |
}
|
| 1409 |
|
|
|
|
| 1411 |
try {
|
| 1412 |
const token = localStorage.getItem('authToken');
|
| 1413 |
if (!token || !isLoggedIn) {
|
| 1414 |
+
alert('请先登录以执行此操作');
|
| 1415 |
showLoginForm();
|
| 1416 |
return;
|
| 1417 |
}
|
|
|
|
| 1419 |
const encodedRepoId = encodeURIComponent(repoId);
|
| 1420 |
const response = await fetch(`/api/proxy/rebuild/${encodedRepoId}`, {
|
| 1421 |
method: 'POST',
|
| 1422 |
+
headers: {
|
| 1423 |
+
'Authorization': `Bearer ${token}`
|
| 1424 |
+
}
|
| 1425 |
});
|
| 1426 |
const result = await response.json();
|
| 1427 |
hideLoading();
|
| 1428 |
if (result.success) {
|
| 1429 |
+
alert(`重建成功: ${repoId}`);
|
| 1430 |
+
// 操作成功后立即刷新数据
|
| 1431 |
refreshData();
|
| 1432 |
} else {
|
| 1433 |
if (response.status === 401) {
|
| 1434 |
+
alert('登录已过期,请重新登录');
|
| 1435 |
localStorage.removeItem('authToken');
|
| 1436 |
isLoggedIn = false;
|
| 1437 |
document.getElementById('loginButton').style.display = 'block';
|
|
|
|
| 1439 |
updateActionButtons(false);
|
| 1440 |
showLoginForm();
|
| 1441 |
} else {
|
| 1442 |
+
alert(`重建失败: ${result.error || '未知错误'}`);
|
| 1443 |
console.error(`重建失败 (${repoId}):`, result.error, result.details);
|
| 1444 |
}
|
| 1445 |
}
|
| 1446 |
} catch (error) {
|
| 1447 |
hideLoading();
|
| 1448 |
+
console.error(`重建失败 (${repoId}):`, error);
|
| 1449 |
+
alert(`重建失败: ${error.message}`);
|
| 1450 |
}
|
| 1451 |
}
|
| 1452 |
|
| 1453 |
function updateSummary() {
|
| 1454 |
let online = 0;
|
| 1455 |
let offline = 0;
|
| 1456 |
+
let totalUpload = 0;
|
| 1457 |
+
let totalDownload = 0;
|
| 1458 |
|
| 1459 |
serverStatus.forEach((status, instanceId) => {
|
| 1460 |
+
const isRecentlyOnline = status.isOnline || status.status.toLowerCase() === 'running';
|
| 1461 |
+
if (isRecentlyOnline) {
|
| 1462 |
online++;
|
| 1463 |
if (status.data) {
|
| 1464 |
+
totalUpload += parseFloat(status.data.tx_bps) || 0;
|
| 1465 |
+
totalDownload += parseFloat(status.data.rx_bps) || 0;
|
| 1466 |
}
|
| 1467 |
} else {
|
| 1468 |
offline++;
|
| 1469 |
}
|
| 1470 |
});
|
| 1471 |
|
| 1472 |
+
document.getElementById('totalServers').textContent = serverStatus.size;
|
| 1473 |
document.getElementById('onlineServers').textContent = online;
|
| 1474 |
document.getElementById('offlineServers').textContent = offline;
|
| 1475 |
+
document.getElementById('totalUpload').textContent = `${formatBytes(totalUpload)}/s`;
|
| 1476 |
+
document.getElementById('totalDownload').textContent = `${formatBytes(totalDownload)}/s`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1477 |
}
|
| 1478 |
|
| 1479 |
+
function formatBytes(bytes) {
|
|
|
|
| 1480 |
if (bytes === 0) return '0 B';
|
| 1481 |
+
const k = 1024;
|
| 1482 |
+
const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
|
| 1483 |
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
| 1484 |
+
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
|
| 1485 |
}
|
| 1486 |
|
| 1487 |
+
setInterval(updateSummary, 5000);
|
| 1488 |
+
|
| 1489 |
setInterval(async () => {
|
| 1490 |
+
metricsStreamManager.disconnect();
|
| 1491 |
+
await initialize();
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1492 |
}, 300000);
|
| 1493 |
|
| 1494 |
+
// 应用过滤和排序
|
| 1495 |
function applyFiltersAndSort() {
|
| 1496 |
const statusFilter = document.getElementById('statusFilter').value;
|
| 1497 |
const userFilter = document.getElementById('userFilter').value;
|
| 1498 |
const sortBy = document.getElementById('sortBy').value;
|
| 1499 |
|
| 1500 |
+
// 过滤实例
|
| 1501 |
+
let filteredInstances = allInstances;
|
| 1502 |
+
if (statusFilter !== 'all') {
|
| 1503 |
+
filteredInstances = filteredInstances.filter(instance => instance.status.toLowerCase() === statusFilter);
|
| 1504 |
+
}
|
| 1505 |
+
if (userFilter !== 'all') {
|
| 1506 |
+
filteredInstances = filteredInstances.filter(instance => instance.owner === userFilter);
|
| 1507 |
+
}
|
| 1508 |
|
| 1509 |
+
// 排序实例
|
| 1510 |
filteredInstances.sort((a, b) => {
|
| 1511 |
if (sortBy === 'name-asc') {
|
| 1512 |
return a.name.localeCompare(b.name);
|
| 1513 |
} else if (sortBy === 'name-desc') {
|
| 1514 |
return b.name.localeCompare(a.name);
|
| 1515 |
} else if (sortBy === 'status-asc') {
|
| 1516 |
+
const statusOrder = { 'running': 0, 'sleeping': 1, 'stopped': 2 };
|
| 1517 |
+
return statusOrder[a.status.toLowerCase()] - statusOrder[b.status.toLowerCase()];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1518 |
} else if (sortBy === 'status-desc') {
|
| 1519 |
+
const statusOrder = { 'running': 2, 'sleeping': 1, 'stopped': 0 };
|
| 1520 |
+
return statusOrder[a.status.toLowerCase()] - statusOrder[b.status.toLowerCase()];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1521 |
}
|
| 1522 |
return 0;
|
| 1523 |
});
|
| 1524 |
|
| 1525 |
+
// 重新渲染过滤和排序后的实例
|
| 1526 |
+
instanceMap.clear();
|
| 1527 |
+
serverStatus.clear();
|
| 1528 |
+
metricsStreamManager.disconnect();
|
| 1529 |
+
// 销毁现有图表实例
|
| 1530 |
+
chartInstances.forEach(chart => {
|
| 1531 |
+
if (chart) {
|
| 1532 |
+
chart.destroy();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1533 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1534 |
});
|
| 1535 |
+
chartInstances.clear();
|
| 1536 |
+
renderInstances(filteredInstances);
|
| 1537 |
+
|
| 1538 |
+
// 默认监控状态为 running 的实例
|
| 1539 |
+
const runningInstances = filteredInstances
|
| 1540 |
+
.filter(instance => instance.status.toLowerCase() === 'running')
|
| 1541 |
+
.map(instance => instance.repo_id);
|
| 1542 |
+
metricsStreamManager.connect(runningInstances);
|
| 1543 |
+
|
| 1544 |
+
updateSummary();
|
| 1545 |
+
updateActionButtons(isLoggedIn);
|
| 1546 |
}
|
| 1547 |
|
| 1548 |
+
// 新增函数:在新标签页中打开实例的URL
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1549 |
function viewInstance(url) {
|
| 1550 |
+
window.open(url, '_blank');
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1551 |
}
|
| 1552 |
|
| 1553 |
+
// 新增函数:在新标签页中打开实例的管理页面
|
| 1554 |
function manageInstance(repoId) {
|
| 1555 |
const manageUrl = `https://huggingface.co/spaces/${repoId}`;
|
| 1556 |
window.open(manageUrl, '_blank');
|
| 1557 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1558 |
</script>
|
| 1559 |
</body>
|
| 1560 |
</html>
|