@@ -7,7 +7,7 @@ import type {
77} from "@shared/types/player" ;
88import type { Platform } from "@shared/types/platform" ;
99import type { ContentScope } from "@/types/collection" ;
10- import type { SortField , SortOrder } from "@/types/list" ;
10+ import type { SongListSortKey , SongListSortPreference } from "@/types/list" ;
1111import type { PersonalFmOptions } from "@shared/types/platform/netease" ;
1212import * as queue from "./queue" ;
1313
@@ -88,10 +88,31 @@ export const useStatusStore = defineStore(
8888 const likedPageTab = ref < ContentScope > ( "local" ) ;
8989 /** 设置弹窗上次手动选择的大分类 */
9090 const settingsCategory = ref ( "" ) ;
91- /** 歌曲列表排序字段 */
92- const sortField = ref < SortField > ( "none" ) ;
93- /** 歌曲列表排序方向 */
94- const sortOrder = ref < SortOrder > ( "asc" ) ;
91+ /** 各列表作用域的排序偏好,仅保存非默认项 */
92+ const sortPreferences = ref < Partial < Record < SongListSortKey , SongListSortPreference > > > ( { } ) ;
93+
94+ /**
95+ * 读取指定作用域的排序偏好
96+ * @param key - 列表排序作用域
97+ * @returns 排序偏好,未设置时为默认值
98+ */
99+ const getSortPreference = ( key : SongListSortKey ) : SongListSortPreference =>
100+ sortPreferences . value [ key ] ?? { field : "none" , order : "asc" } ;
101+
102+ /**
103+ * 写入指定作用域的排序偏好
104+ * @param key - 列表排序作用域
105+ * @param preference - 排序偏好
106+ */
107+ const setSortPreference = ( key : SongListSortKey , preference : SongListSortPreference ) : void => {
108+ const current = sortPreferences . value [ key ] ;
109+ if ( current ?. field === preference . field && current . order === preference . order ) return ;
110+ const next = { ...sortPreferences . value } ;
111+ if ( preference . field === "none" && preference . order === "asc" ) delete next [ key ] ;
112+ else next [ key ] = { ...preference } ;
113+ sortPreferences . value = next ;
114+ } ;
115+
95116 /** 是否正在播放 */
96117 const isPlaying = computed ( ( ) => state . value === "playing" ) ;
97118 /** 是否暂停 */
@@ -154,8 +175,9 @@ export const useStatusStore = defineStore(
154175 myPlaylistSource,
155176 likedPageTab,
156177 settingsCategory,
157- sortField,
158- sortOrder,
178+ sortPreferences,
179+ getSortPreference,
180+ setSortPreference,
159181 currentTrack,
160182 currentIndex,
161183 currentPlaybackContext,
@@ -177,8 +199,7 @@ export const useStatusStore = defineStore(
177199 "myPlaylistSource" ,
178200 "likedPageTab" ,
179201 "settingsCategory" ,
180- "sortField" ,
181- "sortOrder" ,
202+ "sortPreferences" ,
182203 ] ,
183204 } ,
184205 } ,
0 commit comments