feat: 优化选题/任务/日志页面布局并打通任务系统

- topics.html: 重构布局(page-header模式),创作改为走 /api/tasks/run-creator 任务系统
- tasks.html: 重试功能实现,调用 /api/tasks/run-creator 重新提交创作
- logs.html: 统一布局风格
- 三个页面添加 min-height / overflow-x / 统一间距
- backend/run.sh: 修复入口为 app.main:app
This commit is contained in:
lt
2026-05-09 19:58:49 +08:00
parent 25694db33b
commit bc6a302e59
4 changed files with 310 additions and 704 deletions
+45 -98
View File
@@ -7,130 +7,93 @@
<link rel="stylesheet" href="element-plus.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; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background: #f5f7fa; color: #303133; }
.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; }
.sidebar { width: 180px; background: white; padding: 16px; box-shadow: 2px 0 8px rgba(0,0,0,0.05); }
.main-content { display: flex; flex: 1; max-width: 1400px; margin: 0 auto; min-height: calc(100vh - 60px); }
.content-area { flex: 1; padding: 24px; overflow-y: auto; }
.card { background: white; border-radius: 12px; padding: 24px; margin-bottom: 24px; box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.card { background: white; border-radius: 12px; padding: 24px; margin-bottom: 24px; box-shadow: 0 2px 8px rgba(0,0,0,0.08); overflow-x: auto; }
.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; }
@media (max-width: 768px) {
.sidebar { display: none; }
.mobile-nav { display: flex; }
.content-area { padding: 16px; padding-bottom: 80px; }
}
/* logs.html 移动端优化 */
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
.page-title { font-size: 24px; font-weight: 700; color: #303133; display: flex; align-items: center; gap: 8px; }
.controls { display: flex; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; align-items: center; }
.log-container { max-height: 600px; overflow-y: auto; background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 8px; }
.log-container pre { margin: 0; padding: 16px; white-space: pre-wrap; word-wrap: break-word; font-size: 13px; line-height: 1.6; color: #303133; }
@media (max-width: 768px) {
.log-controls { flex-direction: column; gap: 8px; }
.log-controls .el-select, .log-controls .el-date-picker { width: 100% !important; }
.el-card { margin: 0 -16px; border-radius: 0; min-height: calc(100vh - 180px); }
.el-card .el-card__body { padding: 12px; }
pre { font-size: 11px; line-height: 1.4; }
.content-area { padding: 16px; padding-bottom: 80px; }
.card { padding: 16px; }
.controls { flex-direction: column; align-items: stretch; }
.controls .el-select, .controls .el-date-picker { width: 100% !important; }
.log-container { max-height: calc(100vh - 250px); }
.log-container pre { font-size: 11px; padding: 12px; }
}
</style>
<script src="navigation-component.js"></script>
<script src="navbar-component.js"></script>
</head>
<body>
<div id="app">
<navbar-component
title="系统日志"
:username="currentUser.username"
:is-admin="isAdmin"
@logout="handleLogout"
></navbar-component>
<navigation-component
current-page="logs"
:is-admin="isAdmin"
@navigate="redirectToPage"
></navigation-component>
<div class="main-content">
<navbar-component title="系统日志" :username="currentUser.username" :is-admin="isAdmin" @logout="handleLogout"></navbar-component>
<navigation-component current-page="logs" :is-admin="isAdmin" @navigate="redirectToPage"></navigation-component>
<div class="main-content">
<main class="content-area">
<div class="card">
<h2 style="font-size: 24px; font-weight: 600; margin-bottom: 24px;">📄 系统日志</h2>
<div style="display: flex; gap: 16px; margin-bottom: 24px; flex-wrap: wrap;">
<el-select v-model="logType" placeholder="日志类型" size="default" style="width: 180px;">
<div class="page-header">
<h2 class="page-title">📄 系统日志</h2>
</div>
<div class="controls">
<el-select v-model="logType" placeholder="日志类型" style="width: 180px;">
<el-option label="创作日志" value="creator"></el-option>
<el-option label="优化日志" value="optimizer"></el-option>
<el-option label="收集日志" value="collector"></el-option>
</el-select>
<el-date-picker v-model="logDate" type="date" placeholder="选择日期" format="YYYY-MM-DD" value-format="YYYY-MM-DD" size="default"></el-date-picker>
<el-date-picker v-model="logDate" type="date" placeholder="选择日期" format="YYYY-MM-DD" value-format="YYYY-MM-DD"></el-date-picker>
<el-button type="primary" @click="fetchLogs" :loading="loadingLogs">加载日志</el-button>
</div>
<el-card v-if="logContent" ref="logContainer" class="font-mono text-sm bg-gray-50" style="max-height: 600px; overflow-y: auto; background: #f9fafb; border: 1px solid #e5e7eb;"><pre style="margin: 0; white-space: pre-wrap; word-wrap: break-word;">{{ logContent }}</pre></el-card>
<el-empty v-else description="请先选择类型和日期,然后点击加载"></el-empty>
<div v-if="logContent" class="log-container">
<pre>{{ logContent }}</pre>
</div>
<el-empty v-else description="请选择类型和日期,点击加载"></el-empty>
</div>
</main>
</div>
</div>
<script src="vue.global.prod.js"></script>
<script src="element-plus.full.js"></script>
<script>
const LogsApp = {
data() {
const today = new Date().toISOString().split('T')[0]; // YYYY-MM-DD
return {
isLoggedIn: false,
isAdmin: false,
currentUser: { username: '' },
logType: 'creator',
logDate: today,
logContent: '',
loadingLogs: false
} },
const today = new Date().toISOString().split('T')[0];
return {
isLoggedIn: false, isAdmin: false, currentUser: { username: '' },
logType: 'creator', logDate: today, logContent: '', loadingLogs: false
}
},
methods: {
async fetchLogs() {
// 验证输入
if (!this.logType || !this.logDate) {
this.$message.warning('请选择日志类型和日期');
return;
}
if (!this.logType || !this.logDate) { this.$message.warning('请选择日志类型和日期'); return; }
this.loadingLogs = true;
try {
const token = localStorage.getItem('authToken');
if (!token) { this.$message.error('请先登录'); return; }
const response = await fetch(`/api/logs?type=${encodeURIComponent(this.logType)}&date=${encodeURIComponent(this.logDate)}`, {
headers: { 'Authorization': 'Bearer ' + token }
});
if (!response.ok) {
const errorData = await response.json().catch(() => ({}));
throw new Error(errorData.detail || `请求失败: ${response.status}`);
}
if (!response.ok) { const errorData = await response.json().catch(() => ({})); throw new Error(errorData.detail || `请求失败: ${response.status}`); }
const data = await response.json();
// 后端返回: { type, date, content }
this.logContent = `日志类型:${data.type}\n日期:${data.date}\n\n${data.content || '(日志文件为空)'}`;
this.$message.success('日志加载成功');
this.$nextTick(() => {
const container = this.$refs.logContainer;
if (container && container.$el) {
container.$el.scrollTop = container.$el.scrollHeight;
}
});
} catch (error) {
console.error('获取日志失败:', error);
this.$message.error(`获取日志失败: ${error.message}`);
this.logContent = '';
} finally {
this.loadingLogs = false;
}
} finally { this.loadingLogs = false; }
},
handleLogout() { localStorage.removeItem('authToken'); localStorage.removeItem('userRole'); localStorage.removeItem('currentUser'); window.location.href = '/login.html'; },
redirectToPage(page) { window.location.href = page.startsWith('/') ? page : '/' + page; },
@@ -143,29 +106,13 @@
.catch(() => { localStorage.removeItem('authToken'); localStorage.removeItem('userRole'); localStorage.removeItem('currentUser'); window.location.href = '/login.html'; });
}
},
mounted() {
this.checkAuth();
}
mounted() { this.checkAuth(); }
};
const app = Vue.createApp(LogsApp);
app.use(ElementPlus);
// 安装导航组件
if (window.installNavbar) { window.installNavbar(app); }
// 安装导航组件
if (window.installNavigation) { window.installNavigation(app); } else if (window.NavigationComponent) { app.component("navigation-component", window.NavigationComponent); }
app.mount('#app');
// 调试代码:检查导航组件状态
setTimeout(() => {
const hasNav = !!document.querySelector('.navigation-wrapper');
const hasSidebar = !!document.querySelector('.navigation-wrapper .sidebar');
console.log('[调试] 导航wrapper:', hasNav);
console.log('[调试] 侧边栏:', hasSidebar);
if (!hasNav) {
console.error('[调试] 导航组件未渲染!window.NavigationComponent=', !!window.NavigationComponent);
console.error('[调试] app实例是否存在组件注册?', Vue && Vue.app && Vue.app._context.components['navigation-component']);
}
}, 100);
const app = Vue.createApp(LogsApp);
app.use(ElementPlus);
if (window.installNavbar) { window.installNavbar(app); }
if (window.installNavigation) { window.installNavigation(app); } else if (window.NavigationComponent) { app.component("navigation-component", window.NavigationComponent); }
app.mount('#app');
</script>
</body>
</html>
</html>