import store from '@/store/index.js' import authorize from '@/common/config/authorize.js' import ajaxService from '@/services/ajax.service.js' import UserService from '@/services/user.service' const newUserService = new UserService(ajaxService) // 根据微信的code获取用户登录状态:1已登录过 -1未登录过 const wxLoginAuthorize = async function(){ const wechatCode = await authorize.getCode('weixin');// 根据微信的code获取用户登录状态:1已登录过 -1未登录过 newUserService.UserWechatAuthorLogin( { code:wechatCode } ) .then(response =>{ const _data = JSON.parse(response.data); store.commit('updateStatus',_data) store.commit('login',_data); uni.setStorageSync('openId',_data.openId) }) .catch(error =>{ const _data = JSON.parse(error.data); uni.setStorageSync('openId',_data.openId) store.commit('logout',_data) store.commit('updateStatus',_data) }) } const wxLoginQuick = async function(){// 根据微信的code获取用户登录状态:1已登录过 -1未登录过跳转 const wechatCode = await authorize.getCode('weixin');// 根据微信的code获取用户登录状态:1已登录过 -1未登录过 const getUserInfo = await authorize.getUserInfo('weixin'); const params = newUserService.UserWechatAuthorLogin( { code:wechatCode } ) .then(response =>{ const _data = JSON.parse(response.data); store.commit('updateStatus',_data) store.commit('login',_data); uni.setStorageSync('openId',_data.openId) }) .catch(error =>{ const _data = JSON.parse(response.data); uni.setStorageSync('openId',_data.openId) store.commit('logout',_data) store.commit('updateStatus',_data) }) } export default{ wxLoginAuthorize, wxLoginQuick }