feat(WechatSmallProject): 新增 微信小程序 课程(包含实验1-4)
This commit is contained in:
120
WechatSmallProject/test4/pages/shoplist/shoplist.js
Normal file
120
WechatSmallProject/test4/pages/shoplist/shoplist.js
Normal file
@@ -0,0 +1,120 @@
|
||||
// pages/shoplist/shoplist.js
|
||||
Page({
|
||||
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
shopList: [],
|
||||
isLoading: false
|
||||
},
|
||||
|
||||
listData: {
|
||||
page: 1,
|
||||
pageSize: 10,
|
||||
total: 0
|
||||
},
|
||||
|
||||
getShopList: function (cb) {
|
||||
this.isLoading = true
|
||||
wx.showLoading({
|
||||
title: '数据加载中...',
|
||||
})
|
||||
|
||||
wx.request({
|
||||
url: 'http://127.0.0.1:3000/data',
|
||||
method: "GET",
|
||||
data: {
|
||||
page: this.listData.page,
|
||||
pageSize: this.listData.pageSize
|
||||
},
|
||||
success: (res) => {
|
||||
console.log(res);
|
||||
this.setData({
|
||||
shopList: [...this.data.shopList, ...res.data],
|
||||
})
|
||||
this.listData.total = res.header['X-Total-Count'] - 0
|
||||
},
|
||||
complete: () => {
|
||||
wx.hideLoading()
|
||||
this.isLoading = false
|
||||
cb & cb()
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad(options) {
|
||||
this.getShopList()
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
onReady() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面隐藏
|
||||
*/
|
||||
onHide() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
onUnload() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh() {
|
||||
this.setData({
|
||||
shopList: []
|
||||
})
|
||||
this.listData.page = 1
|
||||
this.listData.total = 0
|
||||
this.getShopList(() => {
|
||||
wx.stopPullDownRefresh()
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom() {
|
||||
if (this.listData.page * this.listData.pageSize >= this.listData.total) {
|
||||
return wx.showToast({
|
||||
title: '数据加载完毕',
|
||||
icon: "none"
|
||||
})
|
||||
}
|
||||
|
||||
if (this.isLoading) {
|
||||
return
|
||||
}
|
||||
|
||||
++this.listData.page
|
||||
this.getShopList()
|
||||
},
|
||||
|
||||
/**
|
||||
* 用户点击右上角分享
|
||||
*/
|
||||
onShareAppMessage() {
|
||||
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user