parent
9462ba06fb
commit
0df6619cc3
@ -1,22 +1,33 @@
|
||||
import { printImageBase64 } from "../../utils/print"
|
||||
import { Draw } from "../draw/Draw"
|
||||
|
||||
export class Command {
|
||||
|
||||
private undo: Function
|
||||
private redo: Function
|
||||
private static undo: Function
|
||||
private static redo: Function
|
||||
private static getDataURL: Function
|
||||
|
||||
constructor(draw: Draw) {
|
||||
const historyManager = draw.getHistoryManager()
|
||||
this.undo = historyManager.undo.bind(historyManager)
|
||||
this.redo = historyManager.redo.bind(historyManager)
|
||||
Command.undo = historyManager.undo.bind(historyManager)
|
||||
Command.redo = historyManager.redo.bind(historyManager)
|
||||
Command.getDataURL = draw.getDataURL.bind(draw)
|
||||
}
|
||||
|
||||
// 撤销、重做、格式刷、清除格式
|
||||
public executeUndo() {
|
||||
return this.undo()
|
||||
return Command.undo()
|
||||
}
|
||||
|
||||
public executeRedo() {
|
||||
return this.redo()
|
||||
return Command.redo()
|
||||
}
|
||||
|
||||
// 字体变大、字体变小、加粗、斜体、下划线、删除线、字体颜色、背景色
|
||||
|
||||
// 搜索、打印
|
||||
public executePrint() {
|
||||
return printImageBase64(Command.getDataURL())
|
||||
}
|
||||
|
||||
}
|
||||
@ -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`))
|
||||
}
|
||||
@ -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()
|
||||
})
|
||||
}
|
||||
Loading…
Reference in new issue