From 8523de3e77f8b71cce8f90ed3f1b7d2885d9806b Mon Sep 17 00:00:00 2001 From: wujingjing <gersonwu@qq.com> Date: 星期三, 06 十一月 2024 10:26:14 +0800 Subject: [PATCH] Merge branch 'test' of http://47.103.154.90:83/r/WI/Web.V1.0 into test --- src/hooks/usePageDisplay.ts | 41 +++++++++++++++++++++++++++-------------- 1 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/hooks/usePageDisplay.ts b/src/hooks/usePageDisplay.ts index e9cb5f1..78d866d 100644 --- a/src/hooks/usePageDisplay.ts +++ b/src/hooks/usePageDisplay.ts @@ -1,23 +1,36 @@ -import { onActivated, onDeactivated, ref } from 'vue'; +import { onActivated, onBeforeUnmount, onDeactivated, onMounted, onUnmounted, ref } from 'vue'; +import router from '../router'; /** * 寮�鍚矾鐢辩紦瀛橀〉闈紝绂诲紑鏃讹紝鍜岃繘鍏ユ椂鍙栨秷/寮�鍚闃呬簨浠� * @returns */ -export const usePageDisplay = (pageShow?: () => void, pageHide?: () => void) => { - const haveExecutedMounted = ref(false); - onActivated(() => { - if (!haveExecutedMounted.value) { - return; - } - pageShow?.(); - }); +export const usePageDisplay = (pageShow?: () => void, pageHide?: () => void, needExecutedMounted = true) => { + const haveExecutedMounted = ref(!needExecutedMounted); + const currentRoute = router.currentRoute.value; - onDeactivated(() => { - pageHide?.(); - }); + const isKeepAlive = currentRoute.meta.isKeepAlive ?? false; + if (isKeepAlive) { + onActivated(() => { + if (!haveExecutedMounted.value) { + return; + } + pageShow?.(); + }); + + onDeactivated(() => { + pageHide?.(); + }); + } else { + onMounted(() => { + pageShow?.(); + }); + onBeforeUnmount(() => { + pageHide?.(); + }); + } return { - haveExecutedMounted - }; + haveExecutedMounted, + }; }; -- Gitblit v1.9.3