Lodophtml
var CreatedOKLodop7766 = null export function needCLodop() { try { var ua = navigator.userAgent if (ua.match(/Windows\sPhone/i) != null) return true if (ua.match(/iPhone|iPod/i) != null) return true if (ua.match(/Android/i) != null) return true if (ua.match(/Edge\D?\d+/i) != null) return true var verTrident = ua.match(/Trident\D?\d+/i) var verIE = ua.match(/MSIE\D?\d+/i) var verOPR = ua.match(/OPR\D?\d+/i) var verFF = ua.match(/Firefox\D?\d+/i) var x64 = ua.match(/x64/i) if (verTrident == null && verIE == null && x64 !== null) return true else if (verFF !== null) { verFF = verFF[0].match(/\d+/) if (verFF[0] >= 41 || x64 !== null) return true } else if (verOPR !== null) { verOPR = verOPR[0].match(/\d+/) if (verOPR[0] >= 32) return true } else if (verTrident == null && verIE == null) { var verChrome = ua.match(/Chrome\D?\d+/i) if (verChrome !== null) { verChrome = verChrome[0].match(/\d+/) if (verChrome[0] >= 41) return true } } return false } catch (err) { return true } } //====頁面引用CLodop雲打印必須的JS文件:==== if (needCLodop()) { var head = document.head || document.getElementsByTagName('head')[0] || document.documentElement var oscript = document.createElement('script') oscript.src = 'http://localhost:8000/CLodopfuncs.js?priority=1' head.insertBefore(oscript, head.firstChild) //引用雙端口(8000和18000)避免其中某個被佔用: oscript = document.createElement('script') oscript.src = 'http://localhost:18000/CLodopfuncs.js?priority=0' head.insertBefore(oscript, head.firstChild) } //====獲取LODOP對象的主過程:==== export function getLodop(oOBJECT, oEMBED) { var strHtmInstall = "<br><font color='#FF00FF'>打印控件未安裝!點擊這裏<a href='install_lodop32.exe' target='_self'>執行安裝</a>,安裝後請刷新頁面或從新進入。</font>" var strHtmUpdate = "<br><font color='#FF00FF'>打印控件須要升級!點擊這裏<a href='install_lodop32.exe' target='_self'>執行升級</a>,升級後請從新進入。</font>" var strHtm64_Install = "<br><font color='#FF00FF'>打印控件未安裝!點擊這裏<a href='install_lodop64.exe' target='_self'>執行安裝</a>,安裝後請刷新頁面或從新進入。</font>" var strHtm64_Update = "<br><font color='#FF00FF'>打印控件須要升級!點擊這裏<a href='install_lodop64.exe' target='_self'>執行升級</a>,升級後請從新進入。</font>" var strHtmFireFox = "<br><br><font color='#FF00FF'>(注意:如曾安裝過Lodop舊版附件npActiveXPLugin,請在【工具】->【附加組件】->【擴展】中先卸它)</font>" var strHtmChrome = "<br><br><font color='#FF00FF'>(若是此前正常,僅因瀏覽器升級或重安裝而出問題,需從新執行以上安裝)</font>" var strCLodopInstall = "<br><font color='#FF00FF'>CLodop雲打印服務(localhost本地)未安裝啓動!點擊這裏<a href='http://www.lodop.net/download/CLodop_Setup_for_Win32NT_https_3.046Extend.zip' download target='_self'>執行安裝</a>,安裝後請刷新頁面。</font>" var strCLodopUpdate = "<br><font color='#FF00FF'>CLodop雲打印服務需升級!點擊這裏<a href='http://www.lodop.net/download/CLodop_Setup_for_Win32NT_https_3.046Extend.zip' download target='_self'>執行升級</a>,升級後請刷新頁面。</font>" var LODOP try { var isIE = navigator.userAgent.indexOf('MSIE') >= 0 || navigator.userAgent.indexOf('Trident') >= 0 if (needCLodop()) { try { LODOP = getCLodop() } catch (err) {} if (!LODOP && document.readyState !== 'complete') { alert('C-Lodop沒準備好,請稍後再試!') return } if (!LODOP) { if (isIE) document.write(strCLodopInstall) else document.body.innerHTML = strCLodopInstall + document.body.innerHTML return } else { if (CLODOP.CVERSION < '3.0.4.3') { if (isIE) document.write(strCLodopUpdate) else document.body.innerHTML = strCLodopUpdate + document.body.innerHTML } if (oEMBED && oEMBED.parentNode) oEMBED.parentNode.removeChild(oEMBED) if (oOBJECT && oOBJECT.parentNode) oOBJECT.parentNode.removeChild(oOBJECT) } } else { var is64IE = isIE && navigator.userAgent.indexOf('x64') >= 0 //=====若是頁面有Lodop就直接使用,沒有則新建:========== if (oOBJECT != undefined || oEMBED != undefined) { if (isIE) LODOP = oOBJECT else LODOP = oEMBED } else if (CreatedOKLodop7766 == null) { LODOP = document.createElement('object') LODOP.setAttribute('width', 0) LODOP.setAttribute('height', 0) LODOP.setAttribute( 'style', 'position:absolute;left:0px;top:-100px;width:0px;height:0px;', ) if (isIE) LODOP.setAttribute( 'classid', 'clsid:2105C259-1E0C-4534-8141-A753534CB4CA', ) else LODOP.setAttribute('type', 'application/x-print-lodop') document.documentElement.appendChild(LODOP) CreatedOKLodop7766 = LODOP } else LODOP = CreatedOKLodop7766 //=====Lodop插件未安裝時提示下載地址:========== if (LODOP == null || typeof LODOP.VERSION == 'undefined') { if (navigator.userAgent.indexOf('Chrome') >= 0) document.body.innerHTML = strHtmChrome + document.body.innerHTML if (navigator.userAgent.indexOf('Firefox') >= 0) document.body.innerHTML = strHtmFireFox + document.body.innerHTML if (is64IE) document.write(strHtm64_Install) else if (isIE) document.write(strHtmInstall) else document.body.innerHTML = strHtmInstall + document.body.innerHTML return LODOP } } if (LODOP.VERSION < '6.2.2.3') { if (!needCLodop()) { if (is64IE) document.write(strHtm64_Update) else if (isIE) document.write(strHtmUpdate) else document.body.innerHTML = strHtmUpdate + document.body.innerHTML } return LODOP } //===以下空白位置適合調用統一功能(如註冊語句、語言選擇等):=== //=========================================================== return LODOP } catch (err) { alert('getLodop出錯:' + err) } }
import { getLodop } from '@t/lodop' //這塊就是引用的上面一大坨暴露出來的方法嘍 const PrintAccount = (qrTitle, codetype, url, code) => { let qrAccount = `${url}/#/?type=${codetype}&code=${code}` // 調用打印對象 LODOP = getLodop() // 打印頁面配置 LODOP.SET_PRINT_MODE('PRINT_NOCOLLATE', 1) LODOP.SET_PRINT_PAGESIZE(3, '5.7cm', '2cm', 2) // 條碼內容 LODOP.ADD_PRINT_TEXT(3, 32, 127, 20, qrTitle) LODOP.SET_PRINT_STYLEA(0, 'FontSize', 15) LODOP.ADD_PRINT_BARCODE(26, 15, 170, 147, 'QRCode', qrAccount) // LODOP.ADD_PRINT_TEXT(159, 11, 163, 42, qrAccount) // LODOP.SET_PRINT_STYLEA(0, 'FontSize', 11) } export { PrintAccount }
import { PrintAccount } from '@t/doPrint' import { getLodop } from '@t/lodop'
<div class="selectBtn"> <el-button class="form_button" type="primary" @click="multipPrint" icon="el-icon-printer">批量打印</el-button> <el-button class="form_button" type="primary" @click="singlePrint" icon="el-icon-printer">單個打印</el-button> </div>
// 多選打印 multipPrint() { if (this.multipkeSelect.length <= 1) { this.$notify({ title: '警告', message: '請至少選擇兩項進行打印', type: 'warning', }) return } for (let i = 0; i < this.multipkeSelect.length; i++) { PrintAccount( '商品包裝碼', '3', Connect.codeUrl, this.multipkeSelect[i].packingCode, ) LODOP.PRINT() // LODOP.PREVIEW() } }, singlePrint() { if (this.multipkeSelect.length != 1) { this.$notify({ title: '警告', message: '請選擇且僅選擇一項進行打印', type: 'warning', }) return } PrintAccount( '商品包裝碼', '3', Connect.codeUrl, this.multipkeSelect[0].packingCode, ) LODOP.PRINT() // LODOP.PREVIEW() },