diff --git a/src/App.vue b/src/App.vue index d38fc96e219808cd79283a0145396070b698237c..830a0fc9c9c16bebe260b41193c1245849b1ae1c 100644 --- a/src/App.vue +++ b/src/App.vue @@ -11,21 +11,36 @@ import '@/styles/app.scss'; import router from './router'; const locale = computed(() => appStore.locale); - +// 新增路由状态标记 +const isManualNavigation = ref(false); onMounted(() => { + // 监听手动导航 + router.beforeEach((to, from, next) => { + if (from.name === undefined && to.name !== 'root') { + isManualNavigation.value = true; + } + next(); + }); window.addEventListener('beforeunload', () => { - sessionStorage.setItem('beforeunload', '1'); + if (!isManualNavigation.value) { + sessionStorage.setItem('routerName', router.currentRoute.value.name?.toString() || ''); + } + sessionStorage.setItem('beforeunload', 'true'); }); // 监听页面刷新 const beforeUnload = sessionStorage.getItem('beforeunload'); - if (beforeUnload === '1') { + if (beforeUnload === 'true') { + if (!isManualNavigation.value) { const name = sessionStorage.getItem('routerName'); if (name) { router.push(name); // 如果sessionStorage存在路由,去缓存的路由 } else { router.push('/'); // 不存在存储,去主页 } + } sessionStorage.removeItem('beforeunload'); // 清除标记 + sessionStorage.removeItem('routerName'); + isManualNavigation.value = false; } }); diff --git a/src/components/CustomLoading/index.vue b/src/components/CustomLoading/index.vue index 55aba1903b91a3e96bb6ec481483321566225312..1f50b219fc27ac4d7d5a2f86123539352a9ca6a8 100644 --- a/src/components/CustomLoading/index.vue +++ b/src/components/CustomLoading/index.vue @@ -6,7 +6,18 @@ :element-loading-text="loadingText || `${$t('pageTipText.Loading')}...`" element-loading-background="rgba(122, 122, 122, 0.5)"> +