main
wenyi 6 months ago
parent 5513e1c353
commit d177d6cdc5

@ -0,0 +1,31 @@
/*
* Eslint config file
* Documentation: https://eslint.org/docs/user-guide/configuring/
* Install the Eslint extension before using this feature.
*/
module.exports = {
env: {
es6: true,
browser: true,
node: true,
},
ecmaFeatures: {
modules: true,
},
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},
globals: {
wx: true,
App: true,
Page: true,
getCurrentPages: true,
getApp: true,
Component: true,
requirePlugin: true,
requireMiniProgram: true,
},
// extends: 'eslint:recommended',
rules: {},
}

@ -1,2 +1,2 @@
# five # five
![截图](./food.jpg)

@ -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
}
})

@ -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"
}

@ -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;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

@ -0,0 +1,126 @@
// pages/shoplist/shoplist.js
Page({
/**
* 页面的初始数据
*/
data: {
shopList:[],
},
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:function() {
this.getShopList()
},
onReachBottom:function(){
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()
},
isLoading:false,
onPullDownRefresh:function(){
this.setData({
shopList:[]
})
this.listData.page=1
this.listData.total=0
this.getShopList(()=>{
wx.stopPullDownRefresh()
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})

@ -0,0 +1,4 @@
{
"navigationBarTitleText": "美食",
"onReachBottomDistance": 200
}

@ -0,0 +1,13 @@
<!--pages/shoplist/shoplist.wxml-->
<wxs src="../../utils/tools.wxs" module="tools"/>
<view class="shop-item" wx:for="{{shopList}}" wx:key="id">
<view class="thumb">
<image src="{{item.image}}" mode="" />
</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>

@ -0,0 +1,28 @@
/* pages/shoplist/shoplist.wxss */
/* pages/shoplist/shoplist.wxss */
.shop-item {
display: flex;
padding: 15rpx;
border: 1rpx solid #efefef;
border-radius: 8rpx;
margin: 15rpx;
box-shadow: 1rpx 1rpx 15rpx #ddd;
}
.thumb image {
width: 250rpx;
height: 250rpx;
display: block;
margin-right: 15rpx;
}
.info {
display: flex;
flex-direction: column;
justify-content: space-around;
font-size: 24rpx;
}
.shop-title {
font-weight: bold;
}

@ -0,0 +1,28 @@
{
"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": ""
}
},
"condition": {},
"editorSetting": {
"tabIndent": "auto",
"tabSize": 2
},
"appid": "wxc15fead6ca65fb7b"
}

@ -0,0 +1,8 @@
{
"description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
"projectname": "study",
"setting": {
"compileHotReLoad": true,
"urlCheck": false
}
}

@ -0,0 +1,7 @@
{
"desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html",
"rules": [{
"action": "allow",
"page": "*"
}]
}

@ -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
}

File diff suppressed because one or more lines are too long

@ -0,0 +1,26 @@
let fs = require('fs');
var express = require('express')
// 读取JSON数据
let jsonStr = fs.readFileSync('./data.json', {
encoding: 'utf8'
});
let data = JSON.parse(jsonStr);
// 创建Web服务器对象
var app = express();
// 静态资源处理
app.use(express.static('public'));
app.get('/data', (req, res) => {
let [ ...arr ] = data
let start = (req.query.page - 1) * req.query.pageSize;
res.setHeader('X-Total-Count', data.length);
res.send(arr.splice(start, req.query.pageSize));
});
app.listen(3000, () => {
console.log('服务器启动成功地址为http://127.0.0.1:3000');
});
Loading…
Cancel
Save