Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ declare module 'vue' {
ExcludeLyrics: typeof import('./src/components/Modal/ExcludeLyrics.vue')['default']
FullPlayer: typeof import('./src/components/Player/FullPlayer.vue')['default']
GeneralSetting: typeof import('./src/components/Setting/GeneralSetting.vue')['default']
HomePageSectionManager: typeof import('./src/components/Modal/HomePageSectionManager.vue')['default']
JumpArtist: typeof import('./src/components/Modal/JumpArtist.vue')['default']
KeyboardSetting: typeof import('./src/components/Setting/KeyboardSetting.vue')['default']
LocalSetting: typeof import('./src/components/Setting/LocalSetting.vue')['default']
Expand Down
73 changes: 73 additions & 0 deletions src/components/Modal/HomePageSectionManager.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<template>
<div class="home-page-section-manager">
<div ref="sortableRef" class="sortable-list">
<n-card
v-for="item in settingStore.homePageSections"
:key="item.key"
:content-style="{
display: 'flex',
alignItems: 'center',
gap: '12px',
padding: '16px',
}"
class="sortable-item"
>
<SvgIcon :depth="3" name="Menu" />
<n-text class="name">{{ item.name }}</n-text>
<n-switch v-model:value="item.visible" :round="false" />
</n-card>
</div>
</div>
</template>

<script setup lang="ts">
import { useSettingStore } from "@/stores";
import { useSortable } from "@vueuse/integrations/useSortable";
import SvgIcon from "@/components/Global/SvgIcon.vue";

const settingStore = useSettingStore();

const sortableRef = ref<HTMLElement | null>(null);

// 更新排序值
const updateSortOrder = () => {
settingStore.homePageSections.forEach((item, index) => {
item.order = index;
});
};

// 拖拽
useSortable(sortableRef, settingStore.homePageSections, {
animation: 150,
handle: ".n-icon",
Comment thread
SUBearH marked this conversation as resolved.
onEnd: updateSortOrder,
});

onMounted(() => {
// 初始化排序值
updateSortOrder();
});
Comment thread
SUBearH marked this conversation as resolved.
</script>

<style scoped lang="scss">
.sortable-list {
margin-top: 12px;
display: flex;
flex-direction: column;
gap: 12px;
.sortable-item {
border-radius: 8px;
.n-icon {
font-size: 16px;
cursor: move;
}
.name {
font-size: 16px;
line-height: normal;
}
.n-switch {
margin-left: auto;
}
}
}
</style>
16 changes: 15 additions & 1 deletion src/components/Setting/GeneralSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,20 @@
配置
</n-button>
</n-card>
<n-card class="set-item">
<div class="label">
<n-text class="name">首页栏目配置</n-text>
<n-text class="tip" :depth="3">调整首页各栏目的显示顺序或隐藏不需要的栏目</n-text>
</div>
<n-button
type="primary"
strong
secondary
@click="openHomePageSectionManager"
>
配置
</n-button>
</n-card>
<n-card class="set-item">
<div class="label">
<n-text class="name">显示歌曲音质</n-text>
Expand Down Expand Up @@ -331,7 +345,7 @@ import { isDev, isElectron } from "@/utils/env";
import { getCoverColor } from "@/utils/player-utils/song";
import { isEmpty } from "lodash-es";
import themeColor from "@/assets/data/themeColor.json";
import { openSidebarHideManager } from "@/utils/modal";
import { openSidebarHideManager, openHomePageSectionManager } from "@/utils/modal";

const dataStore = useDataStore();
const musicStore = useMusicStore();
Expand Down
15 changes: 15 additions & 0 deletions src/stores/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,13 @@ export interface SettingState {
appLaunchCount: number;
/** 隐藏 Star 弹窗 */
hideStarPopup: boolean;
/** 首页栏目顺序和显示配置 */
homePageSections: Array<{
key: "playlist" | "radar" | "artist" | "video" | "radio" | "album";
name: string;
visible: boolean;
order: number;
}>;
}

