|
@@ -8,7 +8,7 @@ App({
|
|
|
globalData: {
|
|
|
pageSize: 10,
|
|
|
userInfo: {},
|
|
|
- departments: false,
|
|
|
+ departments: [],
|
|
|
studyInfo: {},
|
|
|
},
|
|
|
onLaunch: function () {
|
|
@@ -45,18 +45,25 @@ App({
|
|
|
}
|
|
|
},
|
|
|
gotoLogin: function(){
|
|
|
+ console.log("gologin")
|
|
|
wx.navigateTo({
|
|
|
url: `/pages/user/identify/index`,
|
|
|
})
|
|
|
},
|
|
|
checkLogin: function(cb){
|
|
|
- if( this.globalData.userInfo){
|
|
|
+ if( this.globalData.userInfo && this.globalData.userInfo.userId ){
|
|
|
cb&&cb( this.globalData.userInfo );
|
|
|
}else{
|
|
|
- this.formPost("user/info", {}).then( res=>{
|
|
|
- if( res.code == 200){
|
|
|
- this.setUserInfo( res.data )
|
|
|
- cb&&cb( this.data.user )
|
|
|
+ let token = wx.getStorageSync('@token');
|
|
|
+ console.log("get token", token)
|
|
|
+ if( !token ) {
|
|
|
+ this.gotoLogin()
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.formPost('weixin/info', {}).then( res =>{
|
|
|
+ if (res.code == 200) {
|
|
|
+ this.setUserInfo(res.data);
|
|
|
+ cb && cb( this.globalData.userInfo )
|
|
|
}else{
|
|
|
this.gotoLogin()
|
|
|
}
|
|
@@ -69,7 +76,7 @@ App({
|
|
|
type: type
|
|
|
});
|
|
|
},
|
|
|
- formPost: function (action, data) {
|
|
|
+ formPost: function (action, data, showErr= true) {
|
|
|
let uid = wx.getStorageSync('@userId')||0;
|
|
|
let token = wx.getStorageSync('@token')||'';
|
|
|
let timestamp = Date.now()
|
|
@@ -93,10 +100,17 @@ App({
|
|
|
if (res.statusCode !== 200 || typeof res.data !== 'object') {
|
|
|
showMsg( "请求异常" )
|
|
|
}
|
|
|
+ let newToken = res.header["new-token"];
|
|
|
+ if( newToken ) {
|
|
|
+ wx.setStorageSync( "@token", newToken )
|
|
|
+ }
|
|
|
if( res.data.data && res.data.data.reload ){
|
|
|
+ wx.clearStorageSync("@token")
|
|
|
wx.navigateTo({
|
|
|
url: '/pages/user/identify/index',
|
|
|
})
|
|
|
+ }else if( res.data.code != 200 && showErr ){
|
|
|
+ util.showMsg(res.data.msg)
|
|
|
}
|
|
|
resolve(res.data);
|
|
|
},
|
|
@@ -110,26 +124,6 @@ App({
|
|
|
})
|
|
|
})
|
|
|
},
|
|
|
- getUserInfo: function ( cb ) {
|
|
|
- let userInfo = this.globalData.userInfo
|
|
|
- if( userInfo && userInfo.token ){
|
|
|
- cb && cb( userInfo);
|
|
|
- return
|
|
|
- }
|
|
|
- let openid = wx.getStorageSync('@openid');
|
|
|
- // let openid="oG3Fi5ait37qL-3edzAkzysH5apU"
|
|
|
- if( !openid ) {
|
|
|
- cb && cb({});
|
|
|
- return
|
|
|
- }
|
|
|
- let param = {"openid": openid};
|
|
|
- this.formPost('Auth.wxLogin', param).then( res =>{
|
|
|
- if (res.code == 200) {
|
|
|
- this.setUserInfo(res.data);
|
|
|
- }
|
|
|
- cb && cb(res.data||{});
|
|
|
- })
|
|
|
- },
|
|
|
getSystemInfo( cb ){
|
|
|
wx.getSystemInfo({
|
|
|
success: function(res) {
|
|
@@ -143,8 +137,8 @@ App({
|
|
|
wx.navigateTo({url})
|
|
|
},
|
|
|
getDepartments: function( cb ){
|
|
|
- if( this.globalData.departments ){
|
|
|
- cb&&cb( this.globalData.departments||[])
|
|
|
+ if( this.globalData.departments.length > 0 ){
|
|
|
+ cb&&cb( this.globalData.departments )
|
|
|
}else{
|
|
|
this.loadDepartments( cb )
|
|
|
}
|
|
@@ -153,14 +147,15 @@ App({
|
|
|
this.formPost( 'base/loadDepartmentList', {}).then( res=>
|
|
|
{
|
|
|
if( res.code == 200){
|
|
|
- this.globalData.departments = res.data
|
|
|
- cb && cb( this.globalData.departments)
|
|
|
+ this.globalData.departments = res.data;
|
|
|
+ cb && cb( res.data );
|
|
|
}
|
|
|
}
|
|
|
)
|
|
|
},
|
|
|
setUserInfo: function (info) {
|
|
|
let {token, user} = info
|
|
|
+ console.log("setUserInfo", token, user)
|
|
|
this.globalData.userInfo = user;
|
|
|
wx.setStorageSync('@token', token)
|
|
|
wx.setStorageSync('@userId', user.userId )
|