|
@@ -168,3 +168,90 @@ export const hdPrint = function (printerType, type, url, params, fileName, callb
|
|
|
callback()
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+/*
|
|
|
+ *printerType: 打印机类型
|
|
|
+ *type: 打印预览,打印,导出
|
|
|
+ *url: 数据请求接口
|
|
|
+ *params: 请求参数
|
|
|
+ *fileName: 导出文件名称
|
|
|
+ *callback: 回调函数
|
|
|
+*/
|
|
|
+export const newHdPrint = function (printerType, type, url, params, fileName, callback) {
|
|
|
+ // 打印时需要传打印机类型
|
|
|
+ if (type !== 'export') {
|
|
|
+ params.type = printerType
|
|
|
+ }
|
|
|
+ // 阵式预览和喷墨预览一样
|
|
|
+ if (type == 'preview' && printerType == 'NEEDLE') {
|
|
|
+ params.type = 'INK'
|
|
|
+ }
|
|
|
+ url(params).then(res => {
|
|
|
+ if (res.type == 'application/json') {
|
|
|
+ var reader = new FileReader()
|
|
|
+ reader.addEventListener('loadend', function () {
|
|
|
+ const obj = JSON.parse(reader.result)
|
|
|
+ notification.error({
|
|
|
+ message: '提示',
|
|
|
+ description: obj.message
|
|
|
+ })
|
|
|
+ })
|
|
|
+ reader.readAsText(res)
|
|
|
+ } else {
|
|
|
+ if (type == 'export') { // 导出
|
|
|
+ downloadExcel(res, fileName)
|
|
|
+ } else { // 打印
|
|
|
+ newJGPrint(res, type, printerType)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ callback()
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+// 打印控件
|
|
|
+export const newJGPrint = function (data, type, printerType) {
|
|
|
+ if (!data) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 针式打印
|
|
|
+ if (printerType == 'NEEDLE' && type=="print") {
|
|
|
+ const LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'))
|
|
|
+ if (!LODOP) {
|
|
|
+ confirm({
|
|
|
+ title: '提示?',
|
|
|
+ content: h => <div>打印控件未安装,请先下载并安装。安装完成后,刷新页面即可打印。</div>,
|
|
|
+ okText: '立即下载',
|
|
|
+ okType: 'danger',
|
|
|
+ cancelText: '暂不打印',
|
|
|
+ onOk () {
|
|
|
+ window.open('http://www.lodop.net/demolist/CLodop_Setup_for_Win32NT.zip')
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ const dlen = data.data.length
|
|
|
+ if(dlen){
|
|
|
+ LODOP.SET_SHOW_MODE("HIDE_PBUTTIN_PREVIEW",1);//隐藏打印按钮
|
|
|
+ // LODOP.SET_SHOW_MODE("HIDE_SBUTTIN_PREVIEW",1);//隐藏设置按钮
|
|
|
+ LODOP.SET_SHOW_MODE('HIDE_PAPER_BOARD', 1) // 隐藏底图上有模拟走纸板的条纹线
|
|
|
+ LODOP.SET_PRINT_STYLEA(0,"PDFScalMode",1);
|
|
|
+ // 开始打印
|
|
|
+ for(let i=0;i<dlen;i++){
|
|
|
+ LODOP.ADD_PRINT_PDF(0, 0, '100%', '100%', data.data[i])
|
|
|
+ LODOP.SET_PRINT_PAGESIZE(3, 2090, 0, '')
|
|
|
+ LODOP.PRINT()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 喷墨打印
|
|
|
+ const url = window.URL.createObjectURL(new Blob([data], { type: 'application/pdf' }))
|
|
|
+ document.getElementById('print').innerHTML = '<iframe id="printfsqd" name="printfsqd" src="' + url + '" hidden></iframe>'
|
|
|
+ if (type == 'preview') { // 预览
|
|
|
+ window.open(url)
|
|
|
+ } else if (type == 'print') { // 打印
|
|
|
+ window.frames['printfsqd'].focus()
|
|
|
+ window.frames['printfsqd'].print()
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|