feat: 优化选题/任务/日志页面布局并打通任务系统
- topics.html: 重构布局(page-header模式),创作改为走 /api/tasks/run-creator 任务系统 - tasks.html: 重试功能实现,调用 /api/tasks/run-creator 重新提交创作 - logs.html: 统一布局风格 - 三个页面添加 min-height / overflow-x / 统一间距 - backend/run.sh: 修复入口为 app.main:app
This commit is contained in:
@@ -3,35 +3,27 @@
|
|||||||
echo "宇之然内容创作平台 - 后端服务启动"
|
echo "宇之然内容创作平台 - 后端服务启动"
|
||||||
echo "=================================="
|
echo "=================================="
|
||||||
|
|
||||||
# 检查Python环境
|
|
||||||
if ! command -v python3 &> /dev/null; then
|
if ! command -v python3 &> /dev/null; then
|
||||||
echo "错误: 未找到python3,请先安装Python 3.8+"
|
echo "错误: 未找到python3,请先安装Python 3.8+"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 检查虚拟环境
|
|
||||||
if [ ! -d "venv" ]; then
|
if [ ! -d "venv" ]; then
|
||||||
echo "正在创建虚拟环境..."
|
echo "正在创建虚拟环境..."
|
||||||
python3 -m venv venv
|
python3 -m venv venv
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 激活虚拟环境
|
|
||||||
source venv/bin/activate
|
source venv/bin/activate
|
||||||
|
|
||||||
# 安装依赖
|
|
||||||
echo "正在安装依赖包..."
|
echo "正在安装依赖包..."
|
||||||
pip install --upgrade pip
|
pip install --upgrade pip
|
||||||
pip install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
|
|
||||||
# 检查.env文件
|
|
||||||
if [ ! -f ".env" ]; then
|
if [ ! -f ".env" ]; then
|
||||||
echo "警告: .env文件不存在,正在复制示例文件..."
|
echo "警告: .env文件不存在,正在复制示例文件..."
|
||||||
cp .env.example .env
|
cp .env.example .env
|
||||||
echo "请编辑 .env 文件配置数据库连接等信息"
|
echo "请编辑 .env 文件配置数据库连接等信息"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 启动服务
|
|
||||||
echo "正在启动后端服务 (端口 8001)..."
|
echo "正在启动后端服务 (端口 8001)..."
|
||||||
PYTHONPATH=$(pwd) uvicorn main:app --host 0.0.0.0 --port 8001 --reload
|
exec python -m uvicorn app.main:app --host 0.0.0.0 --port 8001 --reload
|
||||||
|
|
||||||
echo "服务已停止"
|
|
||||||
|
|||||||
+42
-95
@@ -7,130 +7,93 @@
|
|||||||
<link rel="stylesheet" href="element-plus.css">
|
<link rel="stylesheet" href="element-plus.css">
|
||||||
<style>
|
<style>
|
||||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||||
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background: #f5f7fa; }
|
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background: #f5f7fa; color: #303133; }
|
||||||
.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 { 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-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-title { font-size: 20px; font-weight: 600; }
|
||||||
.navbar-user { display: flex; align-items: center; gap: 16px; }
|
.navbar-user { display: flex; align-items: center; gap: 16px; }
|
||||||
.user-info { display: flex; align-items: center; gap: 8px; }
|
.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; }
|
.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; }
|
.main-content { display: flex; flex: 1; max-width: 1400px; margin: 0 auto; min-height: calc(100vh - 60px); }
|
||||||
.sidebar { width: 180px; background: white; padding: 16px; box-shadow: 2px 0 8px rgba(0,0,0,0.05); }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
.content-area { flex: 1; padding: 24px; overflow-y: auto; }
|
.content-area { flex: 1; padding: 24px; overflow-y: auto; }
|
||||||
.card { background: white; border-radius: 12px; padding: 24px; margin-bottom: 24px; box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
|
.card { background: white; border-radius: 12px; padding: 24px; margin-bottom: 24px; box-shadow: 0 2px 8px rgba(0,0,0,0.08); overflow-x: auto; }
|
||||||
.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 { 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; }
|
||||||
|
|
||||||
|
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
|
||||||
|
.page-title { font-size: 24px; font-weight: 700; color: #303133; display: flex; align-items: center; gap: 8px; }
|
||||||
|
.controls { display: flex; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; align-items: center; }
|
||||||
|
.log-container { max-height: 600px; overflow-y: auto; background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 8px; }
|
||||||
|
.log-container pre { margin: 0; padding: 16px; white-space: pre-wrap; word-wrap: break-word; font-size: 13px; line-height: 1.6; color: #303133; }
|
||||||
|
|
||||||
@media (max-width: 768px) {
|
@media (max-width: 768px) {
|
||||||
.sidebar { display: none; }
|
|
||||||
.mobile-nav { display: flex; }
|
|
||||||
.content-area { padding: 16px; padding-bottom: 80px; }
|
.content-area { padding: 16px; padding-bottom: 80px; }
|
||||||
}
|
.card { padding: 16px; }
|
||||||
|
.controls { flex-direction: column; align-items: stretch; }
|
||||||
/* logs.html 移动端优化 */
|
.controls .el-select, .controls .el-date-picker { width: 100% !important; }
|
||||||
@media (max-width: 768px) {
|
.log-container { max-height: calc(100vh - 250px); }
|
||||||
.log-controls { flex-direction: column; gap: 8px; }
|
.log-container pre { font-size: 11px; padding: 12px; }
|
||||||
.log-controls .el-select, .log-controls .el-date-picker { width: 100% !important; }
|
|
||||||
.el-card { margin: 0 -16px; border-radius: 0; min-height: calc(100vh - 180px); }
|
|
||||||
.el-card .el-card__body { padding: 12px; }
|
|
||||||
pre { font-size: 11px; line-height: 1.4; }
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script src="navigation-component.js"></script>
|
<script src="navigation-component.js"></script>
|
||||||
|
|
||||||
<script src="navbar-component.js"></script>
|
<script src="navbar-component.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app">
|
<div id="app">
|
||||||
<navbar-component
|
<navbar-component title="系统日志" :username="currentUser.username" :is-admin="isAdmin" @logout="handleLogout"></navbar-component>
|
||||||
title="系统日志"
|
<navigation-component current-page="logs" :is-admin="isAdmin" @navigate="redirectToPage"></navigation-component>
|
||||||
:username="currentUser.username"
|
<div class="main-content">
|
||||||
:is-admin="isAdmin"
|
|
||||||
@logout="handleLogout"
|
|
||||||
></navbar-component>
|
|
||||||
|
|
||||||
<navigation-component
|
|
||||||
current-page="logs"
|
|
||||||
:is-admin="isAdmin"
|
|
||||||
@navigate="redirectToPage"
|
|
||||||
></navigation-component>
|
|
||||||
<div class="main-content">
|
|
||||||
|
|
||||||
<main class="content-area">
|
<main class="content-area">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<h2 style="font-size: 24px; font-weight: 600; margin-bottom: 24px;">📄 系统日志</h2>
|
<div class="page-header">
|
||||||
<div style="display: flex; gap: 16px; margin-bottom: 24px; flex-wrap: wrap;">
|
<h2 class="page-title">📄 系统日志</h2>
|
||||||
<el-select v-model="logType" placeholder="日志类型" size="default" style="width: 180px;">
|
</div>
|
||||||
|
<div class="controls">
|
||||||
|
<el-select v-model="logType" placeholder="日志类型" style="width: 180px;">
|
||||||
<el-option label="创作日志" value="creator"></el-option>
|
<el-option label="创作日志" value="creator"></el-option>
|
||||||
<el-option label="优化日志" value="optimizer"></el-option>
|
<el-option label="优化日志" value="optimizer"></el-option>
|
||||||
<el-option label="收集日志" value="collector"></el-option>
|
<el-option label="收集日志" value="collector"></el-option>
|
||||||
</el-select>
|
</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-date-picker v-model="logDate" type="date" placeholder="选择日期" format="YYYY-MM-DD" value-format="YYYY-MM-DD"></el-date-picker>
|
||||||
<el-button type="primary" @click="fetchLogs" :loading="loadingLogs">加载日志</el-button>
|
<el-button type="primary" @click="fetchLogs" :loading="loadingLogs">加载日志</el-button>
|
||||||
</div>
|
</div>
|
||||||
<el-card v-if="logContent" ref="logContainer" class="font-mono text-sm bg-gray-50" style="max-height: 600px; overflow-y: auto; background: #f9fafb; border: 1px solid #e5e7eb;"><pre style="margin: 0; white-space: pre-wrap; word-wrap: break-word;">{{ logContent }}</pre></el-card>
|
<div v-if="logContent" class="log-container">
|
||||||
<el-empty v-else description="请先选择类型和日期,然后点击加载"></el-empty>
|
<pre>{{ logContent }}</pre>
|
||||||
|
</div>
|
||||||
|
<el-empty v-else description="请选择类型和日期,点击加载"></el-empty>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<script src="vue.global.prod.js"></script>
|
<script src="vue.global.prod.js"></script>
|
||||||
<script src="element-plus.full.js"></script>
|
<script src="element-plus.full.js"></script>
|
||||||
<script>
|
<script>
|
||||||
const LogsApp = {
|
const LogsApp = {
|
||||||
data() {
|
data() {
|
||||||
const today = new Date().toISOString().split('T')[0]; // YYYY-MM-DD
|
const today = new Date().toISOString().split('T')[0];
|
||||||
return {
|
return {
|
||||||
isLoggedIn: false,
|
isLoggedIn: false, isAdmin: false, currentUser: { username: '' },
|
||||||
isAdmin: false,
|
logType: 'creator', logDate: today, logContent: '', loadingLogs: false
|
||||||
currentUser: { username: '' },
|
}
|
||||||
logType: 'creator',
|
},
|
||||||
logDate: today,
|
|
||||||
logContent: '',
|
|
||||||
loadingLogs: false
|
|
||||||
} },
|
|
||||||
methods: {
|
methods: {
|
||||||
async fetchLogs() {
|
async fetchLogs() {
|
||||||
// 验证输入
|
if (!this.logType || !this.logDate) { this.$message.warning('请选择日志类型和日期'); return; }
|
||||||
if (!this.logType || !this.logDate) {
|
|
||||||
this.$message.warning('请选择日志类型和日期');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.loadingLogs = true;
|
this.loadingLogs = true;
|
||||||
try {
|
try {
|
||||||
const token = localStorage.getItem('authToken');
|
const token = localStorage.getItem('authToken');
|
||||||
|
if (!token) { this.$message.error('请先登录'); return; }
|
||||||
const response = await fetch(`/api/logs?type=${encodeURIComponent(this.logType)}&date=${encodeURIComponent(this.logDate)}`, {
|
const response = await fetch(`/api/logs?type=${encodeURIComponent(this.logType)}&date=${encodeURIComponent(this.logDate)}`, {
|
||||||
headers: { 'Authorization': 'Bearer ' + token }
|
headers: { 'Authorization': 'Bearer ' + token }
|
||||||
});
|
});
|
||||||
|
if (!response.ok) { const errorData = await response.json().catch(() => ({})); throw new Error(errorData.detail || `请求失败: ${response.status}`); }
|
||||||
if (!response.ok) {
|
|
||||||
const errorData = await response.json().catch(() => ({}));
|
|
||||||
throw new Error(errorData.detail || `请求失败: ${response.status}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
// 后端返回: { type, date, content }
|
|
||||||
this.logContent = `日志类型:${data.type}\n日期:${data.date}\n\n${data.content || '(日志文件为空)'}`;
|
this.logContent = `日志类型:${data.type}\n日期:${data.date}\n\n${data.content || '(日志文件为空)'}`;
|
||||||
this.$message.success('日志加载成功');
|
this.$message.success('日志加载成功');
|
||||||
this.$nextTick(() => {
|
|
||||||
const container = this.$refs.logContainer;
|
|
||||||
if (container && container.$el) {
|
|
||||||
container.$el.scrollTop = container.$el.scrollHeight;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取日志失败:', error);
|
console.error('获取日志失败:', error);
|
||||||
this.$message.error(`获取日志失败: ${error.message}`);
|
this.$message.error(`获取日志失败: ${error.message}`);
|
||||||
this.logContent = '';
|
this.logContent = '';
|
||||||
} finally {
|
} finally { this.loadingLogs = false; }
|
||||||
this.loadingLogs = false;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
handleLogout() { localStorage.removeItem('authToken'); localStorage.removeItem('userRole'); localStorage.removeItem('currentUser'); window.location.href = '/login.html'; },
|
handleLogout() { localStorage.removeItem('authToken'); localStorage.removeItem('userRole'); localStorage.removeItem('currentUser'); window.location.href = '/login.html'; },
|
||||||
redirectToPage(page) { window.location.href = page.startsWith('/') ? page : '/' + page; },
|
redirectToPage(page) { window.location.href = page.startsWith('/') ? page : '/' + page; },
|
||||||
@@ -143,29 +106,13 @@
|
|||||||
.catch(() => { localStorage.removeItem('authToken'); localStorage.removeItem('userRole'); localStorage.removeItem('currentUser'); window.location.href = '/login.html'; });
|
.catch(() => { localStorage.removeItem('authToken'); localStorage.removeItem('userRole'); localStorage.removeItem('currentUser'); window.location.href = '/login.html'; });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() { this.checkAuth(); }
|
||||||
this.checkAuth();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
const app = Vue.createApp(LogsApp);
|
const app = Vue.createApp(LogsApp);
|
||||||
app.use(ElementPlus);
|
app.use(ElementPlus);
|
||||||
// 安装导航组件
|
if (window.installNavbar) { window.installNavbar(app); }
|
||||||
if (window.installNavbar) { window.installNavbar(app); }
|
if (window.installNavigation) { window.installNavigation(app); } else if (window.NavigationComponent) { app.component("navigation-component", window.NavigationComponent); }
|
||||||
// 安装导航组件
|
app.mount('#app');
|
||||||
if (window.installNavigation) { window.installNavigation(app); } else if (window.NavigationComponent) { app.component("navigation-component", window.NavigationComponent); }
|
|
||||||
app.mount('#app');
|
|
||||||
|
|
||||||
// 调试代码:检查导航组件状态
|
|
||||||
setTimeout(() => {
|
|
||||||
const hasNav = !!document.querySelector('.navigation-wrapper');
|
|
||||||
const hasSidebar = !!document.querySelector('.navigation-wrapper .sidebar');
|
|
||||||
console.log('[调试] 导航wrapper:', hasNav);
|
|
||||||
console.log('[调试] 侧边栏:', hasSidebar);
|
|
||||||
if (!hasNav) {
|
|
||||||
console.error('[调试] 导航组件未渲染!window.NavigationComponent=', !!window.NavigationComponent);
|
|
||||||
console.error('[调试] app实例是否存在组件注册?', Vue && Vue.app && Vue.app._context.components['navigation-component']);
|
|
||||||
}
|
|
||||||
}, 100);
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -7,22 +7,26 @@
|
|||||||
<link rel="stylesheet" href="element-plus.css">
|
<link rel="stylesheet" href="element-plus.css">
|
||||||
<style>
|
<style>
|
||||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||||
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background: #f5f7fa; }
|
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background: #f5f7fa; color: #303133; }
|
||||||
.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 { 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-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-title { font-size: 20px; font-weight: 600; }
|
||||||
.navbar-user { display: flex; align-items: center; gap: 16px; }
|
.navbar-user { display: flex; align-items: center; gap: 16px; }
|
||||||
.user-info { display: flex; align-items: center; gap: 8px; }
|
.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; }
|
.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; }
|
.main-content { display: flex; flex: 1; max-width: 1400px; margin: 0 auto; min-height: calc(100vh - 60px); }
|
||||||
.sidebar { width: 180px; background: white; padding: 12px; box-shadow: 2px 0 8px rgba(0,0,0,0.05); }
|
|
||||||
.content-area { flex: 1; padding: 24px; overflow-y: auto; }
|
.content-area { flex: 1; padding: 24px; overflow-y: auto; }
|
||||||
.card { background: white; border-radius: 12px; padding: 24px; margin-bottom: 24px; box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
|
.card { background: white; border-radius: 12px; padding: 24px; margin-bottom: 24px; box-shadow: 0 2px 8px rgba(0,0,0,0.08); overflow-x: auto; }
|
||||||
.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 { 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; }
|
||||||
.task-card { border: 1px solid #ebeef5; border-radius: 12px; padding: 16px; margin-bottom: 12px; transition: all 0.3s; }
|
|
||||||
.task-card:hover { border-color: #409eff; box-shadow: 0 2px 12px rgba(64,158,255,0.15); }
|
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
|
||||||
.task-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
|
.page-title { font-size: 24px; font-weight: 700; color: #303133; display: flex; align-items: center; gap: 8px; }
|
||||||
.task-id { font-size: 13px; color: #909399; }
|
.toolbar { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
|
||||||
|
|
||||||
|
.task-card { border: 1px solid #ebeef5; border-radius: 12px; padding: 16px; margin-bottom: 12px; transition: all 0.3s; background: #fff; }
|
||||||
|
.task-card:hover { border-color: #409eff; box-shadow: 0 2px 12px rgba(64,158,255,0.12); transform: translateY(-1px); }
|
||||||
|
.task-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; flex-wrap: wrap; gap: 8px; }
|
||||||
|
.task-id { font-size: 13px; color: #909399; font-family: monospace; }
|
||||||
.task-stage { display: inline-block; padding: 4px 12px; border-radius: 16px; font-size: 12px; font-weight: 500; }
|
.task-stage { display: inline-block; padding: 4px 12px; border-radius: 16px; font-size: 12px; font-weight: 500; }
|
||||||
.stage-creator { background: #f0f9eb; color: #67c23a; }
|
.stage-creator { background: #f0f9eb; color: #67c23a; }
|
||||||
.stage-optimize { background: #fdf6ec; color: #e6a23c; }
|
.stage-optimize { background: #fdf6ec; color: #e6a23c; }
|
||||||
@@ -31,17 +35,22 @@
|
|||||||
.task-body { margin-bottom: 12px; }
|
.task-body { margin-bottom: 12px; }
|
||||||
.task-message { font-size: 14px; color: #606266; margin-bottom: 8px; }
|
.task-message { font-size: 14px; color: #606266; margin-bottom: 8px; }
|
||||||
.task-meta { display: flex; gap: 16px; font-size: 13px; color: #909399; flex-wrap: wrap; }
|
.task-meta { display: flex; gap: 16px; font-size: 13px; color: #909399; flex-wrap: wrap; }
|
||||||
@media (max-width: 768px) {
|
|
||||||
.sidebar { display: none; }
|
|
||||||
.mobile-nav { display: flex; }
|
|
||||||
.content-area { padding: 16px; padding-bottom: 80px; }
|
|
||||||
}
|
|
||||||
.status-badge { display: inline-flex; align-items: center; gap: 4px; padding: 4px 12px; border-radius: 16px; font-size: 13px; }
|
.status-badge { display: inline-flex; align-items: center; gap: 4px; padding: 4px 12px; border-radius: 16px; font-size: 13px; }
|
||||||
.status-pending { background: #f4f4f5; color: #909399; }
|
.status-pending { background: #f4f4f5; color: #909399; }
|
||||||
.status-running { background: #f0f9eb; color: #67c23a; }
|
.status-running { background: #f0f9eb; color: #67c23a; }
|
||||||
.status-completed { background: #ecf5ff; color: #409eff; }
|
.status-completed { background: #ecf5ff; color: #409eff; }
|
||||||
.status-failed { background: #fef0f0; color: #f56c6c; }
|
.status-failed { background: #fef0f0; color: #f56c6c; }
|
||||||
.status-cancelled { background: #f4f4f5; color: #c0c4cc; }
|
.status-cancelled { background: #f4f4f5; color: #c0c4cc; }
|
||||||
|
.error-box { margin-top: 8px; padding: 8px 12px; background: #fef0f0; border-radius: 6px; font-size: 13px; color: #f56c6c; border-left: 3px solid #f56c6c; }
|
||||||
|
|
||||||
|
.task-card-list-mobile { display: none; }
|
||||||
|
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.content-area { padding: 16px; padding-bottom: 80px; }
|
||||||
|
.card { padding: 16px; }
|
||||||
|
.task-table { display: none; }
|
||||||
|
.task-card-list-mobile { display: block; }
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
<script src="navigation-component.js"></script>
|
<script src="navigation-component.js"></script>
|
||||||
<script src="navbar-component.js"></script>
|
<script src="navbar-component.js"></script>
|
||||||
@@ -52,27 +61,30 @@
|
|||||||
<navigation-component current-page="tasks" :is-admin="isAdmin" @navigate="redirectToPage"></navigation-component>
|
<navigation-component current-page="tasks" :is-admin="isAdmin" @navigate="redirectToPage"></navigation-component>
|
||||||
<div class="main-content">
|
<div class="main-content">
|
||||||
<main class="content-area">
|
<main class="content-area">
|
||||||
<h2 style="font-size: 24px; font-weight: 700; margin-bottom: 24px; color: #303133;">🚀 创作任务</h2>
|
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div style="display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px;">
|
<div class="page-header">
|
||||||
<el-button-group>
|
<h2 class="page-title">🚀 创作任务</h2>
|
||||||
<el-button :type="filterStatus === '' ? 'primary' : ''" @click="filterStatus = ''; loadTasks()">全部</el-button>
|
<div class="toolbar">
|
||||||
<el-button :type="filterStatus === 'running' ? 'primary' : ''" @click="filterStatus = 'running'; loadTasks()">进行中</el-button>
|
<el-button-group>
|
||||||
<el-button :type="filterStatus === 'pending' ? 'primary' : ''" @click="filterStatus = 'pending'; loadTasks()">等待中</el-button>
|
<el-button :type="filterStatus === '' ? 'primary' : ''" @click="filterStatus = ''; loadTasks()">全部</el-button>
|
||||||
<el-button :type="filterStatus === 'completed' ? 'primary' : ''" @click="filterStatus = 'completed'; loadTasks()">已完成</el-button>
|
<el-button :type="filterStatus === 'running' ? 'primary' : ''" @click="filterStatus = 'running'; loadTasks()">进行中</el-button>
|
||||||
<el-button :type="filterStatus === 'failed' ? 'primary' : ''" @click="filterStatus = 'failed'; loadTasks()">失败</el-button>
|
<el-button :type="filterStatus === 'pending' ? 'primary' : ''" @click="filterStatus = 'pending'; loadTasks()">等待中</el-button>
|
||||||
</el-button-group>
|
<el-button :type="filterStatus === 'completed' ? 'primary' : ''" @click="filterStatus = 'completed'; loadTasks()">已完成</el-button>
|
||||||
<el-button @click="loadTasks">🔄 刷新</el-button>
|
<el-button :type="filterStatus === 'failed' ? 'primary' : ''" @click="filterStatus = 'failed'; loadTasks()">失败</el-button>
|
||||||
|
</el-button-group>
|
||||||
|
<el-button @click="loadTasks">🔄 刷新</el-button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="loading" style="text-align: center; padding: 40px;">加载中...</div>
|
<div v-if="loading" style="text-align: center; padding: 40px; color: #909399;">加载中...</div>
|
||||||
<div v-else-if="tasks.length === 0" style="text-align: center; padding: 40px; color: #909399;">
|
<div v-else-if="tasks.length === 0" style="text-align: center; padding: 60px 20px; color: #909399;">
|
||||||
<div style="font-size: 48px; margin-bottom: 16px;">📋</div>
|
<div style="font-size: 56px; margin-bottom: 16px;">📋</div>
|
||||||
<div>暂无任务</div>
|
<div style="font-size: 16px;">暂无任务</div>
|
||||||
|
<div style="margin-top: 12px; font-size: 14px;">前往 <a href="/topics.html" style="color: #409eff;">选题管理</a> 创建新任务</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-else>
|
<div v-else>
|
||||||
<div v-for="task in tasks" :key="task.task_id" class="task-card">
|
<div v-for="task in tasks" :key="task.task_id" class="task-card">
|
||||||
<div class="task-header">
|
<div class="task-header">
|
||||||
<div style="display: flex; align-items: center; gap: 12px;">
|
<div style="display: flex; align-items: center; gap: 12px; flex-wrap: wrap;">
|
||||||
<span class="task-id">#{{ task.task_id }}</span>
|
<span class="task-id">#{{ task.task_id }}</span>
|
||||||
<span class="status-badge" :class="'status-' + task.status">{{ getStatusLabel(task.status) }}</span>
|
<span class="status-badge" :class="'status-' + task.status">{{ getStatusLabel(task.status) }}</span>
|
||||||
<span class="task-stage" :class="'stage-' + task.stage">{{ getStageLabel(task.stage) }}</span>
|
<span class="task-stage" :class="'stage-' + task.stage">{{ getStageLabel(task.stage) }}</span>
|
||||||
@@ -80,7 +92,7 @@
|
|||||||
<div style="display: flex; gap: 8px;">
|
<div style="display: flex; gap: 8px;">
|
||||||
<el-button v-if="task.status === 'running'" size="small" type="danger" @click="cancelTask(task.task_id)">取消</el-button>
|
<el-button v-if="task.status === 'running'" size="small" type="danger" @click="cancelTask(task.task_id)">取消</el-button>
|
||||||
<el-button v-if="task.status === 'failed'" size="small" type="primary" @click="retryTask(task)">重试</el-button>
|
<el-button v-if="task.status === 'failed'" size="small" type="primary" @click="retryTask(task)">重试</el-button>
|
||||||
<el-button size="small" type="info" @click="viewTaskDetail(task)">详情</el-button>
|
<el-button size="small" @click="viewTaskDetail(task)">详情</el-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="task-body">
|
<div class="task-body">
|
||||||
@@ -96,9 +108,7 @@
|
|||||||
<span v-if="task.duration">耗时: {{ task.duration }}秒</span>
|
<span v-if="task.duration">耗时: {{ task.duration }}秒</span>
|
||||||
<span>创建人: {{ task.created_by }}</span>
|
<span>创建人: {{ task.created_by }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="task.error_msg" style="margin-top: 8px; padding: 8px; background: #fef0f0; border-radius: 4px; font-size: 13px; color: #f56c6c;">
|
<div v-if="task.error_msg" class="error-box">错误: {{ task.error_msg }}</div>
|
||||||
错误: {{ task.error_msg }}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -135,52 +145,42 @@
|
|||||||
const TasksApp = {
|
const TasksApp = {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
currentUser: { username: '' },
|
currentUser: { username: '' }, isAdmin: false, isLoggedIn: false,
|
||||||
isAdmin: false,
|
tasks: [], loading: false, filterStatus: '',
|
||||||
isLoggedIn: false,
|
showDetailDialog: false, detailTask: null
|
||||||
tasks: [],
|
|
||||||
loading: false,
|
|
||||||
filterStatus: '',
|
|
||||||
showDetailDialog: false,
|
|
||||||
detailTask: null
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
getToken() { return localStorage.getItem('authToken'); },
|
||||||
|
async api(url, opts = {}) {
|
||||||
|
const token = this.getToken();
|
||||||
|
if (!token) { this.$message.error('请先登录'); 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();
|
||||||
|
},
|
||||||
handleLogout() { localStorage.removeItem('authToken'); localStorage.removeItem('userRole'); localStorage.removeItem('currentUser'); window.location.href = '/login.html'; },
|
handleLogout() { localStorage.removeItem('authToken'); localStorage.removeItem('userRole'); localStorage.removeItem('currentUser'); window.location.href = '/login.html'; },
|
||||||
redirectToPage(page) { window.location.href = page.startsWith('/') ? page : '/' + page; },
|
redirectToPage(page) { window.location.href = page.startsWith('/') ? page : '/' + page; },
|
||||||
checkAuth() {
|
checkAuth() {
|
||||||
const token = localStorage.getItem('authToken');
|
const token = this.getToken();
|
||||||
if (!token) { window.location.href = '/login.html'; return; }
|
if (!token) { window.location.href = '/login.html'; return; }
|
||||||
fetch('/api/auth/me', { headers: { 'Authorization': 'Bearer ' + token } })
|
fetch('/api/auth/me', { headers: { 'Authorization': 'Bearer ' + token } })
|
||||||
.then(r => r.ok ? r.json() : Promise.reject())
|
.then(r => r.ok ? r.json() : Promise.reject())
|
||||||
.then(data => {
|
.then(data => { this.currentUser = data.user; this.isAdmin = data.user.role === 'admin'; this.isLoggedIn = true; this.loadTasks(); })
|
||||||
this.currentUser = data.user;
|
|
||||||
this.isAdmin = data.user.role === 'admin';
|
|
||||||
this.isLoggedIn = true;
|
|
||||||
this.loadTasks();
|
|
||||||
})
|
|
||||||
.catch(() => { localStorage.removeItem('authToken'); localStorage.removeItem('userRole'); localStorage.removeItem('currentUser'); window.location.href = '/login.html'; });
|
.catch(() => { localStorage.removeItem('authToken'); localStorage.removeItem('userRole'); localStorage.removeItem('currentUser'); window.location.href = '/login.html'; });
|
||||||
},
|
},
|
||||||
getStatusLabel(status) {
|
getStatusLabel(status) { return { 'pending': '等待中', 'running': '进行中', 'completed': '已完成', 'failed': '失败', 'cancelled': '已取消' }[status] || status; },
|
||||||
const map = { 'pending': '等待中', 'running': '进行中', 'completed': '已完成', 'failed': '失败', 'cancelled': '已取消' };
|
getStageLabel(stage) { return { 'creator': '创作', 'optimize': '优化', 'review': '审查', 'publish': '发布' }[stage] || stage; },
|
||||||
return map[status] || status;
|
|
||||||
},
|
|
||||||
getStageLabel(stage) {
|
|
||||||
const map = { 'creator': '创作', 'optimize': '优化', 'review': '审查', 'publish': '发布' };
|
|
||||||
return map[stage] || stage;
|
|
||||||
},
|
|
||||||
formatDate(dateStr) {
|
formatDate(dateStr) {
|
||||||
if (!dateStr) return '-';
|
if (!dateStr) return '-';
|
||||||
return new Date(dateStr).toLocaleString('zh-CN');
|
try { return new Date(dateStr).toLocaleString('zh-CN'); } catch (e) { return dateStr; }
|
||||||
},
|
},
|
||||||
async loadTasks() {
|
async loadTasks() {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
try {
|
try {
|
||||||
const token = localStorage.getItem('authToken');
|
|
||||||
let url = '/api/tasks?limit=50';
|
let url = '/api/tasks?limit=50';
|
||||||
if (this.filterStatus) url += '&status=' + this.filterStatus;
|
if (this.filterStatus) url += '&status=' + this.filterStatus;
|
||||||
const res = await fetch(url, { headers: { 'Authorization': 'Bearer ' + token } });
|
this.tasks = await this.api(url) || [];
|
||||||
if (res.ok) this.tasks = await res.json();
|
|
||||||
} catch (e) { console.error(e); }
|
} catch (e) { console.error(e); }
|
||||||
finally { this.loading = false; }
|
finally { this.loading = false; }
|
||||||
},
|
},
|
||||||
@@ -188,18 +188,21 @@ const TasksApp = {
|
|||||||
async cancelTask(taskId) {
|
async cancelTask(taskId) {
|
||||||
try {
|
try {
|
||||||
await this.$confirm('确定取消该任务?', '提示', { type: 'warning' });
|
await this.$confirm('确定取消该任务?', '提示', { type: 'warning' });
|
||||||
const token = localStorage.getItem('authToken');
|
await this.api('/api/tasks/' + taskId, { method: 'DELETE' });
|
||||||
const res = await fetch('/api/tasks/' + taskId, { method: 'DELETE', headers: { 'Authorization': 'Bearer ' + token } });
|
this.$message.success('任务已取消');
|
||||||
if (res.ok) { this.$message.success('任务已取消'); this.loadTasks(); }
|
this.loadTasks();
|
||||||
} catch (e) { if (e !== 'cancel') this.$message.error(e.message || '操作失败'); }
|
} catch (e) { if (e !== 'cancel') this.$message.error(e.message || '操作失败'); }
|
||||||
},
|
},
|
||||||
retryTask(task) {
|
async retryTask(task) {
|
||||||
this.$message.info('重试功能开发中...');
|
if (!task.topic_id) { this.$message.warning('该任务无关联选题,无法重试'); return; }
|
||||||
|
try {
|
||||||
|
await this.api('/api/tasks/run-creator?topic_id=' + task.topic_id, { method: 'POST' });
|
||||||
|
this.$message.success('已重新提交创作任务');
|
||||||
|
this.loadTasks();
|
||||||
|
} catch (e) { this.$message.error('重试失败: ' + e.message); }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() { this.checkAuth(); }
|
||||||
this.checkAuth();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
const app = Vue.createApp(TasksApp);
|
const app = Vue.createApp(TasksApp);
|
||||||
app.use(ElementPlus);
|
app.use(ElementPlus);
|
||||||
|
|||||||
+185
-521
@@ -4,48 +4,47 @@
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>宇之然内容创作平台 - 选题管理</title>
|
<title>宇之然内容创作平台 - 选题管理</title>
|
||||||
<link rel="stylesheet" href="element-plus.css">
|
<link rel="stylesheet" href="element-plus.css">
|
||||||
<style>
|
<style>
|
||||||
.preview-iframe { box-sizing: border-box; }
|
|
||||||
|
|
||||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||||
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background: #f5f7fa; }
|
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background: #f5f7fa; color: #303133; }
|
||||||
.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 { 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-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-title { font-size: 20px; font-weight: 600; }
|
||||||
.navbar-user { display: flex; align-items: center; gap: 16px; }
|
.navbar-user { display: flex; align-items: center; gap: 16px; }
|
||||||
.user-info { display: flex; align-items: center; gap: 8px; }
|
.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; }
|
.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; }
|
.main-content { display: flex; flex: 1; max-width: 1400px; margin: 0 auto; min-height: calc(100vh - 60px); }
|
||||||
.sidebar { width: 180px; background: white; padding: 12px; box-shadow: 2px 0 8px rgba(0,0,0,0.05); }
|
.content-area { flex: 1; padding: 24px; overflow-y: auto; }
|
||||||
|
.card { background: white; border-radius: 12px; padding: 24px; margin-bottom: 24px; box-shadow: 0 2px 8px rgba(0,0,0,0.08); overflow-x: auto; }
|
||||||
|
.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; }
|
||||||
|
|
||||||
|
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
|
||||||
|
.page-title { font-size: 24px; font-weight: 700; color: #303133; display: flex; align-items: center; gap: 8px; }
|
||||||
|
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
|
||||||
|
.filter-bar { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
|
||||||
|
.selected-count { color: #909399; font-size: 14px; margin-left: auto; }
|
||||||
|
|
||||||
|
|
||||||
.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-badge { display: inline-flex; align-items: center; gap: 4px; }
|
||||||
.status-dot { width: 6px; height: 6px; border-radius: 50%; }
|
.status-dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
|
||||||
.status-dot.pending { background: #E6A23C; }
|
.status-dot.pending { background: #E6A23C; }
|
||||||
.status-dot.review { background: #F56C6C; }
|
.status-dot.review { background: #F56C6C; }
|
||||||
.status-dot.ready { background: #67C23A; }
|
.status-dot.ready { background: #67C23A; }
|
||||||
.status-dot.published { background: #409EFF; }
|
.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; }
|
|
||||||
|
|
||||||
|
|
||||||
@media (max-width: 768px) {
|
|
||||||
.sidebar { display: none; }
|
|
||||||
.mobile-nav { display: flex; }
|
|
||||||
.content-area { padding: 12px; padding-bottom: 80px; }
|
|
||||||
}
|
|
||||||
|
|
||||||
.topic-card-list { display: none; }
|
.topic-card-list { display: none; }
|
||||||
/* 移动端卡片布局 */
|
|
||||||
|
.preview-iframe { box-sizing: border-box; }
|
||||||
|
.preview-dialog-custom.el-dialog { max-height: calc(100vh - 90px); overflow: hidden; display: flex; flex-direction: column; margin-top: 0 !important; }
|
||||||
|
.preview-dialog-custom.el-dialog .el-dialog__header { padding: 8px 12px; margin: 0; flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; }
|
||||||
|
.preview-dialog-custom.el-dialog .el-dialog__body { padding: 12px; overflow: hidden; }
|
||||||
|
.preview-dialog-custom.el-dialog .el-dialog__footer { flex-shrink: 0; padding: 8px 12px; }
|
||||||
|
|
||||||
@media (max-width: 768px) {
|
@media (max-width: 768px) {
|
||||||
.el-table { font-size: 12px; display: none; }
|
.content-area { padding: 12px; padding-bottom: 80px; }
|
||||||
.el-table .el-button { padding: 4px 8px; font-size: 11px; min-height: auto; }
|
.card { padding: 16px; }
|
||||||
.el-table .cell { padding: 0 4px; }
|
.el-table { display: none; }
|
||||||
.el-table .el-table__cell { padding: 6px 0; }
|
.topic-card-list { display: block; }
|
||||||
.topic-card-list { display: block; margin: 0 -16px; }
|
|
||||||
.topic-card {
|
.topic-card {
|
||||||
background: white;
|
background: white;
|
||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
@@ -53,166 +52,99 @@
|
|||||||
margin-bottom: 12px;
|
margin-bottom: 12px;
|
||||||
box-shadow: 0 2px 8px rgba(0,0,0,0.08);
|
box-shadow: 0 2px 8px rgba(0,0,0,0.08);
|
||||||
}
|
}
|
||||||
.topic-card-header {
|
.topic-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
|
||||||
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-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-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
|
||||||
.topic-card-meta {
|
.topic-card-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; font-size: 12px; color: #606266; margin-bottom: 12px; }
|
||||||
display: grid;
|
.topic-card-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; padding-top: 12px; border-top: 1px solid #ebeef5; }
|
||||||
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; }
|
.topic-card-actions .el-button { flex: 1; min-width: 60px; }
|
||||||
.mobile-nav { display: flex; }
|
.preview-iframe { max-height: calc(100vh - 250px) !important; }
|
||||||
}
|
}
|
||||||
|
|
||||||
.preview-iframe { box-sizing: border-box; }
|
|
||||||
/* 预览弹窗响应式高度 */
|
|
||||||
@media (min-width: 769px) {
|
@media (min-width: 769px) {
|
||||||
.preview-iframe { max-height: calc(100vh - 100px) !important; }
|
.preview-iframe { max-height: calc(100vh - 100px) !important; }
|
||||||
}
|
}
|
||||||
@media (max-width: 768px) {
|
</style>
|
||||||
.preview-iframe { max-height: calc(100vh - 250px) !important; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 预览弹窗自定义高度(非全屏时) */
|
|
||||||
.preview-dialog-custom.el-dialog {
|
|
||||||
max-height: calc(100vh - 90px) !important;
|
|
||||||
overflow: hidden;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
margin-top: 0 !important;
|
|
||||||
}
|
|
||||||
.preview-dialog-custom.el-dialog .el-dialog__header {
|
|
||||||
padding: 8px 12px;
|
|
||||||
margin: 0;
|
|
||||||
flex-shrink: 0;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: space-between;
|
|
||||||
}
|
|
||||||
.preview-dialog-custom.el-dialog .el-dialog__body {
|
|
||||||
padding: 12px;
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
.preview-dialog-custom.el-dialog .el-dialog__footer {
|
|
||||||
flex-shrink: 0;
|
|
||||||
padding: 8px 12px;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<script src="navigation-component.js"></script>
|
<script src="navigation-component.js"></script>
|
||||||
|
|
||||||
<script src="navbar-component.js"></script>
|
<script src="navbar-component.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app">
|
<div id="app">
|
||||||
<navbar-component
|
<navbar-component title="选题管理" :username="currentUser.username" :is-admin="isAdmin" @logout="handleLogout"></navbar-component>
|
||||||
title="选题管理"
|
<navigation-component current-page="topics" :is-admin="isAdmin" @navigate="redirectToPage"></navigation-component>
|
||||||
:username="currentUser.username"
|
<div class="main-content">
|
||||||
:is-admin="isAdmin"
|
|
||||||
@logout="handleLogout"
|
|
||||||
></navbar-component>
|
|
||||||
<navigation-component
|
|
||||||
current-page="topics"
|
|
||||||
:is-admin="isAdmin"
|
|
||||||
@navigate="redirectToPage"
|
|
||||||
></navigation-component>
|
|
||||||
<div class="main-content">
|
|
||||||
<main class="content-area">
|
<main class="content-area">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<h2 style="font-size: 28px; font-weight: 700; margin-bottom: 32px; color: #303133;">📋 选题管理</h2>
|
<div class="page-header">
|
||||||
<div class="card" style="display: inline-block; min-width: fit-content; padding: 12px; margin-bottom: 24px;">
|
<h2 class="page-title">📋 选题管理</h2>
|
||||||
<div style="display: flex; gap: 8px; flex-wrap: wrap;">
|
<div class="toolbar">
|
||||||
<el-button type="primary" size="small" @click="refreshAll">🔄 批量刷新</el-button>
|
<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="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>
|
<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>
|
<span v-if="selectedTopicIds.length > 0" class="selected-count">已选 {{ selectedTopicIds.length }} 项</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div style="display: flex; gap: 8px; margin-bottom: 24px; flex-wrap: wrap;">
|
<div class="filter-bar">
|
||||||
<el-button size="large" :type="filterStatus === '' ? 'primary' : ''" @click="filterStatus = ''">全部 ({{ topics.length }})</el-button>
|
<el-button size="default" :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="default" :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="default" :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="default" :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>
|
<el-button size="default" :type="filterStatus === 'published' ? 'primary' : ''" @click="filterStatus = 'published'">已发布 ({{ statusStats.published }})</el-button>
|
||||||
</div>
|
</div>
|
||||||
<div class="card" style="width: 100%; overflow-x: auto; padding: 12px;">
|
<el-table :data="filteredTopics" stripe v-loading="loadingTable" @selection-change="selectedTopicIds = $event.map(item => item.id)">
|
||||||
<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 type="selection" width="55"></el-table-column>
|
<el-table-column prop="id" label="ID" width="70" fixed></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="title" label="标题" min-width="200"></el-table-column>
|
<el-table-column prop="field" label="领域" width="100"></el-table-column>
|
||||||
<el-table-column prop="field" label="领域" width="100"></el-table-column>
|
<el-table-column prop="status" label="状态" width="90">
|
||||||
<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>
|
||||||
<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>
|
<el-table-column prop="compliance_score" label="合规分" width="90">
|
||||||
<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>
|
||||||
<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>
|
<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="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="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="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="200" fixed="right">
|
||||||
<el-table-column label="操作" width="180" fixed="right">
|
<template #default="scope">
|
||||||
<template #default="scope">
|
<div style="display: flex; gap: 4px; flex-wrap: wrap;">
|
||||||
<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" @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="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 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 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>
|
||||||
<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">{{ 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="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>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
<div class="topic-card-list" v-if="filteredTopics && filteredTopics.length > 0">
|
||||||
|
<div v-for="topic 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">{{ 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="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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
<!-- 预览弹窗 -->
|
|
||||||
<el-dialog v-model="previewVisible" title="选题预览" width="85%" :modal-props="{ closeOnClickModal: false }" :before-close="() => previewVisible = false" class="preview-dialog-custom" :fullscreen="previewFullscreen">
|
<el-dialog v-model="previewVisible" title="选题预览" width="85%" :modal-props="{ closeOnClickModal: false }" :before-close="() => previewVisible = false" class="preview-dialog-custom" :fullscreen="previewFullscreen">
|
||||||
<div v-if="previewTopic">
|
<div v-if="previewTopic">
|
||||||
<!-- 平台切换按钮 -->
|
|
||||||
<div style="margin-bottom: 16px; display: flex; justify-content: flex-end; gap: 8px;">
|
<div style="margin-bottom: 16px; display: flex; justify-content: flex-end; gap: 8px;">
|
||||||
<el-button-group>
|
<el-button-group>
|
||||||
<el-button :type="previewPlatform === 'zhihu' ? 'primary' : 'default'" @click="previewPlatform = 'zhihu'">知乎</el-button>
|
<el-button :type="previewPlatform === 'zhihu' ? 'primary' : 'default'" @click="previewPlatform = 'zhihu'">知乎</el-button>
|
||||||
@@ -220,7 +152,6 @@
|
|||||||
<el-button :type="previewPlatform === 'xiaohongshu' ? 'primary' : 'default'" @click="previewPlatform = 'xiaohongshu'">小红书</el-button>
|
<el-button :type="previewPlatform === 'xiaohongshu' ? 'primary' : 'default'" @click="previewPlatform = 'xiaohongshu'">小红书</el-button>
|
||||||
</el-button-group>
|
</el-button-group>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div style="display:flex; justify-content:space-between; align-items:center; flex-wrap:wrap; gap:8px;">
|
<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>
|
<h2 style="margin:0; font-size:16px;">{{ previewTopic.title }}</h2>
|
||||||
<div style="display:flex; align-items:center; gap:12px; font-size:13px; color:#909399;">
|
<div style="display:flex; align-items:center; gap:12px; font-size:13px; color:#909399;">
|
||||||
@@ -228,36 +159,23 @@
|
|||||||
<span>状态:{{ getStatusLabel(previewTopic.status) }}</span>
|
<span>状态:{{ getStatusLabel(previewTopic.status) }}</span>
|
||||||
<span v-if="previewTopic.generated_at">创作:{{ formatDate(previewTopic.generated_at) }}</span>
|
<span v-if="previewTopic.generated_at">创作:{{ formatDate(previewTopic.generated_at) }}</span>
|
||||||
<span v-if="previewTopic.published_at">发布:{{ formatDate(previewTopic.published_at) }}</span>
|
<span v-if="previewTopic.published_at">发布:{{ formatDate(previewTopic.published_at) }}</span>
|
||||||
<el-button size="small" @click="togglePreviewFullscreen">
|
<el-button size="small" @click="togglePreviewFullscreen">{{ previewFullscreen ? '退出全屏' : '全屏' }}</el-button>
|
||||||
{{ previewFullscreen ? '退出全屏' : '全屏' }}
|
|
||||||
</el-button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 预览内容使用 iframe 隔离样式 -->
|
|
||||||
<div style="max-width: 1000px; margin: 0 auto; width: 100%; height: 100%; display: flex; flex-direction: column;">
|
<div style="max-width: 1000px; margin: 0 auto; width: 100%; height: 100%; display: flex; flex-direction: column;">
|
||||||
<iframe :srcdoc="currentPreviewHtml"
|
<iframe :srcdoc="currentPreviewHtml" class="preview-iframe" style="flex:1; min-height:500px; border:1px solid #ebeef5; border-radius:8px; background:#fff; overflow:auto; padding:0; width:100%;" sandbox></iframe>
|
||||||
class="preview-iframe"
|
|
||||||
style="flex: 1; min-height: 500px; border:1px solid #ebeef5; border-radius:8px; background:#fff; overflow:auto; padding: 0 0; width: 100%;"
|
|
||||||
sandbox>
|
|
||||||
</iframe>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<div style="display:flex; justify-content:space-between; align-items:center; width:100%; font-size:14px; color:#909399;">
|
<div style="display:flex; justify-content:space-between; align-items:center; width:100%; font-size:14px; color:#909399;">
|
||||||
<div class="preview-info">
|
<div>
|
||||||
<span>创建:{{ formatDate(previewTopic.created_at) }}</span>
|
<span>创建:{{ formatDate(previewTopic.created_at) }}</span>
|
||||||
<span style="margin: 0 8px;">|</span>
|
<span style="margin: 0 8px;">|</span>
|
||||||
<span>状态:{{ getStatusLabel(previewTopic.status) }}</span>
|
<span>状态:{{ getStatusLabel(previewTopic.status) }}</span>
|
||||||
<span v-if="previewTopic.generated_at" style="margin-left:8px;">
|
<span v-if="previewTopic.generated_at" style="margin-left:8px;">创作:{{ formatDate(previewTopic.generated_at) }}</span>
|
||||||
创作:{{ formatDate(previewTopic.generated_at) }}
|
<span v-if="previewTopic.published_at" style="margin-left:8px;">发布:{{ formatDate(previewTopic.published_at) }}</span>
|
||||||
</span>
|
|
||||||
<span v-if="previewTopic.published_at" style="margin-left:8px;">
|
|
||||||
发布:{{ formatDate(previewTopic.published_at) }}
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="dialog-actions">
|
<div>
|
||||||
<el-button @click="previewVisible = false">关闭</el-button>
|
<el-button @click="previewVisible = false">关闭</el-button>
|
||||||
<el-button type="primary" @click="copyContent(previewPlatform)">复制并发布到{{ platformName(previewPlatform) }}</el-button>
|
<el-button type="primary" @click="copyContent(previewPlatform)">复制并发布到{{ platformName(previewPlatform) }}</el-button>
|
||||||
</div>
|
</div>
|
||||||
@@ -267,52 +185,32 @@
|
|||||||
</div>
|
</div>
|
||||||
<script src="vue.global.prod.js"></script>
|
<script src="vue.global.prod.js"></script>
|
||||||
<script src="element-plus.full.js"></script>
|
<script src="element-plus.full.js"></script>
|
||||||
|
<script>
|
||||||
<script>
|
|
||||||
const TopicsApp = {
|
const TopicsApp = {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
currentPage: 'topics',
|
isLoggedIn: false, isAdmin: false, currentUser: { username: '' },
|
||||||
isLoggedIn: false,
|
loadingTable: false, selectedTopicIds: [], filterStatus: '',
|
||||||
isAdmin: false,
|
|
||||||
currentUser: { username: '' },
|
|
||||||
loadingTable: false,
|
|
||||||
selectedTopicIds: [],
|
|
||||||
filterStatus: '',
|
|
||||||
stats: { total: 0, pending: 0, review: 0, ready: 0, published: 0, today: 0 },
|
stats: { total: 0, pending: 0, review: 0, ready: 0, published: 0, today: 0 },
|
||||||
topics: [],
|
topics: [],
|
||||||
previewVisible: false,
|
previewVisible: false, previewTopic: null, previewFullscreen: false,
|
||||||
previewTopic: null,
|
previewPlatform: 'zhihu', platformContents: {}
|
||||||
previewFullscreen: false,
|
|
||||||
previewPlatform: 'zhihu',
|
|
||||||
platformContents: {}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
filteredTopics() {
|
filteredTopics() {
|
||||||
if (!this.topics || !this.topics.length) { return []; }
|
if (!this.topics || !this.topics.length) return [];
|
||||||
if (!this.filterStatus) { return this.topics; }
|
if (!this.filterStatus) return this.topics;
|
||||||
const statusMap = {
|
const map = { 'pending': ['pending','待处理'], 'review': ['review','待审查'], 'ready': ['ready','待发布'], 'published': ['published','已发布'] };
|
||||||
'pending': ['pending', '待处理'],
|
const allowed = map[this.filterStatus] || [this.filterStatus];
|
||||||
'review': ['review', '待审查'],
|
|
||||||
'ready': ['ready', '待发布'],
|
|
||||||
'published': ['published', '已发布']
|
|
||||||
};
|
|
||||||
const allowed = statusMap[this.filterStatus] || [this.filterStatus];
|
|
||||||
return this.topics.filter(t => allowed.includes(t.status));
|
return this.topics.filter(t => allowed.includes(t.status));
|
||||||
},
|
},
|
||||||
statusStats() {
|
statusStats() {
|
||||||
const pending = ['pending', '待处理'];
|
const s = { total: this.topics.length, pending: 0, review: 0, ready: 0, published: 0 };
|
||||||
const review = ['review', '待审查'];
|
const map = { 'pending': s.pending, 'review': s.review, 'ready': s.ready, 'published': s.published };
|
||||||
const ready = ['ready', '待发布'];
|
const aliases = { 'pending': ['pending','待处理'], 'review': ['review','待审查'], 'ready': ['ready','待发布'], 'published': ['published','已发布'] };
|
||||||
const published = ['published', '已发布'];
|
this.topics.forEach(t => { for (const [k, v] of Object.entries(aliases)) { if (v.includes(t.status)) { map[k]++; break; } } });
|
||||||
return {
|
return s;
|
||||||
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
|
|
||||||
};
|
|
||||||
},
|
},
|
||||||
currentPreviewHtml() {
|
currentPreviewHtml() {
|
||||||
const html = this.platformContents[this.previewPlatform];
|
const html = this.platformContents[this.previewPlatform];
|
||||||
@@ -322,369 +220,135 @@ const TopicsApp = {
|
|||||||
const doc = parser.parseFromString(html, 'text/html');
|
const doc = parser.parseFromString(html, 'text/html');
|
||||||
const body = doc.body;
|
const body = doc.body;
|
||||||
if (!body) return html;
|
if (!body) return html;
|
||||||
|
|
||||||
body.querySelectorAll('script, nav, .header, footer, .interaction').forEach(el => el.remove());
|
body.querySelectorAll('script, nav, .header, footer, .interaction').forEach(el => el.remove());
|
||||||
|
const headHtml = doc.querySelector('head') ? doc.querySelector('head').innerHTML : '';
|
||||||
const head = doc.querySelector('head');
|
|
||||||
const headHtml = head ? head.innerHTML : '';
|
|
||||||
const bodyHtml = body.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>';
|
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>`;
|
return `<!DOCTYPE html><html><head>${headHtml}</head><body style="margin:0;padding:0;">${bodyHtml}${ending}</body></html>`;
|
||||||
} catch (e) {
|
} catch (e) { console.error('生成预览 HTML 失败:', e); return html; }
|
||||||
console.error('生成预览 HTML 失败:', e);
|
|
||||||
return html;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
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() {
|
async fetchTopics() {
|
||||||
this.loadingTable = true;
|
this.loadingTable = true;
|
||||||
try {
|
try {
|
||||||
const token = localStorage.getItem('authToken');
|
const data = await this.api('/api/topics');
|
||||||
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.topics = data || [];
|
||||||
this.$message.success('选题加载成功');
|
this.$message.success('选题加载成功');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取选题失败:', error);
|
console.error('获取选题失败:', error);
|
||||||
this.$message.error(`获取选题失败: ${error.message}`);
|
this.$message.error(`获取选题失败: ${error.message}`);
|
||||||
this.topics = [];
|
this.topics = [];
|
||||||
} finally {
|
} finally { this.loadingTable = false; }
|
||||||
this.loadingTable = false;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
refreshAll() { this.$message.info('执行批量刷新'); },
|
refreshAll() { this.$message.info('执行批量刷新'); },
|
||||||
async triggerGenerateSelected() {
|
async triggerGenerateSelected() {
|
||||||
if (!this.selectedTopicIds.length) return;
|
if (!this.selectedTopicIds.length) return;
|
||||||
this.$message.success('批量创作已启动');
|
let count = 0;
|
||||||
try {
|
for (const id of this.selectedTopicIds) {
|
||||||
const token = localStorage.getItem('authToken');
|
try {
|
||||||
if (!token) {
|
await this.api('/api/tasks/run-creator?topic_id=' + id, { method: 'POST' });
|
||||||
this.$message.error('请先登录');
|
count++;
|
||||||
return;
|
} catch (e) { console.error('创作失败:', id, e); }
|
||||||
}
|
|
||||||
// 取第一个选题(当前简单实现)
|
|
||||||
const topicId = this.selectedTopicIds[0];
|
|
||||||
const response = await fetch('/api/system/generate/run', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Authorization': 'Bearer ' + token,
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
body: JSON.stringify({ topic_id: topicId })
|
|
||||||
});
|
|
||||||
if (!response.ok) {
|
|
||||||
const errorData = await response.json().catch(() => ({}));
|
|
||||||
throw new Error(errorData.detail || `请求失败: ${response.status}`);
|
|
||||||
}
|
|
||||||
await response.json();
|
|
||||||
this.$message.success('批量创作已启动');
|
|
||||||
this.selectedTopicIds = [];
|
|
||||||
await this.fetchTopics();
|
|
||||||
} catch (error) {
|
|
||||||
console.error('批量创作失败:', error);
|
|
||||||
this.$message.error(`批量创作失败: ${error.message}`);
|
|
||||||
}
|
}
|
||||||
|
this.$message.success(`已提交 ${count}/${this.selectedTopicIds.length} 个创作任务,可在「创作任务」页面查看进度`);
|
||||||
|
this.selectedTopicIds = [];
|
||||||
|
setTimeout(() => this.fetchTopics(), 2000);
|
||||||
},
|
},
|
||||||
async triggerOptimizeSelected() {
|
async triggerOptimizeSelected() {
|
||||||
if (!this.selectedTopicIds.length) return;
|
if (!this.selectedTopicIds.length) return;
|
||||||
try {
|
try {
|
||||||
const token = localStorage.getItem('authToken');
|
const data = await this.api('/api/system/optimize/run', { method: 'POST', body: JSON.stringify({ topic_ids: this.selectedTopicIds }) });
|
||||||
if (!token) {
|
|
||||||
this.$message.error('请先登录');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const response = await fetch('/api/system/optimize/run', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Authorization': 'Bearer ' + token,
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
body: JSON.stringify({ topic_ids: this.selectedTopicIds })
|
|
||||||
});
|
|
||||||
if (!response.ok) {
|
|
||||||
const errorData = await response.json().catch(() => ({}));
|
|
||||||
throw new Error(errorData.detail || `请求失败: ${response.status}`);
|
|
||||||
}
|
|
||||||
const data = await response.json();
|
|
||||||
this.$message.success('批量优化完成');
|
this.$message.success('批量优化完成');
|
||||||
this.selectedTopicIds = [];
|
this.selectedTopicIds = [];
|
||||||
await this.fetchTopics();
|
await this.fetchTopics();
|
||||||
} catch (error) {
|
} catch (error) { this.$message.error(`批量优化失败: ${error.message}`); }
|
||||||
console.error('批量优化失败:', error);
|
|
||||||
this.$message.error(`批量优化失败: ${error.message}`);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
async openPreview(topic) {
|
async openPreview(topic) {
|
||||||
this.previewTopic = topic;
|
this.previewTopic = topic; this.previewPlatform = 'zhihu'; this.previewVisible = true; this.platformContents = {};
|
||||||
this.previewPlatform = 'zhihu';
|
const token = this.getToken();
|
||||||
this.previewVisible = true;
|
if (!token) return;
|
||||||
this.platformContents = {};
|
|
||||||
// 并行加载所有平台内容
|
|
||||||
const token = localStorage.getItem('authToken');
|
|
||||||
if (!token) {
|
|
||||||
this.$message.warning('请先登录');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const platforms = ['zhihu', 'wechat', 'xiaohongshu'];
|
const platforms = ['zhihu', 'wechat', 'xiaohongshu'];
|
||||||
const promises = platforms.map(p =>
|
await Promise.all(platforms.map(p =>
|
||||||
fetch(`/api/articles/${topic.id}/preview?platform=${p}`, {
|
fetch(`/api/articles/${topic.id}/preview?platform=${p}`, { headers: { 'Authorization': 'Bearer ' + token } })
|
||||||
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))
|
||||||
})
|
));
|
||||||
.then(r => r.ok ? r.json() : null)
|
|
||||||
.then(d => {
|
|
||||||
if (d && d.html) {
|
|
||||||
this.platformContents[p] = d.html;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(e => console.error(`加载${p}预览失败:`, e))
|
|
||||||
);
|
|
||||||
await Promise.all(promises);
|
|
||||||
},
|
},
|
||||||
togglePreviewFullscreen() {
|
togglePreviewFullscreen() { this.previewFullscreen = !this.previewFullscreen; },
|
||||||
this.previewFullscreen = !this.previewFullscreen;
|
platformName(platform) { return { zhihu: '知乎', wechat: '微信公众号', xiaohongshu: '小红书' }[platform] || platform; },
|
||||||
},
|
|
||||||
platformName(platform) {
|
|
||||||
const names = {
|
|
||||||
zhihu: '知乎',
|
|
||||||
wechat: '微信公众号',
|
|
||||||
xiaohongshu: '小红书'
|
|
||||||
};
|
|
||||||
return names[platform] || platform;
|
|
||||||
},
|
|
||||||
// 计算属性:当前平台预览的完整 HTML(响应式更新)
|
|
||||||
copyContent(platform) {
|
copyContent(platform) {
|
||||||
if (!this.previewTopic || !this.previewTopic.content) {
|
if (!this.previewTopic || !this.previewTopic.content) { this.$message.warning('暂无内容可复制'); return; }
|
||||||
this.$message.warning('暂无内容可复制');
|
navigator.clipboard.writeText(`标题:${this.previewTopic.title}\n\n内容:\n${this.previewTopic.content}`)
|
||||||
return;
|
.then(() => this.$message.success(`已复制内容,请前往${platform}粘贴发布`))
|
||||||
}
|
.catch(() => this.$message.error('复制失败,请手动复制'));
|
||||||
const text = `标题:${this.previewTopic.title}\n\n内容:\n${this.previewTopic.content}`;
|
},
|
||||||
navigator.clipboard.writeText(text).then(() => {
|
async createTopic(topic) {
|
||||||
this.$message.success(`已复制内容,请前往${platform}粘贴发布`);
|
if (this.isStatus(topic, 'published')) { this.$message.info('已发布选题不可创作'); return; }
|
||||||
}).catch(err => {
|
try {
|
||||||
console.error('复制失败', err);
|
const data = await this.api('/api/tasks/run-creator?topic_id=' + topic.id, { method: 'POST' });
|
||||||
this.$message.error('复制失败,请手动复制');
|
this.$message.success(`创作任务已启动: ${topic.title},可在「创作任务」页面查看进度`);
|
||||||
});
|
setTimeout(() => this.fetchTopics(), 2000);
|
||||||
|
} catch (error) { this.$message.error(`创作失败: ${error.message}`); }
|
||||||
|
},
|
||||||
|
async optimizeTopic(topic) {
|
||||||
|
if (!this.isStatus(topic, 'review')) { this.$message.info('仅待审查选题可优化'); return; }
|
||||||
|
try {
|
||||||
|
const data = await this.api('/api/system/optimize/run', { method: 'POST', body: JSON.stringify({ topic_ids: [topic.id] }) });
|
||||||
|
this.$message.success(`优化完成: ${topic.title}`);
|
||||||
|
await this.fetchTopics();
|
||||||
|
} catch (error) { this.$message.error(`优化失败: ${error.message}`); }
|
||||||
|
},
|
||||||
|
async handlePublish(topic) {
|
||||||
|
if (!this.isStatus(topic, 'ready')) { this.$message.info('仅待发布选题可发布'); return; }
|
||||||
|
try {
|
||||||
|
const data = await this.api('/api/publishing/create', { method: 'POST', body: JSON.stringify({ topic_ids: [topic.id] }) });
|
||||||
|
this.$message.success(`发布成功: ${topic.title}`);
|
||||||
|
await this.fetchTopics();
|
||||||
|
} catch (error) { this.$message.error(`发布失败: ${error.message}`); }
|
||||||
|
},
|
||||||
|
async deleteTopic(id) {
|
||||||
|
try {
|
||||||
|
await this.$confirm('确定删除?', '提示', { type: 'warning' });
|
||||||
|
await this.api('/api/topics/' + id, { method: 'DELETE' });
|
||||||
|
this.$message.success('删除成功');
|
||||||
|
await this.fetchTopics();
|
||||||
|
} catch (e) { if (e !== 'cancel') this.$message.error('删除失败'); }
|
||||||
},
|
},
|
||||||
async createTopic(topic) {
|
|
||||||
console.log('createTopic clicked, topic:', 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/system/generate/run', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Authorization': 'Bearer ' + token,
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
body: JSON.stringify({ topic_id: 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/system/optimize/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'); localStorage.removeItem('userRole'); localStorage.removeItem('currentUser'); window.location.href = '/login.html'; },
|
handleLogout() { localStorage.removeItem('authToken'); localStorage.removeItem('userRole'); localStorage.removeItem('currentUser'); window.location.href = '/login.html'; },
|
||||||
redirectToPage(page) { window.location.href = page.startsWith('/') ? page : '/' + page; },
|
redirectToPage(page) { window.location.href = page.startsWith('/') ? page : '/' + page; },
|
||||||
getStatusLabel(status) {
|
getStatusLabel(status) { return { 'pending': '待处理', 'review': '待审查', 'ready': '待发布', 'published': '已发布' }[status] || status; },
|
||||||
const statusMap = {
|
|
||||||
'pending': '待处理',
|
|
||||||
'review': '待审查',
|
|
||||||
'ready': '待发布',
|
|
||||||
'published': '已发布'
|
|
||||||
};
|
|
||||||
return statusMap[status] || status;
|
|
||||||
},
|
|
||||||
formatDate(dateStr) {
|
formatDate(dateStr) {
|
||||||
if (!dateStr) return '-';
|
if (!dateStr) return '-';
|
||||||
try {
|
try { return new Date(dateStr.replace(' ', 'T')).toLocaleString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' }); }
|
||||||
return new Date(dateStr.replace(' ', 'T')).toLocaleString('zh-CN', {
|
catch (e) { return dateStr; }
|
||||||
year: 'numeric', month: '2-digit', day: '2-digit',
|
|
||||||
hour: '2-digit', minute: '2-digit'
|
|
||||||
});
|
|
||||||
} catch (e) { return dateStr; }
|
|
||||||
},
|
},
|
||||||
getStatusType(status) {
|
getStatusType(status) { return { 'pending': 'warning', 'review': 'danger', 'ready': 'success', 'published': 'info' }[status] || 'primary'; },
|
||||||
const map = {
|
isStatus(row, status) { const map = { 'pending': ['pending','待处理'], 'review': ['review','待审查'], 'ready': ['ready','待发布'], 'published': ['published','已发布'] }; return map[status] ? map[status].includes(row.status) : row.status === status; }
|
||||||
'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() {
|
mounted() {
|
||||||
console.log('[DEBUG] TopicsApp mounted');
|
|
||||||
const token = localStorage.getItem('authToken');
|
const token = localStorage.getItem('authToken');
|
||||||
console.log('[DEBUG] Token exists:', !!token);
|
|
||||||
if (!token) { window.location.href = '/login.html'; return; }
|
if (!token) { window.location.href = '/login.html'; return; }
|
||||||
// 解析 URL filter 参数
|
const filter = new URLSearchParams(window.location.search).get('filter');
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
if (filter) this.filterStatus = filter;
|
||||||
const filter = urlParams.get('filter');
|
|
||||||
console.log('[DEBUG] URL filter:', filter);
|
|
||||||
if (filter) { this.filterStatus = filter; }
|
|
||||||
fetch('/api/auth/me', { headers: { 'Authorization': 'Bearer ' + token } })
|
fetch('/api/auth/me', { headers: { 'Authorization': 'Bearer ' + token } })
|
||||||
.then(response => response.ok ? response.json() : Promise.reject())
|
.then(r => r.ok ? r.json() : Promise.reject())
|
||||||
.then(data => {
|
.then(data => { this.currentUser = data.user; this.isAdmin = data.user.role === 'admin'; this.isLoggedIn = true; this.fetchTopics(); })
|
||||||
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'); localStorage.removeItem('userRole'); localStorage.removeItem('currentUser'); window.location.href = '/login.html'; });
|
.catch(() => { localStorage.removeItem('authToken'); localStorage.removeItem('userRole'); localStorage.removeItem('currentUser'); window.location.href = '/login.html'; });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const app = Vue.createApp(TopicsApp);
|
const app = Vue.createApp(TopicsApp);
|
||||||
app.use(ElementPlus);
|
app.use(ElementPlus);
|
||||||
// 安装导航组件
|
if (window.installNavbar) { window.installNavbar(app); }
|
||||||
if (window.installNavbar) { window.installNavbar(app); }
|
|
||||||
// 安装导航组件
|
|
||||||
if (window.installNavigation) { window.installNavigation(app); } else if (window.NavigationComponent) { app.component("navigation-component", window.NavigationComponent); }
|
if (window.installNavigation) { window.installNavigation(app); } else if (window.NavigationComponent) { app.component("navigation-component", window.NavigationComponent); }
|
||||||
app.mount('#app');
|
app.mount('#app');
|
||||||
|
|
||||||
// 调试代码:检查导航组件状态
|
|
||||||
setTimeout(() => {
|
|
||||||
const hasNav = !!document.querySelector('.navigation-wrapper');
|
|
||||||
const hasSidebar = !!document.querySelector('.navigation-wrapper .sidebar');
|
|
||||||
console.log('[调试] 导航wrapper:', hasNav);
|
|
||||||
console.log('[调试] 侧边栏:', hasSidebar);
|
|
||||||
if (!hasNav) {
|
|
||||||
console.error('[调试] 导航组件未渲染!window.NavigationComponent=', !!window.NavigationComponent);
|
|
||||||
console.error('[调试] app实例是否存在组件注册?', Vue && Vue.app && Vue.app._context.components['navigation-component']);
|
|
||||||
}
|
|
||||||
}, 100);
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user