index.js 9.92 KB
Newer Older
周宏民's avatar
周宏民 committed
1 2 3 4 5 6 7
/*
 * 功能名称: 宿州登录页
 * 功能路径:
 * 功能参数:
 */

import React, { forwardRef, useEffect, useRef, useState } from 'react';
8
import { CaretUpOutlined, CaretDownOutlined } from '@ant-design/icons';
周宏民's avatar
周宏民 committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
import { Modal, Popover } from 'antd';
import { Helmet, HelmetProvider } from 'react-helmet-async';
import { connect } from 'react-redux';
import { useHistory, withRouter } from '@wisdom-utils/runtime';
import { actionCreators } from '@/containers/App/store';
import classnames from 'classnames';
import moment from 'moment';
import QueueAnim from 'rc-queue-anim';
import QRCode from 'qrcode.react';
import defaultSetting from '../../../../../../../config/defaultSetting';
import LoginAction from '../../../login';
import styles from './index.less';
import Account from './Account';
import { defaultApp } from '../../../../../../micro';
import logo from './images/logo.png';
import qrcodePng from './images/1.png';
import loginTitlePng from './images/text.png';
import Krpano from '../../../components/Krpano';
27 28 29 30 31 32
// 背景图在这里引入一次,避免打包时丢失
import 背景 from './images/背景.png';
import left from './images/left.png';
import 标题 from './images/标题.png';
import 登录btn from './images/登录btn.png';
import 展开bg from './images/展开bg.png';
周宏民's avatar
周宏民 committed
33 34 35 36 37 38 39 40 41 42 43

const PopOvercontent = () => {
  const qrcodes = window.globalConfig && window.globalConfig.qrcode;
  if (qrcodes) {
    return <QRCode value={qrcodes} />;
  }
  return <span>手持APP下载未配置</span>;
};
const welcomeList = ['诚信为基', '合作共赢', '以人为本', '效益优先'];

