Add pagination to admin management tabs (cases/categories/sources/orgs)

This commit is contained in:
Yuzhiran Dev
2026-05-18 19:18:09 +08:00
parent 7169ddb678
commit a09e7e6671
14 changed files with 455 additions and 340 deletions
+9 -97
View File
@@ -3,107 +3,19 @@
<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">
<title>宇之然 - 运行日志</title>
<style>
.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) {
.controls { flex-direction: column; align-items: stretch; }
.controls .el-select, .controls .el-date-picker { width: 100% !important; }
.controls .el-button { width: 100%; }
.log-container { max-height: calc(100vh - 280px); }
.log-container pre { font-size: 11px; padding: 12px; }
}
body { margin: 0; display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, #667eea, #764ba2); color: #fff; font-family: system-ui, sans-serif; }
.msg { text-align: center; padding: 20px; }
.msg h2 { font-size: 24px; font-weight: 600; margin-bottom: 12px; }
.msg p { font-size: 14px; opacity: 0.8; }
</style>
<script src="uni-nav.js"></script>
<script>window.location.href = '/admin.html#tab=logs';</script>
</head>
<body>
<div id="app">
<uni-nav title="系统日志" :username="currentUser.username" :is-admin="isAdmin" current-page="logs" @navigate="redirectToPage" @logout="handleLogout">
</uni-nav>
<div class="main-content">
<main class="content-area">
<div class="card page-fade">
<div class="page-header">
<h2 class="page-title"><el-icon style="vertical-align:-2px;"><IconDocument /></el-icon> 系统日志</h2>
</div>
<div class="controls">
<el-select v-model="logType" placeholder="日志类型" style="width: 200px;">
<el-option label="创作日志" value="creator"></el-option>
<el-option label="审查日志" value="optimizer"></el-option>
<el-option label="研究日志" value="research"></el-option>
<el-option label="大纲日志" value="outline"></el-option>
<el-option label="写作日志" value="writer"></el-option>
<el-option label="发布日志" value="publisher"></el-option>
<el-option label="收集日志" value="collector"></el-option>
<el-option label="通知日志" value="notifier"></el-option>
<el-option label="趋势日志" value="trends"></el-option>
</el-select>
<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>
<div v-if="logContent" class="log-container">
<pre>{{ logContent }}</pre>
</div>
<el-empty v-else description="请选择类型和日期,点击加载"></el-empty>
</div>
</main>
</div>
<div class="msg">
<h2>运行日志已合并</h2>
<p>正在跳转到 系统管理 → 运行日志...</p>
</div>
<script src="vue.global.prod.js"></script>
<script src="icon-components.js"></script>
<script src="element-plus.full.js"></script>
<script>
const LogsApp = {
data() {
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; }
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}`); }
const data = await response.json();
this.logContent = `日志类型:${data.type}\n日期:${data.date}\n\n${data.content || '(日志文件为空)'}`;
this.$message.success('日志加载成功');
} catch (error) {
console.error('获取日志失败:', error);
this.$message.error(`获取日志失败: ${error.message}`);
this.logContent = '';
} 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; },
checkAuth() {
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; })
.catch(() => { localStorage.removeItem('authToken'); localStorage.removeItem('userRole'); localStorage.removeItem('currentUser'); window.location.href = '/login.html'; });
}
},
mounted() { this.checkAuth(); }
};
const app = Vue.createApp(LogsApp);
app.use(ElementPlus);
if (window.installIcons) { window.installIcons(app); }
if (window.installUniNav) { window.installUniNav(app); }
app.mount('#app');
</script>
</body>
</html>