fix: 选题页状态过滤器改用服务端过滤,移除watch覆写URL参数导致无法清除筛选的问题

- fetchTopics 根据 filterStatus 发送 status/today 参数到后端,而非全量拉取后客户端过滤
- 移除 watch.topics 处理器,解决 URL 参数反复覆写用户筛选操作的问题
- 今日新增(?today=true)和服务端 status 参数均走 API 过滤
This commit is contained in:
Yuzhiran Dev
2026-05-18 06:08:33 +08:00
parent 39719354fb
commit a46fedabb5
+9 -9
View File
@@ -235,10 +235,16 @@ const TopicsApp = {
async fetchTopics() {
this.loadingTable = true;
try {
const params = this.filterStatus === 'today' ? '?today=true' : '';
const data = await this.api('/api/topics' + params);
const params = new URLSearchParams();
if (this.filterStatus === 'today') {
params.set('today', 'true');
} else if (this.filterStatus) {
params.set('status', this.filterStatus);
}
const qs = params.toString();
const data = await this.api('/api/topics' + (qs ? '?' + qs : ''));
this.topics = data || [];
this.$message.success('选题加载成功');
if (qs) this.$message.success(`加载 ${this.filterStatus} 选题成功`);
} catch (error) {
console.error('获取选题失败:', error);
this.$message.error(`获取选题失败: ${error.message}`);
@@ -396,12 +402,6 @@ const TopicsApp = {
.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'; });
},
watch: {
topics() {
const urlFilter = new URLSearchParams(window.location.search).get('filter');
if (urlFilter) this.filterStatus = urlFilter;
}
}
};
const app = Vue.createApp(TopicsApp);