Skip to content

Commit cfaa55a

Browse files
committed
feat: 添加个性推荐状态保留功能,支持在页面切换时保存和恢复浏览状态 #194
1 parent 34e8d52 commit cfaa55a

12 files changed

Lines changed: 216 additions & 81 deletions

File tree

src/_locales/cmn-CN.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,9 @@ settings:
288288
username_or_mid: 用户名 / MID
289289
filter_like_view_ratio: 按点赞播放比例筛选(仅在Web推荐模式下有效)
290290
filter_like_view_ratio_desc: 筛选视频的点赞数与播放数比例(默认为5%,最高为10%)
291-
following_tab_show_livestreaming_videos: 在 “正在关注” 中显示直播视频
291+
following_tab_show_livestreaming_videos: 在 "正在关注" 中显示直播视频
292+
preserve_for_you_state: 留存个性推荐切换前状态
293+
preserve_for_you_state_desc: 当从dock栏切换到其他页面时,留存个性推荐页面的浏览状态,返回时保持切换前的内容
292294
use_search_page_mode: 首页使用搜索页模式
293295
settings_shared_with_the_search_page: 与搜索页共用的配置
294296
settings_shared_with_the_search_page_desc: 这些设置都与搜索页共用。

src/_locales/cmn-TW.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ settings:
272272
filter_by_user_table:
273273
username_or_mid: 使用者名稱 / MID
274274
following_tab_show_livestreaming_videos: 在「正在跟隨」中顯示實況直播
275+
preserve_for_you_state: 留存為你推薦切換前狀態
276+
preserve_for_you_state_desc: 當從dock欄切換到其他頁面時,留存為你推薦頁面的瀏覽狀態,返回時保持切換前的內容
275277
use_search_page_mode: 首頁使用搜尋頁模式
276278
settings_shared_with_the_search_page: 與搜尋頁共用的設定
277279
settings_shared_with_the_search_page_desc: 這些設定都與搜尋頁共用。

src/_locales/en.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,8 @@ settings:
310310
filter_by_user_table:
311311
username_or_mid: Username / MID
312312
following_tab_show_livestreaming_videos: Show Live-streaming videos in the "Following" tab
313+
preserve_for_you_state: Preserve "For You" pre-switch state
314+
preserve_for_you_state_desc: When switching from dock to other pages, preserve the browsing state of the "For You" page and maintain content before switching when returning
313315
use_search_page_mode: Use search page mode on homepage
314316
settings_shared_with_the_search_page: Settings shared with the search page
315317
settings_shared_with_the_search_page_desc: Those settings are used in common with the search page.

src/_locales/jyut.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ settings:
255255
filter_by_user_table:
256256
username_or_mid: 用戶名 / MID
257257
following_tab_show_livestreaming_videos: 喺「跟緊啲人」入邊顯示實況直播
258+
preserve_for_you_state: 留存估你心水切換前狀態
259+
preserve_for_you_state_desc: 喺dock欄切換到其它頁面嗰陣,留存估你心水頁面嘅瀏覽狀態,返嚟嗰陣保持切換前嘅內容
258260
use_search_page_mode: 主頁使用搵嘢頁模式
259261
settings_shared_with_the_search_page: 同搵嘢頁共用嘅設定
260262
settings_shared_with_the_search_page_desc: 呢啲設定同搵嘢頁嗰度共用。

