Skip to content

Commit 469e4b5

Browse files
authored
Merge pull request #710 from MoYingJi/pr/l
refactor(setting): 改个变量名什么的 还有一些小改
2 parents 9c29e00 + dcd8fc2 commit 469e4b5

7 files changed

Lines changed: 114 additions & 63 deletions

File tree

src/components/Layout/Menu.vue

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const menuOptions = computed<MenuOption[] | MenuGroupOption[]>(() => {
6666
key: "discover",
6767
link: "discover",
6868
label: "发现音乐",
69-
show: !settingStore.hideDiscover,
69+
show: !settingStore.sidebarHide.hideDiscover,
7070
icon: renderIcon("Discover", {
7171
style: {
7272
transform: "translateY(-1px)",
@@ -76,7 +76,7 @@ const menuOptions = computed<MenuOption[] | MenuGroupOption[]>(() => {
7676
{
7777
key: "personal-fm",
7878
label: "私人漫游",
79-
show: isLogin() !== 0 && !settingStore.hidePersonalFM,
79+
show: isLogin() !== 0 && !settingStore.sidebarHide.hidePersonalFM,
8080
icon: renderIcon("Radio", {
8181
style: {
8282
transform: "translateY(-1px)",
@@ -87,7 +87,7 @@ const menuOptions = computed<MenuOption[] | MenuGroupOption[]>(() => {
8787
key: "radio-hot",
8888
link: "radio-hot",
8989
label: "播客电台",
90-
show: !settingStore.hideRadioHot,
90+
show: !settingStore.sidebarHide.hideRadioHot,
9191
icon: renderIcon("Record", {
9292
style: {
9393
transform: "translateY(-1px)",
@@ -103,7 +103,7 @@ const menuOptions = computed<MenuOption[] | MenuGroupOption[]>(() => {
103103
label: () =>
104104
h("div", { class: "user-liked" }, [
105105
h(NText, null, () => "我喜欢的音乐"),
106-
!settingStore.hideHeartbeatMode
106+
!settingStore.sidebarHide.hideHeartbeatMode
107107
? h(NButton, {
108108
type: statusStore.shuffleMode === "heartbeat" ? "primary" : "default",
109109
round: true,
@@ -123,14 +123,14 @@ const menuOptions = computed<MenuOption[] | MenuGroupOption[]>(() => {
123123
key: "like",
124124
link: "like",
125125
label: "我的收藏",
126-
show: !settingStore.hideLike,
126+
show: !settingStore.sidebarHide.hideLike,
127127
icon: renderIcon("Star"),
128128
},
129129
{
130130
key: "cloud",
131131
link: "cloud",
132132
label: "我的云盘",
133-
show: isLogin() === 1 && !settingStore.hideCloud,
133+
show: isLogin() === 1 && !settingStore.sidebarHide.hideCloud,
134134
icon: renderIcon("Cloud"),
135135
},
136136
{
@@ -145,21 +145,21 @@ const menuOptions = computed<MenuOption[] | MenuGroupOption[]>(() => {
145145
},
146146
() => "下载管理",
147147
),
148-
show: statusStore.isDeveloperMode && isElectron && !settingStore.hideDownload,
148+
show: statusStore.isDeveloperMode && isElectron && !settingStore.sidebarHide.hideDownload,
149149
icon: renderIcon("Download"),
150150
},
151151
{
152152
key: "local",
153153
link: "local",
154154
label: "本地歌曲",
155-
show: isElectron && !settingStore.hideLocal,
155+
show: isElectron && !settingStore.sidebarHide.hideLocal,
156156
icon: renderIcon("FolderMusic"),
157157
},
158158
{
159159
key: "history",
160160
link: "history",
161161
label: "最近播放",
162-
show: !settingStore.hideHistory,
162+
show: !settingStore.sidebarHide.hideHistory,
163163
icon: renderIcon("History"),
164164
},
165165
{
@@ -169,7 +169,7 @@ const menuOptions = computed<MenuOption[] | MenuGroupOption[]>(() => {
169169
// 创建的歌单
170170
{
171171
key: "user-playlists",
172-
show: !settingStore.hideUserPlaylists,
172+
show: !settingStore.sidebarHide.hideUserPlaylists,
173173
icon: statusStore.menuCollapsed ? renderIcon("PlaylistAdd") : undefined,
174174
label: () =>
175175
h("div", { class: "user-list" }, [
@@ -191,7 +191,7 @@ const menuOptions = computed<MenuOption[] | MenuGroupOption[]>(() => {
191191
// 收藏的歌单
192192
{
193193
key: "liked-playlists",
194-
show: !settingStore.hideLikedPlaylists,
194+
show: !settingStore.sidebarHide.hideLikedPlaylists,
195195
icon: statusStore.menuCollapsed ? renderIcon("PlaylistAddCheck") : undefined,
196196
label: () =>
197197
h(

src/components/Modal/Setting/SidebarHideManager.vue

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
>
1616
<n-text class="name">{{ item.label }}</n-text>
1717
<n-switch
18-
:value="settingStore[item.key]"
18+
:value="settingStore.sidebarHide[item.key]"
1919
:round="false"
2020
@update:value="(val) => updateSetting(item.key, val)"
2121
/>
@@ -27,27 +27,37 @@
2727

2828
<script setup lang="ts">
2929
import { NScrollbar } from "naive-ui";
30-
import { useSettingStore } from "@/stores";
30+
import { useSettingStore, useStatusStore } from "@/stores";
31+
import { isElectron } from "@/utils/env";
3132
3233
const settingStore = useSettingStore();
34+
const statusStore = useStatusStore();
3335
34-
const sidebarItems = [
36+
type SidebarHideKey = keyof typeof settingStore.sidebarHide;
37+
type SidebarHideItem = { label: string, key: SidebarHideKey };
38+
39+
const when = (
40+
condition: boolean, ...item: SidebarHideItem[]
41+
): SidebarHideItem[] => {
42+
return condition ? item : [];
43+
}
44+
45+
const sidebarItems: SidebarHideItem[] = [
3546
{ label: "发现音乐", key: "hideDiscover" },
3647
{ label: "私人漫游", key: "hidePersonalFM" },
3748
{ label: "播客电台", key: "hideRadioHot" },
3849
{ label: "我的收藏", key: "hideLike" },
3950
{ label: "我的云盘", key: "hideCloud" },
40-
{ label: "下载管理", key: "hideDownload" },
41-
{ label: "本地歌曲", key: "hideLocal" },
51+
...when(isElectron && statusStore.isDeveloperMode, { label: "下载管理", key: "hideDownload" }),
52+
...when(isElectron, { label: "本地歌曲", key: "hideLocal" }),
4253
{ label: "最近播放", key: "hideHistory" },
4354
{ label: "创建的歌单", key: "hideUserPlaylists" },
4455
{ label: "收藏的歌单", key: "hideLikedPlaylists" },
4556
{ label: "心动模式", key: "hideHeartbeatMode" },
46-
] as const;
57+
];
4758
48-
const updateSetting = (key: keyof typeof settingStore, val: boolean) => {
49-
// @ts-ignore
50-
settingStore[key] = val;
59+
const updateSetting = (key: SidebarHideKey, val: boolean) => {
60+
settingStore.sidebarHide[key] = val;
5161
};
5262
</script>
5363

src/components/Setting/LyricsSetting.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
>
2424
<n-card class="warning" v-if="settingStore.useAMLyrics">
2525
<n-text>
26-
你已使用 Apple-Music-like Lyrics,实际显示效果可能与此处的预览有较大差别
26+
正在使用 Apple Music-like Lyrics,实际显示效果可能与此处的预览有较大差别
2727
</n-text>
2828
</n-card>
2929
<div v-for="item in 2" :key="item" :class="['lrc-item', { on: item === 2 }]">
@@ -293,9 +293,9 @@
293293
歌词支持逐字、翻译、音译等功能,将会在下一首歌生效
294294
</n-text>
295295
</div>
296-
<n-switch v-model:value="settingStore.enableTTMLLyric" class="set" :round="false" />
296+
<n-switch v-model:value="settingStore.enableOnlineTTMLLyric" class="set" :round="false" />
297297
</n-card>
298-
<n-collapse-transition :show="settingStore.enableTTMLLyric">
298+
<n-collapse-transition :show="settingStore.enableOnlineTTMLLyric">
299299
<n-card class="set-item">
300300
<div class="label">
301301
<n-text class="name">AMLL TTML DB 地址</n-text>

src/core/player/LyricManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class LyricManager {
162162
const isStale = () => this.activeLyricReq !== req || musicStore.playSong?.id !== id;
163163
// 处理 TTML 歌词
164164
const adoptTTML = async () => {
165-
if (!settingStore.enableTTMLLyric) return;
165+
if (!settingStore.enableOnlineTTMLLyric) return;
166166
let ttmlContent: string | null = await this.getRawLyricCache(id, "ttml");
167167
if (!ttmlContent) {
168168
ttmlContent = await songLyricTTML(id);

src/stores/migrations/settingMigrations.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { keywords, regexes } from "@/assets/data/exclude";
66
/**
77
* 当前设置 Schema 版本号
88
*/
9-
export const CURRENT_SETTING_SCHEMA_VERSION = 5;
9+
export const CURRENT_SETTING_SCHEMA_VERSION = 6;
1010

1111
/**
1212
* 迁移函数类型
@@ -77,5 +77,41 @@ export const settingMigrations: Record<number, MigrationFunction> = {
7777
excludeUserRegexes: userRegexes,
7878
};
7979
},
80+
6: (state) => {
81+
interface OldSettingState extends Partial<SettingState> {
82+
enableTTMLLyric?: boolean;
83+
84+
hideDiscover?: boolean;
85+
hidePersonalFM?: boolean;
86+
hideRadioHot?: boolean;
87+
hideLike?: boolean;
88+
hideCloud?: boolean;
89+
hideDownload?: boolean;
90+
hideLocal?: boolean;
91+
hideHistory?: boolean;
92+
hideUserPlaylists?: boolean;
93+
hideLikedPlaylists?: boolean;
94+
hideHeartbeatMode?: boolean;
95+
}
96+
const oldState = state as OldSettingState;
97+
98+
return {
99+
enableOnlineTTMLLyric: oldState.enableTTMLLyric,
100+
101+
sidebarHide: {
102+
hideDiscover: oldState.hideDiscover || false,
103+
hidePersonalFM: oldState.hidePersonalFM || false,
104+
hideRadioHot: oldState.hideRadioHot || false,
105+
hideLike: oldState.hideLike || false,
106+
hideCloud: oldState.hideCloud || false,
107+
hideDownload: oldState.hideDownload || false,
108+
hideLocal: oldState.hideLocal || false,
109+
hideHistory: oldState.hideHistory || false,
110+
hideUserPlaylists: oldState.hideUserPlaylists || false,
111+
hideLikedPlaylists: oldState.hideLikedPlaylists || false,
112+
hideHeartbeatMode: oldState.hideHeartbeatMode || false,
113+
},
114+
}
115+
},
80116
};
81117

src/stores/setting.ts

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ export interface SettingState {
165165
playSongDemo: boolean;
166166
/** 显示搜索历史 */
167167
showSearchHistory: boolean;
168-
/** 是否使用 AM 歌词 */
168+
/** 是否使用 AMLL 歌词 */
169169
useAMLyrics: boolean;
170-
/** 是否使用 AM 歌词弹簧效果 */
170+
/** 是否使用 AMLL 歌词弹簧效果 */
171171
useAMSpring: boolean;
172172
/** 隐藏已播放歌词 */
173173
hidePassedLines: boolean;
@@ -176,7 +176,7 @@ export interface SettingState {
176176
/** 歌词时延调节步长(毫秒) */
177177
lyricOffsetStep: number;
178178
/** 是否启用在线 TTML 歌词 */
179-
enableTTMLLyric: boolean;
179+
enableOnlineTTMLLyric: boolean;
180180
/** AMLL DB 服务地址 */
181181
amllDbServer: string;
182182
/** 菜单显示封面 */
@@ -229,28 +229,31 @@ export interface SettingState {
229229
showSongPrivilegeTag: boolean;
230230
/** 显示原唱翻唱标签 */
231231
showSongOriginalTag: boolean;
232-
/** 隐藏发现音乐 */
233-
hideDiscover: boolean;
234-
/** 隐藏私人漫游 */
235-
hidePersonalFM: boolean;
236-
/** 隐藏播客电台 */
237-
hideRadioHot: boolean;
238-
/** 隐藏我的收藏 */
239-
hideLike: boolean;
240-
/** 隐藏我的云盘 */
241-
hideCloud: boolean;
242-
/** 隐藏下载管理 */
243-
hideDownload: boolean;
244-
/** 隐藏本地歌曲 */
245-
hideLocal: boolean;
246-
/** 隐藏最近播放 */
247-
hideHistory: boolean;
248-
/** 隐藏创建的歌单 */
249-
hideUserPlaylists: boolean;
250-
/** 隐藏收藏的歌单 */
251-
hideLikedPlaylists: boolean;
252-
/** 隐藏心动模式 */
253-
hideHeartbeatMode: boolean;
232+
/** 侧边栏隐藏 */
233+
sidebarHide: {
234+
/** 隐藏发现音乐 */
235+
hideDiscover: boolean;
236+
/** 隐藏私人漫游 */
237+
hidePersonalFM: boolean;
238+
/** 隐藏播客电台 */
239+
hideRadioHot: boolean;
240+
/** 隐藏我的收藏 */
241+
hideLike: boolean;
242+
/** 隐藏我的云盘 */
243+
hideCloud: boolean;
244+
/** 隐藏下载管理 */
245+
hideDownload: boolean;
246+
/** 隐藏本地歌曲 */
247+
hideLocal: boolean;
248+
/** 隐藏最近播放 */
249+
hideHistory: boolean;
250+
/** 隐藏创建的歌单 */
251+
hideUserPlaylists: boolean;
252+
/** 隐藏收藏的歌单 */
253+
hideLikedPlaylists: boolean;
254+
/** 隐藏心动模式 */
255+
hideHeartbeatMode: boolean;
256+
};
254257
/** 启用搜索关键词获取 */
255258
enableSearchKeyword: boolean;
256259
/** 失焦后自动清空搜索框 */
@@ -362,7 +365,7 @@ export const useSettingStore = defineStore("setting", {
362365
hidePassedLines: false,
363366
wordFadeWidth: 0.5,
364367
lyricOffsetStep: 500,
365-
enableTTMLLyric: false,
368+
enableOnlineTTMLLyric: false,
366369
amllDbServer: defaultAMLLDbServer,
367370
showYrc: true,
368371
showYrcAnimation: true,
@@ -404,17 +407,19 @@ export const useSettingStore = defineStore("setting", {
404407
showSongQuality: true,
405408
showSongPrivilegeTag: true,
406409
showSongOriginalTag: true,
407-
hideDiscover: false,
408-
hidePersonalFM: false,
409-
hideRadioHot: false,
410-
hideLike: false,
411-
hideCloud: false,
412-
hideDownload: false,
413-
hideLocal: false,
414-
hideHistory: false,
415-
hideUserPlaylists: false,
416-
hideLikedPlaylists: false,
417-
hideHeartbeatMode: false,
410+
sidebarHide: {
411+
hideDiscover: false,
412+
hidePersonalFM: false,
413+
hideRadioHot: false,
414+
hideLike: false,
415+
hideCloud: false,
416+
hideDownload: false,
417+
hideLocal: false,
418+
hideHistory: false,
419+
hideUserPlaylists: false,
420+
hideLikedPlaylists: false,
421+
hideHeartbeatMode: false,
422+
},
418423
enableSearchKeyword: true,
419424
clearSearchOnBlur: false,
420425
homePageSections: [

src/stores/status.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ interface StatusState {
5252
};
5353
/** 纯净歌词模式 */
5454
pureLyricMode: boolean;
55-
/** 是否使用 TTML 歌词 */
55+
/** 当前是否正使用 TTML 歌词 */
5656
usingTTMLLyric: boolean;
5757
/** 当前歌曲音质 */
5858
songQuality: QualityType | undefined;

0 commit comments

Comments
 (0)