Skip to content

Commit

Permalink
1. bug-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
stark81 committed Jul 20, 2023
1 parent e0ba789 commit c4271d1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/components/TrackListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@
</div>

<div v-if="showTrackTime" class="createTime">
{{ getPublishTime(track.createTime || track.publishTime) }}
{{
track.createTime
? getPublishTime(track.createTime)
: getPublishTime(track.publishTime)
}}
</div>
<div v-if="showLikeButton" class="actions">
<button @click="likeThisSong">
Expand Down
27 changes: 23 additions & 4 deletions src/views/localMusic.vue
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,21 @@ function extractLyricPart(rawLyric) {
return rawLyric.split(']').pop().trim();
}
function getRandomNumbersFromList(list, count) {
const listCopy = list.slice();
const result = [];
for (let i = 0; i < count; i++) {
const randomIndex = Math.floor(Math.random() * listCopy.length);
const randomNumber = listCopy[randomIndex];
result.push(randomNumber);
listCopy.splice(randomIndex, 1);
}
return result;
}
export default {
name: 'LocalMusic',
components: { SvgIcon, CoverRow, ContextMenu, TrackList },
Expand Down Expand Up @@ -369,8 +384,10 @@ export default {
allTracks(val) {
clearTimeout(this.timer);
this.timer = setTimeout(() => {
const idx = randomNum(0, val.length - 12);
this.randomShowTracks = val.slice(idx, idx + 12);
// const idx = randomNum(0, val.length - 12);
// this.randomShowTracks = val.slice(idx, idx + 12);
this.randomShowTracks =
val.length > 12 ? getRandomNumbersFromList(val, 12) : val;
const tracks = this.sortList(val, this.sortBy);
this.activeTracks = tracks;
this.activeAlbums = this.filterLocalAlbums;
Expand Down Expand Up @@ -405,8 +422,10 @@ export default {
const artists = this.filterLocalArtists;
// 随机显示的12首歌
const idx = tracks.length > 12 ? randomNum(0, tracks.length - 12) : 0;
this.randomShowTracks = tracks.slice(idx, idx + 12);
// const idx = tracks.length > 12 ? randomNum(0, tracks.length - 12) : 0;
this.randomShowTracks =
tracks.length > 12 ? getRandomNumbersFromList(tracks, 12) : tracks;
// this.randomShowTracks = tracks.slice(idx, idx + 12);
tracks = this.sortList(tracks, this.sortBy);
// 首页先加载20首歌,20个专辑,20个歌手,1秒后再全部加载
Expand Down
1 change: 1 addition & 0 deletions src/views/playlist.vue
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ export default {
trackIDs = trackIDs.map(t => t.id);
getTrackDetail(trackIDs.join(',')).then(data => {
this.tracks.push(...data.songs);
this.tracks = [...new Set(this.tracks)];
this.lastLoadedTrackIndex += trackIDs.length;
this.loadingMore = false;
if (this.lastLoadedTrackIndex + 1 === this.playlist.trackIds.length) {
Expand Down

0 comments on commit c4271d1

Please sign in to comment.