feat: 添加初始加载时不显示toast的时间阈值

This commit is contained in:
weedy233 2025-09-04 15:06:13 +08:00
parent 894eb2823e
commit 8f34721551
No known key found for this signature in database
GPG Key ID: 27A2575D0916FDD7
2 changed files with 17 additions and 3 deletions

View File

@ -41,3 +41,6 @@ export const TOAST_DURATION_CONFIG = {
// Toast显示类名
export const TOAST_CLASS_NAME = 'be-video-scale-toast'
// 页面加载后不显示toast的时间阈值毫秒
export const NO_TOAST_TIME_THRESHOLD = 3000

View File

@ -4,7 +4,12 @@ import { componentsTags } from '@/components/component'
import { videoChange } from '@/core/observer'
import { ScaleState, applyScale, updateScaleFromSettings } from './scale-service'
import { showScaleToast, cleanupToasts, handleError } from './ui-utils'
import { CUSTOM_SCALE_CONFIG, SCALE_PRESETS, TOAST_DURATION_CONFIG } from './constants'
import {
CUSTOM_SCALE_CONFIG,
SCALE_PRESETS,
TOAST_DURATION_CONFIG,
NO_TOAST_TIME_THRESHOLD,
} from './constants'
import { ScalePreset } from './types'
import './styles.scss'
@ -55,6 +60,9 @@ export const component = defineComponentMetadata({
// 缩放状态管理
const scaleState = new ScaleState()
// 记录页面加载时间
const pageLoadTime = Date.now()
// 初始化时根据showToast状态设置toastDuration的可见性
toastDurationOption.hidden = !settings.options.showToast
@ -68,8 +76,11 @@ export const component = defineComponentMetadata({
try {
await applyScale(scale)
// 检查是否启用了toast显示
if (settings.options.showToast) {
// 检查是否启用了toast显示且缩放比例不是100%且已过3秒加载时间
const currentTime = Date.now()
const hasPassedInitialTime = currentTime - pageLoadTime >= NO_TOAST_TIME_THRESHOLD
if (settings.options.showToast && scale !== 100 && hasPassedInitialTime) {
showScaleToast(scale, settings.options.toastDuration as number)
}
} catch (error) {