jiangping
2024-07-29 d9a89d83c2048a964f16ca179feb2b7f21b9d33a
wechat_jiaxuan/app.js
@@ -1,33 +1,50 @@
import {
  wxLoginCustomer
} from './api/index'
import CustomHook from 'spa-custom-hooks';
let globalData = {
  token: '',
  primary: '#B08771',
  bottomLift: ''
}
App({
  globalData: {
    primary: '#B08771',
    bottomLift: ''
  },
  onLaunch: function () {
  globalData,
  onLaunch: function (op) {
    console.log('options', op.query.scene)
    let pathMap = [
      '/pages/detailDis/product',
      '/pages/detailDis/case',
      '/pages/detailDis/realpic',
      '/pages/consult/detail',
      '/pages/productVideo/index',
    ]
    //获取当前设备信息
    const WindowInfo = wx.getWindowInfo()
    if (WindowInfo.safeArea.top > 20) {
      this.globalData.bottomLift = WindowInfo.screenHeight - WindowInfo.safeArea.bottom;
      this.globalData.bottomLift = WindowInfo.screenHeight - WindowInfo.safeArea.bottom
    }
    // 授权登录
    const member = wx.getStorageSync('member')
    wx.login({
      timeout: 5000,
      success(res) {
      success: (res) => {
        if (res.code) {
          //发起网络请求
          wxLoginCustomer({
            code: res.code
          }).then(res => {
            console.log(res)
            wx.setStorageSync('token', res.data.token)
            this.globalData.token = res.data.token
            if (op.query.scene) {
              let temp = op.query.scene.split('_')
              wx.navigateTo({
                url: `${pathMap[temp[1]]}?id=${temp[0]}&userId=${temp[2]}`,
              })
            }
            console.log('拿到token了', res.data.token);
            if (res && res.data.member) {
              wx.setStorageSync('member', res.data.member)
              wx.setStorageSync('openid', res.data.member.openid)
              wx.setStorageSync('sessionKey', res.data.sessionKey)
              wx.setStorageSync('token', res.data.token)
            } else {
              console.log('登录失败!')
            }
@@ -42,5 +59,16 @@
    })
  }
})
})
CustomHook.install({
  'Login':{
     name:'Login',
     watchKey: 'token',
     onUpdate(val){
       //有token则触发此钩子
       return !!val;
     }
   }
 }, globalData || 'globalData')