lilei il y a 3 ans
Parent
commit
5d198e7257
1 fichiers modifiés avec 16 ajouts et 12 suppressions
  1. 16 12
      src/libs/JGPrint.js

+ 16 - 12
src/libs/JGPrint.js

@@ -10,6 +10,7 @@ export const JGPrint = function (data, type, printerType) {
   // 针式打印
   if (printerType == 'NEEDLE') {
     const LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'))
+    console.log(LODOP,'LODOP')
     if (!LODOP) {
       confirm({
         title: '提示?',
@@ -40,11 +41,7 @@ export const JGPrint = function (data, type, printerType) {
     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)
-      const LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'))
-      LODOP.ADD_PRINT_PDF(0, 0, '100%', '100%', data)
-      LODOP.SET_PRINT_STYLEA(0, 'PDFScalMode', 1)
-      LODOP.SET_PRINT_PAGESIZE(3, 0, 0, '')
+      window.open(url)
     } else if (type == 'print') { //  打印
       window.frames['printfsqd'].focus()
       window.frames['printfsqd'].print()
@@ -92,15 +89,22 @@ export const demoDownloadPDF = function (url) {
 // 导出下载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()
+  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对象
+  }
 }
 
 /*