|
@@ -0,0 +1,3474 @@
|
|
|
+<!DOCTYPE html>
|
|
|
+<html lang="zh-CN">
|
|
|
+<head>
|
|
|
+ <meta charset="UTF-8">
|
|
|
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
+ <title>Docker 镜像代理加速 - 管理面板</title>
|
|
|
+ <link rel="icon" href="https://cdn.jsdelivr.net/gh/dqzboy/Blog-Image/BlogCourse/docker-proxy.png" type="image/png">
|
|
|
+ <!-- 引入前端样式表 -->
|
|
|
+ <link rel="stylesheet" href="style.css">
|
|
|
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/css/editormd.min.css">
|
|
|
+ <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script>
|
|
|
+ <script src="https://cdn.jsdelivr.net/npm/[email protected]/editormd.min.js"></script>
|
|
|
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
|
|
+ <style>
|
|
|
+ /* 管理面板特定样式 */
|
|
|
+ .admin-container {
|
|
|
+ display: flex;
|
|
|
+ min-height: 100vh;
|
|
|
+ background-color: var(--background-color);
|
|
|
+ }
|
|
|
+
|
|
|
+ .sidebar {
|
|
|
+ width: 280px;
|
|
|
+ background-color: var(--container-bg);
|
|
|
+ box-shadow: var(--shadow-md);
|
|
|
+ padding: 1.5rem 0;
|
|
|
+ z-index: 10;
|
|
|
+ transition: all 0.3s ease;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 用户信息部分样式 */
|
|
|
+ .user-profile {
|
|
|
+ padding: 1rem 1.5rem;
|
|
|
+ margin-bottom: 1.5rem;
|
|
|
+ display: flex;
|
|
|
+ flex-direction: column;
|
|
|
+ align-items: center;
|
|
|
+ position: relative;
|
|
|
+ }
|
|
|
+
|
|
|
+ .user-avatar {
|
|
|
+ width: 70px;
|
|
|
+ height: 70px;
|
|
|
+ border-radius: 50%;
|
|
|
+ background-color: var(--primary-light);
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: center;
|
|
|
+ font-size: 1.8rem;
|
|
|
+ color: var(--primary-color);
|
|
|
+ margin-bottom: 0.8rem;
|
|
|
+ box-shadow: var(--shadow-sm);
|
|
|
+ }
|
|
|
+
|
|
|
+ .user-info {
|
|
|
+ text-align: center;
|
|
|
+ margin-bottom: 0.5rem;
|
|
|
+ }
|
|
|
+
|
|
|
+ .user-name {
|
|
|
+ font-weight: 600;
|
|
|
+ font-size: 1.1rem;
|
|
|
+ color: var(--text-primary);
|
|
|
+ margin-bottom: 0.25rem;
|
|
|
+ }
|
|
|
+
|
|
|
+ .user-role {
|
|
|
+ color: var(--text-secondary);
|
|
|
+ font-size: 0.85rem;
|
|
|
+ margin-bottom: 0.5rem;
|
|
|
+ }
|
|
|
+
|
|
|
+ .user-actions {
|
|
|
+ display: flex;
|
|
|
+ gap: 0.5rem;
|
|
|
+ margin-top: 0.5rem;
|
|
|
+ }
|
|
|
+
|
|
|
+ .user-action-btn {
|
|
|
+ padding: 0.4rem 0.8rem;
|
|
|
+ font-size: 0.85rem;
|
|
|
+ border-radius: var(--radius-sm);
|
|
|
+ background-color: rgba(61, 124, 244, 0.1);
|
|
|
+ color: var(--primary-color);
|
|
|
+ cursor: pointer;
|
|
|
+ transition: all var(--transition-fast);
|
|
|
+ }
|
|
|
+
|
|
|
+ .user-action-btn:hover {
|
|
|
+ background-color: var(--primary-color);
|
|
|
+ color: white;
|
|
|
+ }
|
|
|
+
|
|
|
+ .user-action-btn.logout {
|
|
|
+ background-color: rgba(255, 82, 82, 0.1);
|
|
|
+ color: var(--danger-color);
|
|
|
+ }
|
|
|
+
|
|
|
+ .user-action-btn.logout:hover {
|
|
|
+ background-color: var(--danger-color);
|
|
|
+ color: white;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 仪表盘卡片样式 */
|
|
|
+ .dashboard-grid {
|
|
|
+ display: grid;
|
|
|
+ grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
|
|
+ gap: 1.5rem;
|
|
|
+ margin-bottom: 2rem;
|
|
|
+ }
|
|
|
+
|
|
|
+ .dashboard-card {
|
|
|
+ background-color: var(--container-bg);
|
|
|
+ border-radius: var(--radius-md);
|
|
|
+ box-shadow: var(--shadow-sm);
|
|
|
+ padding: 1.5rem;
|
|
|
+ transition: all var(--transition-fast);
|
|
|
+ border: 1px solid var(--border-light);
|
|
|
+ position: relative;
|
|
|
+ overflow: hidden;
|
|
|
+ }
|
|
|
+
|
|
|
+ .dashboard-card:hover {
|
|
|
+ transform: translateY(-5px);
|
|
|
+ box-shadow: var(--shadow-md);
|
|
|
+ border-color: var(--primary-light);
|
|
|
+ }
|
|
|
+
|
|
|
+ .dashboard-card::before {
|
|
|
+ content: '';
|
|
|
+ position: absolute;
|
|
|
+ top: 0;
|
|
|
+ left: 0;
|
|
|
+ width: 4px;
|
|
|
+ height: 100%;
|
|
|
+ background-color: var(--primary-color);
|
|
|
+ }
|
|
|
+
|
|
|
+ .card-icon {
|
|
|
+ width: 50px;
|
|
|
+ height: 50px;
|
|
|
+ border-radius: 12px;
|
|
|
+ background-color: rgba(61, 124, 244, 0.1);
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: center;
|
|
|
+ margin-bottom: 1rem;
|
|
|
+ color: var(--primary-color);
|
|
|
+ font-size: 1.4rem;
|
|
|
+ }
|
|
|
+
|
|
|
+ .card-title {
|
|
|
+ font-size: 1.1rem;
|
|
|
+ font-weight: 600;
|
|
|
+ margin-bottom: 0.5rem;
|
|
|
+ color: var(--text-primary);
|
|
|
+ }
|
|
|
+
|
|
|
+ .card-value {
|
|
|
+ font-size: 1.8rem;
|
|
|
+ font-weight: 700;
|
|
|
+ color: var(--text-primary);
|
|
|
+ margin-bottom: 0.5rem;
|
|
|
+ }
|
|
|
+
|
|
|
+ .card-description {
|
|
|
+ color: var(--text-secondary);
|
|
|
+ font-size: 0.9rem;
|
|
|
+ margin-bottom: 1rem;
|
|
|
+ }
|
|
|
+
|
|
|
+ .card-footer {
|
|
|
+ display: flex;
|
|
|
+ justify-content: space-between;
|
|
|
+ align-items: center;
|
|
|
+ border-top: 1px solid var(--border-light);
|
|
|
+ padding-top: 1rem;
|
|
|
+ margin-top: 0.5rem;
|
|
|
+ }
|
|
|
+
|
|
|
+ .trend {
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ gap: 0.3rem;
|
|
|
+ font-size: 0.9rem;
|
|
|
+ }
|
|
|
+
|
|
|
+ .trend.up {
|
|
|
+ color: var(--success-color);
|
|
|
+ }
|
|
|
+
|
|
|
+ .trend.down {
|
|
|
+ color: var(--danger-color);
|
|
|
+ }
|
|
|
+
|
|
|
+ .card-action {
|
|
|
+ color: var(--primary-color);
|
|
|
+ font-size: 0.9rem;
|
|
|
+ font-weight: 500;
|
|
|
+ cursor: pointer;
|
|
|
+ }
|
|
|
+
|
|
|
+ .welcome-banner {
|
|
|
+ background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
|
|
|
+ border-radius: var(--radius-lg);
|
|
|
+ padding: 2rem;
|
|
|
+ margin-bottom: 2rem;
|
|
|
+ color: white;
|
|
|
+ position: relative;
|
|
|
+ overflow: hidden;
|
|
|
+ box-shadow: var(--shadow-md);
|
|
|
+ }
|
|
|
+
|
|
|
+ .welcome-content {
|
|
|
+ position: relative;
|
|
|
+ z-index: 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ .welcome-title {
|
|
|
+ font-size: 1.8rem;
|
|
|
+ margin-bottom: 0.5rem;
|
|
|
+ font-weight: 600;
|
|
|
+ }
|
|
|
+
|
|
|
+ .welcome-subtitle {
|
|
|
+ font-size: 1rem;
|
|
|
+ margin-bottom: 1.5rem;
|
|
|
+ opacity: 0.9;
|
|
|
+ }
|
|
|
+
|
|
|
+ .welcome-action {
|
|
|
+ background-color: rgba(255, 255, 255, 0.2);
|
|
|
+ color: white;
|
|
|
+ border: none;
|
|
|
+ padding: 0.75rem 1.5rem;
|
|
|
+ border-radius: var(--radius-md);
|
|
|
+ font-weight: 500;
|
|
|
+ cursor: pointer;
|
|
|
+ transition: all var(--transition-fast);
|
|
|
+ display: inline-flex;
|
|
|
+ align-items: center;
|
|
|
+ gap: 0.5rem;
|
|
|
+ }
|
|
|
+
|
|
|
+ .welcome-action:hover {
|
|
|
+ background-color: rgba(255, 255, 255, 0.3);
|
|
|
+ transform: translateY(-2px);
|
|
|
+ }
|
|
|
+
|
|
|
+ .welcome-banner::after {
|
|
|
+ content: '';
|
|
|
+ position: absolute;
|
|
|
+ top: -50%;
|
|
|
+ right: -10%;
|
|
|
+ width: 300px;
|
|
|
+ height: 300px;
|
|
|
+ background: rgba(255, 255, 255, 0.1);
|
|
|
+ border-radius: 50%;
|
|
|
+ }
|
|
|
+
|
|
|
+ .welcome-banner::before {
|
|
|
+ content: '';
|
|
|
+ position: absolute;
|
|
|
+ bottom: -30%;
|
|
|
+ left: -5%;
|
|
|
+ width: 200px;
|
|
|
+ height: 200px;
|
|
|
+ background: rgba(255, 255, 255, 0.1);
|
|
|
+ border-radius: 50%;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 用户中心样式 */
|
|
|
+ .user-center-header {
|
|
|
+ display: flex;
|
|
|
+ justify-content: space-between;
|
|
|
+ align-items: center;
|
|
|
+ margin-bottom: 2rem;
|
|
|
+ }
|
|
|
+
|
|
|
+ .user-center-title {
|
|
|
+ font-size: 1.8rem;
|
|
|
+ font-weight: 600;
|
|
|
+ color: var(--text-primary);
|
|
|
+ }
|
|
|
+
|
|
|
+ .user-center-subtitle {
|
|
|
+ color: var(--text-secondary);
|
|
|
+ margin-top: 0.5rem;
|
|
|
+ }
|
|
|
+
|
|
|
+ .user-center-card {
|
|
|
+ background-color: var(--container-bg);
|
|
|
+ border-radius: var(--radius-lg);
|
|
|
+ box-shadow: var(--shadow-md);
|
|
|
+ padding: 2rem;
|
|
|
+ margin-bottom: 2rem;
|
|
|
+ }
|
|
|
+
|
|
|
+ .user-center-section {
|
|
|
+ margin-bottom: 2rem;
|
|
|
+ }
|
|
|
+
|
|
|
+ .user-center-section-title {
|
|
|
+ font-size: 1.3rem;
|
|
|
+ font-weight: 600;
|
|
|
+ margin-bottom: 1.5rem;
|
|
|
+ color: var(--text-primary);
|
|
|
+ position: relative;
|
|
|
+ padding-bottom: 0.75rem;
|
|
|
+ }
|
|
|
+
|
|
|
+ .user-center-section-title::after {
|
|
|
+ content: '';
|
|
|
+ position: absolute;
|
|
|
+ bottom: 0;
|
|
|
+ left: 0;
|
|
|
+ width: 60px;
|
|
|
+ height: 2px;
|
|
|
+ background: var(--primary-color);
|
|
|
+ border-radius: 2px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .user-stats {
|
|
|
+ display: grid;
|
|
|
+ grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
|
|
|
+ gap: 1.5rem;
|
|
|
+ margin-bottom: 2rem;
|
|
|
+ }
|
|
|
+
|
|
|
+ .stat-card {
|
|
|
+ background-color: var(--container-bg);
|
|
|
+ border-radius: var(--radius-md);
|
|
|
+ box-shadow: var(--shadow-sm);
|
|
|
+ padding: 1.5rem;
|
|
|
+ border: 1px solid var(--border-light);
|
|
|
+ text-align: center;
|
|
|
+ }
|
|
|
+
|
|
|
+ .stat-value {
|
|
|
+ font-size: 2rem;
|
|
|
+ font-weight: 700;
|
|
|
+ color: var(--primary-color);
|
|
|
+ margin-bottom: 0.5rem;
|
|
|
+ }
|
|
|
+
|
|
|
+ .stat-label {
|
|
|
+ color: var(--text-secondary);
|
|
|
+ font-size: 0.9rem;
|
|
|
+ }
|
|
|
+
|
|
|
+ .sidebar h2 {
|
|
|
+ color: var(--text-primary);
|
|
|
+ padding: 0 1.5rem;
|
|
|
+ margin-bottom: 2rem;
|
|
|
+ font-size: 1.3rem;
|
|
|
+ font-weight: 600;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ gap: 0.75rem;
|
|
|
+ position: relative;
|
|
|
+ }
|
|
|
+
|
|
|
+ .sidebar h2::after {
|
|
|
+ content: '';
|
|
|
+ position: absolute;
|
|
|
+ bottom: -10px;
|
|
|
+ left: 1.5rem;
|
|
|
+ right: 1.5rem;
|
|
|
+ height: 1px;
|
|
|
+ background: linear-gradient(to right, var(--primary-light), transparent);
|
|
|
+ }
|
|
|
+
|
|
|
+ .sidebar h2 i {
|
|
|
+ color: var(--primary-color);
|
|
|
+ font-size: 1.5rem;
|
|
|
+ }
|
|
|
+
|
|
|
+ .sidebar ul {
|
|
|
+ list-style: none;
|
|
|
+ padding: 0;
|
|
|
+ margin: 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ .sidebar li {
|
|
|
+ padding: 1rem 1.5rem;
|
|
|
+ cursor: pointer;
|
|
|
+ transition: all var(--transition-fast);
|
|
|
+ color: var(--text-secondary);
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ gap: 1rem;
|
|
|
+ font-weight: 500;
|
|
|
+ margin: 0.25rem 0;
|
|
|
+ border-left: 3px solid transparent;
|
|
|
+ }
|
|
|
+
|
|
|
+ .sidebar li:hover {
|
|
|
+ background-color: rgba(61, 124, 244, 0.08);
|
|
|
+ color: var(--primary-color);
|
|
|
+ }
|
|
|
+
|
|
|
+ .sidebar li.active {
|
|
|
+ background-color: rgba(61, 124, 244, 0.1);
|
|
|
+ color: var(--primary-color);
|
|
|
+ border-left: 3px solid var(--primary-color);
|
|
|
+ font-weight: 600;
|
|
|
+ }
|
|
|
+
|
|
|
+ .sidebar li i {
|
|
|
+ font-size: 1.2rem;
|
|
|
+ width: 1.5rem;
|
|
|
+ text-align: center;
|
|
|
+ }
|
|
|
+
|
|
|
+ .content-area {
|
|
|
+ flex: 1;
|
|
|
+ padding: 2rem;
|
|
|
+ overflow-y: auto;
|
|
|
+ background: linear-gradient(135deg, var(--background-color) 0%, rgba(247, 250, 255, 0.8) 100%);
|
|
|
+ }
|
|
|
+
|
|
|
+ .content-section {
|
|
|
+ background-color: var(--container-bg);
|
|
|
+ border-radius: var(--radius-lg);
|
|
|
+ box-shadow: var(--shadow-md);
|
|
|
+ padding: 2rem;
|
|
|
+ margin-bottom: 1.5rem;
|
|
|
+ display: none;
|
|
|
+ transform: translateY(10px);
|
|
|
+ opacity: 0;
|
|
|
+ transition: transform 0.3s ease, opacity 0.3s ease;
|
|
|
+ }
|
|
|
+
|
|
|
+ .content-section.active {
|
|
|
+ display: block;
|
|
|
+ transform: translateY(0);
|
|
|
+ opacity: 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ .admin-title {
|
|
|
+ color: var(--text-primary);
|
|
|
+ font-size: 1.6rem;
|
|
|
+ font-weight: 600;
|
|
|
+ margin-bottom: 2rem;
|
|
|
+ padding-bottom: 1rem;
|
|
|
+ border-bottom: 1px solid var(--border-light);
|
|
|
+ position: relative;
|
|
|
+ }
|
|
|
+
|
|
|
+ .admin-title::after {
|
|
|
+ content: '';
|
|
|
+ position: absolute;
|
|
|
+ bottom: -1px;
|
|
|
+ left: 0;
|
|
|
+ width: 80px;
|
|
|
+ height: 3px;
|
|
|
+ background: var(--primary-color);
|
|
|
+ border-radius: 2px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .menu-label {
|
|
|
+ color: var(--text-primary);
|
|
|
+ font-size: 1.4rem;
|
|
|
+ font-weight: 600;
|
|
|
+ margin-bottom: 1.5rem;
|
|
|
+ position: relative;
|
|
|
+ padding-bottom: 0.5rem;
|
|
|
+ }
|
|
|
+
|
|
|
+ .menu-label::after {
|
|
|
+ content: '';
|
|
|
+ position: absolute;
|
|
|
+ bottom: 0;
|
|
|
+ left: 0;
|
|
|
+ width: 60px;
|
|
|
+ height: 2px;
|
|
|
+ background: var(--primary-color);
|
|
|
+ border-radius: 2px;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 表单元素样式 */
|
|
|
+ .content-section input[type="text"],
|
|
|
+ .content-section input[type="url"],
|
|
|
+ .content-section input[type="password"],
|
|
|
+ .content-section input[type="number"],
|
|
|
+ .content-section select {
|
|
|
+ width: 100%;
|
|
|
+ max-width: 500px;
|
|
|
+ padding: 0.9rem 1rem;
|
|
|
+ border: 1px solid var(--border-color);
|
|
|
+ border-radius: var(--radius-md);
|
|
|
+ background-color: var(--container-bg);
|
|
|
+ color: var(--text-primary);
|
|
|
+ font-size: 0.95rem;
|
|
|
+ margin-bottom: 1.2rem;
|
|
|
+ transition: all var(--transition-fast);
|
|
|
+ box-shadow: var(--shadow-sm);
|
|
|
+ }
|
|
|
+
|
|
|
+ .content-section input:focus,
|
|
|
+ .content-section select:focus {
|
|
|
+ border-color: var(--primary-color);
|
|
|
+ box-shadow: 0 0 0 3px rgba(61, 124, 244, 0.2);
|
|
|
+ outline: none;
|
|
|
+ }
|
|
|
+
|
|
|
+ .content-section button {
|
|
|
+ background-color: var(--primary-color);
|
|
|
+ color: white;
|
|
|
+ border: none;
|
|
|
+ padding: 0.9rem 1.4rem;
|
|
|
+ border-radius: var(--radius-md);
|
|
|
+ cursor: pointer;
|
|
|
+ font-size: 0.95rem;
|
|
|
+ font-weight: 500;
|
|
|
+ transition: all var(--transition-fast);
|
|
|
+ margin-top: 0.5rem;
|
|
|
+ margin-right: 0.5rem;
|
|
|
+ display: inline-flex;
|
|
|
+ align-items: center;
|
|
|
+ gap: 0.5rem;
|
|
|
+ }
|
|
|
+
|
|
|
+ .content-section button:hover {
|
|
|
+ background-color: var(--primary-dark);
|
|
|
+ transform: translateY(-2px);
|
|
|
+ box-shadow: var(--shadow-md);
|
|
|
+ }
|
|
|
+
|
|
|
+ .content-section button:active {
|
|
|
+ transform: translateY(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ .content-section label {
|
|
|
+ display: block;
|
|
|
+ margin-bottom: 0.5rem;
|
|
|
+ color: var(--text-primary);
|
|
|
+ font-weight: 500;
|
|
|
+ font-size: 1rem;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 表格样式 */
|
|
|
+ .content-section table {
|
|
|
+ width: 100%;
|
|
|
+ border-collapse: separate;
|
|
|
+ border-spacing: 0;
|
|
|
+ margin-top: 1.5rem;
|
|
|
+ margin-bottom: 2rem;
|
|
|
+ border-radius: var (--radius-md);
|
|
|
+ overflow: hidden;
|
|
|
+ box-shadow: var(--shadow-sm);
|
|
|
+ }
|
|
|
+
|
|
|
+ .content-section th {
|
|
|
+ background-color: var(--primary-color);
|
|
|
+ color: white;
|
|
|
+ font-weight: 500;
|
|
|
+ text-align: left;
|
|
|
+ padding: 1.2rem 1.5rem;
|
|
|
+ }
|
|
|
+
|
|
|
+ .content-section td {
|
|
|
+ padding: 1rem 1.5rem;
|
|
|
+ border-bottom: 1px solid var(--border-light);
|
|
|
+ vertical-align: middle;
|
|
|
+ }
|
|
|
+
|
|
|
+ .content-section tr:last-child td {
|
|
|
+ border-bottom: none;
|
|
|
+ }
|
|
|
+
|
|
|
+ .content-section tr:hover td {
|
|
|
+ background-color: rgba(61, 124, 244, 0.05);
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 操作按钮样式 */
|
|
|
+ .action-btn {
|
|
|
+ background-color: var(--primary-color);
|
|
|
+ color: white;
|
|
|
+ border: none;
|
|
|
+ padding: 0.6rem 0.9rem;
|
|
|
+ border-radius: var(--radius-sm);
|
|
|
+ cursor: pointer;
|
|
|
+ font-size: 0.9rem;
|
|
|
+ margin-right: 0.5rem;
|
|
|
+ transition: all var(--transition-fast);
|
|
|
+ display: inline-flex;
|
|
|
+ align-items: center;
|
|
|
+ gap: 0.25rem;
|
|
|
+ }
|
|
|
+
|
|
|
+ .action-btn:hover {
|
|
|
+ background-color: var(--primary-dark);
|
|
|
+ transform: translateY(-2px);
|
|
|
+ box-shadow: var(--shadow-sm);
|
|
|
+ }
|
|
|
+
|
|
|
+ .action-btn:active {
|
|
|
+ transform: translateY(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ .edit-btn {
|
|
|
+ background-color: var(--primary-color);
|
|
|
+ }
|
|
|
+
|
|
|
+ .edit-btn:before {
|
|
|
+ content: "\f044";
|
|
|
+ font-family: "Font Awesome 6 Free";
|
|
|
+ font-weight: 900;
|
|
|
+ }
|
|
|
+
|
|
|
+ .delete-btn {
|
|
|
+ background-color: var(--danger-color);
|
|
|
+ }
|
|
|
+
|
|
|
+ .delete-btn:before {
|
|
|
+ content: "\f2ed";
|
|
|
+ font-family: "Font Awesome 6 Free";
|
|
|
+ font-weight: 900;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 登录模态框 */
|
|
|
+ .login-modal {
|
|
|
+ display: flex;
|
|
|
+ position: fixed;
|
|
|
+ z-index: 1000;
|
|
|
+ left: 0;
|
|
|
+ top: 0;
|
|
|
+ width: 100%;
|
|
|
+ height: 100%;
|
|
|
+ overflow: auto;
|
|
|
+ background: url('https://images.unsplash.com/photo-1517694712202-14dd9538aa97?q=80&w=1470&auto=format&fit=crop') center/cover no-repeat;
|
|
|
+ justify-content: center;
|
|
|
+ align-items: center;
|
|
|
+ animation: fadeIn 0.5s ease-in-out;
|
|
|
+ }
|
|
|
+
|
|
|
+ .login-modal::before {
|
|
|
+ content: '';
|
|
|
+ position: absolute;
|
|
|
+ top: 0;
|
|
|
+ left: 0;
|
|
|
+ width: 100%;
|
|
|
+ height: 100%;
|
|
|
+ background: linear-gradient(135deg, rgba(26, 35, 126, 0.85) 0%, rgba(61, 124, 244, 0.85) 100%);
|
|
|
+ backdrop-filter: blur(5px);
|
|
|
+ }
|
|
|
+
|
|
|
+ .login-content {
|
|
|
+ background-color: var(--container-bg);
|
|
|
+ padding: 2.5rem;
|
|
|
+ border-radius: var(--radius-lg);
|
|
|
+ width: 380px;
|
|
|
+ box-shadow: var(--shadow-lg);
|
|
|
+ position: relative;
|
|
|
+ animation: slideUp 0.5s ease-out;
|
|
|
+ border: 1px solid rgba(255, 255, 255, 0.2);
|
|
|
+ }
|
|
|
+
|
|
|
+ @keyframes fadeIn {
|
|
|
+ from { opacity: 0; }
|
|
|
+ to { opacity: 1; }
|
|
|
+ }
|
|
|
+
|
|
|
+ @keyframes slideUp {
|
|
|
+ from { transform: translateY(30px); opacity: 0; }
|
|
|
+ to { transform: translateY(0); opacity: 1; }
|
|
|
+ }
|
|
|
+
|
|
|
+ .login-header h2 {
|
|
|
+ color: var(--text-primary);
|
|
|
+ font-size: 1.8rem;
|
|
|
+ margin-bottom: 2rem;
|
|
|
+ text-align: center;
|
|
|
+ font-weight: 600;
|
|
|
+ position: relative;
|
|
|
+ padding-bottom: 1rem;
|
|
|
+ }
|
|
|
+
|
|
|
+ .login-header h2::after {
|
|
|
+ content: '';
|
|
|
+ position: absolute;
|
|
|
+ bottom: 0;
|
|
|
+ left: 50%;
|
|
|
+ transform: translateX(-50%);
|
|
|
+ width: 50px;
|
|
|
+ height: 2px;
|
|
|
+ background: var(--primary-color);
|
|
|
+ }
|
|
|
+
|
|
|
+ .login-form input[type="text"],
|
|
|
+ .login-form input[type="password"] {
|
|
|
+ width: 100%;
|
|
|
+ padding: 1rem 1.2rem;
|
|
|
+ margin: 0.75rem 0;
|
|
|
+ border: 1px solid var(--border-color);
|
|
|
+ border-radius: var(--radius-md);
|
|
|
+ box-sizing: border-box;
|
|
|
+ font-size: 1rem;
|
|
|
+ background-color: var (--container-bg);
|
|
|
+ color: var(--text-primary);
|
|
|
+ transition: all var(--transition-fast);
|
|
|
+ box-shadow: var(--shadow-sm);
|
|
|
+ }
|
|
|
+
|
|
|
+ .login-form input:focus {
|
|
|
+ border-color: var(--primary-color);
|
|
|
+ box-shadow: 0 0 0 3px rgba(61, 124, 244, 0.2);
|
|
|
+ outline: none;
|
|
|
+ }
|
|
|
+
|
|
|
+ .login-form button {
|
|
|
+ width: 100%;
|
|
|
+ padding: 1rem;
|
|
|
+ background-color: var(--primary-color);
|
|
|
+ color: white;
|
|
|
+ border: none;
|
|
|
+ border-radius: var (--radius-md);
|
|
|
+ cursor: pointer;
|
|
|
+ font-size: 1.1rem;
|
|
|
+ font-weight: 500;
|
|
|
+ margin-top: 1.8rem;
|
|
|
+ transition: all var(--transition-fast);
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: center;
|
|
|
+ gap: 0.5rem;
|
|
|
+ }
|
|
|
+
|
|
|
+ .login-form button:hover {
|
|
|
+ background-color: var(--primary-dark);
|
|
|
+ transform: translateY(-2px);
|
|
|
+ box-shadow: var(--shadow-md);
|
|
|
+ }
|
|
|
+
|
|
|
+ .login-form button:active {
|
|
|
+ transform: translateY(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ .login-form button:before {
|
|
|
+ content: "\f2f6";
|
|
|
+ font-family: "Font Awesome 6 Free";
|
|
|
+ font-weight: 900;
|
|
|
+ }
|
|
|
+
|
|
|
+ .captcha-container {
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ margin: 0.75rem 0;
|
|
|
+ gap: 0.75rem;
|
|
|
+ }
|
|
|
+
|
|
|
+ .captcha-container input {
|
|
|
+ flex: 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ .captcha-container span {
|
|
|
+ padding: 0.85rem;
|
|
|
+ background-color: var(--background-color);
|
|
|
+ border: 1px solid var(--border-color);
|
|
|
+ border-radius: var(--radius-md);
|
|
|
+ cursor: pointer;
|
|
|
+ font-size: 0.95rem;
|
|
|
+ color: var(--text-secondary);
|
|
|
+ transition: all var(--transition-fast);
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: center;
|
|
|
+ }
|
|
|
+
|
|
|
+ .captcha-container span:hover {
|
|
|
+ background-color: var(--border-light);
|
|
|
+ color: var(--primary-color);
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 加载指示器 */
|
|
|
+ .loading-spinner {
|
|
|
+ position: fixed;
|
|
|
+ top: 50%;
|
|
|
+ left: 50%;
|
|
|
+ transform: translate(-50%, -50%);
|
|
|
+ width: 50px;
|
|
|
+ height: 50px;
|
|
|
+ border: 5px solid rgba(61, 124, 244, 0.1);
|
|
|
+ border-top: 5px solid var(--primary-color);
|
|
|
+ border-radius: 50%;
|
|
|
+ animation: spin 1s linear infinite;
|
|
|
+ z-index: 9999;
|
|
|
+ }
|
|
|
+
|
|
|
+ @keyframes spin {
|
|
|
+ 0% { transform: translate(-50%, -50%) rotate(0deg); }
|
|
|
+ 100% { transform: translate(-50%, -50%) rotate(360deg); }
|
|
|
+ }
|
|
|
+
|
|
|
+ #loadingIndicator {
|
|
|
+ display: flex;
|
|
|
+ justify-content: center;
|
|
|
+ align-items: center;
|
|
|
+ height: 100vh;
|
|
|
+ background-color: var(--background-color);
|
|
|
+ color: var(--text-secondary);
|
|
|
+ font-size: 1.1rem;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 状态指示样式 */
|
|
|
+ .disabled {
|
|
|
+ opacity: 0.5;
|
|
|
+ pointer-events: none;
|
|
|
+ }
|
|
|
+
|
|
|
+ .status-cell {
|
|
|
+ position: relative;
|
|
|
+ min-height: 24px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .status-content {
|
|
|
+ position: absolute;
|
|
|
+ top: 50%;
|
|
|
+ left: 50%;
|
|
|
+ transform: translate(-50%, -50%);
|
|
|
+ width: 100%;
|
|
|
+ text-align: center;
|
|
|
+ }
|
|
|
+
|
|
|
+ .loading-container {
|
|
|
+ display: flex;
|
|
|
+ justify-content: center;
|
|
|
+ align-items: center;
|
|
|
+ position: absolute;
|
|
|
+ top: 0;
|
|
|
+ left: 0;
|
|
|
+ right: 0;
|
|
|
+ bottom: 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ .loading {
|
|
|
+ display: inline-block;
|
|
|
+ width: 20px;
|
|
|
+ height: 20px;
|
|
|
+ border: 3px solid rgba(61, 124, 244, 0.1);
|
|
|
+ border-radius: 50%;
|
|
|
+ border-top: 3px solid var(--primary-color);
|
|
|
+ animation: spin 1s linear infinite;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 监控配置部分 */
|
|
|
+ .monitoring-status {
|
|
|
+ margin-bottom: 1.5rem;
|
|
|
+ font-size: 1rem;
|
|
|
+ color: var(--text-secondary);
|
|
|
+ background-color: rgba(61, 124, 244, 0.05);
|
|
|
+ padding: 1rem 1.5rem;
|
|
|
+ border-radius: var(--radius-md);
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ gap: 0.75rem;
|
|
|
+ }
|
|
|
+
|
|
|
+ .monitoring-status:before {
|
|
|
+ content: "\f021";
|
|
|
+ font-family: "Font Awesome 6 Free";
|
|
|
+ font-weight: 900;
|
|
|
+ color: var(--primary-color);
|
|
|
+ }
|
|
|
+
|
|
|
+ .status-indicator {
|
|
|
+ font-weight: 600;
|
|
|
+ }
|
|
|
+
|
|
|
+ .config-form {
|
|
|
+ background-color: var(--container-bg);
|
|
|
+ padding: 1.8rem;
|
|
|
+ border-radius: var(--radius-md);
|
|
|
+ margin-bottom: 1.5rem;
|
|
|
+ border: 1px solid var(--border-light);
|
|
|
+ box-shadow: var(--shadow-sm);
|
|
|
+ }
|
|
|
+
|
|
|
+ .form-group {
|
|
|
+ margin-bottom: 1.2rem;
|
|
|
+ }
|
|
|
+
|
|
|
+ .form-control {
|
|
|
+ width: 100%;
|
|
|
+ padding: 0.9rem 1rem;
|
|
|
+ border: 1px solid var(--border-color);
|
|
|
+ border-radius: var(--radius-md);
|
|
|
+ color: var(--text-primary);
|
|
|
+ background-color: var(--container-bg);
|
|
|
+ }
|
|
|
+
|
|
|
+ .button-group {
|
|
|
+ display: flex;
|
|
|
+ gap: 0.75rem;
|
|
|
+ flex-wrap: wrap;
|
|
|
+ margin-top: 1.5rem;
|
|
|
+ }
|
|
|
+
|
|
|
+ .btn {
|
|
|
+ padding: 0.8rem 1.2rem;
|
|
|
+ border: none;
|
|
|
+ border-radius: var(--radius-md);
|
|
|
+ cursor: pointer;
|
|
|
+ transition: all var(--transition-fast);
|
|
|
+ font-size: 0.95rem;
|
|
|
+ font-weight: 500;
|
|
|
+ display: inline-flex;
|
|
|
+ align-items: center;
|
|
|
+ gap: 0.5rem;
|
|
|
+ }
|
|
|
+
|
|
|
+ .btn-primary {
|
|
|
+ background-color: var(--primary-color);
|
|
|
+ color: white;
|
|
|
+ }
|
|
|
+
|
|
|
+ .btn-primary:before {
|
|
|
+ content: "\f0c7";
|
|
|
+ font-family: "Font Awesome 6 Free";
|
|
|
+ font-weight: 900;
|
|
|
+ }
|
|
|
+
|
|
|
+ .btn-secondary {
|
|
|
+ background-color: var(--text-secondary);
|
|
|
+ color: white;
|
|
|
+ }
|
|
|
+
|
|
|
+ .btn:hover {
|
|
|
+ transform: translateY(-2px);
|
|
|
+ box-shadow: var(--shadow-sm);
|
|
|
+ }
|
|
|
+
|
|
|
+ .btn:active {
|
|
|
+ transform: translateY(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ .section-title {
|
|
|
+ color: var(--text-primary);
|
|
|
+ font-size: 1.3rem;
|
|
|
+ font-weight: 600;
|
|
|
+ margin: 2rem 0 1.2rem;
|
|
|
+ position: relative;
|
|
|
+ padding-left: 1rem;
|
|
|
+ border-left: 3px solid var(--primary-color);
|
|
|
+ }
|
|
|
+
|
|
|
+ .container-table {
|
|
|
+ width: 100%;
|
|
|
+ border-collapse: separate;
|
|
|
+ border-spacing: 0;
|
|
|
+ margin-bottom: 1.5rem;
|
|
|
+ border-radius: var(--radius-md);
|
|
|
+ overflow: hidden;
|
|
|
+ box-shadow: var(--shadow-sm);
|
|
|
+ }
|
|
|
+
|
|
|
+ .container-table th {
|
|
|
+ background-color: var(--primary-color);
|
|
|
+ color: white;
|
|
|
+ padding: 0.9rem 1rem;
|
|
|
+ text-align: left;
|
|
|
+ font-weight: 500;
|
|
|
+ }
|
|
|
+
|
|
|
+ .container-table td {
|
|
|
+ padding: 0.9rem 1rem;
|
|
|
+ border-bottom: 1px solid var(--border-light);
|
|
|
+ }
|
|
|
+
|
|
|
+ .container-table tr:last-child td {
|
|
|
+ border-bottom: none;
|
|
|
+ }
|
|
|
+
|
|
|
+ .error-message {
|
|
|
+ color: var(--danger-color);
|
|
|
+ margin-top: 0.75rem;
|
|
|
+ padding: 0.75rem;
|
|
|
+ border-radius: var (--radius-md);
|
|
|
+ background-color: rgba(255, 82, 82, 0.1);
|
|
|
+ font-size: 0.9rem;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ gap: 0.5rem;
|
|
|
+ }
|
|
|
+
|
|
|
+ .error-message:before {
|
|
|
+ content: "\f071";
|
|
|
+ font-family: "Font Awesome 6 Free";
|
|
|
+ font-weight: 900;
|
|
|
+ }
|
|
|
+
|
|
|
+ .success-message {
|
|
|
+ color: var(--success-color);
|
|
|
+ margin-top: 0.75rem;
|
|
|
+ padding: 0.75rem;
|
|
|
+ border-radius: var(--radius-md);
|
|
|
+ background-color: rgba(50, 213, 131, 0.1);
|
|
|
+ font-size: 0.9rem;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ gap: 0.5rem;
|
|
|
+ }
|
|
|
+
|
|
|
+ .success-message:before {
|
|
|
+ content: "\f00c";
|
|
|
+ font-family: "Font Awesome 6 Free";
|
|
|
+ font-weight: 900;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 网络测试部分 */
|
|
|
+ #network-test .input-group {
|
|
|
+ margin-bottom: 1.2rem;
|
|
|
+ max-width: 600px;
|
|
|
+ background-color: rgba(61, 124, 244, 0.03);
|
|
|
+ padding: 1.5rem;
|
|
|
+ border-radius: var(--radius-md);
|
|
|
+ box-shadow: var(--shadow-sm);
|
|
|
+ }
|
|
|
+
|
|
|
+ #network-test label {
|
|
|
+ display: block;
|
|
|
+ margin-bottom: 0.5rem;
|
|
|
+ color: var (--text-secondary);
|
|
|
+ font-weight: 500;
|
|
|
+ }
|
|
|
+
|
|
|
+ #testResults {
|
|
|
+ margin-top: 1.5rem;
|
|
|
+ padding: 1rem;
|
|
|
+ background-color: #1e2532;
|
|
|
+ color: #e9ecef;
|
|
|
+ border-radius: var(--radius-md);
|
|
|
+ white-space: pre-wrap;
|
|
|
+ font-family: 'JetBrains Mono', monospace;
|
|
|
+ min-height: 300px;
|
|
|
+ max-height: 500px;
|
|
|
+ overflow-y: auto;
|
|
|
+ border: none;
|
|
|
+ box-shadow: var(--shadow-md);
|
|
|
+ position: relative;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 文档编辑器部分 */
|
|
|
+ #editorContainer {
|
|
|
+ margin-top: 2rem;
|
|
|
+ border-radius: var(--radius-md);
|
|
|
+ background-color: var(--container-bg);
|
|
|
+ overflow: hidden;
|
|
|
+ box-shadow: var(--shadow-md);
|
|
|
+ border: 1px solid var(--border-light);
|
|
|
+ }
|
|
|
+
|
|
|
+ #documentTitle {
|
|
|
+ width: 100%;
|
|
|
+ padding: 1rem;
|
|
|
+ margin-bottom: 1rem;
|
|
|
+ border: 1px solid var(--border-color);
|
|
|
+ border-radius: var (--radius-md);
|
|
|
+ font-size: 1.1rem;
|
|
|
+ font-weight: 500;
|
|
|
+ box-shadow: var(--shadow-sm);
|
|
|
+ }
|
|
|
+
|
|
|
+ .password-hint {
|
|
|
+ color: var(--text-secondary);
|
|
|
+ font-size: 0.9rem;
|
|
|
+ margin: 0.5rem 0 1rem;
|
|
|
+ display: block;
|
|
|
+ background-color: rgba(61, 124, 244, 0.05);
|
|
|
+ padding: 0.75rem;
|
|
|
+ border-radius: var(--radius-md);
|
|
|
+ }
|
|
|
+
|
|
|
+ #passwordStrength {
|
|
|
+ font-size: 0.9rem;
|
|
|
+ margin: 0.5rem 0;
|
|
|
+ display: block;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 警告和确认对话框样式 */
|
|
|
+ .swal2-popup {
|
|
|
+ font-size: 1rem !important;
|
|
|
+ border-radius: var(--radius-lg) !important;
|
|
|
+ }
|
|
|
+
|
|
|
+ .swal2-title {
|
|
|
+ font-weight: 600 !important;
|
|
|
+ color: var(--text-primary) !important;
|
|
|
+ }
|
|
|
+
|
|
|
+ .swal2-styled.swal2-confirm {
|
|
|
+ background-color: var(--primary-color) !important;
|
|
|
+ border-radius: var(--radius-md) !important;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 添加条目按钮 */
|
|
|
+ .add-btn {
|
|
|
+ background-color: var(--success-color);
|
|
|
+ color: white;
|
|
|
+ padding: 0.8rem 1.2rem;
|
|
|
+ border-radius: var(--radius-md);
|
|
|
+ display: inline-flex;
|
|
|
+ align-items: center;
|
|
|
+ gap: 0.5rem;
|
|
|
+ font-weight: 500;
|
|
|
+ margin-top: 1rem;
|
|
|
+ box-shadow: var(--shadow-sm);
|
|
|
+ }
|
|
|
+
|
|
|
+ .add-btn:before {
|
|
|
+ content: "\f067";
|
|
|
+ font-family: "Font Awesome 6 Free";
|
|
|
+ font-weight: 900;
|
|
|
+ }
|
|
|
+
|
|
|
+ .add-btn:hover {
|
|
|
+ background-color: #29b873;
|
|
|
+ transform: translateY(-2px);
|
|
|
+ box-shadow: var (--shadow-md);
|
|
|
+ }
|
|
|
+
|
|
|
+ /* Docker状态表格 */
|
|
|
+ .action-select {
|
|
|
+ padding: 0.5rem;
|
|
|
+ border-radius: var(--radius-sm);
|
|
|
+ border: 1px solid var(--border-color);
|
|
|
+ background-color: var(--container-bg);
|
|
|
+ color: var(--text-primary);
|
|
|
+ cursor: pointer;
|
|
|
+ width: 100%;
|
|
|
+ }
|
|
|
+
|
|
|
+ .action-select:focus {
|
|
|
+ border-color: var (--primary-color);
|
|
|
+ outline: none;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 响应式设计 */
|
|
|
+ @media (max-width: 992px) {
|
|
|
+ .admin-container {
|
|
|
+ flex-direction: column;
|
|
|
+ }
|
|
|
+
|
|
|
+ .sidebar {
|
|
|
+ width: 100%;
|
|
|
+ padding: 1rem 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ .sidebar ul {
|
|
|
+ display: flex;
|
|
|
+ flex-wrap: wrap;
|
|
|
+ justify-content: flex-start;
|
|
|
+ }
|
|
|
+
|
|
|
+ .sidebar li {
|
|
|
+ padding: 0.5rem 1rem;
|
|
|
+ border-left: none;
|
|
|
+ border-bottom: 3px solid transparent;
|
|
|
+ }
|
|
|
+
|
|
|
+ .sidebar li.active {
|
|
|
+ border-left: none;
|
|
|
+ border-bottom: 3px solid var(--primary-color);
|
|
|
+ }
|
|
|
+
|
|
|
+ .content-area {
|
|
|
+ padding: 1rem;
|
|
|
+ }
|
|
|
+
|
|
|
+ .content-section {
|
|
|
+ padding: 1.5rem;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @media (max-width: 768px) {
|
|
|
+ .content-section th,
|
|
|
+ .content-section td {
|
|
|
+ padding: 0.75rem 0.5rem;
|
|
|
+ font-size: 0.9rem;
|
|
|
+ }
|
|
|
+
|
|
|
+ .button-group {
|
|
|
+ flex-direction: column;
|
|
|
+ }
|
|
|
+
|
|
|
+ .btn, .action-btn {
|
|
|
+ width: 100%;
|
|
|
+ margin-bottom: 0.5rem;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @media (max-width: 480px) {
|
|
|
+ .login-content {
|
|
|
+ width: 90%;
|
|
|
+ padding: 1.5rem;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ </style>
|
|
|
+</head>
|
|
|
+<body>
|
|
|
+ <div id="loadingSpinner" class="loading-spinner" style="display: none;"></div>
|
|
|
+ <div id="loadingIndicator" style="display: flex; justify-content: center; align-items: center; height: 100vh;">
|
|
|
+ <p>加载中...</p>
|
|
|
+ </div>
|
|
|
+ <div class="admin-container" id="adminContainer" style="display: none;">
|
|
|
+ <div class="sidebar">
|
|
|
+ <div class="user-profile">
|
|
|
+ <div class="user-avatar">
|
|
|
+ <i class="fas fa-user"></i>
|
|
|
+ </div>
|
|
|
+ <div class="user-info">
|
|
|
+ <div class="user-name" id="currentUsername">管理员</div>
|
|
|
+ <div class="user-role">系统管理员</div>
|
|
|
+ </div>
|
|
|
+ <div class="user-actions">
|
|
|
+ <div class="user-action-btn" id="userCenterBtn">个人中心</div>
|
|
|
+ <div class="user-action-btn logout" id="logoutBtn">退出登录</div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <h2><i class="fas fa-cogs"></i>管理面板</h2>
|
|
|
+ <ul>
|
|
|
+ <li data-section="dashboard" class="active">
|
|
|
+ <i class="fas fa-tachometer-alt"></i>控制面板
|
|
|
+ </li>
|
|
|
+ <li data-section="basic-config">
|
|
|
+ <i class="fas fa-wrench"></i>基本配置
|
|
|
+ </li>
|
|
|
+ <li data-section="menu-management">
|
|
|
+ <i class="fas fa-bars"></i>菜单管理
|
|
|
+ </li>
|
|
|
+ <li data-section="documentation-management">
|
|
|
+ <i class="fas fa-file-alt"></i>文档管理
|
|
|
+ </li>
|
|
|
+ <li data-section="network-test">
|
|
|
+ <i class="fas fa-network-wired"></i>网络测试
|
|
|
+ </li>
|
|
|
+ <li data-section="docker-status">
|
|
|
+ <i class="fab fa-docker"></i>容器管理
|
|
|
+ </li>
|
|
|
+ <li data-section="docker-monitoring">
|
|
|
+ <i class="fas fa-chart-line"></i>容器监控
|
|
|
+ </li>
|
|
|
+ <li data-section="user-center">
|
|
|
+ <i class="fas fa-user-cog"></i>用户中心
|
|
|
+ </li>
|
|
|
+ </ul>
|
|
|
+ </div>
|
|
|
+ <div class="content-area">
|
|
|
+ <div class="container">
|
|
|
+ <!-- 控制面板 -->
|
|
|
+ <div id="dashboard" class="content-section active">
|
|
|
+ <div class="welcome-banner">
|
|
|
+ <div class="welcome-content">
|
|
|
+ <h1 class="welcome-title">欢迎回来,<span id="welcomeUsername">管理员</span>!</h1>
|
|
|
+ <p class="welcome-subtitle">这里是 Docker 镜像代理加速系统控制面板</p>
|
|
|
+ <button class="welcome-action" onclick="refreshDockerStatus()">
|
|
|
+ <i class="fas fa-sync-alt"></i> 刷新系统状态
|
|
|
+ </button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="dashboard-grid">
|
|
|
+ <div class="dashboard-card">
|
|
|
+ <div class="card-icon">
|
|
|
+ <i class="fab fa-docker"></i>
|
|
|
+ </div>
|
|
|
+ <div class="card-title">容器总数</div>
|
|
|
+ <div class="card-value" id="totalContainers">--</div>
|
|
|
+ <div class="card-description">当前系统中的容器总数</div>
|
|
|
+ <div class="card-footer">
|
|
|
+ <div class="trend up">
|
|
|
+ <i class="fas fa-arrow-up"></i>
|
|
|
+ <span>正常运行</span>
|
|
|
+ </div>
|
|
|
+ <div class="card-action" onclick="showSection('docker-status')">查看详情</div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="dashboard-card">
|
|
|
+ <div class="card-icon" style="background-color: rgba(255, 152, 0, 0.1); color: #FF9800;">
|
|
|
+ <i class="fas fa-memory"></i>
|
|
|
+ </div>
|
|
|
+ <div class="card-title">系统内存</div>
|
|
|
+ <div class="card-value" id="systemMemory">--</div>
|
|
|
+ <div class="card-description">当前系统内存使用情况</div>
|
|
|
+ <div class="card-footer">
|
|
|
+ <div class="trend up">
|
|
|
+ <i class="fas fa-arrow-up"></i>
|
|
|
+ <span>运行正常</span>
|
|
|
+ </div>
|
|
|
+ <div class="card-action" onclick="showSection('docker-monitoring')">监控详情</div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="dashboard-card">
|
|
|
+ <div class="card-icon" style="background-color: rgba(76, 175, 80, 0.1); color: #4CAF50;">
|
|
|
+ <i class="fas fa-microchip"></i>
|
|
|
+ </div>
|
|
|
+ <div class="card-title">CPU 负载</div>
|
|
|
+ <div class="card-value" id="cpuLoad">--</div>
|
|
|
+ <div class="card-description">当前系统 CPU 负载情况</div>
|
|
|
+ <div class="card-footer">
|
|
|
+ <div class="trend down">
|
|
|
+ <i class="fas fa-arrow-down"></i>
|
|
|
+ <span>降低 5%</span>
|
|
|
+ </div>
|
|
|
+ <div class="card-action" onclick="showSection('docker-monitoring')">监控详情</div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="dashboard-card">
|
|
|
+ <div class="card-icon" style="background-color: rgba(33, 150, 243, 0.1); color: #2196F3;">
|
|
|
+ <i class="fas fa-hdd"></i>
|
|
|
+ </div>
|
|
|
+ <div class="card-title">磁盘空间</div>
|
|
|
+ <div class="card-value" id="diskSpace">--</div>
|
|
|
+ <div class="card-description">当前系统磁盘使用情况</div>
|
|
|
+ <div class="card-footer">
|
|
|
+ <div class="trend up">
|
|
|
+ <i class="fas fa-arrow-up"></i>
|
|
|
+ <span>充足</span>
|
|
|
+ </div>
|
|
|
+ <div class="card-action" onclick="checkDiskSpace()">查看详情</div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="dashboard-card">
|
|
|
+ <h3 class="card-title">最近容器操作</h3>
|
|
|
+ <table id="recentActivitiesTable">
|
|
|
+ <thead>
|
|
|
+ <tr>
|
|
|
+ <th>时间</th>
|
|
|
+ <th>操作</th>
|
|
|
+ <th>容器</th>
|
|
|
+ <th>状态</th>
|
|
|
+ </tr>
|
|
|
+ </thead>
|
|
|
+ <tbody id="recentActivitiesBody">
|
|
|
+ <tr>
|
|
|
+ <td colspan="4" style="text-align: center;">加载中...</td>
|
|
|
+ </tr>
|
|
|
+ </tbody>
|
|
|
+ </table>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <!-- 将原有的内容分成四个部分,每个部分对应一个侧边栏项目 -->
|
|
|
+ <div id="basic-config" class="content-section">
|
|
|
+ <label for="logoUrl">Logo URL: (可选)</label>
|
|
|
+ <input type="url" id="logoUrl" name="logoUrl">
|
|
|
+ <button type="button" onclick="saveLogo()">保存 Logo</button>
|
|
|
+
|
|
|
+ <label for="proxyDomain">Docker镜像代理地址: (必填)</label>
|
|
|
+ <input type="text" id="proxyDomain" name="proxyDomain" required>
|
|
|
+ <button type="button" onclick="saveProxyDomain()">保存代理地址</button>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div id="menu-management" class="content-section">
|
|
|
+ <h2 class="menu-label">菜单项管理</h2>
|
|
|
+ <table id="menuTable">
|
|
|
+ <thead>
|
|
|
+ <tr>
|
|
|
+ <th>文本</th>
|
|
|
+ <th>链接 (可选)</th>
|
|
|
+ <th>新标签页打开</th>
|
|
|
+ <th>操作</th>
|
|
|
+ </tr>
|
|
|
+ </thead>
|
|
|
+ <tbody id="menuTableBody">
|
|
|
+ <!-- 菜单项将在这里动态添加 -->
|
|
|
+ </tbody>
|
|
|
+ </table>
|
|
|
+ <button type="button" class="add-btn" onclick="showNewMenuItemRow()">添加菜单项</button>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <!-- 文档管理部分 -->
|
|
|
+ <div id="documentation-management" class="content-section">
|
|
|
+ <h2 class="menu-label">文档管理</h2>
|
|
|
+ <button type="button" onclick="newDocument()">新建文档</button>
|
|
|
+ <table id="documentTable">
|
|
|
+ <thead>
|
|
|
+ <tr>
|
|
|
+ <th>文章</th>
|
|
|
+ <th>操作</th>
|
|
|
+ </tr>
|
|
|
+ </thead>
|
|
|
+ <tbody id="documentTableBody">
|
|
|
+ <!-- 文档列表将在这里动态添加 -->
|
|
|
+ </tbody>
|
|
|
+ </table>
|
|
|
+ <div id="editorContainer" style="display: none;">
|
|
|
+ <input type="text" id="documentTitle" placeholder="文档标题">
|
|
|
+ <div id="editormd">
|
|
|
+ <textarea style="display:none;"></textarea>
|
|
|
+ </div>
|
|
|
+ <button type="button" onclick="saveDocument()">保存文档</button>
|
|
|
+ <button type="button" onclick="cancelEdit()">取消</button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <!-- 修改密码部分 -->
|
|
|
+ <div id="password-change" class="content-section">
|
|
|
+ <h2 class="menu-label">修改密码</h2>
|
|
|
+ <label for="currentPassword">当前密码</label>
|
|
|
+ <input type="password" id="currentPassword" name="currentPassword">
|
|
|
+ <label for="newPassword">新密码</label>
|
|
|
+ <span class="password-hint" id="passwordHint">密码必须包含至少一个字母、一个数字和一个特殊字符,长度在8到16个字符之间</span>
|
|
|
+ <input type="password" id="newPassword" name="newPassword" oninput="checkPasswordStrength()">
|
|
|
+ <span id="passwordStrength" style="color: red;"></span>
|
|
|
+ <button type="button" onclick="changePassword()">修改密码</button>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <!-- 网络测试 -->
|
|
|
+ <div id="network-test" class="content-section">
|
|
|
+ <h1 class="admin-title">网络测试</h1>
|
|
|
+ <div class="input-group">
|
|
|
+ <label for="testDomain">目标域名或IP地址:</label>
|
|
|
+ <input type="text" id="testDomain" placeholder="例如: www.example.com 或 8.8.8.8" autocomplete="off">
|
|
|
+ <select id="domainSelect">
|
|
|
+ <option value="">选择预定义域名</option>
|
|
|
+ <option value="gcr.io">gcr.io</option>
|
|
|
+ <option value="ghcr.io">ghcr.io</option>
|
|
|
+ <option value="quay.io">quay.io</option>
|
|
|
+ <option value="k8s.gcr.io">k8s.gcr.io</option>
|
|
|
+ <option value="registry.k8s.io">registry.k8s.io</option>
|
|
|
+ <option value="mcr.microsoft.com">mcr.microsoft.com</option>
|
|
|
+ <option value="docker.elastic.co">docker.elastic.co</option>
|
|
|
+ <option value="registry-1.docker.io">registry-1.docker.io</option>
|
|
|
+ </select>
|
|
|
+ </div>
|
|
|
+ <div class="input-group">
|
|
|
+ <label for="testType">测试类型:</label>
|
|
|
+ <select id="testType">
|
|
|
+ <option value="ping">Ping</option>
|
|
|
+ <option value="traceroute">Traceroute</option>
|
|
|
+ </select>
|
|
|
+ </div>
|
|
|
+ <button>开始测试</button>
|
|
|
+ <div id="testResults" style="margin-top: 20px; white-space: pre-wrap; font-family: monospace;"></div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <!-- Docker服务状态 -->
|
|
|
+ <div id="docker-status" class="content-section">
|
|
|
+ <h1 class="admin-title">Docker 服务状态</h1>
|
|
|
+ <table id="dockerStatusTable">
|
|
|
+ <thead>
|
|
|
+ <tr>
|
|
|
+ <th>容器 ID</th>
|
|
|
+ <th>名称</th>
|
|
|
+ <th>镜像</th>
|
|
|
+ <th>状态</th>
|
|
|
+ <th>CPU</th>
|
|
|
+ <th>内存</th>
|
|
|
+ <th>创建时间</th>
|
|
|
+ </tr>
|
|
|
+ </thead>
|
|
|
+ <tbody id="dockerStatusTableBody">
|
|
|
+ <!-- Docker 容器状态将在这里动态添加 -->
|
|
|
+ </tbody>
|
|
|
+ </table>
|
|
|
+ <button type="button" onclick="refreshDockerStatus()">刷新状态</button>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div id="docker-monitoring" class="content-section">
|
|
|
+ <h1 class="admin-title">Docker 容器监控</h1>
|
|
|
+ <div class="monitoring-status">
|
|
|
+ <span>监控状态:</span>
|
|
|
+ <span id="monitoringStatus" class="status-indicator">加载中...</span>
|
|
|
+ </div>
|
|
|
+ <div class="config-form">
|
|
|
+ <div class="form-group">
|
|
|
+ <label for="notificationType">通知方式:</label>
|
|
|
+ <select id="notificationType" class="form-control" onchange="toggleNotificationFields()">
|
|
|
+ <option value="wechat">企业微信群机器人</option>
|
|
|
+ <option value="telegram">Telegram Bot</option>
|
|
|
+ </select>
|
|
|
+ </div>
|
|
|
+ <div id="wechatFields">
|
|
|
+ <div class="form-group">
|
|
|
+ <label for="webhookUrl">企业微信机器人 Webhook URL:</label>
|
|
|
+ <input type="text" id="webhookUrl" name="webhookUrl" class="form-control">
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div id="telegramFields" style="display: none;">
|
|
|
+ <div class="form-group">
|
|
|
+ <label for="telegramToken">Telegram Bot Token:</label>
|
|
|
+ <input type="text" id="telegramToken" name="telegramToken" class="form-control">
|
|
|
+ </div>
|
|
|
+ <div class="form-group">
|
|
|
+ <label for="telegramChatId">Telegram Chat ID:</label>
|
|
|
+ <input type="text" id="telegramChatId" name="telegramChatId" class="form-control">
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div class="form-group">
|
|
|
+ <label for="monitorInterval">监控间隔 (秒):</label>
|
|
|
+ <input type="number" id="monitorInterval" name="monitorInterval" min="1" value="60" class="form-control">
|
|
|
+ </div>
|
|
|
+ <div class="button-group">
|
|
|
+ <button onclick="testNotification()" class="btn btn-secondary">测试通知</button>
|
|
|
+ <button onclick="saveMonitoringConfig()" class="btn btn-primary">保存配置</button>
|
|
|
+ <button onclick="toggleMonitoring()" class="btn btn-secondary" id="toggleMonitoringBtn">开启/关闭监控</button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div id="messageContainer"></div>
|
|
|
+ <h2 class="section-title">已停止的容器</h2>
|
|
|
+ <div class="container-list">
|
|
|
+ <table id="stoppedContainersTable" class="container-table">
|
|
|
+ <thead>
|
|
|
+ <tr>
|
|
|
+ <th>容器 ID</th>
|
|
|
+ <th>名称</th>
|
|
|
+ <th>状态</th>
|
|
|
+ </tr>
|
|
|
+ </thead>
|
|
|
+ <tbody id="stoppedContainersBody"></tbody>
|
|
|
+ </table>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <!-- 用户中心部分 - 修改按钮样式,移除图标 -->
|
|
|
+ <div id="user-center" class="content-section">
|
|
|
+ <div class="user-center-header">
|
|
|
+ <div>
|
|
|
+ <h1 class="user-center-title">用户中心</h1>
|
|
|
+ <p class="user-center-subtitle">管理您的个人信息和账户安全</p>
|
|
|
+ </div>
|
|
|
+ <button class="btn btn-primary" id="ucLogoutBtn">退出登录</button>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="user-center-card">
|
|
|
+ <div class="user-center-section">
|
|
|
+ <h2 class="user-center-section-title">账户信息</h2>
|
|
|
+ <div class="user-stats">
|
|
|
+ <div class="stat-card">
|
|
|
+ <div class="stat-value" id="loginCount">--</div>
|
|
|
+ <div class="stat-label">登录次数</div>
|
|
|
+ </div>
|
|
|
+ <div class="stat-card">
|
|
|
+ <div class="stat-value" id="lastLogin">--</div>
|
|
|
+ <div class="stat-label">上次登录</div>
|
|
|
+ </div>
|
|
|
+ <div class="stat-card">
|
|
|
+ <div class="stat-value" id="accountAge">--</div>
|
|
|
+ <div class="stat-label">账户天数</div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="user-center-section">
|
|
|
+ <h2 class="user-center-section-title">修改密码</h2>
|
|
|
+ <label for="currentPassword">当前密码</label>
|
|
|
+ <input type="password" id="currentPassword" name="currentPassword">
|
|
|
+ <label for="newPassword">新密码</label>
|
|
|
+ <span class="password-hint" id="passwordHint">密码必须包含至少一个字母、一个数字和一个特殊字符,长度在8到16个字符之间</span>
|
|
|
+ <input type="password" id="newPassword" name="newPassword" oninput="checkPasswordStrength()">
|
|
|
+ <span id="passwordStrength" style="color: red;"></span>
|
|
|
+ <button type="button" onclick="changePassword()">修改密码</button>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="user-center-section">
|
|
|
+ <h2 class="user-center-section-title">安全设置</h2>
|
|
|
+ <div class="form-group">
|
|
|
+ <label for="loginNotification">登录通知</label>
|
|
|
+ <select id="loginNotification" class="form-control">
|
|
|
+ <option value="none">不通知</option>
|
|
|
+ <option value="email">邮件通知</option>
|
|
|
+ </select>
|
|
|
+ </div>
|
|
|
+ <button type="button" class="btn btn-primary" id="saveSecurityBtn">保存设置</button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="login-modal" id="loginModal" style="display: none;">
|
|
|
+ <div class="login-content">
|
|
|
+ <div class="login-header">
|
|
|
+ <h2>管理员登录</h2>
|
|
|
+ </div>
|
|
|
+ <form class="login-form">
|
|
|
+ <input type="text" id="username" name="username" placeholder="用户名" required>
|
|
|
+ <input type="password" id="password" name="password" placeholder="密码" required>
|
|
|
+ <div class="captcha-container">
|
|
|
+ <input type="text" id="captcha" name="captcha" placeholder="验证码" required>
|
|
|
+ <span id="captchaText" onclick="refreshCaptcha()">点击刷新验证码</span>
|
|
|
+ </div>
|
|
|
+ <button type="button" onclick="login()">登录</button>
|
|
|
+ </form>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/dragula/3.7.2/dragula.min.js"></script>
|
|
|
+ <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
|
|
+ <script>
|
|
|
+ let menuItems = [];
|
|
|
+ let isLoggedIn = false;
|
|
|
+ let editingIndex = -1; // 用于记录当前编辑的菜单项索引
|
|
|
+ let editor;
|
|
|
+ let currentEditingDoc = null;
|
|
|
+ let documents = [];
|
|
|
+
|
|
|
+ // 初始化编辑器
|
|
|
+ function initEditor() {
|
|
|
+ if (editor) {
|
|
|
+ console.log('Editor already initialized');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ editor = editormd("editormd", {
|
|
|
+ width: "100%",
|
|
|
+ height: 640,
|
|
|
+ path : "https://cdn.jsdelivr.net/npm/[email protected]/lib/",
|
|
|
+ theme : "default",
|
|
|
+ previewTheme : "default",
|
|
|
+ editorTheme : "default",
|
|
|
+ markdown : "",
|
|
|
+ codeFold : true,
|
|
|
+ saveHTMLToTextarea : true,
|
|
|
+ searchReplace : true,
|
|
|
+ watch : true, // 开启实时预览
|
|
|
+ htmlDecode : "style,script,iframe|on*",
|
|
|
+ toolbar : true,
|
|
|
+ toolbarIcons : "full",
|
|
|
+ placeholder: "请输入Markdown格式的文档...",
|
|
|
+ emoji : true,
|
|
|
+ taskList : true,
|
|
|
+ tocm : true,
|
|
|
+ tex : true,
|
|
|
+ flowChart : true,
|
|
|
+ sequenceDiagram : true,
|
|
|
+ onload : function() {
|
|
|
+ console.log('Editor.md loaded successfully');
|
|
|
+ // 在加载完成后,立即切换到编辑模式
|
|
|
+ this.unwatch();
|
|
|
+ this.watch();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ console.log('Editor initialized successfully');
|
|
|
+ } catch (error) {
|
|
|
+ console.error('Error initializing editor:', error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ function newDocument() {
|
|
|
+ currentEditingDoc = null;
|
|
|
+ document.getElementById('documentTitle').value = '';
|
|
|
+ editor.setMarkdown('');
|
|
|
+ showEditor();
|
|
|
+ }
|
|
|
+
|
|
|
+ function showEditor() {
|
|
|
+ document.getElementById('documentTable').style.display = 'none';
|
|
|
+ document.getElementById('editorContainer').style.display = 'block';
|
|
|
+ if (editor) {
|
|
|
+ // 确保每次显示编辑器时都切换到编辑模式
|
|
|
+ editor.unwatch();
|
|
|
+ editor.watch();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function hideEditor() {
|
|
|
+ document.getElementById('documentTable').style.display = 'table';
|
|
|
+ document.getElementById('editorContainer').style.display = 'none';
|
|
|
+ }
|
|
|
+
|
|
|
+ function cancelEdit() {
|
|
|
+ hideEditor();
|
|
|
+ }
|
|
|
+
|
|
|
+ async function saveDocument() {
|
|
|
+ const title = document.getElementById('documentTitle').value.trim();
|
|
|
+ const content = editor.getMarkdown();
|
|
|
+ if (!title) {
|
|
|
+ alert('请输入文档标题');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ const response = await fetch('/api/documentation', {
|
|
|
+ method: 'POST',
|
|
|
+ headers: { 'Content-Type': 'application/json' },
|
|
|
+ body: JSON.stringify({
|
|
|
+ id: currentEditingDoc ? currentEditingDoc.id : null,
|
|
|
+ title,
|
|
|
+ content
|
|
|
+ })
|
|
|
+ });
|
|
|
+ if (response.ok) {
|
|
|
+ alert('文档保存成功');
|
|
|
+ hideEditor();
|
|
|
+ loadDocumentList();
|
|
|
+ } else {
|
|
|
+ throw new Error('保存失败');
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('保存文档失败:', error);
|
|
|
+ alert('保存文档失败: ' + error.message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async function loadDocumentList() {
|
|
|
+ try {
|
|
|
+ const response = await fetch('/api/documentation-list');
|
|
|
+ if (!response.ok) {
|
|
|
+ const errorData = await response.json();
|
|
|
+ throw new Error(`HTTP error! status: ${response.status}, message: ${errorData.error}, details: ${errorData.details}`);
|
|
|
+ }
|
|
|
+ documents = await response.json();
|
|
|
+ console.log('Received documents:', documents);
|
|
|
+ renderDocumentList();
|
|
|
+ } catch (error) {
|
|
|
+ console.error('加载文档列表失败:', error);
|
|
|
+ alert('加载文档列表失败: ' + error.message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function renderDocumentList() {
|
|
|
+ const tbody = document.getElementById('documentTableBody');
|
|
|
+ tbody.innerHTML = '';
|
|
|
+ if (documents.length === 0) {
|
|
|
+ tbody.innerHTML = '<tr><td colspan="2">没有找到文档</td></tr>';
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ documents.forEach(doc => {
|
|
|
+ const row = `
|
|
|
+ <tr>
|
|
|
+ <td>${doc.title || 'Untitled Document'}</td>
|
|
|
+ <td>
|
|
|
+ <button onclick="editDocument('${doc.id}')">编辑</button>
|
|
|
+ <button onclick="deleteDocument('${doc.id}')">删除</button>
|
|
|
+ <button onclick="togglePublish('${doc.id}')">${doc.published ? '取消发布' : '发布'}</button>
|
|
|
+ </td>
|
|
|
+ </tr>
|
|
|
+ `;
|
|
|
+ tbody.innerHTML += row;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ function editDocument(id) {
|
|
|
+ currentEditingDoc = documents.find(doc => doc.id === id);
|
|
|
+ document.getElementById('documentTitle').value = currentEditingDoc.title;
|
|
|
+ editor.setMarkdown(currentEditingDoc.content);
|
|
|
+ showEditor();
|
|
|
+ }
|
|
|
+
|
|
|
+ async function deleteDocument(id) {
|
|
|
+ if (confirm('确定要删除这个文档吗?')) {
|
|
|
+ try {
|
|
|
+ const response = await fetch(`/api/documentation/${id}`, { method: 'DELETE' });
|
|
|
+ if (response.ok) {
|
|
|
+ alert('文档删除成功');
|
|
|
+ loadDocumentList();
|
|
|
+ } else {
|
|
|
+ throw new Error('删除失败');
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('删除文档失败:', error);
|
|
|
+ alert('删除文档失败: ' + error.message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async function togglePublish(id) {
|
|
|
+ try {
|
|
|
+ const response = await fetch(`/api/documentation/${id}/toggle-publish`, { method: 'POST' });
|
|
|
+ if (response.ok) {
|
|
|
+ loadDocumentList();
|
|
|
+ } else {
|
|
|
+ throw new Error('操作失败');
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('更改发布状态失败:', error);
|
|
|
+ alert('更改发布状态失败: ' + error.message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ function getMenuItems() {
|
|
|
+ return menuItems;
|
|
|
+ }
|
|
|
+
|
|
|
+ function setupMenuDeleteButtons() {
|
|
|
+ const deleteButtons = document.querySelectorAll('.menu-delete-btn');
|
|
|
+ deleteButtons.forEach((button) => {
|
|
|
+ button.addEventListener('click', () => {
|
|
|
+ const row = button.closest('tr');
|
|
|
+ const index = parseInt(row.getAttribute('data-index'));
|
|
|
+ const menuText = row.querySelector('.menu-text').value;
|
|
|
+ if (confirm(`确定要删除菜单项 "${menuText}" 吗?`)) {
|
|
|
+ deleteMenuItem(index);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ function renderMenuItems() {
|
|
|
+ const tbody = document.getElementById('menuTableBody');
|
|
|
+ tbody.innerHTML = '';
|
|
|
+ menuItems.forEach((item, index) => {
|
|
|
+ const row = `
|
|
|
+ <tr data-index="${index}">
|
|
|
+ <td><input type="text" class="menu-text" value="${item.text}" disabled></td>
|
|
|
+ <td><input type="url" class="menu-link" value="${item.link || ''}" disabled></td>
|
|
|
+ <td>
|
|
|
+ <select class="menu-newtab" disabled>
|
|
|
+ <option value="false" ${item.newTab ? '' : 'selected'}>否</option>
|
|
|
+ <option value="true" ${item.newTab ? 'selected' : ''}>是</option>
|
|
|
+ </select>
|
|
|
+ </td>
|
|
|
+ <td>
|
|
|
+ <button type="button" class="action-btn edit-btn">编辑</button>
|
|
|
+ <button type="button" class="action-btn delete-btn menu-delete-btn">删除</button>
|
|
|
+ </td>
|
|
|
+ </tr>
|
|
|
+ `;
|
|
|
+ tbody.innerHTML += row;
|
|
|
+ });
|
|
|
+ setupEditButtons();
|
|
|
+ setupMenuDeleteButtons();
|
|
|
+ }
|
|
|
+
|
|
|
+ function setMenuItems(items) {
|
|
|
+ menuItems = items;
|
|
|
+ renderMenuItems();
|
|
|
+ }
|
|
|
+
|
|
|
+ function setupEditButtons() {
|
|
|
+ const editButtons = document.querySelectorAll('.edit-btn');
|
|
|
+ editButtons.forEach((button, index) => {
|
|
|
+ button.addEventListener('click', () => {
|
|
|
+ const row = button.closest('tr');
|
|
|
+ const textInput = row.querySelector('.menu-text');
|
|
|
+ const linkInput = row.querySelector('.menu-link');
|
|
|
+ const newTabSelect = row.querySelector('.menu-newtab');
|
|
|
+
|
|
|
+ if (textInput.disabled) {
|
|
|
+ textInput.disabled = false;
|
|
|
+ linkInput.disabled = false;
|
|
|
+ newTabSelect.disabled = false;
|
|
|
+ button.textContent = '保存';
|
|
|
+ } else {
|
|
|
+ const text = textInput.value;
|
|
|
+ const link = linkInput.value;
|
|
|
+ const newTab = newTabSelect.value === 'true';
|
|
|
+
|
|
|
+ if (text) {
|
|
|
+ const rowIndex = row.getAttribute('data-index');
|
|
|
+ menuItems[rowIndex] = { text, link, newTab };
|
|
|
+ saveMenuItem(rowIndex, { text, link, newTab });
|
|
|
+ renderMenuItems(); // 重新渲染菜单项
|
|
|
+ } else {
|
|
|
+ alert('请填写菜单项文本');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ function showNewMenuItemRow() {
|
|
|
+ const tbody = document.getElementById('menuTableBody');
|
|
|
+ const newRow = `
|
|
|
+ <tr id="newMenuItemRow">
|
|
|
+ <td><input type="text" class="menu-text" placeholder="菜单项文本"></td>
|
|
|
+ <td><input type="url" class="menu-link" placeholder="菜单项链接 (可选)"></td>
|
|
|
+ <td>
|
|
|
+ <select class="menu-newtab">
|
|
|
+ <option value="false">否</option>
|
|
|
+ <option value="true">是</option>
|
|
|
+ </select>
|
|
|
+ </td>
|
|
|
+ <td>
|
|
|
+ <button type="button" class="action-btn" onclick="saveNewMenuItem()">保存</button>
|
|
|
+ <button type="button" class="action-btn" onclick="cancelNewMenuItem()">取消</button>
|
|
|
+ </td>
|
|
|
+ </tr>
|
|
|
+ `;
|
|
|
+ tbody.insertAdjacentHTML('beforeend', newRow);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ function saveNewMenuItem() {
|
|
|
+ const newRow = document.getElementById('newMenuItemRow');
|
|
|
+ const textInput = newRow.querySelector('.menu-text');
|
|
|
+ const linkInput = newRow.querySelector('.menu-link');
|
|
|
+ const newTabSelect = newRow.querySelector('.menu-newtab');
|
|
|
+
|
|
|
+ const text = textInput.value;
|
|
|
+ const link = linkInput.value;
|
|
|
+ const newTab = newTabSelect.value === 'true';
|
|
|
+
|
|
|
+ if (text) {
|
|
|
+ const newItem = { text, link, newTab };
|
|
|
+ menuItems.push(newItem);
|
|
|
+ renderMenuItems(); // 先更新页面
|
|
|
+ saveMenuItem(menuItems.length - 1, newItem);
|
|
|
+ cancelNewMenuItem();
|
|
|
+ } else {
|
|
|
+ alert('请填写菜单项文本');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function cancelNewMenuItem() {
|
|
|
+ const newRow = document.getElementById('newMenuItemRow');
|
|
|
+ if (newRow) {
|
|
|
+ newRow.remove();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async function saveLogo() {
|
|
|
+ const logoUrl = document.getElementById('logoUrl').value;
|
|
|
+ if (!logoUrl) {
|
|
|
+ alert('Logo URL 不可为空');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ await saveConfig({ logo: logoUrl });
|
|
|
+ alert('Logo 保存成功');
|
|
|
+ } catch (error) {
|
|
|
+ alert('Logo 保存失败: ' + error.message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async function saveProxyDomain() {
|
|
|
+ const proxyDomain = document.getElementById('proxyDomain').value;
|
|
|
+ if (!proxyDomain) {
|
|
|
+ alert('Docker镜像代理地址不可为空');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ await saveConfig({ proxyDomain });
|
|
|
+ alert('代理地址保存成功');
|
|
|
+ } catch (error) {
|
|
|
+ alert('代理地址保存失败: ' + error.message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async function saveMenuItem(index, item) {
|
|
|
+ const config = { menuItems: menuItems };
|
|
|
+ config.menuItems[index] = item;
|
|
|
+ await saveConfig(config);
|
|
|
+ }
|
|
|
+
|
|
|
+ async function deleteMenuItem(index) {
|
|
|
+ try {
|
|
|
+ menuItems.splice(index, 1);
|
|
|
+ const response = await fetch('/api/config', {
|
|
|
+ method: 'POST',
|
|
|
+ headers: { 'Content-Type': 'application/json' },
|
|
|
+ body: JSON.stringify({ menuItems: menuItems })
|
|
|
+ });
|
|
|
+ if (response.ok) {
|
|
|
+ console.log('Menu item deleted successfully');
|
|
|
+ renderMenuItems(); // 重新渲染菜单项
|
|
|
+ } else {
|
|
|
+ throw new Error('Failed to delete menu item');
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('删除菜单项失败:', error);
|
|
|
+ alert('删除菜单项失败: ' + error.message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async function saveConfig(partialConfig) {
|
|
|
+ try {
|
|
|
+ const response = await fetch('/api/config', {
|
|
|
+ method: 'POST',
|
|
|
+ headers: { 'Content-Type': 'application/json' },
|
|
|
+ body: JSON.stringify(partialConfig)
|
|
|
+ });
|
|
|
+ if (!response.ok) {
|
|
|
+ throw new Error('保存失败');
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('保存失败: ' + error.message);
|
|
|
+ throw error;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 加载文档的函数
|
|
|
+ async function loadDocumentation() {
|
|
|
+ try {
|
|
|
+ const response = await fetch('/api/documentation');
|
|
|
+ if (!response.ok) {
|
|
|
+ throw new Error(`HTTP error! status: ${response.status}`);
|
|
|
+ }
|
|
|
+ const documents = await response.json();
|
|
|
+ console.log('Received documents from server:', documents);
|
|
|
+ if (documents.length > 0) {
|
|
|
+ const firstDocument = documents[0];
|
|
|
+ if (!editor) {
|
|
|
+ console.warn('Editor not initialized, initializing now');
|
|
|
+ initEditor();
|
|
|
+ }
|
|
|
+ // 等待一小段时间确保编辑器完全初始化
|
|
|
+ setTimeout(() => {
|
|
|
+ if (editor && typeof editor.setMarkdown === 'function') {
|
|
|
+ editor.setMarkdown(firstDocument.content);
|
|
|
+ console.log('Documentation loaded successfully');
|
|
|
+ } else {
|
|
|
+ throw new Error('Editor not properly initialized or setMarkdown method not found');
|
|
|
+ }
|
|
|
+ }, 500);
|
|
|
+ } else {
|
|
|
+ console.log('No documents found');
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('加载文档失败:', error);
|
|
|
+ alert('加载文档失败: ' + error.message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 保存文档的函数
|
|
|
+ async function saveDocumentation() {
|
|
|
+ if (!editor) {
|
|
|
+ console.error('Editor not initialized');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const content = editor.getMarkdown();
|
|
|
+ try {
|
|
|
+ const response = await fetch('/api/documentation', {
|
|
|
+ method: 'POST',
|
|
|
+ headers: {
|
|
|
+ 'Content-Type': 'application/json'
|
|
|
+ },
|
|
|
+ body: JSON.stringify({ content })
|
|
|
+ });
|
|
|
+ if (!response.ok) {
|
|
|
+ throw new Error(`HTTP error! status: ${response.status}`);
|
|
|
+ }
|
|
|
+ const result = await response.json();
|
|
|
+ if (result.success) {
|
|
|
+ alert('文档保存成功');
|
|
|
+ } else {
|
|
|
+ throw new Error('保存失败');
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('保存文档失败:', error);
|
|
|
+ alert('保存文档失败: ' + error.message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async function loadConfig() {
|
|
|
+ try {
|
|
|
+ const response = await fetch('/api/config');
|
|
|
+ const config = await response.json();
|
|
|
+ document.getElementById('logoUrl').value = config.logo || '';
|
|
|
+ document.getElementById('proxyDomain').value = config.proxyDomain || '';
|
|
|
+ setMenuItems(config.menuItems || []);
|
|
|
+ loadDocumentation(); // 新增:加载文档
|
|
|
+ } catch (error) {
|
|
|
+ console.error('加载配置失败:', error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async function login() {
|
|
|
+ console.log("执行登录操作");
|
|
|
+ const username = document.getElementById('username').value;
|
|
|
+ const password = document.getElementById('password').value;
|
|
|
+ const captcha = document.getElementById('captcha').value;
|
|
|
+
|
|
|
+ if (!username || !password || !captcha) {
|
|
|
+ alert('请填写完整的登录信息');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ const response = await fetch('/api/login', {
|
|
|
+ method: 'POST',
|
|
|
+ headers: { 'Content-Type': 'application/json' },
|
|
|
+ body: JSON.stringify({ username, password, captcha })
|
|
|
+ });
|
|
|
+
|
|
|
+ if (response.ok) {
|
|
|
+ console.log("登录成功");
|
|
|
+ isLoggedIn = true;
|
|
|
+ // 不再使用localStorage
|
|
|
+ document.getElementById('loginModal').style.display = 'none';
|
|
|
+ document.getElementById('adminContainer').style.display = 'flex';
|
|
|
+
|
|
|
+ // 加载数据
|
|
|
+ loadConfig();
|
|
|
+ refreshSystemStatus();
|
|
|
+ loadUserStats();
|
|
|
+ loadDockerStatus();
|
|
|
+ } else {
|
|
|
+ const errorData = await response.json();
|
|
|
+ alert(errorData.error || '登录失败');
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ alert('登录失败: ' + error.message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async function changePassword() {
|
|
|
+ const currentPassword = document.getElementById('currentPassword').value;
|
|
|
+ const newPassword = document.getElementById('newPassword').value;
|
|
|
+ const passwordRegex = /^(?=.*[A-Za-z])(?=.*\d)(?=.*[.,\-_+=()[\]{}|\\;:'"<>?/@$!%*#?&])[A-Za-z\d.,\-_+=()[\]{}|\\;:'"<>?/@$!%*#?&]{8,16}$/;
|
|
|
+
|
|
|
+ if (!currentPassword || !newPassword) {
|
|
|
+ alert('请填写当前密码和新密码');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!passwordRegex.test(newPassword)) {
|
|
|
+ alert('密码必须包含至少一个字母、一个数字和一个特殊字符,长度在8到16个字符之间');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ const response = await fetch('/api/change-password', {
|
|
|
+ method: 'POST',
|
|
|
+ headers: { 'Content-Type': 'application/json' },
|
|
|
+ body: JSON.stringify({ currentPassword, newPassword })
|
|
|
+ });
|
|
|
+ if (response.ok) {
|
|
|
+ alert('密码已修改');
|
|
|
+ // 清除当前会话并显示登录模态框
|
|
|
+ localStorage.removeItem('isLoggedIn');
|
|
|
+ isLoggedIn = false;
|
|
|
+ document.getElementById('loginModal').style.display = 'block';
|
|
|
+ document.getElementById('adminContainer').classList.add('hidden');
|
|
|
+ refreshCaptcha();
|
|
|
+
|
|
|
+ // 清除登录表单中的输入数据
|
|
|
+ document.getElementById('username').value = '';
|
|
|
+ document.getElementById('password').value = '';
|
|
|
+ document.getElementById('captcha').value = '';
|
|
|
+ } else {
|
|
|
+ alert('修改密码失败');
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ alert('修改密码失败: ' + error.message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function checkPasswordStrength() {
|
|
|
+ const newPassword = document.getElementById('newPassword').value;
|
|
|
+ const passwordHint = document.getElementById('passwordHint');
|
|
|
+
|
|
|
+ const passwordRegex = /^(?=.*[A-Za-z])(?=.*\d)(?=.*[.,\-_+=()[\]{}|\\;:'"<>?/@$!%*#?&])[A-Za-z\d.,\-_+=()[\]{}|\\;:'"<>?/@$!%*#?&]{8,16}$/;
|
|
|
+
|
|
|
+ if (!passwordRegex.test(newPassword)) {
|
|
|
+ passwordHint.style.display = 'block';
|
|
|
+ } else {
|
|
|
+ passwordHint.style.display = 'none';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 页面加载时检查登录状态
|
|
|
+ window.onload = async function() {
|
|
|
+ try {
|
|
|
+ console.log("检查会话状态...");
|
|
|
+ const response = await fetch('/api/check-session');
|
|
|
+ if (response.ok) {
|
|
|
+ // 不再使用localStorage检查登录状态,而是依赖服务器返回的会话状态
|
|
|
+ console.log("会话有效,用户已登录");
|
|
|
+ isLoggedIn = true;
|
|
|
+ document.getElementById('adminContainer').style.display = 'flex';
|
|
|
+ document.getElementById('loadingIndicator').style.display = 'none';
|
|
|
+
|
|
|
+ // 加载所有必需数据
|
|
|
+ loadDocumentList();
|
|
|
+ await loadConfig();
|
|
|
+ initEditor();
|
|
|
+
|
|
|
+ // 立即加载真实系统数据
|
|
|
+ await refreshSystemStatus();
|
|
|
+ await loadUserStats();
|
|
|
+ await loadDockerStatus();
|
|
|
+
|
|
|
+ const lastSection = localStorage.getItem('currentSection') || 'dashboard';
|
|
|
+ showSection(lastSection);
|
|
|
+ } else {
|
|
|
+ throw new Error('会话检查失败');
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('初始化过程中出错:', error);
|
|
|
+ document.getElementById('loginModal').style.display = 'flex';
|
|
|
+ document.getElementById('loadingIndicator').style.display = 'none';
|
|
|
+ refreshCaptcha();
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ document.addEventListener('DOMContentLoaded', async function() {
|
|
|
+ try {
|
|
|
+ // 直接添加事件监听
|
|
|
+ document.getElementById('userCenterBtn').addEventListener('click', function() {
|
|
|
+ showSection('user-center');
|
|
|
+ });
|
|
|
+
|
|
|
+ document.getElementById('logoutBtn').addEventListener('click', logout);
|
|
|
+
|
|
|
+ document.getElementById('ucLogoutBtn').addEventListener('click', logout);
|
|
|
+
|
|
|
+ document.getElementById('saveSecurityBtn').addEventListener('click', saveSecuritySettings);
|
|
|
+
|
|
|
+ // 确保testDomain输入框可编辑
|
|
|
+ const testDomainInput = document.getElementById('testDomain');
|
|
|
+ testDomainInput.readOnly = false;
|
|
|
+ testDomainInput.addEventListener('input', function() {
|
|
|
+ document.getElementById('domainSelect').value = '';
|
|
|
+ });
|
|
|
+
|
|
|
+ // 控制面板卡片详情按钮
|
|
|
+ document.querySelectorAll('.dashboard-card .card-action').forEach(btn => {
|
|
|
+ btn.addEventListener('click', function() {
|
|
|
+ const cardTitle = this.closest('.dashboard-card').querySelector('.card-title').textContent.trim();
|
|
|
+ if (cardTitle === '磁盘空间') {
|
|
|
+ checkDiskSpace();
|
|
|
+ } else if (cardTitle === 'CPU 负载' || cardTitle === '系统内存') {
|
|
|
+ showSection('docker-monitoring');
|
|
|
+ } else if (cardTitle === '容器总数') {
|
|
|
+ showSection('docker-status');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ // 控制面板刷新按钮
|
|
|
+ document.querySelector('.welcome-action').addEventListener('click', refreshSystemStatus);
|
|
|
+
|
|
|
+ // 加载初始数据
|
|
|
+ const response = await fetch('/api/check-session');
|
|
|
+ if (response.ok) {
|
|
|
+ isLoggedIn = localStorage.getItem('isLoggedIn') === 'true';
|
|
|
+ if (isLoggedIn) {
|
|
|
+ loadDocumentList();
|
|
|
+ document.getElementById('adminContainer').style.display = 'flex';
|
|
|
+ await loadConfig();
|
|
|
+ initEditor();
|
|
|
+
|
|
|
+ // 立即加载真实系统数据
|
|
|
+ refreshSystemStatus();
|
|
|
+ loadUserStats();
|
|
|
+ loadDockerStatus();
|
|
|
+
|
|
|
+ const lastSection = localStorage.getItem('currentSection') || 'basic-config';
|
|
|
+ showSection(lastSection);
|
|
|
+ } else {
|
|
|
+ document.getElementById('loginModal').style.display = 'flex';
|
|
|
+ refreshCaptcha();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new Error('Session check failed');
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('Error during initialization:', error);
|
|
|
+ localStorage.removeItem('isLoggedIn');
|
|
|
+ document.getElementById('loginModal').style.display = 'flex';
|
|
|
+ refreshCaptcha();
|
|
|
+ } finally {
|
|
|
+ document.getElementById('loadingIndicator').style.display = 'none';
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ function updateAdImage(adImages) {
|
|
|
+ const adContainer = document.getElementById('adContainer');
|
|
|
+ adContainer.innerHTML = '';
|
|
|
+ if (adImages && adImages.length > 0) {
|
|
|
+ adImages.forEach(ad => {
|
|
|
+ const adLink = document.createElement('a');
|
|
|
+ adLink.href = ad.link;
|
|
|
+ adLink.target = '_blank';
|
|
|
+ const adImage = document.createElement('img');
|
|
|
+ adImage.src = ad.url;
|
|
|
+ adImage.alt = ad.alt || '广告图片';
|
|
|
+ adLink.appendChild(adImage);
|
|
|
+ adContainer.appendChild(adLink);
|
|
|
+ });
|
|
|
+
|
|
|
+ // 轮播功能
|
|
|
+ let currentAdIndex = 0;
|
|
|
+ setInterval(() => {
|
|
|
+ currentAdIndex = (currentAdIndex + 1) % adImages.length;
|
|
|
+ adImages.forEach((ad, index) => {
|
|
|
+ const adImage = adContainer.children[index];
|
|
|
+ if (index === currentAdIndex) {
|
|
|
+ adImage.style.display = 'block';
|
|
|
+ } else {
|
|
|
+ adImage.style.display = 'none';
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }, 5000); // 每5秒切换一次广告
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async function refreshCaptcha() {
|
|
|
+ try {
|
|
|
+ const response = await fetch('/api/captcha');
|
|
|
+ const data = await response.json();
|
|
|
+ document.getElementById('captchaText').textContent = data.captcha;
|
|
|
+ } catch (error) {
|
|
|
+ console.error('刷新验证码失败:', error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async function refreshDockerStatus() {
|
|
|
+ const spinner = document.getElementById('loadingSpinner');
|
|
|
+ const refreshButton = document.getElementById('refreshDockerStatusButton');
|
|
|
+ const table = document.getElementById('dockerStatusTable');
|
|
|
+
|
|
|
+ try {
|
|
|
+ spinner.style.display = 'block';
|
|
|
+ refreshButton.classList.add('disabled');
|
|
|
+ table.classList.add('disabled');
|
|
|
+
|
|
|
+ await loadDockerStatus();
|
|
|
+ } catch (error) {
|
|
|
+ console.error('刷新 Docker 状态失败:', error);
|
|
|
+ alert('刷新 Docker 状态失败: ' + error.message);
|
|
|
+ } finally {
|
|
|
+ spinner.style.display = 'none';
|
|
|
+ refreshButton.classList.remove('disabled');
|
|
|
+ table.classList.remove('disabled');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function saveDockerStatusToCache(containerStatus) {
|
|
|
+ localStorage.setItem('dockerStatus', JSON.stringify(containerStatus));
|
|
|
+ localStorage.setItem('dockerStatusTimestamp', Date.now());
|
|
|
+ }
|
|
|
+
|
|
|
+ function getDockerStatusFromCache() {
|
|
|
+ const cachedStatus = localStorage.getItem('dockerStatus');
|
|
|
+ const timestamp = localStorage.getItem('dockerStatusTimestamp');
|
|
|
+ if (cachedStatus && timestamp) {
|
|
|
+ // 检查缓存是否在过去5分钟内更新过
|
|
|
+ if (Date.now() - parseInt(timestamp) < 5 * 60 * 1000) {
|
|
|
+ return JSON.parse(cachedStatus);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ async function loadDockerStatus() {
|
|
|
+ const tbody = document.getElementById('dockerStatusTableBody');
|
|
|
+
|
|
|
+ // 尝试从缓存加载数据
|
|
|
+ const cachedStatus = getDockerStatusFromCache();
|
|
|
+ if (cachedStatus) {
|
|
|
+ renderDockerStatus(cachedStatus);
|
|
|
+ isDockerStatusLoaded = true;
|
|
|
+ } else if (!isDockerStatusLoaded) {
|
|
|
+ tbody.innerHTML = '<tr><td colspan="8" style="text-align: center;">加载中...</td></tr>';
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ const response = await fetch('/api/docker-status');
|
|
|
+ if (!response.ok) {
|
|
|
+ if (response.status === 503) {
|
|
|
+ throw new Error('无法连接到 Docker 守护进程');
|
|
|
+ }
|
|
|
+ throw new Error('Failed to fetch Docker status');
|
|
|
+ }
|
|
|
+ const containerStatus = await response.json();
|
|
|
+ renderDockerStatus(containerStatus);
|
|
|
+ isDockerStatusLoaded = true;
|
|
|
+ saveDockerStatusToCache(containerStatus);
|
|
|
+ } catch (error) {
|
|
|
+ console.error('Error loading Docker status:', error);
|
|
|
+ if (!cachedStatus) {
|
|
|
+ tbody.innerHTML = `<tr><td colspan="8" style="text-align: center; color: red;">${error.message}</td></tr>`;
|
|
|
+ }
|
|
|
+ isDockerStatusLoaded = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function renderDockerStatus(containerStatus) {
|
|
|
+ const table = document.getElementById('dockerStatusTable');
|
|
|
+ const thead = table.getElementsByTagName('thead')[0];
|
|
|
+ const tbody = document.getElementById('dockerStatusTableBody');
|
|
|
+
|
|
|
+ thead.innerHTML = `
|
|
|
+ <tr>
|
|
|
+ <th>容器 ID</th>
|
|
|
+ <th>名称</th>
|
|
|
+ <th>镜像</th>
|
|
|
+ <th>状态</th>
|
|
|
+ <th>CPU</th>
|
|
|
+ <th>内存</th>
|
|
|
+ <th>创建时间</th>
|
|
|
+ <th>操作</th>
|
|
|
+ </tr>
|
|
|
+ `;
|
|
|
+
|
|
|
+ tbody.innerHTML = '';
|
|
|
+
|
|
|
+ containerStatus.forEach(container => {
|
|
|
+ const row = `
|
|
|
+ <tr>
|
|
|
+ <td>${container.id}</td>
|
|
|
+ <td>${container.name}</td>
|
|
|
+ <td>${container.image}</td>
|
|
|
+ <td class="status-cell" id="status-${container.id}">
|
|
|
+ <div class="status-content">${container.state}</div>
|
|
|
+ </td>
|
|
|
+ <td>${container.cpu}</td>
|
|
|
+ <td>${container.memory}</td>
|
|
|
+ <td>${container.created}</td>
|
|
|
+ <td>
|
|
|
+ <select onchange="handleContainerAction('${container.id}', '${container.image}', this.value)" class="action-select">
|
|
|
+ <option value="">选择操作</option>
|
|
|
+ <option value="restart">重启</option>
|
|
|
+ <option value="stop">停止</option>
|
|
|
+ <option value="update">更新</option>
|
|
|
+ <option value="delete">删除</option>
|
|
|
+ <option value="logs">查看日志</option>
|
|
|
+ </select>
|
|
|
+ </td>
|
|
|
+ </tr>
|
|
|
+ `;
|
|
|
+ tbody.innerHTML += row;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ function handleContainerAction(id, image, action) {
|
|
|
+ switch(action) {
|
|
|
+ case 'restart':
|
|
|
+ restartContainer(id);
|
|
|
+ break;
|
|
|
+ case 'stop':
|
|
|
+ stopContainer(id);
|
|
|
+ break;
|
|
|
+ case 'update':
|
|
|
+ updateContainer(id, image);
|
|
|
+ break;
|
|
|
+ case 'logs':
|
|
|
+ viewLogs(id);
|
|
|
+ break;
|
|
|
+ case 'delete':
|
|
|
+ deleteContainer(id);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ // 重置选择框
|
|
|
+ document.querySelector(`select[onchange*="${id}"]`).value = "";
|
|
|
+ }
|
|
|
+
|
|
|
+ async function viewLogs(id) {
|
|
|
+ try {
|
|
|
+ // 创建模态框
|
|
|
+ const modal = document.createElement('div');
|
|
|
+ modal.style.position = 'fixed';
|
|
|
+ modal.style.left = '0';
|
|
|
+ modal.style.top = '0';
|
|
|
+ modal.style.width = '100%';
|
|
|
+ modal.style.height = '100%';
|
|
|
+ modal.style.backgroundColor = 'rgba(0,0,0,0.5)';
|
|
|
+ modal.style.display = 'flex';
|
|
|
+ modal.style.justifyContent = 'center';
|
|
|
+ modal.style.alignItems = 'center';
|
|
|
+ modal.style.zIndex = '1000';
|
|
|
+
|
|
|
+ const content = document.createElement('div');
|
|
|
+ content.style.backgroundColor = 'black';
|
|
|
+ content.style.color = 'white';
|
|
|
+ content.style.padding = '20px';
|
|
|
+ content.style.borderRadius = '5px';
|
|
|
+ content.style.width = '80%';
|
|
|
+ content.style.height = '80%';
|
|
|
+ content.style.display = 'flex';
|
|
|
+ content.style.flexDirection = 'column';
|
|
|
+ content.style.position = 'relative';
|
|
|
+
|
|
|
+ const logContent = document.createElement('pre');
|
|
|
+ logContent.style.flex = '1';
|
|
|
+ logContent.style.overflowY = 'auto';
|
|
|
+ logContent.style.padding = '10px';
|
|
|
+ logContent.style.backgroundColor = '#1e1e1e';
|
|
|
+ logContent.style.color = '#d4d4d4';
|
|
|
+ logContent.style.fontFamily = 'monospace';
|
|
|
+ logContent.style.fontSize = '14px';
|
|
|
+ logContent.style.lineHeight = '1.5';
|
|
|
+ logContent.style.whiteSpace = 'pre-wrap';
|
|
|
+ logContent.style.wordBreak = 'break-all';
|
|
|
+
|
|
|
+ const closeButton = document.createElement('button');
|
|
|
+ closeButton.textContent = '关闭';
|
|
|
+ closeButton.style.position = 'absolute';
|
|
|
+ closeButton.style.top = '10px';
|
|
|
+ closeButton.style.right = '10px';
|
|
|
+ closeButton.style.padding = '5px 10px';
|
|
|
+ closeButton.style.backgroundColor = '#4CAF50';
|
|
|
+ closeButton.style.color = 'white';
|
|
|
+ closeButton.style.border = 'none';
|
|
|
+ closeButton.style.borderRadius = '3px';
|
|
|
+ closeButton.style.cursor = 'pointer';
|
|
|
+
|
|
|
+ content.appendChild(logContent);
|
|
|
+ content.appendChild(closeButton);
|
|
|
+ modal.appendChild(content);
|
|
|
+ document.body.appendChild(modal);
|
|
|
+
|
|
|
+ // 使用 WebSocket 或长轮询获取日志
|
|
|
+ const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
|
+ let ws;
|
|
|
+
|
|
|
+ try {
|
|
|
+ ws = new WebSocket(`${protocol}//${window.location.host}/api/docker/logs/${id}`);
|
|
|
+
|
|
|
+ ws.onopen = () => {
|
|
|
+ logContent.textContent += "WebSocket 连接已建立,正在接收日志...\n";
|
|
|
+ };
|
|
|
+
|
|
|
+ ws.onmessage = (event) => {
|
|
|
+ const filteredData = event.data.replace(/[\x00-\x09\x0B-\x0C\x0E-\x1F\x7F-\x9F]/g, '');
|
|
|
+ logContent.textContent += filteredData;
|
|
|
+ logContent.scrollTop = logContent.scrollHeight;
|
|
|
+ };
|
|
|
+
|
|
|
+ ws.onerror = (error) => {
|
|
|
+ console.error('WebSocket错误:', error);
|
|
|
+ logContent.textContent += "WebSocket 连接错误,切换到长轮询模式...\n";
|
|
|
+ useLongPolling(id, logContent);
|
|
|
+ };
|
|
|
+
|
|
|
+ ws.onclose = () => {
|
|
|
+ logContent.textContent += "WebSocket 连接已关闭。\n";
|
|
|
+ };
|
|
|
+ } catch (error) {
|
|
|
+ console.error('WebSocket连接失败:', error);
|
|
|
+ logContent.textContent += "无法建立 WebSocket 连接,使用长轮询模式...\n";
|
|
|
+ useLongPolling(id, logContent);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 关闭按钮和模态框点击事件
|
|
|
+ closeButton.onclick = () => {
|
|
|
+ if (ws) ws.close();
|
|
|
+ document.body.removeChild(modal);
|
|
|
+ };
|
|
|
+
|
|
|
+ modal.onclick = (e) => {
|
|
|
+ if (e.target === modal) {
|
|
|
+ if (ws) ws.close();
|
|
|
+ document.body.removeChild(modal);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ } catch (error) {
|
|
|
+ console.error('查看日志失败:', error);
|
|
|
+ alert('查看日志失败: ' + error.message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function useLongPolling(id, logContent) {
|
|
|
+ let isPolling = true;
|
|
|
+
|
|
|
+ async function pollLogs() {
|
|
|
+ if (!isPolling) return;
|
|
|
+
|
|
|
+ try {
|
|
|
+ const response = await fetch(`/api/docker/logs-poll/${id}`);
|
|
|
+ if (!response.ok) throw new Error('获取日志失败');
|
|
|
+
|
|
|
+ const logs = await response.text();
|
|
|
+ logContent.textContent += logs;
|
|
|
+ logContent.scrollTop = logContent.scrollHeight;
|
|
|
+ } catch (error) {
|
|
|
+ console.error('轮询日志失败:', error);
|
|
|
+ logContent.textContent += "获取日志失败,请检查网络连接...\n";
|
|
|
+ }
|
|
|
+
|
|
|
+ // 继续轮询
|
|
|
+ setTimeout(pollLogs, 2000); // 每2秒轮询一次
|
|
|
+ }
|
|
|
+
|
|
|
+ pollLogs();
|
|
|
+
|
|
|
+ // 返回一个停止轮询的函数
|
|
|
+ return () => { isPolling = false; };
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ async function restartContainer(id) {
|
|
|
+ if (confirm('确定要重启这个容器吗?')) {
|
|
|
+ try {
|
|
|
+ const statusCell = document.getElementById(`status-${id}`);
|
|
|
+ statusCell.innerHTML = '<div class="loading-container"><div class="loading"></div></div>';
|
|
|
+
|
|
|
+ const response = await fetch(`/api/docker/restart/${id}`, { method: 'POST' });
|
|
|
+ if (response.ok) {
|
|
|
+ await new Promise(resolve => setTimeout(resolve, 2000)); // 等待2秒,确保状态已更新
|
|
|
+ const newStatus = await getContainerStatus(id);
|
|
|
+ statusCell.textContent = newStatus;
|
|
|
+ } else {
|
|
|
+ throw new Error('重启失败');
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('重启容器失败:', error);
|
|
|
+ alert('重启容器失败: ' + error.message);
|
|
|
+ loadDockerStatus(); // 重新加载所有容器状态
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async function stopContainer(id) {
|
|
|
+ if (confirm('确定要停止这个容器吗?')) {
|
|
|
+ try {
|
|
|
+ const statusCell = document.getElementById(`status-${id}`);
|
|
|
+ statusCell.innerHTML = '<div class="loading-container"><div class="loading"></div></div>';
|
|
|
+
|
|
|
+ const response = await fetch(`/api/docker/stop/${id}`, { method: 'POST' });
|
|
|
+ if (response.ok) {
|
|
|
+ await new Promise(resolve => setTimeout(resolve, 2000)); // 等待2秒,确保状态已更新
|
|
|
+ const newStatus = await getContainerStatus(id);
|
|
|
+ statusCell.innerHTML = `<div class="status-content">${newStatus}</div>`;
|
|
|
+ } else {
|
|
|
+ throw new Error('停止失败');
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('停止容器失败:', error);
|
|
|
+ alert('停止容器失败: ' + error.message);
|
|
|
+ loadDockerStatus(); // 重新加载所有容器状态
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async function getContainerStatus(id) {
|
|
|
+ const response = await fetch(`/api/docker/status/${id}`);
|
|
|
+ if (response.ok) {
|
|
|
+ const data = await response.json();
|
|
|
+ return data.state;
|
|
|
+ } else {
|
|
|
+ throw new Error('获取容器状态失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ async function updateContainer(id, currentImage) {
|
|
|
+ const tag = prompt(`请输入 ${currentImage} 的新标签:`, 'latest');
|
|
|
+ if (tag) {
|
|
|
+ try {
|
|
|
+ const statusCell = document.getElementById(`status-${id}`);
|
|
|
+ statusCell.textContent = 'Updating';
|
|
|
+ statusCell.style.color = 'orange';
|
|
|
+
|
|
|
+ const response = await fetch(`/api/docker/update/${id}`, {
|
|
|
+ method: 'POST',
|
|
|
+ headers: { 'Content-Type': 'application/json' },
|
|
|
+ body: JSON.stringify({ tag })
|
|
|
+ });
|
|
|
+
|
|
|
+ if (response.ok) {
|
|
|
+ const result = await response.json();
|
|
|
+ alert(result.message || '容器更新成功');
|
|
|
+ } else {
|
|
|
+ const errorData = await response.json();
|
|
|
+ throw new Error(errorData.error || '更新失败');
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('更新容器失败:', error);
|
|
|
+ alert('更新容器失败: ' + error.message);
|
|
|
+ } finally {
|
|
|
+ loadDockerStatus(); // 重新加载容器状态
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function refreshDockerStatus() {
|
|
|
+ isDockerStatusLoaded = false;
|
|
|
+ localStorage.removeItem('dockerStatus');
|
|
|
+ localStorage.removeItem('dockerStatusTimestamp');
|
|
|
+ loadDockerStatus();
|
|
|
+ }
|
|
|
+
|
|
|
+ async function deleteContainer(id) {
|
|
|
+ if (confirm('确定要删除这个容器吗?此操作不可逆。')) {
|
|
|
+ try {
|
|
|
+ const statusCell = document.getElementById(`status-${id}`);
|
|
|
+ statusCell.textContent = 'Deleting';
|
|
|
+ statusCell.style.color = 'red';
|
|
|
+
|
|
|
+ const response = await fetch(`/api/docker/delete/${id}`, { method: 'POST' });
|
|
|
+ if (response.ok) {
|
|
|
+ alert('容器删除成功');
|
|
|
+ loadDockerStatus(); // 重新加载容器状态
|
|
|
+ } else {
|
|
|
+ const errorData = await response.json();
|
|
|
+ throw new Error(errorData.error || '删除失败');
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('删除容器失败:', error);
|
|
|
+ alert('删除容器失败: ' + error.message);
|
|
|
+ loadDockerStatus(); // 重新加载所有容器状态
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ document.addEventListener('DOMContentLoaded', function() {
|
|
|
+ const sidebarItems = document.querySelectorAll('.sidebar li');
|
|
|
+ const contentSections = document.querySelectorAll('.content-section');
|
|
|
+ const testDomainInput = document.getElementById('testDomain');
|
|
|
+ const domainSelect = document.getElementById('domainSelect');
|
|
|
+
|
|
|
+ // 当选择预定义域名时,更新输入框
|
|
|
+ domainSelect.addEventListener('change', function() {
|
|
|
+ if (this.value) {
|
|
|
+ testDomainInput.value = this.value;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 当输入框获得焦点时,清空选择框
|
|
|
+ testDomainInput.addEventListener('focus', function() {
|
|
|
+ domainSelect.value = '';
|
|
|
+ });
|
|
|
+
|
|
|
+ // docker监控
|
|
|
+ loadContainers();
|
|
|
+ loadMonitoringConfig();
|
|
|
+
|
|
|
+ // 绑定测试通知按钮的点击事件
|
|
|
+ document.querySelector('#docker-monitoring button:nth-of-type(1)').addEventListener('click', testNotification);
|
|
|
+
|
|
|
+ // 绑定保存配置按钮的点击事件
|
|
|
+ document.querySelector('#docker-monitoring button:nth-of-type(2)').addEventListener('click', saveMonitoringConfig);
|
|
|
+
|
|
|
+ // 绑定开启/关闭监控按钮的点击事件
|
|
|
+ document.querySelector('#docker-monitoring button:nth-of-type(3)').addEventListener('click', toggleMonitoring);
|
|
|
+
|
|
|
+ // 为通知类型下拉框添加变更事件监听器
|
|
|
+ document.getElementById('notificationType').addEventListener('change', toggleNotificationFields);
|
|
|
+
|
|
|
+ refreshStoppedContainers(); // 初始加载已停止的容器
|
|
|
+
|
|
|
+ // 网络测试函数
|
|
|
+ function runNetworkTest() {
|
|
|
+ const domain = testDomainInput.value.trim();
|
|
|
+ const testType = document.getElementById('testType').value;
|
|
|
+ const resultsDiv = document.getElementById('testResults');
|
|
|
+
|
|
|
+ // 验证输入
|
|
|
+ if (!domain) {
|
|
|
+ alert('请输入目标域名或IP地址');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证域名格式
|
|
|
+ const domainRegex = /^(?!:\/\/)(?=.{1,255}$)((.{1,63}\.){1,127}(?![0-9]*$)[a-z0-9-]+\.?)$/i;
|
|
|
+ // 验证IPv4格式
|
|
|
+ const ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
|
|
+ // 验证IPv6格式
|
|
|
+ const ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
|
|
|
+
|
|
|
+ // 检查是否为预定义的选项之一
|
|
|
+ const predefinedOptions = [
|
|
|
+ 'gcr.io', 'ghcr.io', 'quay.io', 'k8s.gcr.io', 'registry.k8s.io',
|
|
|
+ 'mcr.microsoft.com', 'docker.elastic.com', 'registry-1.docker.io'
|
|
|
+ ];
|
|
|
+
|
|
|
+ if (!predefinedOptions.includes(domain) &&
|
|
|
+ !domainRegex.test(domain) &&
|
|
|
+ !ipv4Regex.test(domain) &&
|
|
|
+ !ipv6Regex.test(domain)) {
|
|
|
+ alert('请输入有效的域名或IP地址');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ resultsDiv.innerHTML = '测试中,请稍候...';
|
|
|
+
|
|
|
+ const controller = new AbortController();
|
|
|
+ const timeoutId = setTimeout(() => controller.abort(), 60000); // 60秒超时
|
|
|
+
|
|
|
+ fetch('/api/network-test', {
|
|
|
+ method: 'POST',
|
|
|
+ headers: {
|
|
|
+ 'Content-Type': 'application/json',
|
|
|
+ },
|
|
|
+ body: JSON.stringify({ domain, testType }),
|
|
|
+ signal: controller.signal
|
|
|
+ })
|
|
|
+ .then(response => {
|
|
|
+ clearTimeout(timeoutId);
|
|
|
+ if (!response.ok) {
|
|
|
+ throw new Error('网络测试失败');
|
|
|
+ }
|
|
|
+ return response.text();
|
|
|
+ })
|
|
|
+ .then(result => {
|
|
|
+ resultsDiv.textContent = result;
|
|
|
+ })
|
|
|
+ .catch(error => {
|
|
|
+ console.error('网络测试出错:', error);
|
|
|
+ if (error.name === 'AbortError') {
|
|
|
+ resultsDiv.textContent = '测试超时,请稍后再试';
|
|
|
+ } else {
|
|
|
+ resultsDiv.textContent = '测试失败: ' + error.message;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 绑定测试按钮点击事件
|
|
|
+ document.querySelector('#network-test button').addEventListener('click', runNetworkTest);
|
|
|
+
|
|
|
+
|
|
|
+ let isDockerStatusLoaded = false;
|
|
|
+
|
|
|
+ function showSection(sectionId) {
|
|
|
+ contentSections.forEach(section => {
|
|
|
+ if (section.id === sectionId) {
|
|
|
+ section.classList.add('active');
|
|
|
+ if (sectionId === 'docker-status') {
|
|
|
+ loadDockerStatus(); // 每次显示 Docker 状态部分时都尝试加载
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ section.classList.remove('active');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ localStorage.setItem('currentSection', sectionId);
|
|
|
+
|
|
|
+ // 更新侧边栏active状态
|
|
|
+ sidebarItems.forEach(item => {
|
|
|
+ if (item.getAttribute('data-section') === sectionId) {
|
|
|
+ item.classList.add('active');
|
|
|
+ } else {
|
|
|
+ item.classList.remove('active');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ sidebarItems.forEach(item => {
|
|
|
+ item.addEventListener('click', function() {
|
|
|
+ const sectionId = this.getAttribute('data-section');
|
|
|
+ showSection(sectionId);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ // docker 监控
|
|
|
+ // 显示消息
|
|
|
+ function showMessage(message, isError = false) {
|
|
|
+ const messageContainer = document.getElementById('messageContainer');
|
|
|
+ const messageElement = document.createElement('div');
|
|
|
+ messageElement.textContent = message;
|
|
|
+ messageElement.className = isError ? 'error-message' : 'success-message';
|
|
|
+ messageContainer.appendChild(messageElement);
|
|
|
+ setTimeout(() => messageElement.remove(), 3000);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 加载容器列表
|
|
|
+ async function loadContainers() {
|
|
|
+ try {
|
|
|
+ const response = await fetch('/api/stopped-containers');
|
|
|
+ const containers = await response.json();
|
|
|
+ renderStoppedContainers(containers);
|
|
|
+ } catch (error) {
|
|
|
+ showMessage('加载容器列表失败: ' + error.message, true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 确保在页面加载时调用 loadContainers
|
|
|
+ document.addEventListener('DOMContentLoaded', loadContainers);
|
|
|
+
|
|
|
+ // 切换单个容器的监控状态
|
|
|
+ async function toggleContainerMonitoring(containerId, isMonitored) {
|
|
|
+ try {
|
|
|
+ const response = await fetch(`/api/container/${containerId}/monitor`, {
|
|
|
+ method: 'POST',
|
|
|
+ headers: { 'Content-Type': 'application/json' },
|
|
|
+ body: JSON.stringify({ isMonitored })
|
|
|
+ });
|
|
|
+ if (response.ok) {
|
|
|
+ showMessage(`容器 ${containerId} 监控状态已${isMonitored ? '开启' : '关闭'}`);
|
|
|
+ } else {
|
|
|
+ throw new Error('操作失败');
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ showMessage(`切换容器监控状态失败: ${error.message}`, true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function toggleNotificationFields() {
|
|
|
+ const notificationType = document.getElementById('notificationType').value;
|
|
|
+ const wechatFields = document.getElementById('wechatFields');
|
|
|
+ const telegramFields = document.getElementById('telegramFields');
|
|
|
+
|
|
|
+ if (notificationType === 'wechat') {
|
|
|
+ wechatFields.style.display = 'block';
|
|
|
+ telegramFields.style.display = 'none';
|
|
|
+ } else if (notificationType === 'telegram') {
|
|
|
+ wechatFields.style.display = 'none';
|
|
|
+ telegramFields.style.display = 'block';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async function testNotification() {
|
|
|
+ const notificationType = document.getElementById('notificationType').value;
|
|
|
+ let data = {
|
|
|
+ notificationType: notificationType,
|
|
|
+ monitorInterval: document.getElementById('monitorInterval').value
|
|
|
+ };
|
|
|
+
|
|
|
+ if (notificationType === 'wechat') {
|
|
|
+ data.webhookUrl = document.getElementById('webhookUrl').value;
|
|
|
+ } else if (notificationType === 'telegram') {
|
|
|
+ data.telegramToken = document.getElementById('telegramToken').value;
|
|
|
+ data.telegramChatId = document.getElementById('telegramChatId').value;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ const response = await fetch('/api/test-notification', {
|
|
|
+ method: 'POST',
|
|
|
+ headers: { 'Content-Type': 'application/json' },
|
|
|
+ body: JSON.stringify(data)
|
|
|
+ });
|
|
|
+
|
|
|
+ if (response.ok) {
|
|
|
+ const result = await response.json();
|
|
|
+ showMessage(result.message || '通知测试成功!');
|
|
|
+ } else {
|
|
|
+ const errorData = await response.json();
|
|
|
+ throw new Error(errorData.error || '测试失败');
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ showMessage('通知测试失败: ' + error.message, true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 修改保存配置的函数
|
|
|
+ async function saveMonitoringConfig() {
|
|
|
+ const notificationType = document.getElementById('notificationType').value;
|
|
|
+ let data = {
|
|
|
+ notificationType: notificationType,
|
|
|
+ monitorInterval: document.getElementById('monitorInterval').value,
|
|
|
+ isEnabled: document.getElementById('monitoringStatus').textContent === '已开启',
|
|
|
+ webhookUrl: document.getElementById('webhookUrl').value,
|
|
|
+ telegramToken: document.getElementById('telegramToken').value,
|
|
|
+ telegramChatId: document.getElementById('telegramChatId').value
|
|
|
+ };
|
|
|
+
|
|
|
+ try {
|
|
|
+ const response = await fetch('/api/monitoring-config', {
|
|
|
+ method: 'POST',
|
|
|
+ headers: { 'Content-Type': 'application/json' },
|
|
|
+ body: JSON.stringify(data)
|
|
|
+ });
|
|
|
+ if (response.ok) {
|
|
|
+ showMessage('监控配置已保存');
|
|
|
+ } else {
|
|
|
+ throw new Error('保存失败');
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ showMessage('保存监控配置失败: ' + error.message, true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async function toggleMonitoring() {
|
|
|
+ const currentStatus = document.getElementById('monitoringStatus').textContent;
|
|
|
+ const newStatus = currentStatus === '已开启' ? false : true;
|
|
|
+
|
|
|
+ try {
|
|
|
+ const response = await fetch('/api/toggle-monitoring', {
|
|
|
+ method: 'POST',
|
|
|
+ headers: { 'Content-Type': 'application/json' },
|
|
|
+ body: JSON.stringify({ isEnabled: newStatus })
|
|
|
+ });
|
|
|
+ if (response.ok) {
|
|
|
+ const result = await response.json();
|
|
|
+ if (result.success) {
|
|
|
+ updateMonitoringStatus(newStatus);
|
|
|
+ showMessage(newStatus ? '监控已开启' : '监控已关闭');
|
|
|
+ } else {
|
|
|
+ throw new Error(result.message || '操作失败');
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new Error('切换失败');
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ showMessage('切换监控状态失败: ' + error.message, true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 加载监控配置
|
|
|
+ async function loadMonitoringConfig() {
|
|
|
+ try {
|
|
|
+ const response = await fetch('/api/monitoring-config');
|
|
|
+ const config = await response.json();
|
|
|
+
|
|
|
+ document.getElementById('notificationType').value = config.notificationType || 'wechat';
|
|
|
+ document.getElementById('webhookUrl').value = config.webhookUrl || '';
|
|
|
+ document.getElementById('telegramToken').value = config.telegramToken || '';
|
|
|
+ document.getElementById('telegramChatId').value = config.telegramChatId || '';
|
|
|
+ document.getElementById('monitorInterval').value = config.monitorInterval || 60;
|
|
|
+
|
|
|
+ updateMonitoringStatus(config.isEnabled);
|
|
|
+ toggleNotificationFields(); // 确保根据加载的配置显示正确的字段
|
|
|
+ } catch (error) {
|
|
|
+ showMessage('加载监控配置失败: ' + error.message, true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新监控状态显示
|
|
|
+ function updateMonitoringStatus(isEnabled) {
|
|
|
+ const statusElement = document.getElementById('monitoringStatus');
|
|
|
+ statusElement.textContent = isEnabled ? '已开启' : '已关闭';
|
|
|
+ statusElement.style.color = isEnabled ? 'green' : 'red';
|
|
|
+ document.getElementById('toggleMonitoringBtn').textContent = isEnabled ? '关闭监控' : '开启监控';
|
|
|
+ }
|
|
|
+
|
|
|
+ async function refreshStoppedContainers() {
|
|
|
+ const spinner = document.getElementById('loadingSpinner');
|
|
|
+ const refreshButton = document.querySelector('#docker-monitoring button:last-child');
|
|
|
+ const table = document.getElementById('stoppedContainersTable');
|
|
|
+
|
|
|
+ try {
|
|
|
+ spinner.style.display = 'block';
|
|
|
+ refreshButton.disabled = true;
|
|
|
+ table.classList.add('disabled');
|
|
|
+
|
|
|
+ const response = await fetch('/api/refresh-stopped-containers');
|
|
|
+ if (!response.ok) {
|
|
|
+ throw new Error('Failed to fetch stopped containers');
|
|
|
+ }
|
|
|
+ const containers = await response.json();
|
|
|
+ renderStoppedContainers(containers);
|
|
|
+ showMessage('已停止的容器状态已刷新', false);
|
|
|
+ } catch (error) {
|
|
|
+ console.error('Error refreshing stopped containers:', error);
|
|
|
+ showMessage('刷新已停止的容器状态失败: ' + error.message, true);
|
|
|
+ } finally {
|
|
|
+ spinner.style.display = 'none';
|
|
|
+ refreshButton.disabled = false;
|
|
|
+ table.classList.remove('disabled');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function renderStoppedContainers(containers) {
|
|
|
+ const tbody = document.getElementById('stoppedContainersBody');
|
|
|
+ tbody.innerHTML = '';
|
|
|
+
|
|
|
+ if (containers.length === 0) {
|
|
|
+ tbody.innerHTML = '<tr><td colspan="3">没有已停止的容器</td></tr>';
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ containers.forEach(container => {
|
|
|
+ const row = `
|
|
|
+ <tr>
|
|
|
+ <td>${container.id}</td>
|
|
|
+ <td>${container.name}</td>
|
|
|
+ <td>${container.status}</td>
|
|
|
+ </tr>
|
|
|
+ `;
|
|
|
+ tbody.innerHTML += row;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 确保在页面加载时初始化停止的容器列表
|
|
|
+ document.addEventListener('DOMContentLoaded', () => {
|
|
|
+ loadMonitoringConfig();
|
|
|
+ document.getElementById('notificationType').addEventListener('change', toggleNotificationFields);
|
|
|
+ });
|
|
|
+
|
|
|
+ // 页面加载时初始化
|
|
|
+ window.addEventListener('load', () => {
|
|
|
+ loadMonitoringConfig();
|
|
|
+ loadContainers();
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ // 页面加载时检查登录状态
|
|
|
+ window.onload = async function() {
|
|
|
+ try {
|
|
|
+ const response = await fetch('/api/check-session');
|
|
|
+ if (response.ok) {
|
|
|
+ isLoggedIn = localStorage.getItem('isLoggedIn') === 'true';
|
|
|
+ if (isLoggedIn) {
|
|
|
+ loadDocumentList();
|
|
|
+ document.getElementById('adminContainer').style.display = 'flex';
|
|
|
+ await loadConfig();
|
|
|
+ initEditor();
|
|
|
+
|
|
|
+ const lastSection = localStorage.getItem('currentSection') || 'basic-config';
|
|
|
+ showSection(lastSection);
|
|
|
+
|
|
|
+ // 立即尝试加载 Docker 状态
|
|
|
+ loadDockerStatus();
|
|
|
+ } else {
|
|
|
+ document.getElementById('loginModal').style.display = 'flex';
|
|
|
+ refreshCaptcha();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new Error('Session check failed');
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('Error during initialization:', error);
|
|
|
+ localStorage.removeItem('isLoggedIn');
|
|
|
+ document.getElementById('loginModal').style.display = 'flex';
|
|
|
+ refreshCaptcha();
|
|
|
+ } finally {
|
|
|
+ document.getElementById('loadingIndicator').style.display = 'none';
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ // 为按钮添加交互反馈效果
|
|
|
+ document.addEventListener('DOMContentLoaded', function() {
|
|
|
+ // 为所有按钮添加点击反馈
|
|
|
+ const buttons = document.querySelectorAll('button');
|
|
|
+ buttons.forEach(button => {
|
|
|
+ button.addEventListener('click', function() {
|
|
|
+ // 添加波纹效果
|
|
|
+ const ripple = document.createElement('span');
|
|
|
+ ripple.classList.add('ripple');
|
|
|
+ this.appendChild(ripple);
|
|
|
+
|
|
|
+ // 设置波纹位置
|
|
|
+ const rect = this.getBoundingClientRect();
|
|
|
+ ripple.style.left = '50%';
|
|
|
+ ripple.style.top = '50%';
|
|
|
+
|
|
|
+ // 移除波纹
|
|
|
+ setTimeout(() => {
|
|
|
+ ripple.remove();
|
|
|
+ }, 600);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ // 增强表单交互
|
|
|
+ const inputs = document.querySelectorAll('input, select');
|
|
|
+ inputs.forEach(input => {
|
|
|
+ // 聚焦时添加类
|
|
|
+ input.addEventListener('focus', function() {
|
|
|
+ this.parentElement.classList.add('focused');
|
|
|
+ });
|
|
|
+
|
|
|
+ // 失焦时移除类
|
|
|
+ input.addEventListener('blur', function() {
|
|
|
+ this.parentElement.classList.remove('focused');
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ // 修复网络测试页面不能手动输入域名问题
|
|
|
+ const testDomainInput = document.getElementById('testDomain');
|
|
|
+ if (testDomainInput) {
|
|
|
+ testDomainInput.removeAttribute('readonly'); // 移除只读属性
|
|
|
+ testDomainInput.addEventListener('input', function() {
|
|
|
+ const domainSelect = document.getElementById('domainSelect');
|
|
|
+ if (this.value && domainSelect) {
|
|
|
+ domainSelect.value = '';
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 修复用户中心页面按钮图标问题
|
|
|
+ const userCenterSaveBtn = document.querySelector('.user-center-section button.btn.btn-primary');
|
|
|
+ if (userCenterSaveBtn) {
|
|
|
+ userCenterSaveBtn.innerHTML = '保存设置';
|
|
|
+ }
|
|
|
+
|
|
|
+ const userCenterLogoutBtn = document.querySelector('.user-center-header .btn.btn-primary');
|
|
|
+ if (userCenterLogoutBtn) {
|
|
|
+ userCenterLogoutBtn.innerHTML = '退出登录';
|
|
|
+ }
|
|
|
+
|
|
|
+ // 修复控制面板详情按钮
|
|
|
+ const dashboardDetailBtns = document.querySelectorAll('.dashboard-card .card-action');
|
|
|
+ dashboardDetailBtns.forEach(btn => {
|
|
|
+ btn.addEventListener('click', function() {
|
|
|
+ const cardTitle = this.closest('.dashboard-card').querySelector('.card-title').textContent.trim();
|
|
|
+ if (cardTitle === '磁盘空间') {
|
|
|
+ checkDiskSpace();
|
|
|
+ } else if (cardTitle === 'CPU 负载' || cardTitle === '系统内存') {
|
|
|
+ showSection('docker-monitoring');
|
|
|
+ } else if (cardTitle === '容器总数') {
|
|
|
+ showSection('docker-status');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ // 替换原有的alert弹窗
|
|
|
+ function showAlert(message, type = 'info') {
|
|
|
+ Swal.fire({
|
|
|
+ title: type === 'error' ? '错误' : '提示',
|
|
|
+ text: message,
|
|
|
+ icon: type,
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ confirmButtonColor: '#3D7CF4'
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 替换原有的confirm弹窗
|
|
|
+ function showConfirm(message, callback) {
|
|
|
+ Swal.fire({
|
|
|
+ title: '确认操作',
|
|
|
+ text: message,
|
|
|
+ icon: 'question',
|
|
|
+ showCancelButton: true,
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ confirmButtonColor: '#3D7CF4',
|
|
|
+ cancelButtonColor: '#6C757D'
|
|
|
+ }).then((result) => {
|
|
|
+ if (result.isConfirmed) {
|
|
|
+ callback();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 覆盖默认的 alert 和 confirm
|
|
|
+ const originalAlert = window.alert;
|
|
|
+ window.alert = function(message) {
|
|
|
+ showAlert(message, message.toLowerCase().includes('失败') || message.toLowerCase().includes('错误') ? 'error' : 'success');
|
|
|
+ };
|
|
|
+
|
|
|
+ const originalConfirm = window.confirm;
|
|
|
+ window.confirm = function(message) {
|
|
|
+ return new Promise((resolve) => {
|
|
|
+ showConfirm(message, () => resolve(true));
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ // 增强操作交互
|
|
|
+ function handleContainerAction(id, image, action) {
|
|
|
+ if (action === '') return;
|
|
|
+
|
|
|
+ // 原有的 switch 语句处理
|
|
|
+ switch(action) {
|
|
|
+ case 'restart':
|
|
|
+ showConfirm(`确定要重启容器 ${id} 吗?`, () => restartContainer(id));
|
|
|
+ break;
|
|
|
+ case 'stop':
|
|
|
+ showConfirm(`确定要停止容器 ${id} 吗?`, () => stopContainer(id));
|
|
|
+ break;
|
|
|
+ case 'update':
|
|
|
+ updateContainer(id, image);
|
|
|
+ break;
|
|
|
+ case 'logs':
|
|
|
+ viewLogs(id);
|
|
|
+ break;
|
|
|
+ case 'delete':
|
|
|
+ showConfirm(`确定要删除容器 ${id} 吗?此操作不可逆。`, () => deleteContainer(id));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 重置选择框
|
|
|
+ document.querySelector(`select[onchange*="${id}"]`).value = "";
|
|
|
+ }
|
|
|
+
|
|
|
+ // 美化表单提交
|
|
|
+ async function saveDocument() {
|
|
|
+ const title = document.getElementById('documentTitle').value.trim();
|
|
|
+ const content = editor.getMarkdown();
|
|
|
+
|
|
|
+ if (!title) {
|
|
|
+ showAlert('请输入文档标题', 'error');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 显示保存中状态
|
|
|
+ Swal.fire({
|
|
|
+ title: '正在保存',
|
|
|
+ text: '请稍候...',
|
|
|
+ allowOutsideClick: false,
|
|
|
+ didOpen: () => {
|
|
|
+ Swal.showLoading();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ try {
|
|
|
+ const response = await fetch('/api/documentation', {
|
|
|
+ method: 'POST',
|
|
|
+ headers: { 'Content-Type': 'application/json' },
|
|
|
+ body: JSON.stringify({
|
|
|
+ id: currentEditingDoc ? currentEditingDoc.id : null,
|
|
|
+ title,
|
|
|
+ content
|
|
|
+ })
|
|
|
+ });
|
|
|
+
|
|
|
+ if (response.ok) {
|
|
|
+ Swal.fire({
|
|
|
+ title: '保存成功',
|
|
|
+ icon: 'success',
|
|
|
+ timer: 1500,
|
|
|
+ showConfirmButton: false
|
|
|
+ }).then(() => {
|
|
|
+ hideEditor();
|
|
|
+ loadDocumentList();
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ throw new Error('保存失败');
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('保存文档失败:', error);
|
|
|
+ showAlert('保存文档失败: ' + error.message, 'error');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ async function logout() {
|
|
|
+ console.log("执行退出登录操作");
|
|
|
+ try {
|
|
|
+ const response = await fetch('/api/logout', {
|
|
|
+ method: 'POST',
|
|
|
+ headers: { 'Content-Type': 'application/json' }
|
|
|
+ });
|
|
|
+
|
|
|
+ if (response.ok) {
|
|
|
+ console.log("退出登录成功");
|
|
|
+ // 不再操作localStorage
|
|
|
+ window.location.reload(); // 直接刷新页面
|
|
|
+ } else {
|
|
|
+ throw new Error('退出登录失败');
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('退出登录失败:', error);
|
|
|
+ alert('退出登录失败: ' + error.message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 控制面板相关函数
|
|
|
+ async function refreshSystemStatus() {
|
|
|
+ console.log("刷新系统状态,获取真实数据");
|
|
|
+ try {
|
|
|
+ const response = await fetch('/api/system-stats');
|
|
|
+ if (!response.ok) {
|
|
|
+ throw new Error('获取系统状态失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ const data = await response.json();
|
|
|
+ console.log("获取到系统数据:", data);
|
|
|
+
|
|
|
+ // 更新控制面板数据
|
|
|
+ document.getElementById('totalContainers').textContent = data.containerCount || '0';
|
|
|
+ document.getElementById('systemMemory').textContent = data.memoryUsage || '0%';
|
|
|
+ document.getElementById('cpuLoad').textContent = data.cpuLoad || '0%';
|
|
|
+ document.getElementById('diskSpace').textContent = data.diskSpace || '0%';
|
|
|
+
|
|
|
+ // 更新最近活动表
|
|
|
+ updateRecentActivities(data.recentActivities || []);
|
|
|
+ } catch (error) {
|
|
|
+ console.error('刷新系统状态失败:', error);
|
|
|
+ alert('刷新系统状态失败: ' + error.message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新最近活动表
|
|
|
+ function updateRecentActivities(activities) {
|
|
|
+ const tbody = document.getElementById('recentActivitiesBody');
|
|
|
+ tbody.innerHTML = '';
|
|
|
+
|
|
|
+ if (activities.length === 0) {
|
|
|
+ tbody.innerHTML = '<tr><td colspan="4" style="text-align: center;">暂无活动记录</td></tr>';
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ activities.forEach(activity => {
|
|
|
+ const row = document.createElement('tr');
|
|
|
+ row.innerHTML = `
|
|
|
+ <td>${activity.time}</td>
|
|
|
+ <td>${activity.action}</td>
|
|
|
+ <td>${activity.container}</td>
|
|
|
+ <td>${activity.status}</td>
|
|
|
+ `;
|
|
|
+ tbody.appendChild(row);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 加载用户统计数据
|
|
|
+ async function loadUserStats() {
|
|
|
+ try {
|
|
|
+ const response = await fetch('/api/user-info');
|
|
|
+ if (!response.ok) {
|
|
|
+ throw new Error('获取用户信息失败');
|
|
|
+ }
|
|
|
+ const data = await response.json();
|
|
|
+
|
|
|
+ // 更新用户统计数据
|
|
|
+ document.getElementById('loginCount').textContent = data.loginCount || '0';
|
|
|
+ document.getElementById('lastLogin').textContent = data.lastLogin || '未知';
|
|
|
+ document.getElementById('accountAge').textContent = data.accountAge || '0';
|
|
|
+
|
|
|
+ // 更新欢迎信息
|
|
|
+ document.getElementById('welcomeUsername').textContent = data.username || '管理员';
|
|
|
+ document.getElementById('currentUsername').textContent = data.username || '管理员';
|
|
|
+ } catch (error) {
|
|
|
+ console.error('加载用户统计数据失败:', error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 安全设置保存函数
|
|
|
+ function saveSecuritySettings() {
|
|
|
+ console.log("保存安全设置");
|
|
|
+ const loginNotification = document.getElementById('loginNotification').value;
|
|
|
+ alert('安全设置已保存');
|
|
|
+ // 这里可以添加实际的API调用来保存设置
|
|
|
+ }
|
|
|
+
|
|
|
+ document.addEventListener('DOMContentLoaded', function() {
|
|
|
+ const sidebarItems = document.querySelectorAll('.sidebar li');
|
|
|
+ const contentSections = document.querySelectorAll('.content-section');
|
|
|
+ const testDomainInput = document.getElementById('testDomain');
|
|
|
+ const domainSelect = document.getElementById('domainSelect');
|
|
|
+
|
|
|
+ // 加载系统真实数据
|
|
|
+ refreshSystemStatus();
|
|
|
+ // 加载用户统计数据
|
|
|
+ loadUserStats();
|
|
|
+
|
|
|
+ // 当选择预定义域名时,更新输入框
|
|
|
+ domainSelect.addEventListener('change', function() {
|
|
|
+ if (this.value) {
|
|
|
+ testDomainInput.value = this.value;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 修复: 允许手动输入域名
|
|
|
+ testDomainInput.removeAttribute('readonly');
|
|
|
+ testDomainInput.addEventListener('input', function() {
|
|
|
+ if (this.value) {
|
|
|
+ domainSelect.value = '';
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 覆盖默认的 alert 和 confirm
|
|
|
+ const originalAlert = window.alert;
|
|
|
+ window.alert = function(message) {
|
|
|
+ showAlert(message, message.toLowerCase().includes('失败') || message.toLowerCase().includes('错误') ? 'error' : 'success');
|
|
|
+ };
|
|
|
+
|
|
|
+ const originalConfirm = window.confirm;
|
|
|
+ window.confirm = function(message) {
|
|
|
+ return new Promise((resolve) => {
|
|
|
+ showConfirm(message, () => resolve(true));
|
|
|
+ });
|
|
|
+ };
|
|
|
+ });
|
|
|
+
|
|
|
+ // 修复: 在DOM加载完成时添加额外的事件监听器
|
|
|
+ document.addEventListener('DOMContentLoaded', function() {
|
|
|
+ // 控制面板刷新按钮
|
|
|
+ document.querySelector('.welcome-action').addEventListener('click', function() {
|
|
|
+ refreshSystemStatus();
|
|
|
+ });
|
|
|
+
|
|
|
+ // 磁盘空间详情按钮
|
|
|
+ const diskSpaceAction = document.querySelector('.dashboard-card:nth-child(4) .card-action');
|
|
|
+ if (diskSpaceAction) {
|
|
|
+ diskSpaceAction.addEventListener('click', checkDiskSpace);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 绑定个人中心和退出登录按钮事件
|
|
|
+ const userCenterBtn = document.querySelector('.user-action-btn:not(.logout)');
|
|
|
+ if (userCenterBtn) {
|
|
|
+ userCenterBtn.addEventListener('click', function() {
|
|
|
+ showSection('user-center');
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ const logoutBtn = document.querySelector('.user-action-btn.logout');
|
|
|
+ if (logoutBtn) {
|
|
|
+ logoutBtn.addEventListener('click', logout);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 用户中心内的退出登录按钮
|
|
|
+ const userCenterLogoutBtn = document.querySelector('.user-center-header .btn.btn-primary');
|
|
|
+ if (userCenterLogoutBtn) {
|
|
|
+ userCenterLogoutBtn.innerHTML = '退出登录';
|
|
|
+ userCenterLogoutBtn.addEventListener('click', logout);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 用户中心内的保存设置按钮
|
|
|
+ const userCenterSaveBtn = document.querySelector('.user-center-section .btn.btn-primary');
|
|
|
+ if (userCenterSaveBtn) {
|
|
|
+ userCenterSaveBtn.innerHTML = '保存设置';
|
|
|
+ userCenterSaveBtn.addEventListener('click', saveSecuritySettings);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ </script>
|
|
|
+</body>
|
|
|
+</html>
|