export const useSettingStore = defineStore("setting", {
Expand Down Expand Up @@ -309,6 +316,14 @@ export const useSettingStore = defineStore("setting", {
enableSearchKeyword: true,
appLaunchCount: 0,
hideStarPopup: true,
homePageSections: [
{ key: "playlist", name: "专属歌单", visible: true, order: 0 },
{ key: "radar", name: "雷达歌单", visible: true, order: 1 },
{ key: "artist", name: "歌手推荐", visible: true, order: 2 },
{ key: "video", name: "推荐 MV", visible: true, order: 3 },
{ key: "radio", name: "推荐播客", visible: true, order: 4 },
{ key: "album", name: "新碟上架", visible: true, order: 5 },
],
}),
getters: {
/**
Expand Down
15 changes: 15 additions & 0 deletions src/utils/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import AutoClose from "@/components/Modal/AutoClose.vue";
import Equalizer from "@/components/Modal/Equalizer.vue";
import SongUnlockManager from "@/components/Modal/SongUnlockManager.vue";
import SidebarHideManager from "@/components/Modal/SidebarHideManager.vue";
import HomePageSectionManager from "@/components/Modal/HomePageSectionManager.vue";
import { NScrollbar } from "naive-ui";

// 用户协议
Expand Down Expand Up @@ -349,3 +350,17 @@ export const openSidebarHideManager = () => {
},
});
};

/** 打开首页栏目配置弹窗 */
export const openHomePageSectionManager = () => {
window.$modal.create({
preset: "card",
transformOrigin: "center",
autoFocus: false,
style: { width: "500px" },
title: "首页栏目配置",
content: () => {
return h(HomePageSectionManager);
},
});
};
18 changes: 16 additions & 2 deletions src/views/Home/HomeOnline.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</n-gi>
</n-grid>
<!-- 公共推荐 -->
<div v-for="(item, index) in recData" :key="index" class="rec-public">
<div v-for="(item, index) in sortedRecData" :key="index" class="rec-public">
<n-flex
class="title"
align="center"
Expand All @@ -52,7 +52,7 @@
<script setup lang="ts">
import type { ArtistType, CoverType } from "@/types/main";
import { NText } from "naive-ui";
import { useDataStore, useMusicStore } from "@/stores";
import { useDataStore, useMusicStore, useSettingStore } from "@/stores";
import { newAlbumsAll, personalized, radarPlaylist, topArtists } from "@/api/rec";
import { allMv } from "@/api/video";
import { radioRecommend } from "@/api/radio";
Expand Down Expand Up @@ -82,6 +82,7 @@ interface RecDataType {
const router = useRouter();
const dataStore = useDataStore();
const musicStore = useMusicStore();
const settingStore = useSettingStore();

// 日推标题
const dailySongsTitle = computed(() => {
Expand Down Expand Up @@ -133,6 +134,19 @@ const recData = ref<RecDataType>({
},
});

// 根据设置过滤和排序推荐数据
const sortedRecData = computed(() => {
const sections = settingStore.homePageSections
.filter((section) => section.visible)
.sort((a, b) => a.order - b.order)
.map((section) => {
const key = section.key as keyof RecDataType;
return recData.value[key];
})
.filter((item) => item);
Comment thread
SUBearH marked this conversation as resolved.
return sections;
});

// 获取全部推荐
const getAllRecData = async () => {
try {
Expand Down
2 changes: 1 addition & 1 deletion src/views/List/liked.vue
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
</n-button>
</n-dropdown>
</n-flex>
<n-flex class="right">
<n-flex class="right" align="center">
<!-- 模糊搜索 -->
<n-input
v-if="playlistData?.length"
Expand Down
2 changes: 1 addition & 1 deletion src/views/List/playlist.vue
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
</n-button>
</n-dropdown>
</n-flex>
<n-flex class="right">
<n-flex class="right" align="center">
<!-- 模糊搜索 -->
<n-input
v-if="playlistData?.length"
Expand Down