const Login = forwardRef((props, _ref) => {
44 45
  const { isVerificationCode, isVerification, verificationCodeType } = window.globalConfig;
  const isValidate = (isVerification || 0) * 1 === 1 || isVerificationCode;
周宏民's avatar
周宏民 committed
46 47
  const loginFormRef = useRef();
  const formRef = useRef(null);
48 49 50
  const krpanoObjRef = useRef(null);
  const krpanoRef = useRef(null);
  const krpanoSceneIdRef = useRef(localStorage.getItem('loginKrpanoSceneId'));
周宏民's avatar
周宏民 committed
51
  const [status, setStatus] = useState('normal');
52
  const [showList, setShowList] = useState(false);
周宏民's avatar
周宏民 committed
53 54 55 56 57 58 59 60
  const [autoLogin, setAutoLogin] = useState(false);
  const [submitting, setSubmitting] = useState(false);
  const [type, setType] = useState('Account');
  const [visible, setVisible] = useState(false);
  const history = useHistory();
  const [action, setAction] = useState(() => new LoginAction(Object.assign({}, props, { history }), setVisible, false));
  const [dateObj, setDateObj] = useState({});
  const { projectName } = props.loginParams;
61
  const [tabShow, setTabShow] = useState(false);
周宏民's avatar
周宏民 committed
62 63 64 65
  const handleSubmit = values => {
    /* eslint-disable */
    action &&
      (type === 'Account'
66 67 68
        ? isValidate
          ? action.loginHandlerValidate(values.userName, values.password, null, autoLogin, 'none', values?.validate)
          : action.loginHandler(values.userName, values.password, null, autoLogin, sliVerify)
周宏民's avatar
周宏民 committed
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
        : type === 'Mobile'
        ? action.phoneLoginFormHandler(values.mobile, values.captcha)
        : null);

    setSubmitting(true);
    props.updateCurrentIndex && props.updateCurrentIndex(-1);
  };

  useEffect(() => {
    action &&
      action.events.on('loginSuccess', event => {
        setSubmitting(false);
        props.updateCurrentIndex && props.updateCurrentIndex(0);
        props.history.push(`/?client=${props.global.client}`);

        defaultApp();
      });
    action &&
      action.events.on('loginError', event => {
        setVisible(false);
        setSubmitting(false);
      });
    action &&
      action.events.on('loginVisible', status => {
        setVisible(status);
      });
    return () => {
      action && action.events && action.events.removeAllListeners('loginSuccess');
      action && action.events && action.events.removeAllListeners('loginError');
      action && action.events && action.events.removeAllListeners('loginVisible');
    };
  }, [props.loginMode]);

  useEffect(() => {
    setSubmitting(false);
  }, [visible]);

  const renderPlatform = () => {
    const template = props.global.loginTemplate;
    const params = {
      fromRef: formRef,
      type,
      setType,
      status,
      submitting,
      autoLogin,
      setAutoLogin,
      action,
      onSubmit: handleSubmit,
      loginMode: props.loginMode,
      updateLoginMode: props.updateLoginMode,
      welcome: null,
    };
    return <Account {...params} isValidate={isValidate} />;
  };
  /* eslint-disable */

  const handleWeek = () => {
    const weekOfDay = Number(moment().format('E'));

    let weekDayName = '';
    switch (weekOfDay) {
      case 1:
        weekDayName = '周一';
        break;
      case 2:
        weekDayName = '周二';
        break;
      case 3:
        weekDayName = '周三';
        break;
      case 4:
        weekDayName = '周四';
        break;
      case 5:
        weekDayName = '周五';
        break;
      case 6:
        weekDayName = '周六';
        break;
      case 7:
        weekDayName = '周日';
        break;
      default:
        weekDayName = '';
    }
    return weekDayName;
  };
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
  const onChangeShow = () => {
    setShowList(!showList);
  };
  const loadedHook = ({ krpanoSwfObject, krpano, json, eventEmitter }) => {
    krpanoObjRef.current = krpanoSwfObject;
    if (krpanoSceneIdRef.current && krpanoObjRef.current) {
      krpanoSwfObject.callKrpano(
        `autorotate.interrupt();loadscene(${krpanoSceneIdRef.current},null, MERGE, BLEND(1.0))`,
      );
    }
    krpanoRef.current = krpano;
    window.krpano = krpano;
    setTabShow(true);
  };
  const sceneLoadedHook = scenename => {
    if (krpanoRef.current) {
      const id = krpanoRef.current.get('xml.scene');
      localStorage.setItem('loginKrpanoSceneId', id || null);
    }
  };
周宏民's avatar
周宏民 committed
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
  useEffect(() => {
    const timer = setInterval(() => {
      setDateObj({
        curTime: moment().format('HH:mm:ss'),
        week: handleWeek(),
        date: moment().format('YYYY/MM/DD'),
      });
    }, 1000);
    return () => {
      clearInterval(timer);
    };
  }, []);

  return (
    <HelmetProvider>
      <Helmet>
        <title>{props.global.title || defaultSetting.title}</title>
        <meta name="description" content={props.global.title || defaultSetting.title} />
      </Helmet>

      <div className={classnames(styles.suzhoulogin, 'suzhoulogin')}>
        <div className={classnames(styles['wrapper'])}>
          <QueueAnim type="scale" duration={1000}>
            <div key={'innerwrapper'} className={classnames(styles['inner-wrapper'])}>
              <div className={classnames(styles['inner-center'])}>
                <div className={styles['welcome-title']}>
                  <img src={loginTitlePng} alt="login-title" className={styles['welcome-title-img']} />
                </div>
                <div className={styles['welcome-list']}>
                  {welcomeList.map(item => (
                    <div className={styles['welcome-list_item']} key={item}>
                      {item}
                    </div>
                  ))}
                </div>
                <div className={classnames(styles['inner-bg'], styles['login-part'])} ref={loginFormRef}>
                  {renderPlatform()}
                </div>
              </div>
              <Popover
                content={PopOvercontent}
                title="扫码下载APP"
                placement="right"
                overlayClassName={'popover-style'}
              >
                <img src={qrcodePng} alt="APP" className={styles['qrcode-box']} />
              </Popover>
            </div>
          </QueueAnim>

          <div key="loginheader" className={classnames(styles['login-header'])}>
            <QueueAnim type="left">
              <div key="logintitle" className={styles['left-title']}>
                <div>
                  <img src={logo} alt="logo" />
                </div>
                <div className={styles['cn-title']} />
              </div>
            </QueueAnim>
            <QueueAnim type="right">
              <div key="logintime" className={styles['right-timebox']}>
                <div className={styles['curr-time']}>{dateObj.curTime}</div>
                <div className={styles['curr-week-date']}>
                  <div className={styles['curr-week']}>{dateObj.week}</div>
                  <div className={styles['curr-date']}>{dateObj.date}</div>
                </div>
              </div>
            </QueueAnim>
          </div>
          {/* <div className={styles['copyright']}>
247 248 249
            Copyright ©水务投资建设有限公司All Rights Reserved{' '}
            <a target="_blank" id="IndexCaseNumber" href="https://">
              渝ICP备
周宏民's avatar
周宏民 committed
250 251 252
            </a>
          </div> */}
        </div>
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
        <div className={classnames(styles['krpano'], 'suzhou_krpano', !showList ? 'suzhou_hideList' : '')}>
          {tabShow ? (
            <div className={classnames(styles.krpano_btn, 'krpano_btn')} onClick={onChangeShow}>
              {showList ? (
                <CaretDownOutlined className={styles.krpano_btn_icon} />
              ) : (
                <CaretUpOutlined className={styles.krpano_btn_icon} />
              )}
              切换全景
            </div>
          ) : null}

          <Krpano
            projectName={projectName}
            style={{ background: '#fff' }}
            loadedHook={loadedHook}
            sceneLoadedHook={sceneLoadedHook}
          />
周宏民's avatar
周宏民 committed
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
        </div>
      </div>
    </HelmetProvider>
  );
});

const mapStateToProps = state => ({
  global: state.getIn(['global', 'globalConfig']),
  loginMode: state.getIn(['global', 'loginMode']),
});

const mapDispatchToProps = dispatch => ({
  updateConfig(config) {
    dispatch(actionCreators.getConfig(config));
  },
  createContext(data) {
    dispatch(actionCreators.createContext(data));
  },
  updateLoginMode(mode) {
    dispatch(actionCreators.changeLoginMode(mode));
  },
  updateCurrentIndex(index) {
    dispatch(actionCreators.updateCurrentIndex(index));
  },
});
export default connect(
  mapStateToProps,
  mapDispatchToProps,
)(withRouter(Login));