增加搜索页面自动加载更多 (之前只能加载一页)
All checks were successful
Build / build-and-test (push) Successful in 30s

~~其实就是太激动了没做完就提交了~~
This commit is contained in:
2025-05-26 18:09:05 +08:00
parent f5d3e7ea88
commit f60bf907b1
2 changed files with 50 additions and 13 deletions

View File

@ -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()
}