IframeFor2.0.js 3.1 KB
Newer Older
1
import React, { Component } from 'react';
钟是志's avatar
钟是志 committed
2 3
import PageHeaderWrapper from '@/components/PageHeaderWrapper';
import Shell from '@/baseComponent/Shell';
钟是志's avatar
钟是志 committed
4
import { getToken, setToken } from '@/utils/authority';
钟是志's avatar
钟是志 committed
5
import config from '@/config/config';
6 7
import { getOneStopConfig, isJSON } from '@/webPublic/zyd_public/utils/utils';
import router from 'umi/router';
钟是志's avatar
钟是志 committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

const getUrlInfo = (param) => {
	let url = window.document.location.href.toString();
	let u = url.split('?');
	if (typeof u[1] == 'string') {
		u = u[1].split('&');
		let get = {};
		for (let i in u) {
			let j = u[i].split('=');
			get[j[0]] = decodeURIComponent(j[1]);
		}
		return get;
	} else {
		return {};
	}
};

export default class Detail extends Component {
	constructor(props) {
		super(props);
		const { state, pathname } = this.props.location;
		let id = '';
    id = getOneStopConfig(pathname);
    if (!id) {
32
			id = getUrlInfo()?.id || this.props.workId;
钟是志's avatar
钟是志 committed
33
		}
钟是志's avatar
钟是志 committed
34 35 36 37 38

    let token = getUrlInfo().token;
    if(token){
      setToken(token);
    }
39
    this.minHeight = document.body.clientHeight - 110;
40

41
    this.state = {
钟是志's avatar
钟是志 committed
42 43 44 45 46
			id,
		};
	}

	componentDidMount() {
钟是志's avatar
钟是志 committed
47 48 49
    window.addEventListener(
      'message',
      (event) => {
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
        if (event && event.data && event.data.indexOf) {
          if(event.data.indexOf('iframeDetailHeight') > -1){ // 高度修改事件
            let height = Number(event.data.split('-')[1]);
            // console.log(height);
            const iframe = document.getElementById('applyIframeId');
            if (iframe && height > 950) {
              iframe.height = height;
            }
          }
          if(event.data.indexOf('routerChange') > -1){ // 路由改变事件
            let jsonData = event.data.split('-')[1];
            if(isJSON(jsonData)){
              let changeData = JSON.parse(jsonData);
              router[changeData.type](changeData.arg);
              console.log(changeData);
            }
钟是志's avatar
钟是志 committed
66 67
          }
        }
68

钟是志's avatar
钟是志 committed
69 70 71
      },
      false,
    );
钟是志's avatar
钟是志 committed
72 73
	}

74 75 76 77 78 79 80 81 82 83 84 85
  // static getDerivedStateFromProps(nextProps, prevState) {
	//   if(nextProps.workId && prevState.id && nextProps.workId !== prevState.id){
	//     return {
	//       id: nextProps.workId,
  //     };
  //   }else{
	//     return null;
  //   }
  //   // ...
  // }

  render() {
钟是志's avatar
钟是志 committed
86
		const { id } = this.state;
87 88
		let iframeUrl = `${config.gateWayPort}/portal/#/showSmartFormOnly?id=${id}&token=${getToken()}&isShow=true`;
		// iframeUrl = `https://yx.bpi.edu.cn/portal/#/showSmartFormOnly?id=${id}&token=${getToken()}&isShow=true`;
钟是志's avatar
钟是志 committed
89
		// iframeUrl = `http://localhost:8022/portal/#/showSmartFormOnly?id=${id}&token=${getToken()}&isShow=true`;
钟是志's avatar
钟是志 committed
90 91
		return (
			<PageHeaderWrapper title="">
92
				<Shell styleShell={{ marginTop: '0px' }}>
钟是志's avatar
钟是志 committed
93 94 95
					<iframe
						src={iframeUrl}
						frameBorder={0}
钟是志's avatar
钟是志 committed
96 97
						id="applyIframeId"
            name="applyIframe"
钟是志's avatar
钟是志 committed
98 99 100 101
						marginWidth="0"
						marginHeight="0"
						allowtransparency="yes"
						seamless
102
            height={this.minHeight}
钟是志's avatar
钟是志 committed
103 104 105
						scrolling={'no'}
						style={{
							width: '100%',
钟是志's avatar
钟是志 committed
106
              // height: '800px',
钟是志's avatar
钟是志 committed
107 108
              overflowY: 'auto',
              backgroundColor: '#fff',
钟是志's avatar
钟是志 committed
109 110 111 112 113 114 115
						}}
					/>
				</Shell>
			</PageHeaderWrapper>
		);
	}
}