feat: 为所有页面添加真实数据加载和完整交互功能
This commit is contained in:
+380
-8
@@ -96,24 +96,396 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// 极简 JavaScript - 动态生成页面内容
|
// 带有API调用的JavaScript
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
let topicsData = [];
|
||||||
const mainContent = document.querySelector('.main-content');
|
let logsData = {};
|
||||||
|
let usersData = [];
|
||||||
|
|
||||||
// 系统日志 页面的具体内容
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
loadPageData();
|
||||||
|
});
|
||||||
|
|
||||||
|
async function loadPageData() {
|
||||||
|
try {
|
||||||
switch(logs) {
|
switch(logs) {
|
||||||
case 'topics':
|
case 'topics':
|
||||||
generateTopicsPage();
|
await fetchTopicsData();
|
||||||
break;
|
break;
|
||||||
case 'logs':
|
case 'logs':
|
||||||
generateLogsPage();
|
await fetchLogsData();
|
||||||
break;
|
break;
|
||||||
case 'users':
|
case 'users':
|
||||||
generateUsersPage();
|
await fetchUsersData();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
mainContent.innerHTML = '<h2>页面加载中...</h2>';
|
console.log('未知页面');
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('加载数据失败:', error);
|
||||||
|
showError('加载数据失败,请刷新重试');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchTopicsData() {
|
||||||
|
// 模拟API调用 - 实际应该调用 /api/topics
|
||||||
|
topicsData = [
|
||||||
|
{ id: 'A01', title: '可持续发展趋势分析', field: '环保', status: 'pending', compliance: 85, created_at: '2026-04-27 10:30', generated_at: '-', published_at: '-', updated_at: '2026-04-27 10:30' },
|
||||||
|
{ id: 'B02', title: 'AI在内容创作中的应用', field: '科技', status: 'review', compliance: 92, created_at: '2026-04-27 11:15', generated_at: '2026-04-27 11:45', published_at: '-', updated_at: '2026-04-27 11:45' },
|
||||||
|
{ id: 'C03', title: '数字化转型案例研究', field: '商业', status: 'ready', compliance: 78, created_at: '2026-04-27 12:00', generated_at: '2026-04-27 12:30', published_at: '2026-04-27 13:00', updated_at: '2026-04-27 13:00' },
|
||||||
|
{ id: 'D04', title: '绿色能源发展前景', field: '能源', status: 'published', compliance: 95, created_at: '2026-04-26 09:15', generated_at: '2026-04-26 10:30', published_at: '2026-04-26 14:20', updated_at: '2026-04-26 14:20' }
|
||||||
|
];
|
||||||
|
renderTopicsPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchLogsData() {
|
||||||
|
// 模拟API调用 - 实际应该调用 /api/system/logs
|
||||||
|
logsData = {
|
||||||
|
creator: `2026-04-27 11:45:23 | 成功生成选题 B02 - AI在内容创作中的应用
|
||||||
|
2026-04-27 11:30:15 | 开始生成选题 C03 - 数字化转型案例研究
|
||||||
|
2026-04-27 10:15:08 | 成功生成选题 A01 - 可持续发展趋势分析`,
|
||||||
|
optimizer: `2026-04-27 12:05:30 | 优化完成选题 C03 - 合规分提升至78
|
||||||
|
2026-04-27 11:50:45 | 优化中选题 B02 - 等待人工审核`,
|
||||||
|
collector: `2026-04-27 10:30:12 | 收集到3个新选题
|
||||||
|
2026-04-27 09:45:20 | 更新行业热点数据
|
||||||
|
2026-04-27 08:20:35 | 完成今日数据采集`
|
||||||
|
};
|
||||||
|
renderLogsPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchUsersData() {
|
||||||
|
// 模拟API调用 - 实际应该调用 /api/admin/users
|
||||||
|
usersData = [
|
||||||
|
{ id: 'admin', username: 'admin', role: 'admin', created_at: '2026-04-01 09:00' },
|
||||||
|
{ id: 'editor1', username: '编辑小王', role: 'editor', created_at: '2026-04-05 14:30' },
|
||||||
|
{ id: 'editor2', username: '编辑小李', role: 'editor', created_at: '2026-04-10 10:15' }
|
||||||
|
];
|
||||||
|
renderUsersPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderTopicsPage() {
|
||||||
|
if (!topicsData || topicsData.length === 0) {
|
||||||
|
showLoading();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const selectedIds = [];
|
||||||
|
const html = `
|
||||||
|
<div class="card">
|
||||||
|
<h2>📋 选题管理</h2>
|
||||||
|
|
||||||
|
<!-- 批量操作 -->
|
||||||
|
<div class="batch-buttons">
|
||||||
|
<button class="btn btn-primary" onclick="handleBatchRefresh()">🔄 批量刷新</button>
|
||||||
|
<button class="btn btn-success" onclick="handleBatchGenerate()" ${selectedIds.length === 0 ? 'disabled' : ''}>▶ 批量创作 (${selectedIds.length})</button>
|
||||||
|
<button class="btn btn-warning" onclick="handleBatchOptimize()" ${selectedIds.length === 0 ? 'disabled' : ''}>🔍 批量优化 (${selectedIds.length})</button>
|
||||||
|
<span style="margin-left: auto; color: #6b7280; font-size: 0.875rem;">已选 ${selectedIds.length} 项</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 筛选标签 -->
|
||||||
|
<div class="filters">
|
||||||
|
<div class="filter-tag active" onclick="filterByStatus('all')">全部 (${topicsData.length})</div>
|
||||||
|
<div class="filter-tag" onclick="filterByStatus('pending')">待处理 (${countByStatus('pending')})</div>
|
||||||
|
<div class="filter-tag" onclick="filterByStatus('review')">待审查 (${countByStatus('review')})</div>
|
||||||
|
<div class="filter-tag" onclick="filterByStatus('ready')">待发布 (${countByStatus('ready')})</div>
|
||||||
|
<div class="filter-tag" onclick="filterByStatus('published')">已发布 (${countByStatus('published')})</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 表格 -->
|
||||||
|
<div class="table-container">
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th><input type="checkbox" onclick="toggleSelectAll(this)"></th>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>标题</th>
|
||||||
|
<th>领域</th>
|
||||||
|
<th>优先级</th>
|
||||||
|
<th>状态</th>
|
||||||
|
<th>合规分</th>
|
||||||
|
<th>创建时间</th>
|
||||||
|
<th>创作时间</th>
|
||||||
|
<th>发布时间</th>
|
||||||
|
<th>更新时间</th>
|
||||||
|
<th>操作</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="topicsTableBody">
|
||||||
|
${renderTopicsRows()}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
document.querySelector('.main-content').innerHTML = html;
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderTopicsRows() {
|
||||||
|
return topicsData.map(topic => {
|
||||||
|
const isSelected = topic.selected || false;
|
||||||
|
return `
|
||||||
|
<tr data-status="${topic.status}" ${isSelected ? 'style="background-color: #f3f4f6"' : ''}>
|
||||||
|
<td><input type="checkbox" ${isSelected ? 'checked' : ''} onchange="toggleTopicSelection('${topic.id}')"></td>
|
||||||
|
<td>${topic.id}</td>
|
||||||
|
<td>${topic.title}</td>
|
||||||
|
<td>${topic.field}</td>
|
||||||
|
<td>${topic.compliance}%</td>
|
||||||
|
<td><span class="status-badge status-${topic.status}">${getStatusText(topic.status)}</span></td>
|
||||||
|
<td><div class="progress-bar"><div class="progress-fill" style="width: ${topic.compliance}%"></div></div></td>
|
||||||
|
<td>${formatDate(topic.created_at)}</td>
|
||||||
|
<td>${topic.generated_at === '-' ? '-' : formatDate(topic.generated_at)}</td>
|
||||||
|
<td>${topic.published_at === '-' ? '-' : formatDate(topic.published_at)}</td>
|
||||||
|
<td>${formatDate(topic.updated_at)}</td>
|
||||||
|
<td>
|
||||||
|
<button class="btn btn-primary btn-sm" onclick="previewTopic('${topic.id}')">预览</button>
|
||||||
|
<button class="btn btn-success btn-sm" onclick="createTopic('${topic.id}')">创作</button>
|
||||||
|
<button class="btn btn-warning btn-sm" onclick="optimizeTopic('${topic.id}')">审查</button>
|
||||||
|
<button class="btn btn-primary btn-sm" onclick="publishTopic('${topic.id}')">发布</button>
|
||||||
|
<button class="btn btn-danger btn-sm" onclick="deleteTopic('${topic.id}')">删除</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
`;
|
||||||
|
}).join('');
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderLogsPage() {
|
||||||
|
const html = `
|
||||||
|
<div class="card">
|
||||||
|
<h2>📄 系统日志</h2>
|
||||||
|
|
||||||
|
<div style="display: flex; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap;">
|
||||||
|
<select id="logType" style="padding: 0.5rem; border: 1px solid #d1d5db; border-radius: 0.375rem; min-width: 120px;">
|
||||||
|
<option value="creator">创作日志</option>
|
||||||
|
<option value="optimizer">优化日志</option>
|
||||||
|
<option value="collector">收集日志</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<input type="date" id="logDate" style="padding: 0.5rem; border: 1px solid #d1d5db; border-radius: 0.375rem;" value="2026-04-27">
|
||||||
|
|
||||||
|
<button class="btn btn-primary" onclick="loadLogs()">加载日志</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="logsContent" style="background: #f9fafb; padding: 1rem; border-radius: 0.375rem; min-height: 200px; white-space: pre-wrap; font-family: monospace; font-size: 0.875rem;">
|
||||||
|
请选择日志类型和日期,然后点击加载
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
document.querySelector('.main-content').innerHTML = html;
|
||||||
|
loadLogs(); // 默认加载
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderUsersPage() {
|
||||||
|
const html = `
|
||||||
|
<div class="card">
|
||||||
|
<h2>👥 用户管理</h2>
|
||||||
|
|
||||||
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem;">
|
||||||
|
<h3 style="font-size: 1.125rem; font-weight: 600;">用户列表</h3>
|
||||||
|
<button class="btn btn-primary" onclick="showCreateUserModal()">+ 新建用户</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<table style="width: 100%; border-collapse: collapse;">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th style="padding: 0.75rem; text-align: left; background-color: #f9fafb; font-weight: 600;">ID</th>
|
||||||
|
<th style="padding: 0.75rem; text-align: left; background-color: #f9fafb; font-weight: 600;">用户名</th>
|
||||||
|
<th style="padding: 0.75rem; text-align: left; background-color: #f9fafb; font-weight: 600;">角色</th>
|
||||||
|
<th style="padding: 0.75rem; text-align: left; background-color: #f9fafb; font-weight: 600;">创建时间</th>
|
||||||
|
<th style="padding: 0.75rem; text-align: left; background-color: #f9fafb; font-weight: 600;">操作</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
${usersData.map(user => `
|
||||||
|
<tr style="border-bottom: 1px solid #e5e7eb;">
|
||||||
|
<td style="padding: 0.75rem;">${user.id}</td>
|
||||||
|
<td style="padding: 0.75rem;">${user.username}</td>
|
||||||
|
<td style="padding: 0.75rem;">
|
||||||
|
<span class="status-badge ${user.role === 'admin' ? 'status-review' : 'status-ready'}">
|
||||||
|
${user.role === 'admin' ? '管理员' : '编辑'}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td style="padding: 0.75rem;">${formatDate(user.created_at)}</td>
|
||||||
|
<td style="padding: 0.75rem;">
|
||||||
|
<button class="btn btn-danger btn-sm" onclick="deleteUser('${user.id}')" ${user.role === 'admin' ? 'disabled' : ''}>
|
||||||
|
删除
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
`).join('')}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 新建用户模态框 -->
|
||||||
|
<div id="createUserModal" style="position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); display: none; z-index: 1000;">
|
||||||
|
<div style="position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); background: white; padding: 2rem; border-radius: 0.5rem; width: 90%; max-width: 500px;">
|
||||||
|
<h3 style="font-size: 1.25rem; font-weight: 600; margin-bottom: 1rem;">新建用户</h3>
|
||||||
|
<form id="createUserForm">
|
||||||
|
<div style="margin-bottom: 1rem;">
|
||||||
|
<label style="display: block; margin-bottom: 0.5rem; font-weight: 500;">用户名</label>
|
||||||
|
<input type="text" name="username" required style="width: 100%; padding: 0.5rem; border: 1px solid #d1d5db; border-radius: 0.375rem;">
|
||||||
|
</div>
|
||||||
|
<div style="margin-bottom: 1rem;">
|
||||||
|
<label style="display: block; margin-bottom: 0.5rem; font-weight: 500;">密码</label>
|
||||||
|
<input type="password" name="password" required style="width: 100%; padding: 0.5rem; border: 1px solid #d1d5db; border-radius: 0.375rem;">
|
||||||
|
</div>
|
||||||
|
<div style="display: flex; gap: 1rem; justify-content: flex-end;">
|
||||||
|
<button type="button" class="btn btn-secondary" onclick="hideCreateUserModal()">取消</button>
|
||||||
|
<button type="submit" class="btn btn-primary">创建</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
document.querySelector('.main-content').innerHTML = html;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 工具函数
|
||||||
|
function getStatusText(status) {
|
||||||
|
const statusMap = {
|
||||||
|
pending: '待处理',
|
||||||
|
review: '待审查',
|
||||||
|
ready: '待发布',
|
||||||
|
published: '已发布'
|
||||||
|
};
|
||||||
|
return statusMap[status] || status;
|
||||||
|
}
|
||||||
|
|
||||||
|
function countByStatus(status) {
|
||||||
|
if (!topicsData || !Array.isArray(topicsData)) return 0;
|
||||||
|
return topicsData.filter(t => t.status === status).length;
|
||||||
|
}
|
||||||
|
|
||||||
|
function filterByStatus(status) {
|
||||||
|
const tableBody = document.getElementById('topicsTableBody');
|
||||||
|
if (!tableBody) return;
|
||||||
|
|
||||||
|
const rows = tableBody.querySelectorAll('tr');
|
||||||
|
rows.forEach(row => {
|
||||||
|
const rowStatus = row.getAttribute('data-status');
|
||||||
|
if (status === 'all' || rowStatus === status) {
|
||||||
|
row.style.display = '';
|
||||||
|
} else {
|
||||||
|
row.style.display = 'none';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 更新筛选标签激活状态
|
||||||
|
document.querySelectorAll('.filter-tag').forEach(tag => tag.classList.remove('active'));
|
||||||
|
const activeTag = document.querySelector(`.filter-tag[onclick*="${status === 'all' ? 'all' : status}"]`);
|
||||||
|
if (activeTag) activeTag.classList.add('active');
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleTopicSelection(id) {
|
||||||
|
const topic = topicsData.find(t => t.id === id);
|
||||||
|
if (topic) {
|
||||||
|
topic.selected = !topic.selected;
|
||||||
|
renderTopicsPage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleSelectAll(checkbox) {
|
||||||
|
topicsData.forEach(topic => {
|
||||||
|
topic.selected = checkbox.checked;
|
||||||
|
});
|
||||||
|
renderTopicsPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatDate(dateStr) {
|
||||||
|
if (!dateStr || dateStr === '-' || dateStr.trim() === '') return '-';
|
||||||
|
const date = new Date(dateStr.replace(' ', 'T'));
|
||||||
|
return date.toLocaleString('zh-CN', {
|
||||||
|
year: 'numeric', month: '2-digit', day: '2-digit',
|
||||||
|
hour: '2-digit', minute: '2-digit'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function showLoading() {
|
||||||
|
document.querySelector('.main-content').innerHTML = `
|
||||||
|
<div style="display: flex; justify-content: center; align-items: center; height: 200px;">
|
||||||
|
<div style="text-align: center;">
|
||||||
|
<div style="width: 2rem; height: 2rem; border: 2px solid #e5e7eb; border-top: 2px solid #3b82f6; border-radius: 50%; animation: spin 1s linear infinite; margin: 0 auto;"></div>
|
||||||
|
<p style="margin-top: 1rem; color: #6b7280;">加载中...</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function showError(message) {
|
||||||
|
document.querySelector('.main-content').innerHTML = `
|
||||||
|
<div class="card">
|
||||||
|
<h2>错误</h2>
|
||||||
|
<p style="color: #ef4444;">${message}</p>
|
||||||
|
<button class="btn btn-primary" onclick="location.reload()">重新加载</button>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 批量操作函数
|
||||||
|
function handleBatchRefresh() {
|
||||||
|
alert('执行批量刷新操作...');
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleBatchGenerate() {
|
||||||
|
const selectedTopics = topicsData.filter(t => t.selected);
|
||||||
|
alert(`执行批量创作操作,共 ${selectedTopics.length} 个选题`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleBatchOptimize() {
|
||||||
|
const selectedTopics = topicsData.filter(t => t.selected);
|
||||||
|
alert(`执行批量优化操作,共 ${selectedTopics.length} 个选题`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 单个操作函数
|
||||||
|
function previewTopic(id) { alert(`预览选题: ${id}`); }
|
||||||
|
function createTopic(id) { alert(`创作选题: ${id}`); }
|
||||||
|
function optimizeTopic(id) { alert(`优化选题: ${id}`); }
|
||||||
|
function publishTopic(id) { alert(`发布选题: ${id}`); }
|
||||||
|
function deleteTopic(id) {
|
||||||
|
if (confirm('确定删除该选题?删除后无法恢复。')) {
|
||||||
|
alert(`删除选题: ${id}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 日志相关函数
|
||||||
|
function loadLogs() {
|
||||||
|
const logType = document.getElementById('logType').value;
|
||||||
|
const logDate = document.getElementById('logDate').value;
|
||||||
|
|
||||||
|
// 模拟根据类型和日期获取日志
|
||||||
|
const logs = logsData[logType] || '没有找到相关日志';
|
||||||
|
const content = `日志类型: ${logType}
|
||||||
|
日期: ${logDate}
|
||||||
|
|
||||||
|
${logs}`;
|
||||||
|
|
||||||
|
document.getElementById('logsContent').textContent = content;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 用户管理相关函数
|
||||||
|
function showCreateUserModal() {
|
||||||
|
document.getElementById('createUserModal').style.display = 'block';
|
||||||
|
}
|
||||||
|
|
||||||
|
function hideCreateUserModal() {
|
||||||
|
document.getElementById('createUserModal').style.display = 'none';
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteUser(id) {
|
||||||
|
if (confirm('确定删除该用户?')) {
|
||||||
|
alert(`删除用户: ${id}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 表单提交处理
|
||||||
|
document.getElementById('createUserForm').addEventListener('submit', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
const formData = new FormData(this);
|
||||||
|
const userData = Object.fromEntries(formData.entries());
|
||||||
|
alert(`创建用户: ${userData.username}`);
|
||||||
|
hideCreateUserModal();
|
||||||
});
|
});
|
||||||
|
|
||||||
function generateTopicsPage() {
|
function generateTopicsPage() {
|
||||||
|
|||||||
@@ -96,24 +96,396 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// 极简 JavaScript - 动态生成页面内容
|
// 带有API调用的JavaScript
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
let topicsData = [];
|
||||||
const mainContent = document.querySelector('.main-content');
|
let logsData = {};
|
||||||
|
let usersData = [];
|
||||||
|
|
||||||
// 选题管理 页面的具体内容
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
loadPageData();
|
||||||
|
});
|
||||||
|
|
||||||
|
async function loadPageData() {
|
||||||
|
try {
|
||||||
switch(topics) {
|
switch(topics) {
|
||||||
case 'topics':
|
case 'topics':
|
||||||
generateTopicsPage();
|
await fetchTopicsData();
|
||||||
break;
|
break;
|
||||||
case 'logs':
|
case 'logs':
|
||||||
generateLogsPage();
|
await fetchLogsData();
|
||||||
break;
|
break;
|
||||||
case 'users':
|
case 'users':
|
||||||
generateUsersPage();
|
await fetchUsersData();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
mainContent.innerHTML = '<h2>页面加载中...</h2>';
|
console.log('未知页面');
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('加载数据失败:', error);
|
||||||
|
showError('加载数据失败,请刷新重试');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchTopicsData() {
|
||||||
|
// 模拟API调用 - 实际应该调用 /api/topics
|
||||||
|
topicsData = [
|
||||||
|
{ id: 'A01', title: '可持续发展趋势分析', field: '环保', status: 'pending', compliance: 85, created_at: '2026-04-27 10:30', generated_at: '-', published_at: '-', updated_at: '2026-04-27 10:30' },
|
||||||
|
{ id: 'B02', title: 'AI在内容创作中的应用', field: '科技', status: 'review', compliance: 92, created_at: '2026-04-27 11:15', generated_at: '2026-04-27 11:45', published_at: '-', updated_at: '2026-04-27 11:45' },
|
||||||
|
{ id: 'C03', title: '数字化转型案例研究', field: '商业', status: 'ready', compliance: 78, created_at: '2026-04-27 12:00', generated_at: '2026-04-27 12:30', published_at: '2026-04-27 13:00', updated_at: '2026-04-27 13:00' },
|
||||||
|
{ id: 'D04', title: '绿色能源发展前景', field: '能源', status: 'published', compliance: 95, created_at: '2026-04-26 09:15', generated_at: '2026-04-26 10:30', published_at: '2026-04-26 14:20', updated_at: '2026-04-26 14:20' }
|
||||||
|
];
|
||||||
|
renderTopicsPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchLogsData() {
|
||||||
|
// 模拟API调用 - 实际应该调用 /api/system/logs
|
||||||
|
logsData = {
|
||||||
|
creator: `2026-04-27 11:45:23 | 成功生成选题 B02 - AI在内容创作中的应用
|
||||||
|
2026-04-27 11:30:15 | 开始生成选题 C03 - 数字化转型案例研究
|
||||||
|
2026-04-27 10:15:08 | 成功生成选题 A01 - 可持续发展趋势分析`,
|
||||||
|
optimizer: `2026-04-27 12:05:30 | 优化完成选题 C03 - 合规分提升至78
|
||||||
|
2026-04-27 11:50:45 | 优化中选题 B02 - 等待人工审核`,
|
||||||
|
collector: `2026-04-27 10:30:12 | 收集到3个新选题
|
||||||
|
2026-04-27 09:45:20 | 更新行业热点数据
|
||||||
|
2026-04-27 08:20:35 | 完成今日数据采集`
|
||||||
|
};
|
||||||
|
renderLogsPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchUsersData() {
|
||||||
|
// 模拟API调用 - 实际应该调用 /api/admin/users
|
||||||
|
usersData = [
|
||||||
|
{ id: 'admin', username: 'admin', role: 'admin', created_at: '2026-04-01 09:00' },
|
||||||
|
{ id: 'editor1', username: '编辑小王', role: 'editor', created_at: '2026-04-05 14:30' },
|
||||||
|
{ id: 'editor2', username: '编辑小李', role: 'editor', created_at: '2026-04-10 10:15' }
|
||||||
|
];
|
||||||
|
renderUsersPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderTopicsPage() {
|
||||||
|
if (!topicsData || topicsData.length === 0) {
|
||||||
|
showLoading();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const selectedIds = [];
|
||||||
|
const html = `
|
||||||
|
<div class="card">
|
||||||
|
<h2>📋 选题管理</h2>
|
||||||
|
|
||||||
|
<!-- 批量操作 -->
|
||||||
|
<div class="batch-buttons">
|
||||||
|
<button class="btn btn-primary" onclick="handleBatchRefresh()">🔄 批量刷新</button>
|
||||||
|
<button class="btn btn-success" onclick="handleBatchGenerate()" ${selectedIds.length === 0 ? 'disabled' : ''}>▶ 批量创作 (${selectedIds.length})</button>
|
||||||
|
<button class="btn btn-warning" onclick="handleBatchOptimize()" ${selectedIds.length === 0 ? 'disabled' : ''}>🔍 批量优化 (${selectedIds.length})</button>
|
||||||
|
<span style="margin-left: auto; color: #6b7280; font-size: 0.875rem;">已选 ${selectedIds.length} 项</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 筛选标签 -->
|
||||||
|
<div class="filters">
|
||||||
|
<div class="filter-tag active" onclick="filterByStatus('all')">全部 (${topicsData.length})</div>
|
||||||
|
<div class="filter-tag" onclick="filterByStatus('pending')">待处理 (${countByStatus('pending')})</div>
|
||||||
|
<div class="filter-tag" onclick="filterByStatus('review')">待审查 (${countByStatus('review')})</div>
|
||||||
|
<div class="filter-tag" onclick="filterByStatus('ready')">待发布 (${countByStatus('ready')})</div>
|
||||||
|
<div class="filter-tag" onclick="filterByStatus('published')">已发布 (${countByStatus('published')})</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 表格 -->
|
||||||
|
<div class="table-container">
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th><input type="checkbox" onclick="toggleSelectAll(this)"></th>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>标题</th>
|
||||||
|
<th>领域</th>
|
||||||
|
<th>优先级</th>
|
||||||
|
<th>状态</th>
|
||||||
|
<th>合规分</th>
|
||||||
|
<th>创建时间</th>
|
||||||
|
<th>创作时间</th>
|
||||||
|
<th>发布时间</th>
|
||||||
|
<th>更新时间</th>
|
||||||
|
<th>操作</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="topicsTableBody">
|
||||||
|
${renderTopicsRows()}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
document.querySelector('.main-content').innerHTML = html;
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderTopicsRows() {
|
||||||
|
return topicsData.map(topic => {
|
||||||
|
const isSelected = topic.selected || false;
|
||||||
|
return `
|
||||||
|
<tr data-status="${topic.status}" ${isSelected ? 'style="background-color: #f3f4f6"' : ''}>
|
||||||
|
<td><input type="checkbox" ${isSelected ? 'checked' : ''} onchange="toggleTopicSelection('${topic.id}')"></td>
|
||||||
|
<td>${topic.id}</td>
|
||||||
|
<td>${topic.title}</td>
|
||||||
|
<td>${topic.field}</td>
|
||||||
|
<td>${topic.compliance}%</td>
|
||||||
|
<td><span class="status-badge status-${topic.status}">${getStatusText(topic.status)}</span></td>
|
||||||
|
<td><div class="progress-bar"><div class="progress-fill" style="width: ${topic.compliance}%"></div></div></td>
|
||||||
|
<td>${formatDate(topic.created_at)}</td>
|
||||||
|
<td>${topic.generated_at === '-' ? '-' : formatDate(topic.generated_at)}</td>
|
||||||
|
<td>${topic.published_at === '-' ? '-' : formatDate(topic.published_at)}</td>
|
||||||
|
<td>${formatDate(topic.updated_at)}</td>
|
||||||
|
<td>
|
||||||
|
<button class="btn btn-primary btn-sm" onclick="previewTopic('${topic.id}')">预览</button>
|
||||||
|
<button class="btn btn-success btn-sm" onclick="createTopic('${topic.id}')">创作</button>
|
||||||
|
<button class="btn btn-warning btn-sm" onclick="optimizeTopic('${topic.id}')">审查</button>
|
||||||
|
<button class="btn btn-primary btn-sm" onclick="publishTopic('${topic.id}')">发布</button>
|
||||||
|
<button class="btn btn-danger btn-sm" onclick="deleteTopic('${topic.id}')">删除</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
`;
|
||||||
|
}).join('');
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderLogsPage() {
|
||||||
|
const html = `
|
||||||
|
<div class="card">
|
||||||
|
<h2>📄 系统日志</h2>
|
||||||
|
|
||||||
|
<div style="display: flex; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap;">
|
||||||
|
<select id="logType" style="padding: 0.5rem; border: 1px solid #d1d5db; border-radius: 0.375rem; min-width: 120px;">
|
||||||
|
<option value="creator">创作日志</option>
|
||||||
|
<option value="optimizer">优化日志</option>
|
||||||
|
<option value="collector">收集日志</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<input type="date" id="logDate" style="padding: 0.5rem; border: 1px solid #d1d5db; border-radius: 0.375rem;" value="2026-04-27">
|
||||||
|
|
||||||
|
<button class="btn btn-primary" onclick="loadLogs()">加载日志</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="logsContent" style="background: #f9fafb; padding: 1rem; border-radius: 0.375rem; min-height: 200px; white-space: pre-wrap; font-family: monospace; font-size: 0.875rem;">
|
||||||
|
请选择日志类型和日期,然后点击加载
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
document.querySelector('.main-content').innerHTML = html;
|
||||||
|
loadLogs(); // 默认加载
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderUsersPage() {
|
||||||
|
const html = `
|
||||||
|
<div class="card">
|
||||||
|
<h2>👥 用户管理</h2>
|
||||||
|
|
||||||
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem;">
|
||||||
|
<h3 style="font-size: 1.125rem; font-weight: 600;">用户列表</h3>
|
||||||
|
<button class="btn btn-primary" onclick="showCreateUserModal()">+ 新建用户</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<table style="width: 100%; border-collapse: collapse;">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th style="padding: 0.75rem; text-align: left; background-color: #f9fafb; font-weight: 600;">ID</th>
|
||||||
|
<th style="padding: 0.75rem; text-align: left; background-color: #f9fafb; font-weight: 600;">用户名</th>
|
||||||
|
<th style="padding: 0.75rem; text-align: left; background-color: #f9fafb; font-weight: 600;">角色</th>
|
||||||
|
<th style="padding: 0.75rem; text-align: left; background-color: #f9fafb; font-weight: 600;">创建时间</th>
|
||||||
|
<th style="padding: 0.75rem; text-align: left; background-color: #f9fafb; font-weight: 600;">操作</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
${usersData.map(user => `
|
||||||
|
<tr style="border-bottom: 1px solid #e5e7eb;">
|
||||||
|
<td style="padding: 0.75rem;">${user.id}</td>
|
||||||
|
<td style="padding: 0.75rem;">${user.username}</td>
|
||||||
|
<td style="padding: 0.75rem;">
|
||||||
|
<span class="status-badge ${user.role === 'admin' ? 'status-review' : 'status-ready'}">
|
||||||
|
${user.role === 'admin' ? '管理员' : '编辑'}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td style="padding: 0.75rem;">${formatDate(user.created_at)}</td>
|
||||||
|
<td style="padding: 0.75rem;">
|
||||||
|
<button class="btn btn-danger btn-sm" onclick="deleteUser('${user.id}')" ${user.role === 'admin' ? 'disabled' : ''}>
|
||||||
|
删除
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
`).join('')}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 新建用户模态框 -->
|
||||||
|
<div id="createUserModal" style="position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); display: none; z-index: 1000;">
|
||||||
|
<div style="position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); background: white; padding: 2rem; border-radius: 0.5rem; width: 90%; max-width: 500px;">
|
||||||
|
<h3 style="font-size: 1.25rem; font-weight: 600; margin-bottom: 1rem;">新建用户</h3>
|
||||||
|
<form id="createUserForm">
|
||||||
|
<div style="margin-bottom: 1rem;">
|
||||||
|
<label style="display: block; margin-bottom: 0.5rem; font-weight: 500;">用户名</label>
|
||||||
|
<input type="text" name="username" required style="width: 100%; padding: 0.5rem; border: 1px solid #d1d5db; border-radius: 0.375rem;">
|
||||||
|
</div>
|
||||||
|
<div style="margin-bottom: 1rem;">
|
||||||
|
<label style="display: block; margin-bottom: 0.5rem; font-weight: 500;">密码</label>
|
||||||
|
<input type="password" name="password" required style="width: 100%; padding: 0.5rem; border: 1px solid #d1d5db; border-radius: 0.375rem;">
|
||||||
|
</div>
|
||||||
|
<div style="display: flex; gap: 1rem; justify-content: flex-end;">
|
||||||
|
<button type="button" class="btn btn-secondary" onclick="hideCreateUserModal()">取消</button>
|
||||||
|
<button type="submit" class="btn btn-primary">创建</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
document.querySelector('.main-content').innerHTML = html;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 工具函数
|
||||||
|
function getStatusText(status) {
|
||||||
|
const statusMap = {
|
||||||
|
pending: '待处理',
|
||||||
|
review: '待审查',
|
||||||
|
ready: '待发布',
|
||||||
|
published: '已发布'
|
||||||
|
};
|
||||||
|
return statusMap[status] || status;
|
||||||
|
}
|
||||||
|
|
||||||
|
function countByStatus(status) {
|
||||||
|
if (!topicsData || !Array.isArray(topicsData)) return 0;
|
||||||
|
return topicsData.filter(t => t.status === status).length;
|
||||||
|
}
|
||||||
|
|
||||||
|
function filterByStatus(status) {
|
||||||
|
const tableBody = document.getElementById('topicsTableBody');
|
||||||
|
if (!tableBody) return;
|
||||||
|
|
||||||
|
const rows = tableBody.querySelectorAll('tr');
|
||||||
|
rows.forEach(row => {
|
||||||
|
const rowStatus = row.getAttribute('data-status');
|
||||||
|
if (status === 'all' || rowStatus === status) {
|
||||||
|
row.style.display = '';
|
||||||
|
} else {
|
||||||
|
row.style.display = 'none';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 更新筛选标签激活状态
|
||||||
|
document.querySelectorAll('.filter-tag').forEach(tag => tag.classList.remove('active'));
|
||||||
|
const activeTag = document.querySelector(`.filter-tag[onclick*="${status === 'all' ? 'all' : status}"]`);
|
||||||
|
if (activeTag) activeTag.classList.add('active');
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleTopicSelection(id) {
|
||||||
|
const topic = topicsData.find(t => t.id === id);
|
||||||
|
if (topic) {
|
||||||
|
topic.selected = !topic.selected;
|
||||||
|
renderTopicsPage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleSelectAll(checkbox) {
|
||||||
|
topicsData.forEach(topic => {
|
||||||
|
topic.selected = checkbox.checked;
|
||||||
|
});
|
||||||
|
renderTopicsPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatDate(dateStr) {
|
||||||
|
if (!dateStr || dateStr === '-' || dateStr.trim() === '') return '-';
|
||||||
|
const date = new Date(dateStr.replace(' ', 'T'));
|
||||||
|
return date.toLocaleString('zh-CN', {
|
||||||
|
year: 'numeric', month: '2-digit', day: '2-digit',
|
||||||
|
hour: '2-digit', minute: '2-digit'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function showLoading() {
|
||||||
|
document.querySelector('.main-content').innerHTML = `
|
||||||
|
<div style="display: flex; justify-content: center; align-items: center; height: 200px;">
|
||||||
|
<div style="text-align: center;">
|
||||||
|
<div style="width: 2rem; height: 2rem; border: 2px solid #e5e7eb; border-top: 2px solid #3b82f6; border-radius: 50%; animation: spin 1s linear infinite; margin: 0 auto;"></div>
|
||||||
|
<p style="margin-top: 1rem; color: #6b7280;">加载中...</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function showError(message) {
|
||||||
|
document.querySelector('.main-content').innerHTML = `
|
||||||
|
<div class="card">
|
||||||
|
<h2>错误</h2>
|
||||||
|
<p style="color: #ef4444;">${message}</p>
|
||||||
|
<button class="btn btn-primary" onclick="location.reload()">重新加载</button>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 批量操作函数
|
||||||
|
function handleBatchRefresh() {
|
||||||
|
alert('执行批量刷新操作...');
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleBatchGenerate() {
|
||||||
|
const selectedTopics = topicsData.filter(t => t.selected);
|
||||||
|
alert(`执行批量创作操作,共 ${selectedTopics.length} 个选题`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleBatchOptimize() {
|
||||||
|
const selectedTopics = topicsData.filter(t => t.selected);
|
||||||
|
alert(`执行批量优化操作,共 ${selectedTopics.length} 个选题`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 单个操作函数
|
||||||
|
function previewTopic(id) { alert(`预览选题: ${id}`); }
|
||||||
|
function createTopic(id) { alert(`创作选题: ${id}`); }
|
||||||
|
function optimizeTopic(id) { alert(`优化选题: ${id}`); }
|
||||||
|
function publishTopic(id) { alert(`发布选题: ${id}`); }
|
||||||
|
function deleteTopic(id) {
|
||||||
|
if (confirm('确定删除该选题?删除后无法恢复。')) {
|
||||||
|
alert(`删除选题: ${id}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 日志相关函数
|
||||||
|
function loadLogs() {
|
||||||
|
const logType = document.getElementById('logType').value;
|
||||||
|
const logDate = document.getElementById('logDate').value;
|
||||||
|
|
||||||
|
// 模拟根据类型和日期获取日志
|
||||||
|
const logs = logsData[logType] || '没有找到相关日志';
|
||||||
|
const content = `日志类型: ${logType}
|
||||||
|
日期: ${logDate}
|
||||||
|
|
||||||
|
${logs}`;
|
||||||
|
|
||||||
|
document.getElementById('logsContent').textContent = content;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 用户管理相关函数
|
||||||
|
function showCreateUserModal() {
|
||||||
|
document.getElementById('createUserModal').style.display = 'block';
|
||||||
|
}
|
||||||
|
|
||||||
|
function hideCreateUserModal() {
|
||||||
|
document.getElementById('createUserModal').style.display = 'none';
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteUser(id) {
|
||||||
|
if (confirm('确定删除该用户?')) {
|
||||||
|
alert(`删除用户: ${id}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 表单提交处理
|
||||||
|
document.getElementById('createUserForm').addEventListener('submit', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
const formData = new FormData(this);
|
||||||
|
const userData = Object.fromEntries(formData.entries());
|
||||||
|
alert(`创建用户: ${userData.username}`);
|
||||||
|
hideCreateUserModal();
|
||||||
});
|
});
|
||||||
|
|
||||||
function generateTopicsPage() {
|
function generateTopicsPage() {
|
||||||
|
|||||||
@@ -96,24 +96,396 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// 极简 JavaScript - 动态生成页面内容
|
// 带有API调用的JavaScript
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
let topicsData = [];
|
||||||
const mainContent = document.querySelector('.main-content');
|
let logsData = {};
|
||||||
|
let usersData = [];
|
||||||
|
|
||||||
// 用户管理 页面的具体内容
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
loadPageData();
|
||||||
|
});
|
||||||
|
|
||||||
|
async function loadPageData() {
|
||||||
|
try {
|
||||||
switch(users) {
|
switch(users) {
|
||||||
case 'topics':
|
case 'topics':
|
||||||
generateTopicsPage();
|
await fetchTopicsData();
|
||||||
break;
|
break;
|
||||||
case 'logs':
|
case 'logs':
|
||||||
generateLogsPage();
|
await fetchLogsData();
|
||||||
break;
|
break;
|
||||||
case 'users':
|
case 'users':
|
||||||
generateUsersPage();
|
await fetchUsersData();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
mainContent.innerHTML = '<h2>页面加载中...</h2>';
|
console.log('未知页面');
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('加载数据失败:', error);
|
||||||
|
showError('加载数据失败,请刷新重试');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchTopicsData() {
|
||||||
|
// 模拟API调用 - 实际应该调用 /api/topics
|
||||||
|
topicsData = [
|
||||||
|
{ id: 'A01', title: '可持续发展趋势分析', field: '环保', status: 'pending', compliance: 85, created_at: '2026-04-27 10:30', generated_at: '-', published_at: '-', updated_at: '2026-04-27 10:30' },
|
||||||
|
{ id: 'B02', title: 'AI在内容创作中的应用', field: '科技', status: 'review', compliance: 92, created_at: '2026-04-27 11:15', generated_at: '2026-04-27 11:45', published_at: '-', updated_at: '2026-04-27 11:45' },
|
||||||
|
{ id: 'C03', title: '数字化转型案例研究', field: '商业', status: 'ready', compliance: 78, created_at: '2026-04-27 12:00', generated_at: '2026-04-27 12:30', published_at: '2026-04-27 13:00', updated_at: '2026-04-27 13:00' },
|
||||||
|
{ id: 'D04', title: '绿色能源发展前景', field: '能源', status: 'published', compliance: 95, created_at: '2026-04-26 09:15', generated_at: '2026-04-26 10:30', published_at: '2026-04-26 14:20', updated_at: '2026-04-26 14:20' }
|
||||||
|
];
|
||||||
|
renderTopicsPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchLogsData() {
|
||||||
|
// 模拟API调用 - 实际应该调用 /api/system/logs
|
||||||
|
logsData = {
|
||||||
|
creator: `2026-04-27 11:45:23 | 成功生成选题 B02 - AI在内容创作中的应用
|
||||||
|
2026-04-27 11:30:15 | 开始生成选题 C03 - 数字化转型案例研究
|
||||||
|
2026-04-27 10:15:08 | 成功生成选题 A01 - 可持续发展趋势分析`,
|
||||||
|
optimizer: `2026-04-27 12:05:30 | 优化完成选题 C03 - 合规分提升至78
|
||||||
|
2026-04-27 11:50:45 | 优化中选题 B02 - 等待人工审核`,
|
||||||
|
collector: `2026-04-27 10:30:12 | 收集到3个新选题
|
||||||
|
2026-04-27 09:45:20 | 更新行业热点数据
|
||||||
|
2026-04-27 08:20:35 | 完成今日数据采集`
|
||||||
|
};
|
||||||
|
renderLogsPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchUsersData() {
|
||||||
|
// 模拟API调用 - 实际应该调用 /api/admin/users
|
||||||
|
usersData = [
|
||||||
|
{ id: 'admin', username: 'admin', role: 'admin', created_at: '2026-04-01 09:00' },
|
||||||
|
{ id: 'editor1', username: '编辑小王', role: 'editor', created_at: '2026-04-05 14:30' },
|
||||||
|
{ id: 'editor2', username: '编辑小李', role: 'editor', created_at: '2026-04-10 10:15' }
|
||||||
|
];
|
||||||
|
renderUsersPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderTopicsPage() {
|
||||||
|
if (!topicsData || topicsData.length === 0) {
|
||||||
|
showLoading();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const selectedIds = [];
|
||||||
|
const html = `
|
||||||
|
<div class="card">
|
||||||
|
<h2>📋 选题管理</h2>
|
||||||
|
|
||||||
|
<!-- 批量操作 -->
|
||||||
|
<div class="batch-buttons">
|
||||||
|
<button class="btn btn-primary" onclick="handleBatchRefresh()">🔄 批量刷新</button>
|
||||||
|
<button class="btn btn-success" onclick="handleBatchGenerate()" ${selectedIds.length === 0 ? 'disabled' : ''}>▶ 批量创作 (${selectedIds.length})</button>
|
||||||
|
<button class="btn btn-warning" onclick="handleBatchOptimize()" ${selectedIds.length === 0 ? 'disabled' : ''}>🔍 批量优化 (${selectedIds.length})</button>
|
||||||
|
<span style="margin-left: auto; color: #6b7280; font-size: 0.875rem;">已选 ${selectedIds.length} 项</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 筛选标签 -->
|
||||||
|
<div class="filters">
|
||||||
|
<div class="filter-tag active" onclick="filterByStatus('all')">全部 (${topicsData.length})</div>
|
||||||
|
<div class="filter-tag" onclick="filterByStatus('pending')">待处理 (${countByStatus('pending')})</div>
|
||||||
|
<div class="filter-tag" onclick="filterByStatus('review')">待审查 (${countByStatus('review')})</div>
|
||||||
|
<div class="filter-tag" onclick="filterByStatus('ready')">待发布 (${countByStatus('ready')})</div>
|
||||||
|
<div class="filter-tag" onclick="filterByStatus('published')">已发布 (${countByStatus('published')})</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 表格 -->
|
||||||
|
<div class="table-container">
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th><input type="checkbox" onclick="toggleSelectAll(this)"></th>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>标题</th>
|
||||||
|
<th>领域</th>
|
||||||
|
<th>优先级</th>
|
||||||
|
<th>状态</th>
|
||||||
|
<th>合规分</th>
|
||||||
|
<th>创建时间</th>
|
||||||
|
<th>创作时间</th>
|
||||||
|
<th>发布时间</th>
|
||||||
|
<th>更新时间</th>
|
||||||
|
<th>操作</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="topicsTableBody">
|
||||||
|
${renderTopicsRows()}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
document.querySelector('.main-content').innerHTML = html;
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderTopicsRows() {
|
||||||
|
return topicsData.map(topic => {
|
||||||
|
const isSelected = topic.selected || false;
|
||||||
|
return `
|
||||||
|
<tr data-status="${topic.status}" ${isSelected ? 'style="background-color: #f3f4f6"' : ''}>
|
||||||
|
<td><input type="checkbox" ${isSelected ? 'checked' : ''} onchange="toggleTopicSelection('${topic.id}')"></td>
|
||||||
|
<td>${topic.id}</td>
|
||||||
|
<td>${topic.title}</td>
|
||||||
|
<td>${topic.field}</td>
|
||||||
|
<td>${topic.compliance}%</td>
|
||||||
|
<td><span class="status-badge status-${topic.status}">${getStatusText(topic.status)}</span></td>
|
||||||
|
<td><div class="progress-bar"><div class="progress-fill" style="width: ${topic.compliance}%"></div></div></td>
|
||||||
|
<td>${formatDate(topic.created_at)}</td>
|
||||||
|
<td>${topic.generated_at === '-' ? '-' : formatDate(topic.generated_at)}</td>
|
||||||
|
<td>${topic.published_at === '-' ? '-' : formatDate(topic.published_at)}</td>
|
||||||
|
<td>${formatDate(topic.updated_at)}</td>
|
||||||
|
<td>
|
||||||
|
<button class="btn btn-primary btn-sm" onclick="previewTopic('${topic.id}')">预览</button>
|
||||||
|
<button class="btn btn-success btn-sm" onclick="createTopic('${topic.id}')">创作</button>
|
||||||
|
<button class="btn btn-warning btn-sm" onclick="optimizeTopic('${topic.id}')">审查</button>
|
||||||
|
<button class="btn btn-primary btn-sm" onclick="publishTopic('${topic.id}')">发布</button>
|
||||||
|
<button class="btn btn-danger btn-sm" onclick="deleteTopic('${topic.id}')">删除</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
`;
|
||||||
|
}).join('');
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderLogsPage() {
|
||||||
|
const html = `
|
||||||
|
<div class="card">
|
||||||
|
<h2>📄 系统日志</h2>
|
||||||
|
|
||||||
|
<div style="display: flex; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap;">
|
||||||
|
<select id="logType" style="padding: 0.5rem; border: 1px solid #d1d5db; border-radius: 0.375rem; min-width: 120px;">
|
||||||
|
<option value="creator">创作日志</option>
|
||||||
|
<option value="optimizer">优化日志</option>
|
||||||
|
<option value="collector">收集日志</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<input type="date" id="logDate" style="padding: 0.5rem; border: 1px solid #d1d5db; border-radius: 0.375rem;" value="2026-04-27">
|
||||||
|
|
||||||
|
<button class="btn btn-primary" onclick="loadLogs()">加载日志</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="logsContent" style="background: #f9fafb; padding: 1rem; border-radius: 0.375rem; min-height: 200px; white-space: pre-wrap; font-family: monospace; font-size: 0.875rem;">
|
||||||
|
请选择日志类型和日期,然后点击加载
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
document.querySelector('.main-content').innerHTML = html;
|
||||||
|
loadLogs(); // 默认加载
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderUsersPage() {
|
||||||
|
const html = `
|
||||||
|
<div class="card">
|
||||||
|
<h2>👥 用户管理</h2>
|
||||||
|
|
||||||
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem;">
|
||||||
|
<h3 style="font-size: 1.125rem; font-weight: 600;">用户列表</h3>
|
||||||
|
<button class="btn btn-primary" onclick="showCreateUserModal()">+ 新建用户</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<table style="width: 100%; border-collapse: collapse;">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th style="padding: 0.75rem; text-align: left; background-color: #f9fafb; font-weight: 600;">ID</th>
|
||||||
|
<th style="padding: 0.75rem; text-align: left; background-color: #f9fafb; font-weight: 600;">用户名</th>
|
||||||
|
<th style="padding: 0.75rem; text-align: left; background-color: #f9fafb; font-weight: 600;">角色</th>
|
||||||
|
<th style="padding: 0.75rem; text-align: left; background-color: #f9fafb; font-weight: 600;">创建时间</th>
|
||||||
|
<th style="padding: 0.75rem; text-align: left; background-color: #f9fafb; font-weight: 600;">操作</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
${usersData.map(user => `
|
||||||
|
<tr style="border-bottom: 1px solid #e5e7eb;">
|
||||||
|
<td style="padding: 0.75rem;">${user.id}</td>
|
||||||
|
<td style="padding: 0.75rem;">${user.username}</td>
|
||||||
|
<td style="padding: 0.75rem;">
|
||||||
|
<span class="status-badge ${user.role === 'admin' ? 'status-review' : 'status-ready'}">
|
||||||
|
${user.role === 'admin' ? '管理员' : '编辑'}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td style="padding: 0.75rem;">${formatDate(user.created_at)}</td>
|
||||||
|
<td style="padding: 0.75rem;">
|
||||||
|
<button class="btn btn-danger btn-sm" onclick="deleteUser('${user.id}')" ${user.role === 'admin' ? 'disabled' : ''}>
|
||||||
|
删除
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
`).join('')}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 新建用户模态框 -->
|
||||||
|
<div id="createUserModal" style="position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); display: none; z-index: 1000;">
|
||||||
|
<div style="position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); background: white; padding: 2rem; border-radius: 0.5rem; width: 90%; max-width: 500px;">
|
||||||
|
<h3 style="font-size: 1.25rem; font-weight: 600; margin-bottom: 1rem;">新建用户</h3>
|
||||||
|
<form id="createUserForm">
|
||||||
|
<div style="margin-bottom: 1rem;">
|
||||||
|
<label style="display: block; margin-bottom: 0.5rem; font-weight: 500;">用户名</label>
|
||||||
|
<input type="text" name="username" required style="width: 100%; padding: 0.5rem; border: 1px solid #d1d5db; border-radius: 0.375rem;">
|
||||||
|
</div>
|
||||||
|
<div style="margin-bottom: 1rem;">
|
||||||
|
<label style="display: block; margin-bottom: 0.5rem; font-weight: 500;">密码</label>
|
||||||
|
<input type="password" name="password" required style="width: 100%; padding: 0.5rem; border: 1px solid #d1d5db; border-radius: 0.375rem;">
|
||||||
|
</div>
|
||||||
|
<div style="display: flex; gap: 1rem; justify-content: flex-end;">
|
||||||
|
<button type="button" class="btn btn-secondary" onclick="hideCreateUserModal()">取消</button>
|
||||||
|
<button type="submit" class="btn btn-primary">创建</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
document.querySelector('.main-content').innerHTML = html;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 工具函数
|
||||||
|
function getStatusText(status) {
|
||||||
|
const statusMap = {
|
||||||
|
pending: '待处理',
|
||||||
|
review: '待审查',
|
||||||
|
ready: '待发布',
|
||||||
|
published: '已发布'
|
||||||
|
};
|
||||||
|
return statusMap[status] || status;
|
||||||
|
}
|
||||||
|
|
||||||
|
function countByStatus(status) {
|
||||||
|
if (!topicsData || !Array.isArray(topicsData)) return 0;
|
||||||
|
return topicsData.filter(t => t.status === status).length;
|
||||||
|
}
|
||||||
|
|
||||||
|
function filterByStatus(status) {
|
||||||
|
const tableBody = document.getElementById('topicsTableBody');
|
||||||
|
if (!tableBody) return;
|
||||||
|
|
||||||
|
const rows = tableBody.querySelectorAll('tr');
|
||||||
|
rows.forEach(row => {
|
||||||
|
const rowStatus = row.getAttribute('data-status');
|
||||||
|
if (status === 'all' || rowStatus === status) {
|
||||||
|
row.style.display = '';
|
||||||
|
} else {
|
||||||
|
row.style.display = 'none';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 更新筛选标签激活状态
|
||||||
|
document.querySelectorAll('.filter-tag').forEach(tag => tag.classList.remove('active'));
|
||||||
|
const activeTag = document.querySelector(`.filter-tag[onclick*="${status === 'all' ? 'all' : status}"]`);
|
||||||
|
if (activeTag) activeTag.classList.add('active');
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleTopicSelection(id) {
|
||||||
|
const topic = topicsData.find(t => t.id === id);
|
||||||
|
if (topic) {
|
||||||
|
topic.selected = !topic.selected;
|
||||||
|
renderTopicsPage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleSelectAll(checkbox) {
|
||||||
|
topicsData.forEach(topic => {
|
||||||
|
topic.selected = checkbox.checked;
|
||||||
|
});
|
||||||
|
renderTopicsPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatDate(dateStr) {
|
||||||
|
if (!dateStr || dateStr === '-' || dateStr.trim() === '') return '-';
|
||||||
|
const date = new Date(dateStr.replace(' ', 'T'));
|
||||||
|
return date.toLocaleString('zh-CN', {
|
||||||
|
year: 'numeric', month: '2-digit', day: '2-digit',
|
||||||
|
hour: '2-digit', minute: '2-digit'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function showLoading() {
|
||||||
|
document.querySelector('.main-content').innerHTML = `
|
||||||
|
<div style="display: flex; justify-content: center; align-items: center; height: 200px;">
|
||||||
|
<div style="text-align: center;">
|
||||||
|
<div style="width: 2rem; height: 2rem; border: 2px solid #e5e7eb; border-top: 2px solid #3b82f6; border-radius: 50%; animation: spin 1s linear infinite; margin: 0 auto;"></div>
|
||||||
|
<p style="margin-top: 1rem; color: #6b7280;">加载中...</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function showError(message) {
|
||||||
|
document.querySelector('.main-content').innerHTML = `
|
||||||
|
<div class="card">
|
||||||
|
<h2>错误</h2>
|
||||||
|
<p style="color: #ef4444;">${message}</p>
|
||||||
|
<button class="btn btn-primary" onclick="location.reload()">重新加载</button>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 批量操作函数
|
||||||
|
function handleBatchRefresh() {
|
||||||
|
alert('执行批量刷新操作...');
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleBatchGenerate() {
|
||||||
|
const selectedTopics = topicsData.filter(t => t.selected);
|
||||||
|
alert(`执行批量创作操作,共 ${selectedTopics.length} 个选题`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleBatchOptimize() {
|
||||||
|
const selectedTopics = topicsData.filter(t => t.selected);
|
||||||
|
alert(`执行批量优化操作,共 ${selectedTopics.length} 个选题`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 单个操作函数
|
||||||
|
function previewTopic(id) { alert(`预览选题: ${id}`); }
|
||||||
|
function createTopic(id) { alert(`创作选题: ${id}`); }
|
||||||
|
function optimizeTopic(id) { alert(`优化选题: ${id}`); }
|
||||||
|
function publishTopic(id) { alert(`发布选题: ${id}`); }
|
||||||
|
function deleteTopic(id) {
|
||||||
|
if (confirm('确定删除该选题?删除后无法恢复。')) {
|
||||||
|
alert(`删除选题: ${id}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 日志相关函数
|
||||||
|
function loadLogs() {
|
||||||
|
const logType = document.getElementById('logType').value;
|
||||||
|
const logDate = document.getElementById('logDate').value;
|
||||||
|
|
||||||
|
// 模拟根据类型和日期获取日志
|
||||||
|
const logs = logsData[logType] || '没有找到相关日志';
|
||||||
|
const content = `日志类型: ${logType}
|
||||||
|
日期: ${logDate}
|
||||||
|
|
||||||
|
${logs}`;
|
||||||
|
|
||||||
|
document.getElementById('logsContent').textContent = content;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 用户管理相关函数
|
||||||
|
function showCreateUserModal() {
|
||||||
|
document.getElementById('createUserModal').style.display = 'block';
|
||||||
|
}
|
||||||
|
|
||||||
|
function hideCreateUserModal() {
|
||||||
|
document.getElementById('createUserModal').style.display = 'none';
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteUser(id) {
|
||||||
|
if (confirm('确定删除该用户?')) {
|
||||||
|
alert(`删除用户: ${id}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 表单提交处理
|
||||||
|
document.getElementById('createUserForm').addEventListener('submit', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
const formData = new FormData(this);
|
||||||
|
const userData = Object.fromEntries(formData.entries());
|
||||||
|
alert(`创建用户: ${userData.username}`);
|
||||||
|
hideCreateUserModal();
|
||||||
});
|
});
|
||||||
|
|
||||||
function generateTopicsPage() {
|
function generateTopicsPage() {
|
||||||
|
|||||||
Reference in New Issue
Block a user