index.js 18.7 KB
Newer Older
邓晓峰's avatar
邓晓峰 committed
1 2
import 'kit_utils/lib/format';

邓晓峰's avatar
邓晓峰 committed
3
import React, { forwardRef, useEffect, useRef, useState } from 'react';
dengxiaofeng's avatar
dengxiaofeng committed
4

邓晓峰's avatar
邓晓峰 committed
5
import { Alert, Checkbox, Form, Modal, Popover } from 'antd';
dengxiaofeng's avatar
dengxiaofeng committed
6
import classNames from 'classnames';
邓晓峰's avatar
邓晓峰 committed
7
import { encode } from 'js-base64';
邓晓峰's avatar
邓晓峰 committed
8
import Cookies from 'js-cookie';
dengxiaofeng's avatar
dengxiaofeng committed
9
import { dom } from 'kit_utils';
邓晓峰's avatar
邓晓峰 committed
10
import QRCode from 'qrcode.react';
dengxiaofeng's avatar
dengxiaofeng committed
11 12
import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom';
13
import { Helmet, HelmetProvider } from 'react-helmet-async';
dengxiaofeng's avatar
dengxiaofeng committed
14 15
import { actionCreators } from '../../../containers/App/store';
import LoginForm from './components/Login';
邓晓峰's avatar
邓晓峰 committed
16
import WxLogin from './components/WxLogin';
邓晓峰's avatar
邓晓峰 committed
17
import LoginAction from './login';
dengxiaofeng's avatar
dengxiaofeng committed
18
import styles from './style.less';
邓晓峰's avatar
邓晓峰 committed
19
import i18n from '../../../utils/share';
20
import defaultSetting from '../../../../config/defaultSetting';
邓晓峰's avatar
邓晓峰 committed
21
const { UserName, Password, Mobile, Captcha, Submit } = LoginForm;
邓晓峰's avatar
邓晓峰 committed
22
const Display = {
邓晓峰's avatar
邓晓峰 committed
23 24 25 26
  Account: 'Account',
  WeChart: 'WeChart',
  Mobile: 'Mobile',
};
邓晓峰's avatar
邓晓峰 committed
27
const LoginWay = {
邓晓峰's avatar
邓晓峰 committed
28 29 30 31
  Account: 'pdw',
  WeChart: 'iotWechat',
  Mobile: 'iotPhone',
};
邓晓峰's avatar
邓晓峰 committed
32
const pages = i18n.getI18n('pages');
dengxiaofeng's avatar
dengxiaofeng committed
33 34 35
const LoginMessage = ({ content }) => (
  <Alert
    style={{
邓晓峰's avatar
邓晓峰 committed
36
      marginBottom: 2,
dengxiaofeng's avatar
dengxiaofeng committed
37 38 39 40 41 42 43
    }}
    message={content}
    type="error"
    showIcon
  />
);

