sun2511 2 vuotta sitten
vanhempi
commit
59108dd453
3 muutettua tiedostoa jossa 63 lisäystä ja 97 poistoa
  1. 14 20
      app.js
  2. 48 76
      pages/index/index.js
  3. 1 1
      pages/index/index.wxml

+ 14 - 20
app.js

@@ -2,41 +2,35 @@ import {
     GetQueryString
 } from 'utils/util'
 import {
-    userLogin
-} from '~/api/user'
+    getOpenidNoLogin
+} from '~/utils/httpUtilNoLogin';
 // const Towxml = require('/towxml/main');
 App({
     watch(method) {
         let obj = this.globalData
-        // 这里监听 openId
+            // 这里监听 openId
         Object.defineProperty(obj, "openId", {
             configurable: true,
             enumerable: true,
-            set: function (value) {
+            set: function(value) {
                 console.log('zzeweqweqw', value);
                 method(value) // 触发页面回调函数
             }
         })
     },
     async onLaunch(options) {
-        /* wx.login({
-            success(res) {
-                if (res.code) {
-                    console.log(res.code);
-                    // 获取openid
-                    userLogin({
-                        code: res.code,
-                        grade: null
-                    }).then(res => {
-                        console.log(res);
-                    })
-                }
-            }
-        }) */
         // 判断设备是否为 iPhone X
         this.checkIsIPhoneX()
         options.referrerInfo.extraData && (this.globalData.upgradeHide = options.referrerInfo.extraData.upgrade)
     },
+    async onShow(options) {
+        let shareUid = options.query.uid
+        getOpenidNoLogin((res) => {
+            if (getApp().callBack) {
+                getApp().callBack(res);
+            }
+        }, () => {}, shareUid);
+    },
     globalData: {
         isIPX: false, // 当前设备是否为 iPhone X
         isIOS: false, // 判断设备是否为苹果
@@ -46,10 +40,10 @@ App({
         upgradeHide: true,
         openId: null
     },
-    checkIsIPhoneX: function () {
+    checkIsIPhoneX: function() {
         const self = this
         wx.getSystemInfo({
-            success: function (res) {
+            success: function(res) {
                 // 根据 model 进行判断
                 if (res.model.search('iPhone X') != -1) {
                     self.globalData.isIPX = true

+ 48 - 76
pages/index/index.js

@@ -256,45 +256,13 @@ Page({
         }, 2800)
     },
     onLoad: function(options) {
-        this.setData({
-            isIos: app.globalData.isIOS
-        })
-        if (options.tabbarIndx) {
-            this.updateData(options.tabbarIndx);
-        }
-        if (options.scene) {
-            let optionsStr = decodeURIComponent(options.scene);
-            let optionsArr = optionsStr.split('&');
-            // 暂时这样写
-            if (optionsArr[0].split("=")[0] === "type") {
-                console.log('我是团购分享')
-                options.type = optionsArr[0].split("=")[1];
-                options.sid = optionsArr[1].split("=")[1];
-            } else {
-                options.readId = optionsArr[0];
-                options.activity = optionsArr[1];
-            }
-        }
-        if (options.readId) {
+        if (wx.getStorageSync('uid')) {
             this.setData({
-                workId: options.readId
+                isLogin: true
             })
         }
-        /**
-         * 活动统计
-         */
-        if (options.activity) {
-            httpRequestApi.shareAddHotAmount(options.readId).success(res => {
-                console.log(res)
-            })
-        }
-        /**团购弹窗时间紧逻辑越写越乱功能越加越多 */
-        this.setData({
-            iphoneType: options.type || ''
-        })
-        console.log('onload', options);
-        let shareUid = options.uid
-        getOpenidNoLogin((res) => {
+        //网络原因,还没有拿到登陆数据,这里调用全局的callback
+        getApp().callBack = (res) => {
             /**获取权限和订单信息 */
             // 获取商品信息
             httpRequestApi.getProductActivity().success(res => {
@@ -311,16 +279,6 @@ Page({
                 // 获取用户权限
             this.getHelpAuth()
             if (!res.data.data.grade) {
-                /* // 没有年级的老用户
-                if (res.data.data.nickName) {
-                    this.setData({
-                        isGradeShow: true,
-                        options,
-                        isLogin: true,
-                        oldUser: true
-                    })
-                    return;
-                } */
                 this.setData({
                     isGradeShow: true,
                     options,
@@ -329,16 +287,11 @@ Page({
                 })
                 return
             } else {
-                if (res.data.data.nickName) {
-                    this.setData({
-                        isLogin: true
-                    }, () => {
-                        this.showPage();
-                    })
-                } else {
-                    console.log('游客未登录有年纪')
+                this.setData({
+                    isLogin: true
+                }, () => {
                     this.showPage();
-                }
+                })
             }
             // 获取商品信息
             httpRequestApi.getProductActivity().success(res => {
@@ -354,7 +307,45 @@ Page({
                 })
                 // 获取用户权限
             this.getHelpAuth()
-        }, () => {}, shareUid);
+        }
+        this.setData({
+            isIos: app.globalData.isIOS
+        })
+        if (options.scene) {
+            let optionsStr = decodeURIComponent(options.scene);
+            let optionsArr = optionsStr.split('&');
+            // 暂时这样写
+            if (optionsArr[0].split("=")[0] === "type") {
+                console.log('我是团购分享')
+                options.type = optionsArr[0].split("=")[1];
+                options.sid = optionsArr[1].split("=")[1];
+            } else {
+                options.readId = optionsArr[0];
+                options.activity = optionsArr[1];
+            }
+        }
+        if (options.readId) {
+            this.setData({
+                workId: options.readId
+            })
+        }
+        /**
+         * 活动统计
+         */
+        if (options.activity) {
+            httpRequestApi.shareAddHotAmount(options.readId).success(res => {
+                console.log(res)
+            })
+        }
+        /**团购弹窗时间紧逻辑越写越乱功能越加越多 */
+        this.setData({
+            iphoneType: options.type || ''
+        })
+        console.log('onload', options);
+
+        if (options.tabbarIndx) {
+            this.updateData(options.tabbarIndx);
+        }
         this.uid = wx.getStorageSync('uid');
         if (options.sid) {
             httpRequestApi.getUserRec(options.sid).success(res => {
@@ -941,26 +932,7 @@ Page({
             this.showPage()
         })
         return;
-        /*  getOpenidNoLogin((res) => {
-             console.log('getOpenidNoLogin', res)
-                 // 登录或注册完成 展示页面
-             if (res.data.data.nickName) {
-                 this.setData({
-                     isLogin: true
-                 })
-             } else {
-                 this.setData({
-                     isLogin: false
-                 })
-             }
-             this.showPage()
-         }, (error) => {
-             console.log('获取失败')
-             wx.setStorageSync('userSourseType', 'normal')
-             this.setData({
-                 hide: !this.data.hide
-             })
-         }, grade); */
+
     },
 
     getFollowData: function() {

+ 1 - 1
pages/index/index.wxml

@@ -86,4 +86,4 @@
 </view>
 <shareDialog id="share-dialog" shareType='works' bindaddShareAmount="addShareAmount" bindShareDialogClose="shareDialogClose" shareId="{{id}}" />
 <canvas canvas-id="myCanvas" style="width:300px; height: 525px; position: absolute; left: -999rpx; top: -9999rpx;"></canvas>
-<canvas id='share' type="2d"> </canvas>
+<canvas id='share' type="2d"> </canvas>