Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 专辑分碟排序错误 #1630

Merged
merged 2 commits into from
May 11, 2022
Merged
Changes from 1 commit
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
27 changes: 21 additions & 6 deletions src/views/album.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@
</div>
</div>
</div>
<div v-if="Object.keys(tracksByDisc).length !== 1">
<div v-for="(disc, cd) in tracksByDisc" :key="cd">
<h2 class="disc">Disc {{ cd }}</h2>
<div v-if="tracksByDisc.length > 1">
<div v-for="(item, index) in tracksByDisc" :key="index">
memorydream marked this conversation as resolved.
Show resolved Hide resolved
<h2 class="disc">Disc {{ item.disc }}</h2>
<TrackList
:id="album.id"
:tracks="disc"
:tracks="item.tracks"
:type="'album'"
:album-object="album"
/>
Expand Down Expand Up @@ -153,7 +153,7 @@ import locale from '@/locale';
import { splitSoundtrackAlbumTitle, splitAlbumTitle } from '@/utils/common';
import NProgress from 'nprogress';
import { isAccountLoggedIn } from '@/utils/auth';
import { groupBy } from 'lodash';
import { groupBy, toPairs, sortBy } from 'lodash';

import ExplicitSymbol from '@/components/ExplicitSymbol.vue';
import ButtonTwoTone from '@/components/ButtonTwoTone.vue';
Expand Down Expand Up @@ -222,7 +222,22 @@ export default {
}
},
tracksByDisc() {
return groupBy(this.tracks, 'cd');
if (this.tracks.length <= 1) return [];
const pairs = toPairs(groupBy(this.tracks, 'cd'));
if (pairs.length === 1) {
return [
{
disc: pairs[0][0],
tracks: pairs[0][1],
},
];
}
memorydream marked this conversation as resolved.
Show resolved Hide resolved
return sortBy(pairs, p => p[0]).map(items => {
return {
disc: items[0],
tracks: items[1],
};
});
memorydream marked this conversation as resolved.
Show resolved Hide resolved
},
},
created() {
Expand Down