472 lines
33 KiB
HTML
472 lines
33 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="element-plus.css">
|
|
<link rel="stylesheet" href="theme-modern.css">
|
|
<style>
|
|
.selected-count { color: var(--color-text-secondary); font-size: var(--font-size-body); margin-left: auto; }
|
|
.topic-card-list { display: none; }
|
|
@media (max-width: 768px) {
|
|
.el-table { display: none; }
|
|
.topic-card-list { display: block; }
|
|
.topic-card { background: var(--color-bg-raised); border-radius: var(--radius-md); padding: 12px; margin-bottom: 12px; box-shadow: var(--shadow-sm); border: 2px solid transparent; }
|
|
.topic-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px; gap: 6px; }
|
|
.topic-card-title { font-size: var(--font-size-body); font-weight: 600; color: var(--color-text-primary); flex: 1; margin-right: 4px; word-break: break-word; overflow: hidden; }
|
|
.topic-card-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
|
|
.topic-card-meta { display: flex; flex-direction: column; gap: 3px; font-size: var(--font-size-caption); color: var(--color-text-regular); margin-bottom: 10px; }
|
|
.topic-card-actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 4px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--color-border); }
|
|
.topic-card-actions .el-button { margin: 0; width: 100%; justify-content: center; padding: 8px 4px !important; }
|
|
.topic-card.is-checked { border-color: var(--color-primary); box-shadow: 0 0 0 1px rgba(64,158,255,0.2); }
|
|
.topic-card-actions .el-button--danger { grid-column: 1 / -1; }
|
|
}
|
|
</style>
|
|
<script src="uni-nav.js"></script>
|
|
</head>
|
|
<body>
|
|
<div id="app">
|
|
<uni-nav title="选题管理" :username="currentUser.username" :is-admin="isAdmin" current-page="topics" @navigate="redirectToPage" @logout="handleLogout">
|
|
</uni-nav>
|
|
<div class="main-content">
|
|
<main class="content-area">
|
|
<div class="card page-fade">
|
|
<div class="page-header">
|
|
<h2 class="page-title"><el-icon style="vertical-align:-2px;"><IconTopic /></el-icon> 选题管理</h2>
|
|
<div class="toolbar">
|
|
<el-button type="primary" size="small" @click="refreshAll"><el-icon style="vertical-align:-2px;"><IconRefresh /></el-icon> 批量刷新</el-button>
|
|
<el-button size="small" @click="toggleSelectAll">{{ selectAllLabel }}</el-button>
|
|
<el-button type="success" size="small" @click="triggerGenerateSelected" :disabled="selectedTopicIds.length === 0"><el-icon style="vertical-align:-2px;"><IconPlus /></el-icon> 批量创作</el-button>
|
|
<el-button type="warning" size="small" @click="triggerReviewSelected" :disabled="selectedTopicIds.length === 0"><el-icon style="vertical-align:-2px;"><IconSearch /></el-icon> 批量审查</el-button>
|
|
<span v-if="selectedTopicIds.length > 0" class="selected-count">已选 {{ selectedTopicIds.length }} 项</span>
|
|
</div>
|
|
</div>
|
|
<div class="filter-bar">
|
|
<el-button size="default" :type="filterStatus === '' ? 'primary' : ''" @click="filterStatus = ''; fetchTopics()">全部 ({{ topics.length }})</el-button>
|
|
<el-button size="default" :type="filterStatus === 'today' ? 'primary' : ''" @click="filterStatus = 'today'; fetchTopics()">今日新增 ({{ todayCount }})</el-button>
|
|
<el-button size="default" :type="filterStatus === 'pending' ? 'primary' : ''" @click="filterStatus = 'pending'; fetchTopics()">待处理 ({{ statusStats.pending }})</el-button>
|
|
<el-button size="default" :type="filterStatus === 'review' ? 'primary' : ''" @click="filterStatus = 'review'; fetchTopics()">待审查 ({{ statusStats.review }})</el-button>
|
|
<el-button size="default" :type="filterStatus === 'ready' ? 'primary' : ''" @click="filterStatus = 'ready'; fetchTopics()">待发布 ({{ statusStats.ready }})</el-button>
|
|
<el-button size="default" :type="filterStatus === 'published' ? 'primary' : ''" @click="filterStatus = 'published'; fetchTopics()">已发布 ({{ statusStats.published }})</el-button>
|
|
</div>
|
|
<el-table :data="paginatedTopics" stripe v-loading="loadingTable" @selection-change="selectedTopicIds = $event.map(item => item.id)">
|
|
<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>{{ getStatusLabel(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="230" fixed="right">
|
|
<template #default="scope">
|
|
<div style="display: flex; gap: 4px; white-space: nowrap;">
|
|
<el-button size="small" @click="openPreview(scope.row)" type="primary" style="padding:5px 8px;">预览</el-button>
|
|
<el-button size="small" type="success" :disabled="isStatus(scope.row, 'published')" @click="createTopic(scope.row)" style="padding:5px 8px;">创作</el-button>
|
|
<el-button size="small" type="warning" :disabled="!isStatus(scope.row, 'review')" @click="reviewTopic(scope.row)" style="padding:5px 8px;">审查</el-button>
|
|
<el-button v-if="isStatus(scope.row, 'ready')" size="small" type="primary" @click="openPublishDialog(scope.row)" style="padding:5px 8px;">发布</el-button>
|
|
<el-button size="small" type="danger" @click="deleteTopic(scope.row.id)" style="padding:5px 8px;">删除</el-button>
|
|
</div>
|
|
</template>
|
|
</el-table-column>
|
|
</el-table>
|
|
<div v-if="!loadingTable && paginatedTopics.length === 0" class="empty-state" style="margin-top:20px;"><el-icon style="font-size:48px;color:#c0c4cc;"><IconTopic /></el-icon><div class="empty-text">暂无选题数据</div></div>
|
|
<div v-if="filteredTopics.length > pageSize" style="display:flex;justify-content:center;align-items:center;margin:12px 0;gap:16px;">
|
|
<span style="font-size:13px;color:#909399;">共 {{ filteredTopics.length }} 条</span>
|
|
<el-pagination background layout="prev, pager, next" :total="filteredTopics.length" :page-size="pageSize" :current-page="currentPage" @current-change="currentPage = $event"></el-pagination>
|
|
</div>
|
|
<div class="topic-card-list" v-if="filteredTopics && filteredTopics.length > 0">
|
|
<div v-for="topic in filteredTopics" :key="topic.id" class="topic-card" :class="{ 'is-checked': selectedTopicIds.includes(topic.id) }">
|
|
<div class="topic-card-header">
|
|
<div class="topic-card-title">
|
|
<el-checkbox :checked="selectedTopicIds.includes(topic.id)" @change="toggleCheck(topic.id)" style="margin-right:6px;"></el-checkbox>
|
|
{{ topic.id }}. {{ topic.title }}
|
|
</div>
|
|
<el-tag :type="getStatusType(topic.status)" size="small">{{ getStatusLabel(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="reviewTopic(topic)">审查</el-button>
|
|
<el-button v-show="isStatus(topic, 'ready')" size="small" type="primary" @click="openPublishDialog(topic)">发布</el-button>
|
|
<el-button size="small" type="danger" @click="deleteTopic(topic.id)">删除</el-button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
</div>
|
|
<el-dialog v-model="publishDialogVisible" title="发布确认" width="420px" :close-on-click-modal="false">
|
|
<div v-if="publishTopic">
|
|
<div style="margin-bottom:16px;">
|
|
<div style="font-size:14px;color:#606266;margin-bottom:8px;">选题:</div>
|
|
<div style="font-size:15px;font-weight:600;color:#303133;">{{ publishTopic.id }}. {{ publishTopic.title }}</div>
|
|
</div>
|
|
<div style="margin-bottom:16px;">
|
|
<div style="font-size:14px;color:#606266;margin-bottom:8px;">选择发布平台:</div>
|
|
<el-checkbox v-model="publishPlatforms.zhihu" label="zhihu" style="display:block;margin-bottom:8px;">知乎</el-checkbox>
|
|
<el-checkbox v-model="publishPlatforms.wechat" label="wechat" style="display:block;margin-bottom:8px;">微信公众号</el-checkbox>
|
|
<el-checkbox v-model="publishPlatforms.xiaohongshu" label="xiaohongshu" style="display:block;">小红书</el-checkbox>
|
|
</div>
|
|
<div v-if="publishing" style="text-align:center;padding:12px;color:#909399;">
|
|
<el-icon class="is-loading" style="margin-right:4px;">
|
|
<svg viewBox="0 0 1024 1024" width="16" height="16"><path d="M512 64a448 448 0 1 1 0 896 448 448 0 0 1 0-896z" fill="none" stroke="currentColor" stroke-width="64"/></svg>
|
|
</el-icon>
|
|
正在发布...
|
|
</div>
|
|
</div>
|
|
<template #footer>
|
|
<el-button @click="publishDialogVisible = false" :disabled="publishing">取消</el-button>
|
|
<el-button type="primary" @click="confirmPublish" :loading="publishing" :disabled="!publishPlatforms.zhihu && !publishPlatforms.wechat && !publishPlatforms.xiaohongshu">确认发布</el-button>
|
|
</template>
|
|
</el-dialog>
|
|
<el-dialog v-model="previewVisible" title="选题预览" width="85%" :modal-props="{ closeOnClickModal: false }" :before-close="() => previewVisible = false" class="preview-dialog-custom" :fullscreen="previewFullscreen" close-on-press-escape>
|
|
<div v-if="previewTopic">
|
|
<div style="display:flex; justify-content:space-between; align-items:center; flex-wrap:wrap; gap:8px;">
|
|
<h2 style="margin:0; font-size:16px;">{{ previewTopic.title }}</h2>
|
|
<div style="display:flex; align-items:center; gap:12px; font-size:13px; color:#909399;">
|
|
<span>创建:{{ formatDate(previewTopic.created_at) }}</span>
|
|
<span>状态:{{ getStatusLabel(previewTopic.status) }}</span>
|
|
<el-tag v-if="editing" type="warning" size="small">编辑模式</el-tag>
|
|
<el-button size="small" @click="togglePreviewFullscreen">{{ previewFullscreen ? '退出全屏' : '全屏' }}</el-button>
|
|
<el-button v-if="previewFullscreen" size="small" type="danger" @click="previewVisible = false">关闭</el-button>
|
|
</div>
|
|
</div>
|
|
<div style="margin: 12px 0 16px; display: flex; justify-content: space-between; align-items: center; gap: 8px;">
|
|
<el-button-group>
|
|
<el-button :type="previewPlatform === 'zhihu' ? 'primary' : 'default'" @click="switchPlatform('zhihu')">知乎</el-button>
|
|
<el-button :type="previewPlatform === 'wechat' ? 'primary' : 'default'" @click="switchPlatform('wechat')">微信公众号</el-button>
|
|
<el-button :type="previewPlatform === 'xiaohongshu' ? 'primary' : 'default'" @click="switchPlatform('xiaohongshu')">小红书</el-button>
|
|
</el-button-group>
|
|
<div>
|
|
<el-button v-if="!editing" size="small" type="primary" @click="startEdit" plain><el-icon style="vertical-align:-2px;"><IconEdit /></el-icon> 编辑</el-button>
|
|
<el-button v-if="editing" size="small" @click="cancelEdit">取消</el-button>
|
|
<el-button v-if="editing" size="small" type="primary" @click="saveContent" :loading="savingContent">保存</el-button>
|
|
</div>
|
|
</div>
|
|
<div style="width:100%;">
|
|
<div v-if="!editing" class="preview-body" style="min-height:300px; height:68vh; border:1px solid #ebeef5; border-radius:8px; background:#fff; padding:20px; overflow-y:auto; width:100%; line-height:1.8;" v-html="currentPreviewBody"></div>
|
|
<div v-else ref="editor" contenteditable="true" style="min-height:300px; height:68vh; border:1px solid #409eff; border-radius:8px; background:#fff; padding:20px; overflow-y:auto; width:100%; line-height:1.8; outline:none; box-shadow:0 0 0 2px rgba(64,158,255,0.2);" @input="editContent = $event.target.innerHTML"></div>
|
|
</div>
|
|
</div>
|
|
<template #footer>
|
|
<div style="display:flex; justify-content:space-between; align-items:center; width:100%; font-size:14px; color:#909399;">
|
|
<div>
|
|
<span>创建:{{ formatDate(previewTopic.created_at) }}</span>
|
|
<span style="margin: 0 8px;">|</span>
|
|
<span>状态:{{ getStatusLabel(previewTopic.status) }}</span>
|
|
<span v-if="previewTopic.generated_at" style="margin-left:8px;">创作:{{ formatDate(previewTopic.generated_at) }}</span>
|
|
<span v-if="previewTopic.published_at" style="margin-left:8px;">发布:{{ formatDate(previewTopic.published_at) }}</span>
|
|
</div>
|
|
<div>
|
|
<el-button @click="previewVisible = false">关闭</el-button>
|
|
<el-button type="primary" @click="copyContent(previewPlatform)">复制并发布到{{ platformName(previewPlatform) }}</el-button>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</el-dialog>
|
|
</div>
|
|
<script src="vue.global.prod.js"></script>
|
|
<script src="icon-components.js"></script>
|
|
<script src="element-plus.full.js"></script>
|
|
<script>
|
|
const TopicsApp = {
|
|
data() {
|
|
return {
|
|
isLoggedIn: false, isAdmin: false, currentUser: { username: '' },
|
|
loadingTable: false, selectedTopicIds: [], filterStatus: '',
|
|
stats: { total: 0, pending: 0, review: 0, ready: 0, published: 0, today: 0 },
|
|
topics: [], allTopics: [], todayTopics: [], todayCount: 0,
|
|
previewVisible: false, previewTopic: null, previewFullscreen: false,
|
|
previewPlatform: 'zhihu', platformContents: {}, editing: false, editContent: '',
|
|
publishDialogVisible: false, publishTopic: null,
|
|
publishPlatforms: { zhihu: true, wechat: true, xiaohongshu: true },
|
|
publishing: false,
|
|
savingContent: false,
|
|
currentPage: 1, pageSize: 10
|
|
}
|
|
},
|
|
computed: {
|
|
filteredTopics() {
|
|
if (this.filterStatus === 'today') return this.todayTopics;
|
|
if (!this.filterStatus) return this.topics;
|
|
const map = { 'pending': ['pending','待处理'], 'review': ['review','待审查'], 'ready': ['ready','待发布'], 'published': ['published','已发布'] };
|
|
const allowed = map[this.filterStatus] || [this.filterStatus];
|
|
return this.topics.filter(t => allowed.includes(t.status));
|
|
},
|
|
paginatedTopics() {
|
|
const start = (this.currentPage - 1) * this.pageSize;
|
|
return this.filteredTopics.slice(start, start + this.pageSize);
|
|
},
|
|
statusStats() {
|
|
const s = { total: this.topics.length, pending: 0, review: 0, ready: 0, published: 0 };
|
|
const aliases = { 'pending': ['pending','待处理'], 'review': ['review','待审查'], 'ready': ['ready','待发布'], 'published': ['published','已发布'] };
|
|
this.topics.forEach(t => { for (const [k, v] of Object.entries(aliases)) { if (v.includes(t.status)) { s[k]++; break; } } });
|
|
return s;
|
|
},
|
|
currentPreviewHtml() {
|
|
const html = this.platformContents[this.previewPlatform];
|
|
if (!html) return '';
|
|
try {
|
|
const parser = new DOMParser();
|
|
const doc = parser.parseFromString(html, 'text/html');
|
|
const body = doc.body;
|
|
if (!body) return html;
|
|
body.querySelectorAll('script, nav, .header, footer, .interaction').forEach(el => el.remove());
|
|
const headHtml = doc.querySelector('head') ? doc.querySelector('head').innerHTML : '';
|
|
const bodyHtml = body.innerHTML;
|
|
const ending = '<p style="margin-top:24px;padding-top:16px;border-top:1px solid #eee;color:#666;font-size:14px;">感兴趣可以收藏关注我们,欢迎在评论区分享你的实践经验和改进建议!</p>';
|
|
return `<!DOCTYPE html><html><head>${headHtml}</head><body style="margin:0;padding:0;">${bodyHtml}${ending}</body></html>`;
|
|
} catch (e) { console.error('生成预览 HTML 失败:', e); return html; }
|
|
},
|
|
currentPreviewBody() {
|
|
const html = this.platformContents[this.previewPlatform];
|
|
if (!html) return '';
|
|
try {
|
|
const parser = new DOMParser();
|
|
const doc = parser.parseFromString(html, 'text/html');
|
|
const body = doc.body;
|
|
if (!body) return html;
|
|
body.querySelectorAll('script, nav, .header, .tags, footer, .interaction').forEach(el => el.remove());
|
|
return body.innerHTML;
|
|
} catch (e) { console.error('解析 HTML 失败:', e); return html; }
|
|
},
|
|
selectAllLabel() {
|
|
const visible = this.filteredTopics.map(t => t.id);
|
|
if (visible.length === 0) return '全选';
|
|
const allChecked = visible.every(id => this.selectedTopicIds.includes(id));
|
|
return allChecked ? '取消全选' : `全选 (${visible.length})`;
|
|
}
|
|
},
|
|
methods: {
|
|
getToken() { return localStorage.getItem('authToken'); },
|
|
async api(url, opts = {}) {
|
|
const token = this.getToken();
|
|
if (!token) { this.$message.error('请先登录'); setTimeout(() => window.location.href = '/', 1500); return null; }
|
|
const res = await fetch(url, { headers: { 'Authorization': 'Bearer ' + token, 'Content-Type': 'application/json', ...opts.headers }, ...opts });
|
|
if (!res.ok) { const data = await res.json().catch(() => ({})); throw new Error(data.detail || `请求失败: ${res.status}`); }
|
|
return res.json();
|
|
},
|
|
async fetchTopics() {
|
|
this.currentPage = 1;
|
|
this.loadingTable = true;
|
|
try {
|
|
const token = this.getToken();
|
|
const allResp = await fetch('/api/topics', { headers: { 'Authorization': 'Bearer ' + token } });
|
|
this.allTopics = await allResp.json() || [];
|
|
this.topics = this.allTopics;
|
|
|
|
if (this.filterStatus === 'today') {
|
|
const todayResp = await fetch('/api/topics?today=true', { headers: { 'Authorization': 'Bearer ' + token } });
|
|
this.todayTopics = await todayResp.json() || [];
|
|
}
|
|
} catch (error) {
|
|
console.error('获取选题失败:', error);
|
|
this.$message.error(`获取选题失败: ${error.message}`);
|
|
this.topics = [];
|
|
} finally { this.loadingTable = false; }
|
|
},
|
|
async fetchTodayCount() {
|
|
try {
|
|
const stats = await this.api('/api/topics/stats');
|
|
if (stats) this.todayCount = stats.today_created || 0;
|
|
} catch (e) { console.error('获取统计失败:', e); this.$message.error('获取统计失败: ' + e.message); }
|
|
},
|
|
refreshAll() { this.fetchTopics(); this.fetchTodayCount(); this.$message.success('已刷新'); },
|
|
async triggerGenerateSelected() {
|
|
if (!this.selectedTopicIds.length) return;
|
|
let count = 0;
|
|
for (const id of this.selectedTopicIds) {
|
|
try {
|
|
await this.api('/api/tasks/run-creator?topic_id=' + id, { method: 'POST' });
|
|
count++;
|
|
} catch (e) { console.error('创作失败:', id, e); }
|
|
}
|
|
this.$message.success(`已提交 ${count}/${this.selectedTopicIds.length} 个创作任务,可在「创作任务」页面查看进度`);
|
|
this.selectedTopicIds = [];
|
|
setTimeout(() => { this.fetchTopics(); this.fetchTodayCount(); }, 2000);
|
|
},
|
|
async triggerReviewSelected() {
|
|
if (!this.selectedTopicIds.length) return;
|
|
try {
|
|
const data = await this.api('/api/system/review/run', { method: 'POST', body: JSON.stringify({ topic_ids: this.selectedTopicIds }) });
|
|
this.$message.success('批量审查完成');
|
|
this.selectedTopicIds = [];
|
|
await this.fetchTopics();
|
|
await this.fetchTodayCount();
|
|
} catch (error) { this.$message.error(`批量审查失败: ${error.message}`); }
|
|
},
|
|
async openPreview(topic) {
|
|
this.previewTopic = topic; this.previewPlatform = 'zhihu'; this.previewVisible = true; this.platformContents = {};
|
|
const token = this.getToken();
|
|
if (!token) return;
|
|
const platforms = ['zhihu', 'wechat', 'xiaohongshu'];
|
|
const names = { zhihu: '知乎', wechat: '微信公众号', xiaohongshu: '小红书' };
|
|
await Promise.all(platforms.map(p =>
|
|
fetch(`/api/articles/${topic.id}/preview?platform=${p}`, { headers: { 'Authorization': 'Bearer ' + token } })
|
|
.then(r => r.ok ? r.json() : null).then(d => { if (d && d.html) this.platformContents[p] = d.html; }).catch(e => { console.error(`加载${p}预览失败:`, e); this.$message.error(`加载${names[p]}预览失败`); })
|
|
));
|
|
},
|
|
togglePreviewFullscreen() {
|
|
this.previewFullscreen = !this.previewFullscreen;
|
|
this.$nextTick(() => {
|
|
const overlays = document.querySelectorAll('.el-overlay');
|
|
const overlay = overlays[overlays.length - 1];
|
|
if (overlay) overlay.style.zIndex = this.previewFullscreen ? '100000' : '';
|
|
const dialog = document.querySelector('.preview-dialog-custom');
|
|
if (dialog) {
|
|
if (this.previewFullscreen) {
|
|
dialog.style.zIndex = '100001';
|
|
} else {
|
|
dialog.style.zIndex = '';
|
|
}
|
|
}
|
|
});
|
|
},
|
|
platformName(platform) { return { zhihu: '知乎', wechat: '微信公众号', xiaohongshu: '小红书' }[platform] || platform; },
|
|
copyContent(platform) {
|
|
if (!this.previewTopic || !this.previewTopic.content) { this.$message.warning('暂无内容可复制'); return; }
|
|
navigator.clipboard.writeText(`标题:${this.previewTopic.title}\n\n内容:\n${this.previewTopic.content}`)
|
|
.then(() => this.$message.success(`已复制内容,请前往${platform}粘贴发布`))
|
|
.catch(() => this.$message.error('复制失败,请手动复制'));
|
|
},
|
|
async createTopic(topic) {
|
|
if (this.isStatus(topic, 'published')) { this.$message.info('已发布选题不可创作'); return; }
|
|
try {
|
|
const data = await this.api('/api/tasks/run-creator?topic_id=' + topic.id, { method: 'POST' });
|
|
this.$message.success(`创作任务已启动: ${topic.title},可在「创作任务」页面查看进度`);
|
|
setTimeout(() => { this.fetchTopics(); this.fetchTodayCount(); }, 2000);
|
|
} catch (error) { this.$message.error(`创作失败: ${error.message}`); }
|
|
},
|
|
async reviewTopic(topic) {
|
|
if (!this.isStatus(topic, 'review')) { this.$message.info('仅待审查选题可操作'); return; }
|
|
try {
|
|
const data = await this.api('/api/system/review/run', { method: 'POST', body: JSON.stringify({ topic_ids: [topic.id] }) });
|
|
this.$message.success(`审查完成: ${topic.title}`);
|
|
await this.fetchTopics();
|
|
await this.fetchTodayCount();
|
|
} catch (error) { this.$message.error(`审查失败: ${error.message}`); }
|
|
},
|
|
openPublishDialog(topic) {
|
|
if (!this.isStatus(topic, 'ready')) { this.$message.info('仅待发布选题可发布'); return; }
|
|
this.publishTopic = topic;
|
|
this.publishPlatforms = { zhihu: true, wechat: true, xiaohongshu: true };
|
|
this.publishing = false;
|
|
this.publishDialogVisible = true;
|
|
},
|
|
async confirmPublish() {
|
|
const selected = Object.entries(this.publishPlatforms).filter(([, v]) => v).map(([k]) => k);
|
|
if (selected.length === 0) { this.$message.warning('请至少选择一个平台'); return; }
|
|
this.publishing = true;
|
|
try {
|
|
const data = await this.api('/api/publishing/create', {
|
|
method: 'POST',
|
|
body: JSON.stringify({ topic_id: this.publishTopic.id, platforms: selected })
|
|
});
|
|
this.$message.success(`发布完成: ${this.publishTopic.title}`);
|
|
this.publishDialogVisible = false;
|
|
await this.fetchTopics();
|
|
await this.fetchTodayCount();
|
|
} catch (error) { this.$message.error(`发布失败: ${error.message}`); }
|
|
finally { this.publishing = false; }
|
|
},
|
|
async deleteTopic(id) {
|
|
try {
|
|
await this.$confirm('确定删除?', '提示', { type: 'warning' });
|
|
await this.api('/api/topics/' + id, { method: 'DELETE' });
|
|
this.$message.success('删除成功');
|
|
await this.fetchTopics();
|
|
await this.fetchTodayCount();
|
|
} catch (e) { if (e !== 'cancel') this.$message.error('删除失败'); }
|
|
},
|
|
switchPlatform(platform) {
|
|
if (this.editing) this.cancelEdit();
|
|
this.previewPlatform = platform;
|
|
},
|
|
startEdit() {
|
|
this.editContent = this.currentPreviewBody;
|
|
this.editing = true;
|
|
this.$nextTick(() => { if (this.$refs.editor) this.$refs.editor.innerHTML = this.editContent; });
|
|
},
|
|
cancelEdit() {
|
|
this.editing = false;
|
|
this.editContent = '';
|
|
},
|
|
async saveContent() {
|
|
if (!this.previewTopic || !this.editContent) { this.$message.warning('没有内容可保存'); return; }
|
|
this.savingContent = true;
|
|
try {
|
|
await this.api(`/api/articles/${this.previewTopic.id}/content`, {
|
|
method: 'PUT',
|
|
body: JSON.stringify({ platform: this.previewPlatform, html_content: this.editContent })
|
|
});
|
|
this.$message.success('保存成功');
|
|
this.platformContents[this.previewPlatform] = this.editContent;
|
|
this.editing = false;
|
|
} catch (e) { this.$message.error('保存失败: ' + e.message); }
|
|
finally { this.savingContent = false; }
|
|
},
|
|
handleLogout() { localStorage.removeItem('authToken'); localStorage.removeItem('userRole'); localStorage.removeItem('currentUser'); window.location.href = '/login.html'; },
|
|
redirectToPage(page) { window.location.href = page.startsWith('/') ? page : '/' + page; },
|
|
getStatusLabel(status) { return { 'pending': '待处理', 'review': '待审查', 'ready': '待发布', 'published': '已发布' }[status] || status; },
|
|
toggleCheck(id) {
|
|
const idx = this.selectedTopicIds.indexOf(id);
|
|
if (idx >= 0) {
|
|
this.selectedTopicIds.splice(idx, 1);
|
|
} else {
|
|
this.selectedTopicIds.push(id);
|
|
}
|
|
},
|
|
toggleSelectAll() {
|
|
const visible = this.filteredTopics.map(t => t.id);
|
|
const allChecked = visible.every(id => this.selectedTopicIds.includes(id));
|
|
if (allChecked) {
|
|
this.selectedTopicIds = this.selectedTopicIds.filter(id => !visible.includes(id));
|
|
} else {
|
|
const existing = new Set(this.selectedTopicIds);
|
|
for (const id of visible) { if (!existing.has(id)) { this.selectedTopicIds.push(id); } }
|
|
}
|
|
},
|
|
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) { return { 'pending': 'warning', 'review': 'danger', 'ready': 'success', 'published': 'info' }[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() {
|
|
const token = localStorage.getItem('authToken');
|
|
if (!token) { window.location.href = '/login.html'; return; }
|
|
const urlFilter = new URLSearchParams(window.location.search).get('filter');
|
|
if (urlFilter) this.filterStatus = urlFilter;
|
|
fetch('/api/auth/me', { headers: { 'Authorization': 'Bearer ' + token } })
|
|
.then(r => r.ok ? r.json() : Promise.reject())
|
|
.then(data => { this.currentUser = data.user; this.isAdmin = data.user.role === 'admin'; this.isLoggedIn = true; this.fetchTopics(); this.fetchTodayCount(); })
|
|
.catch(() => { localStorage.removeItem('authToken'); localStorage.removeItem('userRole'); localStorage.removeItem('currentUser'); window.location.href = '/login.html'; });
|
|
}
|
|
};
|
|
const app = Vue.createApp(TopicsApp);
|
|
app.use(ElementPlus);
|
|
if (window.installIcons) { window.installIcons(app); }
|
|
if (window.installUniNav) { window.installUniNav(app); }
|
|
app.mount('#app');
|
|
</script>
|
|
</body>
|
|
</html>
|