fix: primaryColor calculation (#5337)

This commit is contained in:
Netfan
2025-01-10 01:51:38 +08:00
committed by GitHub
parent c979c23e6b
commit d34838bdd8
2 changed files with 34 additions and 7 deletions

View File

@@ -2,7 +2,7 @@
import type { BuiltinThemePreset } from '@vben/preferences';
import type { BuiltinThemeType } from '@vben/types';
import { computed, ref } from 'vue';
import { computed, ref, watch } from 'vue';
import { UserRoundPen } from '@vben/icons';
import { $t } from '@vben/locales';
@@ -80,11 +80,6 @@ function typeView(name: BuiltinThemeType) {
function handleSelect(theme: BuiltinThemePreset) {
modelValue.value = theme.type;
const primaryColor = props.isDark
? theme.darkPrimaryColor || theme.primaryColor
: theme.primaryColor;
themeColorPrimary.value = primaryColor || theme.color;
}
function handleInputChange(e: Event) {
@@ -95,6 +90,22 @@ function handleInputChange(e: Event) {
function selectColor() {
colorInput.value?.[0]?.click?.();
}
watch(
() => [modelValue.value, props.isDark] as [BuiltinThemeType, boolean],
([themeType, isDark]) => {
const theme = builtinThemePresets.value.find(
(item) => item.type === themeType,
);
if (theme) {
const primaryColor = isDark
? theme.darkPrimaryColor || theme.primaryColor
: theme.primaryColor;
themeColorPrimary.value = primaryColor || theme.color;
}
},
);
</script>
<template>