qingcheng-xiaochengxu/pages/projectModule/projectList/projectList.js
2025-05-29 09:02:02 +08:00

66 lines
1.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const { baseUrl } = require('../../../request');
Page({
/**
* 页面的初始数据
*/
data: {
// 四张轮播图(已统一为同一 URL
banners: [
'./images/banner.png',
'./images/banner.png',
'./images/banner.png',
'./images/banner.png'
],
// 后端返回的项目列表
items: []
},
/**
* 生命周期函数--监听页面加载
*/
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}`
});
},
});