diff --git a/src/layouts/CalculatorLayout.vue b/src/layouts/CalculatorLayout.vue index a45e502..802d1ba 100644 --- a/src/layouts/CalculatorLayout.vue +++ b/src/layouts/CalculatorLayout.vue @@ -159,11 +159,22 @@ import { computed, onMounted, onUnmounted, ref } from 'vue' import { useI18n } from 'vue-i18n' import { navigationConfig } from '@/config/navigation' + import { useNavigationStore } from '@/stores/navigation' + import { useRoute } from 'vue-router' const { t, locale } = useI18n() + const route = useRoute() + + const navigationStore = useNavigationStore() + + const drawer = computed({ + get: () => navigationStore.drawer, + set: (value: boolean) => { + navigationStore.setDrawerOpen(value) + }, + }) + const selectedIndex = computed(() => navigationStore.selectedIndex) - const drawer = ref(true) - const selectedIndex = ref(0) const windowWidth = ref(typeof window === 'undefined' ? 1200 : window.innerWidth) const showAboutDialog = ref(false) @@ -260,7 +271,6 @@ } function handleSelect (index: number) { - selectedIndex.value = index drawer.value = false // 选择后自动关闭抽屉 } diff --git a/src/locale/en.json b/src/locale/en.json index 508c1cb..14f3658 100644 --- a/src/locale/en.json +++ b/src/locale/en.json @@ -69,5 +69,6 @@ "appDescription": "Paper tube production auxiliary production tool provides calculation of various parameters such as weight, size, angle, etc.", "allRightsReserved": "All Rights Reserved", "close": "Close", - "officialWebsite": "Official website" + "officialWebsite": "Official website", + "loading": "Loading" } diff --git a/src/locale/zh.json b/src/locale/zh.json index 1aaaf59..a9fd39f 100644 --- a/src/locale/zh.json +++ b/src/locale/zh.json @@ -69,5 +69,6 @@ "appDescription": "纸管制作辅助生产工具,提供纸管重量、尺寸、角度等多种参数的计算。", "allRightsReserved": "版权所有", "close": "关闭", - "officialWebsite": "官方网站" + "officialWebsite": "官方网站", + "loading": "加载中" } diff --git a/src/pages/index.vue b/src/pages/index.vue index 74809d8..90f74bb 100644 --- a/src/pages/index.vue +++ b/src/pages/index.vue @@ -1,15 +1,48 @@ - Redirecting... + + + + + {{ $t('loading') }}... + + + + + +meta: + layout: CalculatorLayout + diff --git a/src/router/index.ts b/src/router/index.ts index dc0f31a..74cc708 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -33,4 +33,28 @@ router.isReady().then(() => { localStorage.removeItem('vuetify:dynamic-reload') }) +router.beforeEach((to, from, next) => { + // 如果访问根路径且不是直接输入地址访问 + if (to.path === '/' && from.path !== '/') { + // 检查是否有保存的路径 + const lastRoute = sessionStorage.getItem('lastRoute') + const savedPath = localStorage.getItem('lastPath') + + if (lastRoute || savedPath) { + // 重定向到上次访问的页面 + next(lastRoute || savedPath || '/calculators/paper-tube-weight') + return + } + } + + // 保存当前路由(非首页) + if (to.path !== '/') { + sessionStorage.setItem('lastRoute', to.fullPath) + localStorage.setItem('lastPath', to.fullPath) + } + + next() + +}) + export default router diff --git a/src/stores/navigation.ts b/src/stores/navigation.ts new file mode 100644 index 0000000..62753c6 --- /dev/null +++ b/src/stores/navigation.ts @@ -0,0 +1,31 @@ +import { defineStore } from 'pinia' +import { computed, ref } from 'vue' +import { useRoute } from 'vue-router' +import { navigationConfig } from '@/config/navigation' + +export const useNavigationStore = defineStore('navigation', () => { + // Status + const route = useRoute() + const drawer = ref(false) + + // 当前选中的菜单项 + const selectedIndex = computed(() => { + return navigationConfig.findIndex(item => item.to === route.path) + }) + + // Actions + function toggleDrawer () { + drawer.value = !drawer.value + } + + function setDrawerOpen (open: boolean) { + drawer.value = open + } + + return { + selectedIndex, + drawer, + toggleDrawer, + setDrawerOpen, + } +})