src/components/Dock/Dock.vue

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Icon } from '@iconify/vue'
33
import { useElementSize, useWindowSize } from '@vueuse/core'
44
import { computed, ref } from 'vue'
55
6-
import { useBewlyApp } from '~/composables/useAppProvider'
6+
import { UndoForwardState, useBewlyApp } from '~/composables/useAppProvider'
77
import { useDark } from '~/composables/useDark'
88
import { useDelayedHover } from '~/composables/useDelayedHover'
99
import { HomeSubPage } from '~/contentScripts/views/Home/types'
@@ -32,9 +32,12 @@ const emit = defineEmits<{
3232
3333
const mainStore = useMainStore()
3434
const { isDark, toggleDark } = useDark()
35-
const { reachTop, showUndoButton, homeActivatedPage } = useBewlyApp()
36-
// 添加前进按钮状态
37-
const showForwardButton = ref<boolean>(false)
35+
const { reachTop, homeActivatedPage, undoForwardState } = useBewlyApp()
36+
37+
// 计算属性:是否显示撤销按钮
38+
const showUndo = computed(() => undoForwardState.value === UndoForwardState.ShowUndo)
39+
// 计算属性:是否显示前进按钮
40+
const showForward = computed(() => undoForwardState.value === UndoForwardState.ShowForward)
3841
3942
const hideDock = ref<boolean>(false)
4043
const dockContentHover = ref<boolean>(false)
@@ -188,23 +191,21 @@ function handleBackToTopOrRefresh(action: 'backToTop' | 'refresh' | 'auto' = 'au
188191
// 处理撤销刷新
189192
function handleUndoRefresh() {
190193
emit('undoRefresh')
191-
showForwardButton.value = true
192-
showUndoButton.value = false
194+
undoForwardState.value = UndoForwardState.ShowForward
193195
}
194196
195197
// 添加处理前进的方法
196198
function handleForwardRefresh() {
197199
emit('forwardRefresh')
198-
showUndoButton.value = true
199-
showForwardButton.value = false
200+
undoForwardState.value = UndoForwardState.ShowUndo
200201
}
201202
202203
// 添加统一的前进后退处理方法
203204
function handleHistoryNavigation() {
204-
if (showUndoButton.value) {
205+
if (showUndo.value) {
205206
handleUndoRefresh()
206207
}
207-
else if (showForwardButton.value) {
208+
else if (showForward.value) {
208209
handleForwardRefresh()
209210
}
210211
}
@@ -558,20 +559,20 @@ onUnmounted(() => {
558559
<!-- 将原来的两个按钮替换为一个 -->
559560
<Transition name="fade">
560561
<button
561-
v-if="shouldShowUndoForwardButtons && (showUndoButton || showForwardButton) && settings.enableUndoRefreshButton"
562+
v-if="shouldShowUndoForwardButtons && (showUndo || showForward) && settings.enableUndoRefreshButton"
562563
class="back-to-top-or-refresh-btn"
563564
:class="{
564565
inactive: hoveringDockItem.themeMode && isDark,
565566
}"
566567
@click="handleHistoryNavigation"
567568
>
568569
<Icon
569-
v-if="showUndoButton"
570+
v-if="showUndo"
570571
icon="mdi:undo-variant"
571572
shrink-0 absolute text-2xl
572573
/>
573574
<Icon
574-
v-else-if="showForwardButton"
575+
v-else-if="showForward"
575576
icon="mdi:redo-variant"
576577
shrink-0 absolute text-2xl
577578
/>

src/components/Settings/DesktopAndDock/Navigation/Navigation.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ function handleToggleDockItem(dockItem: any) {
168168
<SettingsItem :title="$t('settings.enable_undo_refresh_button')" :desc="$t('settings.enable_undo_refresh_button_desc')">
169169
<Radio v-model="settings.enableUndoRefreshButton" />
170170
</SettingsItem>
171+
<SettingsItem :title="$t('settings.preserve_for_you_state')" :desc="$t('settings.preserve_for_you_state_desc')">
172+
<Radio v-model="settings.preserveForYouState" />
173+
</SettingsItem>
171174
</SettingsItemGroup>
172175

173176
<SettingsItemGroup :title="$t('settings.group_sidebar')" :desc="$t('settings.group_sidebar_desc')">

src/composables/useAppProvider.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ import { inject } from 'vue'
44
import type { HomeSubPage } from '~/contentScripts/views/Home/types'
55
import type { AppPage } from '~/enums/appEnums'
66

7+
// 定义撤销/前进按钮的状态枚举
8+
export enum UndoForwardState {
9+
Hidden = 'hidden', // 隐藏状态
10+
ShowUndo = 'showUndo', // 显示撤销按钮
11+
ShowForward = 'showForward', // 显示前进按钮
12+
}
13+
714
export interface BewlyAppProvider {
815
activatedPage: Ref<AppPage>
916
// 添加Home页面的子页面状态
@@ -16,8 +23,8 @@ export interface BewlyAppProvider {
1623
// 添加撤销刷新的处理函数
1724
handleUndoRefresh: Ref<(() => void) | undefined>
1825
handleForwardRefresh: Ref<(() => void) | undefined>
19-
// 添加控制撤销按钮显示的状态
20-
showUndoButton: Ref<boolean>
26+
// 使用枚举状态统一管理撤销/前进按钮
27+
undoForwardState: Ref<UndoForwardState>
2128
handleBackToTop: (targetScrollTop?: number) => void
2229
haveScrollbar: () => Promise<boolean>
2330
openIframeDrawer: (url: string) => void

src/contentScripts/views/App.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<script setup lang="ts">
22
import { onKeyStroke, useEventListener, useThrottleFn, useToggle } from '@vueuse/core'
33
import type { Ref } from 'vue'
4-
import { ref } from 'vue'
4+
import { provide, ref } from 'vue'
55
66
import type { BewlyAppProvider } from '~/composables/useAppProvider'
7+
import { UndoForwardState } from '~/composables/useAppProvider'
78
import { useDark } from '~/composables/useDark'
89
import { BEWLY_MOUNTED, DRAWER_VIDEO_ENTER_PAGE_FULL, DRAWER_VIDEO_EXIT_PAGE_FULL, IFRAME_PAGE_SWITCH_BEWLY, IFRAME_PAGE_SWITCH_BILI, OVERLAY_SCROLL_BAR_SCROLL } from '~/constants/globalEvents'
910
import { HomeSubPage } from '~/contentScripts/views/Home/types'
@@ -66,7 +67,8 @@ const handlePageRefresh = ref<() => void>()
6667
const handleReachBottom = ref<() => void>()
6768
const handleUndoRefresh = ref<() => void>()
6869
const handleForwardRefresh = ref<() => void>()
69-
const showUndoButton = ref<boolean>(false)
70+
// 使用新的枚举状态管理撤销/前进按钮
71+
const undoForwardState = ref<UndoForwardState>(UndoForwardState.Hidden)
7072
const handleThrottledPageRefresh = useThrottleFn(() => {
7173
const osInstance = scrollbarRef.value?.osInstance()
7274
if (!osInstance) {
@@ -487,7 +489,7 @@ provide<BewlyAppProvider>('BEWLY_APP', {
487489
handleReachBottom,
488490
handleUndoRefresh,
489491
handleForwardRefresh,
490-
showUndoButton,
492+
undoForwardState,
491493
openIframeDrawer,
492494
haveScrollbar,
493495
})

src/contentScripts/views/Home/Home.vue

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -269,16 +269,14 @@ function toggleTabContentLoading(loading: boolean) {
269269
</header>
270270

271271
<Transition name="page-fade">
272-
<KeepAlive include="ForYou">
273-
<Component
274-
:is="pages[activatedPage]" :key="activatedPage"
275-
ref="tabPageRef"
276-
:grid-layout="gridLayout.home"
277-
:top-bar-visibility="topBarVisibility"
278-
@before-loading="toggleTabContentLoading(true)"
279-
@after-loading="toggleTabContentLoading(false)"
280-
/>
281-
</KeepAlive>
272+
<Component
273+
:is="pages[activatedPage]" :key="activatedPage"
274+
ref="tabPageRef"
275+
:grid-layout="gridLayout.home"
276+
:top-bar-visibility="topBarVisibility"
277+
@before-loading="toggleTabContentLoading(true)"
278+
@after-loading="toggleTabContentLoading(false)"
279+
/>
282280
</Transition>
283281
</main>
284282
</div>

0 commit comments

Comments
 (0)