邓晓峰's avatar
邓晓峰 committed
44 45 46
const useRenderQcode = props => {
  if (!props.qrcode) {
    return null;
邓晓峰's avatar
邓晓峰 committed
47
  }
邓晓峰's avatar
邓晓峰 committed
48
  const qrcodes = props.qrcode.split('|');
邓晓峰's avatar
邓晓峰 committed
49 50 51 52 53 54 55 56 57
  const qcodeComponent = url => (
    <img
      src={url}
      className="QuickMark-cont"
      style={{ width: '150px', height: '150px' }}
      alt=""
    />
  );
  const element = [];
邓晓峰's avatar
邓晓峰 committed
58
  qrcodes.forEach((item, index) => {
邓晓峰's avatar
邓晓峰 committed
59 60 61
    const firstValue = item.split('=');
    switch (firstValue[0]) {
      case '小程序':
邓晓峰's avatar
邓晓峰 committed
62
        element.push(
邓晓峰's avatar
邓晓峰 committed
63 64 65 66 67
          <div
            className={classNames(
              styles['quickMark-single'],
              styles['mini-single'],
            )}
邓晓峰's avatar
邓晓峰 committed
68
            key={firstValue[0]}
邓晓峰's avatar
邓晓峰 committed
69 70 71 72 73 74 75
          >
            <Popover
              placement="top"
              content={qcodeComponent(
                'https://panda-water.cn/web4/assets/images/小程序二维码.jpg',
              )}
            >
邓晓峰's avatar
邓晓峰 committed
76
              <div className={styles['icon-Container']}>
邓晓峰's avatar
邓晓峰 committed
77 78
                <span className={styles.Wechat} />
                <span className="iconText WechatText">Wechat</span>
邓晓峰's avatar
邓晓峰 committed
79 80
              </div>
            </Popover>
邓晓峰's avatar
邓晓峰 committed
81 82
          </div>,
        );
邓晓峰's avatar
邓晓峰 committed
83
        break;
邓晓峰's avatar
邓晓峰 committed
84
      case '智联小程序':
邓晓峰's avatar
邓晓峰 committed
85
        element.push(
邓晓峰's avatar
邓晓峰 committed
86 87
          <div
            className={classNames(styles['quickMark-single'], 'miniIOT-single')}
邓晓峰's avatar
邓晓峰 committed
88
            key={firstValue[0]}
邓晓峰's avatar
邓晓峰 committed
89 90 91 92 93 94 95
          >
            <Popover
              placement="top"
              content={qcodeComponent(
                'https://panda-water.cn/web4/assets/images/智联小程序二维码.jpg',
              )}
            >
邓晓峰's avatar
邓晓峰 committed
96
              <div className={styles['icon-Container']}>
邓晓峰's avatar
邓晓峰 committed
97 98 99 100 101 102
                <span className={styles.Wechat} />
                <span
                  className={classNames(styles.iconText, styles.WechatText)}
                >
                  熊猫智联
                </span>
邓晓峰's avatar
邓晓峰 committed
103 104
              </div>
            </Popover>
邓晓峰's avatar
邓晓峰 committed
105 106
          </div>,
        );
邓晓峰's avatar
邓晓峰 committed
107
        break;
邓晓峰's avatar
邓晓峰 committed
108 109 110

      case 'Android':
        if (firstValue[1] && firstValue[1].replace(/ /g, '').length > 0) {
邓晓峰's avatar
邓晓峰 committed
111
          element.push(
邓晓峰's avatar
邓晓峰 committed
112 113 114 115 116
            <div
              className={classNames(
                styles['quickMark-single'],
                'Android-single',
              )}
邓晓峰's avatar
邓晓峰 committed
117
              key={firstValue[0]}
邓晓峰's avatar
邓晓峰 committed
118 119 120 121 122 123 124 125 126 127 128 129
            >
              <Popover
                placement="top"
                content={
                  <QRCode
                    value={firstValue[1].replace(
                      /{ip}/gi,
                      props.ip || window.location.host,
                    )}
                  />
                }
              >
邓晓峰's avatar
邓晓峰 committed
130
                <div className={styles['icon-Container']}>
邓晓峰's avatar
邓晓峰 committed
131 132 133 134 135 136
                  <span className={styles.Android} />
                  <span
                    className={classNames(styles.iconText, styles.AndroidText)}
                  >
                    Android
                  </span>
邓晓峰's avatar
邓晓峰 committed
137 138
                </div>
              </Popover>
邓晓峰's avatar
邓晓峰 committed
139 140
            </div>,
          );
邓晓峰's avatar
邓晓峰 committed
141
        }
邓晓峰's avatar
邓晓峰 committed
142
        break;
邓晓峰's avatar
邓晓峰 committed
143 144
      case 'iPhone':
        if (firstValue[1] && firstValue[1].replace(/ /g, '').length > 0) {
邓晓峰's avatar
邓晓峰 committed
145
          element.push(
邓晓峰's avatar
邓晓峰 committed
146 147 148 149 150
            <div
              className={classNames(
                styles['quickMark-single'],
                'iphone-single',
              )}
邓晓峰's avatar
邓晓峰 committed
151
              key={firstValue[0]}
邓晓峰's avatar
邓晓峰 committed
152 153 154 155 156 157 158 159 160 161 162 163
            >
              <Popover
                placement="top"
                content={
                  <QRCode
                    value={firstValue[1].replace(
                      /{ip}/gi,
                      props.ip || window.location.host,
                    )}
                  />
                }
              >
邓晓峰's avatar
邓晓峰 committed
164
                <div className={styles['icon-Container']}>
邓晓峰's avatar
邓晓峰 committed
165 166 167 168 169 170
                  <span className={styles.Wechat} />
                  <span
                    className={classNames(styles.iconText, styles.iphoneText)}
                  >
                    iPhone
                  </span>
邓晓峰's avatar
邓晓峰 committed
171 172
                </div>
              </Popover>
邓晓峰's avatar
邓晓峰 committed
173 174
            </div>,
          );
邓晓峰's avatar
邓晓峰 committed
175
        }
邓晓峰's avatar
邓晓峰 committed
176 177
        break;
      default:
邓晓峰's avatar
邓晓峰 committed
178 179
        if (item && item.replace(/ /g, '').length > 0) {
          const indexIndex = element.findIndex(
邓晓峰's avatar
邓晓峰 committed
180
            // eslint-disable-next-line no-shadow
邓晓峰's avatar
邓晓峰 committed
181 182
            item => item.props.className.indexOf('Android-single') > -1,
          );
邓晓峰's avatar
邓晓峰 committed
183
          element.splice(indexIndex, 1);
邓晓峰's avatar
邓晓峰 committed
184
          element.push(
邓晓峰's avatar
邓晓峰 committed
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
            <div
              className={classNames(
                styles['quickMark-single'],
                'Android-single',
              )}
              key={index}
            >
              <Popover
                placement="top"
                content={
                  <QRCode
                    value={item.replace(
                      /{ip}/gi,
                      props.ip || window.location.host,
                    )}
                  />
                }
              >
邓晓峰's avatar
邓晓峰 committed
203
                <div className={styles['icon-Container']}>
邓晓峰's avatar
邓晓峰 committed
204 205 206 207 208 209
                  <span className={styles.Android} />
                  <span
                    className={classNames(styles.iconText, styles.AndroidText)}
                  >
                    Android
                  </span>
邓晓峰's avatar
邓晓峰 committed
210 211
                </div>
              </Popover>
邓晓峰's avatar
邓晓峰 committed
212 213
            </div>,
          );
邓晓峰's avatar
邓晓峰 committed
214
        }
邓晓峰's avatar
邓晓峰 committed
215
        break;
邓晓峰's avatar
邓晓峰 committed
216
    }
邓晓峰's avatar
邓晓峰 committed
217
  });
邓晓峰's avatar
邓晓峰 committed
218
  return element;
邓晓峰's avatar
邓晓峰 committed
219
};
邓晓峰's avatar
邓晓峰 committed
220
/* eslint-disable */
邓晓峰's avatar
邓晓峰 committed
221 222 223 224
const Account = props => (
  <LoginForm onSubmit={props.onSubmit}>
    {props.status === 'error' &&
      props.type === 'account' &&
邓晓峰's avatar
邓晓峰 committed
225 226 227
      !props.submitting && (
        <LoginMessage content={pages.get('login.accountLogin.errorMessage')} />
      )}
邓晓峰's avatar
邓晓峰 committed
228 229
    <UserName
      name="userName"
邓晓峰's avatar
邓晓峰 committed
230
      placeholder={pages.get('login.username.placeholder')}
邓晓峰's avatar
邓晓峰 committed
231 232 233
      rules={[
        {
          required: true,
邓晓峰's avatar
邓晓峰 committed
234
          message: pages.get('login.username.required'),
邓晓峰's avatar
邓晓峰 committed
235 236 237 238 239
        },
      ]}
    />
    <Password
      name="password"
邓晓峰's avatar
邓晓峰 committed
240
      placeholder={pages.get('login.password.placeholder')}
邓晓峰's avatar
邓晓峰 committed
241 242 243
      rules={[
        {
          required: true,
邓晓峰's avatar
邓晓峰 committed
244
          message: pages.get('login.password.required'),
邓晓峰's avatar
邓晓峰 committed
245 246 247 248 249 250 251 252
        },
      ]}
    />
    <div>
      <Checkbox
        checked={props.autoLogin}
        onChange={e => props.setAutoLogin(e.target.checked)}
      >
邓晓峰's avatar
邓晓峰 committed
253
        {pages.get('login.rememberMe')}
邓晓峰's avatar
邓晓峰 committed
254 255
      </Checkbox>
    </div>
邓晓峰's avatar
邓晓峰 committed
256
    <Submit loading={props.submitting}>{pages.get('login.submit')}</Submit>
邓晓峰's avatar
邓晓峰 committed
257 258
  </LoginForm>
);
邓晓峰's avatar
邓晓峰 committed
259 260

