mirror of
https://github.com/ialley-workshop-open/uni-halo.git
synced 2026-11-13 22:11:42 +08:00
refactor(load-status): 列表页加载更多统一接入 loadMoreStatus 状态机
category-articles/search/articles/friend-links/archives/votes/gallery 七个列表页参考分类页实现,移除自研 isLoadMore/loadMoreText/hasNext, 统一使用 useDataLoadingStatus 的 loadMoreStatus + uh-data-loadmore: - onReachBottom 增加加载中防重入,有更多才翻页,无更多不再 toast - 筛选/排序/搜索/分组切换与下拉刷新统一 resetLoadMoreStatus 重置 - 首屏与加载更多错误分态处理(loadingStatus / loadMoreStatus) - search 页由一次性 limit:50 改为 page/size 分页加载
This commit is contained in:
@@ -26,10 +26,9 @@ const settingStore = useSettingStore()
|
|||||||
const archivesListLayout = computed(() => settingStore.settings.archivesListLayout)
|
const archivesListLayout = computed(() => settingStore.settings.archivesListLayout)
|
||||||
|
|
||||||
/* ---------------- 状态 ---------------- */
|
/* ---------------- 状态 ---------------- */
|
||||||
const { loadingStatus, updateLoadingStatus } = useDataLoadingStatus()
|
const { loadingStatus, loadMoreStatus, updateLoadingStatus, updateLoadMoreStatus, resetLoadMoreStatus } = useDataLoadingStatus()
|
||||||
const activeTabIndex = ref(0)
|
const activeTabIndex = ref(0)
|
||||||
const queryParams = ref({ size: 10, page: 1 })
|
const queryParams = ref({ size: 10, page: 1 })
|
||||||
const result = ref<{ hasNext: boolean }>({ hasNext: false })
|
|
||||||
const cacheDataList = ref<IPost[]>([])
|
const cacheDataList = ref<IPost[]>([])
|
||||||
const dataList = ref<{
|
const dataList = ref<{
|
||||||
sort: number
|
sort: number
|
||||||
@@ -38,8 +37,6 @@ const dataList = ref<{
|
|||||||
month: string
|
month: string
|
||||||
posts: IPost[]
|
posts: IPost[]
|
||||||
}[]>([])
|
}[]>([])
|
||||||
const isLoadMore = ref(false)
|
|
||||||
const loadMoreText = ref('加载中...')
|
|
||||||
|
|
||||||
const postLabelYearKey = 'content.halo.run/archive-year'
|
const postLabelYearKey = 'content.halo.run/archive-year'
|
||||||
const postLabelMonthKey = 'content.halo.run/archive-month'
|
const postLabelMonthKey = 'content.halo.run/archive-month'
|
||||||
@@ -104,7 +101,8 @@ function handleUniqueCacheDatalist(list: IPost[]): IPost[] {
|
|||||||
/* ---------------- 数据加载 ---------------- */
|
/* ---------------- 数据加载 ---------------- */
|
||||||
async function handleGetData() {
|
async function handleGetData() {
|
||||||
if (calcAuditModeEnabled.value) {
|
if (calcAuditModeEnabled.value) {
|
||||||
// 审核模式:真实文章按 audit-data posts 过滤(数组顺序即展示顺序)
|
// 审核模式:真实文章按 audit-data posts 过滤(数组顺序即展示顺序),一次拉取不分页
|
||||||
|
resetLoadMoreStatus()
|
||||||
const auditPostNames = appConfigStore.auditData.spec?.posts || []
|
const auditPostNames = appConfigStore.auditData.spec?.posts || []
|
||||||
try {
|
try {
|
||||||
const res = await getPostList({ page: 1, size: 99999, sort: ['spec.publishTime,desc'] })
|
const res = await getPostList({ page: 1, size: 99999, sort: ['spec.publishTime,desc'] })
|
||||||
@@ -117,33 +115,35 @@ async function handleGetData() {
|
|||||||
updateLoadingStatus(
|
updateLoadingStatus(
|
||||||
dataList.value.length === 0 ? DataLoadingStatusEnum.Empty : DataLoadingStatusEnum.Success,
|
dataList.value.length === 0 ? DataLoadingStatusEnum.Empty : DataLoadingStatusEnum.Success,
|
||||||
)
|
)
|
||||||
loadMoreText.value = '呜呜,没有更多数据啦~'
|
updateLoadMoreStatus({
|
||||||
|
active: false,
|
||||||
|
status: 'noMore',
|
||||||
|
hasNext: false,
|
||||||
|
})
|
||||||
uni.stopPullDownRefresh()
|
uni.stopPullDownRefresh()
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
updateLoadingStatus(DataLoadingStatusEnum.Error)
|
updateLoadingStatus(DataLoadingStatusEnum.Error)
|
||||||
loadMoreText.value = '加载失败,请下拉刷新!'
|
updateLoadMoreStatus({
|
||||||
|
active: false,
|
||||||
|
status: 'error',
|
||||||
|
})
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isLoadMore.value) {
|
if (!loadMoreStatus.value.active) {
|
||||||
uni.showLoading({ title: '加载中...' })
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
updateLoadingStatus(DataLoadingStatusEnum.Loading)
|
updateLoadingStatus(DataLoadingStatusEnum.Loading)
|
||||||
}
|
}
|
||||||
loadMoreText.value = '加载中...'
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// getPostList 返回 IResponse<IPostListRes>,数据在 .data 下
|
// getPostList 返回 IResponse<IPostListRes>,数据在 .data 下
|
||||||
const res = await getPostList({ ...queryParams.value })
|
const res = await getPostList({ ...queryParams.value })
|
||||||
result.value = { hasNext: res.data.hasNext }
|
|
||||||
const posts = handleGetPosts(res.data.items)
|
const posts = handleGetPosts(res.data.items)
|
||||||
const showDataList = handleGetShowDataList(posts)
|
const showDataList = handleGetShowDataList(posts)
|
||||||
|
|
||||||
if (isLoadMore.value) {
|
if (loadMoreStatus.value.active) {
|
||||||
cacheDataList.value = handleUniqueCacheDatalist([...cacheDataList.value, ...res.data.items])
|
cacheDataList.value = handleUniqueCacheDatalist([...cacheDataList.value, ...res.data.items])
|
||||||
// 合并增量数据
|
// 合并增量数据
|
||||||
showDataList.forEach((item) => {
|
showDataList.forEach((item) => {
|
||||||
@@ -167,16 +167,29 @@ async function handleGetData() {
|
|||||||
dataList.value = showDataList
|
dataList.value = showDataList
|
||||||
cacheDataList.value = res.data.items
|
cacheDataList.value = res.data.items
|
||||||
}
|
}
|
||||||
|
if (!loadMoreStatus.value.active) {
|
||||||
await sleep(500)
|
await sleep(500)
|
||||||
updateLoadingStatus(
|
updateLoadingStatus(
|
||||||
dataList.value.length === 0 ? DataLoadingStatusEnum.Empty : DataLoadingStatusEnum.Success,
|
dataList.value.length === 0 ? DataLoadingStatusEnum.Empty : DataLoadingStatusEnum.Success,
|
||||||
)
|
)
|
||||||
loadMoreText.value = res.data.hasNext ? '上拉加载更多' : '呜呜,没有更多数据啦~'
|
}
|
||||||
|
updateLoadMoreStatus({
|
||||||
|
active: false,
|
||||||
|
status: res.data.hasNext ? 'loadMore' : 'noMore',
|
||||||
|
hasNext: res.data.hasNext,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
|
if (loadMoreStatus.value.active) {
|
||||||
|
updateLoadMoreStatus({
|
||||||
|
active: false,
|
||||||
|
status: 'error',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else {
|
||||||
updateLoadingStatus(DataLoadingStatusEnum.Error)
|
updateLoadingStatus(DataLoadingStatusEnum.Error)
|
||||||
loadMoreText.value = '加载失败,请下拉刷新!'
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
uni.stopPullDownRefresh()
|
uni.stopPullDownRefresh()
|
||||||
@@ -210,7 +223,7 @@ function handleToTopPage(duration = 500) {
|
|||||||
handleGetData()
|
handleGetData()
|
||||||
|
|
||||||
onPullDownRefresh(() => {
|
onPullDownRefresh(() => {
|
||||||
isLoadMore.value = false
|
resetLoadMoreStatus()
|
||||||
queryParams.value.page = 1
|
queryParams.value.page = 1
|
||||||
handleGetData()
|
handleGetData()
|
||||||
})
|
})
|
||||||
@@ -220,13 +233,18 @@ onReachBottom(() => {
|
|||||||
uni.showToast({ icon: 'none', title: '没有更多数据了' })
|
uni.showToast({ icon: 'none', title: '没有更多数据了' })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (result.value.hasNext) {
|
// 正在加载时阻止重复请求
|
||||||
queryParams.value.page += 1
|
if (loadMoreStatus.value.active) {
|
||||||
isLoadMore.value = true
|
return
|
||||||
handleGetData()
|
|
||||||
}
|
}
|
||||||
else {
|
// 有更多数据时继续加载
|
||||||
uni.showToast({ icon: 'none', title: '没有更多数据了' })
|
if (loadMoreStatus.value.hasNext) {
|
||||||
|
queryParams.value.page += 1
|
||||||
|
updateLoadMoreStatus({
|
||||||
|
active: true,
|
||||||
|
status: 'loading',
|
||||||
|
})
|
||||||
|
handleGetData()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
@@ -263,7 +281,7 @@ onReachBottom(() => {
|
|||||||
<block v-else>
|
<block v-else>
|
||||||
<!-- 时间线 -->
|
<!-- 时间线 -->
|
||||||
<view class="timeline px-4 pt-3">
|
<view class="timeline px-4 pt-3">
|
||||||
<view v-for="(item, index) in dataList" :key="item.key" class="timeline-item flex">
|
<view v-for="item in dataList" :key="item.key" class="timeline-item flex">
|
||||||
<!-- <view class="timeline-left w-[96rpx] flex shrink-0 flex-col items-center">
|
<!-- <view class="timeline-left w-[96rpx] flex shrink-0 flex-col items-center">
|
||||||
<view class="timeline-dot mt-2 h-4 w-4 rounded-full bg-secondary shadow-[0_0_0_8rpx_rgba(215,249,76,0.3)]" />
|
<view class="timeline-dot mt-2 h-4 w-4 rounded-full bg-secondary shadow-[0_0_0_8rpx_rgba(215,249,76,0.3)]" />
|
||||||
<view v-if="index !== dataList.length - 1" class="timeline-line mt-2 w-[2rpx] flex-1 bg-black/5" />
|
<view v-if="index !== dataList.length - 1" class="timeline-line mt-2 w-[2rpx] flex-1 bg-black/5" />
|
||||||
@@ -294,9 +312,7 @@ onReachBottom(() => {
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="load-text pb-6 text-center text-[24rpx] text-gray-400">
|
<uh-data-loadmore :status="loadMoreStatus.status" :text="loadMoreStatus.text" />
|
||||||
{{ loadMoreText }}
|
|
||||||
</view>
|
|
||||||
</block>
|
</block>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import { getCategoryList, getPostList } from '@/api/halo'
|
|||||||
import { useAppConfigStore } from '@/store/appConfig'
|
import { useAppConfigStore } from '@/store/appConfig'
|
||||||
import { useSettingStore } from '@/store/setting'
|
import { useSettingStore } from '@/store/setting'
|
||||||
import { checkAvatarUrl } from '@/utils/url'
|
import { checkAvatarUrl } from '@/utils/url'
|
||||||
import { t } from '@/locale'
|
|
||||||
import { DataLoadingStatusEnum, useDataLoadingStatus } from '@/hooks/useDataLoadingStatus'
|
import { DataLoadingStatusEnum, useDataLoadingStatus } from '@/hooks/useDataLoadingStatus'
|
||||||
import { sleep } from '@/utils/common'
|
import { sleep } from '@/utils/common'
|
||||||
import type { ICategory, IPost } from '@/api/types/halo'
|
import type { ICategory, IPost } from '@/api/types/halo'
|
||||||
@@ -27,12 +26,9 @@ const settingStore = useSettingStore()
|
|||||||
const articlesListLayout = computed(() => settingStore.settings.articlesListLayout)
|
const articlesListLayout = computed(() => settingStore.settings.articlesListLayout)
|
||||||
|
|
||||||
/* ---------------- 状态 ---------------- */
|
/* ---------------- 状态 ---------------- */
|
||||||
const { loadingStatus, updateLoadingStatus } = useDataLoadingStatus()
|
const { loadingStatus, loadMoreStatus, updateLoadingStatus, updateLoadMoreStatus, resetLoadMoreStatus } = useDataLoadingStatus()
|
||||||
const articleList = ref<IPost[]>([])
|
const articleList = ref<IPost[]>([])
|
||||||
const queryParams = ref({ size: 10, page: 1 })
|
const queryParams = ref({ size: 10, page: 1 })
|
||||||
const hasNext = ref(false)
|
|
||||||
const isLoadMore = ref(false)
|
|
||||||
const loadMoreText = ref(t('common.loading'))
|
|
||||||
|
|
||||||
interface IFilterOption {
|
interface IFilterOption {
|
||||||
label: string
|
label: string
|
||||||
@@ -67,7 +63,7 @@ function handleSelectFilter(key: 'category' | 'sort', value: string) {
|
|||||||
if (filterValues.value[key] === value)
|
if (filterValues.value[key] === value)
|
||||||
return
|
return
|
||||||
filterValues.value[key] = value
|
filterValues.value[key] = value
|
||||||
isLoadMore.value = false
|
resetLoadMoreStatus()
|
||||||
articleList.value = []
|
articleList.value = []
|
||||||
queryParams.value.page = 1
|
queryParams.value.page = 1
|
||||||
handleGetArticleList()
|
handleGetArticleList()
|
||||||
@@ -87,6 +83,8 @@ async function handleGetCategoryList() {
|
|||||||
/* ---------------- 数据加载 ---------------- */
|
/* ---------------- 数据加载 ---------------- */
|
||||||
async function handleGetArticleList() {
|
async function handleGetArticleList() {
|
||||||
if (calcAuditModeEnabled.value) {
|
if (calcAuditModeEnabled.value) {
|
||||||
|
// 审核模式:真实文章按 audit-data posts 过滤(数组顺序即展示顺序),一次拉取不分页
|
||||||
|
resetLoadMoreStatus()
|
||||||
const auditPostNames = appConfigStore.auditData.spec?.posts || []
|
const auditPostNames = appConfigStore.auditData.spec?.posts || []
|
||||||
try {
|
try {
|
||||||
const res = await getPostList({ page: 1, size: 0, sort: ['spec.publishTime,desc'] })
|
const res = await getPostList({ page: 1, size: 0, sort: ['spec.publishTime,desc'] })
|
||||||
@@ -97,12 +95,19 @@ async function handleGetArticleList() {
|
|||||||
})
|
})
|
||||||
await sleep(600)
|
await sleep(600)
|
||||||
updateLoadingStatus(articleList.value.length === 0 ? DataLoadingStatusEnum.Empty : DataLoadingStatusEnum.Success)
|
updateLoadingStatus(articleList.value.length === 0 ? DataLoadingStatusEnum.Empty : DataLoadingStatusEnum.Success)
|
||||||
loadMoreText.value = t('common.noMore')
|
updateLoadMoreStatus({
|
||||||
|
active: false,
|
||||||
|
status: 'noMore',
|
||||||
|
hasNext: false,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
console.error('获取审核文章失败', err)
|
console.error('获取审核文章失败', err)
|
||||||
updateLoadingStatus(DataLoadingStatusEnum.Error)
|
updateLoadingStatus(DataLoadingStatusEnum.Error)
|
||||||
loadMoreText.value = t('common.loadFailed')
|
updateLoadMoreStatus({
|
||||||
|
active: false,
|
||||||
|
status: 'error',
|
||||||
|
})
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
uni.stopPullDownRefresh()
|
uni.stopPullDownRefresh()
|
||||||
@@ -110,10 +115,9 @@ async function handleGetArticleList() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isLoadMore.value) {
|
if (!loadMoreStatus.value.active) {
|
||||||
updateLoadingStatus(DataLoadingStatusEnum.Loading)
|
updateLoadingStatus(DataLoadingStatusEnum.Loading)
|
||||||
}
|
}
|
||||||
loadMoreText.value = t('common.loading')
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const params = {
|
const params = {
|
||||||
@@ -122,21 +126,33 @@ async function handleGetArticleList() {
|
|||||||
sort: sortMap[filterValues.value.sort] || sortMap.default,
|
sort: sortMap[filterValues.value.sort] || sortMap.default,
|
||||||
}
|
}
|
||||||
const res = await getPostList(params)
|
const res = await getPostList(params)
|
||||||
hasNext.value = res.data.hasNext
|
articleList.value = (loadMoreStatus.value.active
|
||||||
articleList.value = (isLoadMore.value
|
|
||||||
? articleList.value.concat(res.data.items)
|
? articleList.value.concat(res.data.items)
|
||||||
: res.data.items).map((item) => {
|
: res.data.items).map((item) => {
|
||||||
item.owner.avatar = checkAvatarUrl(item.owner.avatar)
|
item.owner.avatar = checkAvatarUrl(item.owner.avatar)
|
||||||
return item
|
return item
|
||||||
})
|
})
|
||||||
|
if (!loadMoreStatus.value.active) {
|
||||||
await sleep(600)
|
await sleep(600)
|
||||||
updateLoadingStatus(articleList.value.length === 0 ? DataLoadingStatusEnum.Empty : DataLoadingStatusEnum.Success)
|
updateLoadingStatus(articleList.value.length === 0 ? DataLoadingStatusEnum.Empty : DataLoadingStatusEnum.Success)
|
||||||
loadMoreText.value = res.data.hasNext ? t('common.loadMore') : t('common.noMore')
|
}
|
||||||
|
updateLoadMoreStatus({
|
||||||
|
active: false,
|
||||||
|
status: res.data.hasNext ? 'loadMore' : 'noMore',
|
||||||
|
hasNext: res.data.hasNext,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
updateLoadingStatus(DataLoadingStatusEnum.Error)
|
|
||||||
loadMoreText.value = t('common.loadFailed')
|
|
||||||
console.error('获取文章失败', err)
|
console.error('获取文章失败', err)
|
||||||
|
if (loadMoreStatus.value.active) {
|
||||||
|
updateLoadMoreStatus({
|
||||||
|
active: false,
|
||||||
|
status: 'error',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
updateLoadingStatus(DataLoadingStatusEnum.Error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
uni.stopPullDownRefresh()
|
uni.stopPullDownRefresh()
|
||||||
@@ -153,7 +169,7 @@ onPullDownRefresh(() => {
|
|||||||
uni.stopPullDownRefresh()
|
uni.stopPullDownRefresh()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
isLoadMore.value = false
|
resetLoadMoreStatus()
|
||||||
queryParams.value.page = 1
|
queryParams.value.page = 1
|
||||||
articleList.value = []
|
articleList.value = []
|
||||||
handleGetArticleList()
|
handleGetArticleList()
|
||||||
@@ -164,13 +180,18 @@ onReachBottom(() => {
|
|||||||
uni.showToast({ icon: 'none', title: '没有更多数据了' })
|
uni.showToast({ icon: 'none', title: '没有更多数据了' })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (hasNext.value) {
|
// 正在加载时阻止重复请求
|
||||||
queryParams.value.page += 1
|
if (loadMoreStatus.value.active) {
|
||||||
isLoadMore.value = true
|
return
|
||||||
handleGetArticleList()
|
|
||||||
}
|
}
|
||||||
else {
|
// 有更多数据时继续加载
|
||||||
uni.showToast({ icon: 'none', title: '没有更多数据了' })
|
if (loadMoreStatus.value.hasNext) {
|
||||||
|
queryParams.value.page += 1
|
||||||
|
updateLoadMoreStatus({
|
||||||
|
active: true,
|
||||||
|
status: 'loading',
|
||||||
|
})
|
||||||
|
handleGetArticleList()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
@@ -224,9 +245,7 @@ onReachBottom(() => {
|
|||||||
:audit-mode="calcAuditModeEnabled"
|
:audit-mode="calcAuditModeEnabled"
|
||||||
/>
|
/>
|
||||||
</view>
|
</view>
|
||||||
<view class="box-border py-5 text-center text-xs text-gray-400">
|
<uh-data-loadmore :status="loadMoreStatus.status" :text="loadMoreStatus.text" />
|
||||||
{{ loadMoreText }}
|
|
||||||
</view>
|
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
import { onLoad, onPullDownRefresh, onReachBottom, onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app'
|
import { onLoad, onPullDownRefresh, onReachBottom, onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app'
|
||||||
import { getCategoryPostList } from '@/api/halo'
|
import { getCategoryPostList } from '@/api/halo'
|
||||||
|
import { sleep } from '@/utils/common'
|
||||||
import { DataLoadingStatusEnum, useDataLoadingStatus } from '@/hooks/useDataLoadingStatus'
|
import { DataLoadingStatusEnum, useDataLoadingStatus } from '@/hooks/useDataLoadingStatus'
|
||||||
import type { IPost, IPostListReq } from '@/api/types/halo'
|
import type { IPost, IPostListReq } from '@/api/types/halo'
|
||||||
|
|
||||||
@@ -13,15 +14,12 @@ definePage({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const { loadingStatus, updateLoadingStatus } = useDataLoadingStatus()
|
const { loadingStatus, loadMoreStatus, updateLoadingStatus, updateLoadMoreStatus, resetLoadMoreStatus } = useDataLoadingStatus()
|
||||||
const queryParams = ref({ size: 10, page: 0 })
|
const queryParams = ref({ size: 10, page: 0 })
|
||||||
const name = ref('')
|
const name = ref('')
|
||||||
const pageTitle = ref('加载中...')
|
const pageTitle = ref('加载中...')
|
||||||
const navbarTitle = ref('分类详情')
|
const navbarTitle = ref('分类详情')
|
||||||
const hasNext = ref(false)
|
|
||||||
const dataList = ref<IPost[]>([])
|
const dataList = ref<IPost[]>([])
|
||||||
const isLoadMore = ref(false)
|
|
||||||
const loadMoreText = ref('')
|
|
||||||
|
|
||||||
/* ---------------- 排序切换(sort 参数由接口透传,见 IPostListReq.sort) ---------------- */
|
/* ---------------- 排序切换(sort 参数由接口透传,见 IPostListReq.sort) ---------------- */
|
||||||
const sortOptions: { key: string; label: string; sort?: string[] }[] = [
|
const sortOptions: { key: string; label: string; sort?: string[] }[] = [
|
||||||
@@ -36,16 +34,15 @@ function handleSortChange(key: string) {
|
|||||||
if (activeSort.value === key)
|
if (activeSort.value === key)
|
||||||
return
|
return
|
||||||
activeSort.value = key
|
activeSort.value = key
|
||||||
isLoadMore.value = false
|
resetLoadMoreStatus()
|
||||||
queryParams.value.page = 0
|
queryParams.value.page = 0
|
||||||
handleGetData()
|
handleGetData()
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleGetData() {
|
async function handleGetData() {
|
||||||
if (!isLoadMore.value) {
|
if (!loadMoreStatus.value.active) {
|
||||||
updateLoadingStatus(DataLoadingStatusEnum.Loading)
|
updateLoadingStatus(DataLoadingStatusEnum.Loading)
|
||||||
}
|
}
|
||||||
loadMoreText.value = '加载中...'
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const reqParams: Record<string, unknown> = { ...queryParams.value }
|
const reqParams: Record<string, unknown> = { ...queryParams.value }
|
||||||
@@ -58,26 +55,35 @@ async function handleGetData() {
|
|||||||
}
|
}
|
||||||
const res = await getCategoryPostList(name.value, reqParams as IPostListReq)
|
const res = await getCategoryPostList(name.value, reqParams as IPostListReq)
|
||||||
navbarTitle.value = `${pageTitle.value} (共${res.data.total}篇)`
|
navbarTitle.value = `${pageTitle.value} (共${res.data.total}篇)`
|
||||||
hasNext.value = res.data.hasNext
|
dataList.value = loadMoreStatus.value.active
|
||||||
dataList.value = isLoadMore.value
|
|
||||||
? dataList.value.concat(res.data.items)
|
? dataList.value.concat(res.data.items)
|
||||||
: res.data.items
|
: res.data.items
|
||||||
loadMoreText.value = res.data.hasNext ? '上拉加载更多' : '呜呜,没有更多数据啦~'
|
if (!loadMoreStatus.value.active) {
|
||||||
setTimeout(() => {
|
await sleep(600)
|
||||||
updateLoadingStatus(
|
updateLoadingStatus(
|
||||||
dataList.value.length === 0 ? DataLoadingStatusEnum.Empty : DataLoadingStatusEnum.Success,
|
dataList.value.length === 0 ? DataLoadingStatusEnum.Empty : DataLoadingStatusEnum.Success,
|
||||||
)
|
)
|
||||||
}, 500)
|
}
|
||||||
|
updateLoadMoreStatus({
|
||||||
|
active: false,
|
||||||
|
status: res.data.hasNext ? 'loadMore' : 'noMore',
|
||||||
|
hasNext: res.data.hasNext,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
|
if (loadMoreStatus.value.active) {
|
||||||
|
updateLoadMoreStatus({
|
||||||
|
active: false,
|
||||||
|
status: 'error',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else {
|
||||||
updateLoadingStatus(DataLoadingStatusEnum.Error)
|
updateLoadingStatus(DataLoadingStatusEnum.Error)
|
||||||
loadMoreText.value = '加载失败,请下拉刷新!'
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
setTimeout(() => {
|
|
||||||
uni.stopPullDownRefresh()
|
uni.stopPullDownRefresh()
|
||||||
}, 500)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,19 +102,24 @@ onLoad((options) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
onPullDownRefresh(() => {
|
onPullDownRefresh(() => {
|
||||||
isLoadMore.value = false
|
resetLoadMoreStatus()
|
||||||
queryParams.value.page = 0
|
queryParams.value.page = 0
|
||||||
handleGetData()
|
handleGetData()
|
||||||
})
|
})
|
||||||
|
|
||||||
onReachBottom(() => {
|
onReachBottom(() => {
|
||||||
if (hasNext.value) {
|
// 正在加载时阻止重复请求
|
||||||
queryParams.value.page += 1
|
if (loadMoreStatus.value.active) {
|
||||||
isLoadMore.value = true
|
return
|
||||||
handleGetData()
|
|
||||||
}
|
}
|
||||||
else {
|
// 有更多数据时继续加载
|
||||||
uni.showToast({ icon: 'none', title: '没有更多数据了' })
|
if (loadMoreStatus.value.hasNext) {
|
||||||
|
queryParams.value.page += 1
|
||||||
|
updateLoadMoreStatus({
|
||||||
|
active: true,
|
||||||
|
status: 'loading',
|
||||||
|
})
|
||||||
|
handleGetData()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -158,9 +169,7 @@ onShareTimeline(() => ({
|
|||||||
:article="article"
|
:article="article"
|
||||||
@on-click="handleToArticleDetail"
|
@on-click="handleToArticleDetail"
|
||||||
/>
|
/>
|
||||||
<view class="load-text py-5 text-center text-[24rpx] text-[#999]">
|
<uh-data-loadmore :status="loadMoreStatus.status" :text="loadMoreStatus.text" />
|
||||||
{{ loadMoreText }}
|
|
||||||
</view>
|
|
||||||
</view>
|
</view>
|
||||||
</block>
|
</block>
|
||||||
</view>
|
</view>
|
||||||
|
|||||||
@@ -92,12 +92,9 @@ watch(() => appConfigStore.auditModeEnabled, (enabled) => {
|
|||||||
|
|
||||||
/* ==================== 站点 tab(plugin-links) ==================== */
|
/* ==================== 站点 tab(plugin-links) ==================== */
|
||||||
/* ---------------- 状态 ---------------- */
|
/* ---------------- 状态 ---------------- */
|
||||||
const { loadingStatus: siteLoadingStatus, updateLoadingStatus: updateSiteLoadingStatus } = useDataLoadingStatus()
|
const { loadingStatus: siteLoadingStatus, loadMoreStatus: siteLoadMoreStatus, updateLoadingStatus: updateSiteLoadingStatus, updateLoadMoreStatus: updateSiteLoadMoreStatus, resetLoadMoreStatus: resetSiteLoadMoreStatus } = useDataLoadingStatus()
|
||||||
const queryParams = ref({ size: 10, page: 1 })
|
const queryParams = ref({ size: 10, page: 1 })
|
||||||
const detail = ref<{ show: boolean, data: ILink | null }>({ show: false, data: null })
|
const detail = ref<{ show: boolean, data: ILink | null }>({ show: false, data: null })
|
||||||
const hasNext = ref(false)
|
|
||||||
const isLoadMore = ref(false)
|
|
||||||
const loadMoreText = ref('')
|
|
||||||
const linkGroupList = ref<ILinkGroup[]>([])
|
const linkGroupList = ref<ILinkGroup[]>([])
|
||||||
const dataList = ref<ILink[]>([])
|
const dataList = ref<ILink[]>([])
|
||||||
|
|
||||||
@@ -122,14 +119,12 @@ async function handleGetLinkGroupData() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function handleGetData() {
|
async function handleGetData() {
|
||||||
if (!isLoadMore.value) {
|
if (!siteLoadMoreStatus.value.active) {
|
||||||
updateSiteLoadingStatus(DataLoadingStatusEnum.Loading)
|
updateSiteLoadingStatus(DataLoadingStatusEnum.Loading)
|
||||||
}
|
}
|
||||||
loadMoreText.value = ''
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await getFriendLinkList({ ...queryParams.value })
|
const res = await getFriendLinkList({ ...queryParams.value })
|
||||||
hasNext.value = res.data.hasNext
|
|
||||||
// 审核模式:站点链接仅展示选中 LinkGroup 分组内的
|
// 审核模式:站点链接仅展示选中 LinkGroup 分组内的
|
||||||
let items = res.data.items
|
let items = res.data.items
|
||||||
if (appConfigStore.auditModeEnabled) {
|
if (appConfigStore.auditModeEnabled) {
|
||||||
@@ -145,17 +140,30 @@ async function handleGetData() {
|
|||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
// 分页加载时累加,首次/刷新时覆盖(修复重复数据)
|
// 分页加载时累加,首次/刷新时覆盖(修复重复数据)
|
||||||
dataList.value = isLoadMore.value ? dataList.value.concat(list) : list
|
dataList.value = siteLoadMoreStatus.value.active ? dataList.value.concat(list) : list
|
||||||
|
if (!siteLoadMoreStatus.value.active) {
|
||||||
await sleep(600)
|
await sleep(600)
|
||||||
updateSiteLoadingStatus(
|
updateSiteLoadingStatus(
|
||||||
dataList.value.length === 0 ? DataLoadingStatusEnum.Empty : DataLoadingStatusEnum.Success,
|
dataList.value.length === 0 ? DataLoadingStatusEnum.Empty : DataLoadingStatusEnum.Success,
|
||||||
)
|
)
|
||||||
loadMoreText.value = res.data.hasNext ? '上拉加载更多' : '呜呜,没有更多数据啦~'
|
}
|
||||||
|
updateSiteLoadMoreStatus({
|
||||||
|
active: false,
|
||||||
|
status: res.data.hasNext ? 'loadMore' : 'noMore',
|
||||||
|
hasNext: res.data.hasNext,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
|
if (siteLoadMoreStatus.value.active) {
|
||||||
|
updateSiteLoadMoreStatus({
|
||||||
|
active: false,
|
||||||
|
status: 'error',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else {
|
||||||
updateSiteLoadingStatus(DataLoadingStatusEnum.Error)
|
updateSiteLoadingStatus(DataLoadingStatusEnum.Error)
|
||||||
loadMoreText.value = '加载失败,请下拉刷新!'
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
uni.stopPullDownRefresh()
|
uni.stopPullDownRefresh()
|
||||||
@@ -358,7 +366,7 @@ onPullDownRefresh(() => {
|
|||||||
uni.stopPullDownRefresh()
|
uni.stopPullDownRefresh()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
isLoadMore.value = false
|
resetSiteLoadMoreStatus()
|
||||||
queryParams.value.page = 1
|
queryParams.value.page = 1
|
||||||
dataList.value = []
|
dataList.value = []
|
||||||
handleGetData()
|
handleGetData()
|
||||||
@@ -376,13 +384,18 @@ onReachBottom(() => {
|
|||||||
if (activeTabIndex.value === 0) {
|
if (activeTabIndex.value === 0) {
|
||||||
if (!sitePluginAvailable.value)
|
if (!sitePluginAvailable.value)
|
||||||
return
|
return
|
||||||
if (hasNext.value) {
|
// 正在加载时阻止重复请求
|
||||||
queryParams.value.page += 1
|
if (siteLoadMoreStatus.value.active) {
|
||||||
isLoadMore.value = true
|
return
|
||||||
handleGetData()
|
|
||||||
}
|
}
|
||||||
else {
|
// 有更多数据时继续加载
|
||||||
uni.showToast({ icon: 'none', title: '没有更多数据了' })
|
if (siteLoadMoreStatus.value.hasNext) {
|
||||||
|
queryParams.value.page += 1
|
||||||
|
updateSiteLoadMoreStatus({
|
||||||
|
active: true,
|
||||||
|
status: 'loading',
|
||||||
|
})
|
||||||
|
handleGetData()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -513,9 +526,7 @@ onReachBottom(() => {
|
|||||||
</scroll-view>
|
</scroll-view>
|
||||||
</uh-glass-popup>
|
</uh-glass-popup>
|
||||||
|
|
||||||
<view class="load-text py-5 text-center text-xs text-gray-400">
|
<uh-data-loadmore :status="siteLoadMoreStatus.status" :text="siteLoadMoreStatus.text" />
|
||||||
{{ loadMoreText }}
|
|
||||||
</view>
|
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed, ref } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
import { onLoad, onPullDownRefresh } from '@dcloudio/uni-app'
|
import { onLoad, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app'
|
||||||
import { getPostListByKeyword } from '@/api/halo'
|
import { getPostListByKeyword } from '@/api/halo'
|
||||||
import { sleep } from '@/utils/common'
|
import { sleep } from '@/utils/common'
|
||||||
import { useAppConfigStore } from '@/store/appConfig'
|
import { useAppConfigStore } from '@/store/appConfig'
|
||||||
@@ -38,10 +38,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------- 状态 ---------------- */
|
/* ---------------- 状态 ---------------- */
|
||||||
const { loadingStatus, updateLoadingStatus } = useDataLoadingStatus()
|
const { loadingStatus, loadMoreStatus, updateLoadingStatus, updateLoadMoreStatus, resetLoadMoreStatus } = useDataLoadingStatus()
|
||||||
const queryParams = ref({
|
const queryParams = ref({
|
||||||
keyword: '',
|
keyword: '',
|
||||||
limit: 50,
|
page: 1,
|
||||||
|
size: 10,
|
||||||
highlightPreTag: '',
|
highlightPreTag: '',
|
||||||
highlightPostTag: '',
|
highlightPostTag: '',
|
||||||
})
|
})
|
||||||
@@ -73,32 +74,53 @@
|
|||||||
async function handleGetData() {
|
async function handleGetData() {
|
||||||
if (calcAuditModeEnabled.value)
|
if (calcAuditModeEnabled.value)
|
||||||
{return}
|
{return}
|
||||||
|
if (!loadMoreStatus.value.active) {
|
||||||
updateLoadingStatus(DataLoadingStatusEnum.Loading)
|
updateLoadingStatus(DataLoadingStatusEnum.Loading)
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const res = await getPostListByKeyword({ ...queryParams.value })
|
const res = await getPostListByKeyword({ ...queryParams.value })
|
||||||
dataList.value = (res.data as unknown as { hits ?: typeof dataList.value }).hits || []
|
const hits = (res.data as unknown as { hits ?: typeof dataList.value }).hits || []
|
||||||
|
dataList.value = loadMoreStatus.value.active
|
||||||
|
? dataList.value.concat(hits)
|
||||||
|
: hits
|
||||||
|
if (!loadMoreStatus.value.active) {
|
||||||
await sleep(600)
|
await sleep(600)
|
||||||
updateLoadingStatus(
|
updateLoadingStatus(
|
||||||
dataList.value.length === 0 ? DataLoadingStatusEnum.Empty : DataLoadingStatusEnum.Success,
|
dataList.value.length === 0 ? DataLoadingStatusEnum.Empty : DataLoadingStatusEnum.Success,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
updateLoadMoreStatus({
|
||||||
|
active: false,
|
||||||
|
status: res.data.hasNext ? 'loadMore' : 'noMore',
|
||||||
|
hasNext: res.data.hasNext,
|
||||||
|
})
|
||||||
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
|
if (loadMoreStatus.value.active) {
|
||||||
|
updateLoadMoreStatus({
|
||||||
|
active: false,
|
||||||
|
status: 'error',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else {
|
||||||
updateLoadingStatus(DataLoadingStatusEnum.Error)
|
updateLoadingStatus(DataLoadingStatusEnum.Error)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
finally {
|
finally {
|
||||||
setTimeout(() => {
|
|
||||||
uni.stopPullDownRefresh()
|
uni.stopPullDownRefresh()
|
||||||
}, 800)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleOnSearch() {
|
function handleOnSearch() {
|
||||||
if (!queryParams.value.keyword) {
|
if (!queryParams.value.keyword) {
|
||||||
dataList.value = []
|
dataList.value = []
|
||||||
|
resetLoadMoreStatus()
|
||||||
updateLoadingStatus(DataLoadingStatusEnum.Empty)
|
updateLoadingStatus(DataLoadingStatusEnum.Empty)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
resetLoadMoreStatus()
|
||||||
|
queryParams.value.page = 1
|
||||||
handleGetData()
|
handleGetData()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -156,6 +178,29 @@
|
|||||||
}
|
}
|
||||||
handleOnSearch()
|
handleOnSearch()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
onReachBottom(() => {
|
||||||
|
if (!uniHaloPluginAvailable.value)
|
||||||
|
return
|
||||||
|
if (calcAuditModeEnabled.value)
|
||||||
|
return
|
||||||
|
// 无关键词不触发分页
|
||||||
|
if (!queryParams.value.keyword)
|
||||||
|
return
|
||||||
|
// 正在加载时阻止重复请求
|
||||||
|
if (loadMoreStatus.value.active) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 有更多数据时继续加载
|
||||||
|
if (loadMoreStatus.value.hasNext) {
|
||||||
|
queryParams.value.page += 1
|
||||||
|
updateLoadMoreStatus({
|
||||||
|
active: true,
|
||||||
|
status: 'loading',
|
||||||
|
})
|
||||||
|
handleGetData()
|
||||||
|
}
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -208,6 +253,7 @@
|
|||||||
:show-language-name="true" copy-by-long-press />
|
:show-language-name="true" copy-by-long-press />
|
||||||
</view>
|
</view>
|
||||||
</block>
|
</block>
|
||||||
|
<uh-data-loadmore :status="loadMoreStatus.status" :text="loadMoreStatus.text" />
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
</view>
|
</view>
|
||||||
|
|||||||
@@ -40,11 +40,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------- 状态 ---------------- */
|
/* ---------------- 状态 ---------------- */
|
||||||
const { loadingStatus, updateLoadingStatus } = useDataLoadingStatus()
|
const { loadingStatus, loadMoreStatus, updateLoadingStatus, updateLoadMoreStatus, resetLoadMoreStatus } = useDataLoadingStatus()
|
||||||
const dataList = ref<IVoteItem[]>([])
|
const dataList = ref<IVoteItem[]>([])
|
||||||
const hasNext = ref(false)
|
|
||||||
const isLoadMore = ref(false)
|
|
||||||
const loadMoreText = ref('加载中...')
|
|
||||||
const filterIsVoted = ref<boolean | undefined>(undefined)
|
const filterIsVoted = ref<boolean | undefined>(undefined)
|
||||||
const queryParams = ref<Record<string, unknown>>({
|
const queryParams = ref<Record<string, unknown>>({
|
||||||
keyword: '',
|
keyword: '',
|
||||||
@@ -145,7 +142,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
queryParams.value.page = 1
|
queryParams.value.page = 1
|
||||||
isLoadMore.value = false
|
resetLoadMoreStatus()
|
||||||
handleGetData()
|
handleGetData()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,35 +150,39 @@
|
|||||||
/** 实时搜索:输入防抖 400ms 后触发 */
|
/** 实时搜索:输入防抖 400ms 后触发 */
|
||||||
const handleOnInput = debounce(() => {
|
const handleOnInput = debounce(() => {
|
||||||
queryParams.value.page = 1
|
queryParams.value.page = 1
|
||||||
isLoadMore.value = false
|
resetLoadMoreStatus()
|
||||||
handleGetData()
|
handleGetData()
|
||||||
}, 400)
|
}, 400)
|
||||||
|
|
||||||
function handleOnSearch() {
|
function handleOnSearch() {
|
||||||
queryParams.value.page = 1
|
queryParams.value.page = 1
|
||||||
isLoadMore.value = false
|
resetLoadMoreStatus()
|
||||||
handleGetData()
|
handleGetData()
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------- 数据加载 ---------------- */
|
/* ---------------- 数据加载 ---------------- */
|
||||||
async function handleGetData() {
|
async function handleGetData() {
|
||||||
if (calcAuditModeEnabled.value) {
|
if (calcAuditModeEnabled.value) {
|
||||||
|
// 审核模式:一次拉取不分页
|
||||||
|
resetLoadMoreStatus()
|
||||||
updateLoadingStatus(
|
updateLoadingStatus(
|
||||||
dataList.value.length === 0 ? DataLoadingStatusEnum.Empty : DataLoadingStatusEnum.Success,
|
dataList.value.length === 0 ? DataLoadingStatusEnum.Empty : DataLoadingStatusEnum.Success,
|
||||||
)
|
)
|
||||||
loadMoreText.value = '呜呜,没有更多数据啦~'
|
updateLoadMoreStatus({
|
||||||
|
active: false,
|
||||||
|
status: 'noMore',
|
||||||
|
hasNext: false,
|
||||||
|
})
|
||||||
uni.stopPullDownRefresh()
|
uni.stopPullDownRefresh()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isLoadMore.value) {
|
if (!loadMoreStatus.value.active) {
|
||||||
updateLoadingStatus(DataLoadingStatusEnum.Loading)
|
updateLoadingStatus(DataLoadingStatusEnum.Loading)
|
||||||
}
|
}
|
||||||
loadMoreText.value = '加载中...'
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await getVoteList({ ...queryParams.value })
|
const res = await getVoteList({ ...queryParams.value })
|
||||||
hasNext.value = res.data.hasNext || false
|
|
||||||
|
|
||||||
const tempItems = res.data.items.map((item) => {
|
const tempItems = res.data.items.map((item) => {
|
||||||
item.spec = item.spec || {}
|
item.spec = item.spec || {}
|
||||||
@@ -192,7 +193,7 @@
|
|||||||
return item
|
return item
|
||||||
})
|
})
|
||||||
|
|
||||||
dataList.value = isLoadMore.value
|
dataList.value = loadMoreStatus.value.active
|
||||||
? dataList.value.concat(tempItems)
|
? dataList.value.concat(tempItems)
|
||||||
: tempItems
|
: tempItems
|
||||||
|
|
||||||
@@ -205,16 +206,29 @@
|
|||||||
if (filterIsVoted.value !== undefined) {
|
if (filterIsVoted.value !== undefined) {
|
||||||
dataList.value = dataList.value.filter(x => x.spec?.isVoted === filterIsVoted.value)
|
dataList.value = dataList.value.filter(x => x.spec?.isVoted === filterIsVoted.value)
|
||||||
}
|
}
|
||||||
|
if (!loadMoreStatus.value.active) {
|
||||||
await sleep(600)
|
await sleep(600)
|
||||||
updateLoadingStatus(
|
updateLoadingStatus(
|
||||||
dataList.value.length === 0 ? DataLoadingStatusEnum.Empty : DataLoadingStatusEnum.Success,
|
dataList.value.length === 0 ? DataLoadingStatusEnum.Empty : DataLoadingStatusEnum.Success,
|
||||||
)
|
)
|
||||||
loadMoreText.value = hasNext.value ? '上拉加载更多' : '呜呜,没有更多数据啦~'
|
}
|
||||||
|
updateLoadMoreStatus({
|
||||||
|
active: false,
|
||||||
|
status: res.data.hasNext ? 'loadMore' : 'noMore',
|
||||||
|
hasNext: res.data.hasNext,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
|
if (loadMoreStatus.value.active) {
|
||||||
|
updateLoadMoreStatus({
|
||||||
|
active: false,
|
||||||
|
status: 'error',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else {
|
||||||
updateLoadingStatus(DataLoadingStatusEnum.Error)
|
updateLoadingStatus(DataLoadingStatusEnum.Error)
|
||||||
loadMoreText.value = '加载失败,请下拉刷新!'
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
uni.stopPullDownRefresh()
|
uni.stopPullDownRefresh()
|
||||||
@@ -256,7 +270,7 @@
|
|||||||
uni.stopPullDownRefresh()
|
uni.stopPullDownRefresh()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
isLoadMore.value = false
|
resetLoadMoreStatus()
|
||||||
queryParams.value.page = 1
|
queryParams.value.page = 1
|
||||||
handleGetData()
|
handleGetData()
|
||||||
})
|
})
|
||||||
@@ -268,13 +282,18 @@
|
|||||||
uni.showToast({ icon: 'none', title: '没有更多数据了' })
|
uni.showToast({ icon: 'none', title: '没有更多数据了' })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (hasNext.value) {
|
// 正在加载时阻止重复请求
|
||||||
queryParams.value.page = Number(queryParams.value.page) + 1
|
if (loadMoreStatus.value.active) {
|
||||||
isLoadMore.value = true
|
return
|
||||||
handleGetData()
|
|
||||||
}
|
}
|
||||||
else {
|
// 有更多数据时继续加载
|
||||||
uni.showToast({ icon: 'none', title: '没有更多数据了' })
|
if (loadMoreStatus.value.hasNext) {
|
||||||
|
queryParams.value.page = Number(queryParams.value.page) + 1
|
||||||
|
updateLoadMoreStatus({
|
||||||
|
active: true,
|
||||||
|
status: 'loading',
|
||||||
|
})
|
||||||
|
handleGetData()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
@@ -319,9 +338,7 @@
|
|||||||
<block v-if="dataList.length !== 0">
|
<block v-if="dataList.length !== 0">
|
||||||
<uh-vote-card v-for="vote in dataList" :key="vote.metadata?.name" :vote="vote"
|
<uh-vote-card v-for="vote in dataList" :key="vote.metadata?.name" :vote="vote"
|
||||||
@click="handleOnVoteClick(vote)" />
|
@click="handleOnVoteClick(vote)" />
|
||||||
<view class="box-border py-5 text-center text-xs text-gray-400">
|
<uh-data-loadmore :status="loadMoreStatus.status" :text="loadMoreStatus.text" />
|
||||||
{{ loadMoreText }}
|
|
||||||
</view>
|
|
||||||
</block>
|
</block>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed, ref, watch } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
import { onLoad, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app'
|
import { onLoad, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app'
|
||||||
import { getPhotoGroupList, getPhotoListByGroupName } from '@/api/halo'
|
import { getPhotoGroupList, getPhotoListByGroupName } from '@/api/halo'
|
||||||
import { useAppConfigStore } from '@/store/appConfig'
|
import { useAppConfigStore } from '@/store/appConfig'
|
||||||
@@ -39,15 +39,12 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
/* ---------------- 状态 ---------------- */
|
/* ---------------- 状态 ---------------- */
|
||||||
const { loadingStatus, updateLoadingStatus } = useDataLoadingStatus()
|
const { loadingStatus, loadMoreStatus, updateLoadingStatus, updateLoadMoreStatus, resetLoadMoreStatus } = useDataLoadingStatus()
|
||||||
const category = ref<{ activeIndex : number, list : IPhotoGroup[] }>({
|
const category = ref<{ activeIndex : number, list : IPhotoGroup[] }>({
|
||||||
activeIndex: 0,
|
activeIndex: 0,
|
||||||
list: [],
|
list: [],
|
||||||
})
|
})
|
||||||
const queryParams = ref({ size: 10, page: 1, group: '' })
|
const queryParams = ref({ size: 10, page: 1, group: '' })
|
||||||
const isLoadMore = ref(false)
|
|
||||||
const loadMoreText = ref('')
|
|
||||||
const hasNext = ref(false)
|
|
||||||
const dataList = ref<IPhoto[]>([])
|
const dataList = ref<IPhoto[]>([])
|
||||||
const lock = ref(false)
|
const lock = ref(false)
|
||||||
|
|
||||||
@@ -67,7 +64,11 @@
|
|||||||
handleGetData(true)
|
handleGetData(true)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
loadMoreText.value = t('common.noMore')
|
updateLoadMoreStatus({
|
||||||
|
active: false,
|
||||||
|
status: 'noMore',
|
||||||
|
hasNext: false,
|
||||||
|
})
|
||||||
uni.stopPullDownRefresh()
|
uni.stopPullDownRefresh()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -97,33 +98,45 @@
|
|||||||
if (isClearList) {
|
if (isClearList) {
|
||||||
dataList.value = []
|
dataList.value = []
|
||||||
queryParams.value.page = 1
|
queryParams.value.page = 1
|
||||||
|
resetLoadMoreStatus()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isLoadMore.value) {
|
if (!loadMoreStatus.value.active) {
|
||||||
updateLoadingStatus(DataLoadingStatusEnum.Loading)
|
updateLoadingStatus(DataLoadingStatusEnum.Loading)
|
||||||
}
|
}
|
||||||
loadMoreText.value = ''
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await getPhotoListByGroupName({ ...queryParams.value })
|
const res = await getPhotoListByGroupName({ ...queryParams.value })
|
||||||
hasNext.value = res.data.hasNext
|
|
||||||
if (res.data.items.length !== 0) {
|
if (res.data.items.length !== 0) {
|
||||||
const list = res.data.items.map(item => ({
|
const list = res.data.items.map(item => ({
|
||||||
...item,
|
...item,
|
||||||
spec: { ...item.spec, url: checkImageUrl(item.spec.url || item.spec.cover) },
|
spec: { ...item.spec, url: checkImageUrl(item.spec.url || item.spec.cover) },
|
||||||
}))
|
}))
|
||||||
dataList.value = isLoadMore.value
|
dataList.value = loadMoreStatus.value.active
|
||||||
? dataList.value.concat(list)
|
? dataList.value.concat(list)
|
||||||
: list
|
: list
|
||||||
}
|
}
|
||||||
|
if (!loadMoreStatus.value.active) {
|
||||||
await sleep(600)
|
await sleep(600)
|
||||||
updateLoadingStatus(dataList.value.length === 0 ? DataLoadingStatusEnum.Empty : DataLoadingStatusEnum.Success)
|
updateLoadingStatus(dataList.value.length === 0 ? DataLoadingStatusEnum.Empty : DataLoadingStatusEnum.Success)
|
||||||
loadMoreText.value = res.data.hasNext ? t('common.loadMore') : t('common.noMore')
|
}
|
||||||
|
updateLoadMoreStatus({
|
||||||
|
active: false,
|
||||||
|
status: res.data.hasNext ? 'loadMore' : 'noMore',
|
||||||
|
hasNext: res.data.hasNext,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
|
if (loadMoreStatus.value.active) {
|
||||||
|
updateLoadMoreStatus({
|
||||||
|
active: false,
|
||||||
|
status: 'error',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else {
|
||||||
updateLoadingStatus(DataLoadingStatusEnum.Error)
|
updateLoadingStatus(DataLoadingStatusEnum.Error)
|
||||||
loadMoreText.value = t('common.loadFailed')
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
uni.stopPullDownRefresh()
|
uni.stopPullDownRefresh()
|
||||||
@@ -167,7 +180,6 @@
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
dataList.value = []
|
dataList.value = []
|
||||||
isLoadMore.value = false
|
|
||||||
queryParams.value.page = 1
|
queryParams.value.page = 1
|
||||||
handleGetData(true)
|
handleGetData(true)
|
||||||
})
|
})
|
||||||
@@ -178,13 +190,18 @@
|
|||||||
uni.showToast({ icon: 'none', title: t('common.noMoreData') })
|
uni.showToast({ icon: 'none', title: t('common.noMoreData') })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (hasNext.value) {
|
// 正在加载时阻止重复请求
|
||||||
queryParams.value.page += 1
|
if (loadMoreStatus.value.active) {
|
||||||
isLoadMore.value = true
|
return
|
||||||
handleGetData(false)
|
|
||||||
}
|
}
|
||||||
else {
|
// 有更多数据时继续加载
|
||||||
uni.showToast({ icon: 'none', title: t('common.noMoreData') })
|
if (loadMoreStatus.value.hasNext) {
|
||||||
|
queryParams.value.page += 1
|
||||||
|
updateLoadMoreStatus({
|
||||||
|
active: true,
|
||||||
|
status: 'loading',
|
||||||
|
})
|
||||||
|
handleGetData(false)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
@@ -226,9 +243,7 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="load-text w-full py-4 text-center text-xs text-gray-500">
|
<uh-data-loadmore :status="loadMoreStatus.status" :text="loadMoreStatus.text" />
|
||||||
{{ loadMoreText }}
|
|
||||||
</view>
|
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
</view>
|
</view>
|
||||||
|
|||||||
Reference in New Issue
Block a user