提交 1b98a669 authored 作者: 钟是志's avatar 钟是志

打印相关功能调整

上级 350b2000
......@@ -123,6 +123,7 @@ export function getLodop(dir, oOBJECT, oEMBED) {
//===如下空白位置适合调用统一功能(如注册语句、语言选择等):===
LODOP.SET_SHOW_MODE('LANGUAGE', 0);
LODOP.SET_LICENSES('成都市知用科技有限公司', '649677881727389907689190562356', '', '');
console.log('licenses注入语句已执行');
//===========================================================
return LODOP;
} catch (err) {
......
......@@ -2,8 +2,8 @@ import { message } from 'antd';
import { ModalConfirm, ModalInfo } from '@/baseComponent/Modal';
import * as lo from './LodopFuncs';
export const A4Height = '29.6cm';
export const A4Width = '20.9cm';
export const A4Height = '28.7cm';
export const A4Width = '19.8cm';
export const imageStyleAll = {
width: '100%',
// height: '100%',
......@@ -28,8 +28,6 @@ export function getCLodopFuncJS() {
}
document.querySelector('body').appendChild(sc);
sc.onload = function() {
console.log(window.LODOP);
// getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
resolve(true);
console.log('打印插件加载成功');
};
......@@ -101,3 +99,22 @@ export const styleCount = (config) => {
};
return style;
};
export const templateCode = [
{
path: '/xg/xg_hard/SearchAndPrint/printReview',
code: 'award',
name: '评奖评优奖状',
},
{
path: '/xg/student_affairs/replace/printStudentCard',
code: 'reissueStudentCard',
name: '学生证补办打印',
},
{
path: '/xg/stundents_record/printStudentCard',
code: 'studentCard',
name: '学生信息-学生证打印',
},
];
import React, { Component, Fragment } from 'react';
import { queryConfig } from '../services';
import { getInfo } from '@/highOrderComponent/Service';
import { message, Button } from 'antd';
import Shell from '@/baseComponent/Shell';
import ReactToPrint from 'react-to-print';
import ButtonDiy from '@/baseComponent/ButtonDiy';
import router from 'umi/router';
import styles from '../index.less';
import DetailDom from './DetailDom';
import { imageStyleAll, A4Width, A4Height } from './config';
export default class ViewPrint extends Component {
constructor(props) {
super(props);
this.state = {
configAll: null,
viewData: null,
loading: false,
minHeight: 0,
showWindowPrint: false,
};
this.getConfigInfo = queryConfig.bind(this);
}
countImageHeight = () => {
if (!this.state.configAll) {
return false;
}
const {
configAll: { backgroundUrl },
} = this.state;
const img = new Image();
img.src = backgroundUrl;
img.onload = () => {
this.setState({
minHeight: img.height,
});
};
};
getViewData = () => {
const { selectedRows } = this.props;
const ids = selectedRows.map((x) => x.id);
this.getConfigInfo().then((x) => {
this.countImageHeight();
if (x && x.queryUrl) {
getInfo(
{
ids: ids.join(','),
},
x.queryUrl,
).then((viewData) => {
if (!viewData || !viewData.length) {
message.warning('未查询到可打印的奖状数据');
console.error(`${x.queryUrl}接口报错或者没有返回数据`);
return false;
}
for (let item of viewData) {
for (let x in item) {
if (item[x] === null || item[x] === 'null') {
item[x] = '';
}
}
}
this.setState({
viewData,
});
});
}
});
};
beforePrint = () => {
console.log('beforePrint');
};
afterPrint = () => {
console.log('afterPrint');
};
componentDidMount() {
this.getViewData();
}
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;
};
onBeforeGetContent = () => {
this.setState({
loading: true,
});
return new Promise((resolve, reject) => {
const { selectedRows } = this.props;
const { configAll } = this.state;
const ids = selectedRows.map((x) => {
return x.id;
});
if (configAll.callUrl && false) {
// 暂时关闭调用这个接口 不通知后台是否打印了
getInfo({ ids: ids.join(',') }, configAll.callUrl).then((x) => {
if (x) {
this.setState({ showWindowPrint: true }, () => {
resolve(true);
});
} else {
resolve(true);
}
});
} else {
this.setState({ showWindowPrint: true }, () => {
resolve(true);
});
}
});
};
import React from 'react';
import ViewPrint from './index2';
export default class Index extends React.Component {
render() {
const {
loading,
configAll,
viewData,
showWindowPrint,
minHeight,
} = this.state;
if (!viewData || !minHeight) {
return null;
}
if (!configAll.backgroundUrl) {
console.error('没有设置模版图片无法使用');
return null;
}
const { hasPrintBackground, backgroundUrl, wide, high } = configAll;
const imageStyle = {
height: `${high}cm` || A4Height,
width: `${wide}cm` || A4Width,
};
return (
<Fragment>
<Shell styleShell={{ marginTop: '0', marginBottom: '20px' }}>
<div style={{ height: '54px', padding: '12px 0 12px 12px' }}>
<ReactToPrint
trigger={() => (
<Button
shape="round"
type="primary"
loading={loading}
style={{ marginRight: '20px' }}>
打印
</Button>
)}
content={() => this.content}
onBeforeGetContent={this.onBeforeGetContent}
onAfterPrint={() => {
this.setState({
showWindowPrint: false,
loading: false,
});
}}
/>
<ButtonDiy
name={'返回'}
handleClick={() => {
router.goBack();
}}
/>
</div>
</Shell>
{/** 预览的dom **/}
{viewData && viewData.length ? (
<div>
{viewData.map((info, index) => {
return (
<div
className={styles.outSideDivPrint}
key={index + 'divKey'}
style={{
...imageStyle,
}}>
<img
src={backgroundUrl}
draggable={false}
className={styles.bgimagePrint}
alt={'背景图'}
style={imageStyleAll}
/>
{this.detailDom(info)}
</div>
);
})}
</div>
) : null}
{/** 打印的dom */}
{viewData && viewData.length ? (
<div
ref={(node) => (this.content = node)}
style={{
display: showWindowPrint /*|| true*/ ? 'block' : 'none',
}}>
{viewData.map((info, index) => {
return (
<div
className={styles.outSideDivPrint}
key={`${index}divKey`}
style={{
...imageStyle,
}}>
{hasPrintBackground ? (
<img
src={backgroundUrl}
draggable={false}
className={styles.bgimagePrint}
alt={'背景图'}
style={imageStyleAll}
/>
) : null}
{this.detailDom(info)}
</div>
);
})}
</div>
) : null}
</Fragment>
<ViewPrint {...this.props}/>
);
}
}
// import React, { Component, Fragment } from 'react';
// import { queryConfig } from '../services';
// import { getInfo } from '@/highOrderComponent/Service';
// import { message, Button } from 'antd';
// import Shell from '@/baseComponent/Shell';
// import ReactToPrint from 'react-to-print';
// import ButtonDiy from '@/baseComponent/ButtonDiy';
// import router from 'umi/router';
// import styles from '../index.less';
// import DetailDom from './DetailDom';
// import { imageStyleAll, A4Width, A4Height } from './config';
//
// export default class ViewPrint extends Component {
// constructor(props) {
// super(props);
// this.state = {
// configAll: null,
// viewData: null,
// loading: false,
// minHeight: 0,
// showWindowPrint: false,
// };
// this.getConfigInfo = queryConfig.bind(this);
// }
//
// countImageHeight = () => {
// if (!this.state.configAll) {
// return false;
// }
// const {
// configAll: { backgroundUrl },
// } = this.state;
// const img = new Image();
// img.src = backgroundUrl;
// img.onload = () => {
// this.setState({
// minHeight: img.height,
// });
// };
// };
//
// getViewData = () => {
// const { selectedRows } = this.props;
// const ids = selectedRows.map((x) => x.id);
// this.getConfigInfo().then((x) => {
// this.countImageHeight();
// if (x && x.queryUrl) {
// getInfo(
// {
// ids: ids.join(','),
// },
// x.queryUrl,
// ).then((viewData) => {
// if (!viewData || !viewData.length) {
// message.warning('未查询到可打印的奖状数据');
// console.error(`${x.queryUrl}接口报错或者没有返回数据`);
// return false;
// }
// for (let item of viewData) {
// for (let x in item) {
// if (item[x] === null || item[x] === 'null') {
// item[x] = '';
// }
// }
// }
// this.setState({
// viewData,
// });
// });
// }
// });
// };
//
//
// beforePrint = () => {
// console.log('beforePrint');
// };
//
// afterPrint = () => {
// console.log('afterPrint');
// };
//
// componentDidMount() {
// this.getViewData();
// }
//
// 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;
// };
//
// onBeforeGetContent = () => {
// this.setState({
// loading: true,
// });
//
// return new Promise((resolve, reject) => {
// const { selectedRows } = this.props;
// const { configAll } = this.state;
// const ids = selectedRows.map((x) => {
// return x.id;
// });
// if (configAll.callUrl && false) {
// // 暂时关闭调用这个接口 不通知后台是否打印了
// getInfo({ ids: ids.join(',') }, configAll.callUrl).then((x) => {
// if (x) {
// this.setState({ showWindowPrint: true }, () => {
// resolve(true);
// });
// } else {
// resolve(true);
// }
// });
// } else {
// this.setState({ showWindowPrint: true }, () => {
// resolve(true);
// });
// }
// });
// };
//
// render() {
// const {
// loading,
// configAll,
// viewData,
// showWindowPrint,
// minHeight,
// } = this.state;
// if (!viewData || !minHeight) {
// return null;
// }
// if (!configAll.backgroundUrl) {
// console.error('没有设置模版图片无法使用');
// return null;
// }
// const { hasPrintBackground, backgroundUrl, wide, high } = configAll;
// const imageStyle = {
// height: `${high}cm` || A4Height,
// width: `${wide}cm` || A4Width,
// };
//
// return (
// <Fragment>
// <Shell styleShell={{ marginTop: '0', marginBottom: '20px' }}>
// <div style={{ height: '54px', padding: '12px 0 12px 12px' }}>
// <ReactToPrint
// trigger={() => (
// <Button
// shape="round"
// type="primary"
// loading={loading}
// style={{ marginRight: '20px' }}>
// 打印
// </Button>
// )}
// content={() => this.content}
// onBeforeGetContent={this.onBeforeGetContent}
// onAfterPrint={() => {
// this.setState({
// showWindowPrint: false,
// loading: false,
// });
// }}
// />
// <ButtonDiy
// name={'返回'}
// handleClick={() => {
// router.goBack();
// }}
// />
// </div>
// </Shell>
//
// {/** 预览的dom **/}
// {viewData && viewData.length ? (
// <div>
// {viewData.map((info, index) => {
// return (
// <div
// className={styles.outSideDivPrint}
// key={index + 'divKey'}
// style={{
// ...imageStyle,
// }}>
// <img
// src={backgroundUrl}
// draggable={false}
// className={styles.bgimagePrint}
// alt={'背景图'}
// style={imageStyleAll}
// />
// {this.detailDom(info)}
// </div>
// );
// })}
// </div>
// ) : null}
//
// {/** 打印的dom */}
// {viewData && viewData.length ? (
// <div
// ref={(node) => (this.content = node)}
// style={{
// display: showWindowPrint /*|| true*/ ? 'block' : 'none',
// }}>
// {viewData.map((info, index) => {
// return (
// <div
// className={styles.outSideDivPrint}
// key={`${index}divKey`}
// style={{
// ...imageStyle,
// }}>
// {hasPrintBackground ? (
// <img
// src={backgroundUrl}
// draggable={false}
// className={styles.bgimagePrint}
// alt={'背景图'}
// style={imageStyleAll}
// />
// ) : null}
//
// {this.detailDom(info)}
// </div>
// );
// })}
// </div>
// ) : null}
// </Fragment>
// );
// }
// }
......@@ -3,20 +3,15 @@ import { queryConfig } from '../services';
import { getInfo } from '@/highOrderComponent/Service';
import { message, Button } from 'antd';
import Shell from '@/baseComponent/Shell';
import ReactToPrint from 'react-to-print';
import ButtonDiy from '@/baseComponent/ButtonDiy';
import router from 'umi/router';
import styles from '../index.less';
import DetailDom from './DetailDom';
import { imageStyleAll, A4Width, A4Height, getCLodopFuncJS } from './config';
import { A4Width, A4Height, getCLodopFuncJS, templateCode } from './config';
import RenderAuthorized from '@/components/Authorized';
import { getAuthority } from '@/utils/authority';
import { ModalInfo } from '@/baseComponent/Modal';
const Authorized = RenderAuthorized(getAuthority());
const { check } = Authorized;
import { ModalInfo } from '@/baseComponent/Modal';
import replace from '../../../../../config/zydxg/routes/studentAffairs/replace';
export default class ViewPrint extends Component {
constructor(props) {
......@@ -47,10 +42,10 @@ export default class ViewPrint extends Component {
console.error(`${x.queryUrl}接口报错或者没有返回数据`);
return false;
}
// let i = 0;
let i = 0;
for (const item of viewData) {
// item.name = ['黎处', '王昊楠', '古力娜扎', '古丽尼帕尔·阿布都黑利力'][i] || '钟是志';
// i++;
// item.name = ['黎处', '王昊楠', '古力娜扎', '古丽尼帕尔·阿布都黑利力'][i] || '钟是志';
i++;
for (let z in item) {
if (item[z] === null || item[z] === 'null') {
item[z] = '';
......@@ -96,72 +91,73 @@ export default class ViewPrint extends Component {
return res;
};
printOne = () => {
printOne = (review = false) => {
const { printIndex, configAll, viewData } = this.state;
const { printMeth } = configAll;
const { wide, high } = configAll;
const { LODOP } = window;
let strHTML = document.getElementById(`djfgkjdlfjg`).innerHTML;
/*strHTML = strHTML.replace(
'break-after: page;',
'page-break-after: always;',
);
strHTML = `${strHTML}`;
strHTML = `<div style="
page-break-after: always;
background-color: red;
position: relative;
/!*background-image: url('http://zysoft.cdzhiyong.com:53003/dsf/u/upload/202006/05182802hzom.jpg');*!/
width: 29.6cm;
height: 21cm; "><div style="position: absolute;top: 10.5cm>123123
</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'); // 纵向打印
let strHTML = document.getElementById(`printDomId_${printIndex}`).innerHTML;
if (review) {
strHTML = document.getElementById(`printDomId_0`).innerHTML;
}
LODOP.PRINT_INITA(0, 0, `${wide}cm`, `${high}cm`, `printDomId_${printIndex}`);
LODOP.SET_PRINT_PAGESIZE(printMeth, `${wide}cm`, `${high}cm`, 'CreateCustomPage'); // 打印方向
LODOP.ADD_PRINT_HTM(0, 0, '100%', '100%', strHTML); // HTML 打印
// LODOP.ADD_PRINT_URL(0, 0, '100%', '100%', strHTML); // URL 打印
// LODOP.PRINT(); // 直接打印
// LODOP.PREVIEW(); // 打印预览
LODOPObj.PRINT_SETUP();
if (review) {
LODOP.PREVIEW(); // 打印预览
} else {
LODOP.PRINT(); // 打印
}
};
printPreview = () => {
// 打印预览
this.printOne(true);
};
printedDataSave = (index) => {
const { selectedRows } = this.props;
const { configAll } = this.state;
if (!selectedRows[index] || !selectedRows[index].id) {
console.error('printedDataSave 没有正确的id 无法保存打印信息到后台');
return false;
}
const ids = selectedRows[index].id;
getInfo({ ids }, configAll.callUrl).then((x) => {
if (x) {
console.log(`${ids}的打印信息已保存到后台`);
return true;
} else {
return false;
}
});
};
printOneByOne = () => {
// 按队列打印
const { configAll, viewData, printIndex } = this.state;
const { viewData, printIndex } = this.state;
if (viewData && viewData.length) {
message.info(`正在打印第${printIndex + 1}张奖状`);
this.printOne();
const { length } = viewData;
let LODOPObj = window.LODOP;
LODOPObj.On_Return_Remain = true;
LODOPObj.On_Return = (TaskId, Value) => {
console.log(
TaskId,
Value === 1 || Value === '1' ? '已发出实际打印命令!' : '放弃打印!',
);
this.setState(
{
printIndex: this.state.printIndex + 1,
},
() => {
if (this.state.printIndex < length) {
message.info(`正在打印第${this.state.printIndex + 1}张奖状`);
this.printOne();
} else {
this.setState({
loading: false,
});
}
},
);
if (Number(Value) === 1) {
message.info(`正在打印第${printIndex + 1}张`);
this.printedDataSave(printIndex);
}
this.setState({ printIndex: this.state.printIndex + 1 }, () => {
if (this.state.printIndex < length) {
this.printOne();
} else {
this.setState({
loading: false,
});
}
});
};
} else {
console.error('暂无数据无法打印');
console.error('暂无任何数据无法打印');
}
};
......@@ -183,26 +179,36 @@ height: 21cm; "><div style="position: absolute;top: 10.5cm>123123
};
render() {
const {
configAll,
viewData,
showWindowPrint,
loading,
printBg,
} = this.state;
const { configAll, viewData, showWindowPrint, loading } = this.state;
if (!viewData) {
return null;
return <Shell styleShell={{ marginTop: '0', marginBottom: '20px' }}>
<div style={{ height: '54px', padding: '12px 0 12px 12px' }}>
<ButtonDiy
name={'返回'}
handleClick={() => {
router.goBack();
}}
/>
</div>
</Shell>;
}
if (!configAll.backgroundUrl) {
console.error('没有设置模版图片无法使用');
return null;
}
const { hasPrintBackground, backgroundUrl, wide, high } = configAll;
let imageStyle = {
const { wide, high } = configAll;
const imageStyle = {
height: high ? `${high}cm` : A4Height,
width: wide ? `${wide}cm` : A4Width,
textAlign: 'center',
};
const { pathname } = this.props.location;
const templateInfo = templateCode.find((x) => {
return x.path === pathname;
});
if(!templateInfo){
console.error('未找到templateInfo', pathname);
}
return (
<Fragment>
<Shell styleShell={{ marginTop: '0', marginBottom: '20px' }}>
......@@ -217,109 +223,75 @@ height: 21cm; "><div style="position: absolute;top: 10.5cm>123123
<ButtonDiy
name={'打印'}
handleClick={() => {
this.setState(
{
printBg: false,
},
() => {
this.printByLodop();
},
);
this.printByLodop();
}}
loading={loading}
/>
<ButtonDiy
name={'返回'}
handleClick={() => {
router.goBack();
}}
/>
</div>
</Shell>
{/** 预览的dom */}
{viewData && viewData.length ? (
<div>
{viewData.map((info, index) => {
return (
<div
className={styles.outSideDivPrint}
key={index + 'divKey'}
style={{
...imageStyle,
}}>
{hasPrintBackground ? (
<img
src={backgroundUrl}
draggable={false}
alt={'背景图'}
style={{
zIndex: 1,
...imageStyleAll,
// border: '1px solid red',
}}
/>
) : null}
{this.detailDom(info)}
</div>
);
})}
</div>
) : null}
<div id={'djfgkjdlfjg'}>
<Authorized authority={'/jc/setting/PrintPositionSetting'}>
<span style={{ float: 'right' }}>
<ButtonDiy
name={'打印预览(实施)'}
handleClick={() => {
this.printPreview();
}}
loading={loading}
/>
</span>
</Authorized>
<Authorized authority={'/jc/setting/PrintPositionSetting'}>
<span style={{ float: 'right' }}>
<ButtonDiy
name={'打印模版设置(实施)'}
handleClick={() => {
router.push({
pathname: '/jc/setting/PrintConfig',
state: { code: templateInfo.code },
});
}}
/>
</span>
</Authorized>
<div
style={{
pageBreakAfter: 'always',
// backgroundColor: 'red',
position: 'relative',
width: '100%',
height: '100%',
}}>
<img
src={backgroundUrl}
width={'1000px'}
height={'800px'}
style={{
// position: 'absolute',
// top: '-0.2cm',
}}
/>
<Authorized authority={'/jc/setting/PrintPositionSetting'}>
<span style={{ float: 'right' }}>
<ButtonDiy
name={'字段位置设置(实施)'}
handleClick={() => {
router.push({
pathname: '/xg/xg_hard/AwardSet/printSetting',
state: { code: templateInfo.code },
});
}}
/>
</span>
</Authorized>
</div>
</div>
{/** 打印的dom */}
</Shell>
{viewData && viewData.length ? (
<div
ref={(node) => (this.content = node)}
style={{
display: showWindowPrint ? 'block' : 'none',
display: showWindowPrint || true ? 'block' : 'none',
}}>
{viewData.map((info, index) => {
return (
<div
key={`${index}divKey`}
id={`printDomId_${index}`}
style={{}}>
<div key={`${index}divKey`} id={`printDomId_${index}`}>
<div
style={{
position: 'relative',
pageBreakAfter: 'always',
// border: '1px solid red',
marginBottom: '10px',
...imageStyle,
backgroundColor: '#fff',
}}>
{hasPrintBackground ? (
<img
src={backgroundUrl}
draggable={false}
alt={'背景图'}
style={{
zIndex: 1,
...imageStyleAll,
// border: '1px solid red',
}}
/>
) : null}
{this.detailDom(info)}
</div>
</div>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论