|
@@ -14,16 +14,16 @@ export class ContentContainer {
|
|
|
this.viewport = options.viewport
|
|
|
this.scale = options.scale
|
|
|
this.$t = options.$t
|
|
|
- this.undoList = options.undoList
|
|
|
- this.redoList = options.redoList
|
|
|
+ this.historyManager = options.historyManager
|
|
|
|
|
|
- this._cancelled = false
|
|
|
this.destroyed = false
|
|
|
this.rendered = false
|
|
|
this.frameEditorList = []
|
|
|
this.tool = this.pageViewer.tool || ''
|
|
|
this.color = this.pageViewer.color || ''
|
|
|
this._selectedFrameIndex = -1
|
|
|
+ this.undoList = this.historyManager.undoList
|
|
|
+ this.redoList = this.historyManager.redoList
|
|
|
|
|
|
this.onHandleTool = this.handleTool.bind(this)
|
|
|
this.onKeydown = this.handleKeyDown.bind(this)
|
|
@@ -31,14 +31,34 @@ export class ContentContainer {
|
|
|
}
|
|
|
|
|
|
async init() {
|
|
|
+ this.undoList.length = 0
|
|
|
+ this.redoList.length = 0
|
|
|
+ this.eventBus.dispatch('changeOperateList', {
|
|
|
+ undoListLength: this.undoList.length,
|
|
|
+ redoListLength: this.redoList.length
|
|
|
+ })
|
|
|
+
|
|
|
const { editPagePtr } = await this.messageHandler.sendWithPromise('InitEditPage', {
|
|
|
pagePtr: this.pagePtr
|
|
|
})
|
|
|
this.editPagePtr = editPagePtr
|
|
|
+
|
|
|
+ const result = await this.messageHandler.sendWithPromise('BeginEdit', {
|
|
|
+ editPagePtr: this.editPagePtr,
|
|
|
+ type: 1 | 2
|
|
|
+ })
|
|
|
+ if (result && result.code) {
|
|
|
+ console.log(result.message)
|
|
|
+ alert(result.message)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ document.addEventListener('keydown', this.onKeydown)
|
|
|
+ this.render()
|
|
|
}
|
|
|
|
|
|
async render () {
|
|
|
- if (this._cancelled || this.contentContainer) {
|
|
|
+ if (this.contentContainer) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -46,24 +66,11 @@ export class ContentContainer {
|
|
|
contentContainer.className = 'contentContainer'
|
|
|
this.contentContainer = contentContainer
|
|
|
this.pageDiv.append(this.contentContainer)
|
|
|
-
|
|
|
- await this.init()
|
|
|
|
|
|
this.eventBus._on('toolChanged', this.onHandleTool)
|
|
|
this.eventBus._on('pagechanging', this.onPageChanging)
|
|
|
- document.addEventListener('keydown', this.onKeydown)
|
|
|
-
|
|
|
- const result = await this.messageHandler.sendWithPromise('BeginEdit', {
|
|
|
- editPagePtr: this.editPagePtr,
|
|
|
- type: 1 | 2
|
|
|
- })
|
|
|
-
|
|
|
- if (result && result.code) {
|
|
|
- console.log(result.message)
|
|
|
- alert(result.message)
|
|
|
- return false
|
|
|
- }
|
|
|
|
|
|
+ this.frameEditorList.length = 0
|
|
|
const editAreaCount = await this.messageHandler.sendWithPromise('GetEditAreaCount', this.editPagePtr)
|
|
|
|
|
|
for (let i = 0; i < editAreaCount; i++) {
|
|
@@ -143,8 +150,21 @@ export class ContentContainer {
|
|
|
}
|
|
|
|
|
|
cancel () {
|
|
|
- this._cancelled = true
|
|
|
- this.destroy()
|
|
|
+ if (this.destroyed || !this.rendered) return
|
|
|
+
|
|
|
+ this.contentContainer?.remove()
|
|
|
+ this.contentContainer = null
|
|
|
+
|
|
|
+ if (this.textManager) {
|
|
|
+ this.textManager.tool = ''
|
|
|
+ this.textManager.reset()
|
|
|
+ }
|
|
|
+ if (this.imageManager) {
|
|
|
+ this.imageManager.tool = ''
|
|
|
+ this.imageManager.reset()
|
|
|
+ }
|
|
|
+
|
|
|
+ this.eventBus._off('toolChanged', this.onHandleTool)
|
|
|
}
|
|
|
|
|
|
destroy () {
|
|
@@ -163,8 +183,6 @@ export class ContentContainer {
|
|
|
}
|
|
|
|
|
|
this.destroyed = true
|
|
|
- this.undoList.length = 0
|
|
|
- this.redoList.length = 0
|
|
|
|
|
|
this.eventBus._off('toolChanged', this.onHandleTool)
|
|
|
document.removeEventListener('keydown', this.onKeydown)
|