Browse Source

登录页,首页

wangxin 6 years ago
parent
commit
0e0a43a561

+ 3 - 2
app.json

@@ -1,15 +1,16 @@
 {
   "pages": [
     "template/home/index",
+    "template/login/index",
     "template/view/index",
     "template/carts/index"
   ],
   "window": {
     "navigationBarTextStyle": "#fff",
-    "navigationBarTitleText": "test",
+    "navigationBarTitleText": "农小盒",
     "navigationBarBackgroundColor": "#000",
     "backgroundColor": "#f8f8f8",
-    "enablePullDownRefresh": true
+    "enablePullDownRefresh": false
   },
   "networkTimeout": {
     "request": 10000,

+ 8 - 0
app.wxss

@@ -5,6 +5,7 @@ page{
     font-size: 16px;
     font-family: -apple-system-font,Helvetica Neue,Helvetica,sans-serif;
 }
+/*
 .page__hd {
     padding: 40px;
 }
@@ -32,4 +33,11 @@ page{
     color: #888888;
     text-align: left;
     font-size: 14px;
+}*/
+.nxh__button {
+  background: #539804;
+  color: #fff;
+  border-radius: 50rpx;
+  width: 420rpx;
+  font-size: 35rpx;
 }

+ 8 - 0
dever/core.js

@@ -114,6 +114,14 @@ var dever =
         })
     }
 
