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

打印调试.所见及所得

上级 2b51aa31
......@@ -3,6 +3,7 @@ import JsBarcode from 'jsbarcode';
import styles from '../index.less';
import moment from 'moment';
import { styleCount } from './config';
/**
* -2 条形码
* -1 常量
......@@ -16,48 +17,39 @@ const normalTextRender = (text, config) => {
if (!text || text === 'undefined' || typeof text === 'undefined') {
return null;
}
const width = config.wide ? config.wide + 'px' : 'auto';
const height = config.high ? config.high + 'px' : 'auto';
if (config.mark && text.indexOf(config.mark) > -1) { // 换行分隔符
text = text.split(config.mark);
let length = text.length;
return <span style={styleCount(config)}>
{text.map((x, index) => {
return <p
return text.map((x, index) => {
return <div
key={x}
style={{
...styleCount(config),
marginBottom: '0',
width: `${config.wide}cm` || 'auto',
width,
textAlign: 'right',
}}>
{x}{length > index + 1 ? config.mark : ''}
</p>;
})}
</span>;
</div>;
});
}
return (
<div style={{
textAlign: 'justify',
textAlignLast: 'justify',
}}>
<p style={{
/* float:'left',
textAlign:'justify',
textJustify:'inter-word',
textJustify:'inter-ideograph',*/
...styleCount(config),
marginBottom: '0',
width: `${config.wide}cm` || 'auto',
width,
height,
lineHeight: height,
textAlign: 'right',
letterSpacing: '2px',
height: `${config.high}cm` || 'auto',
...styleCount(config),
lineHeight: `${config.high}cm` || 'auto',
}}>
{text}
</p>
<div></div>
</div>
)
;
;
};
const imageRender = (imageUrl) => {
......
......@@ -25,34 +25,16 @@ export default class ViewPrint extends Component {
configAll: null,
viewData: null,
loading: true,
minHeight: 0,
printIndex: 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(
{
......@@ -65,15 +47,14 @@ 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] = '';
}
//if(item[])
}
}
this.setState({
......@@ -112,29 +93,19 @@ export default class ViewPrint extends Component {
};
printOne = () => {
const { printIndex, configAll } = this.state;
const { backgroundUrl, wide, high } = configAll;
const { printIndex, configAll, viewData } = this.state;
const { wide, high } = configAll;
let LODOPObj = window.LODOP;
let strHTML = document.getElementById(`printDomId_${printIndex}`).innerHTML;
strHTML = strHTML.replace('break-after: page;', 'page-break-after: always;');
strHTML = `<!DOCTYPE html>${strHTML}`;
LODOPObj.PRINT_INIT(`printDomId_${printIndex}`);
// window.LODOP.PRINT_INITA(1, 1, 770, 660, '测试预览功能');
LODOPObj.ADD_PRINT_HTM(0, 0, `${wide}cm`, `${high}cm`, strHTML); // 打印的宽高和 html
LODOPObj.ADD_PRINT_HTM(0, 0, `${wide + 0.1}cm`, `${high + 0.1}cm`, strHTML); // 打印的宽高和 html
LODOPObj.SET_PRINT_PAGESIZE(2, 0, 0); // 纵向打印
LODOPObj.PREVIEW();
};
printOneByOne = () => { // 按队列打印
const { configAll, viewData, printIndex } = this.state;
if (viewData && viewData.length) {
this.printOne();
} else {
console.error('暂无数据无法打印');
}
const length = viewData.length;
const LODOPObj = window.LODOP;
// LODOPObj.PRINT_SETUP();
const { length } = viewData;
LODOPObj.On_Return = (TaskId, Value) => {
console.log(TaskId, Value === 1 || Value === '1' ? '已发出实际打印命令!' : '放弃打印!');
this.setState({
......@@ -142,11 +113,24 @@ export default class ViewPrint extends Component {
}, () => {
if (this.state.printIndex < length) {
this.printOne();
} else {
this.setState({
loading: false,
});
}
});
};
};
printOneByOne = () => { // 按队列打印
const { configAll, viewData, printIndex } = this.state;
if (viewData && viewData.length) {
this.printOne();
} else {
console.error('暂无数据无法打印');
}
};
printByLodop = () => {
if (!window.LODOP || !window.LODOP.PRINT_INIT) {
console.error('打印服务未启动');
......@@ -165,8 +149,8 @@ export default class ViewPrint extends Component {
};
render() {
const { configAll, viewData, showWindowPrint, minHeight } = this.state;
if (!viewData || !minHeight) {
const { configAll, viewData, showWindowPrint, loading } = this.state;
if (!viewData) {
return null;
}
if (!configAll.backgroundUrl) {
......@@ -182,7 +166,10 @@ export default class ViewPrint extends Component {
<Fragment>
<Shell styleShell={{ marginTop: '0', marginBottom: '20px' }}>
<div style={{ height: '54px', padding: '12px 0 12px 12px' }}>
<ButtonDiy name={'打印'} handleClick={this.printByLodop}/>
<ButtonDiy name={'打印'}
handleClick={this.printByLodop}
loading={loading}
/>
<ButtonDiy
name={'返回'}
handleClick={() => {
......@@ -241,8 +228,6 @@ export default class ViewPrint extends Component {
draggable={false}
alt={'背景图'}
style={{
height: 'auto',
overflow: 'auto',
zIndex: 1,
...imageStyleAll,
}}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论