From a3ff4fa3a25c047faa054ee2ccf7a03264dc7c1e Mon Sep 17 00:00:00 2001 From: lijinke666 Date: Wed, 25 Dec 2024 16:13:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E5=88=B0=204k=20=E6=98=BE=E7=A4=BA=E5=99=A8=E6=97=B6=E6=B8=B2?= =?UTF-8?q?=E6=9F=93=E6=A8=A1=E7=B3=8A=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/s2-core/src/ui/hd-adapter/index.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/s2-core/src/ui/hd-adapter/index.ts b/packages/s2-core/src/ui/hd-adapter/index.ts index 9bb2dac7b1..ae3cb992b4 100644 --- a/packages/s2-core/src/ui/hd-adapter/index.ts +++ b/packages/s2-core/src/ui/hd-adapter/index.ts @@ -17,12 +17,14 @@ export class HdAdapter { private spreadsheet: SpreadSheet; - private isDevicePixelRatioChange = false; + private isDevicePixelRatioChange; private zoomOffsetLeft: number | undefined; constructor(spreadsheet: SpreadSheet) { this.spreadsheet = spreadsheet; + this.isDevicePixelRatioChange = false; + this.zoomOffsetLeft = 0; } public init = () => { @@ -146,10 +148,13 @@ export class HdAdapter { * 如果是触控板双指缩放触发的 resize 事件, offsetLeft 可以获取到值 * 如果是浏览器窗口的放大缩小 (command +/-), offsetLeft 始终是 0 */ - const isTouchPadZoom = this.zoomOffsetLeft !== target.offsetLeft; + const isTouchPadZoom = + (this.zoomOffsetLeft || 0) !== (target?.offsetLeft || 0); if (ratio >= 1 && isTouchPadZoom && !this.isDevicePixelRatioChange) { - await this.renderByDevicePixelRatio(ratio); + const maxDPR = Math.max(ratio, window.devicePixelRatio); + + await this.renderByDevicePixelRatio(maxDPR); this.zoomOffsetLeft = target.offsetLeft; } }, 350);