index.js 10.7 KB
Newer Older
杨思琦's avatar
杨思琦 committed
1
/* eslint-disable global-require */
崔佳豪's avatar
崔佳豪 committed
2
// 云平台引导页
杨思琦's avatar
杨思琦 committed
3
import React, { useCallback, useEffect, useMemo, useState, useRef } from 'react';
崔佳豪's avatar
崔佳豪 committed
4

5
import { Space, Spin, Progress } from 'antd';
崔佳豪's avatar
崔佳豪 committed
6 7 8 9 10 11 12 13 14 15 16
import classNames from 'classnames';
import { connect } from 'react-redux';
import { useIntl } from '@wisdom-utils/components';
import { useDocumentTitle } from '@ant-design/pro-utils';
import { useHistory } from '@wisdom-utils/runtime';
import defaultSetting from '@wisdom-utils/components/lib/AppLayout/layouts/defaultSettings';
import { actionCreators } from '@/containers/App/store';
import LoginAction from '@/pages/user/login/login';
import { defaultApp } from '@/micro';
import usingIcon from '@/assets/bootPage/using-icon.png';
import { appService } from '@/api';
yzl's avatar
yzl committed
17
import styles from './index.less';
崔佳豪's avatar
崔佳豪 committed
18 19

const industries = [
yzl's avatar
yzl committed
20 21 22 23
  { name: '供水', type: '供水', subTitle: 'WATER SUPPLY', color: 'rgb(16,104,239)' },
  { name: '农饮水', type: '农饮水', subTitle: 'RURAL POTABLE WATER', color: 'rgb(4,142,101)' },
  { name: '排水', type: '排水', subTitle: 'DRAINAGE', color: 'rgb(234,117,28)' },
  { name: '水利', type: '水利', subTitle: 'WATER CONSERVANCY', color: 'rgb(0,144,158)' },
yzl's avatar
yzl committed
24
  { name: '能源', type: '能源', subTitle: 'ENERGY SOURCES', color: 'rgb(49,139,27)' },
yzl's avatar
yzl committed
25
  { name: '高品质水', type: '高品质水', subTitle: 'HIGH QUALITY WATER', color: 'rgb(106,208,218)' },
崔佳豪's avatar
崔佳豪 committed
26
  // { name: '水资源', type: '水资源', subTitle: 'WATER RESOURCES' },
yzl's avatar
yzl committed
27
  { name: '熊猫智能实验室', type: '实验室', subTitle: 'PANDA AI. LAB', color: 'rgb(104,163,242)' },
yzl's avatar
yzl committed
28 29 30
  { name: '水务大数据', type: '大数据', subTitle: 'WATER BIG DATA', color: 'rgb(85,77,210)' },
  { name: '熊猫新产品', type: '熊猫新产品', subTitle: "PANDA'S NEW PRODUCT", color: 'rgb(12,103,205)' },
  { name: '项目案例', type: '项目案例', subTitle: 'PROJECT CASE', color: 'rgb(107,36,155)' },
崔佳豪's avatar
崔佳豪 committed
31 32 33 34
];

// let loginAction = null;
const BootPage = props => {
杨思琦's avatar
杨思琦 committed
35 36
  const dataRef = useRef();
  const process = useRef();
yzl's avatar
yzl committed
37
  const [Industries] = useState(props.global.userInfo.Industries);
杨思琦's avatar
杨思琦 committed
38
  const [percentBottom, setPercentBottom] = useState(-40);
yzl's avatar
yzl committed
39
  const [percentNum, setPercentNum] = useState(0);
40 41
  const [currentType, setCurrentType] = useState('');
  // const [loadding, setLoadding] = useState(false);
崔佳豪's avatar
崔佳豪 committed
42 43 44
  const [hasRole, setHasRole] = useState(false);
  const [scale, setScale] = useState(1);
  const [loginAction, setAction] = useState(() => new LoginAction(props));
yzl's avatar
yzl committed
45
  const [num] = useState(Industries.filter(item => !!industries.find(d => d.type === item)).length);
崔佳豪's avatar
崔佳豪 committed
46 47 48 49 50
  // const history = useHistory();
  useDocumentTitle(
    { title: defaultSetting.title, id: '', pageName: '行业切换' },
    props.global.title || defaultSetting.title,
  );
杨思琦's avatar
杨思琦 committed
51 52 53
  useEffect(() => {
    dataRef.current = percentNum;
  }, [percentNum]);
杨思琦's avatar
杨思琦 committed
54
  // eslint-disable-next-line no-shadow
yzl's avatar
yzl committed
55
  const handlePage = (event, type, loginAction) => {
杨思琦's avatar
杨思琦 committed
56 57 58
    let count = 1;
    setPercentBottom(-40 + Math.ceil(Math.random() * 8 * count));
    setPercentNum(Math.ceil(Math.random() * 10));
yzl's avatar
yzl committed
59 60 61 62
    setCurrentType(type);
    //
    // event.persist();
    // event.preventDefault();
杨思琦's avatar
杨思琦 committed
63 64 65 66 67 68 69 70 71 72 73 74
    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);
        setPercentNum(perNum);
        count += 1;
      }, 0);
    }, 3000);
