index.js 973 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import React from 'react'
  2. import { login } from '@/apis'
  3. import router from 'umi/router'
  4. function getQueryString(name) {
  5. const reg = new RegExp(`(^|&)${name}=([^&]*)(&|$)`);
  6. const r = window.location.search.substr(1).match(reg);
  7. if (r != null) return unescape(r[2]); return '';
  8. }
  9. class LoginPage extends React.PureComponent {
  10. toLoginPage () {
  11. window.location.href = `https://login.weipaitang.com/wechatLogin?loginUrl=${window.locationn.host}/login`
  12. }
  13. async doLogin (token) {
  14. const redirect = getQueryString('redirect');
  15. const { code } = await login({ token, redirect, domain: window.location.hostname })
  16. if (code === 0) {
  17. router.push('/')
  18. } else {
  19. this.toLoginPage()
  20. }
  21. }
  22. async componentDidMount () {
  23. const token = this.props.location.query.token
  24. if (token) {
  25. await this.doLogin(token)
  26. } else {
  27. this.toLoginPage()
  28. }
  29. }
  30. render () {
  31. return <div></div>
  32. }
  33. }
  34. export default LoginPage