PrintCheckRecord.js 2.1 KB
Newer Older
钟是志's avatar
钟是志 committed
1 2 3 4
/**
 * 单页面打印.
 * 打印CheckRecord
 * */
钟是志's avatar
钟是志 committed
5 6 7 8 9 10 11 12
import React, { useEffect, useRef, useState } from 'react';
import ReactToPrint from 'react-to-print';
import styles from './index.less';
import { Button } from 'antd';
import IframeForRenderForm from './IframeForRenderForm';
import { getOneStopConfig } from '@/webPublic/zyd_public/utils/utils';

export default function PrintQnmz(props) {
13
  const { location: {pathname}, noNeedPrint } = props;
钟是志's avatar
钟是志 committed
14 15
  const componentRef = useRef();
  const [showPrint, setShowPrint] = useState(false);
16
  const id = props.id || getOneStopConfig(pathname);
钟是志's avatar
钟是志 committed
17
  useEffect(() => {
18 19 20 21 22
    if(!noNeedPrint){
      setTimeout(() => {
        setShowPrint(true);
      }, 2000);
    }
钟是志's avatar
钟是志 committed
23 24
  }, []);
  return (<div>
钟是志's avatar
钟是志 committed
25
    <div id={'showButtonDiv'} className={styles.buttonDiv2}>
钟是志's avatar
钟是志 committed
26 27 28 29 30 31
      {
        showPrint ? <ReactToPrint
          trigger={() => <Button type={'primary'}>打印</Button>}
          content={() => componentRef.current}
          onBeforePrint={() => {
            return new Promise((resolve, reject) => {
钟是志's avatar
钟是志 committed
32 33 34 35 36 37
              // let d = document.getElementsByClassName(`antd-pro\\web-public\\one_stop_public\\libs\\form-list\\-table-list-tableListOperator`);
              // if(d && d.length){
              //   console.log(d);
              //   d[0].style.display = 'none';
              // }

钟是志's avatar
钟是志 committed
38 39 40 41 42
              setTimeout(() => {
                resolve(true);
              }, 2000);
            });
          }}
43
        /> : !noNeedPrint && <div style={{width: '200px'}}>正在加载信息</div>
钟是志's avatar
钟是志 committed
44 45 46 47 48 49 50 51 52 53 54 55 56
      }

      {
        showPrint && window.history.length > 1 &&
        <Button type={'danger'} onClick={() => {
          window.history.go(-1);
        }}>返回</Button>
      }
    </div>
    <div ref={componentRef}>
            <div style={{
              minHeight: '21cm',
              minWidth: '29cm',
钟是志's avatar
钟是志 committed
57
              width: '38cm',
钟是志's avatar
钟是志 committed
58 59
              pageBreakAfter: 'always',
              display: 'flex',
钟是志's avatar
钟是志 committed
60 61 62 63 64
              // justifyContent: 'center',
              // alignItems: 'center',
            }}
                 id={'printDivDom'}
            >
钟是志's avatar
钟是志 committed
65 66 67 68 69
              <IframeForRenderForm id={id} {...props} />
            </div>
    </div>
  </div>);
}