|
@@ -24,8 +24,6 @@ export class ContentContainer {
|
|
|
this.tool = this.pageViewer.tool || ''
|
|
|
this.color = this.pageViewer.color || ''
|
|
|
this._selectedFrameIndex = -1
|
|
|
- this.removedEditorList = [] // 已删除的对象列表
|
|
|
- this.removedStaging = []
|
|
|
|
|
|
this.onHandleTool = this.handleTool.bind(this)
|
|
|
this.onKeydown = this.handleKeyDown.bind(this)
|
|
@@ -315,12 +313,6 @@ export class ContentContainer {
|
|
|
this._selectedFrameIndex = index
|
|
|
}
|
|
|
|
|
|
- removeEditor (index) {
|
|
|
- const removedEditor = this.frameEditorList.splice(index, 1)
|
|
|
- this.removedEditorList.push(...removedEditor)
|
|
|
- this.frameEditorList.forEach((editor, i) => editor.editAreaIndex = i)
|
|
|
- }
|
|
|
-
|
|
|
handleKeyDown (e) {
|
|
|
const selectedEditor = this.frameEditorList[this._selectedFrameIndex]
|
|
|
if (!selectedEditor || selectedEditor.state !== 1) return
|
|
@@ -339,14 +331,14 @@ export class ContentContainer {
|
|
|
const canRedo = await this.messageHandler.sendWithPromise('CanRedo', this.editPagePtr)
|
|
|
canRedo && this.redoList.push(lastUndo)
|
|
|
|
|
|
- await this.updateFrameEditor(res, lastUndo)
|
|
|
+ await this.updateFrameEditor(res)
|
|
|
|
|
|
} else if (op === 'redo') {
|
|
|
const lastRedo = this.redoList.pop()
|
|
|
const res = await this.messageHandler.sendWithPromise('Redo', lastRedo.editPagePtr)
|
|
|
this.undoList.push(lastRedo)
|
|
|
|
|
|
- await this.updateFrameEditor(res, lastRedo)
|
|
|
+ await this.updateFrameEditor(res)
|
|
|
}
|
|
|
|
|
|
// console.log('undoList: ', this.undoList)
|
|
@@ -363,7 +355,6 @@ export class ContentContainer {
|
|
|
if (!canUndo) return
|
|
|
this.undoList.push(data)
|
|
|
this.redoList.length = 0
|
|
|
- this.removedStaging = []
|
|
|
|
|
|
this.eventBus.dispatch('changeOperateList', {
|
|
|
undoListLength: this.undoList.length,
|
|
@@ -372,74 +363,73 @@ export class ContentContainer {
|
|
|
}
|
|
|
|
|
|
// undo/redo后,更新视图
|
|
|
- async updateFrameEditor (res, lastRec) {
|
|
|
+ async updateFrameEditor (res) {
|
|
|
const { editAreaPtr, editCharPlace } = res
|
|
|
- // console.log(res, lastRec)
|
|
|
-
|
|
|
- let editor = null
|
|
|
- // let targetPtr = editAreaPtr || lastRec.editAreaPtr
|
|
|
- let targetPtr = lastRec.editAreaPtr
|
|
|
-
|
|
|
- // console.log('frameEditorList: ')
|
|
|
- // this.frameEditorList.forEach(item => console.log(item.editAreaIndex, item.editAreaPtr))
|
|
|
- // console.log('removedStaging: ')
|
|
|
- // this.removedStaging.forEach(item => console.log(item.editAreaIndex, item.editAreaPtr))
|
|
|
- // console.log('removedEditorList:')
|
|
|
- // this.removedEditorList.forEach(item => console.log(item.editAreaIndex, item.editAreaPtr))
|
|
|
-
|
|
|
- const toRemoved = this.removedStaging.find(item => item.editAreaPtr === targetPtr)
|
|
|
- if (toRemoved) {
|
|
|
- const lastStaging = this.removedStaging.pop()
|
|
|
- editor = this.frameEditorList.find(item => item.editAreaPtr === lastStaging.editAreaPtr)
|
|
|
- editor.remove(true)
|
|
|
- editor.updateCanvasAfterUndoRedo(true)
|
|
|
-
|
|
|
- // console.log('获取页面所有指针:')
|
|
|
- // const editAreaCount = await this.messageHandler.sendWithPromise('GetEditAreaCount', this.editPagePtr)
|
|
|
- // for (let i = 0; i < editAreaCount; i++) {
|
|
|
- // const editAreaPtr = await this.messageHandler.sendWithPromise('GetEditArea', {
|
|
|
- // editPagePtr: this.editPagePtr,
|
|
|
- // index: i
|
|
|
- // })
|
|
|
- // console.log('index: ', i, ' ---- Area指针: ', editAreaPtr)
|
|
|
- // }
|
|
|
+
|
|
|
+ const editor = this.frameEditorList.find(item => item.editAreaPtr === editAreaPtr)
|
|
|
+ if (editor) {
|
|
|
+ editor.updateCanvasAfterUndoRedo()
|
|
|
+ editor.type === 'text' && editCharPlace && editor.updateCursorLine(editCharPlace)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- editor = this.frameEditorList.find(item => item.editAreaPtr === targetPtr)
|
|
|
-
|
|
|
- // console.log('frameEditorList: ')
|
|
|
- // this.frameEditorList.forEach(item => console.log(item.editAreaIndex, item.editAreaPtr))
|
|
|
-
|
|
|
- // console.log('获取页面所有指针:')
|
|
|
- // const editAreaCount = await this.messageHandler.sendWithPromise('GetEditAreaCount', this.editPagePtr)
|
|
|
- // for (let i = 0; i < editAreaCount; i++) {
|
|
|
- // const editAreaPtr = await this.messageHandler.sendWithPromise('GetEditArea', {
|
|
|
- // editPagePtr: this.editPagePtr,
|
|
|
- // index: i
|
|
|
- // })
|
|
|
- // console.log('index: ', i, ' ---- Area指针: ', editAreaPtr)
|
|
|
- // }
|
|
|
-
|
|
|
- if (!editor) {
|
|
|
- const removedEditorIndex = this.removedEditorList.findIndex(item => item.editAreaPtr === targetPtr)
|
|
|
- if (removedEditorIndex === -1) return
|
|
|
-
|
|
|
- editor = this.removedEditorList[removedEditorIndex]
|
|
|
- this.removedStaging.push({
|
|
|
- editAreaIndex: editor.editAreaIndex,
|
|
|
- editAreaPtr: editor.editAreaPtr
|
|
|
+ const newFrameEditorList = []
|
|
|
+ const editAreaCount = await this.messageHandler.sendWithPromise('GetEditAreaCount', this.editPagePtr)
|
|
|
+
|
|
|
+ for (let i = 0; i < editAreaCount; i++) {
|
|
|
+ const editAreaPtr = await this.messageHandler.sendWithPromise('GetEditArea', {
|
|
|
+ editPagePtr: this.editPagePtr,
|
|
|
+ index: i
|
|
|
})
|
|
|
- this.removedEditorList.splice(removedEditorIndex, 1)
|
|
|
- this.frameEditorList.splice(editor.editAreaIndex, 0, editor)
|
|
|
- this.frameEditorList.forEach((editor, i) => editor.editAreaIndex = i)
|
|
|
+ if (!editAreaPtr) continue
|
|
|
+
|
|
|
+ const isTextPtr = await this.messageHandler.sendWithPromise('IsTextArea', editAreaPtr)
|
|
|
+ if (isTextPtr) {
|
|
|
+ const frameEditor = new TextEditor({
|
|
|
+ eventBus: this.eventBus,
|
|
|
+ contentContainer: this,
|
|
|
+ container: this.contentContainer,
|
|
|
+ pagePtr: this.pagePtr,
|
|
|
+ editPagePtr: this.editPagePtr,
|
|
|
+ editAreaPtr,
|
|
|
+ editAreaIndex: i,
|
|
|
+ viewport: this.viewport,
|
|
|
+ scale: this.scale,
|
|
|
+ messageHandler: this.messageHandler,
|
|
|
+ pageViewer: this.pageViewer,
|
|
|
+ hidden: this.tool === 'addImage'
|
|
|
+ })
|
|
|
+ newFrameEditorList.push(frameEditor)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ const isImagePtr = await this.messageHandler.sendWithPromise('IsImageArea', editAreaPtr)
|
|
|
+ if (isImagePtr) {
|
|
|
+ const frameEditor = new ImageEditor({
|
|
|
+ eventBus: this.eventBus,
|
|
|
+ contentContainer: this,
|
|
|
+ container: this.contentContainer,
|
|
|
+ pagePtr: this.pagePtr,
|
|
|
+ editPagePtr: this.editPagePtr,
|
|
|
+ editAreaPtr,
|
|
|
+ editAreaIndex: i,
|
|
|
+ viewport: this.viewport,
|
|
|
+ scale: this.scale,
|
|
|
+ messageHandler: this.messageHandler,
|
|
|
+ pageViewer: this.pageViewer,
|
|
|
+ $t: this.$t,
|
|
|
+ hidden: this.tool === 'addText'
|
|
|
+ })
|
|
|
+ newFrameEditorList.push(frameEditor)
|
|
|
+ }
|
|
|
}
|
|
|
- // console.log('要去做处理的Area: ', ' - index:', editor.editAreaIndex, ' - 指针:', editor.editAreaPtr)
|
|
|
- // console.log('editor: ', editor.editAreaIndex, editor.editAreaPtr, editor)
|
|
|
|
|
|
- !editAreaPtr && !lastRec.replacedImage && editor.remove(true)
|
|
|
- editor.updateCanvasAfterUndoRedo(!editAreaPtr)
|
|
|
- editor.type === 'text' && editCharPlace && editor.updateCursorLine(editCharPlace)
|
|
|
+ this.frameEditorList.forEach(editor => {
|
|
|
+ editor.updateCanvas(null, true)
|
|
|
+ editor.removeViewer()
|
|
|
+ })
|
|
|
+ this.frameEditorList.length = 0
|
|
|
+ this.frameEditorList = newFrameEditorList
|
|
|
}
|
|
|
|
|
|
handlePageChanging ({pageNumber}) {
|