diff --git a/src/contentScripts/views/WatchLater/WatchLater.vue b/src/contentScripts/views/WatchLater/WatchLater.vue index d69967bb..40e2bfb2 100644 --- a/src/contentScripts/views/WatchLater/WatchLater.vue +++ b/src/contentScripts/views/WatchLater/WatchLater.vue @@ -15,37 +15,69 @@ const { t } = useI18n() const api = useApiClient() const isLoading = ref() const noMoreContent = ref() -const watchLaterList = reactive([]) -const { handlePageRefresh } = useBewlyApp() +const allWatchLaterList = ref([]) +const currentWatchLaterList = ref([]) +const { handlePageRefresh, handleReachBottom } = useBewlyApp() +const pageNum = ref(1) onMounted(() => { - getAllWatchLaterList() initPageAction() + initData() }) +async function initData() { + isLoading.value = false + noMoreContent.value = false + allWatchLaterList.value.length = 0 + currentWatchLaterList.value.length = 0 + pageNum.value = 1 + await getAllWatchLaterList() + getData() +} + +function getData() { + getCurrentWatchLaterList() +} + function initPageAction() { - handlePageRefresh.value = () => { + handlePageRefresh.value = async () => { if (isLoading.value) return - watchLaterList.length = 0 - getAllWatchLaterList() + initData() + } + + handleReachBottom.value = async () => { + getData() } } /** * Get watch later list */ -function getAllWatchLaterList() { +async function getAllWatchLaterList() { isLoading.value = true - watchLaterList.length = 0 - api.watchlater.getAllWatchLaterList() - .then((res: WatchLaterResult) => { - if (res.code === 0) - Object.assign(watchLaterList, res.data.list) + currentWatchLaterList.value.length = 0 + try { + const res: WatchLaterResult = await api.watchlater.getAllWatchLaterList() + if (res.code === 0) + allWatchLaterList.value = res.data.list + } + finally { + isLoading.value = false + } +} - isLoading.value = false - }) +function getCurrentWatchLaterList() { + const allWatchLaterListCopy = JSON.parse(JSON.stringify(allWatchLaterList.value)) + const currentList = allWatchLaterListCopy.slice((pageNum.value - 1) * 10, pageNum.value * 10) + + if (currentList.length === 0) { + noMoreContent.value = true + return + } + pageNum.value++ + currentWatchLaterList.value.push(...currentList) } function deleteWatchLaterItem(index: number, aid: number) { @@ -55,7 +87,7 @@ function deleteWatchLaterItem(index: number, aid: number) { }) .then((res) => { if (res.code === 0) - watchLaterList.splice(index, 1) + currentWatchLaterList.value.splice(index, 1) }) } @@ -105,18 +137,18 @@ function jumpToLoginPage() {

- {{ t('watch_later.title') }} ({{ watchLaterList.length }}) + {{ t('watch_later.title') }} ({{ allWatchLaterList.length }})

- +