265 lines
14 KiB
HTML
265 lines
14 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>宇之然内容创作平台</title>
|
|
<link rel="stylesheet" href="element-plus.css">
|
|
<link rel="stylesheet" href="theme-modern.css">
|
|
<style>
|
|
.page { display: none; animation: fadeIn 0.5s ease-out; }
|
|
.page.active { display: block; }
|
|
@keyframes fadeIn {
|
|
from { opacity: 0; transform: translateY(20px); }
|
|
to { opacity: 1; transform: translateY(0); }
|
|
}
|
|
.module-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: var(--spacing-lg); }
|
|
.module-card { background: var(--color-bg-raised); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: var(--spacing-lg); transition: all 0.3s var(--ease-out); }
|
|
.module-card:hover { transform: translateY(-6px); border-color: var(--color-border-hover); box-shadow: var(--shadow-lg); }
|
|
.module-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--spacing-md); }
|
|
.module-title { font-size: var(--font-size-h3); font-weight: 600; color: var(--color-text-primary); display: flex; align-items: center; gap: var(--spacing-sm); }
|
|
.module-status { padding: 6px 12px; border-radius: var(--radius-xl); font-size: var(--font-size-caption); font-weight: 600; background: rgba(103,194,58,0.12); color: #67c23a; border: 1px solid rgba(103,194,58,0.25); }
|
|
.module-status.running { animation: pulse-glow 2s infinite; }
|
|
.module-content { font-size: var(--font-size-body); color: var(--color-text-regular); line-height: 1.8; }
|
|
.module-content div { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px dashed var(--color-border); }
|
|
.module-content div:last-child { border-bottom: none; }
|
|
.stat-title { font-size: var(--font-size-small); color: var(--color-text-secondary); margin-bottom: var(--spacing-md); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 500; }
|
|
@media (max-width: 768px) { .module-grid { grid-template-columns: 1fr; } }
|
|
</style>
|
|
|
|
<script src="uni-nav.js"></script>
|
|
</head>
|
|
<body>
|
|
<div id="app">
|
|
<uni-nav title="仪表盘" :username="currentUser.username" :is-admin="isAdmin" current-page="dashboard" @navigate="redirectToPage" @logout="handleLogout">
|
|
</uni-nav>
|
|
<div class="main-content" v-if="isLoggedIn">
|
|
<main class="content-area">
|
|
<!-- 系统概览页面 -->
|
|
<div id="page-overview" class="page" :class="{ active: currentPage === 'overview' }">
|
|
<h2 style="font-size: var(--font-size-h1); font-weight: 700; margin-bottom: var(--spacing-xl); color: var(--color-text-primary);">
|
|
<el-icon style="vertical-align:-2px;"><IconDashboard /></el-icon> 系统概览
|
|
</h2>
|
|
|
|
<!-- 加载状态 -->
|
|
<div v-if="loadingStats" style="text-align:center;padding:40px 0;color:#909399;">
|
|
<el-icon style="font-size:32px;margin-bottom:12px;" class="is-loading"><IconLoading /></el-icon>
|
|
<div>加载中...</div>
|
|
</div>
|
|
<!-- 空状态 -->
|
|
<div v-else-if="!stats.total && !loadingStats" class="empty-state">
|
|
<el-icon style="font-size:48px;color:#c0c4cc;"><IconDashboard /></el-icon>
|
|
<div class="empty-text">暂无数据</div>
|
|
</div>
|
|
<!-- 统计卡片 -->
|
|
<div v-else class="stats-grid">
|
|
<div class="stat-card primary" @click="goToTopics('')">
|
|
<div class="stat-title">选题总数</div>
|
|
<div class="stat-value">{{ stats.total }}</div>
|
|
</div>
|
|
<div class="stat-card warning" @click="goToTopics('pending')">
|
|
<div class="stat-title">待处理</div>
|
|
<div class="stat-value">{{ stats.pending }}</div>
|
|
</div>
|
|
<div class="stat-card danger" @click="goToTopics('review')">
|
|
<div class="stat-title">待审查</div>
|
|
<div class="stat-value">{{ stats.review }}</div>
|
|
</div>
|
|
<div class="stat-card success" @click="goToTopics('ready')">
|
|
<div class="stat-title">待发布</div>
|
|
<div class="stat-value">{{ stats.ready }}</div>
|
|
</div>
|
|
<div class="stat-card info" @click="goToTopics('published')">
|
|
<div class="stat-title">已发布</div>
|
|
<div class="stat-value">{{ stats.published }}</div>
|
|
</div>
|
|
<div class="stat-card primary" @click="goToTopics('today')">
|
|
<div class="stat-title">今日新增</div>
|
|
<div class="stat-value">{{ stats.today }}</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 模块状态 -->
|
|
<h3 style="font-size: var(--font-size-h2); font-weight: 600; margin-bottom: var(--spacing-lg); color: var(--color-text-primary);">
|
|
<el-icon style="vertical-align:-2px;"><IconSetting /></el-icon> 模块状态
|
|
<span style="font-size: var(--font-size-small); font-weight: 400; color: var(--color-text-secondary); margin-left: var(--spacing-sm);">
|
|
定时任务:
|
|
<el-icon v-if="schedulerRunning" style="color:#67C23A;vertical-align:-2px;"><IconCheck /></el-icon>
|
|
<el-icon v-else style="color:#F56C6C;vertical-align:-2px;"><IconClose /></el-icon>
|
|
{{ schedulerRunning ? '运行中' : '未启动' }}
|
|
</span>
|
|
</h3>
|
|
<div class="module-grid">
|
|
<div v-for="mod in modules" :key="mod.id" class="module-card">
|
|
<div class="module-header">
|
|
<span class="module-title">{{ mod.title }}</span>
|
|
<span :class="['module-status', mod.status === 'running' ? 'running' : '']">{{ mod.status === 'running' ? '运行中' : '已停止' }}</span>
|
|
</div>
|
|
<div class="module-content">
|
|
<div><span>最后运行</span><span>{{ mod.last_run }}</span></div>
|
|
<div><span>今日任务</span><span>{{ mod.task_count }} 个</span></div>
|
|
<div v-if="mod.success_rate !== null"><span>成功率</span><span>{{ mod.success_rate }}%</span></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
</div>
|
|
|
|
<!-- 移动端导航 -->
|
|
</div>
|
|
|
|
<script src="vue.global.prod.js"></script>
|
|
<script src="icon-components.js"></script>
|
|
<script src="element-plus.full.js"></script>
|
|
<script>
|
|
const App = {
|
|
data() {
|
|
return {
|
|
isLoggedIn: false,
|
|
isAdmin: false,
|
|
currentUser: { username: '' },
|
|
currentPage: 'overview',
|
|
loadingStats: false,
|
|
stats: {
|
|
total: 0,
|
|
pending: 0,
|
|
review: 0,
|
|
ready: 0,
|
|
published: 0,
|
|
today: 0
|
|
},
|
|
modules: [],
|
|
schedulerStatus: '',
|
|
schedulerRunning: false
|
|
};
|
|
},
|
|
methods: {
|
|
async handleLogin() {
|
|
this.loginLoading = true;
|
|
this.loginError = '';
|
|
try {
|
|
const response = await fetch('/api/auth/login', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(this.loginForm)
|
|
});
|
|
if (!response.ok) throw new Error('登录失败');
|
|
const data = await response.json();
|
|
localStorage.setItem('authToken', data.token);
|
|
this.currentUser = data.user;
|
|
this.isAdmin = data.user.role === 'admin';
|
|
this.isLoggedIn = true;
|
|
this.currentPage = 'overview';
|
|
this.fetchStats();
|
|
} catch (error) {
|
|
this.loginError = '用户名或密码错误';
|
|
} finally {
|
|
this.loginLoading = false;
|
|
}
|
|
},
|
|
handleLogout() {
|
|
localStorage.removeItem('authToken');
|
|
localStorage.removeItem('userRole');
|
|
localStorage.removeItem('currentUser');
|
|
this.isLoggedIn = false;
|
|
this.currentUser = { username: '' };
|
|
this.isAdmin = false;
|
|
window.location.href = '/login.html';
|
|
},
|
|
async fetchStats() {
|
|
this.loadingStats = true;
|
|
try {
|
|
const token = localStorage.getItem('authToken');
|
|
if (!token) {
|
|
window.location.href = '/login.html';
|
|
return;
|
|
}
|
|
const response = await fetch('/api/system/status', {
|
|
headers: { 'Authorization': 'Bearer ' + token }
|
|
});
|
|
if (response.ok) {
|
|
const data = await response.json();
|
|
// API返回格式: { stats: { total, pending, review, ready, published, today } }
|
|
this.stats = {
|
|
total: data.stats?.total || 0,
|
|
pending: data.stats?.pending || 0,
|
|
review: data.stats?.review || 0,
|
|
ready: data.stats?.ready || 0,
|
|
published: data.stats?.published || 0,
|
|
today: data.stats?.today || 0
|
|
};
|
|
} else if (response.status === 401) {
|
|
// Token无效,清除并跳转登录
|
|
localStorage.removeItem('authToken');
|
|
window.location.href = '/login.html';
|
|
} else {
|
|
console.error('获取统计信息失败:', response.status, response.statusText);
|
|
this.stats = { total: 0, pending: 0, review: 0, ready: 0, published: 0, today: 0 };
|
|
}
|
|
} catch (error) {
|
|
console.error('获取统计信息失败:', error);
|
|
this.$message.error('获取统计信息失败: ' + error.message);
|
|
this.stats = { total: 0, pending: 0, review: 0, ready: 0, published: 0, today: 0 };
|
|
} finally { this.loadingStats = false; }
|
|
},
|
|
async fetchModules() {
|
|
try {
|
|
const token = localStorage.getItem('authToken');
|
|
const resp = await fetch('/api/system/modules/status', {
|
|
headers: { 'Authorization': 'Bearer ' + token }
|
|
});
|
|
if (resp.ok) {
|
|
const data = await resp.json();
|
|
this.modules = data.modules || [];
|
|
const s = data.scheduler || {};
|
|
this.schedulerRunning = s.running;
|
|
this.schedulerStatus = (s.running ? `运行中 · ${s.jobs ? s.jobs.length : 0} 个任务` : '未启动');
|
|
}
|
|
} catch (e) {
|
|
console.error('获取模块状态失败:', e);
|
|
this.$message.error('获取模块状态失败: ' + e.message);
|
|
}
|
|
},
|
|
goToTopics(filter) {
|
|
const url = filter ? '/topics.html?filter=' + encodeURIComponent(filter) : '/topics.html';
|
|
window.location.href = url;
|
|
},
|
|
redirectToPage(page) {
|
|
window.location.href = page.startsWith('/') ? page : '/' + page;
|
|
}
|
|
},
|
|
mounted() {
|
|
const token = localStorage.getItem('authToken');
|
|
if (!token) {
|
|
window.location.href = '/login.html';
|
|
return;
|
|
}
|
|
fetch('/api/auth/me', {
|
|
headers: { 'Authorization': 'Bearer ' + token }
|
|
})
|
|
.then(response => response.ok ? response.json() : Promise.reject())
|
|
.then(data => {
|
|
this.currentUser = data.user;
|
|
this.isAdmin = data.user.role === 'admin';
|
|
this.isLoggedIn = true;
|
|
this.currentPage = 'overview';
|
|
this.fetchStats();
|
|
this.fetchModules();
|
|
})
|
|
.catch(() => {
|
|
localStorage.removeItem('authToken');
|
|
window.location.href = '/login.html';
|
|
});
|
|
}
|
|
};
|
|
|
|
const app = Vue.createApp(App);
|
|
app.use(ElementPlus);
|
|
if (window.installIcons) { window.installIcons(app); }
|
|
if (window.installUniNav) { window.installUniNav(app); }
|
|
app.mount('#app');
|
|
</script>
|
|
</body>
|
|
</html>
|