feat:add save as image element contextmenu
This commit is contained in:
@@ -55,6 +55,7 @@ export class Command {
|
||||
private static search: Function
|
||||
private static replace: Function
|
||||
private static print: Function
|
||||
private static saveAsImageElement: Function
|
||||
private static getImage: Function
|
||||
private static getValue: Function
|
||||
private static getWordCount: Function
|
||||
@@ -111,6 +112,7 @@ export class Command {
|
||||
Command.search = adapt.search.bind(adapt)
|
||||
Command.replace = adapt.replace.bind(adapt)
|
||||
Command.print = adapt.print.bind(adapt)
|
||||
Command.saveAsImageElement = adapt.saveAsImageElement.bind(adapt)
|
||||
Command.getImage = adapt.getImage.bind(adapt)
|
||||
Command.getValue = adapt.getValue.bind(adapt)
|
||||
Command.getWordCount = adapt.getWordCount.bind(adapt)
|
||||
@@ -309,6 +311,10 @@ export class Command {
|
||||
return Command.print()
|
||||
}
|
||||
|
||||
public executeSaveAsImageElement() {
|
||||
return Command.saveAsImageElement()
|
||||
}
|
||||
|
||||
public getImage(): string[] {
|
||||
return Command.getImage()
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import { IColgroup } from '../../interface/table/Colgroup'
|
||||
import { ITd } from '../../interface/table/Td'
|
||||
import { ITr } from '../../interface/table/Tr'
|
||||
import { IWatermark } from '../../interface/Watermark'
|
||||
import { getUUID } from '../../utils'
|
||||
import { downloadFile, getUUID } from '../../utils'
|
||||
import { formatElementList } from '../../utils/element'
|
||||
import { printImageBase64 } from '../../utils/print'
|
||||
import { Control } from '../draw/control/Control'
|
||||
@@ -1238,6 +1238,14 @@ export class CommandAdapt {
|
||||
}
|
||||
}
|
||||
|
||||
public saveAsImageElement() {
|
||||
const { startIndex } = this.range.getRange()
|
||||
const elementList = this.draw.getElementList()
|
||||
const element = elementList[startIndex]
|
||||
if (!element || element.type !== ElementType.IMAGE) return
|
||||
downloadFile(element.url!, `${element.id!}.png`)
|
||||
}
|
||||
|
||||
public getImage(): string[] {
|
||||
return this.draw.getDataURL()
|
||||
}
|
||||
|
||||
@@ -95,7 +95,14 @@ export class ContextMenu {
|
||||
const isInTable = positionContext.isTable
|
||||
// 是否存在跨行/列
|
||||
const isCrossRowCol = isInTable && !!crossRowCol
|
||||
// 当前元素
|
||||
const elementList = this.draw.getElementList()
|
||||
const startElement = elementList[startIndex] || null
|
||||
const endElement = elementList[endIndex] || null
|
||||
|
||||
return {
|
||||
startElement,
|
||||
endElement,
|
||||
isReadonly,
|
||||
editorHasSelection,
|
||||
editorTextFocus,
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { ElementType } from '../../../dataset/enum/Element'
|
||||
import { IRegisterContextMenu } from '../../../interface/contextmenu/ContextMenu'
|
||||
import { Command } from '../../command/Command'
|
||||
|
||||
export const imageMenus: IRegisterContextMenu[] = [
|
||||
{
|
||||
name: '另存为图片',
|
||||
icon: 'image',
|
||||
when: (payload) => {
|
||||
return !payload.editorHasSelection && payload.startElement?.type === ElementType.IMAGE
|
||||
},
|
||||
callback: (command: Command) => {
|
||||
command.executeSaveAsImageElement()
|
||||
}
|
||||
},
|
||||
]
|
||||
Reference in New Issue
Block a user