Skip to content

Commit 8ee3709

Browse files
✨ feat: 添加自定义隐藏侧边栏
1 parent 69ae338 commit 8ee3709

7 files changed

Lines changed: 185 additions & 44 deletions

File tree

auto-eslint.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ export default {
5959
"isRef": true,
6060
"isShallow": true,
6161
"makeDestructurable": true,
62-
"manualResetRef": true,
6362
"markRaw": true,
6463
"nextTick": true,
6564
"onActivated": true,
@@ -97,11 +96,11 @@ export default {
9796
"refAutoReset": true,
9897
"refDebounced": true,
9998
"refDefault": true,
100-
"refManualReset": true,
10199
"refThrottled": true,
102100
"refWithControl": true,
103101
"resolveComponent": true,
104102
"resolveRef": true,
103+
"resolveUnref": true,
105104
"shallowReactive": true,
106105
"shallowReadonly": true,
107106
"shallowRef": true,

components.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ declare module 'vue' {
139139
SearchInp: typeof import('./src/components/Search/SearchInp.vue')['default']
140140
SearchInpMenu: typeof import('./src/components/Menu/SearchInpMenu.vue')['default']
141141
SearchSuggest: typeof import('./src/components/Search/SearchSuggest.vue')['default']
142+
SidebarHideManager: typeof import('./src/components/Modal/SidebarHideManager.vue')['default']
142143
Sider: typeof import('./src/components/Layout/Sider.vue')['default']
143144
SImage: typeof import('./src/components/UI/s-image.vue')['default']
144145
SongCard: typeof import('./src/components/Card/SongCard.vue')['default']

src/components/Layout/Menu.vue

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
:collapsed="statusStore.menuCollapsed"
1010
:collapsed-width="64"
1111
:collapsed-icon-size="22"
12-
:default-expand-all="true"
12+
v-model:expanded-keys="settingStore.menuExpandedKeys"
1313
:options="menuOptions"
1414
:render-label="renderMenuLabel"
1515
@update:value="menuUpdate"
@@ -65,6 +65,7 @@ const menuOptions = computed<MenuOption[] | MenuGroupOption[]>(() => {
6565
key: "discover",
6666
link: "discover",
6767
label: "发现音乐",
68+
show: !settingStore.hideDiscover,
6869
icon: renderIcon("Discover", {
6970
style: {
7071
transform: "translateY(-1px)",
@@ -74,7 +75,7 @@ const menuOptions = computed<MenuOption[] | MenuGroupOption[]>(() => {
7475
{
7576
key: "personal-fm",
7677
label: "私人漫游",
77-
show: isLogin() !== 0,
78+
show: isLogin() !== 0 && !settingStore.hidePersonalFM,
7879
icon: renderIcon("Radio", {
7980
style: {
8081
transform: "translateY(-1px)",
@@ -85,6 +86,7 @@ const menuOptions = computed<MenuOption[] | MenuGroupOption[]>(() => {
8586
key: "radio-hot",
8687
link: "radio-hot",
8788
label: "播客电台",
89+
show: !settingStore.hideRadioHot,
8890
icon: renderIcon("Record", {
8991
style: {
9092
transform: "translateY(-1px)",
@@ -100,44 +102,48 @@ const menuOptions = computed<MenuOption[] | MenuGroupOption[]>(() => {
100102
label: () =>
101103
h("div", { class: "user-liked" }, [
102104
h(NText, null, () => "我喜欢的音乐"),
103-
h(NButton, {
104-
type: "tertiary",
105-
round: true,
106-
strong: true,
107-
secondary: true,
108-
renderIcon: renderIcon("HeartBit"),
109-
onClick: (event: Event) => {
110-
event.stopPropagation();
111-
openHeartMode();
112-
},
113-
}),
105+
!settingStore.hideHeartbeatMode
106+
? h(NButton, {
107+
type: "tertiary",
108+
round: true,
109+
strong: true,
110+
secondary: true,
111+
renderIcon: renderIcon("HeartBit"),
112+
onClick: (event: Event) => {
113+
event.stopPropagation();
114+
openHeartMode();
115+
},
116+
})
117+
: null,
114118
]),
115119
icon: renderIcon("Favorite"),
116120
},
117121
{
118122
key: "like",
119123
link: "like",
120124
label: "我的收藏",
125+
show: !settingStore.hideLike,
121126
icon: renderIcon("Star"),
122127
},
123128
{
124129
key: "cloud",
125130
link: "cloud",
126131
label: "我的云盘",
127-
show: isLogin() === 1,
132+
show: isLogin() === 1 && !settingStore.hideCloud,
128133
icon: renderIcon("Cloud"),
129134
},
130135
{
131136
key: "local",
132137
link: "local",
133138
label: "本地歌曲",
134-
show: isElectron,
139+
show: isElectron && !settingStore.hideLocal,
135140
icon: renderIcon("FolderMusic"),
136141
},
137142
{
138143
key: "history",
139144
link: "history",
140145
label: "最近播放",
146+
show: !settingStore.hideHistory,
141147
icon: renderIcon("History"),
142148
},
143149
{
@@ -147,6 +153,7 @@ const menuOptions = computed<MenuOption[] | MenuGroupOption[]>(() => {
147153
// 创建的歌单
148154
{
149155
key: "user-playlists",
156+
show: !settingStore.hideUserPlaylists,
150157
icon: statusStore.menuCollapsed ? renderIcon("PlaylistAdd") : undefined,
151158
label: () =>
152159
h("div", { class: "user-list" }, [
@@ -168,6 +175,7 @@ const menuOptions = computed<MenuOption[] | MenuGroupOption[]>(() => {
168175
// 收藏的歌单
169176
{
170177
key: "liked-playlists",
178+
show: !settingStore.hideLikedPlaylists,
171179
icon: statusStore.menuCollapsed ? renderIcon("PlaylistAddCheck") : undefined,
172180
label: () =>
173181
h(
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<template>
2+
<div class="sidebar-hide-manager">
3+
<n-scrollbar style="max-height: 400px" trigger="none">
4+
<div class="list">
5+
<n-card
6+
v-for="item in sidebarItems"
7+
:key="item.key"
8+
:content-style="{
9+
display: 'flex',
10+
alignItems: 'center',
11+
gap: '12px',
12+
padding: '16px',
13+
}"
14+
class="item"
15+
>
16+
<n-text class="name">{{ item.label }}</n-text>
17+
<n-switch
18+
:value="settingStore[item.key]"
19+
:round="false"
20+
@update:value="(val) => updateSetting(item.key, val)"
21+
/>
22+
</n-card>
23+
</div>
24+
</n-scrollbar>
25+
</div>
26+
</template>
27+
28+
<script setup lang="ts">
29+
import { NScrollbar } from "naive-ui";
30+
import { useSettingStore } from "@/stores";
31+
32+
const settingStore = useSettingStore();
33+
34+
const sidebarItems = [
35+
{ label: "发现音乐", key: "hideDiscover" },
36+
{ label: "私人漫游", key: "hidePersonalFM" },
37+
{ label: "播客电台", key: "hideRadioHot" },
38+
{ label: "我的收藏", key: "hideLike" },
39+
{ label: "我的云盘", key: "hideCloud" },
40+
{ label: "本地歌曲", key: "hideLocal" },
41+
{ label: "最近播放", key: "hideHistory" },
42+
{ label: "创建的歌单", key: "hideUserPlaylists" },
43+
{ label: "收藏的歌单", key: "hideLikedPlaylists" },
44+
{ label: "心动模式", key: "hideHeartbeatMode" },
45+
] as const;
46+
47+
const updateSetting = (key: keyof typeof settingStore, val: boolean) => {
48+
// @ts-ignore
49+
settingStore[key] = val;
50+
};
51+
</script>
52+
53+
<style scoped lang="scss">
54+
.list {
55+
margin-top: 12px;
56+
padding-right: 12px;
57+
display: flex;
58+
flex-direction: column;
59+
gap: 12px;
60+
.item {
61+
border-radius: 8px;
62+
.name {
63+
font-size: 16px;
64+
line-height: normal;
65+
}
66+
.n-switch {
67+
margin-left: auto;
68+
}
69+
}
70+
}
71+
</style>

src/components/Setting/GeneralSetting.vue

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,20 @@
9595
</div>
9696
<n-switch class="set" v-model:value="settingStore.menuShowCover" :round="false" />
9797
</n-card>
98+
<n-card class="set-item">
99+
<div class="label">
100+
<n-text class="name">侧边栏隐藏</n-text>
101+
<n-text class="tip" :depth="3">配置需要在侧边栏隐藏的菜单项</n-text>
102+
</div>
103+
<n-button
104+
type="primary"
105+
strong
106+
secondary
107+
@click="openSidebarHideManager"
108+
>
109+
配置
110+
</n-button>
111+
</n-card>
98112
<n-card class="set-item">
99113
<div class="label">
100114
<n-text class="name">显示歌曲音质</n-text>
@@ -310,6 +324,7 @@ import { isDev, isElectron } from "@/utils/env";
310324
import { getCoverColor } from "@/utils/player-utils/song";
311325
import { isEmpty } from "lodash-es";
312326
import themeColor from "@/assets/data/themeColor.json";
327+
import { openSidebarHideManager } from "@/utils/modal";
313328
314329
const dataStore = useDataStore();
315330
const musicStore = useMusicStore();

src/stores/setting.ts

Lines changed: 57 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ export interface SettingState {
77
themeMode: "light" | "dark" | "auto";
88
/** 主题类别 */
99
themeColorType:
10-
| "default"
11-
| "orange"
12-
| "blue"
13-
| "pink"
14-
| "brown"
15-
| "indigo"
16-
| "green"
17-
| "purple"
18-
| "yellow"
19-
| "teal"
20-
| "custom";
10+
| "default"
11+
| "orange"
12+
| "blue"
13+
| "pink"
14+
| "brown"
15+
| "indigo"
16+
| "green"
17+
| "purple"
18+
| "yellow"
19+
| "teal"
20+
| "custom";
2121
/** 主题自定义颜色 */
2222
themeCustomColor: string;
2323
/** 全局着色 */
@@ -82,14 +82,14 @@ export interface SettingState {
8282
proxyPort: number;
8383
/** 歌曲音质 */
8484
songLevel:
85-
| "standard"
86-
| "higher"
87-
| "exhigh"
88-
| "lossless"
89-
| "hires"
90-
| "jyeffect"
91-
| "sky"
92-
| "jymaster";
85+
| "standard"
86+
| "higher"
87+
| "exhigh"
88+
| "lossless"
89+
| "hires"
90+
| "jyeffect"
91+
| "sky"
92+
| "jymaster";
9393
/** 播放设备 */
9494
playDevice: "default" | string;
9595
/** 自动播放 */
@@ -138,6 +138,8 @@ export interface SettingState {
138138
enableTTMLLyric: boolean;
139139
/** 菜单显示封面 */
140140
menuShowCover: boolean;
141+
/** 菜单展开项 */
142+
menuExpandedKeys: string[];
141143
/** 是否禁止休眠 */
142144
preventSleep: boolean;
143145
/** 本地文件路径 */
@@ -180,6 +182,26 @@ export interface SettingState {
180182
showSongPrivilegeTag: boolean;
181183
/** 显示原唱翻唱标签 */
182184
showSongOriginalTag: boolean;
185+
/** 隐藏发现音乐 */
186+
hideDiscover: boolean;
187+
/** 隐藏私人漫游 */
188+
hidePersonalFM: boolean;
189+
/** 隐藏播客电台 */
190+
hideRadioHot: boolean;
191+
/** 隐藏我的收藏 */
192+
hideLike: boolean;
193+
/** 隐藏我的云盘 */
194+
hideCloud: boolean;
195+
/** 隐藏本地歌曲 */
196+
hideLocal: boolean;
197+
/** 隐藏最近播放 */
198+
hideHistory: boolean;
199+
/** 隐藏创建的歌单 */
200+
hideUserPlaylists: boolean;
201+
/** 隐藏收藏的歌单 */
202+
hideLikedPlaylists: boolean;
203+
/** 隐藏心动模式 */
204+
hideHeartbeatMode: boolean;
183205
}
184206

185207
export const useSettingStore = defineStore("setting", {
@@ -195,6 +217,7 @@ export const useSettingStore = defineStore("setting", {
195217
hideVipTag: false,
196218
showSearchHistory: true,
197219
menuShowCover: true,
220+
menuExpandedKeys: [],
198221
routeAnimation: "slide",
199222
useOnlineService: true,
200223
showCloseAppTip: true,
@@ -267,6 +290,16 @@ export const useSettingStore = defineStore("setting", {
267290
showSongQuality: true,
268291
showSongPrivilegeTag: true,
269292
showSongOriginalTag: true,
293+
hideDiscover: false,
294+
hidePersonalFM: false,
295+
hideRadioHot: false,
296+
hideLike: false,
297+
hideCloud: false,
298+
hideLocal: false,
299+
hideHistory: false,
300+
hideUserPlaylists: false,
301+
hideLikedPlaylists: false,
302+
hideHeartbeatMode: false,
270303
}),
271304
getters: {
272305
/**
@@ -294,12 +327,11 @@ export const useSettingStore = defineStore("setting", {
294327
}
295328
window.$message.info(
296329
`已切换至
297-
${
298-
this.themeMode === "auto"
299-
? "跟随系统"
300-
: this.themeMode === "light"
301-
? "浅色模式"
302-
: "深色模式"
330+
${this.themeMode === "auto"
331+
? "跟随系统"
332+
: this.themeMode === "light"
333+
? "浅色模式"
334+
: "深色模式"
303335
}`,
304336
{
305337
showIcon: false,

0 commit comments

Comments
 (0)