From f5dbe4470fdc59a32385077e589e39e3664bdafe Mon Sep 17 00:00:00 2001 From: hanshiyang Date: Wed, 19 Nov 2025 20:14:07 +0800 Subject: [PATCH] =?UTF-8?q?refactor(main.ts):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E7=AA=97=E5=8F=A3=E5=AF=B9=E8=B1=A1=E7=B1=BB=E5=9E=8B=E6=96=AD?= =?UTF-8?q?=E8=A8=80=E7=9A=84=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将重复的 `(window as any)` 类型断言提取为 `winAny` 变量,提高代码可读性和维护性 --- src/main.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main.ts b/src/main.ts index 133ee14..278f7b1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -211,7 +211,8 @@ window.onload = function () { }) // 向父窗口暴露:显示保存状态(文本、颜色、延时可选) - ;(window as any).showSaveStatus = (text: string, color?: string, delay?: number) => { + const winAny = window as any + winAny.showSaveStatus = (text: string, color?: string, delay?: number) => { try { const indicator = document.getElementById('save-status-indicator') as HTMLDivElement | null if (!indicator) return @@ -221,11 +222,11 @@ window.onload = function () { indicator.style.display = 'block' // 清理之前的隐藏计时器 const key = '__save_status_timer__' - const prev = (window as any)[key] + const prev = winAny[key] if (prev) { window.clearTimeout(prev) } - ;(window as any)[key] = window.setTimeout(() => { + winAny[key] = window.setTimeout(() => { indicator.style.display = 'none' }, duration) } catch (err) {