[BugFix] 修复了搜索页面加载重复的问题
This commit is contained in:
@ -13,16 +13,15 @@ export const useSimpleSearchState = defineStore('simpleSearch', () => {
|
|||||||
const state = ref(null)
|
const state = ref(null)
|
||||||
async function load() {
|
async function load() {
|
||||||
if (pageCount.value && currentPage.value >= pageCount.value){ state.value = 'finish'; return }
|
if (pageCount.value && currentPage.value >= pageCount.value){ state.value = 'finish'; return }
|
||||||
|
state.value = 'loading'
|
||||||
let res = await api.workSimpleSearch(keyword.value, currentPage.value)
|
let res = await api.workSimpleSearch(keyword.value, currentPage.value)
|
||||||
res = res.data
|
res = res.data
|
||||||
if( pageCount.value ) {
|
|
||||||
currentPage.value++
|
|
||||||
if (currentPage.value > pageCount.value) currentPage.value = pageCount.value
|
|
||||||
}
|
|
||||||
if (res.code == 0) {
|
if (res.code == 0) {
|
||||||
if ( !pageCount.value ) {
|
currentPage.value++
|
||||||
|
if( pageCount.value ) {
|
||||||
|
if (currentPage.value > pageCount.value) currentPage.value = pageCount.value
|
||||||
|
} else {
|
||||||
pageCount.value = res.pageCount
|
pageCount.value = res.pageCount
|
||||||
currentPage.value = res.page
|
|
||||||
}
|
}
|
||||||
count.value = res.count
|
count.value = res.count
|
||||||
state.value = import.meta.env.SSR ? 'ssrready' : 'ready'
|
state.value = import.meta.env.SSR ? 'ssrready' : 'ready'
|
||||||
|
@ -39,7 +39,7 @@ onMounted(async () => {
|
|||||||
isObserver = new IntersectionObserver((entries) => {
|
isObserver = new IntersectionObserver((entries) => {
|
||||||
entries.forEach((entry) => {
|
entries.forEach((entry) => {
|
||||||
if (entry.isIntersecting) {
|
if (entry.isIntersecting) {
|
||||||
if (simpleSearchState.state == 'ready') simpleSearchState.load()
|
if (simpleSearchState.state == 'ready' || simpleSearchState.state == 'ssrready') setTimeout(simpleSearchState.load,400)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}, { threshold: 1 })
|
}, { threshold: 1 })
|
||||||
|
@ -163,8 +163,12 @@ async function switchWorkWithIndex(target) {
|
|||||||
</dl>
|
</dl>
|
||||||
</mdui-card>
|
</mdui-card>
|
||||||
<template v-if="workReadState.cid">
|
<template v-if="workReadState.cid">
|
||||||
<p>第 {{ workReadState.chapterIndex + 1 }} / {{ workReadState.chapters.length }} 章: {{ workReadState.chapters[workReadState.chapterIndex].title }}</p>
|
<h4>第 {{ workReadState.chapterIndex + 1 }} / {{ workReadState.chapters.length }} 章: {{ workReadState.chapters[workReadState.chapterIndex].title }}</h4>
|
||||||
<mdui-button variant='filled' @click="chapterDialog.open = true">章节列表</mdui-button>
|
<div style="display: flex;">
|
||||||
|
<mdui-button variant="filled" v-if="workReadState.chapterIndex != 0" @click="switchWorkWithIndex(workReadState.chapterIndex - 1)">上一章</mdui-button>
|
||||||
|
<mdui-button variant='elevated' @click="chapterDialog.open = true" style="margin: 0px 16px;">章节列表</mdui-button>
|
||||||
|
<mdui-button variant="filled" v-if="workReadState.chapterIndex != workReadState.chapters.length - 1" @click="switchWorkWithIndex(workReadState.chapterIndex + 1)">下一章</mdui-button>
|
||||||
|
</div><br/>
|
||||||
</template>
|
</template>
|
||||||
<blockquote v-if="workReadState.summary">
|
<blockquote v-if="workReadState.summary">
|
||||||
<p v-html='workReadState.summary'></p>
|
<p v-html='workReadState.summary'></p>
|
||||||
@ -192,7 +196,11 @@ async function switchWorkWithIndex(target) {
|
|||||||
<br/>
|
<br/>
|
||||||
点击跳转
|
点击跳转
|
||||||
</span>
|
</span>
|
||||||
<mdui-list><mdui-list-item v-for="(chapter,index) in workReadState.chapters" :key="chapter.chapterId" @click="switchWorkWithIndex(index)">
|
<mdui-list><mdui-list-item
|
||||||
|
v-for="(chapter,index) in workReadState.chapters"
|
||||||
|
:key="chapter.chapterId" @click="switchWorkWithIndex(index)"
|
||||||
|
:class="{ 'active-item' : index === workReadState.chapterIndex }"
|
||||||
|
>
|
||||||
{{index + 1}}. {{ chapter.title }}
|
{{index + 1}}. {{ chapter.title }}
|
||||||
</mdui-list-item></mdui-list>
|
</mdui-list-item></mdui-list>
|
||||||
</mdui-dialog>
|
</mdui-dialog>
|
||||||
@ -249,6 +257,9 @@ async function switchWorkWithIndex(target) {
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
.active-item {
|
||||||
|
background-color: rgb(var(--mdui-color-secondary-container-light));
|
||||||
|
}
|
||||||
.mdui-fab {
|
.mdui-fab {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
bottom: 16px; /* 调整垂直位置 */
|
bottom: 16px; /* 调整垂直位置 */
|
||||||
|
Reference in New Issue
Block a user