|
@@ -3,14 +3,13 @@ import notification from 'ant-design-vue/es/notification'
|
|
|
import { getLodop } from '@/libs/LodopFuncs'
|
|
|
import moment from 'moment'
|
|
|
// 打印控件
|
|
|
-export const JGPrint = function(data, type, printerType){
|
|
|
+export const JGPrint = function (data, type, printerType) {
|
|
|
if (!data) {
|
|
|
return
|
|
|
}
|
|
|
// 针式打印
|
|
|
if (printerType == 'NEEDLE') {
|
|
|
const LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'))
|
|
|
- console.log(LODOP)
|
|
|
if (!LODOP) {
|
|
|
confirm({
|
|
|
title: '提示?',
|
|
@@ -24,13 +23,17 @@ export const JGPrint = function(data, type, printerType){
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
+ console.log('+++data', data)
|
|
|
const rx = /<body[^>]*>([\s\S]+?)<\/body>/i///
|
|
|
let m = rx.exec(data)
|
|
|
if (m) m = m[1]
|
|
|
LODOP.SET_SHOW_MODE('HIDE_PAPER_BOARD', 1) // 隐藏底图上有模拟走纸板的条纹线
|
|
|
- LODOP.SET_PRINT_PAGESIZE(3, '2140', '60', '') // 这里3表示纵向打印且纸高“按内容的高度”;2140表示纸宽214.0mm;45表示页底空白4.5mm
|
|
|
- LODOP.ADD_PRINT_HTM("0","0","RightMargin:0.5cm","BottomMargin:0.5cm",m)
|
|
|
+ LODOP.SET_PRINT_PAGESIZE(3, '2100', '60', '') // 这里3表示纵向打印且纸高“按内容的高度”;2140表示纸宽214.0mm;60表示页底空白6.0mm
|
|
|
+ LODOP.ADD_PRINT_HTM('0', '0', 'RightMargin:0.1cm', 'BottomMargin:0.1cm', m)
|
|
|
// LODOP.ADD_PRINT_TABLE(0, 0, '100%', '100%', m)
|
|
|
+ // LODOP.ADD_PRINT_PDF(0, 0, '100%', '100%', data)
|
|
|
+ // LODOP.SET_PRINT_STYLEA(0, 'PDFScalMode', 1)
|
|
|
+ // LODOP.SET_PRINT_PAGESIZE(3, 0, 0, '')
|
|
|
if (type == 'preview') {
|
|
|
LODOP.PREVIEW()
|
|
|
}
|
|
@@ -50,18 +53,55 @@ export const JGPrint = function(data, type, printerType){
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+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
|
|
|
+}
|
|
|
+// 下载pdf
|
|
|
+export const demoDownloadPDF = function (url) {
|
|
|
+ if (!(/^https?:/i.test(url))) return
|
|
|
+ if (window.XMLHttpRequest) var xhr = new XMLHttpRequest(); else var xhr = new ActiveXObject('MSXML2.XMLHTTP')
|
|
|
+ xhr.open('GET', url, false) // 同步方式
|
|
|
+ if (xhr.overrideMimeType) {
|
|
|
+ try {
|
|
|
+ xhr.responseType = 'arraybuffer'
|
|
|
+ var arrybuffer = true
|
|
|
+ } catch (err) {
|
|
|
+ xhr.overrideMimeType('text/plain; charset=x-user-defined')
|
|
|
+ }
|
|
|
+ }
|
|
|
+ xhr.send(null)
|
|
|
+ var data = xhr.response || xhr.responseBody
|
|
|
+ if (typeof Uint8Array !== 'undefined') {
|
|
|
+ if (arrybuffer) var dataArray = new Uint8Array(data); else {
|
|
|
+ var dataArray = new Uint8Array(data.length)
|
|
|
+ for (var i = 0; i < dataArray.length; i++) { dataArray[i] = data.charCodeAt(i) }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return demoGetBASE64(dataArray)
|
|
|
+}
|
|
|
+
|
|
|
// 导出下载excel
|
|
|
-export const downloadExcel = function (data,fileName){
|
|
|
- if (!data) { return }
|
|
|
- const url = window.URL.createObjectURL(new Blob([data]))
|
|
|
- const link = document.createElement('a')
|
|
|
- link.style.display = 'none'
|
|
|
- link.href = url
|
|
|
- const a = moment().format('YYYYMMDDHHmmss')
|
|
|
- const fname = fileName + a
|
|
|
- link.setAttribute('download', fname + '.xlsx')
|
|
|
- document.body.appendChild(link)
|
|
|
- link.click()
|
|
|
+export const downloadExcel = function (data, fileName) {
|
|
|
+ if (!data) { return }
|
|
|
+ const url = window.URL.createObjectURL(new Blob([data]))
|
|
|
+ const link = document.createElement('a')
|
|
|
+ link.style.display = 'none'
|
|
|
+ link.href = url
|
|
|
+ const a = moment().format('YYYYMMDDHHmmss')
|
|
|
+ const fname = fileName + a
|
|
|
+ link.setAttribute('download', fname + '.xlsx')
|
|
|
+ document.body.appendChild(link)
|
|
|
+ link.click()
|
|
|
}
|
|
|
|
|
|
/*
|
|
@@ -72,9 +112,9 @@ export const downloadExcel = function (data,fileName){
|
|
|
*fileName: 导出文件名称
|
|
|
*callback: 回调函数
|
|
|
*/
|
|
|
-export const hdPrint = function (printerType,type,url,params,fileName,callback){
|
|
|
+export const hdPrint = function (printerType, type, url, params, fileName, callback) {
|
|
|
// 打印时需要传打印机类型
|
|
|
- if(type !== 'export'){
|
|
|
+ if (type !== 'export') {
|
|
|
params.type = printerType
|
|
|
}
|
|
|
url(params).then(res => {
|
|
@@ -97,4 +137,4 @@ export const hdPrint = function (printerType,type,url,params,fileName,callback){
|
|
|
}
|
|
|
callback()
|
|
|
})
|
|
|
-}
|
|
|
+}
|