refactor(main.ts): 优化窗口对象类型断言的使用
将重复的 `(window as any)` 类型断言提取为 `winAny` 变量,提高代码可读性和维护性
This commit is contained in:
parent
e64b49f03d
commit
f5dbe4470f
|
|
@ -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 {
|
try {
|
||||||
const indicator = document.getElementById('save-status-indicator') as HTMLDivElement | null
|
const indicator = document.getElementById('save-status-indicator') as HTMLDivElement | null
|
||||||
if (!indicator) return
|
if (!indicator) return
|
||||||
|
|
@ -221,11 +222,11 @@ window.onload = function () {
|
||||||
indicator.style.display = 'block'
|
indicator.style.display = 'block'
|
||||||
// 清理之前的隐藏计时器
|
// 清理之前的隐藏计时器
|
||||||
const key = '__save_status_timer__'
|
const key = '__save_status_timer__'
|
||||||
const prev = (window as any)[key]
|
const prev = winAny[key]
|
||||||
if (prev) {
|
if (prev) {
|
||||||
window.clearTimeout(prev)
|
window.clearTimeout(prev)
|
||||||
}
|
}
|
||||||
;(window as any)[key] = window.setTimeout(() => {
|
winAny[key] = window.setTimeout(() => {
|
||||||
indicator.style.display = 'none'
|
indicator.style.display = 'none'
|
||||||
}, duration)
|
}, duration)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user