|
@@ -57,9 +57,21 @@ App({
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
let _this = this
|
|
let _this = this
|
|
- let openid = wx.getStorageSync('@openid');
|
|
|
|
- if( !openid ) return cb && cb({code:401});
|
|
|
|
- let param = {"openid": openid};
|
|
|
|
|
|
+ let token = wx.getStorageSync('@token');
|
|
|
|
+ if(!token) return;
|
|
|
|
+ wx.login({
|
|
|
|
+ success(wxres) {
|
|
|
|
+ if( !wxres.code){
|
|
|
|
+ util.showMsg("登入失败")
|
|
|
|
+ }else{
|
|
|
|
+ _this.doLoginByCode( wxres.code, cb )
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+ doLoginByCode( code, cb ){
|
|
|
|
+ let param = {code};
|
|
|
|
+ let _this = this;
|
|
_this.formPost('Auth.wxLogin', param).then( res =>{
|
|
_this.formPost('Auth.wxLogin', param).then( res =>{
|
|
if (res.code == 200) {
|
|
if (res.code == 200) {
|
|
_this.setUserInfo(res.data);
|
|
_this.setUserInfo(res.data);
|
|
@@ -78,7 +90,7 @@ App({
|
|
formPost: function (action, data) {
|
|
formPost: function (action, data) {
|
|
let _this = this
|
|
let _this = this
|
|
let userInfo = this.globalData.userInfo||{}
|
|
let userInfo = this.globalData.userInfo||{}
|
|
- let user_id = userInfo.uid||0;
|
|
|
|
|
|
+ let user_id = userInfo.userId||0;
|
|
let token = userInfo.token||'';
|
|
let token = userInfo.token||'';
|
|
let timestamp = Date.now()
|
|
let timestamp = Date.now()
|
|
action = action.toLowerCase()
|
|
action = action.toLowerCase()
|
|
@@ -130,16 +142,12 @@ App({
|
|
})
|
|
})
|
|
},
|
|
},
|
|
checkNavigateTo: function(url){
|
|
checkNavigateTo: function(url){
|
|
- let openid = wx.getStorageSync('@openid');
|
|
|
|
- if( !openid ) return this.gotoLogin()
|
|
|
|
|
|
+ let token = wx.getStorageSync('@token');
|
|
|
|
+ if( !token ) return this.gotoLogin()
|
|
wx.navigateTo({url})
|
|
wx.navigateTo({url})
|
|
},
|
|
},
|
|
- setUserInfo: function (info) {
|
|
|
|
- let {token, user} = info
|
|
|
|
- console.log("setUserInfo", token, user)
|
|
|
|
|
|
+ setUserInfo: function (user) {
|
|
this.globalData.userInfo = user;
|
|
this.globalData.userInfo = user;
|
|
- wx.setStorageSync('@token', token)
|
|
|
|
- wx.setStorageSync('@userId', user.userId )
|
|
|
|
- this.loadDepartments()
|
|
|
|
|
|
+ wx.setStorageSync('@token', user.token)
|
|
}
|
|
}
|
|
})
|
|
})
|