提交 7ecfb597 作者: 王进

提示升级微信

上级 54106925
...@@ -120,9 +120,8 @@ class WechatSDK { ...@@ -120,9 +120,8 @@ class WechatSDK {
console.log(err) console.log(err)
}) })
} }
private doLogin(res, LoginCallBack, target?) { private doLogin(res, LoginCallBack) {
const that = this const that = this
if(target) target.destroy()
// 获取用户信息 // 获取用户信息
const userInfo = res const userInfo = res
const UserObj = { const UserObj = {
...@@ -587,8 +586,8 @@ class WechatSDK { ...@@ -587,8 +586,8 @@ class WechatSDK {
const that = this const that = this
const w = (wx as any).getSystemInfoSync().windowWidth const w = (wx as any).getSystemInfoSync().windowWidth
const h = (wx as any).getSystemInfoSync().windowHeight const h = (wx as any).getSystemInfoSync().windowHeight
let UserInfoButton; // 按钮对象 if ((wx as any).createUserInfoButton) { // 做兼容
const BtnObjParam = { // 按钮样式 const UserInfoButton = (wx as any).createUserInfoButton({ // 按钮样式
type: 'text', type: 'text',
text: ' ', text: ' ',
style: { style: {
...@@ -599,43 +598,14 @@ class WechatSDK { ...@@ -599,43 +598,14 @@ class WechatSDK {
backgroundColor: 'rgba(0, 0, 0, 0)', backgroundColor: 'rgba(0, 0, 0, 0)',
color: '#ffffff' color: '#ffffff'
} }
}
if ((wx as any).createUserInfoButton) { // 做兼容
UserInfoButton = (wx as any).createUserInfoButton(BtnObjParam)
UserInfoButton.onTap(res => {
if (res.userInfo) that.doLogin(res, LoginCallBack, UserInfoButton) // 用户重新授权
}) })
} else { UserInfoButton.onTap(res => {
UserInfoButton = (wx as any).createopenSettingButton(BtnObjParam) UserInfoButton.destroy()
UserInfoButton.onTap(async res => { if (res.userInfo) that.doLogin(res, LoginCallBack) // 用户重新授权
const status = await that.getSetting();
if (status == 1) {
const userInfo = await that.getUserInfo();
if(userInfo) that.doLogin(userInfo, LoginCallBack, UserInfoButton)
}
}) })
}
}
private async getSetting(): Promise<any> { //获取授权配置
return new Promise((resolve, reject) => {
(wx as any).getSetting({
success: res => {
const authSetting = res.authSetting
if (authSetting['scope.userInfo'] === true) {
resolve(1)
} else if (authSetting['scope.userInfo'] === false) {
resolve(0)
} else { } else {
resolve(-1) that.sdkAlert('微信版本过低,请升级客户端。')
} }
},
fail: () => {
reject()
},
complete: () => { }
})
})
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论