|
|
@ -4,7 +4,7 @@ |
|
|
|
|
|
|
|
|
}, |
|
|
}, |
|
|
onLaunch: function() { |
|
|
onLaunch: function() { |
|
|
this.login(); // 校验登录态 TODO 等待与后端对接 |
|
|
|
|
|
|
|
|
this.getUserInfo(); |
|
|
}, |
|
|
}, |
|
|
onShow: function() { |
|
|
onShow: function() { |
|
|
// #ifdef MP-WEIXIN |
|
|
// #ifdef MP-WEIXIN |
|
|
@ -15,11 +15,27 @@ |
|
|
console.log('App Hide') |
|
|
console.log('App Hide') |
|
|
}, |
|
|
}, |
|
|
methods: { |
|
|
methods: { |
|
|
|
|
|
// 获取用户信息 |
|
|
|
|
|
getUserInfo(){ |
|
|
|
|
|
let userinfo = uni.getStorageSync('userinfo'); |
|
|
|
|
|
if(userinfo && userinfo.id){ |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
uni.login({ |
|
|
|
|
|
complete: result => { |
|
|
|
|
|
if(result.errMsg == 'login:ok'){ |
|
|
|
|
|
let code = result.code; |
|
|
|
|
|
this.userCode(code); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
}, |
|
|
// 接口code换取用户信息 |
|
|
// 接口code换取用户信息 |
|
|
userCode(code){ |
|
|
userCode(code){ |
|
|
return console.log("code", code); |
|
|
|
|
|
this.$http('', { code }).then(res => { |
|
|
|
|
|
|
|
|
console.log("code", code); |
|
|
|
|
|
this.$http(this.API.API_WXLOGIN, { code }).then(res => { |
|
|
console.log("获得用户信息", res); |
|
|
console.log("获得用户信息", res); |
|
|
|
|
|
uni.setStorageSync('userinfo', res.data); |
|
|
}) |
|
|
}) |
|
|
}, |
|
|
}, |
|
|
// 登录 |
|
|
// 登录 |
|
|
@ -27,12 +43,12 @@ |
|
|
this.checkSession().then(code => { |
|
|
this.checkSession().then(code => { |
|
|
this.userCode(code); |
|
|
this.userCode(code); |
|
|
}).catch(err => { |
|
|
}).catch(err => { |
|
|
|
|
|
console.log("进入。。。。。。") |
|
|
uni.login({ |
|
|
uni.login({ |
|
|
complete: result => { |
|
|
complete: result => { |
|
|
console.log(result) |
|
|
console.log(result) |
|
|
if(result.errMsg == 'login:ok'){ |
|
|
if(result.errMsg == 'login:ok'){ |
|
|
let code = result.code; |
|
|
let code = result.code; |
|
|
uni.setStorageSync('login_token', code); |
|
|
|
|
|
this.userCode(code); |
|
|
this.userCode(code); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -45,7 +61,8 @@ |
|
|
uni.checkSession({ |
|
|
uni.checkSession({ |
|
|
complete: result => { |
|
|
complete: result => { |
|
|
if(result.errMsg == 'checkSession:ok'){ // 处于登录状态 session未过期 |
|
|
if(result.errMsg == 'checkSession:ok'){ // 处于登录状态 session未过期 |
|
|
let login_token = uni.getStorageSync('login_token'); |
|
|
|
|
|
|
|
|
// let login_token = uni.getStorageSync('login_token'); |
|
|
|
|
|
let login_token = undefined; |
|
|
if(login_token){ |
|
|
if(login_token){ |
|
|
resolve(login_token); |
|
|
resolve(login_token); |
|
|
}else{ |
|
|
}else{ |
|
|
|