wxLogin.js 1.1 KB

123456789101112131415161718192021222324252627
  1. import store from '@/store/index.js'
  2. import authorize from '@/common/config/authorize.js'
  3. import { userInfoLogin } from "@/api/use.js"
  4. // 根据微信的code获取用户登录状态:1已登录过 -1未登录过
  5. const wxLoginAuthorize = function(){
  6. authorize.getCode('weixin').then(wechatcode =>{
  7. authorize.getUserInfo('weixin').then(wxResponse =>{
  8. userInfoLogin({code:wechatcode,encryptedData:wxResponse.encryptedData,iv:wxResponse.iv}).then(response =>{
  9. store.commit('updateStatus',response.data)
  10. store.commit('login',response.data);
  11. store.commit('wxLogin',wxResponse.userInfo);
  12. uni.setStorageSync('token',response.data.token)
  13. uni.removeStorageSync('sessionid')
  14. uni.setStorageSync('sessionid','JSESSIONID='+response.data.sessionId)
  15. }).catch(response =>{
  16. uni.removeStorageSync('sessionid')
  17. uni.setStorageSync('sessionid','JSESSIONID='+response.data)
  18. store.commit('logout',response.data)
  19. store.commit('updateStatus',response.data)
  20. store.commit('wxLogin',wxResponse.userInfo);
  21. })
  22. })
  23. })
  24. }
  25. export default{
  26. wxLoginAuthorize
  27. }