Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update #7

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#### 引言:
最近微信小程序爆火,顺势写了一个小demo,用了半天编码。结论是开发门槛降低,小程序更注重让开发者关注前端UI和交互。欢迎交流与提交~

### 贡献者名单
---
| 时间 | 贡献者 | 贡献内容 |
|--------|------------|---------------|
| 2016.09.25 | JohnWang | 优化wx:for的使用,创建复用模板 |
| 2016.09.24 | JohnWang | 优化结构目录 |

### 目录结构:
---
为了方便其他开发者学习和使用,拓展目录结构:
Expand All @@ -21,4 +28,4 @@

### 项目地址:
---
https://github.com/aidenzou/SmallApp
https://github.com/aidenzou/SmallApp
12 changes: 6 additions & 6 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
App({
onLaunch: function () {
console.log('App Launch')
//调用API从本地缓存中获取数据
//调用API从本地缓存中获取数据
var logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)
},
getUserInfo:function(cb){
getUserInfo: function (cb) {
var that = this
if(this.globalData.userInfo){
if (this.globalData.userInfo) {
typeof cb == "function" && cb(this.globalData.userInfo)
}else{
} else {
//调用登录接口
wx.login({
success: function () {
Expand All @@ -31,7 +31,7 @@ App({
onHide: function () {
console.log('App Hide')
},
globalData:{
userInfo:null
globalData: {
userInfo: null
}
})
6 changes: 6 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,11 @@
"text": "我的"
}]
},
"networkTimeout": {
"request": 10000,
"connectSocket": 10000,
"uploadFile": 10000,
"downloadFile": 10000
},
"debug": true
}
2 changes: 1 addition & 1 deletion pages/i/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ Page( {
})
})
}
})
})
2 changes: 1 addition & 1 deletion pages/i/index.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
<view class="info">
<text>{{source}}</text>
</view>
</view>
</view>
87 changes: 48 additions & 39 deletions pages/index/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,57 @@
var app = getApp()
Page( {
data: {
//向模板传入数据
// 轮播
images: [
'https://hamlet.b0.upaiyun.com/1609/19171/2788065f96c04ad38c8db50ad723bc37.jpg!/fwfh/640x352/quality/80',
'https://hamlet.b0.upaiyun.com/1609/23150/4cc74e62833e4cdaaec79f3a2ef256e5.jpg!/fwfh/640x352/quality/80',
'https://hamlet.b0.upaiyun.com/1609/23150/4cc74e62833e4cdaaec79f3a2ef256e5.jpg!/fwfh/640x352/quality/80',
'https://hamlet.b0.upaiyun.com/1609/20180/934270f1be264c63bfaf85b37e545928.jpg!/fwfh/640x352/quality/80',
'https://hamlet.b0.upaiyun.com/1609/20171/77f7a3c93fd641bf95150501ef9a7cad.jpg!/fwfh/640x352/quality/80',
'https://hamlet.b0.upaiyun.com/1609/19171/2788065f96c04ad38c8db50ad723bc37.jpg!/fwfh/640x352/quality/80',
'https://hamlet.b0.upaiyun.com/1609/23171/70065cf9e45d46729ca51dec55d5f650.jpg!/fwfh/640x352/quality/80'
],
indicatorDots: true,
vertical: false,
autoplay: true,
interval: 3000,
duration: 1200,
index_index_scroll_tmpl: {
images: [
'https://hamlet.b0.upaiyun.com/1609/19171/2788065f96c04ad38c8db50ad723bc37.jpg!/fwfh/640x352/quality/80',
'https://hamlet.b0.upaiyun.com/1609/23150/4cc74e62833e4cdaaec79f3a2ef256e5.jpg!/fwfh/640x352/quality/80',
'https://hamlet.b0.upaiyun.com/1609/23150/4cc74e62833e4cdaaec79f3a2ef256e5.jpg!/fwfh/640x352/quality/80',
'https://hamlet.b0.upaiyun.com/1609/20180/934270f1be264c63bfaf85b37e545928.jpg!/fwfh/640x352/quality/80',
'https://hamlet.b0.upaiyun.com/1609/20171/77f7a3c93fd641bf95150501ef9a7cad.jpg!/fwfh/640x352/quality/80',
'https://hamlet.b0.upaiyun.com/1609/19171/2788065f96c04ad38c8db50ad723bc37.jpg!/fwfh/640x352/quality/80',
'https://hamlet.b0.upaiyun.com/1609/23171/70065cf9e45d46729ca51dec55d5f650.jpg!/fwfh/640x352/quality/80'
],
indicatorDots: true,
vertical: false,
autoplay: true,
interval: 3000,
duration: 1200
},
// nav
navs: [
{
image: 'https://m.youcai.xin/static/img/gravida.png',
text: '孕妇'
}, {
image: 'https://m.youcai.xin/static/img/confinement.png',
text: '月子'
}, {
image: 'https://m.youcai.xin/static/img/baby.png',
text: '幼儿'
}, {
image: 'https://m.youcai.xin/static/img/old.png',
text: '老人'
}
],
index_index_navs_tmpl: {
navs: [
{
image: 'https://m.youcai.xin/static/img/gravida.png',
text: '孕妇'
}, {
image: 'https://m.youcai.xin/static/img/confinement.png',
text: '月子'
}, {
image: 'https://m.youcai.xin/static/img/baby.png',
text: '幼儿'
}, {
image: 'https://m.youcai.xin/static/img/old.png',
text: '老人'
}
]
},

// item
items: [
{image: 'https://hamlet.b0.upaiyun.com/1609/22111/fe8765fa7f2f48cd87760c10ddd20ae6.jpg'},
{image: 'https://hamlet.b0.upaiyun.com/1609/22111/84439174cad04497beda3a076663beb4.jpg'},
{image: 'https://hamlet.b0.upaiyun.com/1609/22111/1987d8eb8b1748368b7f2382332c9718.jpg'},
{image: 'https://hamlet.b0.upaiyun.com/1609/22111/fe8765fa7f2f48cd87760c10ddd20ae6.jpg'},
{image: 'https://hamlet.b0.upaiyun.com/1609/22111/fe8765fa7f2f48cd87760c10ddd20ae6.jpg'},
{image: 'https://hamlet.b0.upaiyun.com/1609/22111/fe8765fa7f2f48cd87760c10ddd20ae6.jpg'},
{image: 'https://hamlet.b0.upaiyun.com/1609/22111/fe8765fa7f2f48cd87760c10ddd20ae6.jpg'},
{image: 'https://hamlet.b0.upaiyun.com/1609/22111/fe8765fa7f2f48cd87760c10ddd20ae6.jpg'}
]
index_index_items_tmpl: {
items: [
{image: 'https://hamlet.b0.upaiyun.com/1609/22111/fe8765fa7f2f48cd87760c10ddd20ae6.jpg'},
{image: 'https://hamlet.b0.upaiyun.com/1609/22111/84439174cad04497beda3a076663beb4.jpg'},
{image: 'https://hamlet.b0.upaiyun.com/1609/22111/1987d8eb8b1748368b7f2382332c9718.jpg'},
{image: 'https://hamlet.b0.upaiyun.com/1609/22111/fe8765fa7f2f48cd87760c10ddd20ae6.jpg'},
{image: 'https://hamlet.b0.upaiyun.com/1609/22111/fe8765fa7f2f48cd87760c10ddd20ae6.jpg'},
{image: 'https://hamlet.b0.upaiyun.com/1609/22111/fe8765fa7f2f48cd87760c10ddd20ae6.jpg'},
{image: 'https://hamlet.b0.upaiyun.com/1609/22111/fe8765fa7f2f48cd87760c10ddd20ae6.jpg'},
{image: 'https://hamlet.b0.upaiyun.com/1609/22111/fe8765fa7f2f48cd87760c10ddd20ae6.jpg'}
]
}

},

//事件处理函数
Expand Down
29 changes: 8 additions & 21 deletions pages/index/index.wxml
Original file line number Diff line number Diff line change
@@ -1,33 +1,20 @@
<!--index.wxml-->
<import src="../../template/item-template.wxml"/>
<view class="container">

<view class="section section_gap swiper_box">
<swiper class="swiper" indicator-dots="{{indicatorDots}}" vertical="{{vertical}}"
autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}" bindchange="swiperchange">
<block wx:for-items="{{images}}">
<swiper-item>
<image src="{{item}}" class="slide-image"/>
</swiper-item>
</block>
</swiper>
<template is="index_index_scroll_tmpl" data="{{...index_index_scroll_tmpl}}"/>
</view>

<view class="section index-nav">
<block wx:for-items="{{navs}}">
<view class="l-c-c" catchtap="go" data-type="{{item.text}}">
<image src="{{item.image}}" class="slide-image"/>
<text>{{item.text}}</text>
</view>
</block>
<template is="index_index_navs_tmpl" data="{{...index_index_navs_tmpl}}"/>
</view>

<view class="text">
<view class="line_y"></view>
<text>精品特价</text>
</view>

<block wx:for-items="{{items}}">
<view class="item">
<image src="{{item.image}}" class="slide-image"/>
</view>
</block>

<template is="index_index_items_tmpl" data="{{...index_index_items_tmpl}}"/>

</view>
5 changes: 4 additions & 1 deletion pages/list/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 4 additions & 13 deletions pages/list/index.wxml
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
<!--index.wxml-->
<import src="../../template/item-template.wxml" />

<view class="container">
<block wx:for-items="{{items}}">
<view class="l-r l-c item">
<view class="image">
<image src="{{item.imgs[0]}}!/fwfh/330x330/quality/80"/>
</view>
<view class="l_auto item-right">
<view class="title"><text>{{item.title}}</text></view>
<text>{{item.quantity}}{{item.unit}}/份</text>
<text class="c-1">¥{{item.price/100}}</text>
</view>
</view>
</block>
</view>
<template is="list_index_items_tmpl" data="{{...list_index_items_tmpl}}" />
</view>
2 changes: 1 addition & 1 deletion pages/logs/logs.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"navigationBarTitleText": "查看启动日志"
}
}
46 changes: 46 additions & 0 deletions template/item-template.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!--index_index_scroll-->
<template name="index_index_scroll_tmpl">
<swiper class="swiper" indicator-dots="{{indicatorDots}}" vertical="{{vertical}}"
autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}" bindchange="swiperchange">
<block wx:for="{{images}}">
<swiper-item>
<image src="{{item}}" class="slide-image"/>
</swiper-item>
</block>
</swiper>
</template>

<!--index_index_navs-->
<template name="index_index_navs_tmpl">
<block wx:for="{{navs}}">
<view class="l-c-c" catchtap="go" data-type="{{item.text}}">
<image src="{{item.image}}" class="slide-image"/>
<text>{{item.text}}</text>
</view>
</block>
</template>

<!--index_index_items-->
<template name="index_index_items_tmpl">
<block wx:for="{{items}}">
<view class="item">
<image src="{{item.image}}" class="slide-image"/>
</view>
</block>
</template>

<!--list_index_items-->
<template name="list_index_items_tmpl">
<block wx:for="{{items}}">
<view class="l-r l-c item">
<view class="image">
<image src="{{item.imgs[0]}}!/fwfh/330x330/quality/80"/>
</view>
<view class="l_auto item-right">
<view class="title"><text>{{item.title}}</text></view>
<text>{{item.quantity}}{{item.unit}}/份</text>
<text class="c-1">¥{{item.price/100}}</text>
</view>
</view>
</block>
</template>