feat: add search in playlist | 增加歌单内搜索 (#450)

master
Vidocq 4 years ago committed by GitHub
parent 2098170867
commit cc50faeb09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -79,8 +79,22 @@
</ButtonTwoTone> </ButtonTwoTone>
</div> </div>
</div> </div>
<div class="search-box" v-if="displaySearchInPlaylist">
<div class="container" :class="{ active: inputFocus }">
<svg-icon icon-class="search" />
<div class="input">
<input
:placeholder="inputFocus ? '' : $t('playlist.search')"
v-model.trim="inputSearchKeyWords"
v-focus="displaySearchInPlaylist"
@input="inputDebounce()"
@focus="inputFocus = true"
@blur="inputFocus = false"
/>
</div>
</div>
</div>
</div> </div>
<div class="special-playlist" v-if="specialPlaylistInfo !== undefined"> <div class="special-playlist" v-if="specialPlaylistInfo !== undefined">
<div <div
class="title" class="title"
@ -136,7 +150,7 @@
</div> </div>
<TrackList <TrackList
:tracks="tracks" :tracks="filteredTracks"
:type="'playlist'" :type="'playlist'"
:id="playlist.id" :id="playlist.id"
:extraContextMenuItem=" :extraContextMenuItem="
@ -158,6 +172,7 @@
<div class="item" @click="likePlaylist(true)">{{ <div class="item" @click="likePlaylist(true)">{{
playlist.subscribed ? "从音乐库删除" : "保存到音乐库" playlist.subscribed ? "从音乐库删除" : "保存到音乐库"
}}</div> }}</div>
<div class="item" @click="searchInPlaylist()"></div>
<div <div
class="item" class="item"
v-if="playlist.creator.userId === data.user.userId" v-if="playlist.creator.userId === data.user.userId"
@ -302,6 +317,11 @@ export default {
tracks: [], tracks: [],
loadingMore: false, loadingMore: false,
lastLoadedTrackIndex: 9, lastLoadedTrackIndex: 9,
displaySearchInPlaylist: false,
searchKeyWords: "", // 使
inputSearchKeyWords: "", //
inputFocus: false,
debounceTimeout: null,
}; };
}, },
created() { created() {
@ -328,6 +348,22 @@ export default {
this.playlist.id !== this.data.likedSongPlaylistID this.playlist.id !== this.data.likedSongPlaylistID
); );
}, },
filteredTracks() {
return this.tracks.filter(
(track) =>
track.name
.toLowerCase()
.includes(this.searchKeyWords.toLowerCase()) ||
track.al.name
.toLowerCase()
.includes(this.searchKeyWords.toLowerCase()) ||
track.ar.find((artist) =>
artist.name
.toLowerCase()
.includes(this.searchKeyWords.toLowerCase())
)
);
},
}, },
methods: { methods: {
...mapMutations(["appendTrackToPlayerList"]), ...mapMutations(["appendTrackToPlayerList"]),
@ -384,11 +420,11 @@ export default {
} }
}); });
}, },
loadMore() { loadMore(loadNum = 50) {
let trackIDs = this.playlist.trackIds.filter((t, index) => { let trackIDs = this.playlist.trackIds.filter((t, index) => {
if ( if (
index > this.lastLoadedTrackIndex && index > this.lastLoadedTrackIndex &&
index <= this.lastLoadedTrackIndex + 50 index <= this.lastLoadedTrackIndex + loadNum
) )
return t; return t;
}); });
@ -438,6 +474,15 @@ export default {
editPlaylist() { editPlaylist() {
alert("此功能开发中"); alert("此功能开发中");
}, },
searchInPlaylist() {
this.displaySearchInPlaylist = !this.displaySearchInPlaylist;
if (this.displaySearchInPlaylist == false) {
this.searchKeyWords = "";
this.inputSearchKeyWords = "";
} else {
this.loadMore(500);
}
},
removeTrack(trackID) { removeTrack(trackID) {
if (!isAccountLoggedIn()) { if (!isAccountLoggedIn()) {
this.showToast("此操作需要登录网易云账号"); this.showToast("此操作需要登录网易云账号");
@ -445,6 +490,19 @@ export default {
} }
this.tracks = this.tracks.filter((t) => t.id !== trackID); this.tracks = this.tracks.filter((t) => t.id !== trackID);
}, },
inputDebounce() {
if (this.debounceTimeout) clearTimeout(this.debounceTimeout);
this.debounceTimeout = setTimeout(() => {
this.searchKeyWords = this.inputSearchKeyWords;
}, 600);
},
},
directives: {
focus: {
inserted: function (el) {
el.focus();
},
},
}, },
}; };
</script> </script>
@ -453,6 +511,7 @@ export default {
.playlist-info { .playlist-info {
display: flex; display: flex;
margin-bottom: 72px; margin-bottom: 72px;
position: relative;
.info { .info {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@ -711,4 +770,63 @@ export default {
} }
} }
} }
.search-box {
display: flex;
position: absolute;
right: 20px;
bottom: -55px;
justify-content: flex-end;
-webkit-app-region: no-drag;
.container {
display: flex;
align-items: center;
height: 32px;
background: var(--color-secondary-bg-for-transparent);
border-radius: 8px;
width: 200px;
}
.svg-icon {
height: 15px;
width: 15px;
color: var(--color-text);
opacity: 0.28;
margin: {
left: 8px;
right: 4px;
}
}
input {
font-size: 16px;
border: none;
background: transparent;
width: 96%;
font-weight: 600;
margin-top: -1px;
color: var(--color-text);
}
.active {
background: var(--color-primary-bg-for-transparent);
input,
.svg-icon {
opacity: 1;
color: var(--color-primary);
}
}
}
[data-theme="dark"] {
.search-box {
.active {
input,
.svg-icon {
color: var(--color-text);
}
}
}
}
</style> </style>

Loading…
Cancel
Save