yzl's avatar
yzl committed
75 76 77
    // 新增熊猫新产品引导页
    if (type === '熊猫新产品') {
      setTimeout(() => {
杨思琦's avatar
杨思琦 committed
78
        setPercentBottom(40);
yzl's avatar
yzl committed
79
        setPercentNum(100);
杨思琦's avatar
杨思琦 committed
80
        clearInterval(process.current);
yzl's avatar
yzl committed
81
        setTimeout(() => {
82 83
          props.history.push('/cloud/introduction/newproducts');
          // window.history.pushState('', null, `/cloud/introduction/newproducts`);
yzl's avatar
yzl committed
84 85
        }, 500);
      });
86

yzl's avatar
yzl committed
87 88 89 90 91 92 93 94 95 96 97 98
      return;
    }

    // setLoadding(true);
    const config = props.global;
    // const loginAction = new LoginAction(props);
    config.uiwidgets = [];
    config.widgets = [];
    config.allWidgets = [];
    props.instance && props.instance.updateConfig(config);
    // props.instance && props.instance.getUserInfoAndConfig('', true, type);
    loginAction && loginAction.getUserInfoAndConfig('', true, type);
杨思琦's avatar
杨思琦 committed
99
  };
100

崔佳豪's avatar
崔佳豪 committed
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
  useEffect(() => {
    // eslint-disable-next-line no-use-before-define
    handleResize();
  }, []);
  const handleResize = () => {
    const width = document.documentElement.clientWidth;
    const height = document.documentElement.clientHeight;
    // eslint-disable-next-line no-shadow
    const scale = width / 1920;
    setScale(scale);
  };
  useEffect(() => {
    window.addEventListener('resize', handleResize);

    const handleToggleIndustry = event => {
杨思琦's avatar
杨思琦 committed
116
      setPercentBottom(38);
yzl's avatar
yzl committed
117
      setPercentNum(98);
杨思琦's avatar
杨思琦 committed
118
      clearInterval(process.current);
yzl's avatar
yzl committed
119
      setTimeout(() => {
yzl's avatar
yzl committed
120 121
        props.history.push(`/?client=${props.global.client}`);
      }, 1000);
122

崔佳豪's avatar
崔佳豪 committed
123 124
      // window.share.event.emit('triggerMicro', props.global);
      props.updateCurrentIndex(0);
125

yzl's avatar
yzl committed
126
      defaultApp();
崔佳豪's avatar
崔佳豪 committed
127 128
    };
    loginAction.events.on('toggleIndustry', handleToggleIndustry);
yzl's avatar
yzl committed
129

崔佳豪's avatar
崔佳豪 committed
130 131 132 133
    return () => {
      window.removeEventListener('resize', handleResize);
      loginAction.events.removeListener('toggleIndustry', handleToggleIndustry);
    };
yzl's avatar
yzl committed
134 135 136
  }, [loginAction.events, props, currentType]);

  useEffect(() => {
yzl's avatar
yzl committed
137
    window.share.event.on('visible', ret => {
yzl's avatar
yzl committed
138
      setTimeout(() => {
杨思琦's avatar
杨思琦 committed
139
        setPercentBottom(40);
yzl's avatar
yzl committed
140
        setPercentNum(100);
杨思琦's avatar
杨思琦 committed
141
        clearInterval(process.current);
yzl's avatar
yzl committed
142 143 144
        setTimeout(() => {
          window.history.pushState(null, '', ret);
        }, 500);
yzl's avatar
yzl committed
145 146 147
      }, 500);
    });
  }, []);
崔佳豪's avatar
崔佳豪 committed
148 149 150 151 152 153 154

  const intl = useIntl();
  const toOMSUsingAnalysis = e => {
    e && e.stopPropagation();
    props.history.push(`/cloud/analysis/using`);
  };

yzl's avatar
yzl committed
155 156 157 158
  // const test = `bootPageUl_${props.global && props.global.userInfo && props.global.userInfo.Industries
  //   ? props.global.userInfo.Industries.filter(item => !!industries.find(d => d.type === item)).length
  //   : 0`

