createPrintPage(data) {
let printStr = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><style>th,td{padding:2px 10px;font-size:14px} .next-table{margin:25px 0 0}</style></head><body style="padding:15px">',
content = `<table border="1" style="border-collapse: collapse;100%"><tr><td>操作时间</td><td>查询</td><td>操作用户</td><td>备注</td></tr>`
data.forEach((item, i) => {
content += `<tr>
<td>${parseTime(item.exec_time, '{y}-{m}-{d} {h}:{i}:{s}')}</td>
<td>${item.exec_type}</td>
<td>${item.exec_user}</td>
<td>${item.remark}</td>
</tr>`
// 每页40条数据
if (i > 0 && i % 40 === 0) {
content += '</table>'
content += '<div style="page-break-after:always"></div>' // 分页
content += `<table class="next-table" border="1" style="border-collapse: collapse;100%"><tr><td>操作时间</td><td>查询</td><td>操作用户</td><td>备注</td></tr>`
}
})
printStr = printStr + content + '</table></body></html>'
let printWindow = window.open("Print.html", "print")
printWindow.document.write(printStr)
printWindow.document.close()
printWindow.print()
}
资料
JS 使用 window对象的print方法实现分页打印