riku
2026-01-19 068be2757aa2d51e3f6604dae54287683160ad0e
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import userservice from '../../../service/userservice'
import moment from '../../../utils/moment.min'
import {
  loadConfig
} from "../../../config/loadConfig";
 
const app = getApp()
 
/**
 * 登录流程
 */
module.exports = Behavior({
  data: {
 
  },
  lifetimes: {
    attached: function () {}
  },
  methods: {
    loginPw(accessTokenPW) {
      // accessTokenPW.nickName = '\xF0\x9F\x98\x84'
      // debugger
      wx.showLoading({
        title: '登录中',
        mask: true,
      })
      setTimeout(() => {
        wx.hideLoading()
      }, 10000);
      var that = this
      wx.login({
        success: (res) => {
          console.log(res);
          accessTokenPW.code = res.code
          userservice.loginPW(accessTokenPW, {
            success(data) {
              wx.hideLoading()
              if (data.success) {
                wx.getStorage({
                  key: 'accessToken',
                  success(res) {
                    app.globalData.accessToken = res.data
                    app.globalData.accessToken.userId = data.userId
                    app.globalData.accessToken.suserId = data.suserId
                    app.globalData.accessToken.openId = data.openId
                    if (accessTokenPW.userName) {
                      app.globalData.accessToken.userName = accessTokenPW.userName
                    }
                    if (accessTokenPW.password) {
                      app.globalData.accessToken.password = accessTokenPW.password
                    }
                    wx.setStorage({
                      key: 'accessToken',
                      data: app.globalData.accessToken,
                    })
                    that.gotoHomePage()
                  },
                  fail(e) {
                    app.globalData.accessToken = {
                      userName: accessTokenPW.userName,
                      password: accessTokenPW.password,
                      userId: data.userId,
                      suserId: data.suserId,
                      openId: data.openId
                    }
                    wx.setStorage({
                      key: 'accessToken',
                      data: app.globalData.accessToken,
                    })
                    that.gotoHomePage()
                  }
                })
 
              } else {
                that._onLoginFail()
              }
            },
            complete() {
              // wx.hideLoading()
              // 2026.1.19 加载状态由下面配置获取接口 结束
              // that.setData({
              //   loading: false
              // })
            }
          })
        },
      })
    },
 
    gotoHomePage() {
      var that = this
      if (app.globalData.accessToken.userName == 'pcheck') {
        wx.navigateTo({
          url: '/pages/mExtra/pSupervisiontask/pSupervisiontask',
        })
      } else {
        userservice.getUserInfo(app.globalData.accessToken.userId, {
          success(data) {
            if (data.uiCreateTime) {
              const registerTime = moment(data.uiCreateTime)
              const now = moment()
              app.globalData.newUser = now.diff(registerTime, 'months') <= 1
            }
            console.log('app.globalData.newUser', app.globalData.newUser);
            app.globalData.userInfo = data
            app.globalData.isLogin = true
            wx.setStorage({
              key: 'userInfo',
              data: data,
              success: (result) => {
                loadConfig().then(() => {
                    wx.switchTab({
                      url: '/pages/home/home',
                    })
                  })
                  .finally(() => {
                    that.setData({
                      loading: false,
                    });
                  });
              },
              fail: err => {
                that.setData({
                  loading: false,
                });
              },
            })
          }
        })
      }
 
    },
  }
})