Skip to content

Commit

Permalink
增加微信小程序
Browse files Browse the repository at this point in the history
  • Loading branch information
shen100 committed May 20, 2017
1 parent 5a74f58 commit 638fa0b
Show file tree
Hide file tree
Showing 26 changed files with 242 additions and 0 deletions.
30 changes: 30 additions & 0 deletions wexin/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//app.js
App({
onLaunch: function () {
//调用API从本地缓存中获取数据
var logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)
},
getUserInfo:function(cb){
var that = this
if(this.globalData.userInfo){
typeof cb == "function" && cb(this.globalData.userInfo)
}else{
//调用登录接口
wx.login({
success: function () {
wx.getUserInfo({
success: function (res) {
that.globalData.userInfo = res.userInfo
typeof cb == "function" && cb(that.globalData.userInfo)
}
})
}
})
}
},
globalData:{
userInfo:null
}
})
48 changes: 48 additions & 0 deletions wexin/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"pages":[
"pages/index/index",
"pages/logs/logs",
"pages/product/product",
"pages/cart/cart",
"pages/mine/mine"
],
"window":{
"backgroundTextStyle": "light",
"backgroundColor": "#ff0",
"navigationBarBackgroundColor": "#000",
"navigationBarTitleText": "爱宝宝母婴微商城",
"navigationBarTextStyle": "white"
},
"tabBar": {
"color": "#5f616c",
"selectedColor": "#f13030",
"backgroundColor": "#fff",
"borderStyle": "white",
"position": "bottom",
"list": [
{
"pagePath": "pages/index/index",
"text": "首页",
"iconPath": "./icons/home.png",
"selectedIconPath": "./icons/homeSelected.png"
},
{
"pagePath": "pages/cart/cart",
"text": "购物车",
"iconPath": "./icons/cart.png",
"selectedIconPath": "./icons/cartSelected.png"
},
{
"pagePath": "pages/mine/mine",
"text": "购物车",
"iconPath": "./icons/mine.png",
"selectedIconPath": "./icons/mineSelected.png"
}
]
},
"networkTimeout": {
"request": 10000,
"downloadFile": 10000
},
"debug": true
}
10 changes: 10 additions & 0 deletions wexin/app.wxss
Original file line number Diff line number Diff line change
@@ -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 added wexin/icons/cart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added wexin/icons/cartSelected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added wexin/icons/home.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added wexin/icons/homeSelected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added wexin/icons/mine.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added wexin/icons/mineSelected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions wexin/pages/cart/cart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Page({
data: {
name: 'test'
},
onLoad: function () {
this.setData({
name: 'xxx'
})
}
})
4 changes: 4 additions & 0 deletions wexin/pages/cart/cart.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!--购物车-->
<view class="container log-list">
<text class="log-item">我的购物车</text>
</view>
Empty file added wexin/pages/cart/cart.wxss
Empty file.
26 changes: 26 additions & 0 deletions wexin/pages/index/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//index.js
//获取应用实例
var app = getApp()
Page({
data: {
motto: 'Hello World',
userInfo: {}
},
//事件处理函数
bindViewTap: function() {
wx.navigateTo({
url: '../logs/logs'
})
},
onLoad: function () {
console.log('onLoad')
var that = this
//调用应用实例的方法获取全局数据
app.getUserInfo(function(userInfo){
//更新数据
that.setData({
userInfo:userInfo
})
})
}
})
10 changes: 10 additions & 0 deletions wexin/pages/index/index.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!--index.wxml-->
<view class="container">
<view bindtap="bindViewTap" class="userinfo">
<image class="userinfo-avatar" src="{{userInfo.avatarUrl}}" background-size="cover"></image>
<text class="userinfo-nickname">{{userInfo.nickName}}</text>
</view>
<view class="usermotto">
<text class="user-motto">{{motto}}</text>
</view>
</view>
21 changes: 21 additions & 0 deletions wexin/pages/index/index.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**index.wxss**/
.userinfo {
display: flex;
flex-direction: column;
align-items: center;
}

.userinfo-avatar {
width: 128rpx;
height: 128rpx;
margin: 20rpx;
border-radius: 50%;
}

.userinfo-nickname {
color: #aaa;
}

.usermotto {
margin-top: 200px;
}
14 changes: 14 additions & 0 deletions wexin/pages/logs/logs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//logs.js
var util = require('../../utils/util.js')
Page({
data: {
logs: []
},
onLoad: function () {
this.setData({
logs: (wx.getStorageSync('logs') || []).map(function (log) {
return util.formatTime(new Date(log))
})
})
}
})
3 changes: 3 additions & 0 deletions wexin/pages/logs/logs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"navigationBarTitleText": "查看启动日志"
}
6 changes: 6 additions & 0 deletions wexin/pages/logs/logs.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!--logs.wxml-->
<view class="container log-list">
<block wx:for="{{logs}}" wx:for-item="log" wx:key="*this">
<text class="log-item">{{index + 1}}. {{log}}</text>
</block>
</view>
8 changes: 8 additions & 0 deletions wexin/pages/logs/logs.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.log-list {
display: flex;
flex-direction: column;
padding: 40rpx;
}
.log-item {
margin: 10rpx;
}
10 changes: 10 additions & 0 deletions wexin/pages/mine/mine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Page({
data: {
name: 'test'
},
onLoad: function () {
this.setData({
name: 'xxx'
})
}
})
4 changes: 4 additions & 0 deletions wexin/pages/mine/mine.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!--我的-->
<view class="container log-list">
<text class="log-item">我的</text>
</view>
10 changes: 10 additions & 0 deletions wexin/pages/product/product.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Page({
data: {
name: 'test'
},
onLoad: function () {
this.setData({
name: 'shen100'
})
}
})
3 changes: 3 additions & 0 deletions wexin/pages/product/product.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{

}
4 changes: 4 additions & 0 deletions wexin/pages/product/product.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!--产品详情页-->
<view class="container log-list">
<text class="log-item">我的商品</text>
</view>
Empty file.
21 changes: 21 additions & 0 deletions wexin/utils/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function formatTime(date) {
var year = date.getFullYear()
var month = date.getMonth() + 1
var day = date.getDate()

var hour = date.getHours()
var minute = date.getMinutes()
var second = date.getSeconds()


return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

function formatNumber(n) {
n = n.toString()
return n[1] ? n : '0' + n
}

module.exports = {
formatTime: formatTime
}

0 comments on commit 638fa0b

Please sign in to comment.