崔佳豪's avatar
崔佳豪 committed
159 160 161 162 163 164 165 166 167
  useEffect(() => {
    appService
      .getUserInfo({
        token: props.global.token,
        subOID: 'subOID',
        site: 'cloud',
        ignoreSite: true,
      })
      .then(res => {
168
        const roles = res?.data?.roles ?? [];
杨思琦's avatar
杨思琦 committed
169 170
        // eslint-disable-next-line no-underscore-dangle
        const _hasRole = roles && Array.isArray(roles) && roles.filter(r => r.name === '客户运维管理员').length;
崔佳豪's avatar
崔佳豪 committed
171 172 173 174 175 176 177 178 179 180 181
        setHasRole(!!_hasRole);
      });
  }, [props.global.token]);

  return (
    <div className={styles.bootPage}>
      <div className={styles.bootPageMain}>
        <header className={styles.bootPageHead}>
          {/* eslint-disable-next-line jsx-a11y/alt-text */}
          <img src="https://panda-water.cn/web4/assets/images/bootPage/熊猫图标.png" />
          <div className={styles.bootPageTitle}>
yzl's avatar
yzl committed
182
            <span className={styles.bootPageZh}>熊猫智慧水务一体化解决方案</span>
崔佳豪's avatar
崔佳豪 committed
183 184 185 186 187 188 189 190 191 192
            <span className={styles.bootPageEn}>Panda Smart Water Integration Platform & Solution</span>
          </div>
        </header>
        <section
          className={classNames(styles.bootPageSection, 'animate__fadeInDown', 'animate__animated', 'duration-500ms')}
          // style={{
          //   width: `${scale < 1 ? 1280 : Math.ceil(1280 * scale)}px`,
          // }}
        >
          <ul
yzl's avatar
yzl committed
193
            className={classNames(styles.bootPageUl, 'animate__animated')}
崔佳豪's avatar
崔佳豪 committed
194 195 196 197 198
            style={{
              transform: `scale(${scale})`,
              left: '300px',
              bottom: '105px',
              opacity: 1,
杨思琦's avatar
杨思琦 committed
199
              width: num === 5 ? 960 : num === 9 || num === 10 ? 1600 : 1280,
崔佳豪's avatar
崔佳豪 committed
200 201
            }}
          >
yzl's avatar
yzl committed
202 203
            {industries.map(
              item =>
杨思琦's avatar
杨思琦 committed
204 205 206
                props.global &&
                Industries.indexOf(item.type) > -1 && (
                  <li
yzl's avatar
yzl committed
207 208
                    className={styles.bootPageLi}
                    key={item.type}
杨思琦's avatar
杨思琦 committed
209 210
                    onClick={event => handlePage(event, item.type, loginAction)}
                  >
yzl's avatar
yzl committed
211 212 213 214 215 216 217 218
                    <div className={styles.bootPageList}>
                      <div className={styles.listMain}>
                        <img src={require(`@/assets/bootPage/${item.type}.png`)} alt="" />
                        <span className={styles.bootPageName}>{item.name}</span>
                        <span className={styles.bootPageNameEng}>{item.subTitle}</span>
                      </div>
                    </div>
                    {currentType === item.type && (
杨思琦's avatar
杨思琦 committed
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
                      <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={item.color} opacity="0.1" />
                              <use xlinkHref="#gentle-wave" x="50" y="-1" fill={item.color} opacity="0.2" />
                            </g>
                          </svg>
                        </div>
                      </div>
yzl's avatar
yzl committed
241 242
                    )}
                  </li>
杨思琦's avatar
杨思琦 committed
243
                ),
yzl's avatar
yzl committed
244
            )}
崔佳豪's avatar
崔佳豪 committed
245 246
          </ul>
        </section>
yzl's avatar
yzl committed
247 248 249
        {/* <Space className={styles.abs}> */}
        {/*  <Spin spinning={loadding} size="large" /> */}
        {/* </Space> */}
崔佳豪's avatar
崔佳豪 committed
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
      </div>
      {hasRole ? (
        <div className={styles.cloudMonitorBtns}>
          <div className="cloud-using-anaylysis-btn" onClick={toOMSUsingAnalysis}>
            <img src={usingIcon} alt="" title="点击查看平台使用监控" />
            <span>平台使用分析</span>
          </div>
        </div>
      ) : null}
    </div>
  );
};
const mapStateToProps = state => ({
  global: state.getIn(['global', 'globalConfig']),
  instance: state.getIn(['global', 'instance']),
});
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,
)(BootPage);