JGPrint.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import confirm from 'ant-design-vue/es/modal/confirm'
  2. import notification from 'ant-design-vue/es/notification'
  3. import { getLodop } from '@/libs/LodopFuncs'
  4. import moment from 'moment'
  5. // 打印页签,支持批量打印
  6. export const JGPrintTag = function (html, width, height, data) {
  7. const LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'))
  8. if (!LODOP) {
  9. confirm({
  10. title: '提示?',
  11. content: h => <div>打印控件未安装,请先下载并安装。安装完成后,刷新页面即可打印。</div>,
  12. okText: '立即下载',
  13. okType: 'danger',
  14. cancelText: '暂不打印',
  15. onOk () {
  16. var agent = navigator.userAgent.toLowerCase();
  17. if (agent.indexOf("win32") >= 0 || agent.indexOf("wow32") >= 0) {
  18. window.open('http://www.lodop.net/demolist/CLodop_Setup_for_Win32NT.zip')
  19. }else if (agent.indexOf("win64") >= 0 || agent.indexOf("wow64") >= 0) {
  20. window.open('http://www.lodop.net/download/CLodop_Setup_for_Win64NT_4.155EN.zip')
  21. }
  22. }
  23. })
  24. return
  25. }
  26. LODOP.PRINT_INIT("")
  27. LODOP.SET_SHOW_MODE('HIDE_PAPER_BOARD', 1) // 隐藏底图上有模拟走纸板的条纹线
  28. LODOP.SET_PRINT_MODE('POS_BASEON_PAPER', true) // 可使输出以纸张边缘为基点
  29. LODOP.ADD_PRINT_HTML(0, 0, '100%', '100%', html)
  30. LODOP.ADD_PRINT_BARCODE('36%','65%',90,90,"QRCode",data.qrCodeContent)
  31. LODOP.SET_PRINT_STYLEA(0,"QRCodeVersion",5)
  32. // LODOP.SET_PRINT_STYLEA(0,"QRCodeErrorLevel",'H')
  33. LODOP.SET_PRINT_COPIES(data.printQty)// 指定份数
  34. LODOP.SET_PRINT_PAGESIZE(1, width, height)
  35. LODOP.PRINT()
  36. }
  37. // 导出下载excel
  38. export const downloadExcel = function (data, fileName) {
  39. if (!data) { return }
  40. const a = moment().format('YYYYMMDDHHmmss')
  41. const fname = fileName + a
  42. const blob = new Blob([data], { type: 'application/vnd.ms-excel' })
  43. if (window.navigator && window.navigator.msSaveOrOpenBlob) {
  44. navigator.msSaveBlob(blob, fname + '.xlsx')
  45. } else {
  46. const link = document.createElement('a')
  47. link.style.display = 'none'
  48. var href = URL.createObjectURL(blob)
  49. link.href = href
  50. link.setAttribute('download', fname + '.xlsx')
  51. document.body.appendChild(link)
  52. link.click()
  53. document.body.removeChild(link)
  54. window.URL.revokeObjectURL(href) // 释放掉blob对象
  55. }
  56. }
  57. // 打印控件
  58. export const jGPrint = function (data, type) {
  59. if (!data) {
  60. return
  61. }
  62. const LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'))
  63. if (!LODOP) {
  64. confirm({
  65. title: '提示?',
  66. content: h => <div>打印控件未安装,请先下载并安装。安装完成后,刷新页面即可打印。</div>,
  67. okText: '立即下载',
  68. okType: 'danger',
  69. cancelText: '暂不打印',
  70. onOk () {
  71. var agent = navigator.userAgent.toLowerCase();
  72. if (agent.indexOf("win32") >= 0 || agent.indexOf("wow32") >= 0) {
  73. window.open('http://www.lodop.net/demolist/CLodop_Setup_for_Win32NT.zip')
  74. }else if (agent.indexOf("win64") >= 0 || agent.indexOf("wow64") >= 0) {
  75. window.open('http://www.lodop.net/download/CLodop_Setup_for_Win64NT_4.155EN.zip')
  76. }
  77. }
  78. })
  79. return
  80. }
  81. LODOP.SET_SHOW_MODE('HIDE_PAPER_BOARD', 1) // 隐藏底图上有模拟走纸板的条纹线
  82. // LODOP.SET_PRINT_MODE('POS_BASEON_PAPER', true) // 可使输出以纸张边缘为基点
  83. // LODOP.SET_PRINT_STYLEA(0,"TableRowThickNess",50)
  84. LODOP.ADD_PRINT_HTM(10, 2, '98%', '100%', data)
  85. LODOP.SET_PRINT_PAGESIZE(1,2100,0,"");
  86. if (type == 'preview') { // 预览
  87. LODOP.PREVIEW()
  88. } else if (type == 'print') { // 打印
  89. LODOP.PRINT()
  90. }
  91. }