useIOTComponent.js 1.78 KB
Newer Older
邓晓峰's avatar
邓晓峰 committed
1 2 3 4 5 6
import Cookies from 'js-cookie';
import React from 'react';
import { LOGIN_DISPLAY, LOGIN_WAY } from '@/constants';
import Account from './useAccount';
import IOTQRCode from './useIOTQRCode';
import Phone from './usePhone';
7
import { useIntl } from '@wisdom-utils/components';
邓晓峰's avatar
邓晓峰 committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
import styles from '../style.less';

const useIOTComponent = props => {
  const handlerType = type => {
    props.setType(LOGIN_DISPLAY[type]);
    props.updateLoginMode(LOGIN_WAY[type]);
    Cookies.set('loginMode', LOGIN_WAY[type], {
      expires: 5 * 60 * 1000,
      path: '/',
    });
  };
  return (
    <div className={styles.wechatQRcode}>
      {props.type === LOGIN_DISPLAY.Account ? (
        <Account {...props} />
      ) : props.type === LOGIN_DISPLAY.WeChart ? (
        <IOTQRCode {...props} />
      ) : props.type === LOGIN_DISPLAY.Mobile ? (
        <Phone {...props} />
      ) : (
        <Account {...props} />
      )}
      <div className={styles.loginDisplay}>
        <a
          onClick={() => handlerType('Account')}
          style={{
            display: props.type === LOGIN_DISPLAY.Account ? 'none' : 'block',
          }}
        >
          {useIntl().formatMessage({ id: 'pages.login.accountLogin.tab' })}
        </a>
        <a
          onClick={() => handlerType('WeChart')}
          style={{
            display: props.type === LOGIN_DISPLAY.WeChart ? 'none' : 'block',
          }}
        >
          {useIntl().formatMessage({ id: 'pages.login.weChart.tab' })}
        </a>
        <a
          onClick={() => handlerType('Mobile')}
          style={{
            display: props.type === LOGIN_DISPLAY.Mobile ? 'none' : 'block',
          }}
        >
          {useIntl().formatMessage({ id: 'pages.login.phoneLogin.tab' })}
        </a>
      </div>
    </div>
  );
};
export default useIOTComponent;