wangxin 6 年之前
父節點
當前提交
911dfdbdaa
共有 7 個文件被更改,包括 62 次插入35 次删除
  1. 3 9
      app.js
  2. 2 4
      components/cashdialog/index.js
  3. 1 1
      components/cashdialog/index.wxml
  4. 6 4
      components/cashdialog/index.wxss
  5. 4 1
      dever/core.js
  6. 44 11
      template/home/index.js
  7. 2 5
      template/login/index.js

+ 3 - 9
app.js

@@ -1,14 +1,8 @@
 var dever = require('./dever/core.js');
 
 App({
+    dever: dever.load,
     onLaunch: function () {
-        console.log('App Launch');
-    },
-    onShow: function () {
-        console.log('App Show');
-    },
-    onHide: function () {
-        console.log('App Hide');
-    },
-    dever: dever.load
+      this.dever.log('App', 'onLaunch');
+    }
 });

+ 2 - 4
components/cashdialog/index.js

@@ -18,7 +18,6 @@ Component({
   data: {
     // 弹窗显示控制
     isShow: false,
-    isHideErrMsg: true,
     errMsg: '',
     cashCode: ''
   },
@@ -48,10 +47,9 @@ Component({
     getCashCode(){
       return this.data.cashCode;
     },
-    setErrMsg(isHide, _errMsg){
+    setErrMsg(_errMsg){
       this.setData({
-        errMsg: _errMsg,
-        isHideErrMsg: isHide
+        errMsg: _errMsg
       })
     },
     confirmEvent() {

+ 1 - 1
components/cashdialog/index.wxml

@@ -2,7 +2,7 @@
     <view class='dialog-mask' bindtap='hideDialog'></view>
     <view class='dialog-info'>
         <input class='dialog-content' placeholder-class='dialog-hint' placeholder='输入兑换码' type='text' bindinput ="cashCodeInput"></input>
-        <view class='dialog-errmsg' hidden='{{isHideErrmsg}}'>{{errMsg}}</view>
+        <view class='dialog-errmsg'>{{errMsg}}</view>
         <button class='dialog-footer' catchtap='confirmEvent'>{{confirmText}}</button>
     </view>
 </view>

+ 6 - 4
components/cashdialog/index.wxss

@@ -20,7 +20,7 @@
     text-align: center;
     border-radius: 3px;
     overflow: hidden;
-    padding: 90rpx 0 30rpx;
+    padding: 60rpx 0 60rpx;
 }
 .dialog-hint{
     font-size: 50rpx;
@@ -33,10 +33,14 @@
   color: #333;
   border-bottom: 1rpx solid #E5E5E5;
   border-top: 1rpx solid #E5E5E5;
-  margin: 30rpx;
+  margin: 30rpx 30rpx 0 30rpx;
 }
 .dialog-errmsg {
   color: #fc513f;
+  height: 90rpx;
+  display: flex;
+  justify-content: center;
+  align-items: center;
 }
 .dialog-footer{
     background: #539804;
@@ -44,6 +48,4 @@
     border-radius: 50rpx;
     width: 180rpx;
     font-size: 35rpx;
-    margin-top: 60rpx;
-    margin-bottom: 30rpx;
 }

+ 4 - 1
dever/core.js

@@ -50,7 +50,10 @@ var dever =
 
     //获取登录签名串儿
     ,getSignature: function(){
-      return this.getLoginInfo() != null ? this.getLoginInfo().signature : '';
+      if(this.getLoginInfo() == null){
+        return '';
+      }
+      return this.getLoginInfo().signature ? this.getLoginInfo().signature : '';
     }
 
     //设置服务器传过来的公共值

+ 44 - 11
template/home/index.js

@@ -6,8 +6,38 @@ Page({
     isShowNull: false
   },
   onLoad: function (options) {
-    var that = this;
-    if(that.pg == 1){
+    if(this.dever.getSignature() == ''){
+      var that = this;
+      wx.login({
+        success: function (res) {
+          if (res.code) {
+            that.dever.request("passport.applet.bind", {
+              json: 1,
+              code: res.code
+            }, {
+                success: function (data, res) {
+                  that.dever.saveLoginInfo(data);
+                  that.getHomeData(that);
+                },
+                fail: function (res) {
+                  that.dever.log('wx.login', JSON.stringify(res));
+                }
+              });
+          } else {
+            that.dever.log('wx.login', res.errMsg);
+          }
+        }
+      })
+    }else{
+      this.getHomeData(this);
+    }
+  },
+
+  /**
+   * 获取首页数据
+   */
+  getHomeData: function(that){
+    if (that.pg == 1) {
       that.dever.showLoading();
     }
     that.cashdialog = this.selectComponent("#cashdialog");
@@ -16,22 +46,22 @@ Page({
       json: 1,
       pg: that.pg,
       signature: that.dever.getSignature()
-    },{
+    }, {
         success: function (data, res) {
-          if (data.product.length > 0){
-            if(that.pg > 1){
+          if (data.product.length > 0) {
+            if (that.pg > 1) {
               that.dever.appendList(that, data.product);
-            }else{
+            } else {
               that.dever.setList(that, data.product);
             }
             that.pg++;
             that.dever.set(that, 'isShowNull', false);
-          }else{
+          } else {
             that.dever.set(that, 'isShowNull', true);
           }
           that.dever.hideLoading();
         }
-    });
+      });
   },
 
   /**
@@ -53,7 +83,7 @@ Page({
     var that = this;
     this.dever.isLogin(function (res) {
       if (res) {
-        that.cashdialog.setErrMsg(true, '');
+        that.cashdialog.setErrMsg('');
         that.cashdialog.showDialog();
       } else {
         that.dever.location('login/index');
@@ -69,7 +99,7 @@ Page({
     var cashCode = this.cashdialog.getCashCode();
 
     if (cashCode.length <= 0) {
-      that.cashdialog.setErrMsg(false, '请输入兑换码!');
+      that.cashdialog.setErrMsg('请输入兑换码!');
       return ;
     }
     that.dever.request('product.api.checkCode', {
@@ -83,7 +113,7 @@ Page({
         },
         fail: function (res) {
           that.dever.log('product.api.checkCode', res);
-          that.cashdialog.setErrMsg(false, res.data.msg);
+          that.cashdialog.setErrMsg(res.data.msg);
         }
     });
   },
@@ -103,6 +133,9 @@ Page({
     });
   },
 
+  /**
+   * 页面下拉事件的处理函数
+   */
   onPullDownRefresh: function () {
     this.pg = 1;
     this.dever.startPullDown(this);

+ 2 - 5
template/login/index.js

@@ -44,15 +44,12 @@ Page({
     wx.login({
       success: function (res) {
         if (res.code) {
-          that.dever.request("passport.applet.bind"
-          ,{
+          that.dever.request("passport.applet.bind",{
              json: 1,
              code: res.code 
-          }
-          ,{
+          },{
             success: function (data, res) {
               that.dever.saveLoginInfo(data);
-              var loginInfo = that.dever.getLoginInfo();
               that.checkAuth();
               that.dever.goBack();
             },