diff --git a/wexin/app.js b/wexin/app.js new file mode 100644 index 00000000..0b9b17ad --- /dev/null +++ b/wexin/app.js @@ -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 + } +}) \ No newline at end of file diff --git a/wexin/app.json b/wexin/app.json new file mode 100644 index 00000000..7d41fb9a --- /dev/null +++ b/wexin/app.json @@ -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 +} diff --git a/wexin/app.wxss b/wexin/app.wxss new file mode 100644 index 00000000..06c6fc9c --- /dev/null +++ b/wexin/app.wxss @@ -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; +} diff --git a/wexin/icons/cart.png b/wexin/icons/cart.png new file mode 100644 index 00000000..92aa06f7 Binary files /dev/null and b/wexin/icons/cart.png differ diff --git a/wexin/icons/cartSelected.png b/wexin/icons/cartSelected.png new file mode 100644 index 00000000..a3758bb8 Binary files /dev/null and b/wexin/icons/cartSelected.png differ diff --git a/wexin/icons/home.png b/wexin/icons/home.png new file mode 100644 index 00000000..d3d9f23a Binary files /dev/null and b/wexin/icons/home.png differ diff --git a/wexin/icons/homeSelected.png b/wexin/icons/homeSelected.png new file mode 100644 index 00000000..a0c157e5 Binary files /dev/null and b/wexin/icons/homeSelected.png differ diff --git a/wexin/icons/mine.png b/wexin/icons/mine.png new file mode 100644 index 00000000..01e2c2d9 Binary files /dev/null and b/wexin/icons/mine.png differ diff --git a/wexin/icons/mineSelected.png b/wexin/icons/mineSelected.png new file mode 100644 index 00000000..35cca33d Binary files /dev/null and b/wexin/icons/mineSelected.png differ diff --git a/wexin/pages/cart/cart.js b/wexin/pages/cart/cart.js new file mode 100644 index 00000000..7efbfe81 --- /dev/null +++ b/wexin/pages/cart/cart.js @@ -0,0 +1,10 @@ +Page({ + data: { + name: 'test' + }, + onLoad: function () { + this.setData({ + name: 'xxx' + }) + } +}) \ No newline at end of file diff --git a/wexin/pages/cart/cart.wxml b/wexin/pages/cart/cart.wxml new file mode 100644 index 00000000..19948be5 --- /dev/null +++ b/wexin/pages/cart/cart.wxml @@ -0,0 +1,4 @@ + + + 我的购物车 + \ No newline at end of file diff --git a/wexin/pages/cart/cart.wxss b/wexin/pages/cart/cart.wxss new file mode 100644 index 00000000..e69de29b diff --git a/wexin/pages/index/index.js b/wexin/pages/index/index.js new file mode 100644 index 00000000..6ae22caf --- /dev/null +++ b/wexin/pages/index/index.js @@ -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 + }) + }) + } +}) diff --git a/wexin/pages/index/index.wxml b/wexin/pages/index/index.wxml new file mode 100644 index 00000000..022ad3ba --- /dev/null +++ b/wexin/pages/index/index.wxml @@ -0,0 +1,10 @@ + + + + + {{userInfo.nickName}} + + + {{motto}} + + diff --git a/wexin/pages/index/index.wxss b/wexin/pages/index/index.wxss new file mode 100644 index 00000000..ce30de01 --- /dev/null +++ b/wexin/pages/index/index.wxss @@ -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; +} \ No newline at end of file diff --git a/wexin/pages/logs/logs.js b/wexin/pages/logs/logs.js new file mode 100644 index 00000000..c201bfe4 --- /dev/null +++ b/wexin/pages/logs/logs.js @@ -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)) + }) + }) + } +}) diff --git a/wexin/pages/logs/logs.json b/wexin/pages/logs/logs.json new file mode 100644 index 00000000..66dcbc7b --- /dev/null +++ b/wexin/pages/logs/logs.json @@ -0,0 +1,3 @@ +{ + "navigationBarTitleText": "查看启动日志" +} \ No newline at end of file diff --git a/wexin/pages/logs/logs.wxml b/wexin/pages/logs/logs.wxml new file mode 100644 index 00000000..0a4efa7a --- /dev/null +++ b/wexin/pages/logs/logs.wxml @@ -0,0 +1,6 @@ + + + + {{index + 1}}. {{log}} + + diff --git a/wexin/pages/logs/logs.wxss b/wexin/pages/logs/logs.wxss new file mode 100644 index 00000000..94d4b88a --- /dev/null +++ b/wexin/pages/logs/logs.wxss @@ -0,0 +1,8 @@ +.log-list { + display: flex; + flex-direction: column; + padding: 40rpx; +} +.log-item { + margin: 10rpx; +} diff --git a/wexin/pages/mine/mine.js b/wexin/pages/mine/mine.js new file mode 100644 index 00000000..7efbfe81 --- /dev/null +++ b/wexin/pages/mine/mine.js @@ -0,0 +1,10 @@ +Page({ + data: { + name: 'test' + }, + onLoad: function () { + this.setData({ + name: 'xxx' + }) + } +}) \ No newline at end of file diff --git a/wexin/pages/mine/mine.wxml b/wexin/pages/mine/mine.wxml new file mode 100644 index 00000000..94c7e1f2 --- /dev/null +++ b/wexin/pages/mine/mine.wxml @@ -0,0 +1,4 @@ + + + 我的 + \ No newline at end of file diff --git a/wexin/pages/product/product.js b/wexin/pages/product/product.js new file mode 100644 index 00000000..3efcb74e --- /dev/null +++ b/wexin/pages/product/product.js @@ -0,0 +1,10 @@ +Page({ + data: { + name: 'test' + }, + onLoad: function () { + this.setData({ + name: 'shen100' + }) + } +}) \ No newline at end of file diff --git a/wexin/pages/product/product.json b/wexin/pages/product/product.json new file mode 100644 index 00000000..544b7b4d --- /dev/null +++ b/wexin/pages/product/product.json @@ -0,0 +1,3 @@ +{ + +} \ No newline at end of file diff --git a/wexin/pages/product/product.wxml b/wexin/pages/product/product.wxml new file mode 100644 index 00000000..cdc2cab8 --- /dev/null +++ b/wexin/pages/product/product.wxml @@ -0,0 +1,4 @@ + + + 我的商品 + \ No newline at end of file diff --git a/wexin/pages/product/product.wxss b/wexin/pages/product/product.wxss new file mode 100644 index 00000000..e69de29b diff --git a/wexin/utils/util.js b/wexin/utils/util.js new file mode 100644 index 00000000..a3367dcb --- /dev/null +++ b/wexin/utils/util.js @@ -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 +}