noSecret.js 1.92 KB
Newer Older
邓晓峰's avatar
邓晓峰 committed
1
import '@wisdom-utils/utils/lib/helpers/format';
邓晓峰's avatar
邓晓峰 committed
2

邓晓峰's avatar
邓晓峰 committed
3
import React, { forwardRef, useEffect, useState } from 'react';
邓晓峰's avatar
邓晓峰 committed
4
import { connect } from 'react-redux';
邓晓峰's avatar
邓晓峰 committed
5
import { useHistory } from '@wisdom-utils/runtime';
邓晓峰's avatar
邓晓峰 committed
6 7
import { actionCreators } from '@/containers/App/store';
import LoginAction from './login';
张瑶's avatar
张瑶 committed
8
import { initMicroApps } from '../../../micro';
邓晓峰's avatar
邓晓峰 committed
9 10 11
const Login = forwardRef((props, _ref) => {
  const history = useHistory();
  const [action, setAction] = useState(
邓晓峰's avatar
邓晓峰 committed
12 13
    () =>
      new LoginAction(Object.assign({}, props, { history }), () => {}, true),
邓晓峰's avatar
邓晓峰 committed
14 15 16 17
  );

  useEffect(() => {
    action.globalConfig = props.global;
邓晓峰's avatar
邓晓峰 committed
18 19
  }, [action.globalConfig, props.global]);

邓晓峰's avatar
邓晓峰 committed
20 21
  useEffect(() => {
    action &&
邓晓峰's avatar
邓晓峰 committed
22 23 24 25 26
      action.events.on('loginSuccess', event => {
        // http://127.0.0.1:8080/civbase/civweb4/
        //   props.updateConfig(Object.assign({}, props.global, {
        //       homepage:  params.getParams('redirect')
        //   }));
邓晓峰's avatar
邓晓峰 committed
27
        // props.history.push('/' + params.getParams('redirect'))
邓晓峰's avatar
邓晓峰 committed
28 29 30 31 32 33 34 35 36 37
        props.history.push(
          `/?client=${props.global.client}&generateType=${
            props.global.generateType
          }`,
        );
        // window.share.event.emit('triggerMicro', props.global);
        initMicroApps();
      });
  }, [action, props.global.client, props.global.generateType, props.history]);

邓晓峰's avatar
邓晓峰 committed
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
  return <div>{props.children}</div>;
});

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,
)(Login);