import confirm from 'ant-design-vue/es/modal/confirm'
import notification from 'ant-design-vue/es/notification'
import { getLodop } from '@/libs/LodopFuncs'
import moment from 'moment'
// 打印页签,支持批量打印
export const JGPrintTag = function (html, width, height, data) {
const LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'))
if (!LODOP) {
confirm({
title: '提示?',
content: h =>
打印控件未安装,请先下载并安装。安装完成后,刷新页面即可打印。
,
okText: '立即下载',
okType: 'danger',
cancelText: '暂不打印',
onOk () {
var agent = navigator.userAgent.toLowerCase();
if (agent.indexOf("win32") >= 0 || agent.indexOf("wow32") >= 0) {
window.open('http://www.lodop.net/demolist/CLodop_Setup_for_Win32NT.zip')
}else if (agent.indexOf("win64") >= 0 || agent.indexOf("wow64") >= 0) {
window.open('http://www.lodop.net/download/CLodop_Setup_for_Win64NT_4.155EN.zip')
}
}
})
return
}
LODOP.PRINT_INIT("")
LODOP.SET_SHOW_MODE('HIDE_PAPER_BOARD', 1) // 隐藏底图上有模拟走纸板的条纹线
LODOP.SET_PRINT_MODE('POS_BASEON_PAPER', true) // 可使输出以纸张边缘为基点
LODOP.ADD_PRINT_HTML(0, 0, '100%', '100%', html)
LODOP.ADD_PRINT_BARCODE('36%','65%',90,90,"QRCode",data.qrCodeContent)
LODOP.SET_PRINT_STYLEA(0,"QRCodeVersion",5)
// LODOP.SET_PRINT_STYLEA(0,"QRCodeErrorLevel",'H')
LODOP.SET_PRINT_COPIES(data.printQty)// 指定份数
LODOP.SET_PRINT_PAGESIZE(1, width, height)
LODOP.PRINT()
}
// 导出下载excel
export const downloadExcel = function (data, fileName) {
if (!data) { return }
const a = moment().format('YYYYMMDDHHmmss')
const fname = fileName + a
const blob = new Blob([data], { type: 'application/vnd.ms-excel' })
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
navigator.msSaveBlob(blob, fname + '.xlsx')
} else {
const link = document.createElement('a')
link.style.display = 'none'
var href = URL.createObjectURL(blob)
link.href = href
link.setAttribute('download', fname + '.xlsx')
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
window.URL.revokeObjectURL(href) // 释放掉blob对象
}
}
// 打印控件
export const jGPrint = function (data, type) {
if (!data) {
return
}
const LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'))
if (!LODOP) {
confirm({
title: '提示?',
content: h => 打印控件未安装,请先下载并安装。安装完成后,刷新页面即可打印。
,
okText: '立即下载',
okType: 'danger',
cancelText: '暂不打印',
onOk () {
var agent = navigator.userAgent.toLowerCase();
if (agent.indexOf("win32") >= 0 || agent.indexOf("wow32") >= 0) {
window.open('http://www.lodop.net/demolist/CLodop_Setup_for_Win32NT.zip')
}else if (agent.indexOf("win64") >= 0 || agent.indexOf("wow64") >= 0) {
window.open('http://www.lodop.net/download/CLodop_Setup_for_Win64NT_4.155EN.zip')
}
}
})
return
}
LODOP.SET_SHOW_MODE('HIDE_PAPER_BOARD', 1) // 隐藏底图上有模拟走纸板的条纹线
// LODOP.SET_PRINT_MODE('POS_BASEON_PAPER', true) // 可使输出以纸张边缘为基点
// LODOP.SET_PRINT_STYLEA(0,"TableRowThickNess",50)
LODOP.ADD_PRINT_HTM(10, 2, '98%', '100%', data)
LODOP.SET_PRINT_PAGESIZE(1,2100,0,"");
if (type == 'preview') { // 预览
LODOP.PREVIEW()
} else if (type == 'print') { // 打印
LODOP.PRINT()
}
}