diff --git a/src/contentScripts/views/Home/Home.vue b/src/contentScripts/views/Home/Home.vue index 30389e0a..6920395d 100644 --- a/src/contentScripts/views/Home/Home.vue +++ b/src/contentScripts/views/Home/Home.vue @@ -23,6 +23,7 @@ const showSearchPageMode = ref(false) const shouldMoveTabsUp = ref(false) const tabContentLoading = ref(false) const currentTabs = ref([]) +const tabPageRef = ref() const gridLayoutIcons = computed((): GridLayoutIcon[] => { return [ @@ -98,6 +99,15 @@ onUnmounted(() => { }) function handleChangeTab(tab: HomeTab) { + if (activatedPage.value === tab.page) { + handleBackToTop(settings.value.useSearchPageModeOnHomePage ? 510 : 0) + + if (tabContentLoading.value) + return + tabPageRef.value && tabPageRef.value.initData() + return + } + // When the content of a tab is loading, prevent switching to another tab. // Since `initPageAction()` within the tab replaces the `handleReachBottom` and `handlePageRefresh` functions. // Therefore, this will lead to a failure in refreshing the data of the current tab @@ -228,6 +238,7 @@ function toggleTabContentLoading(loading: boolean) { (false) const { handleReachBottom, handlePageRefresh } = useBewlyApp() onMounted(async () => { - for (let i = 0; i < 3; i++) - await getFollowedUsersVideos() + initData() initPageAction() }) @@ -46,23 +45,30 @@ function initPageAction() { if (noMoreContent.value) return - for (let i = 0; i < 3; i++) - await getFollowedUsersVideos() + getData() } handlePageRefresh.value = async () => { if (isLoading.value) return - offset.value = '' - updateBaseline.value = '' - videoList.length = 0 - noMoreContent.value = false - - for (let i = 0; i < 3; i++) - await getFollowedUsersVideos() + initData() } } +async function initData() { + offset.value = '' + updateBaseline.value = '' + videoList.length = 0 + noMoreContent.value = false + + await getData() +} + +async function getData() { + for (let i = 0; i < 3; i++) + await getFollowedUsersVideos() +} + async function getFollowedUsersVideos() { if (noMoreContent.value) return @@ -120,6 +126,8 @@ async function getFollowedUsersVideos() { function jumpToLoginPage() { location.href = 'https://passport.bilibili.com/login' } + +defineExpose({ initData })