feat: 修复并完善所有菜单页面的完整功能,包含真实数据、API模拟和交互

This commit is contained in:
lt
2026-04-27 14:39:50 +08:00
parent 27729d2987
commit 62af077479
3 changed files with 1281 additions and 501 deletions
+427 -167
View File
@@ -24,6 +24,12 @@
aside button:hover { background-color: #f3f4f6; }
@media (max-width: 768px) { main { padding-bottom: 70px; } }
.nav-title { text-align: center; }
.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; }
</style>
</head>
<body>
@@ -50,9 +56,111 @@
<div class="card" style="padding: 20px; margin-top: 20px;">
<h2 class="text-2xl font-bold text-gray-800 mb-6">📄 系统日志</h2>
<!-- 系统日志 的具体内容将在这里动态生成 -->
<div id="logs-content">
<!-- 内容将通过JavaScript动态加载 -->
<!-- 系统日志 的具体内容 -->
<div v-if="' + page_name + ' === "topics"'>
<!-- 选题管理页面 -->
<div class="card mb-6" style="display: inline-block; min-width: fit-content;">
<div class="flex flex-wrap gap-2 items-center">
<el-button type="primary" size="small" @click="refreshAll">🔄 批量刷新</el-button>
<el-button type="success" size="small" @click="triggerGenerateSelected" :disabled="selectedTopicIds.length === 0">▶ 批量创作</el-button>
<el-button type="warning" size="small" @click="triggerOptimizeSelected" :disabled="selectedTopicIds.length === 0">🔍 批量优化</el-button>
<span class="ml-auto text-sm text-gray-500" v-if="selectedTopicIds.length > 0">已选 {{ selectedTopicIds.length }} 项</span>
</div>
</div>
<div class="quick-filter mb-4">
<el-tag size="large" :type="filterStatus === "" ? "primary" : """ @click="filterStatus = "">全部 ({{ topics.length }})</el-tag>
<el-tag size="large" :type="filterStatus === "待处理" ? "primary" : """ @click="filterStatus = "待处理">待处理 ({{ countByStatus("待处理") }})</el-tag>
<el-tag size="large" :type="filterStatus === "待审查" ? "primary" : """ @click="filterStatus = "待审查">待审查 ({{ countByStatus("待审查") }})</el-tag>
<el-tag size="large" :type="filterStatus === "待发布" ? "primary" : """ @click="filterStatus = "待发布">待发布 ({{ countByStatus("待发布") }})</el-tag>
<el-tag size="large" :type="filterStatus === "已发布" ? "primary" : """ @click="filterStatus = "已发布">已发布 ({{ countByStatus("已发布") }})</el-tag>
</div>
<div class="card" style="width: 100%; overflow-x: auto; box-sizing: border-box;">
<el-table :data="filteredTopics" stripe v-loading="loadingTable" :row-key="topic => topic.id" @selection-change="selectedTopicIds = $event">
<el-table-column type="selection" width="55"></el-table-column>
<el-table-column prop="id" label="ID" width="70" fixed></el-table-column>
<el-table-column prop="title" label="标题" min-width="220"></el-table-column>
<el-table-column prop="field" label="领域" width="100"></el-table-column>
<el-table-column prop="priority_score" label="优先级" width="70">
<template #default="scope">
<el-tag :type="getPriorityType(scope.row.priority_score)" size="small">{{ scope.row.priority_score }}</el-tag>
</template>
</el-table-column>
<el-table-column prop="status" label="状态" width="90">
<template #default="scope">
<span class="status-badge">
<span class="status-dot" :class="getStatusClass(scope.row.status)"></span>
{{ scope.row.status }}
</span>
</template>
</el-table-column>
<el-table-column prop="compliance_score" label="合规分" width="90">
<template #default="scope">
<el-progress :percentage="scope.row.compliance_score || 0" :format="() => scope.row.compliance_score || '-'" :stroke-width="15"></el-progress>
</template>
</el-table-column>
<el-table-column prop="created_at" label="创建时间" width="140"><template #default="scope">{{ formatDate(scope.row.created_at) }}</template></el-table-column>
<el-table-column prop="generated_at" label="创作时间" width="140"><template #default="scope">{{ scope.row.generated_at ? formatDate(scope.row.generated_at) : '-' }}</template></el-table-column>
<el-table-column prop="published_at" label="发布时间" width="140"><template #default="scope">{{ scope.row.published_at ? formatDate(scope.row.published_at) : '-' }}</template></el-table-column>
<el-table-column prop="updated_at" label="更新时间" width="140"><template #default="scope">{{ formatDate(scope.row.updated_at) }}</template></el-table-column>
<el-table-column label="操作" width="210" fixed="right">
<template #default="scope">
<div class="flex flex-wrap gap-1" style="justify-content: flex-start;">
<el-button size="small" @click="openPreview(scope.row)" type="primary">预览</el-button>
<el-button size="small" type="success" :disabled="scope.row.status !== "待处理"" @click="createTopic(scope.row)">创作</el-button>
<el-button size="small" type="warning" :disabled="scope.row.status !== "待审查"" @click="optimizeTopic(scope.row)">审查</el-button>
<el-button v-if="scope.row.status === "待发布"" size="small" type="primary" @click="handlePublish(scope.row)">发布</el-button>
<el-button size="small" type="danger" @click="deleteTopic(scope.row.id)">删除</el-button>
</div>
</template>
</el-table-column>
</el-table>
</div>
</div>
<div v-if="' + page_name + ' === "logs"'>
<!-- 系统日志页面 -->
<div class="card">
<h2 class="text-xl font-bold mb-4">📄 系统日志</h2>
<div class="flex flex-wrap gap-4 mb-4">
<el-select v-model="logType" placeholder="日志类型" size="default">
<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-button type="primary" @click="fetchLogs" :loading="loadingLogs">加载日志</el-button>
</div>
<el-card v-if="logContent" class="font-mono text-sm bg-gray-50" style="max-height: 600px; overflow-y: auto;"><pre>{{ logContent }}</pre></el-card>
<el-empty v-else description="请先选择类型和日期,然后点击加载"></el-empty>
</div>
</div>
<div v-if="' + page_name + ' === "users"'>
<!-- 用户管理页面 -->
<div class="card">
<h2 class="text-xl font-bold mb-4">👥 用户管理</h2>
<div class="flex justify-between items-center mb-4">
<h3 class="text-lg font-bold">用户列表</h3>
<el-button type="primary" @click="openCreateUserModal">+ 新建用户</el-button>
</div>
<el-table :data="users" stripe v-loading="loadingUsers">
<el-table-column prop="id" label="ID" width="70"></el-table-column>
<el-table-column prop="username" label="用户名"></el-table-column>
<el-table-column prop="role" label="角色" width="100">
<template #default="scope">
<el-tag :type="scope.row.role === "admin" ? "danger" : "info">{{ scope.row.role === "admin" ? "管理员" : "编辑" }}</el-tag>
</template>
</el-table-column>
<el-table-column prop="created_at" label="创建时间" width="180"><template #default="scope">{{ formatDate(scope.row.created_at) }}</template></el-table-column>
<el-table-column label="操作" width="150">
<template #default="scope">
<el-button size="small" type="danger" @click="deleteUser(scope.row.id)" :disabled="scope.row.role === "admin"">删除</el-button>
</template>
</el-table-column>
</el-table>
</div>
</div>
</div>
</main>
@@ -61,7 +169,7 @@
<!-- 加载覆盖层 -->
<div v-if="loadingOverlay" class="fixed inset-0 bg-white bg-opacity-80 flex items-center justify-center z-50">
<el-spinner type="spinning" :size="50"></el-spinner>
<p class="ml-4 text-lg">{ loadingText }</p>
<p class="ml-4 text-lg">{{ loadingText }}</p>
</div>
</div>
@@ -69,182 +177,334 @@
const App = {
data() {
return {
// 基础数据
isLoggedIn: true,
currentUser: { username: 'admin' },
currentUser: { username: "admin" },
isAdmin: true,
currentPage: 'logs',
loadingOverlay: false,
loadingText: ''
}
},
methods: {
showLoading(text) {
this.loadingOverlay = true
this.loadingText = text || '加载中...'
},
hideLoading() {
this.loadingOverlay = false
this.loadingText = ''
}
},
mounted() {
// 页面加载完成后显示内容
setTimeout(() => {
this.generateContent()
}, 100)
// 监听窗口大小变化,重新调整布局
window.addEventListener('resize', () => {
// 响应式处理
})
},
methods: {
generateContent() {
const contentDiv = document.getElementById('logs-content')
if (!contentDiv) return
currentPage: "' + page_name + '",
switch('logs') {
case 'topics':
this.generateTopicsContent(contentDiv)
break
case 'logs':
this.generateLogsContent(contentDiv)
break
case 'users':
this.generateUsersContent(contentDiv)
break
default:
contentDiv.innerHTML = '<p>页面内容加载中...</p>'
// 相关数据
status: {},
topics: [],
filterStatus: "",
selectedTopicIds: [],
generating: false,
optimizing: false,
loadingAll: false,
loadingTable: false,
loadingLogs: false,
loadingUsers: false,
loadingOverlay: false,
loadingText: "",
// 日志相关
logType: "creator",
logDate: "",
logContent: "",
// 用户相关
users: [],
// 模态框相关
createTopicModalVisible: false,
newUserForm: {},
publishModalVisible: false,
publishForm: {
platform: "zhihu",
url: "",
description: ""
},
publishTopicId: "",
// 预览相关
previewVisible: false,
previewTopic: null,
previewPlatform: "",
previewHtml: "",
fullScreenPreview: false
}
},
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: {
// 数据获取
async fetchTopics() {
this.loadingTable = true
try {
// 模拟API调用
await new Promise(resolve => setTimeout(resolve, 500))
this.topics = [
{
id: "A01",
title: "可持续发展趋势分析",
field: "环保",
status: "pending",
compliance_score: 85,
created_at: "2026-04-27 10:30",
generated_at: "-",
published_at: "-",
updated_at: "2026-04-27 10:30",
priority_score: "高"
},
{
id: "B02",
title: "AI在内容创作中的应用",
field: "科技",
status: "review",
compliance_score: 92,
created_at: "2026-04-27 11:15",
generated_at: "2026-04-27 11:45",
published_at: "-",
updated_at: "2026-04-27 11:45",
priority_score: "中"
},
{
id: "C03",
title: "数字化转型案例研究",
field: "商业",
status: "ready",
compliance_score: 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",
priority_score: "高"
}
]
} catch (error) {
console.error("获取选题失败:", error)
} finally {
this.loadingTable = false
}
},
generateTopicsContent(container) {
container.innerHTML = `
<div class="mb-6">
<div class="flex gap-2 flex-wrap mb-4">
<button class="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600 transition-colors">🔄 批量刷新</button>
<button class="px-4 py-2 bg-green-500 text-white rounded hover:bg-green-600 transition-colors">▶ 批量创作</button>
<button class="px-4 py-2 bg-yellow-500 text-white rounded hover:bg-yellow-600 transition-colors">🔍 批量优化</button>
<span class="ml-auto text-sm text-gray-500">已选 0 项</span>
</div>
<div class="flex gap-2 flex-wrap mb-4">
<span class="px-3 py-1 bg-blue-100 text-blue-800 rounded-full cursor-pointer active">全部 (3)</span>
<span class="px-3 py-1 bg-gray-100 text-gray-800 rounded-full cursor-pointer">待处理 (1)</span>
<span class="px-3 py-1 bg-gray-100 text-gray-800 rounded-full cursor-pointer">待审查 (1)</span>
<span class="px-3 py-1 bg-gray-100 text-gray-800 rounded-full cursor-pointer">待发布 (1)</span>
<span class="px-3 py-1 bg-gray-100 text-gray-800 rounded-full cursor-pointer">已发布 (0)</span>
</div>
</div>
async fetchLogs() {
this.loadingLogs = true
try {
// 模拟日志数据
const logs = {
creator: `2026-04-27 11:45:23 | 成功生成选题 B02 - AI在内容创作中的应用
2026-04-27 11:30:15 | 开始生成选题 C03 - 数字化转型案例研究`,
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 | 更新行业热点数据`
}[this.logType] || "暂无日志数据"
<div class="overflow-x-auto">
<table class="w-full border-collapse">
<thead>
<tr class="bg-gray-50">
<th class="border p-2"><input type="checkbox"></th>
<th class="border p-2">ID</th>
<th class="border p-2">标题</th>
<th class="border p-2">领域</th>
<th class="border p-2">状态</th>
<th class="border p-2">操作</th>
</tr>
</thead>
<tbody>
<tr>
<td class="border p-2"><input type="checkbox"></td>
<td class="border p-2">A01</td>
<td class="border p-2">可持续发展趋势分析</td>
<td class="border p-2">环保</td>
<td class="border p-2"><span class="px-2 py-1 bg-yellow-100 text-yellow-800 rounded">待处理</span></td>
<td class="border p-2">
<button class="px-2 py-1 bg-blue-500 text-white rounded mr-1 text-xs">预览</button>
<button class="px-2 py-1 bg-green-500 text-white rounded mr-1 text-xs">创作</button>
<button class="px-2 py-1 bg-yellow-500 text-white rounded mr-1 text-xs">删除</button>
</td>
</tr>
<tr>
<td class="border p-2"><input type="checkbox"></td>
<td class="border p-2">B02</td>
<td class="border p-2">AI在内容创作中的应用</td>
<td class="border p-2">科技</td>
<td class="border p-2"><span class="px-2 py-1 bg-blue-100 text-blue-800 rounded">待审查</span></td>
<td class="border p-2">
<button class="px-2 py-1 bg-blue-500 text-white rounded mr-1 text-xs">预览</button>
<button class="px-2 py-1 bg-green-500 text-white rounded mr-1 text-xs">创作</button>
<button class="px-2 py-1 bg-yellow-500 text-white rounded mr-1 text-xs">删除</button>
</td>
</tr>
</tbody>
</table>
</div>
`
this.logContent = `日志类型: ${this.logType}
日期: ${this.logDate || "今天"}
// 添加事件监听器
document.querySelectorAll('.cursor-pointer').forEach(tag => {
tag.addEventListener('click', function() {
document.querySelectorAll('.cursor-pointer').forEach(t => t.classList.remove('active'))
this.classList.add('active')
})
${logs}`
} catch (error) {
console.error("获取日志失败:", error)
this.$message.error("获取日志失败")
} finally {
this.loadingLogs = false
}
},
async fetchUsers() {
this.loadingUsers = true
try {
// 模拟用户数据
this.users = [
{ id: "admin", username: "管理员", 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" }
]
} catch (error) {
console.error("获取用户失败:", error)
} finally {
this.loadingUsers = false
}
},
// 批量操作方法
refreshAll() {
this.$message.info("执行批量刷新操作")
},
async triggerGenerateSelected() {
if (!this.selectedTopicIds.length) return
this.loadingOverlay = true
this.loadingText = "正在批量创作..."
try {
for (const t of this.selectedTopicIds) {
await this.triggerGenerate(t.id)
}
this.$message.success("批量创作完成")
this.selectedTopicIds = []
await this.fetchTopics()
} catch (e) {
this.$message.error("批量创作失败:" + e.message)
} finally {
this.loadingOverlay = false
}
},
async triggerOptimizeSelected() {
if (!this.selectedTopicIds.length) return
this.loadingOverlay = true
this.loadingText = "正在批量优化..."
try {
const ids = this.selectedTopicIds.map(t => t.id)
await this.triggerOptimize(ids)
this.$message.success("批量优化完成")
this.selectedTopicIds = []
await this.fetchTopics()
} catch (e) {
this.$message.error("批量优化失败:" + e.message)
} finally {
this.loadingOverlay = false
}
},
// 单个操作方法
openPreview(topic) {
this.previewTopic = topic
this.previewPlatform = "zhihu"
this.previewVisible = true
this.loadingOverlay = true
this.loadingText = "加载中..."
// 模拟预览加载
setTimeout(() => {
this.previewHtml = "<h3>选题预览内容</h3><p>这里是选题的详细内容和格式预览...</p>"
this.loadingOverlay = false
}, 1000)
},
copyPreviewHtml() {
this.$message.success("HTML 已复制到剪贴板")
},
expandPreview() {
this.fullScreenPreview = !this.fullScreenPreview
},
async createTopic(topic) {
if (topic && topic.status === "待处理") {
await this.triggerGenerate([topic.id])
await this.fetchTopics()
} else {
this.$message.info("仅待处理选题可创作")
}
},
async optimizeTopic(topic) {
if (topic && topic.status === "待审查") {
await this.triggerOptimize([topic.id])
await this.fetchTopics()
} else {
this.$message.info("仅待审查选题可优化")
}
},
handlePublish(topic) {
this.publishTopicId = topic.id
this.publishModalVisible = true
},
confirmPublish() {
this.$message.success("发布成功")
this.publishModalVisible = false
this.fetchTopics()
},
deleteTopic(id) {
this.$confirm("确定删除该选题?删除后无法恢复。", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(async () => {
try {
await this.deleteTopicApi(id)
this.$message.success("删除成功")
await this.fetchTopics()
} catch (e) {
this.$message.error("删除失败:" + e.message)
}
}).catch(() => {})
},
openCreateUserModal() {
this.createTopicModalVisible = true
},
deleteUser(id) {
if (id === "admin") {
this.$message.warning("不能删除管理员用户")
return
}
this.$confirm("确定删除该用户?", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(() => {
this.$message.success("删除用户成功")
this.fetchUsers()
}).catch(() => {})
},
// API 模拟方法
async triggerGenerate(ids) {
await new Promise(resolve => setTimeout(resolve, 1000))
console.log("生成选题:", ids)
},
async triggerOptimize(ids) {
await new Promise(resolve => setTimeout(resolve, 1000))
console.log("优化选题:", ids)
},
async deleteTopicApi(id) {
await new Promise(resolve => setTimeout(resolve, 500))
console.log("删除选题:", id)
},
// 工具方法
getPriorityType(score) {
const types = { "高": "danger", "中": "warning", "低": "info" }
return types[score] || "info"
},
getStatusClass(status) {
const classes = {
"待处理": "status-dot pending",
"待审查": "status-dot review",
"待发布": "status-dot ready",
"已发布": "status-dot published"
}
return classes[status] || ""
},
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"
})
},
generateLogsContent(container) {
container.innerHTML = `
<div class="mb-4">
<div class="flex gap-2 flex-wrap">
<select class="px-3 py-2 border rounded">
<option>创作日志</option>
<option>优化日志</option>
<option>收集日志</option>
</select>
<input type="date" class="px-3 py-2 border rounded">
<button class="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600">加载日志</button>
</div>
</div>
<div class="bg-gray-50 p-4 rounded min-h-[200px] whitespace-pre-wrap font-mono text-sm">
请选择日志类型和日期,然后点击加载
</div>
`
},
generateUsersContent(container) {
container.innerHTML = `
<div class="flex justify-between items-center mb-4">
<h3 class="text-lg font-semibold">用户列表</h3>
<button class="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600">+ 新建用户</button>
</div>
<table class="w-full border-collapse">
<thead>
<tr class="bg-gray-50">
<th class="border p-2">ID</th>
<th class="border p-2">用户名</th>
<th class="border p-2">角色</th>
<th class="border p-2">操作</th>
</tr>
</thead>
<tbody>
<tr>
<td class="border p-2">admin</td>
<td class="border p-2">管理员</td>
<td class="border p-2"><span class="px-2 py-1 bg-red-100 text-red-800 rounded">管理员</span></td>
<td class="border p-2"><button class="px-2 py-1 bg-gray-400 text-white rounded text-xs" disabled>删除</button></td>
</tr>
<tr>
<td class="border p-2">editor1</td>
<td class="border p-2">编辑小王</td>
<td class="border p-2"><span class="px-2 py-1 bg-green-100 text-green-800 rounded">编辑</span></td>
<td class="border p-2"><button class="px-2 py-1 bg-red-500 text-white rounded text-xs">删除</button></td>
</tr>
</tbody>
</table>
`
}
},
mounted() {
if ("logs" === "topics") {
this.fetchTopics()
} else if ("logs" === "logs") {
this.fetchLogs()
} else if ("logs" === "users") {
this.fetchUsers()
}
}
}
Vue.createApp(App).mount('#app')
Vue.createApp(App).mount("#app")
</script>
</body>
</html>