bayi 1 年間 前
コミット
7987d89f81
7 ファイル変更105 行追加68 行削除
  1. 5 10
      app.js
  2. 7 0
      mixins/event.js
  3. 63 47
      pages/donutLogin/index.js
  4. 9 11
      pages/index/index.js
  5. 9 0
      pages/index/index.less
  6. 4 0
      pages/index/index.wxml
  7. 8 0
      pages/index/index.wxss

+ 5 - 10
app.js

@@ -84,6 +84,10 @@ App({
                     }
                 }
             })
+            // #elif ANDROID
+            this.setUser({
+                grade: 'PRIMARY_FIRST_GRADE'
+            })
             // #endif
         }
     },
@@ -98,16 +102,7 @@ App({
                     }
                 }
             })
-            /*  wx.getMiniProgramCode({
-                 success(res) {
-                     if (res.code) {
-                         reslove(res)
-                     } else {
-                         console.log('获取小程序 code 失败!' + res.errMsg)
-                         reject(res.errMsg)
-                     }
-                 }
-             }) */
+            
         })
     },
     checkIsIos: function () {

+ 7 - 0
mixins/event.js

@@ -18,5 +18,12 @@ module.exports = Behavior({
                 targetContent: url
             })
         },
+    },
+    methods: {
+        toAndroidLogin() {
+            wx.redirectTo({
+                url: '/pages/donutLogin/index',
+            })
+        }
     }
 })

+ 63 - 47
pages/donutLogin/index.js

@@ -1,53 +1,69 @@
+import {
+    userLogin,
+} from '~/api/user'
 Page({
-  data: {
-    checkedAgree: false,
-    loginSuccess: false, // 标记是否登录成功
-  },
+    data: {
+        checkedAgree: false,
+        loginSuccess: false, // 标记是否登录成功
+    },
 
-  /**
-   * 退出页面时触发基础库回调,由基础库内部处理系统登录态。
-   */
-  onUnload() {
-    const eventChannel = this.getOpenerEventChannel();
-    if (eventChannel) {
-      eventChannel.emit('__donutLogin__', { success: this.data.loginSuccess });
-    }
-  },
+    /**
+     * 退出页面时触发基础库回调,由基础库内部处理系统登录态。
+     */
+    onUnload() {
+        const eventChannel = this.getOpenerEventChannel();
+        if (eventChannel) {
+            eventChannel.emit('__donutLogin__', {
+                success: this.data.loginSuccess
+            });
+        }
+    },
 
-  /**
-   * 触发小程序登录,登录成功后自动退出页面
-   */
-  onTapWeixinMiniProgramLogin() {
-    wx.weixinMiniProgramLogin({
-      success: () => {
-        this.setData({ loginSuccess: true });
-        wx.navigateBack();
-      },
-      fail: () => {
-        wx.showToast({
-          title: '小程序登录失败',
-          icon: 'none'
-        });
-      }
-    })
-  },
+    /**
+     * 触发小程序登录,登录成功后自动退出页面
+     */
+    onTapWeixinMiniProgramLogin() {
+        wx.getMiniProgramCode({
+            success: async (res) => {
+                let data = {
+                    code: res.code,
+                    userChannelCode
+                }
+                let userRes = await userLogin(data)
+            }
+        })
+        /* wx.weixinMiniProgramLogin({
+          success: () => {
+            this.setData({ loginSuccess: true });
+            wx.navigateBack();
+          },
+          fail: () => {
+            wx.showToast({
+              title: '小程序登录失败',
+              icon: 'none'
+            });
+          }
+        }) */
+    },
 
-  onCheckboxChange() {
-    this.setData({ checkedAgree: !this.data.checkedAgree });
-  },
+    onCheckboxChange() {
+        this.setData({
+            checkedAgree: !this.data.checkedAgree
+        });
+    },
 
-  /**
-   * 
-   * 使用单独的 webview 页面展示用户协议
-   */
-  onShowAgreement(e) {
-    const urls = [
-      'link1',
-      'link2'
-    ];
-    const url = urls[e.target.dataset.idx];
-    // wx.navigateTo({
-    //   url: `/pages/webview/index?url=${url}`,
-    // });
-  },
+    /**
+     * 
+     * 使用单独的 webview 页面展示用户协议
+     */
+    onShowAgreement(e) {
+        const urls = [
+            'link1',
+            'link2'
+        ];
+        const url = urls[e.target.dataset.idx];
+        // wx.navigateTo({
+        //   url: `/pages/webview/index?url=${url}`,
+        // });
+    },
 })

+ 9 - 11
pages/index/index.js

@@ -24,10 +24,11 @@ Page({
         categoryList: [],
         listOptions: {},
         subscribeShow: false,
-        tmplIds: []
+        tmplIds: [],
+        androidMask: false
     },
     onLoad(options) {
-        // if MP
+        // #if MP
         this.getLocUserInfo()
         if (Object.keys(this.data.userInfo).length > 0) {
             this.requestAgain()
@@ -51,10 +52,10 @@ Page({
                 })
             }, 6000)
         }
-        // elif ANDROID
+        // #elif ANDROID
         this.getLocUserInfo()
         this.requestAgain()
-        // endif
+        // #endif
     },
     onShow() {
         if (typeof this.getTabBar === 'function') {
@@ -77,16 +78,13 @@ Page({
             },
         })
         this.storeBindings.updateStoreBindings()
-        // if ANDROID
-        console.log(this.data.userInfo.grade);
-        if(!this.data.userInfo.grade){
+        // #if ANDROID
+        if (!wx.getStorageSync('uid')) {
             this.setData({
-                userInfo:{
-                    grade:"PRIMARY_FIRST_GRADE"
-                }
+                androidMask: true
             })
         }
-        // endif
+        // #endif
     },
     async getCategoryList() {
         let grade = this.data.userInfo.grade

+ 9 - 0
pages/index/index.less

@@ -76,4 +76,13 @@
     z-index: 99;
     width: 100vw;
     height: 100vh;
+}
+
+.androidMask {
+    position: fixed;
+    left: 0;
+    top: 0;
+    width: 100vw;
+    height: 100vh;
+    background-color: rgba(255, 166, 0, 0.123);
 }

+ 4 - 0
pages/index/index.wxml

@@ -29,4 +29,8 @@
     </view>
 </view>
 <view class="subscribe" wx:if="{{subscribeShow}}" bindtap="requestMessage"></view>
+<!-- #if ANDROID  -->
+to
+<view class="androidMask" wx:if="{{androidMask}}" bind:tap="toAndroidLogin"></view>
+<!-- #endif -->
 <canvas id='share' type="2d"> </canvas>

+ 8 - 0
pages/index/index.wxss

@@ -68,3 +68,11 @@
   width: 100vw;
   height: 100vh;
 }
+.androidMask {
+  position: fixed;
+  left: 0;
+  top: 0;
+  width: 100vw;
+  height: 100vh;
+  background-color: rgba(255, 166, 0, 0.123);
+}