45 lines
861 B
JavaScript
45 lines
861 B
JavaScript
import {
|
|
$bindWx,
|
|
$bindStatus
|
|
} from '@/api/login/login.js'
|
|
|
|
// 绑定状态
|
|
export async function bindStatus() {
|
|
const res = await $bindStatus()
|
|
return res.wxBind ? true : false;
|
|
}
|
|
export function toBindWx() {
|
|
uni.navigateTo({
|
|
url: '/pages/login/bindWx'
|
|
})
|
|
|
|
}
|
|
//绑定微信
|
|
export async function bindWx() {
|
|
console.log('bindWx');
|
|
const isBind = await bindStatus()
|
|
if (isBind) {
|
|
uni.showToast({
|
|
title: '已绑定微信,请勿重复绑定',
|
|
icon: 'none'
|
|
})
|
|
return
|
|
}
|
|
return new Promise((reslove, reject) => {
|
|
uni.login({
|
|
"provider": "weixin",
|
|
"onlyAuthorize": true, // 微信登录仅请求授权认证
|
|
success: function(loginRes) {
|
|
console.log(loginRes);
|
|
reslove(loginRes.code)
|
|
},
|
|
fail: function(err) {
|
|
// 登录授权失败
|
|
// err.code是错误码
|
|
console.log(err);
|
|
reject()
|
|
}
|
|
});
|
|
})
|
|
|
|
} |