初始提交 - FutureOSS v1.0 插件化运行时框架

一切皆为插件的开发者工具运行时框架

🧩 核心特性:
  - 插件热插拔 (importlib 动态加载)
  - 依赖自动解析 (拓扑排序 + 循环检测)
  - 企业级稳定 (熔断/降级/重试/隔离)
  - 事件驱动 (发布/订阅事件总线)
  - 完整配置 (YAML 配置 + 热重载)
This commit is contained in:
Falck
2026-04-06 09:57:10 +08:00
commit 76147bae94
174 changed files with 15626 additions and 0 deletions

View File

@@ -0,0 +1,363 @@
/* ============================================
OSS Community 认证页面样式
与官网风格保持一致
============================================ */
/* 认证页面布局 */
.auth-page {
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
padding: 40px 20px;
margin-left: 80px;
position: relative;
z-index: 1;
}
.auth-container {
width: 100%;
max-width: 480px;
position: relative;
}
/* 认证卡片 */
.auth-card {
background: rgba(15, 23, 42, 0.8);
backdrop-filter: blur(20px);
border: 1px solid rgba(99, 102, 241, 0.2);
border-radius: 16px;
padding: 40px;
box-shadow:
0 20px 60px rgba(0, 0, 0, 0.5),
0 0 0 1px rgba(99, 102, 241, 0.1),
inset 0 1px 0 rgba(255, 255, 255, 0.05);
animation: cardSlideUp 0.6s ease-out;
}
@keyframes cardSlideUp {
from {
opacity: 0;
transform: translateY(30px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
/* 认证头部 */
.auth-header {
text-align: center;
margin-bottom: 32px;
}
.auth-logo {
width: 64px;
height: 64px;
margin: 0 auto 20px;
background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
border-radius: 16px;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 8px 24px rgba(99, 102, 241, 0.4);
}
.auth-logo svg {
width: 32px;
height: 32px;
color: white;
}
.auth-title {
font-size: 28px;
font-weight: 700;
margin: 0 0 8px 0;
background: linear-gradient(135deg, #e0e7ff 0%, #c7d2fe 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.auth-subtitle {
color: #94a3b8;
font-size: 14px;
margin: 0;
}
/* 表单样式 */
.auth-form {
display: flex;
flex-direction: column;
gap: 20px;
}
.form-group {
display: flex;
flex-direction: column;
gap: 8px;
}
.form-label {
font-size: 14px;
font-weight: 500;
color: #e2e8f0;
}
.input-wrapper {
position: relative;
display: flex;
align-items: center;
}
.input-icon {
position: absolute;
left: 14px;
width: 18px;
height: 18px;
color: #64748b;
pointer-events: none;
transition: color 0.2s;
}
.form-input {
width: 100%;
padding: 12px 14px 12px 44px;
background: rgba(30, 41, 59, 0.6);
border: 1px solid rgba(99, 102, 241, 0.2);
border-radius: 8px;
color: #e2e8f0;
font-size: 14px;
transition: all 0.2s;
}
.form-input::placeholder {
color: #64748b;
}
.form-input:focus {
outline: none;
border-color: #6366f1;
background: rgba(30, 41, 59, 0.8);
box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}
.form-input:focus + .input-icon,
.form-input:focus ~ .input-icon {
color: #6366f1;
}
.input-hint {
font-size: 12px;
color: #64748b;
margin-top: 4px;
}
/* 切换密码可见性按钮 */
.toggle-password {
position: absolute;
right: 12px;
background: none;
border: none;
padding: 4px;
cursor: pointer;
color: #64748b;
transition: color 0.2s;
}
.toggle-password:hover {
color: #6366f1;
}
.toggle-password svg {
width: 18px;
height: 18px;
}
/* 表单选项 */
.form-options {
display: flex;
justify-content: space-between;
align-items: center;
font-size: 14px;
}
.checkbox-label {
display: flex;
align-items: center;
gap: 8px;
cursor: pointer;
color: #94a3b8;
}
.checkbox-label input[type="checkbox"] {
width: 16px;
height: 16px;
accent-color: #6366f1;
cursor: pointer;
}
.forgot-link {
color: #6366f1;
text-decoration: none;
transition: color 0.2s;
}
.forgot-link:hover {
color: #8b5cf6;
}
/* 警告框 */
.alert {
padding: 12px 16px;
border-radius: 8px;
font-size: 14px;
display: none;
}
.alert-error {
background: rgba(239, 68, 68, 0.1);
border: 1px solid rgba(239, 68, 68, 0.3);
color: #fca5a5;
}
.alert-success {
background: rgba(34, 197, 94, 0.1);
border: 1px solid rgba(34, 197, 94, 0.3);
color: #86efac;
}
/* 按钮样式 */
.btn-auth {
width: 100%;
padding: 14px 24px;
font-size: 16px;
font-weight: 600;
margin-top: 8px;
position: relative;
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
}
.btn-auth:disabled {
opacity: 0.6;
cursor: not-allowed;
}
.btn-spinner {
width: 20px;
height: 20px;
animation: spin 1s linear infinite;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
/* 认证页脚 */
.auth-footer {
text-align: center;
margin-top: 24px;
padding-top: 24px;
border-top: 1px solid rgba(99, 102, 241, 0.2);
color: #94a3b8;
font-size: 14px;
}
.auth-link {
color: #6366f1;
text-decoration: none;
font-weight: 500;
transition: color 0.2s;
}
.auth-link:hover {
color: #8b5cf6;
text-decoration: underline;
}
/* 装饰元素 */
.auth-decoration {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
pointer-events: none;
overflow: hidden;
z-index: -1;
}
.deco-circle {
position: absolute;
border-radius: 50%;
background: radial-gradient(circle, rgba(99, 102, 241, 0.3) 0%, transparent 70%);
}
.deco-circle-1 {
width: 400px;
height: 400px;
top: -100px;
right: -100px;
animation: float 20s ease-in-out infinite;
}
.deco-circle-2 {
width: 300px;
height: 300px;
bottom: -50px;
left: 10%;
background: radial-gradient(circle, rgba(139, 92, 246, 0.3) 0%, transparent 70%);
animation: float 15s ease-in-out infinite reverse;
}
.deco-circle-3 {
width: 200px;
height: 200px;
top: 40%;
right: 15%;
background: radial-gradient(circle, rgba(6, 182, 212, 0.2) 0%, transparent 70%);
animation: float 18s ease-in-out infinite;
}
@keyframes float {
0%, 100% {
transform: translate(0, 0);
}
25% {
transform: translate(20px, -20px);
}
50% {
transform: translate(-10px, 15px);
}
75% {
transform: translate(15px, 10px);
}
}
/* 响应式 */
@media (max-width: 640px) {
.auth-page {
margin-left: 0;
padding: 20px 16px;
}
.auth-card {
padding: 32px 24px;
}
.auth-title {
font-size: 24px;
}
.form-options {
flex-direction: column;
gap: 12px;
align-items: flex-start;
}
}

View File

@@ -0,0 +1,572 @@
/* OSS Community 样式 - 已对齐官网视觉规范 */
:root {
--bg: #030712;
--bg-card: rgba(255, 255, 255, 0.02);
--border: rgba(255, 255, 255, 0.05);
--border-hover: rgba(6, 182, 212, 0.3);
--cyan: #06b6d4;
--cyan-light: #22d3ee;
--text: #fff;
--text-secondary: #9ca3af;
--text-muted: #6b7280;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: 'Inter', sans-serif;
background: var(--bg);
color: var(--text);
line-height: 1.6;
overflow-x: hidden;
}
/* 全局背景网格 */
body::before {
content: '';
position: fixed;
inset: 0;
background-image:
linear-gradient(rgba(6, 182, 212, 0.03) 1px, transparent 1px),
linear-gradient(90deg, rgba(6, 182, 212, 0.03) 1px, transparent 1px);
background-size: 60px 60px;
pointer-events: none;
z-index: -1;
}
/* 头部导航 */
.comm-header {
position: sticky;
top: 0;
z-index: 100;
background: rgba(3, 7, 18, 0.8);
backdrop-filter: blur(16px);
border-bottom: 1px solid var(--border);
transition: border-color 0.3s;
}
.header-container {
max-width: 1400px;
margin: 0 auto;
padding: 0 24px;
height: 64px;
display: flex;
align-items: center;
justify-content: space-between;
}
.header-left {
display: flex;
align-items: center;
gap: 24px;
}
.back-link {
color: var(--text-muted);
text-decoration: none;
font-size: 14px;
transition: all 0.3s ease;
display: flex;
align-items: center;
gap: 4px;
}
.back-link:hover {
color: var(--cyan-light);
transform: translateX(-4px);
}
.site-title {
font-size: 18px;
font-weight: 700;
background: linear-gradient(135deg, var(--cyan), #3b82f6);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
letter-spacing: 0.02em;
}
.btn {
padding: 10px 20px;
border-radius: 10px;
font-size: 14px;
font-weight: 600;
cursor: pointer;
border: none;
transition: all 0.3s ease;
display: flex;
align-items: center;
gap: 6px;
}
.btn-primary {
background: linear-gradient(135deg, var(--cyan), #3b82f6);
color: #fff;
box-shadow: 0 4px 12px rgba(6, 182, 212, 0.1);
}
.btn-primary:hover {
box-shadow: 0 8px 24px rgba(6, 182, 212, 0.4);
transform: translateY(-2px);
}
/* 主布局 */
.comm-main {
max-width: 1200px;
margin: 0 auto;
padding: 24px 100px 24px 24px; /* 右侧为 Dock 留空间 */
min-height: calc(100vh - 64px);
}
.comm-container {
display: grid;
grid-template-columns: 260px 1fr;
gap: 32px;
animation: fadeInUp 0.6s ease forwards;
opacity: 0;
transform: translateY(20px);
}
@keyframes fadeInUp {
to { opacity: 1; transform: translateY(0); }
}
/* 侧边栏 */
.comm-sidebar {
position: sticky;
top: 88px;
height: fit-content;
}
.sidebar-section {
background: rgba(10, 15, 30, 0.6);
border: 1px solid var(--border);
border-radius: 16px;
padding: 20px;
margin-bottom: 20px;
backdrop-filter: blur(8px);
transition: all 0.3s ease;
}
.sidebar-section:hover {
border-color: rgba(255, 255, 255, 0.1);
}
.sidebar-section h3 {
font-size: 12px;
font-weight: 700;
color: var(--text-muted);
margin-bottom: 16px;
text-transform: uppercase;
letter-spacing: 0.1em;
}
.category-list { list-style: none; }
.category-list li {
display: flex;
align-items: center;
gap: 12px;
padding: 12px;
border-radius: 10px;
cursor: pointer;
transition: all 0.25s ease;
margin-bottom: 4px;
color: var(--text-secondary);
font-size: 14px;
font-weight: 500;
}
.category-list li:hover {
background: rgba(255, 255, 255, 0.04);
color: #fff;
transform: translateX(4px);
}
.category-list li.active {
background: rgba(6, 182, 212, 0.1);
border-left: 3px solid var(--cyan);
color: var(--cyan-light);
}
.cat-icon {
width: 20px;
height: 20px;
display: flex;
align-items: center;
justify-content: center;
opacity: 0.7;
}
.cat-icon svg {
width: 16px;
height: 16px;
fill: none;
stroke: currentColor;
stroke-width: 2;
}
.category-list li.active .cat-icon { opacity: 1; color: var(--cyan); }
.cat-count {
font-size: 11px;
color: var(--text-muted);
background: rgba(255, 255, 255, 0.03);
padding: 2px 8px;
border-radius: 6px;
font-weight: 600;
}
.stats-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 12px;
text-align: center;
}
.stat-item {
padding: 10px 4px;
background: rgba(255, 255, 255, 0.02);
border-radius: 8px;
}
.stat-num {
display: block;
font-size: 20px;
font-weight: 800;
color: var(--cyan-light);
margin-bottom: 4px;
}
.stat-label {
font-size: 10px;
color: var(--text-muted);
font-weight: 500;
text-transform: uppercase;
}
/* 内容区 */
.comm-content { min-width: 0; }
.content-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 20px;
padding-bottom: 16px;
border-bottom: 1px solid var(--border);
}
.content-header h2 {
font-size: 22px;
font-weight: 700;
color: #fff;
display: flex;
align-items: center;
gap: 10px;
}
.content-header h2::before {
content: '';
display: block;
width: 4px;
height: 20px;
background: var(--cyan);
border-radius: 2px;
}
.sort-options {
display: flex;
gap: 8px;
background: rgba(255, 255, 255, 0.02);
border: 1px solid var(--border);
border-radius: 10px;
padding: 4px;
}
.sort-btn {
padding: 6px 14px;
border-radius: 8px;
background: transparent;
border: none;
color: var(--text-secondary);
font-size: 13px;
font-weight: 500;
cursor: pointer;
transition: all 0.2s ease;
}
.sort-btn:hover { color: #fff; }
.sort-btn.active {
background: rgba(6, 182, 212, 0.15);
color: var(--cyan-light);
box-shadow: 0 2px 6px rgba(6, 182, 212, 0.1);
}
/* 帖子列表 - 卡片动效 */
.posts-list { display: flex; flex-direction: column; gap: 16px; }
.post-card {
background: rgba(10, 15, 30, 0.6);
border: 1px solid var(--border);
border-radius: 16px;
padding: 24px;
transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
cursor: pointer;
position: relative;
overflow: hidden;
animation: cardEnter 0.5s ease forwards;
opacity: 0;
transform: translateY(20px);
}
@keyframes cardEnter {
to { opacity: 1; transform: translateY(0); }
}
.post-card::before {
content: '';
position: absolute;
top: 0; left: 0; right: 0; bottom: 0;
background: linear-gradient(135deg, rgba(6, 182, 212, 0.05), transparent);
opacity: 0;
transition: opacity 0.4s;
}
.post-card:hover {
border-color: var(--border-hover);
transform: translateY(-4px) scale(1.005);
box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4), 0 0 12px rgba(6, 182, 212, 0.1);
}
.post-card:hover::before { opacity: 1; }
.post-header {
display: flex;
align-items: center;
gap: 14px;
margin-bottom: 14px;
position: relative;
z-index: 1;
}
.post-avatar {
width: 44px;
height: 44px;
border-radius: 12px;
background: linear-gradient(135deg, var(--cyan), #3b82f6);
display: flex;
align-items: center;
justify-content: center;
font-weight: 800;
font-size: 18px;
color: #fff;
box-shadow: 0 4px 10px rgba(6, 182, 212, 0.3);
flex-shrink: 0;
}
.post-meta { flex: 1; min-width: 0; }
.post-author {
font-weight: 600;
font-size: 14px;
color: #fff;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.post-time {
font-size: 12px;
color: var(--text-muted);
}
.post-tags { display: flex; gap: 6px; flex-shrink: 0; }
.tag {
padding: 3px 8px;
border-radius: 6px;
font-size: 11px;
font-weight: 600;
background: rgba(6, 182, 212, 0.08);
border: 1px solid rgba(6, 182, 212, 0.15);
color: var(--cyan-light);
text-transform: uppercase;
}
.pinned-badge {
padding: 3px 8px;
border-radius: 6px;
font-size: 11px;
font-weight: 700;
background: rgba(245, 158, 11, 0.15);
border: 1px solid rgba(245, 158, 11, 0.3);
color: #fbbf24;
display: flex;
align-items: center;
gap: 4px;
}
.post-title {
font-size: 17px;
font-weight: 700;
margin-bottom: 8px;
display: flex;
align-items: flex-start;
gap: 8px;
position: relative;
z-index: 1;
color: #fff;
transition: color 0.2s;
}
.post-card:hover .post-title { color: var(--cyan-light); }
.post-excerpt {
font-size: 14px;
color: var(--text-secondary);
line-height: 1.6;
margin-bottom: 14px;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
position: relative;
z-index: 1;
}
.post-stats {
display: flex;
gap: 20px;
font-size: 12px;
color: var(--text-muted);
font-weight: 500;
position: relative;
z-index: 1;
}
.post-stats span {
display: flex;
align-items: center;
gap: 6px;
transition: color 0.2s;
}
.post-stats svg {
width: 14px;
height: 14px;
opacity: 0.6;
}
.post-card:hover .post-stats span { color: var(--text-secondary); }
/* 空状态 / 加载动画 */
.empty-state {
text-align: center;
padding: 80px 20px;
color: var(--text-muted);
animation: fadeIn 0.5s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.loading-spinner {
width: 32px;
height: 32px;
border: 3px solid rgba(6, 182, 212, 0.1);
border-top-color: var(--cyan);
border-radius: 50%;
animation: spin 0.8s linear infinite;
margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state-icon {
font-size: 48px;
margin-bottom: 16px;
opacity: 0.4;
}
/* 分页 */
.pagination {
display: flex;
justify-content: center;
gap: 8px;
margin-top: 32px;
padding-bottom: 32px;
}
.page-btn {
width: 36px;
height: 36px;
border-radius: 10px;
background: rgba(255, 255, 255, 0.02);
border: 1px solid var(--border);
color: var(--text-secondary);
cursor: pointer;
transition: all 0.2s ease;
display: flex;
align-items: center;
justify-content: center;
font-weight: 600;
font-size: 14px;
}
.page-btn:hover {
background: rgba(6, 182, 212, 0.1);
border-color: var(--border-hover);
color: var(--cyan);
transform: translateY(-2px);
}
.page-btn.active {
background: var(--cyan);
border-color: var(--cyan);
color: #fff;
box-shadow: 0 4px 12px rgba(6, 182, 212, 0.4);
}
/* 响应式 */
@media (max-width: 900px) {
.comm-container {
grid-template-columns: 1fr;
}
.comm-sidebar {
position: static;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 16px;
}
.stats-grid { margin-top: 0; }
}
@media (max-width: 600px) {
.header-container { padding: 0 16px; }
.comm-main { padding: 16px; }
.content-header h2 { font-size: 18px; }
.sort-options { display: none; }
.post-card { padding: 16px; }
.post-title { font-size: 15px; }
}
/* 创建帖子按钮样式 - 区别于普通导航链接 */
button.dock-item {
background: transparent;
border: none;
cursor: pointer;
}
.dock-action-btn {
color: #10b981; /* 翡翠绿 - 代表创建/动作 */
background: rgba(16, 185, 129, 0.08);
border: 1px solid rgba(16, 185, 129, 0.2);
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}
.dock-action-btn:hover {
background: rgba(16, 185, 129, 0.2);
border-color: #10b981;
color: #34d399;
box-shadow: 0 0 12px rgba(16, 185, 129, 0.4);
transform: scale(1.1);
}

View File

@@ -0,0 +1,177 @@
/* Dock 用户信息面板样式 */
.user-popover {
position: fixed;
z-index: 10001;
width: 260px;
background: rgba(15, 23, 42, 0.95);
backdrop-filter: blur(12px);
border: 1px solid rgba(99, 102, 241, 0.2);
border-radius: 12px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
opacity: 0;
visibility: hidden;
transform: translateY(10px) scale(0.98);
transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
pointer-events: none;
color: #e2e8f0;
font-family: 'Inter', sans-serif;
}
.user-popover.active {
opacity: 1;
visibility: visible;
transform: translateY(0) scale(1);
pointer-events: auto;
}
.popover-header {
display: flex;
align-items: center;
gap: 12px;
padding: 16px;
border-bottom: 1px solid rgba(99, 102, 241, 0.1);
}
.popover-avatar {
width: 44px;
height: 44px;
border-radius: 10px;
background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
display: flex;
align-items: center;
justify-content: center;
font-size: 20px;
font-weight: 700;
color: white;
flex-shrink: 0;
}
.popover-info {
flex: 1;
min-width: 0;
}
.popover-name {
font-size: 14px;
font-weight: 600;
color: #f1f5f9;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.popover-role {
font-size: 11px;
color: #94a3b8;
margin-top: 2px;
text-transform: uppercase;
letter-spacing: 0.5px;
background: rgba(255, 255, 255, 0.05);
padding: 2px 6px;
border-radius: 4px;
display: inline-block;
}
.popover-menu {
padding: 8px;
border-bottom: 1px solid rgba(99, 102, 241, 0.1);
}
.menu-item {
display: flex;
align-items: center;
gap: 10px;
padding: 10px 12px;
border-radius: 8px;
color: #e2e8f0;
text-decoration: none;
transition: all 0.2s;
background: transparent;
border: none;
cursor: pointer;
width: 100%;
}
.menu-item:hover {
background: rgba(99, 102, 241, 0.15);
color: #f1f5f9;
}
.menu-item svg {
width: 16px;
height: 16px;
flex-shrink: 0;
color: #94a3b8;
}
.menu-item:hover svg {
color: #c7d2fe;
}
.menu-item span {
flex: 1;
font-size: 13px;
font-weight: 500;
}
.menu-badge {
font-size: 11px;
font-weight: 600;
padding: 2px 8px;
border-radius: 10px;
background: rgba(99, 102, 241, 0.3);
color: #c7d2fe;
min-width: 24px;
text-align: center;
}
.popover-footer {
padding: 12px;
display: flex;
flex-direction: column;
gap: 8px;
}
.popover-btn {
width: 100%;
padding: 8px 12px;
border-radius: 8px;
font-size: 13px;
font-weight: 500;
cursor: pointer;
border: none;
transition: all 0.2s;
display: flex;
align-items: center;
justify-content: center;
gap: 6px;
}
.btn-logout {
background: rgba(99, 102, 241, 0.2);
color: #c7d2fe;
border: 1px solid rgba(99, 102, 241, 0.3);
}
.btn-logout:hover {
background: rgba(99, 102, 241, 0.3);
color: white;
}
.btn-danger {
background: transparent;
color: #94a3b8;
border: 1px solid rgba(100, 116, 139, 0.2);
}
.btn-danger:hover {
background: rgba(239, 68, 68, 0.1);
color: #fca5a5;
border-color: rgba(239, 68, 68, 0.3);
}
.btn-danger svg {
width: 14px;
height: 14px;
}

View File

@@ -0,0 +1,325 @@
/* OSS Community Editor - 优化版两栏布局 */
* { margin: 0; padding: 0; box-sizing: border-box; }
.editor-page {
min-height: 100vh;
background: #0f172a;
display: flex;
flex-direction: column;
}
.editor-container {
flex: 1;
display: flex;
flex-direction: column;
padding: 24px;
padding-right: 100px;
max-width: 1400px;
margin: 0 auto;
width: 100%;
}
/* 顶部工具栏 */
.editor-toolbar {
flex-shrink: 0;
display: flex;
justify-content: space-between;
align-items: center;
padding: 12px 18px;
background: rgba(15, 23, 42, 0.9);
border: 1px solid rgba(99, 102, 241, 0.2);
border-radius: 12px;
margin-bottom: 20px;
}
.toolbar-left { display: flex; align-items: center; gap: 12px; }
.back-btn {
display: flex; align-items: center; gap: 6px;
color: #94a3b8; text-decoration: none; font-size: 14px; font-weight: 500;
transition: color 0.2s;
}
.back-btn:hover { color: #e2e8f0; }
.back-btn svg { width: 18px; height: 18px; }
.toolbar-title {
font-size: 16px; font-weight: 700;
background: linear-gradient(135deg, #e0e7ff 0%, #c7d2fe 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent; background-clip: text;
}
.toolbar-right { display: flex; gap: 8px; }
.btn {
display: flex; align-items: center; gap: 6px;
padding: 8px 16px; border-radius: 8px; font-size: 13px;
font-weight: 600; cursor: pointer; border: none; transition: all 0.2s;
}
.btn svg { width: 16px; height: 16px; }
.btn-outline {
background: rgba(100, 116, 139, 0.2);
color: #94a3b8; border: 1px solid rgba(100, 116, 139, 0.3);
}
.btn-outline:hover { background: rgba(100, 116, 139, 0.3); color: #e2e8f0; }
.btn-primary {
background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
color: white; box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}
.btn-primary:hover { box-shadow: 0 4px 16px rgba(99, 102, 241, 0.4); transform: translateY(-1px); }
/* 标题输入 */
.editor-header {
flex-shrink: 0;
margin-bottom: 20px;
}
.title-input {
width: 100%;
padding: 12px 16px;
background: rgba(30, 41, 59, 0.6);
border: 1px solid rgba(99, 102, 241, 0.2);
border-radius: 10px;
color: #e2e8f0;
font-size: 24px;
font-weight: 700;
transition: all 0.2s;
}
.title-input:focus {
outline: none; border-color: #6366f1;
box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}
.title-input::placeholder { color: #64748b; font-weight: 400; }
/* 两栏主工作区 */
.editor-workspace {
display: grid;
grid-template-columns: 1fr 280px;
gap: 20px;
flex: 1;
min-height: calc(100vh - 280px);
}
/* 编辑器面板 */
.editor-panel {
background: rgba(15, 23, 42, 0.6);
border: 1px solid rgba(99, 102, 241, 0.2);
border-radius: 12px;
display: flex;
flex-direction: column;
overflow: hidden;
}
.panel-header {
flex-shrink: 0;
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 14px;
background: rgba(30, 41, 59, 0.4);
border-bottom: 1px solid rgba(99, 102, 241, 0.1);
}
.panel-title {
font-size: 12px; font-weight: 600; color: #94a3b8;
text-transform: uppercase; letter-spacing: 0.05em;
}
.panel-actions { display: flex; gap: 4px; }
.md-btn {
padding: 6px 8px;
background: transparent; border: 1px solid transparent; border-radius: 6px;
color: #64748b; cursor: pointer; transition: all 0.2s;
}
.md-btn:hover {
background: rgba(99, 102, 241, 0.1);
border-color: rgba(99, 102, 241, 0.2);
color: #e2e8f0;
}
.md-btn svg { width: 16px; height: 16px; }
.editor-textarea {
flex: 1;
width: 100%;
padding: 18px;
background: transparent;
border: none;
color: #e2e8f0;
font-family: 'JetBrains Mono', monospace;
font-size: 14px;
line-height: 1.8;
resize: none;
overflow-y: auto;
tab-size: 2;
min-height: 600px;
}
.editor-textarea:focus { outline: none; }
.editor-textarea::placeholder { color: #475569; }
/* 右侧栏 */
.sidebar-panel {
display: flex;
flex-direction: column;
gap: 16px;
}
.sidebar-section {
background: rgba(15, 23, 42, 0.6);
border: 1px solid rgba(99, 102, 241, 0.2);
border-radius: 12px;
padding: 16px;
}
.sidebar-title {
font-size: 12px;
font-weight: 600;
color: #94a3b8;
text-transform: uppercase;
letter-spacing: 0.05em;
margin-bottom: 12px;
}
.meta-select-large {
width: 100%;
padding: 8px 12px;
background: rgba(30, 41, 59, 0.6);
border: 1px solid rgba(99, 102, 241, 0.2);
border-radius: 8px;
color: #e2e8f0;
font-size: 13px;
}
.meta-select-large:focus { outline: none; border-color: #6366f1; }
/* 标签管理 */
.tags-container {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-bottom: 10px;
}
.tag-item {
display: inline-flex;
align-items: center;
gap: 4px;
padding: 4px 10px;
background: rgba(99, 102, 241, 0.15);
border: 1px solid rgba(99, 102, 241, 0.3);
border-radius: 14px;
font-size: 12px;
font-weight: 500;
color: #c7d2fe;
}
.tag-remove {
background: none; border: none; color: #94a3b8;
cursor: pointer; font-size: 16px; line-height: 1; padding: 0;
width: 16px; height: 16px; display: flex; align-items: center; justify-content: center;
}
.tag-remove:hover { color: #ef4444; }
.tag-input {
width: 100%;
padding: 6px 10px;
background: rgba(15, 23, 42, 0.8);
border: 1px solid rgba(99, 102, 241, 0.2);
border-radius: 6px;
color: #e2e8f0;
font-size: 12px;
margin-bottom: 10px;
}
.tag-input:focus { outline: none; border-color: #6366f1; }
.tags-suggestions {
display: flex;
flex-wrap: wrap;
gap: 6px;
}
.tag-suggestion {
padding: 3px 10px;
background: rgba(100, 116, 139, 0.15);
border: 1px solid rgba(100, 116, 139, 0.2);
border-radius: 12px;
font-size: 11px;
color: #94a3b8;
cursor: pointer;
transition: all 0.2s;
}
.tag-suggestion:hover {
background: rgba(99, 102, 241, 0.1);
border-color: rgba(99, 102, 241, 0.2);
color: #c7d2fe;
}
/* Markdown 帮助 */
.markdown-help {
display: flex;
flex-direction: column;
gap: 6px;
}
.help-item {
font-size: 12px;
color: #94a3b8;
line-height: 1.5;
}
.help-item code {
display: inline-block;
background: rgba(30, 41, 59, 0.6);
padding: 2px 6px;
border-radius: 4px;
font-family: 'JetBrains Mono', monospace;
font-size: 11px;
color: #f472b6;
margin-right: 6px;
min-width: 90px;
}
/* Toast 提示 */
.toast {
position: fixed; bottom: 16px; right: 16px;
padding: 10px 14px; border-radius: 8px;
display: flex; align-items: center; gap: 6px;
font-size: 13px; font-weight: 500;
z-index: 10000; animation: toastSlideIn 0.3s ease-out;
box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}
@keyframes toastSlideIn {
from { opacity: 0; transform: translateX(100px); }
to { opacity: 1; transform: translateX(0); }
}
.toast svg { width: 16px; height: 16px; }
.toast-success { background: rgba(34, 197, 94, 0.15); border: 1px solid rgba(34, 197, 94, 0.3); color: #86efac; }
.toast-error { background: rgba(239, 68, 68, 0.15); border: 1px solid rgba(239, 68, 68, 0.3); color: #fca5a5; }
/* 响应式 */
@media (max-width: 1024px) {
.editor-container { padding: 20px; }
.editor-workspace { grid-template-columns: 1fr; }
.sidebar-panel {
flex-direction: row;
flex-wrap: wrap;
}
.sidebar-section { flex: 1; min-width: 200px; }
}
@media (max-width: 768px) {
.editor-page { margin-left: 0; }
.editor-container { padding: 16px; padding-bottom: 80px; }
.editor-toolbar {
flex-direction: column;
gap: 12px;
padding: 12px;
}
.toolbar-left, .toolbar-right { width: 100%; justify-content: center; }
.title-input { font-size: 18px; padding: 10px 14px; }
.editor-workspace { min-height: auto; }
.sidebar-panel { flex-direction: column; }
.editor-textarea { min-height: 400px; }
}

View File

@@ -0,0 +1,316 @@
/* OSS Community - 文章抽屉样式 */
/* 遮罩层 */
.post-drawer-overlay {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.6);
backdrop-filter: blur(4px);
z-index: 9998;
opacity: 0;
visibility: hidden;
transition: all 0.3s ease;
}
.post-drawer-overlay.active {
opacity: 1;
visibility: visible;
}
/* 抽屉容器 */
.post-drawer {
position: fixed;
left: 50%;
bottom: 0;
transform: translateX(-50%) translateY(100%);
width: 90%;
max-width: 900px;
max-height: 85vh;
background: #0f172a;
border: 1px solid rgba(99, 102, 241, 0.2);
border-bottom: none;
border-radius: 20px 20px 0 0;
box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
z-index: 9999;
display: flex;
flex-direction: column;
transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
overflow: hidden;
}
.post-drawer.active {
transform: translateX(-50%) translateY(0);
}
/* 抽屉顶部标题栏 */
.post-drawer-header {
flex-shrink: 0;
padding: 24px 28px 20px;
border-bottom: 1px solid rgba(99, 102, 241, 0.1);
background: rgba(15, 23, 42, 0.95);
position: relative;
}
.post-drawer-close {
position: absolute;
top: 16px;
right: 16px;
width: 36px;
height: 36px;
border-radius: 10px;
border: 1px solid rgba(255, 255, 255, 0.1);
background: rgba(30, 41, 59, 0.6);
color: #94a3b8;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.2s;
}
.post-drawer-close:hover {
background: rgba(239, 68, 68, 0.2);
border-color: rgba(239, 68, 68, 0.3);
color: #fca5a5;
transform: scale(1.05);
}
.post-drawer-close svg {
width: 18px;
height: 18px;
}
.post-drawer-title {
font-size: 22px;
font-weight: 700;
color: #e2e8f0;
margin: 0 0 12px 0;
padding-right: 50px;
line-height: 1.3;
}
.post-drawer-meta {
display: flex;
align-items: center;
gap: 12px;
color: #64748b;
font-size: 13px;
}
.post-drawer-avatar {
width: 32px;
height: 32px;
border-radius: 8px;
background: linear-gradient(135deg, #6366f1, #8b5cf6);
display: flex;
align-items: center;
justify-content: center;
font-weight: 700;
font-size: 14px;
color: white;
flex-shrink: 0;
}
.post-drawer-user-info {
display: flex;
flex-direction: column;
gap: 2px;
}
.post-drawer-username {
color: #e2e8f0;
font-weight: 600;
font-size: 13px;
}
.post-drawer-date {
color: #64748b;
font-size: 12px;
}
.post-drawer-category {
font-size: 11px;
font-weight: 600;
padding: 3px 10px;
border-radius: 8px;
background: rgba(99, 102, 241, 0.2);
color: #c7d2fe;
margin-left: auto;
}
/* 抽屉内容区域 */
.post-drawer-body {
flex: 1;
overflow-y: auto;
padding: 28px;
}
.post-drawer-content {
color: #cbd5e1;
font-size: 15px;
line-height: 1.8;
}
.post-drawer-content h1,
.post-drawer-content h2,
.post-drawer-content h3 {
color: #e2e8f0;
margin: 1.2em 0 0.6em;
font-weight: 700;
}
.post-drawer-content h1 { font-size: 1.8em; border-bottom: 2px solid rgba(99, 102, 241, 0.3); padding-bottom: 0.3em; }
.post-drawer-content h2 { font-size: 1.4em; border-bottom: 1px solid rgba(99, 102, 241, 0.2); padding-bottom: 0.2em; }
.post-drawer-content h3 { font-size: 1.2em; }
.post-drawer-content p {
color: #cbd5e1;
line-height: 1.8;
margin: 0.8em 0;
}
.post-drawer-content code {
background: rgba(30, 41, 59, 0.6);
padding: 2px 6px;
border-radius: 4px;
font-family: 'JetBrains Mono', monospace;
font-size: 0.9em;
color: #f472b6;
}
.post-drawer-content pre {
background: rgba(15, 23, 42, 0.8);
border: 1px solid rgba(99, 102, 241, 0.2);
border-radius: 8px;
padding: 16px;
overflow-x: auto;
margin: 0.8em 0;
}
.post-drawer-content pre code {
background: transparent;
padding: 0;
color: #e2e8f0;
}
.post-drawer-content blockquote {
border-left: 4px solid #6366f1;
margin: 0.8em 0;
padding: 12px 16px;
background: rgba(99, 102, 241, 0.05);
border-radius: 0 8px 8px 0;
color: #94a3b8;
}
.post-drawer-content ul,
.post-drawer-content ol {
padding-left: 24px;
color: #cbd5e1;
}
.post-drawer-content li {
margin: 0.4em 0;
}
.post-drawer-content a {
color: #6366f1;
text-decoration: none;
}
.post-drawer-content a:hover {
text-decoration: underline;
}
.post-drawer-content img {
max-width: 100%;
border-radius: 8px;
margin: 0.8em 0;
}
.post-drawer-content hr {
border: none;
height: 1px;
background: rgba(99, 102, 241, 0.2);
margin: 1.5em 0;
}
/* 底部统计栏 */
.post-drawer-footer {
flex-shrink: 0;
padding: 16px 28px;
border-top: 1px solid rgba(99, 102, 241, 0.1);
background: rgba(15, 23, 42, 0.95);
display: flex;
gap: 24px;
color: #64748b;
font-size: 13px;
font-weight: 500;
}
.post-drawer-stat {
display: flex;
align-items: center;
gap: 6px;
}
.post-drawer-stat svg {
width: 16px;
height: 16px;
opacity: 0.7;
}
/* 滚动条样式 */
.post-drawer-body::-webkit-scrollbar {
width: 6px;
}
.post-drawer-body::-webkit-scrollbar-track {
background: transparent;
}
.post-drawer-body::-webkit-scrollbar-thumb {
background: rgba(99, 102, 241, 0.3);
border-radius: 3px;
}
.post-drawer-body::-webkit-scrollbar-thumb:hover {
background: rgba(99, 102, 241, 0.5);
}
/* 响应式 */
@media (max-width: 768px) {
.post-drawer {
width: 100%;
max-width: none;
max-height: 90vh;
border-radius: 16px 16px 0 0;
}
.post-drawer-header {
padding: 20px 20px 16px;
}
.post-drawer-title {
font-size: 18px;
}
.post-drawer-body {
padding: 20px;
}
.post-drawer-content {
font-size: 14px;
}
.post-drawer-footer {
padding: 14px 20px;
gap: 16px;
}
.post-drawer-close {
top: 12px;
right: 12px;
width: 32px;
height: 32px;
}
}

View File

@@ -0,0 +1,168 @@
/**
* OSS Community 认证页面 JS
* 处理登录/注册表单提交
*/
// 切换密码可见性
function togglePassword(fieldId = 'password') {
const input = document.getElementById(fieldId);
const icon = document.getElementById(`eyeIcon-${fieldId}`) || document.getElementById('eyeIcon');
if (input.type === 'password') {
input.type = 'text';
icon.innerHTML = `
<path stroke-linecap="round" stroke-linejoin="round" d="M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.88 9.88l-3.29-3.29m7.532 7.532l3.29 3.29M3 3l3.59 3.59m0 0A9.953 9.953 0 0112 5c4.478 0 8.268 2.943 9.543 7a10.025 10.025 0 01-4.132 5.411m0 0L21 21"/>
`;
} else {
input.type = 'password';
icon.innerHTML = `
<path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/>
<path stroke-linecap="round" stroke-linejoin="round" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"/>
`;
}
}
// 显示错误消息
function showError(message) {
const errorEl = document.getElementById('errorMessage');
const successEl = document.getElementById('successMessage');
if (errorEl) {
errorEl.textContent = message;
errorEl.style.display = 'block';
}
if (successEl) {
successEl.style.display = 'none';
}
}
// 显示成功消息
function showSuccess(message) {
const successEl = document.getElementById('successMessage');
const errorEl = document.getElementById('errorMessage');
if (successEl) {
successEl.textContent = message;
successEl.style.display = 'block';
}
if (errorEl) {
errorEl.style.display = 'none';
}
}
// 隐藏消息
function hideMessages() {
const errorEl = document.getElementById('errorMessage');
const successEl = document.getElementById('successMessage');
if (errorEl) errorEl.style.display = 'none';
if (successEl) successEl.style.display = 'none';
}
// 设置按钮加载状态
function setButtonLoading(loading) {
const btn = document.getElementById('submitBtn');
const text = btn.querySelector('.btn-text');
const spinner = btn.querySelector('.btn-spinner');
if (loading) {
btn.disabled = true;
text.style.display = 'none';
spinner.style.display = 'block';
} else {
btn.disabled = false;
text.style.display = 'inline';
spinner.style.display = 'none';
}
}
// 登录表单
const loginForm = document.getElementById('loginForm');
if (loginForm) {
loginForm.addEventListener('submit', async (e) => {
e.preventDefault();
hideMessages();
setButtonLoading(true);
const formData = {
username: document.getElementById('username').value.trim(),
password: document.getElementById('password').value,
remember: document.getElementById('remember').checked
};
try {
const response = await fetch('api/auth.php?action=login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(formData)
});
const result = await response.json();
if (result.success) {
showSuccess('登录成功!正在跳转...');
setTimeout(() => {
window.location.href = 'index.php';
}, 1000);
} else {
showError(result.message || '登录失败,请检查用户名和密码');
}
} catch (error) {
showError('网络错误,请稍后重试');
} finally {
setButtonLoading(false);
}
});
}
// 注册表单
const registerForm = document.getElementById('registerForm');
if (registerForm) {
registerForm.addEventListener('submit', async (e) => {
e.preventDefault();
hideMessages();
setButtonLoading(true);
const password = document.getElementById('password').value;
const confirmPassword = document.getElementById('confirmPassword').value;
// 前端验证
if (password !== confirmPassword) {
showError('两次输入的密码不一致');
setButtonLoading(false);
return;
}
if (password.length < 6) {
showError('密码长度至少 6 个字符');
setButtonLoading(false);
return;
}
const formData = {
username: document.getElementById('username').value.trim(),
email: document.getElementById('email').value.trim(),
password: password
};
try {
const response = await fetch('api/auth.php?action=register', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(formData)
});
const result = await response.json();
if (result.success) {
showSuccess('注册成功!正在跳转到登录页...');
setTimeout(() => {
window.location.href = 'login.php';
}, 1500);
} else {
showError(result.message || '注册失败,请稍后重试');
}
} catch (error) {
showError('网络错误,请稍后重试');
} finally {
setButtonLoading(false);
}
});
}

View File

@@ -0,0 +1,255 @@
/**
* OSS Community Module
* Handles rendering of categories, stats, and posts list.
* Designed to be SPA-friendly (re-initializable).
*/
// Global state variables
let currentPage = 1;
let currentCategory = '';
let currentSort = 'latest';
// Expose initialization function globally for SPA Router
window.initCommunity = function() {
// Check if we are deep-linked (e.g. ?page=2)
const params = new URLSearchParams(window.location.search);
if(params.has('page')) currentPage = parseInt(params.get('page'));
// Fetch and Render Data
loadCategories();
loadStats();
loadPosts();
// Bind Events (to the new DOM elements created by SPA)
bindCommunityEvents();
};
function bindCommunityEvents() {
const catList = document.getElementById('categoryList');
if (catList) {
catList.addEventListener('click', e => {
const li = e.target.closest('li');
if (!li) return;
document.querySelectorAll('.category-list li').forEach(el => el.classList.remove('active'));
li.classList.add('active');
currentCategory = li.dataset.id || '';
currentPage = 1;
document.getElementById('currentCategory').textContent = li.querySelector('span:nth-child(2)').textContent + '帖子';
loadPosts();
});
}
const sortOptions = document.querySelector('.sort-options');
if (sortOptions) {
sortOptions.addEventListener('click', e => {
if (!e.target.classList.contains('sort-btn')) return;
document.querySelectorAll('.sort-btn').forEach(btn => btn.classList.remove('active'));
e.target.classList.add('active');
currentSort = e.target.dataset.sort;
currentPage = 1;
loadPosts();
});
}
}
// --- Data Loading Functions ---
const API = './api/index.php'; // Relative to community/ directory
async function loadCategories() {
try {
const res = await fetch(`${API}?action=categories`);
const data = await res.json();
const list = document.getElementById('categoryList');
if (!list) return;
// Keep the "All" item (first child) if it exists
const allItem = list.firstElementChild;
list.innerHTML = '';
if (allItem) list.appendChild(allItem);
data.categories.forEach(cat => {
const li = document.createElement('li');
li.dataset.id = cat.id;
li.innerHTML = `<span class="cat-icon">${getIconSvg(cat.icon)}</span><span>${cat.name}</span>`;
list.appendChild(li);
});
} catch (e) {
console.error('Failed to load categories', e);
}
}
async function loadStats() {
try {
const res = await fetch(`${API}?action=stats`);
const data = await res.json();
animateValue('statPosts', 0, data.posts, 1000);
animateValue('statReplies', 0, data.replies, 1000);
animateValue('statUsers', 0, data.users, 1000);
const countAll = document.getElementById('countAll');
if (countAll) countAll.textContent = data.posts;
} catch (e) {
console.error('Failed to load stats', e);
}
}
async function loadPosts() {
const list = document.getElementById('postsList');
if (!list) return;
list.innerHTML = '<div class="empty-state"><div class="loading-spinner"></div><p>正在连接节点...</p></div>';
try {
const params = new URLSearchParams({ action: 'posts', page: currentPage });
if (currentCategory) params.append('category_id', currentCategory);
const res = await fetch(`${API}?${params}`);
const data = await res.json();
list.innerHTML = '';
if (data.posts.length === 0) {
list.innerHTML = `
<div class="empty-state">
<div class="empty-state-icon">📭</div>
<h3>暂无帖子</h3>
<p>成为第一个发帖的人吧!</p>
</div>
`;
return;
}
data.posts.forEach((post, index) => {
const card = document.createElement('div');
card.className = 'post-card';
card.dataset.postId = post.id;
card.style.animationDelay = `${index * 0.1}s`;
card.innerHTML = `
<div class="post-header">
<div class="post-avatar">${post.username[0].toUpperCase()}</div>
<div class="post-meta">
<div class="post-author">${escapeHtml(post.username)}</div>
<div class="post-time">${timeAgo(post.created_at)}</div>
</div>
<div class="post-tags">
<span class="tag">${post.category_name}</span>
${post.is_pinned ? '<span class="pinned-badge"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="12" height="12"><path d="M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z"/></svg> 置顶</span>' : ''}
</div>
</div>
<div class="post-title">${escapeHtml(post.title)}</div>
<div class="post-excerpt">${escapeHtml(post.content.substring(0, 150))}...</div>
<div class="post-stats">
<span>
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>
${post.views}
</span>
<span>
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z"/></svg>
${post.likes}
</span>
<span>
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z"/></svg>
${post.reply_count || 0}
</span>
</div>
`;
list.appendChild(card);
});
renderPagination(data.pages);
} catch (e) {
list.innerHTML = '<div class="empty-state"><p>加载失败,请稍后重试</p></div>';
}
}
function renderPagination(pages) {
const container = document.getElementById('pagination');
if (!container) return;
container.innerHTML = '';
if (pages <= 1) return;
for (let i = 1; i <= pages; i++) {
const btn = document.createElement('button');
btn.className = `page-btn ${i === currentPage ? 'active' : ''}`;
btn.textContent = i;
btn.onclick = () => {
currentPage = i;
loadPosts();
window.scrollTo({ top: 0, behavior: 'smooth' });
};
container.appendChild(btn);
}
}
// --- Utilities ---
function animateValue(id, start, end, duration) {
const obj = document.getElementById(id);
if (!obj) return;
let startTimestamp = null;
const step = (timestamp) => {
if (!startTimestamp) startTimestamp = timestamp;
const progress = Math.min((timestamp - startTimestamp) / duration, 1);
obj.textContent = Math.floor(progress * (end - start) + start);
if (progress < 1) {
window.requestAnimationFrame(step);
}
};
window.requestAnimationFrame(step);
}
function timeAgo(dateStr) {
const now = new Date();
const date = new Date(dateStr);
const seconds = Math.floor((now - date) / 1000);
const intervals = [
[31536000, '年'], [2592000, '个月'], [604800, '周'],
[86400, '天'], [3600, '小时'], [60, '分钟']
];
for (const [secondsCount, label] of intervals) {
const count = Math.floor(seconds / secondsCount);
if (count >= 1) return `${count}${label}`;
}
return '刚刚';
}
function escapeHtml(str) {
if (!str) return '';
const div = document.createElement('div');
div.textContent = str;
return div.innerHTML;
}
function getIconSvg(name) {
const icons = {
megaphone: '<svg viewBox="0 0 24 24"><path d="M3 11l18-5v12L3 13v-2zm11.5 1a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3zM7 20v-2h10v2H7z"/></svg>',
question: '<svg viewBox="0 0 24 24"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 17h-2v-2h2v2zm2.07-7.75l-.9.92C13.45 12.9 13 13.5 13 15h-2v-.5c0-1.1.45-2.1 1.17-2.83l1.24-1.26c.37-.36.59-.86.59-1.41 0-1.1-.9-2-2-2s-2 .9-2 2H8c0-2.21 1.79-4 4-4s4 1.79 4 4c0 .88-.36 1.68-.93 2.25z"/></svg>',
chat: '<svg viewBox="0 0 24 24"><path d="M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm0 14H6l-2 2V4h16v12z"/></svg>',
puzzle: '<svg viewBox="0 0 24 24"><path d="M20.5 11H19V7c0-1.1-.9-2-2-2h-4V3.5C13 2.12 11.88 1 10.5 1S8 2.12 8 3.5V5H4c-1.1 0-2 .9-2 2v3.8h1.5c1.49 0 2.7 1.21 2.7 2.7s-1.21 2.7-2.7 2.7H2V20c0 1.1.9 2 2 2h3.8v-1.5c0-1.49 1.21-2.7 2.7-2.7s2.7 1.21 2.7 2.7V22H17c1.1 0 2-.9 2-2v-4h1.5c1.38 0 2.5-1.12 2.5-2.5S21.88 11 20.5 11z"/></svg>',
bug: '<svg viewBox="0 0 24 24"><path d="M14 12c0 1.1-.9 2-2 2s-2-.9-2-2 .9-2 2-2 2 .9 2 2zM7.56 14.05l1.66-1.66c.36.36.87.59 1.44.65.24.02.47.04.69.04.48 0 .94-.07 1.39-.2l1.32 1.32c-.65.18-1.33.28-2.03.32C10.18 14.64 8.72 14.33 7.56 14.05zM17.77 9.48l-1.32 1.32c-.45-.13-.91-.2-1.39-.2-.22 0-.45.02-.69.04-.57.06-1.08.29-1.44.65l-1.66-1.66c1.16-.28 2.62-.59 4.48-.47.69.04 1.37.14 2.02.32zM12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8z"/></svg>'
};
return icons[name] || icons['chat'];
}
// showCreateModal 函数已移至 post-modal.php 中定义
// 此处仅保留兼容性封装
window.showCreateModal = window.showCreateModal || function() {
if (typeof window.showCreatePostModal === 'function') {
window.showCreatePostModal();
} else {
console.warn('发帖模态框未加载');
}
};
// Auto-init if not loaded via SPA (Hard refresh case)
document.addEventListener('DOMContentLoaded', () => {
if (typeof AppRouter === 'undefined') {
window.initCommunity();
}
});

View File

@@ -0,0 +1,91 @@
document.addEventListener('DOMContentLoaded', () => {
const trigger = document.getElementById('dockUserMenuBtn');
const popover = document.getElementById('dockUserMenu');
const logoutBtn = document.getElementById('logoutBtn');
const deleteBtn = document.getElementById('deleteAccountBtn');
const myPostCount = document.getElementById('myPostCount');
// 获取用户文章数量
async function fetchMyPostCount() {
if (!myPostCount) return;
try {
const res = await fetch('api/auth.php?action=my-post-count');
if (res.ok) {
const data = await res.json();
if (data.success) {
myPostCount.textContent = data.count;
}
}
} catch (err) {
console.error('Failed to fetch post count:', err);
}
}
// 页面加载时获取文章数量
fetchMyPostCount();
if (trigger && popover) {
// 点击图标切换面板
trigger.addEventListener('click', (e) => {
e.preventDefault();
e.stopPropagation();
const isActive = popover.classList.contains('active');
if (isActive) {
popover.classList.remove('active');
} else {
// 计算位置:在图标右侧
const rect = trigger.getBoundingClientRect();
// Dock 通常在左侧,我们定位在图标右边,稍微向上偏移一点居中
popover.style.left = `${rect.right + 16}px`;
popover.style.top = `${rect.top + 10}px`;
popover.classList.add('active');
}
});
// 点击外部关闭
document.addEventListener('click', (e) => {
if (!popover.contains(e.target) && !trigger.contains(e.target)) {
popover.classList.remove('active');
}
});
// 退出登录逻辑
if (logoutBtn) {
logoutBtn.addEventListener('click', async () => {
try {
const originalText = logoutBtn.innerHTML;
logoutBtn.innerHTML = '<span class="spinner"></span> 退出中...';
logoutBtn.disabled = true;
// 使用相对路径,因为 JS 可能在子目录中运行
// 注意:这里假设 api/auth.php 相对于当前页面路径可用
// 在 community/index.php 中api/ 是同级目录
const res = await fetch('api/auth.php?action=logout');
if (res.ok) {
// 退出成功,刷新页面
window.location.reload();
} else {
logoutBtn.innerHTML = originalText;
logoutBtn.disabled = false;
alert('退出失败,请重试');
}
} catch (err) {
console.error('Logout error:', err);
logoutBtn.innerHTML = '退出失败';
logoutBtn.disabled = false;
}
});
}
// 注销账户逻辑
if (deleteBtn) {
deleteBtn.addEventListener('click', () => {
if (confirm('确定要注销(永久删除)此账户吗?\n此操作不可撤销所有数据将被清除。')) {
alert('该功能暂未开放,请联系管理员。');
}
});
}
}
});

View File

@@ -0,0 +1,252 @@
/**
* OSS Community Editor JS
* Markdown 编辑器、实时预览、表单提交
*/
document.addEventListener('DOMContentLoaded', () => {
initEditor();
initToolbar();
initTags();
initForm();
});
// 初始化编辑器
function initEditor() {
const textarea = document.getElementById('postContent');
const titleInput = document.getElementById('postTitle');
// Tab 键支持
if (textarea) {
textarea.addEventListener('keydown', (e) => {
if (e.key === 'Tab') {
e.preventDefault();
const start = textarea.selectionStart;
const end = textarea.selectionEnd;
textarea.value = textarea.value.substring(0, start) + ' ' + textarea.value.substring(end);
textarea.selectionStart = textarea.selectionEnd = start + 2;
}
});
}
}
// 初始化工具栏
function initToolbar() {
const buttons = document.querySelectorAll('.md-btn');
const textarea = document.getElementById('postContent');
if (!textarea) return;
buttons.forEach(btn => {
btn.addEventListener('click', () => {
const action = btn.dataset.md;
insertMarkdown(textarea, action);
});
});
}
function insertMarkdown(textarea, action) {
const start = textarea.selectionStart;
const end = textarea.selectionEnd;
const selected = textarea.value.substring(start, end);
let insertion = '';
switch (action) {
case 'bold':
insertion = `**${selected || '粗体文本'}**`;
break;
case 'italic':
insertion = `*${selected || '斜体文本'}*`;
break;
case 'heading':
insertion = `\n## ${selected || '标题'}\n`;
break;
case 'quote':
insertion = `\n> ${selected || '引用文本'}\n`;
break;
case 'code':
insertion = selected.includes('\n') ? `\n\`\`\`\n${selected || '代码块'}\n\`\`\`\n` : `\`${selected || '行内代码'}\``;
break;
case 'link':
insertion = `[${selected || '链接文本'}](url)`;
break;
case 'list':
insertion = `\n- ${selected || '列表项'}\n`;
break;
}
textarea.value = textarea.value.substring(0, start) + insertion + textarea.value.substring(end);
textarea.focus();
textarea.selectionStart = textarea.selectionEnd = start + insertion.length;
}
// 初始化标签
function initTags() {
const tagInput = document.getElementById('tagInput');
const tagsContainer = document.getElementById('tagsContainer');
if (!tagInput || !tagsContainer) return;
tagInput.addEventListener('keydown', (e) => {
if (e.key === 'Enter') {
e.preventDefault();
const tagName = tagInput.value.trim();
if (tagName) {
addTag(tagName);
tagInput.value = '';
}
}
});
}
function addTag(name) {
const tagsContainer = document.getElementById('tagsContainer');
if (!tagsContainer) return;
// 检查是否已存在
const existing = tagsContainer.querySelectorAll('.tag-item');
for (const tag of existing) {
if (tag.textContent.trim().replace('×', '').trim() === name) {
return;
}
}
const tagEl = document.createElement('span');
tagEl.className = 'tag-item';
tagEl.innerHTML = `
${name}
<button type="button" class="tag-remove" onclick="this.parentElement.remove()">&times;</button>
`;
tagsContainer.appendChild(tagEl);
}
// 初始化表单
function initForm() {
const form = document.getElementById('postEditorForm');
const saveBtn = document.getElementById('savePostBtn');
if (!form || !saveBtn) return;
saveBtn.addEventListener('click', async (e) => {
e.preventDefault();
const postId = document.getElementById('editPostId').value;
const title = document.getElementById('postTitle').value.trim();
const content = document.getElementById('postContent').value.trim();
const categoryId = document.getElementById('postCategory').value;
// 收集标签
const tags = [];
document.querySelectorAll('#tagsContainer .tag-item').forEach(tag => {
const name = tag.textContent.replace('×', '').trim();
if (name) tags.push(name);
});
// 验证
if (!title) {
showError('请输入帖子标题');
return;
}
if (title.length < 5) {
showError('标题至少 5 个字符');
return;
}
if (!content) {
showError('请输入帖子内容');
return;
}
if (content.length < 10) {
showError('内容至少 10 个字符');
return;
}
if (!categoryId) {
showError('请选择分类');
return;
}
// 提交
setSaveButtonLoading(true);
const formData = {
title: title,
content: content,
category_id: categoryId,
tags: tags
};
if (postId) {
formData.id = parseInt(postId);
}
const action = postId ? 'update' : 'create';
const url = `api/posts.php?action=${action}`;
try {
const response = await fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(formData)
});
const result = await response.json();
if (result.success) {
showSuccess(postId ? '更新成功!' : '发布成功!正在跳转...');
setTimeout(() => {
window.location.href = `post.php?id=${result.post_id || postId}`;
}, 1000);
} else {
showError(result.message || '操作失败');
}
} catch (error) {
showError('网络错误,请稍后重试');
} finally {
setSaveButtonLoading(false);
}
});
}
function showSuccess(message) {
const toast = document.getElementById('successToast');
const msgEl = document.getElementById('successMessage');
if (toast && msgEl) {
msgEl.textContent = message;
toast.style.display = 'flex';
setTimeout(() => { toast.style.display = 'none'; }, 3000);
}
}
function showError(message) {
const toast = document.getElementById('errorToast');
const msgEl = document.getElementById('errorMessage');
if (toast && msgEl) {
msgEl.textContent = message;
toast.style.display = 'flex';
setTimeout(() => { toast.style.display = 'none'; }, 4000);
}
}
function setSaveButtonLoading(loading) {
const btn = document.getElementById('savePostBtn');
if (!btn) return;
if (loading) {
btn.disabled = true;
btn.style.opacity = '0.6';
btn.innerHTML = `
<svg class="btn-spinner" viewBox="0 0 24 24" fill="none">
<circle cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4" stroke-linecap="round" opacity="0.25"/>
<path d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z" fill="currentColor" opacity="0.75"/>
</svg>
处理中...
`;
} else {
btn.disabled = false;
btn.style.opacity = '1';
btn.innerHTML = `
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7"/>
</svg>
${document.getElementById('editPostId').value ? '保存修改' : '发布帖子'}
`;
}
}

View File

@@ -0,0 +1,91 @@
/**
* OSS Community - 实时轮询系统
* 每2秒从数据库刷新所有数据
*/
class CommunityPollingSystem {
constructor() {
this.interval = 2000;
this.timer = null;
this.isRunning = false;
this.listeners = { user: [], posts: [], stats: [], categories: [] };
this.cache = { user: null, posts: null, stats: null, categories: null };
}
start() {
if (this.isRunning) return;
this.isRunning = true;
this._fetchAll();
this.timer = setInterval(() => this._fetchAll(), this.interval);
}
stop() {
clearInterval(this.timer);
this.isRunning = false;
this.timer = null;
}
on(event, callback) {
if (this.listeners[event]) this.listeners[event].push(callback);
}
async _fetch(url) {
try {
const res = await fetch(url);
return res.ok ? await res.json() : null;
} catch { return null; }
}
async _fetchAll() {
// 并行请求所有接口
const [userData, postsData, statsData, catsData] = await Promise.all([
this._fetch('api/auth.php?action=current-user'),
this._fetch('api/index.php?action=posts'),
this._fetch('api/index.php?action=stats'),
this._fetch('api/index.php?action=categories')
]);
// 用户数据
if (userData && userData.success) {
const changed = JSON.stringify(userData) !== JSON.stringify(this.cache.user);
this.cache.user = userData;
if (changed) this._notify('user', userData);
}
// 帖子数据(含 views, likes, replies
if (postsData && postsData.posts) {
const changed = JSON.stringify(postsData.posts) !== JSON.stringify(this.cache.posts);
this.cache.posts = postsData.posts;
if (changed) this._notify('posts', postsData);
}
// 统计数据(含 hot_posts
if (statsData) {
const changed = JSON.stringify(statsData) !== JSON.stringify(this.cache.stats);
this.cache.stats = statsData;
if (changed) this._notify('stats', statsData);
}
// 分类
if (catsData && catsData.categories) {
const changed = JSON.stringify(catsData.categories) !== JSON.stringify(this.cache.categories);
this.cache.categories = catsData.categories;
if (changed) this._notify('categories', catsData);
}
}
_notify(event, data) {
(this.listeners[event] || []).forEach(fn => {
try { fn(data); } catch(e) {}
});
}
}
window.Polling = new CommunityPollingSystem();
document.addEventListener('DOMContentLoaded', () => {
const dock = document.getElementById('dock');
if (dock && dock.dataset.loggedIn === '1') {
window.Polling.start();
}
});

View File

@@ -0,0 +1,236 @@
/**
* OSS Community - 文章抽屉交互逻辑
*/
document.addEventListener('DOMContentLoaded', () => {
initPostDrawer();
});
let drawerInitialized = false;
let currentDrawerPostId = null;
let drawerPollTimer = null;
function initPostDrawer() {
if (drawerInitialized) return;
drawerInitialized = true;
createDrawerElements();
// 全局点击事件委托
document.addEventListener('click', (e) => {
const postCard = e.target.closest('.post-card');
if (postCard && postCard.dataset.postId) {
e.preventDefault();
e.stopPropagation();
openPostDrawer(postCard.dataset.postId);
}
});
const overlay = document.getElementById('postDrawerOverlay');
if (overlay) overlay.addEventListener('click', closePostDrawer);
const closeBtn = document.getElementById('postDrawerClose');
if (closeBtn) closeBtn.addEventListener('click', closePostDrawer);
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') closePostDrawer();
});
// 监听轮询数据更新抽屉内的 views/likes
if (window.Polling) {
window.Polling.on('posts', (data) => {
if (!data.posts || !currentDrawerPostId) return;
const post = data.posts.find(p => p.id == currentDrawerPostId);
if (post) updateDrawerStats(post);
});
}
}
function createDrawerElements() {
if (document.getElementById('postDrawerOverlay')) return;
// 创建遮罩层
const overlay = document.createElement('div');
overlay.id = 'postDrawerOverlay';
overlay.className = 'post-drawer-overlay';
// 创建抽屉
const drawer = document.createElement('div');
drawer.id = 'postDrawer';
drawer.className = 'post-drawer';
drawer.innerHTML = `
<div class="post-drawer-header">
<button class="post-drawer-close" id="postDrawerClose" aria-label="关闭">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<line x1="18" y1="6" x2="6" y2="18"/>
<line x1="6" y1="6" x2="18" y2="18"/>
</svg>
</button>
<h2 class="post-drawer-title" id="postDrawerTitle"></h2>
<div class="post-drawer-meta" id="postDrawerMeta"></div>
</div>
<div class="post-drawer-body">
<div class="post-drawer-content" id="postDrawerContent"></div>
</div>
<div class="post-drawer-footer" id="postDrawerFooter"></div>
`;
document.body.appendChild(overlay);
document.body.appendChild(drawer);
// 绑定关闭按钮
document.getElementById('postDrawerClose').addEventListener('click', closePostDrawer);
}
async function openPostDrawer(postId) {
const drawer = document.getElementById('postDrawer');
const overlay = document.getElementById('postDrawerOverlay');
const titleEl = document.getElementById('postDrawerTitle');
const metaEl = document.getElementById('postDrawerMeta');
const contentEl = document.getElementById('postDrawerContent');
const footerEl = document.getElementById('postDrawerFooter');
if (!drawer || !overlay) return;
// 显示加载状态
titleEl.textContent = '加载中...';
metaEl.innerHTML = '';
contentEl.innerHTML = '<div style="text-align:center;padding:40px;color:#64748b;">正在加载文章内容...</div>';
footerEl.innerHTML = '';
// 显示抽屉(先滑入,再加载内容)
overlay.classList.add('active');
drawer.classList.add('active');
document.body.style.overflow = 'hidden';
try {
const response = await fetch(`api/index.php?action=post&id=${postId}`);
if (!response.ok) throw new Error('加载失败');
const data = await response.json();
if (!data.post) throw new Error('帖子不存在');
const post = data.post;
const replies = data.replies || [];
currentDrawerPostId = post.id;
// 更新标题和元信息
titleEl.textContent = post.title;
metaEl.innerHTML = `
<div class="post-drawer-avatar">${post.username.charAt(0).toUpperCase()}</div>
<div class="post-drawer-user-info">
<div class="post-drawer-username">${escapeHtml(post.username)}</div>
<div class="post-drawer-date">${formatDate(post.created_at)}</div>
</div>
<span class="post-drawer-category">${escapeHtml(post.category_name)}</span>
`;
// 更新内容(使用 marked 解析 Markdown
if (typeof marked !== 'undefined') {
contentEl.innerHTML = marked.parse(post.content);
} else {
contentEl.innerHTML = escapeHtml(post.content).replace(/\n/g, '<br>');
}
// 更新底部统计
footerEl.innerHTML = `
<div class="post-drawer-stat">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>
${post.views} 浏览
</div>
<div class="post-drawer-stat">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z"/></svg>
${post.likes} 点赞
</div>
<div class="post-drawer-stat">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>
${replies.length} 回复
</div>
`;
// 如果有回复,在内容下方显示
if (replies.length > 0) {
contentEl.innerHTML += `
<hr style="margin:2em 0;border:none;height:1px;background:rgba(99,102,241,0.2);">
<h3 style="color:#e2e8f0;margin-bottom:1em;font-size:18px;">回复 (${replies.length})</h3>
${replies.map(reply => `
<div style="padding:16px;background:rgba(30,41,59,0.4);border-radius:12px;margin-bottom:12px;border:1px solid rgba(99,102,241,0.1);">
<div style="display:flex;align-items:center;gap:8px;margin-bottom:8px;">
<div style="width:28px;height:28px;border-radius:6px;background:linear-gradient(135deg,#6366f1,#8b5cf6);display:flex;align-items:center;justify-content:center;font-size:12px;font-weight:700;color:white;flex-shrink:0;">
${reply.username.charAt(0).toUpperCase()}
</div>
<span style="color:#e2e8f0;font-weight:600;font-size:13px;">${escapeHtml(reply.username)}</span>
<span style="color:#64748b;font-size:12px;margin-left:auto;">${formatDate(reply.created_at)}</span>
</div>
<div style="color:#cbd5e1;font-size:14px;line-height:1.6;">${escapeHtml(reply.content).replace(/\n/g, '<br>')}</div>
</div>
`).join('')}
`;
}
} catch (error) {
console.error('Failed to load post:', error);
contentEl.innerHTML = `
<div style="text-align:center;padding:40px;color:#ef4444;">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="width:48px;height:48px;margin:0 auto 16px;opacity:0.5;">
<circle cx="12" cy="12" r="10"/>
<line x1="12" y1="8" x2="12" y2="12"/>
<line x1="12" y1="16" x2="12.01" y2="16"/>
</svg>
<p style="font-size:16px;font-weight:600;margin-bottom:8px;">加载失败</p>
<p style="font-size:14px;">${error.message || '未知错误,请稍后重试'}</p>
</div>
`;
}
}
function closePostDrawer() {
const drawer = document.getElementById('postDrawer');
const overlay = document.getElementById('postDrawerOverlay');
if (drawer) drawer.classList.remove('active');
if (overlay) overlay.classList.remove('active');
document.body.style.overflow = '';
currentDrawerPostId = null;
}
function updateDrawerStats(post) {
const footerEl = document.getElementById('postDrawerFooter');
if (!footerEl || !currentDrawerPostId) return;
footerEl.innerHTML = `
<div class="post-drawer-stat">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>
${post.views} 浏览
</div>
<div class="post-drawer-stat">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z"/></svg>
${post.likes} 点赞
</div>
<div class="post-drawer-stat">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z"/></svg>
${post.reply_count || 0} 回复
</div>
`;
}
function escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
function formatDate(dateString) {
const date = new Date(dateString);
const now = new Date();
const diff = now - date;
const minutes = Math.floor(diff / 60000);
const hours = Math.floor(diff / 3600000);
const days = Math.floor(diff / 86400000);
if (minutes < 1) return '刚刚';
if (minutes < 60) return `${minutes} 分钟前`;
if (hours < 24) return `${hours} 小时前`;
if (days < 7) return `${days} 天前`;
return date.toLocaleDateString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit' });
}

View File

@@ -0,0 +1,108 @@
/**
* OSS Community - 轮询数据实时更新
*/
document.addEventListener('DOMContentLoaded', () => {
if (!window.Polling) return;
// ========== 用户数据(称号、权限) ==========
let prevTitle = '', prevPerms = {};
window.Polling.on('user', (data) => {
if (!data.success || !data.user) return;
const { title, role } = data.user;
// 更新称号徽章
if (title !== prevTitle) {
prevTitle = title;
const avatar = document.getElementById('dockUserAvatar');
if (avatar) {
const name = avatar.dataset.tooltip.split(' - ')[0] || avatar.dataset.tooltip;
avatar.dataset.tooltip = title ? `${name} - ${title}` : name;
}
let badge = document.querySelector('.user-title-badge');
if (title) {
if (!badge) { badge = document.createElement('span'); badge.className = 'user-title-badge'; if (avatar) avatar.appendChild(badge); }
badge.textContent = title;
} else if (badge) badge.remove();
}
// 权限控制
if (data.permissions && JSON.stringify(data.permissions) !== JSON.stringify(prevPerms)) {
prevPerms = data.permissions;
document.querySelectorAll('.admin-only').forEach(el => el.style.display = prevPerms.can_manage_users ? '' : 'none');
document.querySelectorAll('.moderator-only').forEach(el => el.style.display = prevPerms.can_manage_posts ? '' : 'none');
}
});
// ========== 帖子数据实时更新 views/likes/replies ==========
window.Polling.on('posts', (data) => {
if (!data.posts || !Array.isArray(data.posts)) return;
data.posts.forEach(post => {
// 更新帖子卡片上的浏览、点赞、回复数
const cards = document.querySelectorAll(`.post-card[data-post-id="${post.id}"]`);
cards.forEach(card => {
const statsEls = card.querySelectorAll('.post-stats span');
if (statsEls.length >= 3) {
// views
const viewsSvg = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>';
// likes
const likesSvg = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z"/></svg>';
// replies
const repliesSvg = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z"/></svg>';
statsEls[0].innerHTML = viewsSvg + ` ${post.views}`;
statsEls[1].innerHTML = likesSvg + ` ${post.likes}`;
statsEls[2].innerHTML = repliesSvg + ` ${post.reply_count || 0}`;
}
});
// 更新个人主页帖子列表的 stats
const myListItems = document.querySelectorAll(`.my-post-item[data-post-id="${post.id}"] .my-post-meta`);
myListItems.forEach(meta => {
const spans = meta.querySelectorAll('span');
if (spans.length >= 4) {
spans[1].textContent = `👁️ ${post.views} 浏览`;
spans[2].textContent = `❤️ ${post.likes} 点赞`;
spans[3].textContent = `💬 ${post.reply_count || 0} 回复`;
}
});
});
});
// ========== 统计数字实时更新 ==========
window.Polling.on('stats', (data) => {
if (data.posts !== undefined) animateNumber('statPosts', data.posts);
if (data.replies !== undefined) animateNumber('statReplies', data.replies);
if (data.users !== undefined) animateNumber('statUsers', data.users);
const countAll = document.getElementById('countAll');
if (countAll) countAll.textContent = data.posts || 0;
// 更新热门帖子 views如果有这个区域
if (data.hot_posts && Array.isArray(data.hot_posts)) {
data.hot_posts.forEach(hp => {
const hotItems = document.querySelectorAll(`.hot-post-item[data-post-id="${hp.id}"]`);
hotItems.forEach(item => {
const viewsEl = item.querySelector('.hot-views');
if (viewsEl) viewsEl.textContent = hp.views;
});
});
}
});
// ========== 分类更新 ==========
window.Polling.on('categories', (data) => {
if (!data.categories) return;
const countAll = document.getElementById('countAll');
if (countAll) countAll.textContent = data.posts || data.categories.length;
});
});
// 数字动画
function animateNumber(id, target) {
const el = document.getElementById(id);
if (!el) return;
const current = parseInt(el.textContent) || 0;
if (current === target) return;
el.textContent = target;
}