improve: compute zone tooltip performance

pr675
Hufe921 2 years ago
parent 095414fbe6
commit 28ef4af15e

@ -27,7 +27,7 @@ export class Zone {
this.indicatorContainer = null this.indicatorContainer = null
// 区域提示 // 区域提示
if (!this.options.zone.tipDisabled) { if (!this.options.zone.tipDisabled) {
new ZoneTip(draw) new ZoneTip(draw, this)
} }
} }
@ -71,6 +71,26 @@ export class Zone {
}) })
} }
public getZoneByY(y: number): EditorZone {
// 页眉底部距离页面顶部距离
const header = this.draw.getHeader()
const headerBottomY = header.getHeaderTop() + header.getHeight()
// 页脚上部距离页面顶部距离
const footer = this.draw.getFooter()
const pageHeight = this.draw.getHeight()
const footerTopY =
pageHeight - (footer.getFooterBottom() + footer.getHeight())
// 页眉:当前位置小于页眉底部位置
if (y < headerBottomY) {
return EditorZone.HEADER
}
// 页脚:当前位置大于页脚顶部位置
if (y > footerTopY) {
return EditorZone.FOOTER
}
return EditorZone.MAIN
}
public drawZoneIndicator() { public drawZoneIndicator() {
this._clearZoneIndicator() this._clearZoneIndicator()
if (!this.isHeaderActive() && !this.isFooterActive()) return if (!this.isHeaderActive() && !this.isFooterActive()) return

@ -3,10 +3,10 @@ import { EditorZone } from '../../dataset/enum/Editor'
import { throttle } from '../../utils' import { throttle } from '../../utils'
import { Draw } from '../draw/Draw' import { Draw } from '../draw/Draw'
import { I18n } from '../i18n/I18n' import { I18n } from '../i18n/I18n'
import { Position } from '../position/Position' import { Zone } from './Zone'
export class ZoneTip { export class ZoneTip {
private position: Position private zone: Zone
private i18n: I18n private i18n: I18n
private container: HTMLDivElement private container: HTMLDivElement
private pageContainer: HTMLDivElement private pageContainer: HTMLDivElement
@ -16,8 +16,8 @@ export class ZoneTip {
private tipContent: HTMLSpanElement private tipContent: HTMLSpanElement
private currentMoveZone: EditorZone | undefined private currentMoveZone: EditorZone | undefined
constructor(draw: Draw) { constructor(draw: Draw, zone: Zone) {
this.position = draw.getPosition() this.zone = zone
this.i18n = draw.getI18n() this.i18n = draw.getI18n()
this.container = draw.getContainer() this.container = draw.getContainer()
this.pageContainer = draw.getPageContainer() this.pageContainer = draw.getPageContainer()
@ -36,22 +36,19 @@ export class ZoneTip {
'mousemove', 'mousemove',
throttle((evt: MouseEvent) => { throttle((evt: MouseEvent) => {
if (this.isDisableMouseMove) return if (this.isDisableMouseMove) return
const pageNo = Number((<HTMLCanvasElement>evt.target).dataset.index) if (evt.target instanceof HTMLCanvasElement) {
if (Number.isNaN(pageNo)) { const mousemoveZone = this.zone.getZoneByY(evt.offsetY)
this._updateZoneTip(false) this.currentMoveZone = mousemoveZone
} else { // 激活区域是正文,移动区域是页眉、页脚时绘制
const positionInfo = this.position.getPositionByXY({
x: evt.offsetX,
y: evt.offsetY,
pageNo
})
this.currentMoveZone = positionInfo.zone
this._updateZoneTip( this._updateZoneTip(
positionInfo.zone === EditorZone.HEADER || this.zone.getZone() === EditorZone.MAIN &&
positionInfo.zone === EditorZone.FOOTER, (mousemoveZone === EditorZone.HEADER ||
mousemoveZone === EditorZone.FOOTER),
evt.x, evt.x,
evt.y evt.y
) )
} else {
this._updateZoneTip(false)
} }
}, 250) }, 250)
) )

@ -479,5 +479,8 @@ export const options: IEditorOption = {
placeholder: { placeholder: {
data: '请输入正文' data: '请输入正文'
}, },
zone: {
tipDisabled: false
},
maskMargin: [60, 0, 30, 0] // 菜单栏高度60底部工具栏30为遮盖层 maskMargin: [60, 0, 30, 0] // 菜单栏高度60底部工具栏30为遮盖层
} }

Loading…
Cancel
Save