123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- 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 => <div>打印控件未安装,请先下载并安装。安装完成后,刷新页面即可打印。</div>,
- 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_HTM(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()
- }
-
- export const demoGetBASE64 = function (dataArray) {
- var digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
- var strData = ''
- for (var i = 0, ii = dataArray.length; i < ii; i += 3) {
- if (isNaN(dataArray[i])) break
- var b1 = dataArray[i] & 0xFF; var b2 = dataArray[i + 1] & 0xFF; var b3 = dataArray[i + 2] & 0xFF
- var d1 = b1 >> 2; var d2 = ((b1 & 3) << 4) | (b2 >> 4)
- var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64
- var d4 = i + 2 < ii ? (b3 & 0x3F) : 64
- strData += digits.substring(d1, d1 + 1) + digits.substring(d2, d2 + 1) + digits.substring(d3, d3 + 1) + digits.substring(d4, d4 + 1)
- }
- return strData
- }
- // 导出下载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对象
- }
- }
- /*
- *printerType: 打印机类型
- *type: 打印预览,打印,导出
- *url: 数据请求接口
- *params: 请求参数
- *fileName: 导出文件名称
- *callback: 回调函数
- */
- export const hdPrint = function (printerType, type, url, params, fileName, callback) {
- // 打印时需要传打印机类型
- if (type !== 'export') {
- params.type = printerType
- }
- // 针式预览和喷墨预览一样
- if (type == 'preview') {
- // params.type = 'INK'
- // params.printType = 'INK'
- // printerType = 'INK'
- }
- url(params).then(res => {
- console.log(res, type, printerType)
- 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 { // 打印
- jGPrint(res, type, printerType)
- }
- }
- callback()
- })
- }
- // pdf blob 转 base64
- export const blobToBaseByPdf = function(data,callback){
- const reader = new FileReader()
- reader.readAsDataURL(new Blob([data], { type: 'application/pdf' }))
- reader.addEventListener('load', () => {
- callback(reader.result)
- })
- }
- // 打印控件
- export const jGPrint = function (data, type, printerType) {
- if (!data) {
- return
- }
- // 针式打印
- if (printerType == 'NEEDLE') {
- const LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'))
- if (!LODOP) {
- confirm({
- title: '提示?',
- content: h => <div>打印控件未安装,请先下载并安装。安装完成后,刷新页面即可打印。</div>,
- 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) // 可使输出以纸张边缘为基点
- if (type == 'preview') { // 预览
- // blobToBaseByPdf(data,function(result){
- // LODOP.ADD_PRINT_PDF(0, 0, '100%', '100%', result.split('base64,')[1])
- // LODOP.SET_PRINT_PAGESIZE(3,2090,65,"");
- // LODOP.PREVIEW()
- // })
- if(data.data.length > 1){
- LODOP.SET_SHOW_MODE("HIDE_PBUTTIN_PREVIEW",1);//隐藏打印按钮
- }
- LODOP.ADD_PRINT_PDF(0, 0, '100%', '100%', data.data[0])
- LODOP.SET_PRINT_PAGESIZE(3,2090,40,"");
- LODOP.PREVIEW()
- } else if (type == 'print') { // 打印
- const dlen = data.data.length
- for(let i=0;i<dlen;i++){
- LODOP.PRINT_INIT("")
- LODOP.ADD_PRINT_PDF(0, 0, '100%', '100%', data.data[i])
- LODOP.SET_PRINT_PAGESIZE(3, 2090, 40, '')
- 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()
- }
- }
- }
|