|
@ -126,6 +126,7 @@ |
|
|
const uniLogin = util.promisify(uni.login); |
|
|
const uniLogin = util.promisify(uni.login); |
|
|
const uniGetUserInfo= util.promisify(uni.getUserInfo); |
|
|
const uniGetUserInfo= util.promisify(uni.getUserInfo); |
|
|
const app = getApp(); |
|
|
const app = getApp(); |
|
|
|
|
|
const APPID = uni.getAccountInfoSync().miniProgram.appId; |
|
|
export default { |
|
|
export default { |
|
|
computed: { |
|
|
computed: { |
|
|
|
|
|
|
|
@ -139,9 +140,19 @@ |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
async onLoad() { |
|
|
async onLoad() { |
|
|
await this.checkUserAuthor(); |
|
|
|
|
|
this.isLogin = app.isLogin(); |
|
|
|
|
|
if(!!app.isLogin())this.getIndexInfo(); |
|
|
|
|
|
|
|
|
try{ |
|
|
|
|
|
util.showLoad(); |
|
|
|
|
|
await this.checkUserAuthor(); |
|
|
|
|
|
util.hideLoad(); |
|
|
|
|
|
this.$nextTick(_=>this.isLogin = app.isLogin()); |
|
|
|
|
|
if(!!app.isLogin())this.getIndexInfo(); |
|
|
|
|
|
}catch(err){ |
|
|
|
|
|
util.hideLoad(); |
|
|
|
|
|
uni.removeStorageSync('token'); |
|
|
|
|
|
this.$nextTick(_=>this.isLogin = app.isLogin()); |
|
|
|
|
|
util.showNone(err.message || '身份校验失败!'); |
|
|
|
|
|
console.log('onLoad err',err); |
|
|
|
|
|
} |
|
|
}, |
|
|
}, |
|
|
onShow(){ |
|
|
onShow(){ |
|
|
let { indexData } = this; |
|
|
let { indexData } = this; |
|
@ -181,17 +192,45 @@ |
|
|
try{ |
|
|
try{ |
|
|
let setting; |
|
|
let setting; |
|
|
try{setting = await uniGetSetting({})}catch(err){console.error(err)}; |
|
|
try{setting = await uniGetSetting({})}catch(err){console.error(err)}; |
|
|
|
|
|
|
|
|
if(setting&&setting.authSetting&&setting.authSetting['scope.userInfo'] === true){ |
|
|
if(setting&&setting.authSetting&&setting.authSetting['scope.userInfo'] === true){ |
|
|
|
|
|
|
|
|
let [ loginRes, userRes ] = await Promise.all([uniLogin(), uniGetUserInfo()]); |
|
|
let [ loginRes, userRes ] = await Promise.all([uniLogin(), uniGetUserInfo()]); |
|
|
console.log(codeRes); |
|
|
|
|
|
console.log(userInfo); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return servers.post({ |
|
|
|
|
|
url: API.wechatMiniAppLoginAndSync, |
|
|
|
|
|
data: { |
|
|
|
|
|
appid: APPID, |
|
|
|
|
|
code: loginRes.code, |
|
|
|
|
|
encryptedData: userRes.encryptedData, |
|
|
|
|
|
iv: userRes.iv, |
|
|
|
|
|
is_details: 1, |
|
|
|
|
|
}, |
|
|
|
|
|
isDefaultGet: false, |
|
|
|
|
|
}) |
|
|
|
|
|
.then(res=>{ |
|
|
|
|
|
util.hideLoad(); |
|
|
|
|
|
if(res.data.code == 0){ |
|
|
|
|
|
let _data = res.data.data; |
|
|
|
|
|
if(_data.user.role == ''){ |
|
|
|
|
|
uni.removeStorageSync('token'); |
|
|
|
|
|
return util.routeTo(`/pages/merchant_login/merchant_login`,'rL'); |
|
|
|
|
|
} |
|
|
|
|
|
uni.setStorageSync('token',_data.token); |
|
|
|
|
|
|
|
|
|
|
|
return _data; |
|
|
|
|
|
}else{ |
|
|
|
|
|
throw res.data || {}; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}) |
|
|
|
|
|
.catch(err=>{ |
|
|
|
|
|
throw err; |
|
|
|
|
|
}) |
|
|
}else{ |
|
|
}else{ |
|
|
uni.removeStorageSync('token'); |
|
|
|
|
|
|
|
|
throw 'author err'; |
|
|
} |
|
|
} |
|
|
}catch(err){ |
|
|
}catch(err){ |
|
|
|
|
|
|
|
|
|
|
|
throw err; |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
showAuthor(){ |
|
|
showAuthor(){ |
|
@ -214,7 +253,6 @@ |
|
|
this.closeAuthor(); |
|
|
this.closeAuthor(); |
|
|
return util.showNone('获取登陆凭证失败!稍后重试'); |
|
|
return util.showNone('获取登陆凭证失败!稍后重试'); |
|
|
} |
|
|
} |
|
|
const APPID = uni.getAccountInfoSync().miniProgram.appId; |
|
|
|
|
|
|
|
|
|
|
|
util.showLoad(); |
|
|
util.showLoad(); |
|
|
|
|
|
|
|
|