feat:富文本加粗
This commit is contained in:
@@ -5,6 +5,7 @@ export class Command {
|
|||||||
private static undo: Function
|
private static undo: Function
|
||||||
private static redo: Function
|
private static redo: Function
|
||||||
private static format: Function
|
private static format: Function
|
||||||
|
private static bold: Function
|
||||||
private static print: Function
|
private static print: Function
|
||||||
|
|
||||||
constructor(adapt: CommandAdapt) {
|
constructor(adapt: CommandAdapt) {
|
||||||
@@ -12,6 +13,7 @@ export class Command {
|
|||||||
Command.redo = adapt.redo.bind(adapt)
|
Command.redo = adapt.redo.bind(adapt)
|
||||||
Command.print = adapt.print.bind(adapt)
|
Command.print = adapt.print.bind(adapt)
|
||||||
Command.format = adapt.format.bind(adapt)
|
Command.format = adapt.format.bind(adapt)
|
||||||
|
Command.bold = adapt.bold.bind(adapt)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 撤销、重做、格式刷、清除格式
|
// 撤销、重做、格式刷、清除格式
|
||||||
@@ -28,6 +30,9 @@ export class Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 字体变大、字体变小、加粗、斜体、下划线、删除线、字体颜色、背景色
|
// 字体变大、字体变小、加粗、斜体、下划线、删除线、字体颜色、背景色
|
||||||
|
public executeBold() {
|
||||||
|
return Command.bold()
|
||||||
|
}
|
||||||
|
|
||||||
// 搜索、打印
|
// 搜索、打印
|
||||||
public executePrint() {
|
public executePrint() {
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export class CommandAdapt {
|
|||||||
const { startIndex, endIndex } = this.range.getRange()
|
const { startIndex, endIndex } = this.range.getRange()
|
||||||
if (startIndex === endIndex) return
|
if (startIndex === endIndex) return
|
||||||
const elementList = this.draw.getElementList()
|
const elementList = this.draw.getElementList()
|
||||||
elementList.slice(startIndex, endIndex)
|
elementList.slice(startIndex + 1, endIndex + 1)
|
||||||
.forEach(el => {
|
.forEach(el => {
|
||||||
el.font = ''
|
el.font = ''
|
||||||
el.color = ''
|
el.color = ''
|
||||||
@@ -39,6 +39,17 @@ export class CommandAdapt {
|
|||||||
this.draw.render({ isSetCursor: false })
|
this.draw.render({ isSetCursor: false })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bold() {
|
||||||
|
const { startIndex, endIndex } = this.range.getRange()
|
||||||
|
if (startIndex === endIndex) return
|
||||||
|
const elementList = this.draw.getElementList()
|
||||||
|
elementList.slice(startIndex + 1, endIndex + 1)
|
||||||
|
.forEach(el => {
|
||||||
|
el.bold = true
|
||||||
|
})
|
||||||
|
this.draw.render({ isSetCursor: false })
|
||||||
|
}
|
||||||
|
|
||||||
public print() {
|
public print() {
|
||||||
return printImageBase64(this.draw.getDataURL())
|
return printImageBase64(this.draw.getDataURL())
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-1
@@ -60,7 +60,10 @@ window.onload = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 字体变大、字体变小、加粗、斜体、下划线、删除线、字体颜色、背景色
|
// 字体变大、字体变小、加粗、斜体、下划线、删除线、字体颜色、背景色
|
||||||
|
document.querySelector<HTMLDivElement>('.menu-item__bold')!.onclick = function () {
|
||||||
|
console.log('bold')
|
||||||
|
instance.command.executeBold()
|
||||||
|
}
|
||||||
|
|
||||||
// 搜索、打印
|
// 搜索、打印
|
||||||
document.querySelector<HTMLDivElement>('.menu-item__print')!.onclick = function () {
|
document.querySelector<HTMLDivElement>('.menu-item__print')!.onclick = function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user