const IOTQRCode = () => {
邓晓峰's avatar
邓晓峰 committed
261 262
  const REDIRECT_URI = 'https://panda-water.com/civbase/user/login';
  const APPID = 'wx8bfa8b02cb95010b';
邓晓峰's avatar
邓晓峰 committed
263 264 265 266 267
  const [rstate, setRstate] = useState(() =>
    encode(
      `panda_${Math.round(Math.random() * 10000 + Date.now()).toString(16)}`,
    ),
  );
邓晓峰's avatar
邓晓峰 committed
268

邓晓峰's avatar
邓晓峰 committed
269
  useEffect(() => {
邓晓峰's avatar
邓晓峰 committed
270
    Cookies.set('redirect_state', rstate, {
邓晓峰's avatar
邓晓峰 committed
271
      expires: 5 * 60 * 1000,
邓晓峰's avatar
邓晓峰 committed
272 273 274
      path: '/',
    });
  }, []);
邓晓峰's avatar
邓晓峰 committed
275

邓晓峰's avatar
邓晓峰 committed
276 277 278 279 280 281 282 283 284 285 286 287 288
  const props = Object.assign(
    {},
    {
      self_redirect: false,
      scope: 'snsapi_login',
      appid: APPID,
      state: rstate,
      redirect_uri: REDIRECT_URI,
      href: 'https://panda-water.cn/web4/styles/PandaIOTQrcodeStyle.css',
    },
  );
  return <WxLogin {...props} />;
};
邓晓峰's avatar
邓晓峰 committed
289 290

