Compare commits
2 Commits
8080976772
...
Router
| Author | SHA1 | Date | |
|---|---|---|---|
| ccaa10f25b | |||
| 9d57758154 |
@ -10,7 +10,7 @@
|
|||||||
md="6"
|
md="6"
|
||||||
>
|
>
|
||||||
<v-card
|
<v-card
|
||||||
class="pa-6 parameter-card"
|
class="pa-6 parameters-card"
|
||||||
elevation="8"
|
elevation="8"
|
||||||
rounded="xl"
|
rounded="xl"
|
||||||
>
|
>
|
||||||
|
|||||||
@ -159,20 +159,11 @@
|
|||||||
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import { navigationConfig } from '@/config/navigation'
|
import { navigationConfig } from '@/config/navigation'
|
||||||
import { useNavigationStore } from '@/stores/navigation'
|
|
||||||
|
|
||||||
const { t, locale } = useI18n()
|
const { t, locale } = useI18n()
|
||||||
|
|
||||||
const navigationStore = useNavigationStore()
|
const drawer = ref(true)
|
||||||
|
const selectedIndex = ref(0)
|
||||||
const drawer = computed({
|
|
||||||
get: () => navigationStore.drawer,
|
|
||||||
set: (value: boolean) => {
|
|
||||||
navigationStore.setDrawerOpen(value)
|
|
||||||
},
|
|
||||||
})
|
|
||||||
const selectedIndex = computed(() => navigationStore.selectedIndex)
|
|
||||||
|
|
||||||
const windowWidth = ref(typeof window === 'undefined' ? 1200 : window.innerWidth)
|
const windowWidth = ref(typeof window === 'undefined' ? 1200 : window.innerWidth)
|
||||||
|
|
||||||
const showAboutDialog = ref(false)
|
const showAboutDialog = ref(false)
|
||||||
@ -268,7 +259,8 @@
|
|||||||
locale.value = locale.value === 'zh' ? 'en' : 'zh'
|
locale.value = locale.value === 'zh' ? 'en' : 'zh'
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleSelect (_index: number) {
|
function handleSelect (index: number) {
|
||||||
|
selectedIndex.value = index
|
||||||
drawer.value = false // 选择后自动关闭抽屉
|
drawer.value = false // 选择后自动关闭抽屉
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -69,6 +69,5 @@
|
|||||||
"appDescription": "Paper tube production auxiliary production tool provides calculation of various parameters such as weight, size, angle, etc.",
|
"appDescription": "Paper tube production auxiliary production tool provides calculation of various parameters such as weight, size, angle, etc.",
|
||||||
"allRightsReserved": "All Rights Reserved",
|
"allRightsReserved": "All Rights Reserved",
|
||||||
"close": "Close",
|
"close": "Close",
|
||||||
"officialWebsite": "Official website",
|
"officialWebsite": "Official website"
|
||||||
"loading": "Loading"
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -69,6 +69,5 @@
|
|||||||
"appDescription": "纸管制作辅助生产工具,提供纸管重量、尺寸、角度等多种参数的计算。",
|
"appDescription": "纸管制作辅助生产工具,提供纸管重量、尺寸、角度等多种参数的计算。",
|
||||||
"allRightsReserved": "版权所有",
|
"allRightsReserved": "版权所有",
|
||||||
"close": "关闭",
|
"close": "关闭",
|
||||||
"officialWebsite": "官方网站",
|
"officialWebsite": "官方网站"
|
||||||
"loading": "加载中"
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,48 +1,15 @@
|
|||||||
<template>
|
<template>
|
||||||
<v-container class="d-flex justify-center align-center" style="min-height: 50vh;">
|
<div>Redirecting...</div>
|
||||||
<div class="text-center">
|
|
||||||
<v-progress-circular
|
|
||||||
color="primary"
|
|
||||||
indeterminate
|
|
||||||
size="64"
|
|
||||||
width="6"
|
|
||||||
/>
|
|
||||||
<div class="text-h6 mt-4 text-primary">
|
|
||||||
{{ $t('loading') }}...
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</v-container>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { onMounted } from 'vue'
|
import { onMounted } from 'vue'
|
||||||
import { useRoute, useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const route = useRoute()
|
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(() => {
|
||||||
// 等待路由完全准备好
|
// Redirect to the calculators page
|
||||||
await router.isReady()
|
router.push('/calculators/paper-tube-weight')
|
||||||
|
|
||||||
// 检查是否是直接访问首页
|
|
||||||
const isDirectAccess = route.path === '/' && !document.referrer.includes(window.location.origin)
|
|
||||||
|
|
||||||
let targetPath = '/calculators/paper-tube-weight' // 默认路径
|
|
||||||
|
|
||||||
if (!isDirectAccess) {
|
|
||||||
// 如果不是直接访问,尝试恢复上次的路径
|
|
||||||
const lastRoute = sessionStorage.getItem('lastRoute')
|
|
||||||
const savedPath = localStorage.getItem('lastPath')
|
|
||||||
targetPath = lastRoute || savedPath || targetPath
|
|
||||||
}
|
|
||||||
|
|
||||||
// 使用 replace 避免在历史记录中留下首页
|
|
||||||
router.replace(targetPath)
|
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<route lang="yaml">
|
|
||||||
meta:
|
|
||||||
layout: CalculatorLayout
|
|
||||||
</route>
|
|
||||||
|
|||||||
@ -33,28 +33,4 @@ router.isReady().then(() => {
|
|||||||
localStorage.removeItem('vuetify:dynamic-reload')
|
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
|
export default router
|
||||||
|
|||||||
@ -1,31 +0,0 @@
|
|||||||
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,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
Reference in New Issue
Block a user