import React from 'react'; import './index.less'; import Page from '@src/containers/Page'; import { asyncSMessage } from '@src/services/AsyncTools'; import { WechatH5AppId, H5Url } from '../../../../Constant'; import { User } from '../../../stores/user'; export default class extends Page { init() { const { code, state = '' } = this.props.core.query; console.log(this.state); const [scope, jump] = state.split('|'); if (code) { User.loginWechat(code, !!scope).then((info) => { if (!info.id && !scope) { this.redirect('snsapi_userinfo', `1|${jump || '/'}`); } else if (info.bindMobile) { toLink(jump || '/'); } else { replaceLink(`/bind?url=${encodeURIComponent(jump)}`); } }) .catch(e => { asyncSMessage(e.message, 'error'); }); } else { this.redirect('snsapi_base', `|${this.state.search.url || '/'}`); } } redirect(scope, state) { const url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${WechatH5AppId}&redirect_uri=${encodeURIComponent( `${H5Url}/login`, )}&response_type=code&scope=${scope}&state=${encodeURIComponent(state)}#wechat_redirect`; window.location.href = url; } renderView() { return
; } }