1
This commit is contained in:
parent
cf39d2380d
commit
45923ec6cb
@ -120,6 +120,7 @@
|
||||
<span class="progress-tip">进度: {{ completedPrintCount }} / {{ selectionRows.length }}</span>
|
||||
<div>
|
||||
<el-button @click="visible = false">关闭</el-button>
|
||||
<el-button type="success" plain :disabled="!previewInfo.width" @click="browserPrint">浏览器打印</el-button>
|
||||
<el-button type="primary" :loading="printing" @click="doPrint">
|
||||
{{ currentPrintIndex < selectionRows.length - 1 ? '打印并切换下一个' : '打印当前单据' }}
|
||||
</el-button>
|
||||
@ -579,6 +580,36 @@ async function doPrint() {
|
||||
printing.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function browserPrint() {
|
||||
const previewEl = document.querySelector('.preview-page') as HTMLElement | null
|
||||
if (!previewEl) {
|
||||
ElMessage.warning('暂无预览内容可打印')
|
||||
return
|
||||
}
|
||||
const printWindow = window.open('', '_blank', 'width=800,height=600')
|
||||
if (!printWindow) {
|
||||
ElMessage.warning('请允许浏览器弹出窗口')
|
||||
return
|
||||
}
|
||||
const styles = document.querySelectorAll('style, link[rel="stylesheet"]')
|
||||
let styleHtml = ''
|
||||
styles.forEach(s => { styleHtml += s.outerHTML })
|
||||
|
||||
printWindow.document.write(`
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head><meta charset="utf-8"><title>打印预览</title>${styleHtml}</head>
|
||||
<body style="margin:0;display:flex;justify-content:center;">
|
||||
${previewEl.outerHTML}
|
||||
</body>
|
||||
</html>
|
||||
`)
|
||||
printWindow.document.close()
|
||||
printWindow.focus()
|
||||
printWindow.print()
|
||||
printWindow.close()
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user