完成单曲搜索,其他pr

This commit is contained in:
zilong 2021-11-01 14:44:47 +08:00
parent 82e56c3d51
commit e16176d6ea
8 changed files with 105 additions and 36 deletions

View File

@ -185,7 +185,7 @@ export default {
user-select: none; user-select: none;
.trh{ .trh{
background-color: #eee; background-color: #f0f0f0;
font-weight: 600; font-weight: 600;
td{ td{
// background-color: red; // background-color: red;

View File

@ -5,7 +5,7 @@ export default createStore({
// appVersion: "0.0.1", // appVersion: "0.0.1",
// debugStr: "测试debug字符", // debugStr: "测试debug字符",
showSongDetail: false, //是否显示歌曲详情 showSongDetail: false, //是否显示歌曲详情
keywords: '', //查询关键字 keywords: "", //查询关键字
settings: { settings: {
currentRoute: "/discover/recommend", //当前路由 currentRoute: "/discover/recommend", //当前路由
songId: 0, //歌曲id songId: 0, //歌曲id
@ -125,6 +125,25 @@ export default createStore({
saveLoaclSettings(state.settings); saveLoaclSettings(state.settings);
} }
}, },
// 搜索历史
addSearchHistory(state, history) {
let h = state.settings.searchHistory.filter(
(item) => item != history
);
h.unshift(history);
state.settings.searchHistory = h;
saveLoaclSettings(state.settings);
},
removeSearchHistory(state, history) {
state.settings.searchHistory = state.settings.searchHistory.filter(
(item) => item != history
);
saveLoaclSettings(state.settings);
},
clearSearchHistory(state) {
state.settings.searchHistory = []
saveLoaclSettings(state.settings);
},
}, },
actions: {}, actions: {},
modules: {}, modules: {},

View File

@ -1,38 +1,44 @@
<script setup> <script setup>
import { ref, onActivated, watch } from "vue"; import { ref, onActivated, watch, onMounted } from "vue";
import { searchResult } from "../network/search"; import { searchResult } from "../network/search";
import Songlist from "../components/Songlist.vue"; import Songlist from "../components/Songlist.vue";
import SongsList from "../components/SongsList.vue"; import SongsList from "../components/SongsList.vue";
import { useStore } from 'vuex'; import { useStore } from "vuex";
import { NPagination } from "naive-ui";
const props = defineProps({ const props = defineProps({
type: String, type: String,
keywords: String, keywords: String,
}); });
const store = useStore() const store = useStore();
onActivated(() => {}); onActivated(() => {});
const type = ref(props.type); const type = ref(props.type);
const keywords = ref(props.keywords); const keywords = ref(props.keywords);
const count = ref(0); const count = ref(0);
const page = ref(1);
const pageSize = ref(50);
const things = ref("单曲"); const things = ref("单曲");
const songs = ref([]); const songs = ref([]);
watch( watch(
() => [props.type, props.keywords], () => [props.type, props.keywords, page.value, pageSize.value],
([t, k]) => { ([t, k]) => {
search(t, k); type.value = t;
keywords.value = k;
search();
} }
// { immediate: true } // { immediate: true }
); );
const search = (t, k) => { onMounted(() => {
type.value = t; search();
keywords.value = k; });
switch (t) { const search = () => {
switch (type.value) {
case "1": case "1":
default: default:
type.value = "1"; type.value = "1";
@ -41,7 +47,12 @@ const search = (t, k) => {
} }
if (keywords.value.length > 0) { if (keywords.value.length > 0) {
searchResult(k, 20, 0, t) searchResult(
keywords.value,
pageSize.value,
(page.value - 1) * pageSize.value,
type.value
)
.then((res) => { .then((res) => {
if (res.data.code == 200) { if (res.data.code == 200) {
if (type.value == 1) { if (type.value == 1) {
@ -58,13 +69,14 @@ const search = (t, k) => {
}; };
const selStyle = (t) => { const selStyle = (t) => {
if(t == type.value){ if (t == type.value) {
const {primaryColor} = store.state.theme.themeOverrides.common const { primaryColor } = store.state.theme.themeOverrides.common;
return { return {
color: primaryColor, color: primaryColor,
borderBottom: 'solid 2px ' + primaryColor, borderBottom: "solid 2px " + primaryColor,
}} };
} }
};
</script> </script>
<template> <template>
@ -78,9 +90,7 @@ const selStyle = (t) => {
<div class="tabs"> <div class="tabs">
<div class="tab"> <div class="tab">
<div class="btns"> <div class="btns">
<span class="caption" :style="selStyle('1')"> <span class="caption" :style="selStyle('1')"> 单曲 </span>
单曲
</span>
<span class="caption" :style="selStyle('10')"> <span class="caption" :style="selStyle('10')">
专辑 专辑
</span> </span>
@ -109,6 +119,12 @@ const selStyle = (t) => {
<div class="panel" v-show="type == '100'"></div> <div class="panel" v-show="type == '100'"></div>
<div class="panel" v-show="type == '1000'"></div> <div class="panel" v-show="type == '1000'"></div>
</div> </div>
<div class="pager">
<NPagination
v-model:page="page"
:page-count="Math.ceil(count / pageSize)"
/>
</div>
</div> </div>
</div> </div>
</template> </template>
@ -146,12 +162,18 @@ export default {};
// border-bottom: solid 2px red; // border-bottom: solid 2px red;
// } // }
} }
.bt{ .bt {
margin-top: -2px; margin-top: -2px;
height: 2px; height: 2px;
background-color: #f0f0f0; background-color: #f0f0f0;
} }
} }
} }
.pager{
margin: 18px;
display: flex;
justify-content: center;
}
} }
</style> </style>

View File

@ -17,6 +17,7 @@ const search = () => {
if (keywords.value.length > 0){ if (keywords.value.length > 0){
pubsub.publish("zp.toggleSearch"); pubsub.publish("zp.toggleSearch");
// elSearch.value.blur() // elSearch.value.blur()
store.commit('addSearchHistory', keywords.value)
router.push(`/search/1/${keywords.value}`); router.push(`/search/1/${keywords.value}`);
} }
}; };

View File

@ -1,11 +1,13 @@
<script setup> <script setup>
import { useStore } from "vuex"; import { useStore } from "vuex";
import { useRouter } from "vue-router";
import { getHotDetail, searchSuggest } from "@/network/search.js"; import { getHotDetail, searchSuggest } from "@/network/search.js";
import { ref, onUnmounted } from "vue"; import { ref, onUnmounted } from "vue";
import { NTag, NButton, NSpace } from "naive-ui"; import { NTag, NButton, NSpace } from "naive-ui";
import pubsub from "pubsub-js"; import pubsub from "pubsub-js";
const store = useStore(); const store = useStore();
const router = useRouter();
//#region //#region
const hotSearch = ref([]); const hotSearch = ref([]);
@ -68,7 +70,11 @@ onUnmounted(() => {
> >
<div class="caption"> <div class="caption">
<span class="txt">搜索历史</span> <span class="txt">搜索历史</span>
<NButton round size="tiny" type="error">清除</NButton> <NButton round size="tiny" type="error"
@click="()=>{
store.commit('clearSearchHistory')
}"
>清除</NButton>
</div> </div>
<NSpace class="h-list" :size="[6, 6]"> <NSpace class="h-list" :size="[6, 6]">
<NTag <NTag
@ -77,6 +83,11 @@ onUnmounted(() => {
round round
size="small" size="small"
type="primary" type="primary"
@close.stop="store.commit('removeSearchHistory', h)"
@click="()=>{
pubsub.publish('zp.toggleSearch');
router.push(`/search/1/${h}`);
}"
>{{ h }}</NTag >{{ h }}</NTag
> >
</NSpace> </NSpace>
@ -87,6 +98,11 @@ onUnmounted(() => {
class="hot-list" class="hot-list"
v-for="(item, idx) in hotSearch" v-for="(item, idx) in hotSearch"
key="idx" key="idx"
@click="()=>{
pubsub.publish('zp.toggleSearch');
store.commit('addSearchHistory', item.searchWord)
router.push(`/search/1/${item.searchWord}`);
}"
> >
<div class="idx" :class="{ idxHot: item.iconType == 1 }"> <div class="idx" :class="{ idxHot: item.iconType == 1 }">
{{ idx + 1 }} {{ idx + 1 }}
@ -165,6 +181,9 @@ export default {};
display: flex; display: flex;
align-items: center; align-items: center;
color: #999; color: #999;
&:hover{
background: #efefef;
}
.idx { .idx {
padding: 6px 12px; padding: 6px 12px;
width: 30px; width: 30px;

View File

@ -98,7 +98,7 @@ const stop = async () => {
store.commit("saveSettings", { store.commit("saveSettings", {
songId: null, songId: null,
}); });
pubsub.publish('zp.hideSongInfo') pubsub.publish("zp.hideSongInfo");
} }
}; };
@ -164,6 +164,10 @@ const favorite = () => {
// console.log(audioEl.value.currentTime); // console.log(audioEl.value.currentTime);
}; };
const removeCurrentSong = () => {
pubsub.publish('zp.removeCurrPlayingSong', { id: store.state.settings.songId })
};
let interval; let interval;
watch(playing, (val, old) => { watch(playing, (val, old) => {
store.state.settings.playing = val; store.state.settings.playing = val;
@ -268,13 +272,13 @@ onUnmounted(() => {
</n-icon> </n-icon>
</template> </template>
</n-button> </n-button>
<!-- <n-button circle> <n-button circle @click="removeCurrentSong">
<template #icon> <template #icon>
<n-icon> <n-icon>
<TrashOutline /> <TrashOutline />
</n-icon> </n-icon>
</template> </template>
</n-button> --> </n-button>
</n-space> </n-space>
<!-- </div> --> <!-- </div> -->

View File

@ -47,6 +47,9 @@ const token = pubsub.subscribe("zp", (msg, data) => {
switch (msg) { switch (msg) {
case "zp.togglePlaying": case "zp.togglePlaying":
break; break;
case "zp.removeCurrPlayingSong":
removeCurrPlayingSong(data.id);
break;
} }
}); });
@ -127,15 +130,16 @@ const handleSelect = (key, id) => {
case "nextToPlay": case "nextToPlay":
break; break;
case "remove": case "remove":
store.commit("removePlayingList", { id }); removeCurrPlayingSong(id)
if (playingList.value.length > 0){
if (store.state.settings.songId == id)
pubsub.publish("zp.next");
}
else pubsub.publish("zp.stop");
break; break;
} }
}; };
const removeCurrPlayingSong = (id) => {
store.commit("removePlayingList", { id });
if (playingList.value.length > 0) {
if (store.state.settings.songId == id) pubsub.publish("zp.next");
} else pubsub.publish("zp.stop");
};
const handleClick = () => { const handleClick = () => {
// showDropdownRef.value = !showDropdownRef.value; // showDropdownRef.value = !showDropdownRef.value;
}; };

View File

@ -40,7 +40,7 @@
> >
<n-grid-item <n-grid-item
v-for="(song, idx) in topSongs" v-for="(song, idx) in topSongs"
key="idx" :key="song.id"
> >
<div class="c2-list"> <div class="c2-list">
<div class="play-btn"> <div class="play-btn">
@ -110,7 +110,7 @@
> >
<n-grid-item <n-grid-item
v-for="(mv, idx) in personalizedMV" v-for="(mv, idx) in personalizedMV"
key="idx" :key="mv.id"
> >
<div class="mv-c2-list"> <div class="mv-c2-list">
<div class="play-mv"> <div class="play-mv">
@ -170,7 +170,7 @@
:cols="4" :cols="4"
style="margin: 6px 0" style="margin: 6px 0"
> >
<n-grid-item v-for="p in personalized"> <n-grid-item v-for="p in personalized" :key="p.id">
<n-card <n-card
title title
hoverable hoverable