liukangdong
2024-07-18 0358677c06e86f05c992f406c9714a32b30a235d
wechat_jiaxuan/app.js
@@ -1,4 +1,4 @@
// app.js
import { wxLoginCustomer } from './api/index'
App({
  globalData: {
    primary: '#B08771',
@@ -10,5 +10,32 @@
    if (WindowInfo.safeArea.top > 20) {
      this.globalData.bottomLift = WindowInfo.screenHeight - WindowInfo.safeArea.bottom;
    }
    //
    wx.login({
      timeout: 5000,
      success(res) {
        if (res.code) {
          //发起网络请求
          wxLoginCustomer({
            code: res.code
          }).then(res => {
            console.log(res)
            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('登录失败!')
            }
          })
        } else {
          console.log('登录失败!' + res)
        }
      },
      fail(err) {
        console.log(err)
      }
    })
  }
})
})