const Phone = props => {
邓晓峰's avatar
邓晓峰 committed
291
  const [form] = Form.useForm();
邓晓峰's avatar
邓晓峰 committed
292
  return (
邓晓峰's avatar
邓晓峰 committed
293
    <LoginForm form={form} onSubmit={props.onSubmit}>
邓晓峰's avatar
邓晓峰 committed
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
      {props.status === 'error' &&
        props.type === 'account' &&
        !props.submitting && <LoginMessage content="手机号码未注册" />}
      <Mobile name="mobile" placeholder="请输入手机号码" />
      <Captcha
        name="captcha"
        placeholder="请输入短信验证码"
        countDown={60}
        getCaptchaButtonText=""
        getCaptchaSecondText="秒"
        autoComplete="off"
        rules={[
          {
            required: true,
            message: '请输入短信验证码!',
          },
        ]}
      />
      <Submit loading={props.submitting} style={{ marginTop: '0px' }}>
        登录
      </Submit>
    </LoginForm>
  );
};
邓晓峰's avatar
邓晓峰 committed
318 319

const IotComponent = props => {
邓晓峰's avatar
邓晓峰 committed
320 321 322 323
  const handlerType = type => {
    props.setType(Display[type]);
    props.updateLoginMode(LoginWay[type]);
    Cookies.set('loginMode', LoginWay[type], {
邓晓峰's avatar
邓晓峰 committed
324
      expires: 5 * 60 * 1000,
邓晓峰's avatar
邓晓峰 committed
325 326 327
      path: '/',
    });
  };
邓晓峰's avatar
邓晓峰 committed
328 329
  return (
    <div className={styles.wechatQRcode}>
邓晓峰's avatar
邓晓峰 committed
330
      {props.type === Display.Account ? (
邓晓峰's avatar
邓晓峰 committed
331
        <Account {...props} />
邓晓峰's avatar
邓晓峰 committed
332
      ) : props.type === Display.WeChart ? (
邓晓峰's avatar
邓晓峰 committed
333
        <IOTQRCode {...props} />
邓晓峰's avatar
邓晓峰 committed
334
      ) : props.type === Display.Mobile ? (
邓晓峰's avatar
邓晓峰 committed
335 336 337 338
        <Phone {...props} />
      ) : (
        <Account {...props} />
      )}
邓晓峰's avatar
邓晓峰 committed
339
      <div className={styles.loginDisplay}>
邓晓峰's avatar
邓晓峰 committed
340 341 342
        <a
          onClick={() => handlerType('Account')}
          style={{
邓晓峰's avatar
邓晓峰 committed
343
            display: props.type === Display.Account ? 'none' : 'block',
邓晓峰's avatar
邓晓峰 committed
344 345
          }}
        >
邓晓峰's avatar
邓晓峰 committed
346
          {pages.get('login.accountLogin.tab')}
邓晓峰's avatar
邓晓峰 committed
347 348 349 350
        </a>
        <a
          onClick={() => handlerType('WeChart')}
          style={{
邓晓峰's avatar
邓晓峰 committed
351
            display: props.type === Display.WeChart ? 'none' : 'block',
邓晓峰's avatar
邓晓峰 committed
352 353
          }}
        >
邓晓峰's avatar
邓晓峰 committed
354
          {pages.get('login.weChart.tab')}
邓晓峰's avatar
邓晓峰 committed
355 356 357 358
        </a>
        <a
          onClick={() => handlerType('Mobile')}
          style={{
邓晓峰's avatar
邓晓峰 committed
359
            display: props.type === Display.Mobile ? 'none' : 'block',
邓晓峰's avatar
邓晓峰 committed
360 361
          }}
        >
邓晓峰's avatar
邓晓峰 committed
362
          {pages.get('login.phoneLogin.tab')}
邓晓峰's avatar
邓晓峰 committed
363
        </a>
邓晓峰's avatar
邓晓峰 committed
364 365
      </div>
    </div>
邓晓峰's avatar
邓晓峰 committed
366 367
  );
};
邓晓峰's avatar
邓晓峰 committed
368

