/*
 * @Author: your name
 * @Date: 2022-03-03 18:04:40
 * @LastEditTime: 2022-04-01 14:29:24
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: /KC-MiddlePlatform/src/pages/platform/setting/reports/index.tsx
 */

import { useEffect, useState } from 'react';
import { useModel } from 'umi';
import { Skeleton } from 'antd';

export default () => {
  const { initialState, setInitialState } = useModel('@@initialState');
  const [specialPageUrl, setspecialPageUrl] = useState<string | undefined>(undefined);
  const [loading, setloading] = useState(false);

  const onLoadhandle = () => {
    setloading(false);
  };

  useEffect(() => {
    setloading(true);
    if (initialState && initialState.spacicalPageParamsType && initialState.currentUser) {
      const {
        spacicalPageParamsType,
        currentUser: { youshuToken },
      } = initialState;
      const { pathname } = location;
      const spacialPage = spacicalPageParamsType.filter((t) => `/app1${t.path}` == pathname);

      if (spacialPage.length > 0) {
        //当前页面属于有数数据展示页面
        console.log(`${spacialPage[0].url}&token=${youshuToken}`);

        const url = `${spacialPage[0].url}&token=${youshuToken}`;
        setspecialPageUrl(url);
      }
    }
  }, [initialState]);

  return (
    <>
      <Skeleton loading={loading} paragraph={{ rows: 50 }} active />
      <iframe
        onLoad={() => onLoadhandle()}
        style={{ width: '100%', height:'calc(100vh - 96px)', border: 'none' }}
        src={specialPageUrl}
      ></iframe>
    </>
  );
};
