From 86452f04208198d0578597c8b5ef0c91a1e80e68 Mon Sep 17 00:00:00 2001 From: qier222 Date: Sun, 31 Jan 2021 17:36:00 +0800 Subject: [PATCH] fix: search issues --- src/api/others.js | 2 +- src/components/Navbar.vue | 32 ++++++++++++------------- src/store/mutations.js | 3 --- src/store/state.js | 3 --- src/views/search.vue | 50 ++++++++++++++++++++------------------- src/views/searchType.vue | 10 ++------ 6 files changed, 44 insertions(+), 56 deletions(-) diff --git a/src/api/others.js b/src/api/others.js index f63423a..d1027c1 100644 --- a/src/api/others.js +++ b/src/api/others.js @@ -22,7 +22,7 @@ export function search(params) { method: "get", params, }).then((data) => { - if (data.result.song !== undefined) + if (data.result?.song !== undefined) data.result.song.songs = mapTrackPlayableStatus(data.result.song.songs); return data; }); diff --git a/src/components/Navbar.vue b/src/components/Navbar.vue index 0f992f9..a1962ab 100644 --- a/src/components/Navbar.vue +++ b/src/components/Navbar.vue @@ -38,7 +38,8 @@ ref="searchInput" :placeholder="inputFocus ? '' : $t('nav.search')" v-model="keywords" - @focus="focusSearchBox" + @keydown.enter="doSearch" + @focus="inputFocus = true" @blur="inputFocus = false" /> @@ -61,32 +62,29 @@ export default { return { inputFocus: false, langs: ["zh-CN", "en"], + keywords: "", }; }, computed: { - ...mapState(["settings", "search"]), - keywords: { - get() { - return this.search.keywords; - }, - set(value) { - this.$store.commit("updateSearch", { key: "keywords", value }); - }, - }, + ...mapState(["settings"]), }, methods: { go(where) { if (where === "back") this.$router.go(-1); else this.$router.go(1); }, - focusSearchBox() { - this.inputFocus = true; - if (this.$route.name !== "search") { - this.$router.push({ - name: "search", - params: { keywords: this.keywords }, - }); + doSearch() { + if (!this.keywords) return; + if ( + this.$route.name === "search" && + this.$route.params.keywords === this.keywords + ) { + return; } + this.$router.push({ + name: "search", + params: { keywords: this.keywords }, + }); }, }, }; diff --git a/src/store/mutations.js b/src/store/mutations.js index 4c290df..66a66af 100644 --- a/src/store/mutations.js +++ b/src/store/mutations.js @@ -36,7 +36,4 @@ export default { toggleLyrics(state) { state.showLyrics = !state.showLyrics; }, - updateSearch(state, { key, value }) { - state.search[key] = value; - }, }; diff --git a/src/store/state.js b/src/store/state.js index 883c2bf..9f7065c 100644 --- a/src/store/state.js +++ b/src/store/state.js @@ -34,9 +34,6 @@ export default { afterCreateAddTrackID: 0, }, }, - search: { - keywords: "", - }, player: JSON.parse(localStorage.getItem("player")), settings: JSON.parse(localStorage.getItem("settings")), data: JSON.parse(localStorage.getItem("data")), diff --git a/src/views/search.vue b/src/views/search.vue index bbeaa95..b3ff967 100644 --- a/src/views/search.vue +++ b/src/views/search.vue @@ -1,5 +1,5 @@