wangxin 6 years ago
parent
commit
f90bf6010f

+ 206 - 5
app.js

@@ -1,8 +1,209 @@
-var dever = require('./dever/core.js');
+//引入公共方法
+const dever = require('./dever/core.js');
 
 App({
-    dever: dever.load,
-    onLaunch: function () {
-      this.dever.log('App', 'onLaunch');
+
+  /**
+   * 保存邀请人id
+   */
+  saveInviteUid(uid){
+    dever.save('invite_uid', uid);
+  },
+
+  /**
+   * 获取邀请人id
+   */
+  getInviteUid(){
+    let inviteUid = dever.getSave('invite_uid')
+    return inviteUid == null ? '': inviteUid;
+  },
+
+  /**
+   * 判断是否登录状态
+   */
+  isLogin: function (fun){
+    return dever.getSign() == '' ? false : true;
+  },
+
+  /**
+   * 获取用户id
+   */
+  getUid: function(){
+    return dever.getUid();
+  },
+
+  /**
+    * 设置模板变量[单个]
+    */
+  set: function (self, key, value) {
+    var data = {};
+    data[key] = value;
+    this.sets(self, data);
+  },
+
+  /**
+   * 设置模板变量[多个]
+   */
+  sets: function (self, data) {
+    self.setData(data);
+  },
+
+  /**
+   * 设置模板变量[列表]
+   */
+  setList: function (self, value, isAppend) {
+    if (isAppend) {
+      let list = self.data.list;
+      for (var i = 0; i < value.length; i++) {
+        list.push(value[i]);
+      }
+      this.set(self, 'list', list);
+    } else {
+      this.set(self, 'list', value);
     }
-});
+  },
+
+  /**
+   * 获取模板里传过来的data
+   */
+  getData: function (event) {
+    return event.currentTarget.dataset;
+  },
+
+  /**
+   * Toast提示框 3s消失
+   */
+  toast: function (msg, title) {
+    wx.showToast({
+      title: msg,
+      icon: 'none',
+      duration: 3000
+    });
+  },
+
+  /**
+   * 解析html
+   */
+  html: function (bindName, data, target) {
+    var wxParse = dever.package('wxParse/wxParse');
+    wxParse.wxParse(bindName, 'html', data, target, 0);
+  },
+
+  /**
+   * 跳转页面
+   */
+  location: function (url) {
+    dever.log('location', url);
+    wx.navigateTo({
+      url: '../../template/' + url,
+    })
+  },
+
+  /**
+   * 重定向页面
+   */
+  redirect: function (url) {
+    dever.log('redirect', url);
+    wx.redirectTo({
+      url: '../../template/' + url,
+    })
+  },
+
+  /**
+   * 回退 delta 返回的页面数,如果 delta 大于现有页面数,则返回到首页
+   */
+  goBack: function (delta) {
+    if (typeof delta != 'number') delta = 1;
+    wx.navigateBack({
+      delta: delta
+    })
+  },
+
+  /**
+   * 开始下拉刷新
+   */
+  startPullDown: function (self) {
+    wx.showNavigationBarLoading();
+    self.onLoad();
+  },
+
+  /**
+   * 停止下拉刷新
+   */
+  stopPullDown: function () {
+    wx.hideNavigationBarLoading();
+    wx.stopPullDownRefresh();
+  },
+
+  /**
+   * 显示加载中[数据交互动画]
+   */
+  showLoading: function () {
+    wx.showLoading({
+      title: '加载中',
+      mask: true
+    })
+  },
+
+  /**
+   * 隐藏加载中
+   */
+  hideLoading: function () {
+    wx.hideLoading();
+  },
+
+  /**
+   * 海报分享,路径附带的参数 encodeURIComponent(uid,product_id)
+   */
+  getSceneArray: function(scene){
+    let str = decodeURIComponent(scene);
+    return str.split(',');//[0] = uid [1] = product_id
+  },
+
+  /**
+   * http请求
+   * url 请求路径 
+   * param 请求参数 {}
+   * callback 回调方法 {success fail complete}
+   * method 请求方式 OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
+   */
+  request: function (url, param, callback, method){
+    if (!param) param = {};
+    
+    //是否返回json格式的数据1为返回2为不返回
+    param['json'] = 1;
+    
+    //用于登录后的uid验证,每次都要传入
+    param['signature'] = dever.getSign();
+
+    var that = this;
+
+    dever.package('network').request(dever, url, param, {
+      success: function(res){
+        if (res.data.status == 1) {
+          let data = res.data.data;
+          if (data.config) {
+            dever.setSetting(data.config);
+          }
+          if (url == 'passport.applet.bind'){
+            dever.saveLoginInfo(data);
+          }
+          callback.success(data, res);
+        } else {
+          callback.fail(res);
+        }
+      },
+      fail: function(res){
+        callback.fail(res);
+      },
+      complete: function(res){
+        if(callback.complete){
+          callback.complete(res);
+        }
+        that.stopPullDown();
+        dever.log('request ' + url, res);
+      }
+    }, method);
+  }
+
+})

+ 1 - 1
app.wxss