+    //回退 delta 返回的页面数,如果 delta 大于现有页面数,则返回到首页。
+    ,goBack: function(delta){
+      if(typeof delta == 'undefined') delta = 1;
+      wx.navigateBack({
+        delta: delta
+      })
+    }
+
     //log
     ,log : function(title, msg)
     {

BIN
static/img/item-1.png


BIN
static/img/item-2.png


BIN
static/img/logo.png


+ 3 - 1
template/carts/index.json

@@ -1 +1,3 @@
-{}
+{
+  "navigationBarTitleText": "农小盒"
+}

+ 25 - 2
template/home/index.js

@@ -8,14 +8,28 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
-    var self = this;
+    /*var self = this;
     // 初始化购物车
     self.dever.carts(self, 'carts.save', 'carts/index');
     var success = function(data, res)
     {
         self.dever.setList(self, data.product);
     };
-    self.dever.request('main.api.home', {}, {success: success});
+    self.dever.request('main.api.home', {}, {success: success});*/
+
+    //test - begin
+    var list = new Array();
+    for(var i=1; i<4; i++){
+      var item = new Object();
+      item.id = i;
+      item.pic = '/static/img/item-'+(1+Math.round(Math.random()*1))+'.png';
+      item.name = i+'盒有机韭菜';
+      item.price = i*20;
+      list.push(item);
+    }
+    this.dever.setList(this, list);
+    this.dever.stopPullDown();
+    //test - end
   },
 
   view: function (event) {
@@ -27,6 +41,15 @@ Page({
     this.dever.location('view/index?id=' + id);
   },
 
+  addCarts: function (event){
+    if (typeof (event) == 'object') {
+      var id = event.currentTarget.dataset.id
+    } else {
+      var id = event
+    }
+    this.dever.location('carts/index?id=' + id);
+  },
+
   /**
    * 生命周期函数--监听页面初次渲染完成
    */

+ 4 - 1
template/home/index.json

@@ -1 +1,4 @@
-{}
+{
+  "navigationBarTitleText": "农小盒",
+  "enablePullDownRefresh": true
+}

+ 5 - 5
template/home/index.wxml

@@ -1,10 +1,10 @@
 <view class="page">
-    <view class="page__hd" wx:for="{{list}}">
-        <view class="page__pic" bindtap="view" data-id="{{item.id}}"><image class="pic" src="{{item.pic}}"></image></view>
-        <view class="page__title"  bindtap="view" data-id="{{item.id}}">{{item.name}}</view>
+    <view class="page__hd" wx:for="{{list}}" wx:key="{{index}}" bindtap="view" data-id="{{item.id}}">
+        <image class="pic" src="{{item.pic}}" mode="widthFix"></image>
+        <view class="page__title">{{item.name}}</view>
         <view class="page__desc">
-          <view class="price">¥{{item.price}}</view>
-          <view class="button" bindtap="addCarts" data-id="{{item.id}}" data-name="{{item.name}}"><button class="weui-btn mini-btn" type="primary" size="mini">购买</button></view>
+          <text class="price">¥ {{item.price}}</text>
+          <view class="button" bindtap="addCarts" data-id="{{item.id}}" data-name="{{item.name}}"><button class="nxh__button" type="primary" size="mini">购买</button></view>
         </view>
     </view>
 </view>

+ 21 - 24
template/home/index.wxss

@@ -1,40 +1,37 @@
-/* template/home/index.wxss */
-
 .page__hd
 {
-  border:1px solid #DBDBDB;
-  width:70%;
-  margin-left:40rpx;
   margin-top:28rpx;
-
   border-radius: 5px;
-  padding-top:0px;
-
+  box-shadow: 0rpx 3rpx 5rpx #DBDBDB;
+  margin: 28rpx 30rpx 0 30rpx;
+  padding: 0rpx;
 }
-.page__pic
-{
-  display: inline;
-  margin-left:-72rpx;
-}
-
 .pic
 {
   border-top-right-radius: 5px;
   border-top-left-radius: 5px;
-  width:672rpx;
+  width:695rpx;
+}
+.page__title {
+  padding: 0 30rpx 0 30rpx;
+}
+.page__desc 
+{
+  display: flex;
+  flex-direction: row;
+  justify-content: space-between;
+  padding: 0 30rpx 0 30rpx;
+  align-items: center;
+  -ms-flex-item-align: center;
 }
-
 .price
 {
-  float:left;
-  margin-top:5rpx;
-  font-size:16px;
-  color:#ff9900;
+  font-size:36rpx;
+  color:#ff9900; 
 }
 
-.button
+.nxh__button
 {
-  float:right;
-  margin-top:-16px;
-
+  display: flex;
+  width: 180rpx;
 }

+ 49 - 0
template/login/index.js

@@ -0,0 +1,49 @@
+Page({
+  dever: getApp().dever,
+  data: {
+    //判断小程序的API,回调,参数,组件等是否在当前版本可用。
+    canIUse: wx.canIUse('button.open-type.getUserInfo')
+  },
+  onLoad: function (options) {
+    // 查看是否授权
+    wx.getSetting({
+      success(res) {
+        if (res.authSetting['scope.userInfo']) {
+          // 已经授权,可以直接调用 getUserInfo 获取头像昵称
+          wx.getUserInfo({
+            success: function (res) {
+              console.log(res.userInfo)
+            }
+          })
+        }
+      }
+    })
+  },
+  //微信授权回调
+  bindGetUserInfo: function (e) {
+    var that = this;
+    if (e.detail.userInfo) {
+      console.log(e.detail.userInfo);
+      wx.login({
+        success: function (res) {
+          if (res.code) {
+            that.doLogin(res.code);
+          } else {
+            console.log(res.errMsg);
+          }
+        }
+      })
+    } else {
+      console.log("拒绝了授权");
+    }
+  },
+  doLogin: function(wxCode){
+    var that = this;
+    this.dever.request("/wxLogin", {code: wxCode}, {
+      success: function (data, res) {
+        that.dever.goBack();
+      }
+    }, "POST");
+  }
+
+})

+ 3 - 0
template/login/index.json

@@ -0,0 +1,3 @@
+{
+  "navigationBarTitleText": "农小盒"
+}

+ 5 - 0
template/login/index.wxml

@@ -0,0 +1,5 @@
+<view wx:if="{{canIUse}}">
+  <image src='/static/img/logo.png'></image>
+  <button class="nxh__button" open-type="getUserInfo" lang="zh_CN" bindgetuserinfo="bindGetUserInfo">授权登录</button>
+</view>
+<view wx:else>请升级微信版本</view>

+ 16 - 0
template/login/index.wxss

@@ -0,0 +1,16 @@
+page,view {
+  background: #fff;
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+}
+
+image {
+  width: 370rpx;
+  height: 370rpx;
+  margin-top: 200rpx;
+}
+
+.nxh__button {
+  margin-top: 130rpx;
+}

+ 3 - 1
template/view/index.json

@@ -1 +1,3 @@
-{}
+{
+  "navigationBarTitleText": "农小盒"
+}