const { get } = require('../../../utils/http'); const tabService = require("../../../utils/tab-serve"); Page({ data: { homeworkList: [], pageIndex: 1, pageSize: 20, hasMore: true, isLoading: false, }, onLoad() { console.log("页面加载 - onLoad 触发"); this.loadHomework(false); console.log("页面加载完成 - onLoad 触发"); }, onShow(){ tabService.updateIndex(this,2) }, // 加载作业列表 loadHomework(isRefresh) { this.setData({ isLoading: true }); get("ClientSide/Articles", { pageIndex: this.data.pageIndex,pageSize: this.data.pageSize }) .then(res => { wx.hideLoading(); console.log("res:",res); console.log(isRefresh) if (res.success) { if(isRefresh){ console.log('bbbb') wx.stopPullDownRefresh() wx.showToast({ title: '刷新成功!', icon:'none' }) } const newList = this.processHomeworkData(res.data.datas || []); this.setData({ homeworkList: this.data.pageIndex === 1 ? newList : [...this.data.homeworkList, ...newList], pageIndex: this.data.pageIndex + 1, hasMore: newList.length >= this.data.pageSize, totalCount: res.data.total || 0 }); } else { wx.showToast({ title: res.message || "加载失败", icon: "none" }); } }) .catch(err => { wx.hideLoading(); console.error("加载作业失败:", err); wx.showToast({ title: "网络错误", icon: "none" }); }) .finally(() => { this.setData({ isLoading: false }); }); }, // 下拉刷新 onPullDownRefresh() { this.setData({ pageIndex: 1, hasMore: true }, () => { this.loadHomework(true); }); wx.stopPullDownRefresh() wx.showToast({ title: '刷新成功', icon:'none' }) }, //上拉加载 onReachBottom: function() { if(!this.data.hasMore) return this.loadHomework(false) }, // 处理数据 processHomeworkData(data) { console.log(data[0].updateDate) return data.map(item => ({ id: item.id, title: item.title, detail: item.abstract, summary: item.summary || "暂无摘要", url: item.articleUrl, thumb_url: item.coverImage || "/static/logo.png", update_time:item.updateDate.replace('-','年').replace('-','月').replace(' ','日').slice(0,11) })); }, // 跳转详情页 goToDetail(event) { const url = event.currentTarget.dataset.url; wx.navigateTo({ url: `/subpackage/teacher/articledetails/articledetails?url=${encodeURIComponent(url)}` }); } });