page.js 914 B

123456789101112131415161718192021222324252627282930313233
  1. import React from 'react';
  2. import './index.less';
  3. import Page from '@src/containers/Page';
  4. import { WechatH5AppId } from '../../../../Constant';
  5. import { User } from '../../../stores/user';
  6. export default class extends Page {
  7. init() {
  8. const { code, url } = this.props.core.query;
  9. if (code) {
  10. User.loginWechat(code).then(info => {
  11. if (info.bindMobile) {
  12. if (url) {
  13. toLink(url);
  14. } else {
  15. replaceLink('/');
  16. }
  17. } else {
  18. replaceLink(`/bind?url=${url}`);
  19. }
  20. });
  21. } else {
  22. const authUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${WechatH5AppId}&redirect_uri=${encodeURIComponent(
  23. `${window.location.href}`,
  24. )}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect`;
  25. window.location.href = authUrl;
  26. }
  27. }
  28. renderView() {
  29. return <div />;
  30. }
  31. }