Skip to content

Commit 0ecf0e1

Browse files
committed
feat: 列表排序持久化 #82
1 parent 8b9a91f commit 0ecf0e1

3 files changed

Lines changed: 39 additions & 29 deletions

File tree

‎src/components/list/SongList.vue‎

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script setup lang="ts">
22
import type { Artist, Track, TrackSource } from "@shared/types/player";
33
import type { CollectionType } from "@/types/collection";
4+
import type { SortField } from "@/types/list";
45
import { useMediaStore } from "@/stores/media";
56
import { useStatusStore } from "@/stores/status";
67
import { useSettingsStore } from "@/stores/settings";
@@ -121,24 +122,7 @@ const goAlbum = (item: Track): void => {
121122
};
122123
123124
/** 排序字段 */
124-
type SortField =
125-
| "none"
126-
| "title"
127-
| "artist"
128-
| "album"
129-
| "path"
130-
| "duration"
131-
| "size"
132-
| "mtime"
133-
| "ctime"
134-
| "track";
135-
/** 排序方向 */
136-
type SortOrder = "asc" | "desc";
137-
138-
/** 排序字段 */
139-
const sortField = ref<SortField>("none");
140-
/** 排序方向 */
141-
const sortOrder = ref<SortOrder>("asc");
125+
const { sortField, sortOrder } = storeToRefs(status);
142126
143127
/** 字段文案 key 映射 */
144128
const sortFieldLabelKeyMap: Record<SortField, string> = {

‎src/stores/status.ts‎

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import type {
77
} from "@shared/types/player";
88
import type { Platform } from "@shared/types/platform";
99
import type { ContentScope } from "@/types/collection";
10+
import type { SortField, SortOrder } from "@/types/list";
1011
export type { RepeatMode, ShuffleMode } from "@shared/types/player";
12+
export type { SortField, SortOrder } from "@/types/list";
1113
import * as queue from "./queue";
1214

1315
export const useStatusStore = defineStore(
@@ -81,6 +83,10 @@ export const useStatusStore = defineStore(
8183
const likedPageTab = ref<ContentScope>("local");
8284
/** 设置弹窗上次手动选择的大分类 */
8385
const settingsCategory = ref("");
86+
/** 歌曲列表排序字段 */
87+
const sortField = ref<SortField>("none");
88+
/** 歌曲列表排序方向 */
89+
const sortOrder = ref<SortOrder>("asc");
8490
/** 是否正在播放 */
8591
const isPlaying = computed(() => state.value === "playing");
8692
/** 是否暂停 */
@@ -136,24 +142,29 @@ export const useStatusStore = defineStore(
136142
myPlaylistSource,
137143
likedPageTab,
138144
settingsCategory,
145+
sortField,
146+
sortOrder,
139147
currentTrack,
140148
showComments,
141149
};
142150
},
143151
{
144152
persist: {
145153
storage: localStorage,
146-
pick: [
147-
"playIndex",
148-
"repeatMode",
149-
"shuffleMode",
150-
"heartMode",
151-
"volume",
152-
"position",
153-
"searchPlatform",
154-
"myPlaylistSource",
155-
"likedPageTab",
156-
"settingsCategory",
154+
omit: [
155+
"state",
156+
"duration",
157+
"currentSource",
158+
"outputDevices",
159+
"trackLoading",
160+
"outerQueueOpen",
161+
"fullQueueOpen",
162+
"searchOpen",
163+
"commentsOpen",
164+
"commentsTrack",
165+
"autoClose",
166+
"abLoop",
167+
"lyricOffsetMs",
157168
],
158169
},
159170
},

‎src/types/list.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/** 歌曲列表排序字段 */
2+
export type SortField =
3+
| "none"
4+
| "title"
5+
| "artist"
6+
| "album"
7+
| "path"
8+
| "duration"
9+
| "size"
10+
| "mtime"
11+
| "ctime"
12+
| "track";
13+
14+
/** 歌曲列表排序方向 */
15+
export type SortOrder = "asc" | "desc";

0 commit comments

Comments
 (0)