wui-print
Version:
前端打印插件,包含打印设计器、打印表单、打印API
55 lines (54 loc) • 2.17 kB
JavaScript
import { deepCopy } from "../print-designer-utils";
export default ({ printData = {}, layoutConfig } = {}) => {
const createBarcodeJsString = (componentItem) => {
let componentItemProps = deepCopy(componentItem.props);
let notFormatKeyList = ["field"];
Object.keys(componentItemProps).forEach((key, index) => {
if (notFormatKeyList.indexOf(key) >= 0) {
return;
}
if (typeof componentItemProps[key] == "string") {
componentItemProps[key] = `"${componentItemProps[key]}"`;
}
});
let nowBarcodeValue = printData[componentItemProps.field];
if (!nowBarcodeValue && nowBarcodeValue !== 0) {
return "";
}
let barcodeJsString = `JsBarcode('[name="barcode_${componentItem.id}"]', ${printData[componentItemProps.field]},{
format: ${componentItemProps.format},
lineColor:${componentItemProps.lineColor},
background: ${componentItemProps.background},
width: ${componentItemProps.width},
height: ${componentItemProps.height},
displayValue: ${componentItemProps.displayValue},
fontSize: ${componentItemProps.fontSize},
margin: ${componentItemProps.margin},
textAlign: ${componentItemProps.textAlign},
textPosition: ${componentItemProps.textPosition}
});\n`;
return barcodeJsString;
};
const creatQrcodeJsString = (componentItem) => {
let componentItemProps = deepCopy(componentItem.props);
let notFormatKeyList = ["field"];
Object.keys(componentItemProps).forEach((key, index) => {
if (notFormatKeyList.indexOf(key) >= 0) {
return;
}
if (typeof componentItemProps[key] == "string") {
componentItemProps[key] = `"${componentItemProps[key]}"`;
}
});
let qrcodeJsString = `createQRCode('qrcode_${componentItem.id}',{
text: "${printData[componentItemProps.field]}",
width: ${componentItemProps.width},
height: ${componentItemProps.height}
});\n`;
return qrcodeJsString;
};
return {
createBarcodeJsString,
creatQrcodeJsString
};
};