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() {
|
||||
|
||||
}
|
||||
})
|
||||
8
WechatSmallProject/test4/pages/shoplist/shoplist.json
Normal file
8
WechatSmallProject/test4/pages/shoplist/shoplist.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"usingComponents": {},
|
||||
"navigationBarTitleText": "美食",
|
||||
"onReachBottomDistance": 200,
|
||||
"enablePullDownRefresh": true,
|
||||
"backgroundColor": "#efefef",
|
||||
"backgroundTextStyle": "dark"
|
||||
}
|
||||
12
WechatSmallProject/test4/pages/shoplist/shoplist.wxml
Normal file
12
WechatSmallProject/test4/pages/shoplist/shoplist.wxml
Normal file
@@ -0,0 +1,12 @@
|
||||
<view class="shop-item" wx:for="{{ shopList}}" wx:key="id">
|
||||
<view class="thumb">
|
||||
<image src="{{ item.image }}" mode="aspectFill" />
|
||||
</view>
|
||||
<view class="info">
|
||||
<text class="shop-title">{{item.name}}</text>
|
||||
<text>电话:{{tools.splitPhone(item.phone)}}</text>
|
||||
<text>地址:{{item.address}}</text>
|
||||
<text>营业时间:{{item.businessHours}}</text>
|
||||
</view>
|
||||
</view>
|
||||
<wxs src="../../utils/tools.wxs" module="tools" />
|
||||
74
WechatSmallProject/test4/pages/shoplist/shoplist.wxss
Normal file
74
WechatSmallProject/test4/pages/shoplist/shoplist.wxss
Normal file
@@ -0,0 +1,74 @@
|
||||
/* 页面整体 */
|
||||
page {
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
/* 列表项 */
|
||||
.shop-item {
|
||||
display: flex;
|
||||
padding: 20rpx;
|
||||
margin: 20rpx;
|
||||
background: #ffffff;
|
||||
border-radius: 16rpx;
|
||||
box-shadow: 0 8rpx 20rpx rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
/* 图片区域 */
|
||||
.thumb {
|
||||
width: 180rpx;
|
||||
height: 180rpx;
|
||||
margin-right: 20rpx;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.thumb image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border-radius: 12rpx;
|
||||
background: #eee;
|
||||
}
|
||||
|
||||
/* 右侧信息 */
|
||||
.info {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
/* 标题 */
|
||||
.shop-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
margin-bottom: 10rpx;
|
||||
|
||||
/* 超出两行省略 */
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* 文字通用 */
|
||||
.info text {
|
||||
font-size: 24rpx;
|
||||
color: #666;
|
||||
margin-bottom: 6rpx;
|
||||
}
|
||||
|
||||
/* 电话高亮 */
|
||||
.info text:nth-child(2) {
|
||||
color: #2a7fff;
|
||||
}
|
||||
|
||||
/* 地址稍微淡一点 */
|
||||
.info text:nth-child(3) {
|
||||
color: #999;
|
||||
}
|
||||
|
||||
/* 营业时间 */
|
||||
.info text:nth-child(4) {
|
||||
color: #999;
|
||||
font-size: 22rpx;
|
||||
}
|
||||
Reference in New Issue
Block a user