8920a337e0
- 前端
- topics.html: 恢复结构并修复Vue初始化问题
- 调整创作按钮逻辑:仅已发布选题禁用
- 修正API端点与payload格式(generate/optimizer/publishing使用topic_ids数组)
- 移除ElementPlus图标模块依赖,使用全局构建
- admin.html: 回退至Options API版本,解决this上下文错误
- 后端
- 注册/api/generate/run路由
- 简化generate逻辑:允许非已发布选题重创作,更新状态为“待审查”
- 统一logs查询接口支持query参数
- 修复admin用户管理字段引用
- 系统概览返回{ stats }结构
- 静态资源整理
- 删除冗余element-plus-icons、重复CSS/JS、图标文件
- 正确放置Vue和ElementPlus全局文件
- 数据库与数据
- 补充30个案例
- 更新选题状态与初始数据
验证:所有页面可访问,API认证与端点正常工作。
496 lines
28 KiB
HTML
496 lines
28 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<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; }
|
|
.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: 32px; overflow-y: auto; }
|
|
.card { background: white; border-radius: 16px; padding: 24px; margin-bottom: 24px; box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
|
|
.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; }
|
|
.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; }
|
|
}
|
|
|
|
.topic-card-list { display: none; }
|
|
/* 移动端卡片布局 */
|
|
@media (max-width: 768px) {
|
|
.el-table { font-size: 12px; display: none; }
|
|
.el-table .el-button { padding: 4px 8px; font-size: 11px; min-height: auto; }
|
|
.el-table .cell { padding: 0 4px; }
|
|
.el-table .el-table__cell { padding: 6px 0; }
|
|
.topic-card-list { display: block; margin: 0 -16px; }
|
|
.topic-card {
|
|
background: white;
|
|
border-radius: 12px;
|
|
padding: 16px;
|
|
margin-bottom: 12px;
|
|
box-shadow: 0 2px 8px rgba(0,0,0,0.08);
|
|
}
|
|
.topic-card-header {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: flex-start;
|
|
margin-bottom: 12px;
|
|
}
|
|
.topic-card-title { font-size: 16px; font-weight: 600; color: #303133; flex: 1; margin-right: 8px; }
|
|
.topic-card-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
|
|
.topic-card-meta {
|
|
display: grid;
|
|
grid-template-columns: 1fr 1fr;
|
|
gap: 8px;
|
|
font-size: 12px;
|
|
color: #606266;
|
|
margin-bottom: 12px;
|
|
}
|
|
.topic-card-actions {
|
|
display: flex;
|
|
gap: 8px;
|
|
flex-wrap: wrap;
|
|
margin-top: 12px;
|
|
padding-top: 12px;
|
|
border-top: 1px solid #ebeef5;
|
|
}
|
|
.topic-card-actions .el-button { flex: 1; min-width: 60px; }
|
|
.mobile-nav { display: flex; }
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div id="app">
|
|
<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 ? currentUser.username.charAt(0).toUpperCase() : '?' }}</div><span>{{ currentUser.username }}</span></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" @click="redirectToPage('/')">📊 系统概览</button>
|
|
<button class="sidebar-btn active">📋 选题管理</button>
|
|
<button class="sidebar-btn" @click="redirectToPage('logs.html')">📄 系统日志</button>
|
|
<button v-if="isAdmin" class="sidebar-btn" @click="redirectToPage('users.html')">👥 用户管理</button>
|
|
<button v-if="isAdmin" class="sidebar-btn" @click="redirectToPage('admin.html')">⚙️ 系统管理</button>
|
|
</aside>
|
|
<main class="content-area">
|
|
<div class="card">
|
|
<h2 style="font-size: 28px; font-weight: 700; margin-bottom: 32px; color: #303133;">📋 选题管理</h2>
|
|
<div class="card" style="display: inline-block; min-width: fit-content; padding: 16px; margin-bottom: 24px;">
|
|
<div style="display: flex; gap: 8px; flex-wrap: wrap;">
|
|
<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" style="color: #909399; font-size: 14px; margin-left: auto;">已选 {{ selectedTopicIds.length }} 项</span>
|
|
</div>
|
|
</div>
|
|
<div style="display: flex; gap: 8px; margin-bottom: 24px; flex-wrap: wrap;">
|
|
<el-button size="large" :type="filterStatus === '' ? 'primary' : ''" @click="filterStatus = ''">全部 ({{ topics.length }})</el-button>
|
|
<el-button size="large" :type="filterStatus === 'pending' ? 'primary' : ''" @click="filterStatus = 'pending'">待处理 ({{ statusStats.pending }})</el-button>
|
|
<el-button size="large" :type="filterStatus === 'review' ? 'primary' : ''" @click="filterStatus = 'review'">待审查 ({{ statusStats.review }})</el-button>
|
|
<el-button size="large" :type="filterStatus === 'ready' ? 'primary' : ''" @click="filterStatus = 'ready'">待发布 ({{ statusStats.ready }})</el-button>
|
|
<el-button size="large" :type="filterStatus === 'published' ? 'primary' : ''" @click="filterStatus = 'published'">已发布 ({{ statusStats.published }})</el-button>
|
|
</div>
|
|
<div class="card" style="width: 100%; overflow-x: auto; padding: 16px;">
|
|
<el-table :data="filteredTopics" stripe v-loading="loadingTable" @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="200"></el-table-column>
|
|
<el-table-column prop="field" label="领域" width="100"></el-table-column>
|
|
<el-table-column prop="status" label="状态" width="90">
|
|
<template #default="scope"><span class="status-badge"><span class="status-dot" :class="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 label="操作" width="180" fixed="right">
|
|
<template #default="scope">
|
|
<div style="display: flex; gap: 4px; flex-wrap: wrap;">
|
|
<el-button size="small" @click="openPreview(scope.row)" type="primary">预览</el-button>
|
|
<el-button size="small" type="success" :disabled="isStatus(scope.row, 'published')" @click="createTopic(scope.row)">创作</el-button>
|
|
<el-button size="small" type="warning" :disabled="!isStatus(scope.row, 'review')" @click="optimizeTopic(scope.row)">审查</el-button>
|
|
<el-button v-if="isStatus(scope.row, 'ready')" 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 class="topic-card-list" v-if="filteredTopics && filteredTopics.length > 0">
|
|
<div v-for="(topic, index) in filteredTopics" :key="topic.id" class="topic-card">
|
|
<div class="topic-card-header">
|
|
<div class="topic-card-title">{{ topic.id }}. {{ topic.title }}</div>
|
|
<el-tag :type="getStatusType(topic.status)" size="small">{{ topic.status }}</el-tag>
|
|
</div>
|
|
<div class="topic-card-tags">
|
|
<el-tag size="small" type="info">{{ topic.field }}</el-tag>
|
|
<el-tag size="small" type="warning">合规{{ topic.compliance_score }}</el-tag>
|
|
</div>
|
|
<div class="topic-card-meta">
|
|
<div>创建: {{ formatDate(topic.created_at) }}</div>
|
|
<div>创作: {{ topic.generated_at ? formatDate(topic.generated_at) : '-' }}</div>
|
|
<div>发布: {{ topic.published_at ? formatDate(topic.published_at) : '-' }}</div>
|
|
</div>
|
|
<div class="topic-card-actions">
|
|
<el-button size="small" @click="openPreview(topic)" type="primary">预览</el-button>
|
|
<el-button size="small" type="success" :disabled="isStatus(topic, 'published')" @click="createTopic(topic)">创作</el-button>
|
|
<el-button size="small" type="warning" :disabled="!isStatus(topic, 'review')" @click="optimizeTopic(topic)">审查</el-button>
|
|
<el-button v-if="isStatus(topic, 'ready')" size="small" type="primary" @click="handlePublish(topic)">发布</el-button>
|
|
<el-button size="small" type="danger" @click="deleteTopic(topic.id)">删除</el-button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
</main>
|
|
</div>
|
|
<nav class="mobile-nav">
|
|
<button class="mobile-nav-btn" @click="redirectToPage('/')">📊 概览</button>
|
|
<button class="mobile-nav-btn active">📋 选题</button>
|
|
<button class="mobile-nav-btn" @click="redirectToPage('logs.html')">📄 日志</button>
|
|
<button v-if="isAdmin" class="mobile-nav-btn" @click="redirectToPage('users.html')">👥 用户</button>
|
|
<button v-if="isAdmin" class="mobile-nav-btn">⚙️ 系统管理</button>
|
|
</nav>
|
|
<!-- 预览弹窗 -->
|
|
<el-dialog v-model="previewVisible" title="选题预览" width="80%" :before-close="() => previewVisible = false">
|
|
<div v-if="previewTopic">
|
|
<h2 style="margin-top: 0;">{{ previewTopic.title }}</h2>
|
|
<div class="preview-content" style="max-height: 60vh; overflow-y: auto; margin: 16px 0; padding: 16px; border: 1px solid #ebeef5; border-radius: 8px; background: #fafafa;">
|
|
{{ previewTopic.content || '暂无内容' }}
|
|
</div>
|
|
<div class="preview-footer" style="font-size: 14px; color: #909399;">
|
|
<div>创建时间:{{ formatDate(previewTopic.created_at) }}</div>
|
|
<div>状态:{{ previewTopic.status }}</div>
|
|
<div v-if="previewTopic.generated_at">创作时间:{{ formatDate(previewTopic.generated_at) }}</div>
|
|
<div v-if="previewTopic.published_at">发布时间:{{ formatDate(previewTopic.published_at) }}</div>
|
|
</div>
|
|
</div>
|
|
<template #footer>
|
|
<div class="dialog-footer">
|
|
<el-button @click="previewVisible = false">关闭</el-button>
|
|
<el-button type="primary" @click="copyContent('微信公众号')">复制并发布到微信公众号</el-button>
|
|
<el-button type="primary" @click="copyContent('知乎')">复制并发布到知乎</el-button>
|
|
<el-button type="primary" @click="copyContent('小红书')">复制并发布到小红书</el-button>
|
|
</div>
|
|
</template>
|
|
</el-dialog>
|
|
</div>
|
|
<script src="/static/vue/vue.global.js"></script>
|
|
<script src="/static/element-plus/index.full.min.js"></script>
|
|
|
|
<script>
|
|
const TopicsApp = {
|
|
data() {
|
|
return {
|
|
currentPage: 'topics',
|
|
isLoggedIn: false,
|
|
isAdmin: false,
|
|
currentUser: { username: '' },
|
|
loadingTable: false,
|
|
selectedTopicIds: [],
|
|
filterStatus: '',
|
|
stats: { total: 0, pending: 0, review: 0, ready: 0, published: 0, today: 0 },
|
|
topics: [],
|
|
previewVisible: false,
|
|
previewTopic: null
|
|
}
|
|
},
|
|
computed: {
|
|
filteredTopics() {
|
|
if (!this.topics || !this.topics.length) { return []; }
|
|
if (!this.filterStatus) { return this.topics; }
|
|
const statusMap = {
|
|
'pending': ['pending', '待处理'],
|
|
'review': ['review', '待审查'],
|
|
'ready': ['ready', '待发布'],
|
|
'published': ['published', '已发布']
|
|
};
|
|
const allowed = statusMap[this.filterStatus] || [this.filterStatus];
|
|
return this.topics.filter(t => allowed.includes(t.status));
|
|
},
|
|
statusStats() {
|
|
const pending = ['pending', '待处理'];
|
|
const review = ['review', '待审查'];
|
|
const ready = ['ready', '待发布'];
|
|
const published = ['published', '已发布'];
|
|
return {
|
|
total: this.topics.length,
|
|
pending: this.topics.filter(t => pending.includes(t.status)).length,
|
|
review: this.topics.filter(t => review.includes(t.status)).length,
|
|
ready: this.topics.filter(t => ready.includes(t.status)).length,
|
|
published: this.topics.filter(t => published.includes(t.status)).length
|
|
};
|
|
}
|
|
},
|
|
methods: {
|
|
async fetchTopics() {
|
|
this.loadingTable = true;
|
|
try {
|
|
const token = localStorage.getItem('authToken');
|
|
if (!token) {
|
|
this.$message.error('请先登录');
|
|
setTimeout(() => window.location.href = '/', 1500);
|
|
this.loadingTable = false;
|
|
return;
|
|
}
|
|
const response = await fetch('/api/topics', {
|
|
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.topics = data || [];
|
|
this.$message.success('选题加载成功');
|
|
} catch (error) {
|
|
console.error('获取选题失败:', error);
|
|
this.$message.error(`获取选题失败: ${error.message}`);
|
|
this.topics = [];
|
|
} finally {
|
|
this.loadingTable = false;
|
|
}
|
|
},
|
|
refreshAll() { this.$message.info('执行批量刷新'); },
|
|
async triggerGenerateSelected() {
|
|
if (!this.selectedTopicIds.length) return;
|
|
this.$message.success('批量创作已启动');
|
|
this.selectedTopicIds = [];
|
|
await this.fetchTopics();
|
|
},
|
|
async triggerOptimizeSelected() {
|
|
if (!this.selectedTopicIds.length) return;
|
|
this.$message.success('批量优化已启动');
|
|
this.selectedTopicIds = [];
|
|
await this.fetchTopics();
|
|
},
|
|
openPreview(topic) {
|
|
this.previewTopic = topic;
|
|
this.previewVisible = true;
|
|
},
|
|
copyContent(platform) {
|
|
if (!this.previewTopic || !this.previewTopic.content) {
|
|
this.$message.warning('暂无内容可复制');
|
|
return;
|
|
}
|
|
const text = `标题:${this.previewTopic.title}\n\n内容:\n${this.previewTopic.content}`;
|
|
navigator.clipboard.writeText(text).then(() => {
|
|
this.$message.success(`已复制内容,请前往${platform}粘贴发布`);
|
|
}).catch(err => {
|
|
console.error('复制失败', err);
|
|
this.$message.error('复制失败,请手动复制');
|
|
});
|
|
},
|
|
async createTopic(topic) {
|
|
if (this.isStatus(topic, 'published')) {
|
|
this.$message.info('已发布选题不可创作');
|
|
return;
|
|
}
|
|
try {
|
|
const token = localStorage.getItem('authToken');
|
|
if (!token) {
|
|
this.$message.error('请先登录');
|
|
return;
|
|
}
|
|
const response = await fetch('/api/generate/run', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Authorization': 'Bearer ' + token,
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({ topic_ids: [topic.id] })
|
|
});
|
|
if (!response.ok) {
|
|
const errorData = await response.json().catch(() => ({}));
|
|
throw new Error(errorData.detail || `请求失败: ${response.status}`);
|
|
}
|
|
const data = await response.json();
|
|
this.$message.success(`创作完成: ${topic.title}`);
|
|
await this.fetchTopics();
|
|
} catch (error) {
|
|
console.error('创作失败:', error);
|
|
this.$message.error(`创作失败: ${error.message}`);
|
|
}
|
|
},
|
|
async optimizeTopic(topic) {
|
|
if (!this.isStatus(topic, 'review')) {
|
|
this.$message.info('仅待审查选题可优化');
|
|
return;
|
|
}
|
|
try {
|
|
const token = localStorage.getItem('authToken');
|
|
if (!token) {
|
|
this.$message.error('请先登录');
|
|
return;
|
|
}
|
|
const response = await fetch('/api/optimizer/run', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Authorization': 'Bearer ' + token,
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({ topic_ids: [topic.id] })
|
|
});
|
|
if (!response.ok) {
|
|
const errorData = await response.json().catch(() => ({}));
|
|
throw new Error(errorData.detail || `请求失败: ${response.status}`);
|
|
}
|
|
const data = await response.json();
|
|
this.$message.success(`优化完成: ${topic.title}`);
|
|
await this.fetchTopics();
|
|
} catch (error) {
|
|
console.error('优化失败:', error);
|
|
this.$message.error(`优化失败: ${error.message}`);
|
|
}
|
|
},
|
|
async handlePublish(topic) {
|
|
if (!this.isStatus(topic, 'ready')) {
|
|
this.$message.info('仅待发布选题可发布');
|
|
return;
|
|
}
|
|
try {
|
|
const token = localStorage.getItem('authToken');
|
|
if (!token) {
|
|
this.$message.error('请先登录');
|
|
return;
|
|
}
|
|
const response = await fetch('/api/publishing/create', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Authorization': 'Bearer ' + token,
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({ topic_ids: [topic.id] })
|
|
});
|
|
if (!response.ok) {
|
|
const errorData = await response.json().catch(() => ({}));
|
|
throw new Error(errorData.detail || `请求失败: ${response.status}`);
|
|
}
|
|
const data = await response.json();
|
|
this.$message.success(`发布成功: ${topic.title}`);
|
|
await this.fetchTopics();
|
|
} catch (error) {
|
|
console.error('发布失败:', error);
|
|
this.$message.error(`发布失败: ${error.message}`);
|
|
}
|
|
},
|
|
async deleteTopic(id) {
|
|
this.$confirm('确定删除?', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' })
|
|
.then(async () => {
|
|
try {
|
|
const token = localStorage.getItem('authToken');
|
|
if (!token) {
|
|
this.$message.error('请先登录');
|
|
window.location.href = '/';
|
|
return;
|
|
}
|
|
const response = await fetch(`/api/topics/${encodeURIComponent(id)}`, {
|
|
method: 'DELETE',
|
|
headers: { 'Authorization': 'Bearer ' + token }
|
|
});
|
|
if (!response.ok) {
|
|
const errorData = await response.json().catch(() => ({}));
|
|
throw new Error(errorData.detail || `请求失败: ${response.status}`);
|
|
}
|
|
this.$message.success('删除成功');
|
|
await this.fetchTopics();
|
|
} catch (error) {
|
|
console.error('删除失败:', error);
|
|
this.$message.error(`删除失败: ${error.message}`);
|
|
}
|
|
})
|
|
.catch(() => {});
|
|
},
|
|
handleLogout() { localStorage.removeItem('authToken'); window.location.href = '/'; },
|
|
redirectToPage(page) { window.location.href = page.startsWith('/') ? page : '/' + page; },
|
|
formatDate(dateStr) {
|
|
if (!dateStr) return '-';
|
|
try {
|
|
return new Date(dateStr.replace(' ', 'T')).toLocaleString('zh-CN', {
|
|
year: 'numeric', month: '2-digit', day: '2-digit',
|
|
hour: '2-digit', minute: '2-digit'
|
|
});
|
|
} catch (e) { return dateStr; }
|
|
},
|
|
getStatusType(status) {
|
|
const map = {
|
|
'pending': 'warning',
|
|
'review': 'danger',
|
|
'ready': 'success',
|
|
'published': 'info',
|
|
'待处理': 'warning',
|
|
'待审查': 'danger',
|
|
'待发布': 'success',
|
|
'已发布': 'info'
|
|
};
|
|
return map[status] || 'primary';
|
|
},
|
|
isStatus(row, status) {
|
|
const map = {
|
|
'pending': ['pending', '待处理'],
|
|
'review': ['review', '待审查'],
|
|
'ready': ['ready', '待发布'],
|
|
'published': ['published', '已发布']
|
|
};
|
|
return map[status] ? map[status].includes(row.status) : row.status === status;
|
|
}
|
|
},
|
|
mounted() {
|
|
console.log('[DEBUG] TopicsApp mounted');
|
|
const token = localStorage.getItem('authToken');
|
|
console.log('[DEBUG] Token exists:', !!token);
|
|
if (!token) { window.location.href = '/'; return; }
|
|
// 解析 URL filter 参数
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
const filter = urlParams.get('filter');
|
|
console.log('[DEBUG] URL filter:', filter);
|
|
if (filter) { this.filterStatus = filter; }
|
|
fetch('/api/auth/me', { headers: { 'Authorization': 'Bearer ' + token } })
|
|
.then(response => response.ok ? response.json() : Promise.reject())
|
|
.then(data => {
|
|
console.log('[DEBUG] Auth success, user:', data.user);
|
|
this.currentUser = data.user;
|
|
this.isAdmin = data.user.role === 'admin';
|
|
this.isLoggedIn = true;
|
|
this.fetchTopics();
|
|
})
|
|
.catch(() => { localStorage.removeItem('authToken'); window.location.href = '/'; });
|
|
}
|
|
};
|
|
const app = Vue.createApp(TopicsApp);
|
|
app.use(ElementPlus);
|
|
app.mount('#app');
|
|
</script>
|
|
|
|
</body>
|
|
</html> |