提交 077b2cf3 authored 作者: 钟是志's avatar 钟是志

打印预览修改

上级 9a26e2aa
...@@ -19,268 +19,314 @@ import { ModalInfo } from '@/baseComponent/Modal'; ...@@ -19,268 +19,314 @@ import { ModalInfo } from '@/baseComponent/Modal';
import replace from '../../../../../config/zydxg/routes/studentAffairs/replace'; import replace from '../../../../../config/zydxg/routes/studentAffairs/replace';
export default class ViewPrint extends Component { export default class ViewPrint extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
configAll: null, configAll: null,
viewData: null, viewData: null,
loading: true, loading: true,
printIndex: 0, printIndex: 0,
showWindowPrint: false, showWindowPrint: false,
}; };
this.getConfigInfo = queryConfig.bind(this); this.getConfigInfo = queryConfig.bind(this);
} }
getViewData = () => { getViewData = () => {
const { selectedRows } = this.props; const { selectedRows } = this.props;
const ids = selectedRows.map((x) => x.id); const ids = selectedRows.map((x) => x.id);
this.getConfigInfo().then((x) => { this.getConfigInfo().then((x) => {
if (x && x.queryUrl) { if (x && x.queryUrl) {
getInfo( getInfo(
{ {
ids: ids.join(','), ids: ids.join(','),
}, },
x.queryUrl, x.queryUrl,
).then((viewData) => { ).then((viewData) => {
if (!viewData || !viewData.length) { if (!viewData || !viewData.length) {
message.warning('未查询到可打印的奖状数据'); message.warning('未查询到可打印的奖状数据');
console.error(`${x.queryUrl}接口报错或者没有返回数据`); console.error(`${x.queryUrl}接口报错或者没有返回数据`);
return false; return false;
} }
// let i = 0; // let i = 0;
for (const item of viewData) { for (const item of viewData) {
// item.name = ['黎处', '王昊楠', '古力娜扎', '古丽尼帕尔·阿布都黑利力'][i] || '钟是志'; // item.name = ['黎处', '王昊楠', '古力娜扎', '古丽尼帕尔·阿布都黑利力'][i] || '钟是志';
// i++; // i++;
for (let z in item) { for (let z in item) {
if (item[z] === null || item[z] === 'null') { if (item[z] === null || item[z] === 'null') {
item[z] = ''; item[z] = '';
} }
} }
} }
this.setState({ this.setState({
viewData, viewData,
}); });
}); });
} }
}); });
}; };
componentDidMount() { componentDidMount() {
this.getViewData(); this.getViewData();
getCLodopFuncJS().then((response) => { getCLodopFuncJS().then((response) => {
window.On_CLodop_Opened = function(){ window.On_CLodop_Opened = function() {
console.log('打印插件准备就绪,随时可以打印'); console.log('打印插件准备就绪,随时可以打印');
window.On_CLodop_Opened = null; window.On_CLodop_Opened = null;
}; };
if (response) { if (response) {
this.setState({ this.setState({
loading: false, loading: false,
}); });
} }
}); });
}
} detailDom = (data) => {
const {
configAll: { config },
} = this.state;
const res = [];
for (const item of config) {
res.push(
DetailDom({
config: item,
data: data[item.fieldCode],
}),
);
}
return res;
};
detailDom = (data) => { printOne = () => {
const { const { printIndex, configAll, viewData } = this.state;
configAll: { config }, const { printMeth } = configAll;
} = this.state; const { wide, high } = configAll;
const res = []; const { LODOP } = window;
for (const item of config) { let strHTML = document.getElementById(`djfgkjdlfjg`).innerHTML;
res.push( /*strHTML = strHTML.replace(
DetailDom({
config: item,
data: data[item.fieldCode],
}),
);
}
return res;
};
printOne = () => {
const { printIndex, configAll, viewData } = this.state;
const { printMeth } = configAll;
const { wide, high } = configAll;
const { LODOP } = window;
let strHTML = document.getElementById(`printDomId_${printIndex}`).innerHTML;
strHTML = strHTML.replace(
'break-after: page;', 'break-after: page;',
'page-break-after: always;', 'page-break-after: always;',
); );
strHTML = `${strHTML}`; strHTML = `${strHTML}`;
// strHTML = 'http://scjoyedu.eicp.net:53005/config/23333.pdf'; strHTML = `<div style="
LODOP.PRINT_INITA(0, 0, `100%`, `100%`, "printDomId_" + printIndex); page-break-after: always;
LODOP.SET_PRINT_MODE('POS_BASEON_PAPER', true); background-color: red;
LODOP.SET_PRINT_PAGESIZE(printMeth, 0, 0, "A4"); position: relative;
LODOP.ADD_PRINT_HTM(0, 0, '100%', '100%', strHTML); // HTML 打印 /!*background-image: url('http://zysoft.cdzhiyong.com:53003/dsf/u/upload/202006/05182802hzom.jpg');*!/
// LODOP.ADD_PRINT_URL(0, 0, '100%', '100%', strHTML); // URL 打印 width: 29.6cm;
// LODOP.PRINT(); // 直接打印 height: 21cm; "><div style="position: absolute;top: 10.5cm>123123
LODOP.PREVIEW(); // 打印预览 </div>
}; </div>`;
console.log(strHTML);*/
LODOP.PRINT_INITA(0, '-0.3cm', `100%`, `100%`, 'printDomId_' + printIndex);
// LODOP.SET_PRINT_MODE('POS_BASEON_PAPER', true);
// LODOP.SET_PRINT_STYLEA('All', 'VOrient', 2);
// LODOP.SET_PRINT_STYLEA('All', 'HOrient', 2);
LODOP.SET_PRINT_PAGESIZE(printMeth, 0, 0, 'A4'); // 纵向打印
//LODOP.SET_PRINT_PAGESIZE(1, 0, 0, 'A4'); // 纵向打印
LODOP.ADD_PRINT_HTM(0, 0, '100%', '100%', strHTML); // HTML 打印
// LODOP.ADD_PRINT_URL(0, 0, '100%', '100%', strHTML); // URL 打印
// LODOP.PRINT(); // 直接打印
LODOP.PREVIEW(); // 打印预览
};
printOneByOne = () => { printOneByOne = () => {
// 按队列打印 // 按队列打印
const { configAll, viewData, printIndex } = this.state; const { configAll, viewData, printIndex } = this.state;
if (viewData && viewData.length) { if (viewData && viewData.length) {
message.info(`正在打印第${printIndex + 1}张奖状`); message.info(`正在打印第${printIndex + 1}张奖状`);
this.printOne(); this.printOne();
const { length } = viewData; const { length } = viewData;
let LODOPObj = window.LODOP; let LODOPObj = window.LODOP;
LODOPObj.On_Return_Remain = true; LODOPObj.On_Return_Remain = true;
LODOPObj.On_Return = (TaskId, Value) => { LODOPObj.On_Return = (TaskId, Value) => {
console.log(TaskId, Value === 1 || Value === '1' ? '已发出实际打印命令!' : '放弃打印!'); console.log(
this.setState({ TaskId,
printIndex: this.state.printIndex + 1, Value === 1 || Value === '1' ? '已发出实际打印命令!' : '放弃打印!',
}, () => { );
if (this.state.printIndex < length) { this.setState(
message.info(`正在打印第${this.state.printIndex + 1}张奖状`); {
this.printOne(); printIndex: this.state.printIndex + 1,
} else { },
this.setState({ () => {
loading: false, if (this.state.printIndex < length) {
}); message.info(`正在打印第${this.state.printIndex + 1}张奖状`);
} this.printOne();
}, } else {
); this.setState({
}; loading: false,
} else { });
console.error('暂无数据无法打印'); }
} },
}; );
};
} else {
console.error('暂无数据无法打印');
}
};
printByLodop = () => { printByLodop = () => {
if (!window.LODOP || !window.LODOP.PRINT_INIT) { if (!window.LODOP || !window.LODOP.PRINT_INIT) {
console.error('打印服务未启动'); console.error('打印服务未启动');
ModalInfo('打印服务未启动'); ModalInfo('打印服务未启动');
return false; return false;
} }
this.setState( this.setState(
{ {
showWindowPrint: true, showWindowPrint: true,
printIndex: 0, printIndex: 0,
}, },
() => { () => {
this.printOneByOne(); this.printOneByOne();
}, },
); );
}; };
render() { render() {
const { configAll, viewData, showWindowPrint, loading, printBg } = this.state; const {
if (!viewData) { configAll,
return null; viewData,
} showWindowPrint,
if (!configAll.backgroundUrl) { loading,
console.error('没有设置模版图片无法使用'); printBg,
return null; } = this.state;
} if (!viewData) {
const { hasPrintBackground, backgroundUrl, wide, high } = configAll; return null;
let imageStyle = { }
height: high ? `${high}cm` : A4Height, if (!configAll.backgroundUrl) {
width: wide ? `${wide}cm` : A4Width, console.error('没有设置模版图片无法使用');
textAlign: 'center', return null;
}; }
return ( const { hasPrintBackground, backgroundUrl, wide, high } = configAll;
<Fragment> let imageStyle = {
<Shell styleShell={{ marginTop: '0', marginBottom: '20px' }}> height: high ? `${high}cm` : A4Height,
<div style={{ height: '54px', padding: '12px 0 12px 12px' }}> width: wide ? `${wide}cm` : A4Width,
<ButtonDiy textAlign: 'center',
name={'打印设备选择'} };
handleClick={() => { return (
window.LODOP.SELECT_PRINTER(); <Fragment>
}} <Shell styleShell={{ marginTop: '0', marginBottom: '20px' }}>
loading={loading} <div style={{ height: '54px', padding: '12px 0 12px 12px' }}>
/> <ButtonDiy
<ButtonDiy name={'打印设备选择'}
name={'打印'} handleClick={() => {
handleClick={() => { window.LODOP.SELECT_PRINTER();
this.setState({ }}
printBg: false, loading={loading}
}, () => { />
this.printByLodop(); <ButtonDiy
}); name={'打印'}
}} handleClick={() => {
loading={loading} this.setState(
/> {
<ButtonDiy printBg: false,
name={'返回'} },
handleClick={() => { () => {
router.goBack(); this.printByLodop();
}} },
/> );
</div> }}
</Shell> loading={loading}
/>
<ButtonDiy
name={'返回'}
handleClick={() => {
router.goBack();
}}
/>
</div>
</Shell>
{/** 预览的dom */} {/** 预览的dom */}
{viewData && viewData.length ? ( {viewData && viewData.length ? (
<div> <div>
{viewData.map((info, index) => { {viewData.map((info, index) => {
return ( return (
<div <div
className={styles.outSideDivPrint} className={styles.outSideDivPrint}
key={index + 'divKey'} key={index + 'divKey'}
style={{ style={{
...imageStyle, ...imageStyle,
}}> }}>
{ hasPrintBackground ? ( {hasPrintBackground ? (
<img <img
src={backgroundUrl} src={backgroundUrl}
draggable={false} draggable={false}
alt={'背景图'} alt={'背景图'}
style={{ style={{
zIndex: 1, zIndex: 1,
...imageStyleAll, ...imageStyleAll,
// border: '1px solid red', // border: '1px solid red',
}} }}
/> />
) : null} ) : null}
{this.detailDom(info)} {this.detailDom(info)}
</div> </div>
); );
})} })}
</div> </div>
) : null} ) : null}
<div id={'djfgkjdlfjg'}>
{/** 打印的dom */} <div
{viewData && viewData.length ? ( style={{
<div pageBreakAfter: 'always',
ref={(node) => (this.content = node)} // backgroundColor: 'red',
style={{ position: 'relative',
display: showWindowPrint ? 'block' : 'none', width: '100%',
}}> height: '100%',
{viewData.map((info, index) => { }}>
return ( <img
<div src={backgroundUrl}
key={`${index}divKey`} width={'1000px'}
id={`printDomId_${index}`} height={'800px'}
style={{}}> style={{
<div // position: 'absolute',
style={{ // top: '-0.2cm',
position: 'relative', }}
pageBreakAfter: 'always', />
// border: '1px solid red', </div>
...imageStyle, </div>
}}>
{ hasPrintBackground ? ( {/** 打印的dom */}
<img {viewData && viewData.length ? (
src={backgroundUrl} <div
draggable={false} ref={(node) => (this.content = node)}
alt={'背景图'} style={{
style={{ display: showWindowPrint ? 'block' : 'none',
zIndex: 1, }}>
...imageStyleAll, {viewData.map((info, index) => {
// border: '1px solid red', return (
}} <div
/> key={`${index}divKey`}
) : null} id={`printDomId_${index}`}
{this.detailDom(info)} style={{}}>
</div> <div
</div> style={{
); position: 'relative',
})} pageBreakAfter: 'always',
</div> // border: '1px solid red',
) : null} ...imageStyle,
</Fragment> }}>
); {hasPrintBackground ? (
} <img
src={backgroundUrl}
draggable={false}
alt={'背景图'}
style={{
zIndex: 1,
...imageStyleAll,
// border: '1px solid red',
}}
/>
) : null}
{this.detailDom(info)}
</div>
</div>
);
})}
</div>
) : null}
</Fragment>
);
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论