import userservice from '../../../service/userservice' const app = getApp() /** * 登录流程 */ module.exports = Behavior({ data: { }, lifetimes: { attached: function () {} }, methods: { loginPw(accessTokenPW) { 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) { 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 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, } wx.setStorage({ key: 'accessToken', data: app.globalData.accessToken, }) that.gotoHomePage() } }) } else { that._onLoginFail() } wx.hideLoading() }, complete() { // wx.hideLoading() that.setData({ loading: false }) } }) }, }) }, gotoHomePage() { userservice.getUserInfo(app.globalData.accessToken.userId, { success(data) { app.globalData.userInfo = data app.globalData.isLogin = true wx.setStorage({ key: 'userInfo', data: data, success: (result) => { wx.switchTab({ url: '/pages/home/home', }) } }) } }) }, } })