Skip to content

Commit 498293f

Browse files
authored
Merge pull request #669 from MoYingJi/pr/f
refactor(font): 重构歌词字体配置管理
2 parents b91fc41 + 74e7146 commit 498293f

File tree

4 files changed

+68
-52
lines changed

4 files changed

+68
-52
lines changed

src/components/Modal/Setting/FontManager.vue

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -46,34 +46,34 @@
4646

4747
<div class="set-list">
4848
<n-h3 prefix="bar">歌词字体</n-h3>
49-
<n-card v-for="font in lyricFontConfigs" :key="font.key" class="set-item">
49+
<n-card v-for="font in lyricFontConfigs" :key="font.keySetting" class="set-item">
5050
<div class="label">
5151
<n-text class="name">{{ font.name }}</n-text>
5252
<n-text class="tip" :depth="3">{{ font.tip }}</n-text>
5353
</div>
5454
<n-flex align="center">
5555
<Transition name="fade" mode="out-in">
5656
<n-button
57-
v-if="settingStore[font.key] !== font.default"
57+
v-if="settingStore[font.keySetting] !== font.default"
5858
type="primary"
5959
strong
6060
secondary
61-
@click="settingStore[font.key] = font.default"
61+
@click="settingStore[font.keySetting] = font.default"
6262
>
6363
恢复默认
6464
</n-button>
6565
</Transition>
6666
<s-input
6767
v-if="settingStore.useCustomFont || !isElectron"
68-
v-model:value="settingStore[font.key]"
68+
v-model:value="settingStore[font.keySetting]"
6969
:update-value-on-input="false"
7070
placeholder="输入字体名称"
7171
class="set"
7272
/>
7373
<n-select
7474
v-else
75-
v-model:value="settingStore[font.key]"
76-
:options="getOptions(font.key)"
75+
v-model:value="settingStore[font.keySetting]"
76+
:options="getOptions(font.keySetting)"
7777
class="set"
7878
filterable
7979
/>
@@ -87,43 +87,10 @@
8787
import { useSettingStore } from "@/stores";
8888
import { isElectron } from "@/utils/env";
8989
import type { SelectOption } from "naive-ui";
90+
import { lyricFontConfigs } from "@/utils/lyricFontConfig";
9091
9192
const settingStore = useSettingStore();
9293
93-
interface FontConfig {
94-
name: string;
95-
key: "globalFont" | "LyricFont" | "japaneseLyricFont" | "englishLyricFont" | "koreanLyricFont";
96-
default: string;
97-
tip: string;
98-
}
99-
100-
const lyricFontConfigs: FontConfig[] = [
101-
{
102-
name: "歌词区域字体",
103-
key: "LyricFont",
104-
default: "follow",
105-
tip: "主歌词区域的基础字体",
106-
},
107-
{
108-
name: "英语歌词字体",
109-
key: "englishLyricFont",
110-
default: "follow",
111-
tip: "当歌词包含英语时使用的特定字体",
112-
},
113-
{
114-
name: "日语歌词字体",
115-
key: "japaneseLyricFont",
116-
default: "follow",
117-
tip: "当歌词包含日语时使用的特定字体",
118-
},
119-
{
120-
name: "韩语歌词字体",
121-
key: "koreanLyricFont",
122-
default: "follow",
123-
tip: "当歌词包含韩语时使用的特定字体",
124-
},
125-
];
126-
12794
// 系统字体选项
12895
const systemFonts = ref<SelectOption[]>([]);
12996

src/components/Player/MainAMLyric.vue

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,9 @@
2424
:wordFadeWidth="settingStore.wordFadeWidth"
2525
:style="{
2626
'--amll-lp-font-size': settingStore.lyricFontSize + 'px',
27-
'--ja-font-family':
28-
settingStore.japaneseLyricFont !== 'follow' ? settingStore.japaneseLyricFont : '',
29-
'--en-font-family':
30-
settingStore.englishLyricFont !== 'follow' ? settingStore.englishLyricFont : '',
31-
'--ko-font-family':
32-
settingStore.koreanLyricFont !== 'follow' ? settingStore.koreanLyricFont : '',
3327
'font-weight': settingStore.lyricFontBold ? 'bold' : 'normal',
3428
'font-family': settingStore.LyricFont !== 'follow' ? settingStore.LyricFont : '',
29+
...lyricLangFontStyle(settingStore),
3530
}"
3631
class="am-lyric"
3732
@line-click="jumpSeek"
@@ -50,6 +45,7 @@ import { getLyricLanguage } from "@/utils/format";
5045
import { usePlayerController } from "@/core/player/PlayerController";
5146
import { cloneDeep } from "lodash-es";
5247
import "@applemusic-like-lyrics/core/style.css";
48+
import { lyricLangFontStyle } from "@/utils/lyricFontConfig";
5349
5450
const musicStore = useMusicStore();
5551
const statusStore = useStatusStore();

