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 13 14 15 16 17 18 19 20 21 22
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) {
  const { location: {pathname} } = props;
  const componentRef = useRef();
  const [showPrint, setShowPrint] = useState(false);
  const id = getOneStopConfig(pathname);
  useEffect(() => {
    setTimeout(() => {
      setShowPrint(true);
    }, 2000);
  }, []);
  return (<div>
钟是志's avatar
钟是志 committed
23
    <div id={'showButtonDiv'} className={styles.buttonDiv2}>
钟是志's avatar
钟是志 committed
24 25 26 27 28 29
      {
        showPrint ? <ReactToPrint
          trigger={() => <Button type={'primary'}>打印</Button>}
          content={() => componentRef.current}
          onBeforePrint={() => {
            return new Promise((resolve, reject) => {
钟是志's avatar
钟是志 committed
30 31 32 33 34 35
              // 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
36 37 38 39 40
              setTimeout(() => {
                resolve(true);
              }, 2000);
            });
          }}
钟是志's avatar
钟是志 committed
41
        /> : <div style={{width: '200px'}}>正在加载信息</div>
钟是志's avatar
钟是志 committed
42 43 44 45 46 47 48 49 50 51 52 53 54
      }

      {
        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
55
              width: '38cm',
钟是志's avatar
钟是志 committed
56 57
              pageBreakAfter: 'always',
              display: 'flex',
钟是志's avatar
钟是志 committed
58 59 60 61 62
              // justifyContent: 'center',
              // alignItems: 'center',
            }}
                 id={'printDivDom'}
            >
钟是志's avatar
钟是志 committed
63 64 65 66 67
              <IframeForRenderForm id={id} {...props} />
            </div>
    </div>
  </div>);
}