12345678910111213141516171819202122232425262728293031323334353637383940 |
- import React from 'react'
- import { login } from '@/apis'
- import router from 'umi/router'
- function getQueryString(name) {
- const reg = new RegExp(`(^|&)${name}=([^&]*)(&|$)`);
- const r = window.location.search.substr(1).match(reg);
- if (r != null) return unescape(r[2]); return '';
- }
- class LoginPage extends React.PureComponent {
- toLoginPage () {
- window.location.href = `https://login.weipaitang.com/wechatLogin?loginUrl=${window.locationn.host}/login`
- }
- async doLogin (token) {
- const redirect = getQueryString('redirect');
- const { code } = await login({ token, redirect, domain: window.location.hostname })
- if (code === 0) {
- router.push('/')
- } else {
- this.toLoginPage()
- }
- }
- async componentDidMount () {
- const token = this.props.location.query.token
- if (token) {
- await this.doLogin(token)
- } else {
- this.toLoginPage()
- }
- }
- render () {
- return <div></div>
- }
- }
- export default LoginPage
|