src/components/Player/MainLyric.vue

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,9 @@
66
'--lrc-tran-size': settingStore.lyricTranFontSize + 'px',
77
'--lrc-roma-size': settingStore.lyricRomaFontSize + 'px',
88
'--lrc-bold': settingStore.lyricFontBold ? 'bold' : 'normal',
9-
'--ja-font-family':
10-
settingStore.japaneseLyricFont !== 'follow' ? settingStore.japaneseLyricFont : '',
11-
'--en-font-family':
12-
settingStore.englishLyricFont !== 'follow' ? settingStore.englishLyricFont : '',
13-
'--ko-font-family':
14-
settingStore.koreanLyricFont !== 'follow' ? settingStore.koreanLyricFont : '',
159
'font-family': settingStore.LyricFont !== 'follow' ? settingStore.LyricFont : '',
1610
cursor: statusStore.playerMetaShow ? 'auto' : 'none',
11+
...lyricLangFontStyle(settingStore),
1712
}"
1813
:class="[
1914
'lyric',
@@ -169,6 +164,7 @@ import { useMusicStore, useSettingStore, useStatusStore } from "@/stores";
169164
import { usePlayerController } from "@/core/player/PlayerController";
170165
import { getLyricLanguage } from "@/utils/format";
171166
import { isElectron } from "@/utils/env";
167+
import { lyricLangFontStyle } from "@/utils/lyricFontConfig";
172168
173169
const musicStore = useMusicStore();
174170
const statusStore = useStatusStore();

src/utils/lyricFontConfig.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { useSettingStore } from "@/stores";
2+
3+
export interface LyricFontConfig {
4+
name: string;
5+
keySetting: "LyricFont" | "japaneseLyricFont" | "englishLyricFont" | "koreanLyricFont";
6+
default: string;
7+
tip: string;
8+
}
9+
10+
export interface LyricLangFontConfig extends LyricFontConfig {
11+
keyCss: string;
12+
}
13+
14+
export const lyricLangFontConfigs: LyricLangFontConfig[] = [
15+
{
16+
name: "英语歌词字体",
17+
keySetting: "englishLyricFont",
18+
keyCss: "--en-font-family",
19+
default: "follow",
20+
tip: "当歌词包含英语时使用的特定字体",
21+
},
22+
{
23+
name: "日语歌词字体",
24+
keySetting: "japaneseLyricFont",
25+
keyCss: "--ja-font-family",
26+
default: "follow",
27+
tip: "当歌词包含日语时使用的特定字体",
28+
},
29+
{
30+
name: "韩语歌词字体",
31+
keySetting: "koreanLyricFont",
32+
keyCss: "--ko-font-family",
33+
default: "follow",
34+
tip: "当歌词包含韩语时使用的特定字体",
35+
},
36+
];
37+
38+
export const lyricFontConfigs: LyricFontConfig[] = [
39+
{
40+
name: "歌词区域字体",
41+
keySetting: "LyricFont",
42+
default: "follow",
43+
tip: "主歌词区域的基础字体",
44+
},
45+
...lyricLangFontConfigs,
46+
];
47+
48+
export const lyricLangFontStyle = (
49+
settingStore = useSettingStore()
50+
) => {
51+
return Object.fromEntries(
52+
lyricLangFontConfigs.map((c) => {
53+
const settingValue = settingStore[c.keySetting];
54+
return [c.keyCss, settingValue !== c.default ? settingValue : ""];
55+
}),
56+
);
57+
};

0 commit comments

Comments
 (0)