@@ -3,7 +3,7 @@
 
 page{
     background-color: #FFFFFF;
-    font-size: 16px;
+    font-size: 36rpx;
     font-family: -apple-system-font,Helvetica Neue,Helvetica,sans-serif;
 }
 .nxh__button {

+ 5 - 6
components/cashdialog/index.wxss

@@ -23,17 +23,16 @@
     padding: 60rpx 0 60rpx;
 }
 .dialog-hint{
-    font-size: 50rpx;
+    font-size: 40rpx;
     color: #707070;
 }
 .dialog-content{
   height: 100rpx;
   padding: 30rpx;
-  font-size: 50rpx;
+  font-size: 40rpx;
   color: #333;
-  border-bottom: 1rpx solid #E5E5E5;
-  border-top: 1rpx solid #E5E5E5;
-  margin: 30rpx 30rpx 0 30rpx;
+  border: 1rpx solid #539804;
+  margin: 30rpx 60rpx 0 60rpx;
 }
 .dialog-errmsg {
   color: #fc513f;
@@ -46,6 +45,6 @@
     background: #539804;
     color: #fff;
     border-radius: 50rpx;
-    width: 180rpx;
+    width: 220rpx;
     font-size: 35rpx;
 }

+ 4 - 5
dever/config.js

@@ -1,8 +1,7 @@
 var config = 
 {
     // 域名
-    host : 
-    {
+    host: {
         // 主域名
         'main': 'http://192.168.33.10/leek/product/?l=',
         'product': 'https://api.nongchanghezi.com/product/?l=',
@@ -10,13 +9,13 @@ var config =
     },
 
     // 项目id
-    project : 1,
+    project: 1,
 
     //版本号
-    version : '1.0.0',
+    version: '1.0.0',
 
     //debug模式
-    debug : true
+    debug: true
 }
 
 module.exports = {

+ 85 - 190
dever/core.js

@@ -1,218 +1,113 @@
+/**
+ * 公共方法
+ */
+var dever = {
 
-//公共方法,写的匆忙。暂时先扔这里吧。
-var dever =
-{
-    //初始化
-    init : function()
-    {
-        if (!this.config) {
-          this.config = require('config.js').config;
-          this.setting = {};
-          this.log('init config', this.config);
-        }
-    }
+    /**
+     * 初始化配置文件
+     */
+    init: function(){
+      if (!this.config) {
+        this.config = require('config.js').config;
+        this.setting = {};
+        this.log('init config', this.config);
+      }
+    },
 
-    //设置title
-    ,title : function(title)
-    {
+    /**
+     * 设置顶部导航栏标题
+     */
+    title: function(title){
       wx.setNavigationBarTitle({
         title: title
       })
-    }
+    },
 
-    //获取模板里传过来的data
-    ,getData : function(event)
-    {
-      return event.currentTarget.dataset;
-    }
-
-    //保存数据到存储器
-    ,save : function(key, value)
-    {
+    /**
+     * 保存数据到存储器
+     */
+    save: function(key, value){
       wx.setStorageSync(key, value);
       this.log('save ' + key, value);
-    }
+    },
 
-    //读取保存数据到存储器
-    ,getSave: function (key) {
+    /**
+     * 读取保存数据到存储器
+     */
+    getSave: function (key) {
       return wx.getStorageSync(key);
-    }
-
-    //保存登录信息
-    ,saveLoginInfo: function(value){
-      this.save('applet.bind', value);
-    }
-
-    //获取登录信息
-    ,getLoginInfo: function(){
-      return this.getSave('applet.bind');
-    }
+    },
 
-    //获取登录签名串儿
-    ,getSignature: function(){
-      if(this.getLoginInfo() == null){
-        return '';
+    /**
+     * 设置服务器传过来的公共值
+     */
+    setSetting: function(value){
+      this.setting = value;
+      if (value.title) {
+        this.title(value.title);
+      } else if(value.name) {
+        this.title(value.name);
       }
-      return this.getLoginInfo().signature ? this.getLoginInfo().signature : '';
-    }
+      this.log('init server setting', this.setting);
+    },
 
-    //设置服务器传过来的公共值
-    ,setSetting : function(value)
-    {
-        this.setting = value;
-        this.log('init server setting', this.setting);
-        if (value.title) {
-          this.title(value.title);
-        } else if(value.name) {
-          this.title(value.name);
-        }
-    }
-
-    //设置模板变量
-    ,set : function(self, key, value)
-    {
-      var data = {};
-      data[key] = value;
-      this.sets(self, data);
-    }
+    /**
+     * 获取包
+     */
+    package: function(name){
+      return require('package/' + name + '.js');
+    },
 
-    //设置模板变量
-    ,setList: function (self, value) {
-      this.set(self, 'list', value);
-    }
+    /**
+     * 保存登录信息
+     * vid Number 微信id
+     * uid Number 用户id
+     * signature String 用于登录后的uid验证,每次都要传入
+     */
+    saveLoginInfo: function (obj) {
+      this.save('applet.bind', obj);
+    },
 
-    //设置模板变量
-    ,sets: function (self, data) {
-      this.log('data', data);
-      self.setData(data);
-    }
+    /**
+     * 获取登录信息
+     */
+    getLoginInfo: function () {
+      return this.getSave('applet.bind');
+    },
 
-    //列表分页追加
-    , appendList: function (self, value) {
-      var list = self.data.list;
-      for(var i=0; i<value.length; i++){
-        list.push(value[i]); 
+    /**
+     * 获取签名串儿
+     */
+    getSign: function () {
+      let loginInfo = this.getLoginInfo();
+      if (loginInfo == null) {
+        return '';
       }
-      this.setList(self, list);
-    }
-
-    //设置模板变量
-    , setView: function (self, value) {
-      this.set(self, 'view', value);
-    }
-
-    //获取包
-    ,package : function(name)
-    {
-        return require('package/' + name + '.js');
-    }
-
-    //html解析
-    , html: function (bindName, data, target)
-    {
-        var wxParse = this.package('wxParse/wxParse');
-        wxParse.wxParse(bindName, 'html', data, target, 0);
-    }
-
-    //获取请求
-    ,request : function(url, param, callback, method)
-    {
-        if (!method) {
-            method = 'get';
-        }
-        return this.package('network').request(this, url, param, callback, method);
-    }
-
-    //提示框
-    ,alert : function(msg, title)
-    {
-        wx.showToast({
-          title: msg,
-          icon: 'none',
-          duration: 3000
-        });
-    }
-
-    //跳转
-    ,location : function(url)
-    {
-        this.log('location', url);
-        wx.navigateTo({
-          url: '../../template/' + url,
-        })
-    }
+      return loginInfo.signature ? loginInfo.signature : '';
+    },
 
     /**
-     * 重定向页面
+     * 获取用户id
      */
-    ,redirect: function(url){
-      this.log('redirect', url);
-      wx.redirectTo({
-        url: '../../template/' + url,
-      })
-    }
-
-    //回退 delta 返回的页面数,如果 delta 大于现有页面数,则返回到首页。
-    ,goBack: function(delta){
-      if(typeof delta != 'number') delta = 1;
-      wx.navigateBack({
-        delta: delta
-      })
-    }
+    getUid: function(){
+      let loginInfo = this.getLoginInfo();
+      if (loginInfo == null) {
+        return '';
+      }
+      return loginInfo.uid ? loginInfo.uid : '';
+    },
 
-    //log
-    ,log : function(title, msg)
-    {
+    /**
+     * 打印日志
+     */
+    log : function(title, msg){
       if (this.config.debug) {
         console.log('dever debug -- ' + title, msg);
       }
     }
-
-    //开始下拉刷新
-    ,startPullDown : function(self)
-    {
-      wx.showNavigationBarLoading();
-      self.onLoad();
-    }
-
-    //停止下拉刷新
-    ,stopPullDown: function () {
-      wx.hideNavigationBarLoading();
-      wx.stopPullDownRefresh();
-    }
-
-    //加载购物车
-    ,carts: function(self, save, path)
-    {
-      this.package('carts').load(self, save, path);
-    }
-
-    //显示加载中...
-    ,showLoading: function(){
-      wx.showLoading({
-        title: '加载中',
-        mask: true
-      })
-    }
     
-    //隐藏加载中...
-    ,hideLoading: function(){
-      wx.hideLoading();
-    }
-
-    //检查用户是否登录状态,暂支持微信登录
-    ,isLogin: function(fun){
-      wx.checkSession({
-        success: function(res){
-          fun(true);
-        },
-        fail: function(res){
-          fun(false);
-        }
-      })    
-    }
 }
+
 dever.init();
-module.exports = {
-    load: dever
-}
+
+module.exports = dever;

+ 0 - 46
dever/package/carts.js

@@ -1,46 +0,0 @@
-//dever 购物车组件
-var carts = {
-  init: function (page, save, path) {
-    var self = this;
-    self.page = page;
-    self.save = save;
-    self.data = {};
-    self.price = 0;
-    self.total = 0;
-    self.path = path;
-    self.dever = self.page.dever;
-    self.dever.log('carts init', save);
-    //初始化公共方法
-    page.addCarts = function (event)
-    {
-      self.dever.log('event', event);
-      var data = self.dever.getData(event);
-      if (data && data.id) {
-        self.dever.log('carts add', data.name + '(' + data.id + ')');
-        if (!self.data[data.id]) {
-          self.data[data.id] = data;
-          self.data[data.id]['num'] = 1;
-        } else {
-          self.data[data.id]['num']++;
-        }
-
-        self.total++;
-        self.dever.log('carts data', self.data);
-        self.dever.set(self.page, 'carts_total', self.total);
-        self.dever.save('carts', self.data);
-        //调取购物车后端接口
-        if (self.save) {
-
-        }
-        if (self.path) {
-          self.dever.location(self.path);
-        }
-      }
-    }
-    return self;
-  }
-}
-
-module.exports = {
-  load:carts.init
-}

+ 24 - 35
dever/package/network.js

@@ -1,41 +1,30 @@
 // method OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
-function request(dever, url, param, callback, method, header)
-{
-    if (!header) {
-        var header = {};
-        header['content-type'] = 'application/x-www-form-urlencoded';
-    }
+function request(dever, url, param, callback, method, header){
+  if(!method) {
+    method = 'get';
+  }
+  
+  if (!header) {
+      var header = {};
+      header['content-type'] = 'application/x-www-form-urlencoded';
+  }
 
-    for (var i in dever.config.host) {
-        if (url.indexOf(i + '.') != -1) {
-            url = url.replace(i + '.', dever.config.host[i]);
-            break;
-        }
-    }
+  for (var i in dever.config.host) {
+      if (url.indexOf(i + '.') != -1) {
+          url = url.replace(i + '.', dever.config.host[i]);
+          break;
+      }
+  }
 
-    wx.request(
-    {
-        url: url,
-        data: param,
-        method: method.toUpperCase(), 
-        header: header,
-        success: function (res) {
-          if (res.data.status == 1) {
-              if (res.data.data.config) {
-                dever.setSetting(res.data.data.config);
-              }
-              callback.success(res.data.data, res);
-          } else {
-              callback.fail(res);
-          }
-        },
-        fail: function (res) {
-            callback.fail(res);
-        },
-        complete: function () {
-          dever.stopPullDown();
-        }
-    })
+  wx.request({
+      url: url,
+      data: param,
+      method: method.toUpperCase(), 
+      header: header,
+      success: callback.success,
+      fail: callback.fail,
+      complete: callback.complete
+  })
 }
 
 module.exports = {

+ 0 - 83
dever/package/share.js

@@ -1,83 +0,0 @@
-var app = getApp();
-var network = require('./network.js')
-
-
-function share(newsname, Thepath,newsid, typevalue){
-  if (!typevalue) {
-    typevalue = 1
-  }
-  var _this = this;
-
-  var params = new Object()
-  params.uid = app.getUid()
-  params.session = app.getSession()
-  params.type = typevalue
-  params.id = newsid
-  params.status = 1
-  params.content = newsname
-  console.log(params)
-  //发起请求
-  network.GET(
-    {
-      turl: 'share.submit',
-      params: params,
-      success: function (res) {
-      },
-      fail: function () {
-        //失败后的逻辑
-      },
-    })
-
-  return {
-    title: newsname,
-    path: Thepath + newsid + '&share_uid=' + app.getUid() + '&share_id=' + newsid + '&share_table=' + typevalue,
-    success: function (res) {
-      var params = new Object()
-      params.uid = app.getUid()
-      params.session = app.getSession()
-      params.type = typevalue
-      params.id = newsid
-      params.status = 2
-      params.content = newsname
-      console.log(params)
-      //发起请求
-      network.GET(
-        {
-          turl: 'share.submit',
-          params: params,
-          success: function (res) {
-          },
-          fail: function () {
-            //失败后的逻辑
-          },
-        })
-    },
-    fail: function () {
-      //失败后的逻辑
-
-      var params = new Object()
-      params.uid = app.getUid()
-      params.session = app.getSession()
-      params.type = 1
-      params.id = newsid
-      params.status = 3
-      params.content = newsname
-      //发起请求
-      network.GET(
-        {
-          turl: 'share.submit',
-          params: params,
-          success: function (res) {
-          },
-          fail: function () {
-            //失败后的逻辑
-          },
-        })
-    },
-  }
-
-}
-
-module.exports = {
-  share: share,
-}

+ 32 - 35
template/carts/index.js

@@ -1,5 +1,6 @@
+const app = getApp();
+
 Page({
-  dever: getApp().dever,
   authdialog: null,
   product_ids: '',
   product_num: '',
@@ -9,16 +10,14 @@ Page({
   },
   onLoad: function (options) {
     var that = this;
-    that.dever.showLoading();
+    app.showLoading();
     //获取自定义授权组件
     that.authdialog = this.selectComponent("#authdialog");
-    that.dever.request('product.api.carts',{
-      signature: that.dever.getSignature()
-    },{
+    app.request('product.api.carts',{},{
       success: function(data, res){
-        that.dever.setList(that, data.carts);
+        app.setList(that, data.carts);
         that.doSettlement();
-        that.dever.hideLoading();
+        app.hideLoading();
       }
     });
   },
@@ -32,20 +31,18 @@ Page({
     if (e == null && arguments.length==2){
       pid = arguments[1];
     }else{
-      pid = e.currentTarget.dataset.id;
+      pid = app.getData(e).id;
     }
     var delfun = function(){
-      that.dever.request('product.api.delCarts',{
-        json: 1,
-        signature: that.dever.getSignature(),
+      app.request('product.api.delCarts',{
         product_id: pid
       },{
         success: function(data, res){
-          that.dever.alert('删除商品成功!');
+          app.toast('删除商品成功!');
           that.onLoad();
         },
         fail: function(res){
-          that.dever.alert('删除商品失败!');
+          app.toast('删除商品失败!');
         }
       });
     }
@@ -63,7 +60,7 @@ Page({
    * 减少商品数量>0 and <=1
    */
   doSub: function(e){
-    var id = e.currentTarget.dataset.id;
+    var id = app.getData(e).id;
     var list = this.data.list;
     for(var i=0; i<list.length; i++){
       if (list[i].product_id == id){
@@ -77,14 +74,14 @@ Page({
         break;
       }
     }
-    this.dever.setList(this, list);
+    app.setList(this, list);
     this.doSettlement();
   },
   /**
    * 增加商品数量>1 and <=库存
    */
   doAdd: function(e){
-    var id = e.currentTarget.dataset.id;
+    var id = app.getData(e).id;
     var list = this.data.list;
     for (var i = 0; i < list.length; i++) {
       if (list[i].product_id == id) {
@@ -92,7 +89,7 @@ Page({
         break;
       }
     }
-    this.dever.setList(this, list);
+    app.setList(this, list);
     this.doSettlement();
   },
 
@@ -115,35 +112,39 @@ Page({
         this.product_num += ',' + num;
       }
     }
-    this.dever.set(this, 'settlement', count.toFixed(2));
+    app.set(this, 'settlement', count.toFixed(2));
   },
 
   /**
-   * 支付
+   * 立即支付
    */
-  doPay: function(e){
+  doPay: function(){
     var that = this;
     var addrObj = that.data.addrObj;
     if (!addrObj){
-      that.dever.alert('请选择收货地址');
+      app.toast('请选择收货地址');
     }
-    that.dever.request('product.api.buy',{
-      signature: that.dever.getSignature(),
+    app.request('product.api.buy',{
       product_id: that.product_ids,
       num: that.product_num,
       name: addrObj.userName,
       address: addrObj.provinceName + addrObj.cityName + addrObj.countyName + addrObj.detailInfo,
-      mobile: addrObj.telNumber
+      mobile: addrObj.telNumber,
+      invite_uid: app.getInviteUid()
     },{
       success:function(data, res){
-        that.dever.redirect('pay/index');
-        that.dever.log('doPay success', res);
+        app.saveInviteUid('');
+        var id = that.product_ids;
+        let idx = ids.indexOf(',');
+        if (idx > -1) {
+          id = id.substring(0, idx);
+        }
+        app.redirect('pay/index?id='+id);
       },
       fail: function(res){
-        that.dever.alert('支付失败!');
-        that.dever.log('doPay fail', res);
+        app.toast('支付失败!');
       }
-    });
+    })
   },
 
   /**
@@ -154,12 +155,8 @@ Page({
     var success = function(){
       wx.chooseAddress({
         success: function (res) {
-          that.dever.log('wx.chooseAddress', res);
-          that.dever.set(that,'addrObj', res);
-          that.dever.set(that,'isUseAddress', true);
-        },
-        fail: function (res) {
-          that.dever.log('wx.chooseAddress', 'fail');
+          app.set(that,'addrObj', res);
+          app.set(that,'isUseAddress', true);
         }
       })
     }

+ 32 - 36
template/cash/index.js

@@ -1,5 +1,6 @@
+const app = getApp();
+
 Page({
-  dever: getApp().dever,
   authdialog: null,
   product_ids: '',
   cash_code: '',
@@ -9,24 +10,20 @@ Page({
   },
   onLoad: function (options) {
     var that = this;
-    that.dever.showLoading();
+    app.showLoading();
     //获取自定义授权组件
-    that.authdialog = this.selectComponent("#authdialog");
+    this.authdialog = this.selectComponent("#authdialog");
     //获取兑换商品信息
-    that.cash_code = options.code;
-    that.dever.request('product.api.checkCode',{
-      signature: that.dever.getSignature(),
-      code: that.cash_code
-    },{
-      success: function(data, res){
-        that.dever.setList(that, data.product);
-        that.doSettlement();
-        that.dever.hideLoading();
-      },
-      fail: function(res){
-        that.dever.log('product.api.checkCode', res);
-      }
-    });
+    this.cash_code = options.code;
+    app.request('product.api.checkCode',{
+        code: that.cash_code
+      },{
+        success: function(data, res){
+          app.setList(that, data.product);
+          that.doSettlement();
+          app.hideLoading();
+        }
+    })
   },
 
   /**
@@ -45,36 +42,39 @@ Page({
         this.product_ids += ',' + product_id;
       }
     }
-    this.dever.set(this, 'settlement', count.toFixed(2));
+    app.set(this, 'settlement', count.toFixed(2));
   },
 
   /**
-   * 去支付
+   * 立即兑换
    */
   doCash: function(e){
     var that = this;
-    var addrObj = that.data.addrObj;
+    var addrObj = this.data.addrObj;
     if (!addrObj) {
-      that.dever.alert('请选择收货地址');
+      app.toast('请选择收货地址');
     }
-    that.dever.request('product.api.code',{
-      json: 1,
-      signature: that.dever.getSignature(),
+    app.request('product.api.code',{
       product_id: that.product_ids,
       code: that.cash_code,
       name: addrObj.userName,
       address: addrObj.provinceName + addrObj.cityName + addrObj.countyName + addrObj.detailInfo,
-      mobile: addrObj.telNumber
+      mobile: addrObj.telNumber,
+      invite_uid: app.getInviteUid()
     },{
       success:function(data, res){
-        that.dever.redirect('pay/index');
-        that.dever.log('doCash success', res);
+        app.saveInviteUid('');
+        var id = that.product_ids;
+        let idx = ids.indexOf(',');
+        if (idx > -1) {
+          id = id.substring(0, idx);
+        }
+        app.redirect('pay/index?id=' + id);
       },
       fail: function(res){
-        that.dever.alert('兑换失败!');
-        that.dever.log('doCash fail', res);
+        app.toast('兑换失败!');
       }
-    });
+    })
   },
 
   /**
@@ -85,12 +85,8 @@ Page({
     var success = function(){
       wx.chooseAddress({
         success: function (res) {
-          that.dever.log('wx.chooseAddress', res);
-          that.dever.set(that,'addrObj', res);
-          that.dever.set(that,'isUseAddress', true);
-        },
-        fail: function (res) {
-          that.dever.log('wx.chooseAddress', 'fail');
+          app.set(that,'addrObj', res);
+          app.set(that,'isUseAddress', true);
         }
       })
     }

+ 1 - 1
template/cash/index.wxml

@@ -28,5 +28,5 @@
 </view>
 <view class='bottom'>
   <view class='left'>合计 ¥{{settlement}} 元</view>
-  <view class='right' bindtap='doCash'>立即兑换</view>
+  <view class='right' bindtap='doCash'>确定</view>
 </view>

+ 29 - 62
template/home/index.js

@@ -1,35 +1,29 @@
+const app = getApp();
+
 Page({
-  dever: getApp().dever,
   cashdialog: null,
   pg: 1,
   data: {
     isShowNull: false
   },
   onLoad: function (options) {
-    if(this.dever.getSignature() == ''){
+    if (app.isLogin){
+      this.getHomeData(this);
+    }else{
       var that = this;
       wx.login({
         success: function (res) {
           if (res.code) {
-            that.dever.request("passport.applet.bind", {
-              json: 1,
+            app.request("passport.applet.bind", {
               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);
     }
   },
 
@@ -38,28 +32,26 @@ Page({
    */
   getHomeData: function(that){
     if (that.pg == 1) {
-      that.dever.showLoading();
+      app.showLoading();
     }
-    that.cashdialog = this.selectComponent("#cashdialog");
-    that.dever.set(that, 'loadMoreText', '正在加载');
-    that.dever.request('product.api.home', {
-      json: 1,
-      pg: that.pg,
-      signature: that.dever.getSignature()
+    that.cashdialog = that.selectComponent("#cashdialog");
+    app.set(that, 'loadMoreText', '正在加载');
+    app.request('product.api.home', {
+      pg: that.pg
     }, {
         success: function (data, res) {
           if (data.product.length > 0) {
             if (that.pg > 1) {
-              that.dever.appendList(that, data.product);
+              app.setList(that, data.product, true);
             } else {
-              that.dever.setList(that, data.product);
+              app.setList(that, data.product);
             }
             that.pg++;
-            that.dever.set(that, 'isShowNull', false);
+            app.set(that, 'isShowNull', false);
           } else {
-            that.dever.set(that, 'isShowNull', true);
+            app.set(that, 'isShowNull', true);
           }
-          that.dever.hideLoading();
+          app.hideLoading();
         }
       });
   },
@@ -68,27 +60,20 @@ Page({
    * 查看商品详情
    */
   view: function (event) {
-    if (typeof (event) == 'object') {
-      var id = event.currentTarget.dataset.id
-    } else {
-      var id = event
-    }
-    this.dever.location('view/index?id=' + id);
+    let id = app.getData(event).id;
+    app.location('view/index?id=' + id);
   },
 
   /**
    * 礼品卡兑换
    */
   cash: function(e){
-    var that = this;
-    this.dever.isLogin(function (res) {
-      if (res) {
-        that.cashdialog.setErrMsg('');
-        that.cashdialog.showDialog();
-      } else {
-        that.dever.location('login/index');
-      }
-    });
+    if(app.isLogin()){
+      this.cashdialog.setErrMsg('');
+      this.cashdialog.showDialog();
+    }else{
+      app.location('login/index');
+    }
   },
 
   /**
@@ -102,49 +87,31 @@ Page({
       that.cashdialog.setErrMsg('请输入兑换码!');
       return ;
     }
-    that.dever.request('product.api.checkCode', {
-      json: 1,
-      signature: that.dever.getSignature(),
+    app.request('product.api.checkCode', {
       code: cashCode
     }, {
         success: function (data, res) {
           that.cashdialog.hideDialog();
-          that.dever.location('cash/index?code=' + cashCode);
+          app.location('cash/index?code=' + cashCode);
         },
         fail: function (res) {
-          that.dever.log('product.api.checkCode', res);
           that.cashdialog.setErrMsg(res.data.msg);
         }
     });
   },
 
-  /**
-   * 添加购物车
-   */
-  doBuy: function (event){
-    var that = this;
-    var id = event.currentTarget.dataset.id;
-    this.dever.isLogin(function(res){
-      if(res){
-        that.dever.location('view/index?id=' + id);
-      }else{
-        that.dever.location('login/index');
-      }
-    });
-  },
-
   /**
    * 页面下拉事件的处理函数
    */
   onPullDownRefresh: function () {
     this.pg = 1;
-    this.dever.startPullDown(this);
+    app.startPullDown(this);
   },
 
   /**
    * 页面上拉触底事件的处理函数
    */
   onReachBottom: function () {
-    this.dever.startPullDown(this);
+    app.startPullDown(this);
   },
 })

+ 2 - 5
template/home/index.wxml

@@ -2,10 +2,7 @@
     <view class="page_item" wx:for="{{list}}" wx:key="{{index}}" bindtap="view" data-id="{{item.id}}">
         <image class="item_pic" src="{{item.pic}}" mode="widthFix"></image>
         <view class="item_title">{{item.name}}</view>
-        <view class="item_desc">
-          <text class="price">¥ {{item.price}}</text>
-          <button class="nxh__button nxh__button2" catchtap='doBuy' data-id="{{item.id}}" data-name="{{item.name}}">购买</button>
-        </view>
+        <view class="item_price">¥ {{item.price}}</view>
     </view>
     <view class="item_null" wx:if='{{isShowNull}}'>
       <view class='left_line' />
@@ -19,4 +16,4 @@
 </view>
 
 <!-- 礼品卡兑换弹框 -->
-<cashdialog id='cashdialog' confirmText='兑换' bindcustomevent='toCash'></cashdialog>
+<cashdialog id='cashdialog' confirmText='立即兑换' bindcustomevent='toCash'></cashdialog>

+ 12 - 11
template/home/index.wxss

@@ -7,6 +7,10 @@
   margin: 30rpx;
   padding: 0rpx;
   overflow: hidden;
+  display: flex;
+  flex-direction: column;
+  justify-content: center;
+  align-items: center;
 }
 .item_pic{
   border-top-right-radius: 5px;
@@ -14,24 +18,21 @@
   width:695rpx;
 }
 .item_title {
+  display: flex;
+  justify-content: center;
+  align-items: center;
+  text-align: center;
   padding: 0 30rpx 0 30rpx;
+  font-size: 36rpx;
 }
-.item_desc {
+.item_price {
   display: flex;
   flex-direction: row;
-  justify-content: space-between;
-  padding: 0 30rpx 0 30rpx;
+  justify-content: center;
+  padding: 30rpx;
   align-items: center;
-}
-.item_desc .price {
   font-size:36rpx;
   color:#ff9900; 
-  display: flex;
-  flex-grow: 1;
-}
-.nxh__button2{
-  width: 180rpx;
-  margin-bottom: 25rpx;
 }
 .item_null {
   margin: 50rpx 30rpx 30rpx 30rpx;

+ 35 - 40
template/login/index.js

@@ -1,33 +1,33 @@
+const app = getApp();
+
 Page({
-  dever: getApp().dever,
+  
   data: {
     //判断小程序的API,回调,参数,组件等是否在当前版本可用。
     canIUse: wx.canIUse('button.open-type.getUserInfo')
   },
-  onLoad: function (options) {
-    //TODO 
-  },
 
-  // 微信授权回调
+  /**
+   * 微信授权回调
+   */
   bindGetUserInfo: function (e) {
-    var that = this;
     if (e.detail.userInfo) {
-      that.wxLogin();
+      this.wxLogin();
     } else {
-      that.dever.log("用户拒绝授权");
+      //TODO 用户拒绝了授权
     }
   },
 
-  // 查看是否授权,须在登录后调用
+  /**
+   * 查看是否授权,须在登录后调用
+   */
   checkAuth: function(){
     var that = this;
-    // 查看是否授权
     wx.getSetting({
       //是否带上登录态信息, true 返回的数据会包含 encryptedData, iv 等敏感信息
       withCredentials: true,
       success(res) {
         if (res.authSetting['scope.userInfo']) {
-          // 已经授权,可以直接调用 getUserInfo 获取头像昵称
           wx.getUserInfo({
             success: function (res) {
               that.updateUserInfo(res);
@@ -35,54 +35,49 @@ Page({
           })
         }
       }
-    });
+    })
   },
 
-  //微信登录
+  /**
+   * 微信登录
+   */
   wxLogin: function(){
     var that = this;
     wx.login({
       success: function (res) {
         if (res.code) {
-          that.dever.request("passport.applet.bind",{
-             json: 1,
+          app.request("passport.applet.bind",{
              code: res.code 
           },{
             success: function (data, res) {
-              that.dever.saveLoginInfo(data);
               that.checkAuth();
-              that.dever.goBack();
-            },
-            fail: function(res){
-              that.dever.log('wx.login', JSON.stringify(res));
+              app.goBack();
             }
-          });
-        } else {
-          that.dever.log('wx.login', res.errMsg);
+          })
         }
       }
-    });
+    })
   },
 
-  //更新用户信息
+  /**
+   * 更新用户信息
+   */
   updateUserInfo: function (wxObj){
     var that = this;
     var userInfo = wxObj.userInfo;
-    var loginInfo = that.dever.getLoginInfo();
-    that.dever.request('passport.applet.update'
-    ,{
-      nickname: userInfo.nickName,
-      avatarurl: userInfo.avatarUrl,
-      iv: wxObj.iv,
-      encryptedData: wxObj.encryptedData,
-      vid: loginInfo.vid,
-      uid: loginInfo.uid,
-      signature: loginInfo.signature
-    }
-    ,{
-      success: function(data, res){
-        that.dever.log('applet.update', '用户信息更新成功~');
-      }
+    var loginInfo = app.getLoginInfo();
+    app.request('passport.applet.update',{
+        nickname: encodeURIComponent(userInfo.nickName),
+        avatarurl: userInfo.avatarUrl,
+        iv: wxObj.iv,
+        encryptedData: wxObj.encryptedData,
+        vid: loginInfo.vid,
+        uid: loginInfo.uid,
+        signature: loginInfo.signature
+      } ,{
+        success: function(data, res){
+          //TODO 更新成功~
+        }
     }, 'POST');
   }
 

+ 3 - 4
template/pay/index.js

@@ -1,18 +1,17 @@
+const app = getApp();
 Page({
-  dever: getApp().dever,
   data: {
     
   },
 
   onLoad: function (options) {
-    //that.dever.getSignature()
-    //that.dever.showLoading();
+    //invite_uid
   },
 
   /**
    * 跳转海报分享页面,分享海报
    */
   toShare: function(){
-    this.dever.redirect('poster/index');
+    app.redirect('poster/index');
   }
 })

+ 25 - 25
template/poster/index.js

@@ -1,40 +1,31 @@
+const app = getApp();
+
 Page({
-  dever: getApp().dever,
-  /**
-   * 页面的初始数据
-   */
-  data: {
-    imgUrl: ''
-  },
+  pid: '',
 
-  /**
-   * 生命周期函数--监听页面加载
-   */
   onLoad: function (options) {
     var that = this;
-    that.dever.request('product.api.poster',{
-      signature: that.dever.getSignature(),
-      path: '/template/view/index'
-    },{
+    this.pid = options.id;
+    app.request('product.api.poster',{product_id: this.pid},{
       success: function(data, res){
-        that.dever.set(that, 'imgUrl', data.pic);
+        app.set(that, 'imgUrl', data);
       }
-    });
+    })
   },
 
   /**
    * 保存好报分享到朋友圈
    */
-  savePoster: function(imgUrl){
-    var that = this;
+  savePoster: function(){
+    var imgUrl = this.data.imgUrl;
     wx.getImageInfo({
       src: imgUrl,
       success: function (sres){
-        that.dever.log('wx.getImageInfo', sres.path);
+        console.log('wx.getImageInfo', sres.path);
         wx.saveImageToPhotosAlbum({
           filePath: sres.path,
           success: function (fres){
-            that.dever.log('wx.saveImageToPhotosAlbum', fres);
+            console.log('wx.saveImageToPhotosAlbum', fres);
           }
         })
       }
@@ -45,16 +36,25 @@ Page({
    * 用户点击右上角分享
    */
   onShareAppMessage: function (options) {
-    var that = this;
+    //打开好友列表
     wx.showShareMenu({
       withShareTicket: true,
       success: function (res) {
-        that.dever.log('wx.showShareMenu success', res.data);
+        console.log('wx.showShareMenu success', res.data);
       },
       fail: function (res) {
-        that.dever.log('wx.showShareMenu fail', res.data);
+        console.log('wx.showShareMenu fail', res.data);
       }
-    }) ;
-    //options.from可以用来判断是从自定义button打开的转发页面,还是从右上角的打开的转发页面。
+    });
+
+    //拼接分享参数
+    var scene = app.getUid()+','+ this.pid;
+
+    return {
+      title: '',
+      desc: '',
+      path: '/template/home/index?scene=' + encodeURIComponent(scene)
+    };
+
   }
 })

+ 37 - 51
template/view/index.js

@@ -1,47 +1,40 @@
-Page({
-  dever: getApp().dever,
-  product_id: '',
-  data: {
-    content: ''
-  },
+const app = getApp();
 
+Page({
+  options: {},
+  pid: '',
   onLoad: function (options) {
-    var that = this;
-    that.dever.showLoading();
-    if(typeof options.scene == 'undefined'){
-      that.product_id = options.id;
-    }else{
-      var scene = decodeURIComponent(options.scene);
-      scene = scene.split(','); 
-      //var uid = scene[0]; 
-      that.product_id = scene[1];
+    this.options = options;
+    //产品详情路径附带参数,用于来源分享的参数scene = uid, product_id
+    if (typeof options.scene == 'undefined') {//来源首页商品浏览
+      this.pid = options.id;
+    } else {//来源于分享
+      let arr = app.getSceneArray(options.scene);
+      let uid = arr[0];
+      this.pid = arr[1];
+      app.saveInviteUid(uid);
     }
-    that.dever.request('product.api.view',{
-      signature: that.dever.getSignature(),
-      id: that.product_id
-    }, {
-        success: function (data, res) {
-          var temp = that.dever.html('content', data.product.content, that);
-          that.setData({
-            content: temp
-          })
-          that.dever.hideLoading();
-        }
-    });
+    var that = this;
+    app.showLoading();
+    app.request('product.api.view', {id: this.pid}, {
+      success: function (data, res) {
+        app.html('content', data.product.content, that);
+      },
+      complete: function(res){
+        app.hideLoading();
+      }
+    })
   },
 
   /**
    * 跳转海报分享页面,分享海报
    */
   toShare: function(){
-    var that = this;
-    that.dever.isLogin(function (res) {
-      if (res) {
-        this.dever.location('poster/index');
-      } else {
-        that.dever.location('login/index');
-      }
-    });
+    if(app.isLogin()){
+      app.location('poster/index?id=' + this.pid);
+    }else{
+      app.location('login/index');
+    }
   },
 
   /**
@@ -49,22 +42,15 @@ Page({
    */
   doBuy: function(e){
     var that = this;
-    this.dever.isLogin(function (res) {
-      if (res) {
-        that.dever.request('product.api.addCarts', {
-          json: 1,
-          signature: that.dever.getSignature(),
-          product_id: that.product_id,
-          num: 1
-        }, {
-            success: function (data, res) {
-              that.dever.location('carts/index?id=' + that.product_id);
-            }
-          });
-      } else {
-        that.dever.location('login/index');
-      }
-    });
+    if(app.isLogin()){
+      app.request('product.api.addCarts', {product_id: this.pid, num: 1}, {
+          success: function (data, res) {
+            app.location('carts/index?id=' + that.pid);
+          }
+        })
+    } else {
+      app.location('login/index');
+    }
   }
 
 })

+ 1 - 1
template/view/index.wxss

@@ -1,5 +1,5 @@
 .content {
-  padding: 30rpx 30rpx 150rpx 30rpx;
+  padding-bottom: 150rpx;
 }
 .content image {
   width: 750rpx;