提交 74559a6f authored 作者: 钟是志's avatar 钟是志

打印功能修改

上级 e81ef846
import React, { useEffect, useRef, useState } from "react"; import React, { useEffect, useRef, useState } from 'react';
import ReactToPrint from "react-to-print"; import ReactToPrint from 'react-to-print';
import styles from "./index.less"; import styles from './index.less';
import { Button } from "antd"; import { Button } from 'antd';
import IframeForRenderForm from './IframeForRenderForm'; import IframeForRenderForm from './IframeForRenderForm';
const idsConfig = [ const idsConfig = [
{ {
id: '1427569429700411392', id: '1427569429700411392',
name: "新生入学登记表", name: '新生入学登记表',
key: "xsrxdjb" key: 'xsrxdjb',
}, },
{ {
id: '1427570690688548864', id: '1427570690688548864',
name: "新生入学报到单", name: '新生入学报到单',
key: "xsrxbdd" key: 'xsrxbdd',
}, },
]; ];
...@@ -23,32 +23,62 @@ export default function PrintQnmz(props) { ...@@ -23,32 +23,62 @@ export default function PrintQnmz(props) {
const [showPrint, setShowPrint] = useState(false); const [showPrint, setShowPrint] = useState(false);
console.log(window.history); console.log(window.history);
useEffect(() => { useEffect(() => {
document.title = "新手报到单打印"; document.title = '新手报到单打印';
setTimeout(() => { setTimeout(() => {
setShowPrint(true); setShowPrint(true);
}, 1000); }, 2000);
}, []); }, []);
// function printDom() {
// document.getElementById('showButtonDiv').style.display = 'none';
// window.print();
// setTimeout(() => {
// document.getElementById('showButtonDiv').style.display = 'grid';
// }, 1000);
// }
return (<div> return (<div>
<div className={styles.buttonDiv}> <div className={styles.buttonDiv} id={'showButtonDiv'}>
{ {/* {
showPrint && <ReactToPrint showPrint ? <Button type={"primary"} onClick={printDom}>打印</Button> : <div>正在加载打印信息, 请稍等</div>
trigger={() => <Button type={"primary"}>打印</Button>} }
content={() => componentRef.current} */}
/> {
} showPrint ? <ReactToPrint
trigger={() => <Button type={'primary'}>打印</Button>}
content={() => componentRef.current}
onBeforePrint={() => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(true);
}, 2000);
});
}}
/> : <div>正在加载打印信息, 请稍等</div>
}
{ {
showPrint && window.history.length > 1 && showPrint && window.history.length > 1 &&
<Button type={"danger"} onClick={() => { <Button type={'danger'} onClick={() => {
window.history.go(-1); window.history.go(-1);
}}>返回</Button> }}>返回</Button>
} }
</div> </div>
<div ref={componentRef}> <div ref={componentRef}>
{ {
idsConfig.map((x) => { idsConfig.map((x) => {
return ( return (
<div style={{minHeight: '29cm'}}> <div style={{
<IframeForRenderForm id={x.id} {...props}/> minHeight: '29cm',
minWidth: '21cm',
pageBreakAfter: 'always',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
}}>
<IframeForRenderForm id={x.id} {...props} />
</div> </div>
); );
}) })
......
...@@ -24,3 +24,9 @@ ...@@ -24,3 +24,9 @@
padding: 10px; padding: 10px;
justify-content: center; justify-content: center;
} }
@media print{
table{
//min-width: 19cm !important;
//min-height: 25cm !important;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论