Files
yu-zhi-ran/platform/frontend/index.html
T
Yuzhiran Dev 9c37c9a574 feat: Phase 4 多租户隔离 + 四阶段升级测试 + CSS 统一化
Phase 4: org_id 注入 JWT/API 过滤/组织管理 CRUD/前端组织列
测试: tests/test_phase_upgrades.py 97项全覆盖
CSS: theme-modern.css 共享 mobile-card-list/status-dot/search-bar 等模式
修复: initial_data.py LLM配置 NOT NULL 约束, TopicResponse 含 org_id
2026-05-17 06:56:53 +08:00

378 lines
17 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); }
}
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 20px;
margin-bottom: 40px;
}
.stat-card {
background: white;
border: 1px solid #ebeef5;
border-radius: 16px;
padding: 24px;
cursor: pointer;
transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
position: relative;
overflow: hidden;
}
.stat-card:hover {
transform: translateY(-8px) scale(1.02);
border-color: #c6d8ff;
box-shadow: 0 12px 32px rgba(102, 126, 234, 0.15);
}
.stat-title {
font-size: 13px;
color: #909399;
margin-bottom: 12px;
text-transform: uppercase;
letter-spacing: 0.5px;
font-weight: 500;
}
.stat-value {
font-size: 36px;
font-weight: 800;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
line-height: 1.2;
}
.stat-card.primary .stat-value { background: linear-gradient(135deg, #667eea, #764ba2); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.stat-card.success .stat-value { background: linear-gradient(135deg, #67c23a, #85e61d); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.stat-card.warning .stat-value { background: linear-gradient(135deg, #e6a23c, #f5c543); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.stat-card.danger .stat-value { background: linear-gradient(135deg, #f56c6c, #f79296); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.stat-card.info .stat-value { background: linear-gradient(135deg, #409eff, #5cd0f3); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
/* 模块卡片 */
.module-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
gap: 20px;
}
.module-card {
background: white;
border: 1px solid #ebeef5;
border-radius: 16px;
padding: 24px;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.module-card:hover {
transform: translateY(-6px);
border-color: #c6d8ff;
box-shadow: 0 8px 24px rgba(0,0,0,0.08);
}
.module-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 16px;
}
.module-title {
font-size: 16px;
font-weight: 600;
color: #303133;
display: flex;
align-items: center;
gap: 8px;
}
.module-status {
padding: 6px 12px;
border-radius: 20px;
font-size: 12px;
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: 14px;
color: #606266;
line-height: 1.8;
}
.module-content div {
display: flex;
justify-content: space-between;
padding: 4px 0;
border-bottom: 1px dashed #f0f0f0;
}
.module-content div:last-child { border-bottom: none; }
@media (max-width: 768px) {
.stats-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
.stat-card { padding: 16px; }
.stat-value { font-size: 24px; }
.module-grid { grid-template-columns: 1fr; }
}
</style>
<style>
body { background: #f5f7fa !important; color: #303133 !important; }
.navbar { background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%) !important; border-bottom: none !important; backdrop-filter: none !important; }
.navbar-title { background: none !important; -webkit-text-fill-color: white !important; color: white !important; }
.user-info { color: white !important; }
.avatar { background: rgba(255,255,255,0.2) !important; color: white !important; }
.sidebar { background: white !important; border-right: 1px solid #ebeef5 !important; backdrop-filter: none !important; }
#page-overview h2, #page-overview h3, #page-overview .module-title { color: #303133 !important; }
#page-overview .module-content { color: #303133 !important; }
</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: 28px; font-weight: 700; margin-bottom: 32px; color: #e0e6ed;">
<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: 20px; font-weight: 600; margin-bottom: 24px; color: #e0e6ed;">
<el-icon style="vertical-align:-2px;"><IconSetting /></el-icon> 模块状态
<span style="font-size: 13px; font-weight: 400; color: #909399; margin-left: 12px;">
定时任务:
<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>
{{ schedulerStatus }}
</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 ? '运行中' : '未启动');
if (s.jobs && s.jobs.length) {
this.schedulerStatus += ' · ' + s.jobs.length + ' 个任务';
}
}
} 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>