import store from '@/store/index.js' import authorize from '@/common/config/authorize.js' import { userInfoLogin } from '@/services/user.service.js' // 根据微信的code获取用户登录状态:1已登录过 -1未登录过 const wxLoginAuthorize = function() { authorize.getCode('weixin').then(wechatcode => { console.log('code:' + wechatcode) authorize.getUserInfo('weixin').then(wxResponse => { userInfoLogin({ code: wechatcode }).then(response => { store.commit('updateStatus', response.data) store.commit('login', response.data) }).catch(error => { console.log(error) store.commit('logout', error.data) store.commit('updateStatus', error.data) }) }) }) } const wxLoginQuick = function() { // 根据微信的code获取用户登录状态:1已登录过 -1未登录过跳转 authorize.getCode('weixin').then(wechatcode => { // 根据微信的code获取用户登录状态:1已登录过 -1未登录过 authorize.getUserInfo('weixin').then(wxResponse => { userInfoLogin({ code: wechatcode, encryptedData: wxResponse.encryptedData, iv: wxResponse.iv }).then(response => { console.log(response) store.commit('updateStatus', response.data) store.commit('login', response.data) store.commit('wxLogin', wxResponse.userInfo) if (response.data.userIdentity == 1) { uni.navigateTo({ url: '/seller/pages/index/index' }) } else if (response.data.userIdentity === 3) { uni.navigateTo({ url: '/supplier/pages/index/index' }) } else { uni.switchTab({ url: '/pages/tabBar/user/user' }) } }).catch(error => { store.commit('logout', error.data) store.commit('updateStatus', error.data) store.commit('wxLogin', wxResponse.userInfo) }) }) }) } export default { wxLoginAuthorize, wxLoginQuick }