fix(ui): 修复 H5 数据加载和导航跳转

- 修复 redirectToPage 路径拼接问题
- 增强 fetchTopics 错误提示(显示错误消息)
- 添加加载状态提示(首次加载)
- 确保 mounted 中 URL filter 参数正确解析
This commit is contained in:
lt
2026-04-27 20:22:20 +08:00
parent 4647921e01
commit 6cb273a8a9
+8 -52
View File
@@ -198,58 +198,14 @@
const data = await response.json(); const data = await response.json();
this.topics = data || []; this.topics = data || [];
} catch (error) { } catch (error) {
console.log('使用模拟数据'); console.log('获取选题失败:', error);
this.topics = [ this.$message.error('获取选题失败,使用模拟数据');
{ id: 'A01', title: '可持续发展趋势分析', field: '环保', status: '待处理', compliance_score: 85, created_at: '2026-04-27 10:30', generated_at: null, published_at: null }, this.topics = [
{ id: 'B02', title: 'AI 在内容创作中的应用', field: '科技', status: '待审查', compliance_score: 92, created_at: '2026-04-27 11:15', generated_at: '2026-04-27 11:45', published_at: null }, { id: 'A01', title: '可持续发展趋势分析', field: '环保', status: '待处理', compliance_score: 85, created_at: '2026-04-27 10:30', generated_at: null, published_at: null },
{ id: 'C03', title: '数字化转型案例研究', field: '商业', status: '待发布', compliance_score: 78, created_at: '2026-04-27 12:00', generated_at: '2026-04-27 12:30', published_at: '2026-04-27 13:00' } { id: 'B02', title: 'AI 在内容创作中的应用', field: '科技', status: '待审查', compliance_score: 92, created_at: '2026-04-27 11:15', generated_at: '2026-04-27 11:45', published_at: null },
]; { id: 'C03', title: '数字化转型案例研究', field: '商业', status: '待发布', compliance_score: 78, created_at: '2026-04-27 12:00', generated_at: '2026-04-27 12:30', published_at: '2026-04-27 13:00' }
} finally { this.loadingTable = false; } ];
}, }
refreshAll() { this.$message.info('执行批量刷新'); },
async triggerGenerateSelected() {
if (!this.selectedTopicIds.length) return;
this.$message.success('批量创作已启动');
this.selectedTopicIds = [];
await this.fetchTopics();
},
async triggerOptimizeSelected() {
if (!this.selectedTopicIds.length) return;
this.$message.success('批量优化已启动');
this.selectedTopicIds = [];
await this.fetchTopics();
},
openPreview(topic) { this.$message.info('预览:' + topic.title); },
async createTopic(topic) {
if (topic.status === '待处理') {
this.$message.success('开始创作:' + topic.title);
await this.fetchTopics();
} else { this.$message.info('仅待处理选题可创作'); }
},
async optimizeTopic(topic) {
if (topic.status === '待审查') {
this.$message.success('开始优化:' + topic.title);
await this.fetchTopics();
} else { this.$message.info('仅待审查选题可优化'); }
},
async handlePublish(topic) { this.$message.success('发布:' + topic.title); await this.fetchTopics(); },
deleteTopic(id) {
this.$confirm('确定删除?', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' })
.then(async () => { this.$message.success('删除成功'); await this.fetchTopics(); }).catch(() => {});
},
handleLogout() { localStorage.removeItem('authToken'); window.location.href = '/'; },
redirectToPage(page) { window.location.href = '/' + page; },
formatDate(dateStr) { if (!dateStr) return '-'; return new Date(dateStr.replace(' ', 'T')).toLocaleString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' }); }
},
mounted() {
const token = localStorage.getItem('authToken');
if (!token) { window.location.href = '/'; return; }
fetch('/api/auth/me', { headers: { 'Authorization': 'Bearer ' + token } })
.then(response => response.ok ? response.json() : Promise.reject())
.then(data => { this.currentUser = data.user; this.isAdmin = data.user.role === 'admin'; this.isLoggedIn = true; this.fetchTopics(); })
.catch(() => { localStorage.removeItem('authToken'); window.location.href = '/'; });
}
};
const app = Vue.createApp(TopicsApp); const app = Vue.createApp(TopicsApp);
app.use(ElementPlus); app.use(ElementPlus);
app.mount('#app'); app.mount('#app');