mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-04-14 06:30:49 +08:00
feat: 优化歌词颜色检测逻辑
This commit is contained in:
@@ -417,42 +417,29 @@ const setTextColors = (background: string) => {
|
||||
}
|
||||
};
|
||||
|
||||
// 监听背景变化
|
||||
const targetBackground = computed(() => {
|
||||
if (config.value.useCustomBackground && customBackgroundStyle.value) {
|
||||
if (typeof customBackgroundStyle.value === 'string') {
|
||||
return customBackgroundStyle.value;
|
||||
}
|
||||
}
|
||||
if (config.value.theme !== 'default') {
|
||||
return themeMusic[config.value.theme] || props.background;
|
||||
}
|
||||
return props.background;
|
||||
});
|
||||
|
||||
// 监听目标背景变化并更新文字颜色
|
||||
watch(
|
||||
() => props.background,
|
||||
targetBackground,
|
||||
(newBg) => {
|
||||
if (config.value.useCustomBackground) {
|
||||
// 使用自定义背景时,根据自定义背景计算文字颜色
|
||||
if (customBackgroundStyle.value) {
|
||||
setTextColors(customBackgroundStyle.value);
|
||||
}
|
||||
} else if (config.value.theme === 'default') {
|
||||
if (newBg) {
|
||||
setTextColors(newBg);
|
||||
} else {
|
||||
setTextColors(themeMusic[config.value.theme] || props.background);
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
// 监听自定义背景配置变化
|
||||
watch(
|
||||
() => [config.value.useCustomBackground, customBackgroundStyle.value] as const,
|
||||
([useCustom, customBg]) => {
|
||||
if (useCustom && customBg && typeof customBg === 'string') {
|
||||
setTextColors(customBg);
|
||||
} else {
|
||||
// 回退到主题模式
|
||||
if (config.value.theme === 'default') {
|
||||
setTextColors(props.background);
|
||||
} else {
|
||||
setTextColors(themeMusic[config.value.theme] || props.background);
|
||||
}
|
||||
}
|
||||
},
|
||||
{ deep: true }
|
||||
);
|
||||
|
||||
const { getLrcStyle: originalLrcStyle } = useLyricProgress();
|
||||
|
||||
const getLrcStyle = (index: number) => {
|
||||
@@ -589,15 +576,6 @@ watch(
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
// 监听配置变化并保存到本地存储
|
||||
watch(
|
||||
() => config.value,
|
||||
(newConfig) => {
|
||||
localStorage.setItem('music-full-config', JSON.stringify(newConfig));
|
||||
},
|
||||
{ deep: true }
|
||||
);
|
||||
|
||||
// 监听滚动事件
|
||||
const handleScroll = () => {
|
||||
if (!lrcSider.value || !config.value.hideCover) return;
|
||||
@@ -677,16 +655,6 @@ watch(
|
||||
}
|
||||
);
|
||||
|
||||
// 监听主题变化
|
||||
watch(
|
||||
() => config.value.theme,
|
||||
(newTheme) => {
|
||||
const newBackground = themeMusic[newTheme] || props.background;
|
||||
setTextColors(newBackground);
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
// 添加文字间距监听
|
||||
watch(
|
||||
() => config.value.letterSpacing,
|
||||
|
||||
@@ -979,14 +979,19 @@ const setTextColors = (background: string) => {
|
||||
}
|
||||
};
|
||||
|
||||
// 监听背景变化
|
||||
const targetBackground = computed(() => {
|
||||
if (config.value.theme !== 'default') {
|
||||
return themeMusic[config.value.theme] || props.background;
|
||||
}
|
||||
return props.background;
|
||||
});
|
||||
|
||||
// 监听目标背景变化并更新文字颜色
|
||||
watch(
|
||||
() => props.background,
|
||||
targetBackground,
|
||||
(newBg) => {
|
||||
if (config.value.theme === 'default') {
|
||||
if (newBg) {
|
||||
setTextColors(newBg);
|
||||
} else {
|
||||
setTextColors(themeMusic[config.value.theme] || props.background);
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
@@ -1040,16 +1045,6 @@ const closeMusicFull = () => {
|
||||
playerStore.setMusicFull(false);
|
||||
};
|
||||
|
||||
// 监听主题变化
|
||||
watch(
|
||||
() => config.value.theme,
|
||||
(newTheme) => {
|
||||
const newBackground = themeMusic[newTheme] || props.background;
|
||||
setTextColors(newBackground);
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
// 添加对 playMusic.id 的监听,歌曲切换时滚动到顶部
|
||||
watch(
|
||||
() => playMusic.value.id,
|
||||
@@ -1116,7 +1111,9 @@ onMounted(() => {
|
||||
watch(isVisible, (newVal) => {
|
||||
if (newVal) {
|
||||
// 播放器显示时,重新设置背景颜色
|
||||
setTextColors(props.background);
|
||||
if (targetBackground.value) {
|
||||
setTextColors(targetBackground.value);
|
||||
}
|
||||
} else {
|
||||
showFullLyrics.value = false;
|
||||
if (autoScrollTimer.value) {
|
||||
|
||||
@@ -44,7 +44,7 @@ export const DEFAULT_LYRIC_CONFIG: LyricConfig = {
|
||||
hideMiniPlayBar: false,
|
||||
pureModeEnabled: false,
|
||||
hideLyrics: false,
|
||||
contentWidth: 100, // 默认100%宽度
|
||||
contentWidth: 75, // 默认100%宽度
|
||||
// 移动端默认配置
|
||||
mobileLayout: 'ios',
|
||||
mobileCoverStyle: 'full',
|
||||
|
||||
Reference in New Issue
Block a user