邓晓峰's avatar
邓晓峰 committed
369
const Login = forwardRef((props, _ref) => {
dengxiaofeng's avatar
dengxiaofeng committed
370 371 372 373
  const videoRef = useRef();
  const loginRef = useRef();
  const timeRef = useRef();
  const titleRef = useRef();
邓晓峰's avatar
邓晓峰 committed
374
  const sliVerify = useRef();
dengxiaofeng's avatar
dengxiaofeng committed
375
  const loginFormRef = useRef();
邓晓峰's avatar
邓晓峰 committed
376
  const formRef = useRef(null);
dengxiaofeng's avatar
dengxiaofeng committed
377
  const footerRef = useRef();
邓晓峰's avatar
邓晓峰 committed
378
  const [status, setStatus] = useState('normal');
邓晓峰's avatar
邓晓峰 committed
379
  const [autoLogin, setAutoLogin] = useState(false);
邓晓峰's avatar
邓晓峰 committed
380
  const [submitting, setSubmitting] = useState(false);
dengxiaofeng's avatar
dengxiaofeng committed
381
  const [currentDate, setCurrentDate] = useState({});
邓晓峰's avatar
邓晓峰 committed
382
  const [type, setType] = useState('Account');
邓晓峰's avatar
邓晓峰 committed
383
  const [visible, setVisible] = useState(false);
邓晓峰's avatar
邓晓峰 committed
384 385 386
  const [action, setAction] = useState(
    () => new LoginAction(props, setVisible, true),
  );
邓晓峰's avatar
邓晓峰 committed
387

邓晓峰's avatar
邓晓峰 committed
388 389 390 391
  useEffect(() => {
    action.globalConfig = props.global;
  }, [props.global]);

dengxiaofeng's avatar
dengxiaofeng committed
392
  const handleSubmit = values => {
邓晓峰's avatar
邓晓峰 committed
393
    /* eslint-disable */
邓晓峰's avatar
邓晓峰 committed
394 395 396 397 398 399 400 401 402 403 404 405
    action &&
      (type === 'Account'
        ? action.loginHandler(
            values.userName,
            values.password,
            null,
            autoLogin,
            sliVerify,
          )
        : type === 'Mobile'
        ? action.phoneLoginFormHandler(values.mobile, values.captcha)
        : null);
邓晓峰's avatar
邓晓峰 committed
406

邓晓峰's avatar
邓晓峰 committed
407
    setSubmitting(true);
邓晓峰's avatar
邓晓峰 committed
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422
    action &&
      action.events.on('loginSuccess', event => {
        setSubmitting(false);
        props.history.push(`/?client=${props.global.client}`);
        window.share.event.emit('triggerMicro', props.global);
      });
    action &&
      action.events.on('loginError', event => {
        setVisible(false);
        setSubmitting(false);
      });
    action &&
      action.events.on('loginVisible', status => {
        setVisible(status);
      });
dengxiaofeng's avatar
dengxiaofeng committed
423 424
  };

邓晓峰's avatar
邓晓峰 committed
425
  useEffect(() => {
邓晓峰's avatar
邓晓峰 committed
426 427 428 429 430 431 432 433 434 435 436 437
    console.log('===LoginWay===', LoginWay.WeChart);
    if (props.loginMode === LoginWay.WeChart) {
      action &&
        action.events.on('loginSuccess', event => {
          props.history.push(`/?client=${props.global.client}`);
          window.share.event.emit('triggerMicro', props.global);
        });
      action &&
        action.events.on('loginError', event => {
          setVisible(false);
          setSubmitting(false);
        });
邓晓峰's avatar
邓晓峰 committed
438 439
    }
  }, [props.loginMode]);
邓晓峰's avatar
邓晓峰 committed
440

dengxiaofeng's avatar
dengxiaofeng committed
441
  let loginTimeInterval = null;
邓晓峰's avatar
邓晓峰 committed
442
  let videoTimeout = null;
dengxiaofeng's avatar
dengxiaofeng committed
443
  useEffect(() => {
邓晓峰's avatar
邓晓峰 committed
444 445
    if (loginTimeInterval)
      clearInterval(loginTimeInterval), (loginTimeInterval = null);
dengxiaofeng's avatar
dengxiaofeng committed
446 447
    loginTimeInterval = setInterval(() => {
      const date = new Date();
邓晓峰's avatar
邓晓峰 committed
448
      const weekday = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
邓晓峰's avatar
邓晓峰 committed
449 450 451 452 453 454 455
      const time = `${
        date.getHours() < 10 ? `0${date.getHours()}` : date.getHours()
      }:${
        date.getMinutes() < 10 ? `0${date.getMinutes()}` : date.getMinutes()
      }:${
        date.getSeconds() < 10 ? `0${date.getSeconds()}` : date.getSeconds()
      }`;
dengxiaofeng's avatar
dengxiaofeng committed
456
      setCurrentDate({
邓晓峰's avatar
邓晓峰 committed
457
        time,
dengxiaofeng's avatar
dengxiaofeng committed
458
        dayofweek: weekday[date.getDay()],
邓晓峰's avatar
邓晓峰 committed
459
        date: date.pattern('yyyy/MM/dd'),
邓晓峰's avatar
邓晓峰 committed
460
      });
dengxiaofeng's avatar
dengxiaofeng committed
461 462
    }, 1000);
    return () => {
邓晓峰's avatar
邓晓峰 committed
463 464
      loginTimeInterval && clearInterval(loginTimeInterval);
    };
dengxiaofeng's avatar
dengxiaofeng committed
465 466 467
  }, []);

  useEffect(() => {
468
    if (videoRef && videoRef.current) {
dengxiaofeng's avatar
dengxiaofeng committed
469 470 471
      videoRef.current.addEventListener('ended', function() {
        dom.removeClass(loginRef.current, styles.caseHide);
        dom.addClass(loginRef.current, styles.loginTimeShow);
邓晓峰's avatar
邓晓峰 committed
472
        videoTimeout = setTimeout(() => {
dengxiaofeng's avatar
dengxiaofeng committed
473
          dom.removeClass(timeRef.current, styles.caseHide);
邓晓峰's avatar
邓晓峰 committed
474 475
          dom.addClass(timeRef.current, 'animate__fadeIn');

dengxiaofeng's avatar
dengxiaofeng committed
476
          dom.removeClass(loginFormRef.current, styles.caseHide);
邓晓峰's avatar
邓晓峰 committed
477 478
          dom.addClass(loginFormRef.current, 'animate__fadeInUp');

dengxiaofeng's avatar
dengxiaofeng committed
479
          dom.removeClass(footerRef.current, styles.caseHide);
邓晓峰's avatar
邓晓峰 committed
480
          dom.addClass(footerRef.current, 'animate__slideInUp');
dengxiaofeng's avatar
dengxiaofeng committed
481
          dom.removeClass(titleRef.current, styles.caseHide);
邓晓峰's avatar
邓晓峰 committed
482
          dom.addClass(titleRef.current, 'animte__fadeInUp');
dengxiaofeng's avatar
dengxiaofeng committed
483
        }, 500);
邓晓峰's avatar
邓晓峰 committed
484
      });
dengxiaofeng's avatar
dengxiaofeng committed
485
    }
邓晓峰's avatar
邓晓峰 committed
486 487

    return () => {
邓晓峰's avatar
邓晓峰 committed
488
      videoTimeout && clearTimeout(videoTimeout);
邓晓峰's avatar
邓晓峰 committed
489
      videoRef.current.removeEventListener('ended', () => {});
邓晓峰's avatar
邓晓峰 committed
490
    };
dengxiaofeng's avatar
dengxiaofeng committed
491
  }, [videoRef]);
邓晓峰's avatar
邓晓峰 committed
492 493
  useEffect(() => {
    setSubmitting(false);
邓晓峰's avatar
邓晓峰 committed
494 495
  }, [visible]);
  const renderAddons = useRenderQcode(props.global);
邓晓峰's avatar
邓晓峰 committed
496 497 498
  const renderPlatform = () => {
    const template = props.global.loginTemplate;
    const params = {
邓晓峰's avatar
邓晓峰 committed
499
      fromRef: formRef,
邓晓峰's avatar
邓晓峰 committed
500 501 502 503 504 505 506
      type,
      setType,
      status,
      submitting,
      autoLogin,
      setAutoLogin,
      action,
邓晓峰's avatar
邓晓峰 committed
507 508 509 510 511 512 513 514 515 516
      onSubmit: handleSubmit,
      loginMode: props.loginMode,
      updateLoginMode: props.updateLoginMode,
    };
    switch (template) {
      case 'DarkCloud.html':
      case 'Dark.html':
        return <Account {...params} />;
      case 'Dark - IOTMultiLogin.html':
        return <IotComponent {...params} />;
邓晓峰's avatar
邓晓峰 committed
517
      default:
邓晓峰's avatar
邓晓峰 committed
518 519
        return <Account {...params} />;
        break;
邓晓峰's avatar
邓晓峰 committed
520
    }
邓晓峰's avatar
邓晓峰 committed
521
  };
邓晓峰's avatar
邓晓峰 committed
522
  /* eslint-disable */
523

dengxiaofeng's avatar
dengxiaofeng committed
524
  return (
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567
    <HelmetProvider>
      <Helmet>
        <title>{props.global.title || defaultSetting.title}</title>
        <meta name="description" content={props.global.title || defaultSetting.title} />
      </Helmet>
      <div className={styles.main}>
        <video
          src={require("../../../assets/videos/beforPage.mp4") }
          className={styles.videLayer}
          autoPlay="autoPlay"
          muted
          playsInline="playsinline"
          ref={videoRef}
        />
        <div className={styles.inner}>
          <div
            className={classNames(styles.loginTime, styles.caseHide)}
            ref={loginRef}
          >
            <img
              role="logo"
              src={`https://panda-water.cn/web4/${props.global.logo}`}
            />
            <div
              className={classNames(
                styles.titleCase,
                styles.caseHide,
                'animated',
              )}
              ref={titleRef}
            >
              <span className={styles.title}>{props.global.title}</span>
              <span className={styles.subtitle}>
              {window.globalConfig.subtitle}
            </span>
            </div>
          </div>
          <span
            className={classNames(
              styles.divider,
              styles.caseHide,
              'animate__animated',
            )}
邓晓峰's avatar
邓晓峰 committed
568 569 570
          />
          <div
            className={classNames(
571
              styles.timeCase,
邓晓峰's avatar
邓晓峰 committed
572
              styles.caseHide,
573
              'animate__animated',
邓晓峰's avatar
邓晓峰 committed
574
            )}
575
            ref={timeRef}
邓晓峰's avatar
邓晓峰 committed
576
          >
577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592
            <span className={styles.time}>{currentDate.time}</span>
            <span className={styles.dayofweek}>{currentDate.dayofweek}</span>
            <span className={styles.date}>{currentDate.date}</span>
          </div>
          <div
            className={classNames(
              styles['login-block'],
              styles.caseHide,
              'animate__animated',
            )}
            ref={loginFormRef}
          >
            <div>
              <img src="https://panda-water.cn/web4/assets/images/login/dark/login.png" />
            </div>
            <div className={styles['login-form']}>{renderPlatform()}</div>
dengxiaofeng's avatar
dengxiaofeng committed
593 594
          </div>
        </div>
邓晓峰's avatar
邓晓峰 committed
595 596
        <div
          className={classNames(
597
            styles.footerCase,
邓晓峰's avatar
邓晓峰 committed
598 599 600
            styles.caseHide,
            'animate__animated',
          )}
601
          ref={footerRef}
邓晓峰's avatar
邓晓峰 committed
602
        >
603 604
          <div className={classNames(styles.quickMark)}>{renderAddons}</div>
          <span className={classNames(styles.copyright)}>
dengxiaofeng's avatar
dengxiaofeng committed
605
          Copyright ©
邓晓峰's avatar
邓晓峰 committed
606 607 608
          <a target="_blank" href="https://panda-water.cn">
            熊猫智慧水务
          </a>
609 610
            {new Date().getFullYear()} All Rights Reserved{' '}
            <a target="_blank" id="IndexCaseNumber" href="">
邓晓峰's avatar
邓晓峰 committed
611 612
            ICP11036640-1
          </a>
邓晓峰's avatar
邓晓峰 committed
613
          <span className="addons">
邓晓峰's avatar
邓晓峰 committed
614 615 616 617 618 619 620 621
            <span className="split" />
            <a id="qrcode">
              <span
                className="glyphicon glyphicon-qrcode"
                role="button"
                title="手持APP下载"
              />
            </a>
邓晓峰's avatar
邓晓峰 committed
622
          </span>
dengxiaofeng's avatar
dengxiaofeng committed
623
        </span>
624 625 626 627 628 629 630 631 632 633 634
        </div>
        <Modal
          centered
          visible={visible}
          width={340}
          footer={null}
          closable={false}
          bodyStyle={{ padding: '15px' }}
        >
          <div ref={sliVerify} />
        </Modal>
dengxiaofeng's avatar
dengxiaofeng committed
635
      </div>
636
    </HelmetProvider>
dengxiaofeng's avatar
dengxiaofeng committed
637
  );
邓晓峰's avatar
邓晓峰 committed
638
});
邓晓峰's avatar
邓晓峰 committed
639

邓晓峰's avatar
邓晓峰 committed
640 641 642 643
const mapStateToProps = state => ({
  global: state.getIn(['global', 'globalConfig']),
  loginMode: state.getIn(['global', 'loginMode']),
});
dengxiaofeng's avatar
dengxiaofeng committed
644

邓晓峰's avatar
邓晓峰 committed
645 646 647 648 649 650 651 652 653 654 655
const mapDispatchToProps = dispatch => ({
  updateConfig(config) {
    dispatch(actionCreators.getConfig(config));
  },
  createContext(data) {
    dispatch(actionCreators.createContext(data));
  },
  updateLoginMode(mode) {
    dispatch(actionCreators.changeLoginMode(mode));
  },
});
邓晓峰's avatar
邓晓峰 committed
656 657 658 659
export default connect(
  mapStateToProps,
  mapDispatchToProps,
)(withRouter(Login));