index.js 10.4 KB
Newer Older
1 2 3 4 5 6 7 8 9
/* eslint-disable global-require */
// 集成登录引导页
import React, { useCallback, useEffect, useMemo, useState, useRef } from 'react';
import { notification } from 'antd';
import classNames from 'classnames';
import { connect } from 'react-redux';
import { useDocumentTitle } from '@ant-design/pro-utils';
import defaultSetting from '@wisdom-utils/components/lib/AppLayout/layouts/defaultSettings';
import { actionCreators } from '@/containers/App/store';
10
import { store } from '@wisdom-utils/utils';
11
import LoginAction from '@/pages/user/login/login';
徐乐's avatar
徐乐 committed
12
import Cookies from 'js-cookie';
13 14 15
import { defaultApp } from '@/micro';
import { appService } from '@/api';
import { SERVICE_INTERFACE_SUCCESS_CODE } from '@/constants';
16
import axios from 'axios';
17 18
import imgLogo from '@/assets/bootPage/熊猫图标.png';
import styles from './index.less';
19 20
const Integration = props => {
  const dataRef = useRef();
周宏民's avatar
周宏民 committed
21 22 23 24
  const integratedConfig = props.integratedConfig?.toObject
    ? props.integratedConfig.toObject()
    : props.integratedConfig || {};
  const integrationClient = integratedConfig?.client || window?.globalConfig?.client || 'city'; // 集成登录client
25

26 27 28 29 30 31 32 33
  const [percentBottom, setPercentBottom] = useState(-40);
  const [currentType, setCurrentType] = useState('');
  const [scale, setScale] = useState(1);
  const [loginAction, setAction] = useState(() => new LoginAction(props));
  const [num, setNum] = useState(0);
  const [dataList, setDataList] = useState([]);
  const [client, setClient] = useState('');

34 35
  // 子站跳转
  const handlePage = useCallback((item, loginAction) => {
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
    let count = 1;
    setPercentBottom(-40 + Math.ceil(Math.random() * 8 * count));

    process.current = setInterval(() => {
      setTimeout(() => {
        const perBottom = -40 + 8 * count + Math.ceil(Math.random() * 8);
        const perNum = 10 * count + Math.ceil(Math.random() * 10);
        if (perNum >= 80 || dataRef.current >= 80 || count === 10) {
          return clearInterval(process.current);
        }
        setPercentBottom(perBottom);
        count += 1;
      }, 0);
    }, 3000);

李纪文's avatar
李纪文 committed
51 52
    if (item.subType === '外链') {
      if (item.paramValue === 'ticket') {
53
        // 获取临时token
徐乐's avatar
徐乐 committed
54 55
        appService.getTicketByToken({ token: window.globalConfig?.token }).then(res => {
          if (res.code === 0) {
56
            const url = `${item.url + (item.url.indexOf('?') > 0 ? '&' : '?') + item.paramName}=${res.data}`;
李纪文's avatar
李纪文 committed
57 58 59 60 61
            if (item?.openOpt === '当前页打开') {
              props.history.push('/thirdParty', { linkUrl: url });
            } else {
              window.open(url, '_blank');
            }
徐乐's avatar
徐乐 committed
62 63 64 65 66 67 68 69 70
          } else {
            notification.error({
              message: '提示',
              duration: 3,
              description: res.msg,
            });
          }
        });
      } else {
71 72 73
        const url = `${item.url + (item.url.indexOf('?') > 0 ? '&' : '?') + item.paramName}=${
          window.globalConfig?.token
        }`;
李纪文's avatar
李纪文 committed
74 75 76 77 78
        if (item?.openOpt === '当前页打开') {
          props.history.push('/thirdParty', { linkUrl: url });
        } else {
          window.open(url, '_blank');
        }
徐乐's avatar
徐乐 committed
79
      }
李纪文's avatar
李纪文 committed
80
    } else if (item.subType === '内链') {
81 82 83 84
      if (window.qiankunIsCache) {
        store.set('event:dropCache');
      }

85
      const cli = item.url?.indexOf('client=') >= 0 ? item.url.split('client=')[1] : '';
徐乐's avatar
徐乐 committed
86 87 88 89 90 91

      Cookies.set('client', cli, {
        expires: 86400000 / (24 * 60 * 60 * 1000),
        path: '/',
      });
      sessionStorage.setItem('client', cli);
92 93
      const currentProduct = `__global__recent_productIndex__micro_${window.location.hostname}_${window.globalConfig
        ?.client ?? 'city'}`;
徐乐's avatar
徐乐 committed
94 95 96 97
      sessionStorage.removeItem(currentProduct);
      const currentProductNew = `__global__recent_productIndex__micro_${window.location.hostname}_${cli || 'city'}`;
      sessionStorage.setItem(currentProductNew, 0);

98 99 100 101 102 103 104
      setClient(cli);
      setCurrentType(item.name);

      const config = props.global;
      config.uiwidgets = [];
      config.widgets = [];
      config.allWidgets = [];
杨思琦's avatar
杨思琦 committed
105
      window.qiankunStarted = false;
106
      if (cli) {
杨思琦's avatar
杨思琦 committed
107
        config.client = cli;
108 109
      }

110 111
      // props.instance && props.instance.updateConfig(config);
      loginAction && loginAction.getUserInfoAndConfig('', true, item.type);
112
    } else {
113
      let { url } = item;
114 115 116 117
      if (url?.indexOf('{userId}') >= 0) {
        url = url.replace('{userId}', window.globalConfig?.userInfo?.OID);
      }
      axios({
118
        url,
119
        method: 'get',
120
        dataType: 'json',
121 122
      }).then(res => {
        if (res?.data?.code === 0) {
123
          // window.location.href = res.data?.data;
李纪文's avatar
李纪文 committed
124 125 126 127 128
          if (item?.openOpt === '当前页打开') {
            props.history.push('/thirdParty', { linkUrl: res.data?.data });
          } else {
            window.open(res.data?.data, '_blank');
          }
129 130
        }
      });
131
    }
132
  });
133 134 135 136 137

  useEffect(() => {
    const handleToggleIndustry = event => {
      setPercentBottom(38);
      clearInterval(process.current);
138
      props.history.push(`/?client=${integrationClient}`);
139 140 141 142 143 144 145 146 147 148 149 150

      props.updateCurrentIndex(0);

      defaultApp();
    };
    loginAction.events.on('toggleIndustry', handleToggleIndustry);

    return () => {
      loginAction.events.removeListener('toggleIndustry', handleToggleIndustry);
    };
  }, [loginAction.events, props, currentType]);

151
  // 获取集成站点数据
152
  useEffect(() => {
周宏民's avatar
周宏民 committed
153 154
    const cli = integratedConfig?.client || sessionStorage.getItem('client') || props?.global?.client || '';
    localStorage.setItem('integrationClient', cli);
155 156 157 158 159
    appService
      .GetIntegrationConfig({
        type: '集成登录',
        userId: window.globalConfig.userInfo?.OID ?? null,
        isEnable: true,
周宏民's avatar
周宏民 committed
160
        client: cli,
161 162
      })
      .then(res => {
周宏民's avatar
周宏民 committed
163
        const { code, data = [] } = res;
164 165 166 167
        if (code !== SERVICE_INTERFACE_SUCCESS_CODE) {
          notification.error({ message: '提示', duration: 3, description: '集成站点配置错误' });
        } else {
          setNum(data.length);
周宏民's avatar
周宏民 committed
168
          setDataList(data.sort((a, b) => a.index - b.index));
169 170 171
          const config = props.global;
          config.isIntegration = data.length;
          props.updateConfig && props.updateConfig(config);
周宏民's avatar
周宏民 committed
172
          if (data.length === 1) {
173
            handlePage(data[0], loginAction);
174 175 176 177 178 179
          }
        }
      })
      .catch(err => {
        notification.error({ message: '提示', duration: 3, description: '集成站点配置错误' });
      });
180
  }, []);
181 182 183 184 185

  return (
    <div className={styles.bootPage}>
      <div className={styles.bootPageMain}>
        <header className={styles.bootPageHead}>
186 187 188 189 190
          {props.global.logo && props.global.transformDevAssetsBaseURL ? (
            <img role="logo" src={props.global.transformDevAssetsBaseURL(props.global.logo)} alt="" />
          ) : (
            <img src={window.globalConfig.logo ? require(window.globalConfig.logo) : imgLogo} alt="" />
          )}
191
          <div className={styles.bootPageTitle}>
192
            <span className={styles.bootPageZh}>{window.globalConfig?.title ?? '熊猫智慧水务一体化解决方案'}</span>
193 194 195 196 197
            <span className={styles.bootPageEn}>
              {window.globalConfig.title
                ? window.globalConfig.subtitle
                : 'Panda Smart Water Integration Platform & Solution'}
            </span>
198 199
          </div>
        </header>
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
        <section
          className={classNames(styles.bootPageSection, 'animate__fadeInDown', 'animate__animated', 'duration-500ms')}
        >
          <ul
            className={classNames(styles.bootPageUl, 'animate__animated')}
            style={{
              transform: `scale(${scale})`,
              left: '300px',
              bottom: '105px',
              opacity: 1,
              width: num === 5 ? 960 : num === 9 || num === 10 ? 1600 : 1280,
            }}
          >
            {dataList.length > 1
              ? dataList.map(item => (
                  <li className={styles.bootPageLi} key={item.name} onClick={event => handlePage(item, loginAction)}>
                    <div className={styles.bootPageList}>
                      <div className={styles.listMain}>
                        {/* <img src={require(`@/assets/bootPage/供水.png`)} alt="" /> */}
                        <img
                          src={`${window.location.origin}/${item.icon ? item.icon : 'center/images/科技风/二供.png'}`}
                          alt=""
                        />
                        <span className={styles.bootPageName}>{item.name}</span>
                      </div>
225
                    </div>
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
                    {currentType === item.name && (
                      <div className={styles.bootProgress}>
                        <div className={styles.inner} style={{ bottom: percentBottom }}>
                          <svg
                            className={styles.wave}
                            xmlns="http://www.w3.org/2000/svg"
                            xmlnsXlink="http://www.w3.org/1999/xlink"
                            viewBox="0 24 150 68"
                            preserveAspectRatio="none"
                          >
                            <defs>
                              <path
                                id="gentle-wave"
                                d="M-160 44c30 0 58-18 88-18s 58 18 88 18 58-18 88-18 58 18 88 18 v44h-352z"
                              />
                            </defs>
                            <g className={styles.parallax}>
                              <use xlinkHref="#gentle-wave" x="50" y="0" fill="rgb(16,104,239)" opacity="0.1" />
                              <use xlinkHref="#gentle-wave" x="50" y="-1" fill="rgb(16,104,239)" opacity="0.2" />
                            </g>
                          </svg>
                        </div>
                      </div>
                    )}
                  </li>
                ))
              : ''}
253 254 255 256 257 258 259 260 261
          </ul>
        </section>
      </div>
    </div>
  );
};
const mapStateToProps = state => ({
  global: state.getIn(['global', 'globalConfig']),
  instance: state.getIn(['global', 'instance']),
周宏民's avatar
周宏民 committed
262
  integratedConfig: state.getIn(['global', 'integratedConfig']),
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
});
const mapDispatchToProps = dispatch => ({
  updateConfig(config) {
    dispatch(actionCreators.getConfig(config));
  },
  createContext(data) {
    dispatch(actionCreators.createContext(data));
  },
  updateCurrentIndex(index) {
    dispatch(actionCreators.updateCurrentIndex(index));
  },
});
export default connect(
  mapStateToProps,
  mapDispatchToProps,
)(Integration);