You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
2.5 KiB
97 lines
2.5 KiB
import http from '../../../utils/api'
|
|
Page({
|
|
data: {
|
|
// 分类数据
|
|
categories: [
|
|
{ name: '全部', value: 'all' },
|
|
{ name: '系统公告', value: 'system', tagBg: '#e9efff', importanceColor: '#3b82f6' },
|
|
{ name: '活动通知', value: 'activity', tagBg: '#f3e8ff', importanceColor: '#8b5cf6' },
|
|
{ name: '紧急提醒', value: 'urgent', tagBg: '#ffe4e2', importanceColor: '#ef4444' },
|
|
{ name: '学术讲座', value: 'academic', tagBg: '#dcfce7', importanceColor: '#10b981' },
|
|
{ name: '校园生活', value: 'campus', tagBg: '#fff3cd', importanceColor: '#f59e0b' },
|
|
],
|
|
currentCategory: 'all', // 当前选中分类
|
|
searchKeyword: '', // 搜索关键字
|
|
noticeList: [], // 渲染列表数据
|
|
pageIndex: 1, // 页码
|
|
pageSize: 8, // 每页条数
|
|
hasMore: true, // 是否有更多
|
|
loading: false, // 首次加载/加载中
|
|
refreshing: false, // 下拉刷新状态
|
|
mockTotal: 28, // 模拟总条数
|
|
},
|
|
|
|
onLoad() {
|
|
// this.loadFirstPage();
|
|
this.getdisaster()
|
|
},
|
|
|
|
|
|
// 通知公告
|
|
getdisaster(){
|
|
http.disaster({
|
|
data:{},
|
|
success: res => {
|
|
console.log(111,res);
|
|
this.setData({
|
|
noticeList:res.rows
|
|
})
|
|
}
|
|
})
|
|
},
|
|
|
|
|
|
|
|
|
|
// 切换分类
|
|
switchCategory(e) {
|
|
const category = e.currentTarget.dataset.category;
|
|
if (category === this.data.currentCategory) return;
|
|
this.setData({ currentCategory: category });
|
|
this.loadFirstPage();
|
|
},
|
|
|
|
// 搜索输入
|
|
onSearchInput(e) {
|
|
this.setData({ searchKeyword: e.detail.value });
|
|
},
|
|
|
|
// 执行搜索(确认或点击清空后也会触发重置)
|
|
handleSearch() {
|
|
this.loadFirstPage();
|
|
},
|
|
|
|
// 清空搜索框
|
|
clearSearch() {
|
|
this.setData({ searchKeyword: '' }, () => {
|
|
this.loadFirstPage();
|
|
});
|
|
},
|
|
|
|
// 上拉加载更多
|
|
loadMore() {
|
|
const { hasMore, loading, refreshing } = this.data;
|
|
if (!hasMore || loading || refreshing) return;
|
|
this.setData({ loading: true });
|
|
this.fetchNotices(false);
|
|
},
|
|
|
|
// 下拉刷新
|
|
onRefresh() {
|
|
this.setData({ refreshing: true });
|
|
// 重置到第一页
|
|
this.setData({ pageIndex: 1, hasMore: true }, () => {
|
|
this.fetchNotices(true);
|
|
});
|
|
},
|
|
|
|
// 查看详情 (仅跳转示意)
|
|
viewDetail(e) {
|
|
const id = e.currentTarget.dataset.id;
|
|
wx.showToast({
|
|
title: `查看公告 ${id}`,
|
|
icon: 'none'
|
|
});
|
|
// 实际开发: wx.navigateTo...
|
|
}
|
|
})
|