mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-07-01 04:21:37 +08:00
perf: optimize infinite list loading
This commit is contained in:
@@ -6,6 +6,7 @@ import { useDisplay } from 'vuetify'
|
||||
import ProgressDialog from './ProgressDialog.vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { mediaTypeDict } from '@/api/constants'
|
||||
import type { InfiniteScrollDone } from '@/composables/usePaginatedInfiniteScroll'
|
||||
|
||||
// 国际化
|
||||
const { t } = useI18n()
|
||||
@@ -24,9 +25,6 @@ const emit = defineEmits(['close', 'save'])
|
||||
// 订阅历史列表
|
||||
const historyList = ref<Subscribe[]>([])
|
||||
|
||||
// 当前加载数据
|
||||
const currData = ref<Subscribe[]>([])
|
||||
|
||||
// 当前页
|
||||
const currentPage = ref(1)
|
||||
|
||||
@@ -46,7 +44,7 @@ const progressDialog = ref(false)
|
||||
const progressText = ref('')
|
||||
|
||||
// 调用API查询列表
|
||||
async function loadHistory({ done }: { done: any }) {
|
||||
async function loadHistory({ done }: { done: InfiniteScrollDone }) {
|
||||
// 如果正在加载中,直接返回
|
||||
if (loading.value) {
|
||||
done('ok')
|
||||
@@ -57,7 +55,7 @@ async function loadHistory({ done }: { done: any }) {
|
||||
try {
|
||||
// 设置加载中
|
||||
loading.value = true
|
||||
currData.value = await api.get(`subscribe/history/${props.type}`, {
|
||||
const currentData: Subscribe[] = await api.get(`subscribe/history/${props.type}`, {
|
||||
params: {
|
||||
page: currentPage.value,
|
||||
count: pageSize.value,
|
||||
@@ -65,12 +63,12 @@ async function loadHistory({ done }: { done: any }) {
|
||||
})
|
||||
// 标计为已请求完成
|
||||
isRefreshed.value = true
|
||||
if (currData.value.length === 0) {
|
||||
if (currentData.length === 0) {
|
||||
// 如果没有数据,跳出
|
||||
done('empty')
|
||||
} else {
|
||||
// 合并数据
|
||||
historyList.value = [...historyList.value, ...currData.value]
|
||||
historyList.value.push(...currentData)
|
||||
// 页码+1
|
||||
currentPage.value++
|
||||
// 返回加载成功
|
||||
|
||||
Reference in New Issue
Block a user