Bläddra i källkod

接口请求带入 from

zhashaonan 6 år sedan
förälder
incheckning
d7b79c9100
4 ändrade filer med 120 tillägg och 51 borttagningar
  1. 5 1
      app.js
  2. 13 1
      pages/details/details.js
  3. 55 49
      pages/index/index.js
  4. 47 0
      utils/recordSource.js

+ 5 - 1
app.js

@@ -127,7 +127,11 @@ App({
     defaultAddress: null,
     fcodeErr: '',
     backLogin:false,
-    arrayTree: []
+    arrayTree: [],
+    fromSource: ''
+  },
+  setFromSource(fromSource) {
+    this.globalData.fromSource = fromSource
   },
   checkDefaultAddress(address) {
     this.globalData.defaultAddress = address

+ 13 - 1
pages/details/details.js

@@ -2,6 +2,7 @@
 
 const getReq = require('./../../config.js').getReq;
 const app = getApp();
+import recordSource from '../../utils/recordSource'
 var WxParse = require('../../wxParse/wxParse.js');
 Page({
 
@@ -62,6 +63,13 @@ Page({
 
   },
   getDatas(goods_id) {
+
+    let fromSource = recordSource(app, `act=goods_common&op=index&goods_id=${goods_id}&client_type=mini`)
+
+    // let fromSource = app.globalData.fromSource
+    // let currentSource = new RecordSource(`act=goods_common&op=index&goods_id=${goods_id}&client_type=mini`).encode()
+    // app.setFromSource(currentSource)
+
     wx.showLoading({
       title: '加载中',
     })
@@ -69,7 +77,8 @@ Page({
     getReq({
       act: 'goods_common',
       op: 'index',
-      goods_id
+      goods_id,
+      from: fromSource
     }, function (res) {
       wx.hideLoading()
       if (res.code == 200) {
@@ -452,6 +461,9 @@ Page({
    * 生命周期函数--监听页面显示
    */
   onShow: function () {
+    console.log('detail source:', app.globalData.fromSource);
+
+
     if (app.globalData.fcodeErr) {
       wx.showToast({
         icon: 'none',

+ 55 - 49
pages/index/index.js

@@ -1,58 +1,37 @@
 let app = getApp();
+import recordSource from '../../utils/recordSource'
 const getReq = require('./../../config.js').getReq;
 
 Page({
   data: {
     tabs: [],
-    prop_special:[],
-    surplus_special:[],
+    prop_special: [],
+    surplus_special: [],
     special_datas: {},
     summery: [],
-    isScroll:false,
-    isSendProp:false
+    isScroll: false,
+    isSendProp: false,
+    firstLoad: true
   },
 
-  onShow: function() {
-    if (app.globalData.backLogin) {
+  onShow: function () {
+    if (app.globalData.backLogin && !this.data.firstLoad) {
       app.globalData.backLogin = false;
-      wx.reLaunch({
-        url: "/pages/index/index"
-      });
+      this.getDatas(0)
     }
   },
 
   onLoad: function () {
-    // this.req_tabs();
     this.getDatas(0)
   },
+  getDatas(special_id) {
 
-  req_tabs(){
-    let self = this
-    getReq({
-      act: 'index',
-      op: 'tabs'
-    }, function (res) {
-      if (res.code == 200) {
-        self.getDatas(res.datas.tabs[0].special_id);
-        // console.log(res.datas.tabs[0].special_id);
-        // self.getDatas(1364);
-        self.setData({
-          tabs: res.datas.tabs
-        });
-      }
-    })
-  },
-  onMyEvent: function (e) {
-    this.setData({
-      prop_special:[],
-      surplus_special:[],
-      special_datas: {},
-      summery: []
-    });
-    this.getDatas(e.detail.item.special_id)
-  },
+    let fromSource = recordSource(app, 'act=special&op=index&special_id=0&page=10&curpage=1&client_type=mini')
+
+    // let fromSource = app.globalData.fromSource
+    // let currentSource = new RecordSource('act=special&op=index&special_id=0&page=10&curpage=1&client_type=mini').encode()
+    // app.setFromSource(currentSource)
 
-  getDatas(special_id) {
     wx.showLoading({
       title: '加载中'
     });
@@ -62,7 +41,8 @@ Page({
       op: 'index',
       special_id,
       page: 10,
-      curpage: 1
+      curpage: 1,
+      from: fromSource
     }, function (res) {
       if (res.code == 200) {
         let prop_special = res.datas.special_list;
@@ -71,7 +51,8 @@ Page({
           surplus_special: prop_special,
           prop_special: sent_down_special,
           special_datas: res.datas,
-          summery: res.datas.summary
+          summery: res.datas.summary,
+          firstLoad: false
         });
       }
       setTimeout(function () {
@@ -79,9 +60,34 @@ Page({
       }, 1000)
     })
   },
-  onPageScroll(e){
+  req_tabs() {
+    let self = this
+    getReq({
+      act: 'index',
+      op: 'tabs'
+    }, function (res) {
+      if (res.code == 200) {
+        self.getDatas(res.datas.tabs[0].special_id);
+        // console.log(res.datas.tabs[0].special_id);
+        // self.getDatas(1364);
+        self.setData({
+          tabs: res.datas.tabs
+        });
+      }
+    })
+  },
+  onMyEvent: function (e) {
+    this.setData({
+      prop_special: [],
+      surplus_special: [],
+      special_datas: {},
+      summery: []
+    });
+    this.getDatas(e.detail.item.special_id)
+  },
+  onPageScroll(e) {
     clearTimeout(this.showTop);
-    this.showTop = setTimeout(()=>{
+    this.showTop = setTimeout(() => {
       let scrollTop = e.scrollTop;
       if (scrollTop >= 300) {
         this.setData({
@@ -93,9 +99,9 @@ Page({
           isScroll: false
         })
       }
-    },100);
+    }, 100);
   },
-  backTop(){
+  backTop() {
     wx.pageScrollTo({
       scrollTop: 0,
       duration: 300
@@ -103,22 +109,22 @@ Page({
   },
   onShareAppMessage: function () {
     return {
-      title:"熊猫美妆小程序",
-      path:"/pages/index/index"
+      title: "熊猫美妆小程序",
+      path: "/pages/index/index"
     }
   },
-  onReachBottom: function(){
-    if (this.data.isSendProp){
+  onReachBottom: function () {
+    if (this.data.isSendProp) {
       return;
     }
-    
+
     let surplus_special_num = this.data.surplus_special.length;
-    if (surplus_special_num > 0){
+    if (surplus_special_num > 0) {
       // wx.showLoading({
       //   title: '加载中'
       // });
       this.setData({
-        isSendProp:true
+        isSendProp: true
       });
       this.data.isSendProp = true;
       let prop_special = this.data.surplus_special;

+ 47 - 0
utils/recordSource.js

@@ -0,0 +1,47 @@
+class TransCoding {
+  constructor(params) {
+    this.params = params
+    this.toBase64Table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
+    this.base64Pad = '='
+  }
+  toBase64() {
+    let result = ''
+    let length = this.params.length
+    let i
+
+    for (i = 0; i < (length - 2); i += 3) {
+      result += this.toBase64Table[this.params.charCodeAt(i) >> 2];
+      result += this.toBase64Table[((this.params.charCodeAt(i) & 0x03) << 4) + (this.params.charCodeAt(i + 1) >> 4)];
+      result += this.toBase64Table[((this.params.charCodeAt(i + 1) & 0x0f) << 2) + (this.params.charCodeAt(i + 2) >> 6)];
+      result += this.toBase64Table[this.params.charCodeAt(i + 2) & 0x3f];
+    }
+
+    if (length % 3) {
+      i = length - (length % 3);
+      result += this.toBase64Table[this.params.charCodeAt(i) >> 2];
+      if ((length % 3) == 2) {
+        result += this.toBase64Table[((this.params.charCodeAt(i) & 0x03) << 4) + (this.params.charCodeAt(i + 1) >> 4)];
+        result += this.toBase64Table[(this.params.charCodeAt(i + 1) & 0x0f) << 2];
+        result += this.base64Pad;
+      } else {
+        result += this.toBase64Table[(this.params.charCodeAt(i) & 0x03) << 4];
+        result += this.base64Pad + this.base64Pad;
+      }
+    }
+    return result;
+  }
+  encode() {
+    return encodeURIComponent(this.toBase64())
+  }
+}
+
+function recordSource(app, params) {
+  let fromSource = app.globalData.fromSource
+  let currentSource = new TransCoding(params).encode()
+  app.setFromSource(currentSource)
+  return fromSource
+}
+export default recordSource
+
+
+