feat(WechatSmallProject): 新增 微信小程序 课程(包含实验1-4)
This commit is contained in:
19
WechatSmallProject/test4/app.js
Normal file
19
WechatSmallProject/test4/app.js
Normal file
@@ -0,0 +1,19 @@
|
||||
// app.js
|
||||
App({
|
||||
onLaunch() {
|
||||
// 展示本地存储能力
|
||||
const logs = wx.getStorageSync('logs') || []
|
||||
logs.unshift(Date.now())
|
||||
wx.setStorageSync('logs', logs)
|
||||
|
||||
// 登录
|
||||
wx.login({
|
||||
success: res => {
|
||||
// 发送 res.code 到后台换取 openId, sessionKey, unionId
|
||||
}
|
||||
})
|
||||
},
|
||||
globalData: {
|
||||
userInfo: null
|
||||
}
|
||||
})
|
||||
14
WechatSmallProject/test4/app.json
Normal file
14
WechatSmallProject/test4/app.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"pages": [
|
||||
"pages/shoplist/shoplist"
|
||||
],
|
||||
"window": {
|
||||
"navigationBarTextStyle": "black",
|
||||
"navigationBarTitleText": "Weixin",
|
||||
"navigationBarBackgroundColor": "#ffffff"
|
||||
},
|
||||
"style": "v2",
|
||||
"componentFramework": "glass-easel",
|
||||
"sitemapLocation": "sitemap.json",
|
||||
"lazyCodeLoading": "requiredComponents"
|
||||
}
|
||||
10
WechatSmallProject/test4/app.wxss
Normal file
10
WechatSmallProject/test4/app.wxss
Normal file
@@ -0,0 +1,10 @@
|
||||
/**app.wxss**/
|
||||
.container {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 200rpx 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
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;
|
||||
}
|
||||
41
WechatSmallProject/test4/project.config.json
Normal file
41
WechatSmallProject/test4/project.config.json
Normal file
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"compileType": "miniprogram",
|
||||
"libVersion": "trial",
|
||||
"packOptions": {
|
||||
"ignore": [],
|
||||
"include": []
|
||||
},
|
||||
"setting": {
|
||||
"coverView": true,
|
||||
"es6": true,
|
||||
"postcss": true,
|
||||
"minified": true,
|
||||
"enhance": true,
|
||||
"showShadowRootInWxmlPanel": true,
|
||||
"packNpmRelationList": [],
|
||||
"babelSetting": {
|
||||
"ignore": [],
|
||||
"disablePlugins": [],
|
||||
"outputPath": ""
|
||||
},
|
||||
"compileWorklet": false,
|
||||
"uglifyFileName": false,
|
||||
"uploadWithSourceMap": true,
|
||||
"packNpmManually": false,
|
||||
"minifyWXSS": true,
|
||||
"minifyWXML": true,
|
||||
"localPlugins": false,
|
||||
"condition": false,
|
||||
"swc": false,
|
||||
"disableSWC": true,
|
||||
"disableUseStrict": false,
|
||||
"useCompilerPlugins": false
|
||||
},
|
||||
"condition": {},
|
||||
"editorSetting": {
|
||||
"tabIndent": "auto",
|
||||
"tabSize": 2
|
||||
},
|
||||
"appid": "wx8c60a45abd90774a",
|
||||
"simulatorPluginLibVersion": {}
|
||||
}
|
||||
23
WechatSmallProject/test4/project.private.config.json
Normal file
23
WechatSmallProject/test4/project.private.config.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
|
||||
"projectname": "test4",
|
||||
"setting": {
|
||||
"compileHotReLoad": true,
|
||||
"urlCheck": false,
|
||||
"coverView": true,
|
||||
"lazyloadPlaceholderEnable": false,
|
||||
"skylineRenderEnable": false,
|
||||
"preloadBackgroundData": false,
|
||||
"autoAudits": false,
|
||||
"useApiHook": true,
|
||||
"useApiHostProcess": true,
|
||||
"showShadowRootInWxmlPanel": true,
|
||||
"useStaticServer": false,
|
||||
"useLanDebug": false,
|
||||
"showES6CompileOption": false,
|
||||
"bigPackageSizeSupport": false,
|
||||
"checkInvalidKey": true,
|
||||
"ignoreDevUnusedFiles": true
|
||||
},
|
||||
"libVersion": "3.15.2"
|
||||
}
|
||||
7
WechatSmallProject/test4/sitemap.json
Normal file
7
WechatSmallProject/test4/sitemap.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html",
|
||||
"rules": [{
|
||||
"action": "allow",
|
||||
"page": "*"
|
||||
}]
|
||||
}
|
||||
13
WechatSmallProject/test4/utils/tools.wxs
Normal file
13
WechatSmallProject/test4/utils/tools.wxs
Normal file
@@ -0,0 +1,13 @@
|
||||
function splitPhone(str) {
|
||||
if (str.length !== 11) {
|
||||
return str
|
||||
}
|
||||
var arr = str.split("")
|
||||
arr.splice(3, 0, '-')
|
||||
arr.splice(8, 0, '-')
|
||||
return arr.join("")
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
splitPhone: splitPhone
|
||||
}
|
||||
Reference in New Issue
Block a user