From f60bf907b1d7a42bea803ba2f5b987e597ee9e35 Mon Sep 17 00:00:00 2001 From: UnknownMp Date: Mon, 26 May 2025 18:09:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=90=9C=E7=B4=A2=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E8=87=AA=E5=8A=A8=E5=8A=A0=E8=BD=BD=E6=9B=B4=E5=A4=9A?= =?UTF-8?q?=20(=E4=B9=8B=E5=89=8D=E5=8F=AA=E8=83=BD=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E4=B8=80=E9=A1=B5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ~~其实就是太激动了没做完就提交了~~ --- src/stores/search.js | 21 ++++++++++++------- src/views/SimpleSearch.vue | 42 ++++++++++++++++++++++++++++++++------ 2 files changed, 50 insertions(+), 13 deletions(-) diff --git a/src/stores/search.js b/src/stores/search.js index 10bb86e..0360565 100644 --- a/src/stores/search.js +++ b/src/stores/search.js @@ -7,25 +7,31 @@ export const useSimpleSearchState = defineStore('simpleSearch', () => { const api = useApiStore() const keyword = ref('') const result = ref([]) - const count = ref([]) + const count = ref(0) const pageCount = ref(0) const currentPage = ref(0) const state = ref(null) async function load() { - if (currentPage.value == pageCount.value) state.value = 'finish' + if (pageCount.value && currentPage.value >= pageCount.value){ state.value = 'finish'; return } let res = await api.workSimpleSearch(keyword.value, currentPage.value) res = res.data + if( pageCount.value ) { + currentPage.value++ + if (currentPage.value > pageCount.value) currentPage.value = pageCount.value + } if (res.code == 0) { - currentPage.value = res.page - pageCount.value = res.pageCount + if ( !pageCount.value ) { + pageCount.value = res.pageCount + currentPage.value = res.page + } count.value = res.count state.value = import.meta.env.SSR ? 'ssrready' : 'ready' result.value.push(...res.works) } else if (res.code == 1) { - if (currentPage.value) { + if ( count.value ) { state.value = 'finish' } else { - currentPage.value = 1 + currentPage.value = 0 state.value = 'notfound' } } @@ -35,7 +41,8 @@ export const useSimpleSearchState = defineStore('simpleSearch', () => { keyword.value = key result.value = [] state.value = 'loading' - currentPage.value = 0 + currentPage.value = 1 + pageCount.value = 0 await load() } diff --git a/src/views/SimpleSearch.vue b/src/views/SimpleSearch.vue index 2bb43b0..0057aaa 100644 --- a/src/views/SimpleSearch.vue +++ b/src/views/SimpleSearch.vue @@ -1,5 +1,5 @@