|
|
@ -8,10 +8,11 @@
|
|
|
|
<compose @post-success="onPostSuccess" />
|
|
|
|
<compose @post-success="onPostSuccess" />
|
|
|
|
</n-list-item>
|
|
|
|
</n-list-item>
|
|
|
|
|
|
|
|
|
|
|
|
<div v-if="loading" class="skeleton-wrap">
|
|
|
|
<div v-if="loading && list.length === 0" class="skeleton-wrap">
|
|
|
|
<post-skeleton :num="pageSize" />
|
|
|
|
<post-skeleton :num="pageSize" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div v-else>
|
|
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
<div class="empty-wrap" v-if="list.length === 0">
|
|
|
|
<div class="empty-wrap" v-if="list.length === 0">
|
|
|
|
<n-empty size="large" description="暂无数据" />
|
|
|
|
<n-empty size="large" description="暂无数据" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
@ -28,14 +29,17 @@
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</n-list>
|
|
|
|
</n-list>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="pagination-wrap" v-if="totalPage > 0">
|
|
|
|
|
|
|
|
<n-pagination
|
|
|
|
<n-space v-if="totalPage > 0" justify="center">
|
|
|
|
:page="page"
|
|
|
|
<InfiniteLoading class="load-more" :slots="{ complete: '没有更多泡泡了', error: '加载出错' }" @infinite="nextPage()">
|
|
|
|
@update:page="updatePage"
|
|
|
|
<template #spinner>
|
|
|
|
:page-slot="!store.state.collapsedRight ? 8 : 5"
|
|
|
|
<div class="load-more-wrap">
|
|
|
|
:page-count="totalPage"
|
|
|
|
<n-spin :size="14" v-if="!noMore" />
|
|
|
|
/>
|
|
|
|
<span class="load-more-spinner">{{ noMore ? '没有更多泡泡了' : '加载更多' }}</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
</InfiniteLoading>
|
|
|
|
|
|
|
|
</n-space>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
@ -43,6 +47,7 @@
|
|
|
|
import { ref, onMounted, computed, watch } from 'vue';
|
|
|
|
import { ref, onMounted, computed, watch } from 'vue';
|
|
|
|
import { useStore } from 'vuex';
|
|
|
|
import { useStore } from 'vuex';
|
|
|
|
import { useRoute, useRouter } from 'vue-router';
|
|
|
|
import { useRoute, useRouter } from 'vue-router';
|
|
|
|
|
|
|
|
import InfiniteLoading from "v3-infinite-loading";
|
|
|
|
import { getPosts } from '@/api/post';
|
|
|
|
import { getPosts } from '@/api/post';
|
|
|
|
|
|
|
|
|
|
|
|
const store = useStore();
|
|
|
|
const store = useStore();
|
|
|
@ -50,8 +55,9 @@ const route = useRoute();
|
|
|
|
const router = useRouter();
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
|
|
|
|
|
|
const loading = ref(false);
|
|
|
|
const loading = ref(false);
|
|
|
|
|
|
|
|
const noMore = ref(false);
|
|
|
|
const list = ref<any[]>([]);
|
|
|
|
const list = ref<any[]>([]);
|
|
|
|
const page = ref(+(route.query.p as string) || 1);
|
|
|
|
const page = ref(1);
|
|
|
|
const pageSize = ref(20);
|
|
|
|
const pageSize = ref(20);
|
|
|
|
const totalPage = ref(0);
|
|
|
|
const totalPage = ref(0);
|
|
|
|
const title = computed(() => {
|
|
|
|
const title = computed(() => {
|
|
|
@ -78,10 +84,18 @@ const loadPosts = () => {
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.then((rsp) => {
|
|
|
|
.then((rsp) => {
|
|
|
|
loading.value = false;
|
|
|
|
loading.value = false;
|
|
|
|
list.value = rsp.list;
|
|
|
|
if (rsp.list.length === 0) {
|
|
|
|
totalPage.value = Math.ceil(rsp.pager.total_rows / pageSize.value);
|
|
|
|
noMore.value = true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (page.value > 1) {
|
|
|
|
|
|
|
|
list.value = list.value.concat(rsp.list);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
list.value = rsp.list;
|
|
|
|
window.scrollTo(0, 0);
|
|
|
|
window.scrollTo(0, 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
totalPage.value = Math.ceil(rsp.pager.total_rows / pageSize.value);
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
.catch((err) => {
|
|
|
|
loading.value = false;
|
|
|
|
loading.value = false;
|
|
|
@ -121,14 +135,9 @@ const onPostSuccess = (post: Item.PostProps) => {
|
|
|
|
list.value = items;
|
|
|
|
list.value = items;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const updatePage = (p: number) => {
|
|
|
|
const nextPage = () => {
|
|
|
|
router.push({
|
|
|
|
page.value++;
|
|
|
|
name: 'home',
|
|
|
|
loadPosts()
|
|
|
|
query: {
|
|
|
|
|
|
|
|
...route.query,
|
|
|
|
|
|
|
|
p,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
onMounted(() => {
|
|
|
@ -142,14 +151,16 @@ watch(
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
(to, from) => {
|
|
|
|
(to, from) => {
|
|
|
|
if (to.refresh !== from.refresh) {
|
|
|
|
if (to.refresh !== from.refresh) {
|
|
|
|
page.value = +(route.query.p as string) || 1;
|
|
|
|
noMore.value = false;
|
|
|
|
|
|
|
|
page.value = 1;
|
|
|
|
setTimeout(() => {
|
|
|
|
setTimeout(() => {
|
|
|
|
loadPosts();
|
|
|
|
loadPosts();
|
|
|
|
}, 0);
|
|
|
|
}, 0);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (from.path !== '/post' && to.path === '/') {
|
|
|
|
if (from.path !== '/post' && to.path === '/') {
|
|
|
|
page.value = +(route.query.p as string) || 1;
|
|
|
|
noMore.value = false;
|
|
|
|
|
|
|
|
page.value = 1;
|
|
|
|
setTimeout(() => {
|
|
|
|
setTimeout(() => {
|
|
|
|
loadPosts();
|
|
|
|
loadPosts();
|
|
|
|
}, 0);
|
|
|
|
}, 0);
|
|
|
@ -159,14 +170,36 @@ watch(
|
|
|
|
</script>
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style lang="less" scoped>
|
|
|
|
<style lang="less" scoped>
|
|
|
|
|
|
|
|
.load-more {
|
|
|
|
|
|
|
|
margin: 20px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.load-more-wrap {
|
|
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
|
|
flex-direction: row;
|
|
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
gap: 14px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.load-more-spinner {
|
|
|
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
|
|
opacity: 0.65;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.pagination-wrap {
|
|
|
|
.pagination-wrap {
|
|
|
|
padding: 10px;
|
|
|
|
padding: 10px;
|
|
|
|
display: flex;
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
justify-content: center;
|
|
|
|
overflow: hidden;
|
|
|
|
overflow: hidden;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.dark {
|
|
|
|
.dark {
|
|
|
|
.main-content-wrap, .pagination-wrap, .empty-wrap, .skeleton-wrap {
|
|
|
|
|
|
|
|
|
|
|
|
.main-content-wrap,
|
|
|
|
|
|
|
|
.pagination-wrap,
|
|
|
|
|
|
|
|
.empty-wrap,
|
|
|
|
|
|
|
|
.skeleton-wrap {
|
|
|
|
background-color: rgba(16, 16, 20, 0.75);
|
|
|
|
background-color: rgba(16, 16, 20, 0.75);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|