const { baseUrl } = require('../../../request'); import { globalImgUrl } from '../../../request'; Page({ /** * 页面的初始数据 */ data: { // 四张轮播图(已统一为同一 URL) banners: [ './images/banner.png', './images/banner.png', './images/banner.png', './images/banner.png' ], // 后端返回的项目列表 items: [], globalImgUrl, }, /** * 生命周期函数--监听页面加载 */ onLoad() { // 从本地缓存取出 token const token = wx.getStorageSync('token'); // 请求项目列表 wx.request({ url: baseUrl + '/project/query/card', // 请替换为真实接口 method: 'POST', header: { Authorization: token // 带上授权头 }, success: res => { console.log(res.data); if (res.data.code === 1) { // 渲染项目数据 this.setData({ items: res.data.data }); } else if(res.data.code === 40101) { wx.reLaunch({ url: '/pages/loginModule/pwdLogin/pwdLogin', }) } else { wx.showToast({ title: res.data.message || '获取项目列表失败', icon: 'none' }); } }, fail: () => { wx.showToast({ title: '网络错误,请重试', icon: 'none' }); } }); }, /** * 点击“参与推广” */ gotoPromotion(e) { // 从 dataset 拿到 data-id const projectId = e.currentTarget.dataset.id; // 带上 id 跳转到详情页(路径按你的项目结构调整) wx.navigateTo({ url: `/pages/projectModule/projectDetail/projectDetail?id=${projectId}&isPromo=0` }); }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { this.onRefresh(); }, onRefresh:function(){ //导航条加载动画 wx.showNavigationBarLoading() //loading 提示框 wx.showLoading({ title: '加载中...', }) console.log("下拉刷新啦"); this.onLoad() setTimeout(function () { wx.hideLoading(); wx.hideNavigationBarLoading(); //停止下拉刷新 wx.stopPullDownRefresh(); }, 1000) }, });