liukangdong
2024-07-19 1b897c74e44d185669d87abd4c3a29c90d6fe225
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { wxLoginCustomer } from './api/index'
App({
  globalData: {
    primary: '#B08771',
    bottomLift: ''
  },
  onLaunch: function () {
    //获取当前设备信息
    const WindowInfo = wx.getWindowInfo()
    if (WindowInfo.safeArea.top > 20) {
      this.globalData.bottomLift = WindowInfo.screenHeight - WindowInfo.safeArea.bottom;
    } 
    const res = wx.getStorageSync('member')  
    if (res) {
      this.globalData.userInfo = res
      console.error("res",res)
    } else {
      // 登录
      wx.login({
        timeout: 5000,
        success(res) {
          if (res.code) {
            //发起网络请求
            wxLoginCustomer({
              code: res.code
            }).then(res => {
              console.log(res)
              if (res && res.data.users) {
                wx.setStorageSync('member', res.data.users)
                wx.setStorageSync('openid', res.data.users.openid)
                wx.setStorageSync('sessionKey', res.data.sessionKey)
                wx.setStorageSync('token', res.data.token)
              } else {
                wx.navigateTo({
                  url: '/pages/login/index',
                })
                console.log('登录失败!')
              }
            })
          } else {
            wx.navigateTo({
              url: '/pages/login/index',
            })
            console.log('登录失败!' + res)
          }
        },
        fail(err) {
          console.log(err)
        }
      })
    }
  }
})