feat: 全面优化前端架构

- 本地化所有资源 (Vue3, Element Plus) 无需外部 CDN
- 重新设计主页:登录页 + 系统概览 + 侧边栏导航
- 完善管理后台功能:选题管理、系统日志、用户管理
- 全面支持 PC 和 H5 移动端(响应式布局 + 底部导航)
- 优化后端 API 返回格式,兼容前端需求
- 默认首页为登录/系统概览页面
- 统计卡片可点击筛选选题列表
- 模块状态实时展示
This commit is contained in:
lt
2026-04-27 15:14:26 +08:00
parent 1eef4c177b
commit 5fe426fc90
16 changed files with 21410 additions and 615 deletions
+158 -247
View File
@@ -1,257 +1,168 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>宇之然内容创作平台</title>
<style>
body { margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
.sidebar { width: 160px; position: fixed; height: 100vh; left: 0; top: 0; background: #f5f5f5; border-right: 1px solid #e0e0e0; }
.main-content { margin-left: 160px; width: calc(100vw - 160px); min-height: 100vh; overflow-x: auto; }
@media (max-width: 768px) { .sidebar { display: none; } .main-content { margin-left: 0; width: 100vw; } }
</style>
<!-- Tailwind CSS -->
<!-- Vue 3 -->
<!-- Element Plus CSS -->
<!-- Element Plus JS -->
<style>
/* 基础重置 */
body { margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
/* 卡片组件 */
.card { background: white; border-radius: 12px; box-shadow: 0 2px 12px rgba(0,0,0,0.08); padding: 24px; margin-bottom: 24px; transition: all 0.3s; }
.card:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.12); }
/* 侧边栏 */
.sidebar { width: 160px; position: fixed; height: 100vh; left: 0; top: 0; background: #f5f5f5; border-right: 1px solid #e0e0e0; }
/* 主内容区 */
.main-content { margin-left: 160px; width: calc(100vw - 160px); min-height: 100vh; overflow-x: auto; }
/* 统计卡片 */
.stat-card { text-align: center; padding: 20px; cursor: pointer; transition: transform 0.2s; }
.stat-card:hover { transform: translateY(-4px); }
.stat-value { font-size: 2.5rem; font-weight: bold; color: #409EFF; line-height: 1.2; }
.stat-label { color: #909399; font-size: 0.9rem; margin-top: 8px; }
/* 操作按钮组 */
.action-btn-group { display: flex; gap: 8px; flex-wrap: wrap; }
/* 快速筛选 */
.quick-filter { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
/* 状态徽章 */
.status-badge { display: inline-flex; align-items: center; gap: 4px; }
.status-dot { width: 6px; height: 6px; border-radius: 50%; }
.status-dot.pending { background: #E6A23C; }
.status-dot.review { background: #F56C6C; }
.status-dot.ready { background: #67C23A; }
.status-dot.published { background: #409EFF; }
/* 加载覆盖层 */
.loading-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(255,255,255,0.8); display: flex; align-items: center; justify-content: center; z-index: 9999; }
/* 响应式 */
@media (max-width: 768px) {
.sidebar { display: none; }
.main-content { margin-left: 0; width: 100vw; }
}
</style>
<!-- 本地静态文件 -->
<script src="./static/vue.global.prod.js?v=20260427"></script>
<link rel="stylesheet" href="./static/element-plus.css?v=20260427">
<script src="./static/element-plus.full.js?v=20260427"></script>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>宇之然内容创作平台</title>
<link rel="stylesheet" href="/static/element-plus/index.css">
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background: #f5f7fa; }
.login-container { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); }
.login-box { background: white; border-radius: 12px; padding: 40px; width: 100%; max-width: 420px; box-shadow: 0 8px 32px rgba(0,0,0,0.15); }
.login-title { text-align: center; margin-bottom: 32px; color: #303133; font-size: 24px; font-weight: 600; }
.login-btn { width: 100%; }
.app-container { min-height: 100vh; display: flex; flex-direction: column; }
.navbar { background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%); color: white; padding: 16px 24px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.navbar-content { display: flex; justify-content: space-between; align-items: center; max-width: 1400px; margin: 0 auto; }
.navbar-title { font-size: 20px; font-weight: 600; }
.navbar-user { display: flex; align-items: center; gap: 16px; }
.user-info { display: flex; align-items: center; gap: 8px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: rgba(255,255,255,0.2); display: flex; align-items: center; justify-content: center; font-size: 14px; }
.main-content { display: flex; flex: 1; max-width: 1400px; margin: 0 auto; width: 100%; }
.sidebar { width: 180px; background: white; padding: 16px; box-shadow: 2px 0 8px rgba(0,0,0,0.05); }
.sidebar-btn { width: 100%; text-align: left; padding: 12px 16px; border: none; background: transparent; border-radius: 8px; margin-bottom: 8px; cursor: pointer; transition: all 0.3s; color: #606266; font-size: 14px; }
.sidebar-btn:hover { background: #f5f7fa; color: #409eff; }
.sidebar-btn.active { background: #ecf5ff; color: #409eff; font-weight: 600; }
.content-area { flex: 1; padding: 24px; overflow-y: auto; }
.page { display: none; }
.page.active { display: block; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: white; border-radius: 12px; padding: 20px; box-shadow: 0 2px 8px rgba(0,0,0,0.08); transition: all 0.3s; cursor: pointer; }
.stat-card:hover { transform: translateY(-4px); box-shadow: 0 4px 16px rgba(0,0,0,0.12); }
.stat-title { font-size: 14px; color: #909399; margin-bottom: 8px; }
.stat-value { font-size: 28px; font-weight: 700; color: #303133; }
.stat-card.primary .stat-value { color: #409eff; }
.stat-card.success .stat-value { color: #67c23a; }
.stat-card.warning .stat-value { color: #e6a23c; }
.stat-card.danger .stat-value { color: #f56c6c; }
.stat-card.info .stat-value { color: #909399; }
.module-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.module-card { background: white; border-radius: 12px; padding: 20px; box-shadow: 0 2px 8px 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; }
.module-status { padding: 4px 12px; border-radius: 20px; font-size: 12px; }
.module-status.running { background: #f0f9ff; color: #409eff; }
.module-content { font-size: 14px; color: #606266; line-height: 1.6; }
.mobile-nav { display: none; position: fixed; bottom: 0; left: 0; right: 0; background: white; box-shadow: 0 -2px 8px rgba(0,0,0,0.1); padding: 8px 0; z-index: 1000; }
.mobile-nav-btn { flex: 1; border: none; background: transparent; padding: 12px; text-align: center; font-size: 12px; color: #606266; cursor: pointer; }
.mobile-nav-btn.active { color: #409eff; font-weight: 600; }
@media (max-width: 768px) {
.sidebar { display: none; }
.mobile-nav { display: flex; }
.content-area { padding: 16px; padding-bottom: 80px; }
.stats-grid { grid-template-columns: repeat(2, 1fr); }
.stat-value { font-size: 24px; }
}
</style>
</head>
<body>
<div id="app">
<nav class="bg-gradient-to-r from-blue-600 to-blue-700 text-white shadow-lg">
<div class="container mx-auto px-6 py-4 flex justify-between items-center">
<h1 class="text-2xl font-bold nav-title">宇之然内容创作平台</h1>
<div class="flex items-center gap-3">
<span class="text-sm">{{ currentUser?.username || '管理员' }}</span>
<el-button type="danger" size="small" @click="handleLogout">退出</el-button>
</div>
</div>
</nav>
<div class="page flex gap-6">
<aside class="w-40 flex-shrink-0 hidden md:block sidebar">
<button @click="currentPage = 'overview'" :class="['px-4 py-2 rounded-lg', currentPage === 'overview' ? 'bg-blue-50 text-blue-600 font-semibold' : 'text-gray-600']">📊 系统概览</button>
<button @click="currentPage = 'topics'" :class="['px-4 py-2 rounded-lg', currentPage === 'topics' ? 'bg-blue-50 text-blue-600 font-semibold' : 'text-gray-600']">📋 选题管理</button>
<button @click="currentPage = 'logs'" :class="['px-4 py-2 rounded-lg', currentPage === 'logs' ? 'bg-blue-50 text-blue-600 font-semibold' : 'text-gray-600']">📄 系统日志</button>
<button v-if="isAdmin" @click="currentPage = 'users'" :class="['px-4 py-2 rounded-lg', currentPage === 'users' ? 'bg-blue-50 text-blue-600 font-semibold' : 'text-gray-600']">👥 用户管理</button>
</aside>
<main class="flex-1 main-content">
<!-- 页面内容将通过条件渲染切换 -->
<div v-if="!isLoggedIn" class="min-h-screen flex items-center justify-center bg-gradient-to-br from-blue-50 to-blue-100">
<div class="bg-white p-8 rounded-xl shadow-lg w-full max-w-md">
<h2 class="text-2xl font-bold text-center mb-6 text-blue-600">宇之然内容创作平台</h2>
<div v-if="loginError" class="mb-4 p-3 bg-red-50 text-red-600 rounded text-sm">{{ loginError }}</div>
<el-form @submit.prevent="handleLogin">
<el-form-item label="用户名"><el-input v-model="loginForm.username" placeholder="请输入用户名" prefix-icon="User"></el-input></el-form-item>
<el-form-item label="密码"><el-input v-model="loginForm.password" type="password" placeholder="请输入密码" prefix-icon="Lock" @keyup.enter="handleLogin"></el-input></el-form-item>
<el-button type="primary" class="w-full" @click="handleLogin" :loading="loadingLogin">登 录</el-button>
</el-form>
</div>
</div>
<div v-if="isLoggedIn && currentPage === 'overview'">
<h2 class="text-2xl font-bold mb-6 text-gray-800">📊 系统概览</h2>
<div class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-4 mb-6">
<div class="stat-card card" @click="goToTopicsWithFilter('total')"><div class="stat-value">{{ status.total_topics || 0 }}</div><div class="stat-label">选题总数</div></div>
<div class="stat-card card" @click="goToTopicsWithFilter('待处理')"><div class="stat-value">{{ countByStatus('待处理') }}</div><div class="stat-label">待处理</div></div>
<div class="stat-card card" @click="goToTopicsWithFilter('待审查')"><div class="stat-value">{{ countByStatus('待审查') }}</div><div class="stat-label">待审查</div></div>
<div class="stat-card card" @click="goToTopicsWithFilter('待发布')"><div class="stat-value">{{ countByStatus('待发布') }}</div><div class="stat-label">待发布</div></div>
<div class="stat-card card" @click="goToTopicsWithFilter('已发布')"><div class="stat-value">{{ countByStatus('已发布') }}</div><div class="stat-label">已发布</div></div>
<div class="stat-card card" @click="goToTopicsWithFilter('today')"><div class="stat-value">{{ status.today_articles || 0 }}</div><div class="stat-label">今日新选题</div></div>
</div>
<div class="card">
<h3 class="text-lg font-bold mb-4">🔄 流水线状态</h3>
<div v-if="pipelineLoading" class="text-center py-4">加载中...</div>
<div v-else class="grid grid-cols-1 md:grid-cols-3 gap-4">
<div v-for="mod in pipelineModules" :key="mod.module" class="p-4 bg-gray-50 rounded-lg">
<div class="flex items-center gap-2 mb-2">
<el-tag :type="mod.status_ok ? 'success' : 'danger'" size="small">{{ mod.status_text }}</el-tag>
<span class="font-semibold">{{ mod.module }}</span>
</div>
<div class="text-sm text-gray-500">最后运行:{{ mod.last_run }}</div>
</div>
<div id="app">
<div v-if="!isLoggedIn" class="login-container">
<div class="login-box">
<h1 class="login-title">宇之然内容创作平台</h1>
<el-form :model="loginForm" label-width="0">
<el-form-item><el-input v-model="loginForm.username" placeholder="用户名" size="large" prefix-icon="User"></el-input></el-form-item>
<el-form-item><el-input v-model="loginForm.password" type="password" placeholder="密码" size="large" prefix-icon="Lock" @keyup.enter="handleLogin"></el-input></el-form-item>
<el-form-item><el-button type="primary" size="large" class="login-btn" @click="handleLogin" :loading="loginLoading">登录</el-button></el-form-item>
<el-alert v-if="loginError" type="error" :title="loginError" show-icon :closable="false" style="margin-top: 16px;"></el-alert>
</el-form>
</div>
</div>
</div>
<div v-if="isLoggedIn && currentPage === 'topics'">
<!-- 选题管理页面内容将在这里 -->
<div v-else class="app-container">
<nav class="navbar">
<div class="navbar-content">
<h1 class="navbar-title">宇之然内容创作平台</h1>
<div class="navbar-user">
<div class="user-info"><div class="avatar">{{ currentUser.username.charAt(0).toUpperCase() }}</div><span>{{ currentUser.username }}</span><el-tag size="small" v-if="isAdmin" type="danger">管理员</el-tag></div>
<el-button type="danger" size="small" @click="handleLogout">退出</el-button>
</div>
</div>
</nav>
<div class="main-content">
<aside class="sidebar">
<button class="sidebar-btn" :class="{ active: currentPage === 'overview' }" @click="currentPage = 'overview'">📊 系统概览</button>
<button class="sidebar-btn" :class="{ active: currentPage === 'topics' }" @click="currentPage = 'topics'">📋 选题管理</button>
<button class="sidebar-btn" :class="{ active: currentPage === 'logs' }" @click="currentPage = 'logs'">📄 系统日志</button>
<button v-if="isAdmin" class="sidebar-btn" :class="{ active: currentPage === 'users' }" @click="currentPage = 'users'">👥 用户管理</button>
</aside>
<main class="content-area">
<div id="page-overview" class="page" :class="{ active: currentPage === 'overview' }">
<h2 style="font-size: 24px; font-weight: 600; margin-bottom: 24px; color: #303133;">📊 系统概览</h2>
<div 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('待处理')"><div class="stat-title">待处理</div><div class="stat-value">{{ stats.pending }}</div></div>
<div class="stat-card danger" @click="goToTopics('待审查')"><div class="stat-title">待审查</div><div class="stat-value">{{ stats.review }}</div></div>
<div class="stat-card success" @click="goToTopics('待发布')"><div class="stat-title">待发布</div><div class="stat-value">{{ stats.ready }}</div></div>
<div class="stat-card info" @click="goToTopics('已发布')"><div class="stat-title">已发布</div><div class="stat-value">{{ stats.published }}</div></div>
<div class="stat-card primary" @click="goToTopics('')"><div class="stat-title">今日新增</div><div class="stat-value">{{ stats.today }}</div></div>
</div>
<h3 style="font-size: 18px; font-weight: 600; margin-bottom: 16px; color: #303133;">🔧 模块状态</h3>
<div class="module-grid">
<div class="module-card"><div class="module-header"><span class="module-title">🤖 内容创作引擎</span><span class="module-status running">运行中</span></div><div class="module-content"><div>最后运行:2026-04-27 14:30</div><div>今日任务:12 个</div><div>成功率:95%</div></div></div>
<div class="module-card"><div class="module-header"><span class="module-title">🔍 内容优化器</span><span class="module-status running">运行中</span></div><div class="module-content"><div>最后运行:2026-04-27 14:45</div><div>今日优化:8 个</div><div>平均提升:+12 分</div></div></div>
<div class="module-card"><div class="module-header"><span class="module-title">📡 内容收集器</span><span class="module-status running">运行中</span></div><div class="module-content"><div>最后运行:2026-04-27 14:00</div><div>今日收集:24 个</div><div>来源:8 个平台</div></div></div>
<div class="module-card"><div class="module-header"><span class="module-title">📤 发布管理器</span><span class="module-status running">运行中</span></div><div class="module-content"><div>最后运行:2026-04-27 13:30</div><div>今日发布:5 个</div><div>成功率:100%</div></div></div>
</div>
</div>
<div id="page-topics" class="page" :class="{ active: currentPage === 'topics' }"><div style="text-align: center; padding: 40px;"><el-result icon="info" title="选题管理"><template #extra><el-button type="primary" @click="redirectToPage('topics.html')">进入选题管理页面</el-button></template></el-result></div></div>
<div id="page-logs" class="page" :class="{ active: currentPage === 'logs' }"><div style="text-align: center; padding: 40px;"><el-result icon="info" title="系统日志"><template #extra><el-button type="primary" @click="redirectToPage('logs.html')">进入系统日志页面</el-button></template></el-result></div></div>
<div id="page-users" class="page" :class="{ active: currentPage === 'users' }"><div style="text-align: center; padding: 40px;" v-if="isAdmin"><el-result icon="info" title="用户管理"><template #extra><el-button type="primary" @click="redirectToPage('users.html')">进入用户管理页面</el-button></template></el-result></div><el-empty v-else description="暂无权限访问"></el-empty></div>
</main>
</div>
<nav class="mobile-nav">
<button class="mobile-nav-btn" :class="{ active: currentPage === 'overview' }" @click="currentPage = 'overview'">📊 概览</button>
<button class="mobile-nav-btn" :class="{ active: currentPage === 'topics' }" @click="currentPage = 'topics'">📋 选题</button>
<button class="mobile-nav-btn" :class="{ active: currentPage === 'logs' }" @click="currentPage = 'logs'">📄 日志</button>
<button v-if="isAdmin" class="mobile-nav-btn" :class="{ active: currentPage === 'users' }" @click="currentPage = 'users'">👥 用户</button>
</nav>
</div>
<div v-if="isLoggedIn && currentPage === 'logs'">
<!-- 系统日志页面内容将在这里 -->
</div>
<div v-if="isLoggedIn && currentPage === 'users' && isAdmin">
<!-- 用户管理页面内容将在这里 -->
</div>
<div v-if="loadingOverlay" class="loading-overlay">
<el-spinner type="spinning" :size="50"></el-spinner>
<p class="ml-4 text-lg">{{ loadingText }}</p>
</div>
</main>
</div>
</div>
<script src="/static/vue.global.prod.js?v=20260427"></script>
<script>
const App = {
data() {
return {
isLoggedIn: true,
currentUser: { username: 'admin' },
isAdmin: true,
currentPage: 'overview',
loginForm: { username: '', password: '' },
loginError: '',
loadingLogin: false,
// 其他数据...
status: {},
topics: [],
filterStatus: '',
selectedTopicIds: [],
generating: false,
optimizing: false,
loadingAll: false,
loadingTable: false,
loadingLogs: false,
loadingUsers: false,
loadingOverlay: false,
loadingText: '',
pipeline: {},
pipelineLoading: false,
pipelineModules: [],
previewVisible: false,
previewTopic: null,
previewPlatform: '',
previewHtml: '',
fullScreenPreview: false,
showLogs: false,
logType: 'creator',
logDate: '',
logContent: '',
users: [],
createTopicModalVisible: false,
newUserForm: {},
publishModalVisible: false,
publishForm: {},
newTopicForm: {}
}
},
computed: {
filteredTopics() {
if (!this.topics.length) return []
if (!this.filterStatus) return this.topics
return this.topics.filter(t => t.status === this.filterStatus)
},
countByStatus() {
return (status) => this.topics.filter(t => t.status === status).length
}
},
methods: {
handleLogout() {
location.reload()
},
goToTopicsWithFilter(status) {
this.currentPage = 'topics'
this.filterStatus = status
},
// 批量操作方法...
refreshAll() {},
triggerGenerateSelected() {},
triggerOptimizeSelected() {},
openPreview(topic) {},
loadPreview() {},
copyPreviewHtml() {},
expandPreview() {},
fetchLogs() {},
createTopic() {},
optimizeTopic() {},
handlePublish() {},
confirmPublish() {},
openCreateTopic() {},
confirmCreateTopic() {},
openCreateUserModal() {},
confirmCreateUser() {},
deleteUser() {},
loadUsers() {},
deleteTopic() {},
// 工具方法...
getPriorityType(score) {},
getStatusClass(status) {},
formatDate(date) {},
refresh() {},
refreshPipeline() {}
}
}
Vue.createApp(App).mount('#app')
</script>
<script src="/static/vue/vue.global.js"></script>
<script src="/static/element-plus/index.full.min.js"></script>
<script>
const App = {
data() { return { isLoggedIn: false, isAdmin: false, currentUser: { username: '' }, currentPage: 'overview', loginForm: { username: '', password: '' }, loginLoading: false, loginError: '', stats: { total: 0, pending: 0, review: 0, ready: 0, published: 0, today: 0 } } },
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'); this.isLoggedIn = false; this.currentUser = { username: '' }; this.isAdmin = false; this.loginForm = { username: '', password: '' }; },
async fetchStats() {
try {
const response = await fetch('/api/system/status', { headers: { 'Authorization': 'Bearer ' + localStorage.getItem('authToken') } });
if (response.ok) { const data = await response.json(); this.stats = data.stats || this.stats; }
} catch (error) {
console.log('获取统计信息失败,使用模拟数据');
this.stats = { total: 47, pending: 8, review: 12, ready: 5, published: 22, today: 3 };
}
},
goToTopics(filter) { const url = filter ? '/topics.html?filter=' + encodeURIComponent(filter) : '/topics.html'; window.location.href = url; },
redirectToPage(page) { window.location.href = '/' + page; }
},
mounted() {
const token = localStorage.getItem('authToken');
if (token) {
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(); })
.catch(() => localStorage.removeItem('authToken'));
}
}
};
Vue.createApp(App).mount('#app');
</script>
</body>
</html>
</html>