feat:add getValue interface
This commit is contained in:
@@ -2,6 +2,7 @@ import { IElement } from '../..'
|
||||
import { EditorMode } from '../../dataset/enum/Editor'
|
||||
import { RowFlex } from '../../dataset/enum/Row'
|
||||
import { IDrawImagePayload } from '../../interface/Draw'
|
||||
import { IEditorResult } from '../../interface/Editor'
|
||||
import { IWatermark } from '../../interface/Watermark'
|
||||
import { CommandAdapt } from './CommandAdapt'
|
||||
|
||||
@@ -55,6 +56,7 @@ export class Command {
|
||||
private static replace: Function
|
||||
private static print: Function
|
||||
private static getImage: Function
|
||||
private static getValue: Function
|
||||
private static pageScaleRecovery: Function
|
||||
private static pageScaleMinus: Function
|
||||
private static pageScaleAdd: Function
|
||||
@@ -108,6 +110,7 @@ export class Command {
|
||||
Command.replace = adapt.replace.bind(adapt)
|
||||
Command.print = adapt.print.bind(adapt)
|
||||
Command.getImage = adapt.getImage.bind(adapt)
|
||||
Command.getValue = adapt.getValue.bind(adapt)
|
||||
Command.pageScaleRecovery = adapt.pageScaleRecovery.bind(adapt)
|
||||
Command.pageScaleMinus = adapt.pageScaleMinus.bind(adapt)
|
||||
Command.pageScaleAdd = adapt.pageScaleAdd.bind(adapt)
|
||||
@@ -306,6 +309,10 @@ export class Command {
|
||||
return Command.getImage()
|
||||
}
|
||||
|
||||
public getValue(): IEditorResult {
|
||||
return Command.getValue()
|
||||
}
|
||||
|
||||
// 页面缩放
|
||||
public executePageScaleRecovery() {
|
||||
return Command.pageScaleRecovery()
|
||||
|
||||
@@ -7,7 +7,7 @@ import { ElementType } from '../../dataset/enum/Element'
|
||||
import { ElementStyleKey } from '../../dataset/enum/ElementStyle'
|
||||
import { RowFlex } from '../../dataset/enum/Row'
|
||||
import { IDrawImagePayload } from '../../interface/Draw'
|
||||
import { IEditorOption } from '../../interface/Editor'
|
||||
import { IEditorOption, IEditorResult } from '../../interface/Editor'
|
||||
import { IElement, IElementStyle } from '../../interface/Element'
|
||||
import { IColgroup } from '../../interface/table/Colgroup'
|
||||
import { ITd } from '../../interface/table/Td'
|
||||
@@ -1239,6 +1239,10 @@ export class CommandAdapt {
|
||||
return this.draw.getDataURL()
|
||||
}
|
||||
|
||||
public getValue(): IEditorResult {
|
||||
return this.draw.getValue()
|
||||
}
|
||||
|
||||
public pageScaleRecovery() {
|
||||
const { scale } = this.options
|
||||
if (scale !== 1) {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { version } from '../../../../package.json'
|
||||
import { ZERO } from '../../dataset/constant/Common'
|
||||
import { RowFlex } from '../../dataset/enum/Row'
|
||||
import { IDrawOption, IDrawRowPayload, IDrawRowResult } from '../../interface/Draw'
|
||||
import { IEditorOption } from '../../interface/Editor'
|
||||
import { IEditorOption, IEditorResult } from '../../interface/Editor'
|
||||
import { IElement, IElementMetrics, IElementPosition, IElementFillRect, IElementStyle } from '../../interface/Element'
|
||||
import { IRow, IRowElement } from '../../interface/Row'
|
||||
import { deepClone, getUUID } from '../../utils'
|
||||
@@ -35,6 +36,7 @@ import { PageBreakParticle } from './particle/PageBreak'
|
||||
import { Watermark } from './frame/Watermark'
|
||||
import { EditorMode } from '../../dataset/enum/Editor'
|
||||
import { Control } from './control/Control'
|
||||
import { zipElementList } from '../../utils/element'
|
||||
|
||||
export class Draw {
|
||||
|
||||
@@ -362,6 +364,21 @@ export class Draw {
|
||||
}
|
||||
}
|
||||
|
||||
public getValue(): IEditorResult {
|
||||
// 配置
|
||||
const { width, height, margins, watermark } = this.options
|
||||
// 数据
|
||||
const data = zipElementList(this.elementList)
|
||||
return {
|
||||
version,
|
||||
width,
|
||||
height,
|
||||
margins,
|
||||
watermark: watermark.data ? watermark : undefined,
|
||||
data
|
||||
}
|
||||
}
|
||||
|
||||
private _createPageContainer(): HTMLDivElement {
|
||||
// 容器宽度需跟随纸张宽度
|
||||
this.container.style.width = `${this.getWidth()}px`
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
import { version } from '../../../../package.json'
|
||||
import { ElementType } from '../..'
|
||||
import { ZERO } from '../../dataset/constant/Common'
|
||||
import { EDITOR_ELEMENT_COPY_ATTR } from '../../dataset/constant/Element'
|
||||
import { ElementStyleKey } from '../../dataset/enum/ElementStyle'
|
||||
import { MouseEventButton } from '../../dataset/enum/Event'
|
||||
import { KeyMap } from '../../dataset/enum/Keymap'
|
||||
import { IEditorResult } from '../../interface/Editor'
|
||||
import { IElement } from '../../interface/Element'
|
||||
import { ICurrentPosition } from '../../interface/Position'
|
||||
import { writeTextByElementList } from '../../utils/clipboard'
|
||||
import { zipElementList } from '../../utils/element'
|
||||
import { Cursor } from '../cursor/Cursor'
|
||||
import { Draw } from '../draw/Draw'
|
||||
import { HyperlinkParticle } from '../draw/particle/HyperlinkParticle'
|
||||
@@ -419,9 +416,8 @@ export class CanvasEvent {
|
||||
this.selectAll()
|
||||
} else if (evt.ctrlKey && evt.key === KeyMap.S) {
|
||||
if (isReadonly) return
|
||||
const saved = this.listener.saved
|
||||
if (saved) {
|
||||
saved(this.save())
|
||||
if (this.listener.saved) {
|
||||
this.listener.saved(this.draw.getValue())
|
||||
}
|
||||
evt.preventDefault()
|
||||
}
|
||||
@@ -589,20 +585,4 @@ export class CanvasEvent {
|
||||
this.isCompositing = false
|
||||
}
|
||||
|
||||
public save(): IEditorResult {
|
||||
// 配置
|
||||
const { width, height, margins, watermark } = this.draw.getOptions()
|
||||
// 数据
|
||||
const elementList = this.draw.getOriginalElementList()
|
||||
const data = zipElementList(elementList)
|
||||
return {
|
||||
version,
|
||||
width,
|
||||
height,
|
||||
margins,
|
||||
watermark: watermark.data ? watermark : undefined,
|
||||
data
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user