Browse Source

悦道登录

bayi 9 months ago
parent
commit
46c6c873fb
6 changed files with 25 additions and 149 deletions
  1. 2 0
      api/user.js
  2. 16 135
      app.js
  3. 1 1
      custom-tab-bar/index.wxml
  4. 1 4
      pages/ranking/index.wxml
  5. 0 4
      pages/reading/index.wxml
  6. 5 5
      utils/request.js

+ 2 - 0
api/user.js

@@ -5,6 +5,8 @@ import {
 module.exports = {
     // 用户登录
     userLogin: data => request('/user/openId', 'get', data),
+    // 安卓设备登录
+    androidLogin: data => request('/user/registerExtOpenId', 'post', data),
     // 统计用户登录
     loginLog: data => request('/loginLog', 'post', data),
     //获取他人用户信息,

+ 16 - 135
app.js

@@ -1,7 +1,7 @@
 // app.js
 import {
     loginLog,
-    userLogin,
+    androidLogin,
     getMyInfo,
     bindDevice
 } from '~/api/user'
@@ -14,11 +14,8 @@ import {
 let storeBindings
 App({
     async onLaunch() {
-        // #if MP
-        wx.setStorageSync('channelCode', '3001')
-        this.updateApplet()
-        // #elif ANDROID
-        wx.setStorageSync('channelCode', '3001')
+        // #if ANDROID
+        wx.setStorageSync('channelCode', '3016')
         this.initPlugin()
         // #endif
         this.getNavbarInfo()
@@ -31,115 +28,29 @@ App({
                 actions: ['setUser']
             })
         }
-        let {
-            path,
-            scene,
-            query
-        } = wx.getEnterOptionsSync()
-        //判断是不是扫海报进入
-        if (query.scene && [1047, 1048].includes(scene) && path == 'pages/index/index') {
-            let params = decodeURIComponent(query.scene).split('&')
-            if (params.length == 1) {
-                this.login(params[0])
-            } else {
-                this.login()
-            }
-        } else {
-            let shareUid = options.query.uid || ''
-            let userChannelCode = '3001'
-            // console.log("朋友圈广告进入");
-            if ([1045, 1046, 1084].includes(scene)) {
-                userChannelCode = '4001'
-            }
-            this.login(shareUid, userChannelCode)
-        }
+        this.login()
     },
-    async login(shareUid, userChannelCode = '3001') {
+    async login() {
         let uid = wx.getStorageSync('uid')
         if (uid) {
             let userInfo = await getMyInfo()
-            this.setUser(userInfo.user)
-            this.globalData.userInfo = userInfo.user
-            this.deviceLogin()
+            console.log(userInfo);
+            this.setUser(userInfo)
+            this.globalData.userInfo = userInfo
             if (getApp().callBack) {
                 getApp().callBack();
             }
         } else {
-            // #if MP
-            this.getWXCode().then(async res => {
-                if (res.code) {
-                    // 获取openid
-                    let data = {
-                        code: res.code,
-                        userChannelCode
-                    }
-                    if (shareUid != 'undefined' && shareUid) {
-                        data.shareUid = shareUid
-                    }
-                    let userRes = await userLogin(data)
-                    this.setUser(userRes.data)
-                    wx.setStorageSync('uid', userRes.data.uid)
-                    wx.setStorageSync('user', userRes.data)
-                    this.globalData.userInfo = userRes.data
-                    this.deviceLogin()
-                    if (getApp().callBack) {
-                        getApp().callBack(userRes);
-                    }
-                }
-            })
-            // #elif ANDROID
-            this.setUser({
-                grade: 'PRIMARY_FIRST_GRADE'
-            })
-            // #endif
-        }
-    },
-    getWXCode() {
-        return new Promise((reslove, reject) => {
-            wx.login({
-                success: async (res) => {
-                    if (res.code) {
-                        reslove(res)
-                    } else {
-                        reject(res.errMsg)
-                    }
-                }
-            })
-
-        })
-    },
-    // 音箱端登录
-    deviceLogin() {
-        // #if MP
-        let {
-            path,
-            scene,
-            query
-        } = wx.getEnterOptionsSync()
-        // 1047	扫描小程序码	1048长按图片识别小程序码
-        var gradeObj = Object.keys({
-            "PRESCHOOL": "学前班",
-            "PRIMARY_FIRST_GRADE": "一年级",
-            "PRIMARY_SECOND_GRADE": "二年级",
-            "PRIMARY_THREE_GRADE": "三年级",
-            "PRIMARY_SENIOR_GRADE": "四年级",
-            "PRIMARY_FIVE_GRADE": "五年级",
-            "PRIMARY_SIX_GRADE": "六年级",
-        })
-        if (query.scene && [1047, 1048].includes(scene) && path == 'pages/index/index') {
-            let params = decodeURIComponent(query.scene).split('&')
-            if (params.length > 1) {
-                bindDevice({
-                    deviceCode: params[0],
-                    channelCode: params[1],
-                    grade: gradeObj[params[2]],
-                    uid: wx.getStorageSync('uid')
-                }).then(res => {
-                    console.log(res);
-                })
+            let userRes = await androidLogin({extOpenId:'1234567',channel:'3016',grade:'PRIMARY_FIRST_GRADE'})
+            console.log(userRes);
+            this.setUser(userRes)
+            wx.setStorageSync('uid', userRes.uid)
+            wx.setStorageSync('user', userRes)
+            this.globalData.userInfo = userRes
+            if (getApp().callBack) {
+                getApp().callBack(userRes);
             }
         }
-        // #endif
     },
     getNavbarInfo() {
         // 获取系统信息
@@ -155,36 +66,6 @@ App({
         this.globalData.windowWidth = systemInfo.windowWidth
         this.globalData.windowHeight = systemInfo.windowHeight
     },
-    updateApplet() {
-        // 获取小程序更新机制兼容
-        if (wx.canIUse('getUpdateManager')) {
-            const updateManager = wx.getUpdateManager()
-            updateManager.onCheckForUpdate(function (res) {
-                // 请求完新版本信息的回调
-                if (res.hasUpdate) {
-                    updateManager.onUpdateReady(function () {
-                        wx.showModal({
-                            title: '更新提示',
-                            content: '新版本已经准备好,是否重启应用?',
-                            success: function (res) {
-                                if (res.confirm) {
-                                    // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
-                                    updateManager.applyUpdate()
-                                }
-                            }
-                        })
-                    })
-                    updateManager.onUpdateFailed(function () {
-                        // 新的版本下载失败
-                        wx.showModal({
-                            title: '已经有新版本了哟~',
-                            content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~',
-                        })
-                    })
-                }
-            })
-        }
-    },
     initPlugin() {
         let miniAppPluginId = 'wxf1a06dafa3350688'
         //根据模块ID初始化模块

+ 1 - 1
custom-tab-bar/index.wxml

@@ -8,6 +8,6 @@
         <view style="color: {{selected === index ? selectedColor : color}}">{{item.text}}</view>
     </view>
     <!-- #if ANDROID  -->
-    <view class="androidMask" wx:if="{{androidMask}}" bind:tap="toAndroidLogin"></view>
+    <!--   <view class="androidMask" wx:if="{{androidMask}}" bind:tap="toAndroidLogin"></view> -->
     <!-- #endif -->
 </view>

+ 1 - 4
pages/ranking/index.wxml

@@ -87,10 +87,7 @@
     </view>
     <view class="footer">
         <view class="left">我的排名<text>{{ranking?ranking:'100+'}}</text></view>
-        <button class="resetBtn rigth" open-type="share" wx:if="{{rankingType!=4}}">
-            <image src="/static/forward.png" class="share" />呼朋唤友来加热
-        </button>
-        <button class="resetBtn rigth" wx:else bindtap="jumpIndex">
+        <button class="resetBtn rigth" wx:if="{{rankingType==4}}" bindtap="jumpIndex">
             我要冲榜
         </button>
     </view>

+ 0 - 4
pages/reading/index.wxml

@@ -38,10 +38,6 @@
         </view>
     </view>
     <view class="workFooter" wx:if="{{readingType=='public'&&!readingReset&&!state}}">
-        <button class="resetBtn mangeL-box" open-type="share" data-info='{{videoInfo}}'>
-            <image src="/static/share.png" mode="" class="icon" />
-            <view class="icon-name">分享</view>
-        </button>
         <view class="mangeL-box" bindtap="collect">
             <image src="{{videoInfo.isFavorites ? '/static/star_colored.png' : '/static/star.png'}}" class="icon" />
             <view class="icon-name">{{videoInfo.isFavorites?'已收藏':'收藏'}}</view>

+ 5 - 5
utils/request.js

@@ -5,13 +5,13 @@ const {
         envVersion
     }
 } = wx.getAccountInfoSync();
-// if (envVersion == 'develop') {
-//     baseUrl = 'https://reader-api.efunbox.cn/wx'
-//     oldUrl = 'https://reader-api.efunbox.cn'
-// } else {
+if (envVersion == 'develop') {
+    baseUrl = 'https://reader-api.efunbox.cn/wx'
+    oldUrl = 'https://reader-api.efunbox.cn'
+} else {
 baseUrl = 'https://reader-api.ai160.com/wx'
 oldUrl = 'https://reader-api.ai160.com'
-// }
+}
 
 function request(url, method, data, oldBaseUrl = false, intercept = true) {
     let header = {