From 36bf6fc1495f7241f4b0157dbc9913da36124a9d Mon Sep 17 00:00:00 2001 From: Netfan Date: Sat, 12 Apr 2025 01:44:08 +0800 Subject: [PATCH] fix: builtin color change throttled in preference drawer (#5924) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复偏好设置中的自定义主题色拖动选择颜色时页面会明显卡顿的问题 --- .../widgets/preferences/blocks/theme/builtin.vue | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/effects/layouts/src/widgets/preferences/blocks/theme/builtin.vue b/packages/effects/layouts/src/widgets/preferences/blocks/theme/builtin.vue index 8a41763a..27dfd28a 100644 --- a/packages/effects/layouts/src/widgets/preferences/blocks/theme/builtin.vue +++ b/packages/effects/layouts/src/widgets/preferences/blocks/theme/builtin.vue @@ -9,6 +9,8 @@ import { $t } from '@vben/locales'; import { BUILT_IN_THEME_PRESETS } from '@vben/preferences'; import { convertToHsl, TinyColor } from '@vben/utils'; +import { useThrottleFn } from '@vueuse/core'; + defineOptions({ name: 'PreferenceBuiltinTheme', }); @@ -19,6 +21,15 @@ const colorInput = ref(); const modelValue = defineModel({ default: 'default' }); const themeColorPrimary = defineModel('themeColorPrimary'); +const updateThemeColorPrimary = useThrottleFn( + (value: string) => { + themeColorPrimary.value = value; + }, + 300, + true, + true, +); + const inputValue = computed(() => { return new TinyColor(themeColorPrimary.value || '').toHexString(); }); @@ -84,7 +95,7 @@ function handleSelect(theme: BuiltinThemePreset) { function handleInputChange(e: Event) { const target = e.target as HTMLInputElement; - themeColorPrimary.value = convertToHsl(target.value); + updateThemeColorPrimary(convertToHsl(target.value)); } function selectColor() {