feat:增加打印功能

This commit is contained in:
黄云飞
2021-11-15 19:47:36 +08:00
parent 9462ba06fb
commit 0df6619cc3
6 changed files with 53 additions and 15 deletions
+6
View File
@@ -0,0 +1,6 @@
import { ZERO } from "../dataset/constant/Common"
export function writeText(text: string) {
if (!text) return
window.navigator.clipboard.writeText(text.replaceAll(ZERO, `\n`))
}
-7
View File
@@ -1,5 +1,3 @@
import { ZERO } from "../dataset/constant/Common"
export function debounce(func: Function, delay: number) {
let timer: number
return function (...args: any) {
@@ -11,11 +9,6 @@ export function debounce(func: Function, delay: number) {
}
}
export function writeText(text: string) {
if (!text) return
window.navigator.clipboard.writeText(text.replaceAll(ZERO, `\n`))
}
export function deepClone(obj: any) {
if (!obj || typeof obj !== 'object') {
return obj
+19
View File
@@ -0,0 +1,19 @@
export function printImageBase64(base64: string) {
const iframe = document.createElement('iframe')
document.body.append(iframe)
const doc = iframe.contentWindow!.document
doc.open()
const image = doc.createElement('img')
image.style.width = '794px'
image.style.height = '1123px'
image.src = base64
const style = document.createElement('style')
const stylesheet = `*{margin:0;padding:0;}`
style.append(document.createTextNode(stylesheet))
setTimeout(() => {
doc.write(`${style.outerHTML}${image.outerHTML}`)
iframe.contentWindow?.print()
doc.close()
iframe.remove()
})
}