Skip to content

Commit 28b8df7

Browse files
committed
feat: 应用配置增加 home.fullPath
框架中所有跳转到主页的操作均改成取该配置设置的路由地址
1 parent ffc402d commit 28b8df7

File tree

12 files changed

+30
-16
lines changed

12 files changed

+30
-16
lines changed

src/components/NotAllowed/index.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
<script setup lang="ts">
2+
import useSettingsStore from '@/store/modules/settings'
3+
24
defineOptions({
35
name: 'NotAllowed',
46
})
57
68
const router = useRouter()
79
10+
const settingsStore = useSettingsStore()
11+
812
const data = ref({
913
inter: Number.NaN,
1014
countdown: 5,
@@ -25,7 +29,7 @@ onMounted(() => {
2529
})
2630
2731
function goBack() {
28-
router.push('/')
32+
router.push(settingsStore.settings.home.fullPath)
2933
}
3034
</script>
3135

src/layouts/components/Logo/index.vue

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@ const settingsStore = useSettingsStore()
2222
const title = ref(import.meta.env.VITE_APP_TITLE)
2323
const logo = ref(imgLogo)
2424
25-
const to = computed(() => {
26-
return {
27-
...(settingsStore.settings.home.enable && { name: 'home' }),
28-
}
29-
})
25+
const to = computed(() => settingsStore.settings.home.enable ? settingsStore.settings.home.fullPath : '')
3026
</script>
3127

3228
<template>

src/layouts/components/Tools/index.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ watch(() => userStore.avatar, () => {
7676
<HDropdownMenu
7777
:items="[
7878
[
79-
{ label: settingsStore.settings.home.title, handle: () => router.push({ name: 'home' }), hide: !settingsStore.settings.home.enable },
79+
{ label: settingsStore.settings.home.title, handle: () => router.push({ path: settingsStore.settings.home.fullPath }), hide: !settingsStore.settings.home.enable },
80+
{ label: '个人设置', handle: () => router.push({ name: 'personalSetting' }) },
8081
],
8182
[
8283
{ label: '快捷键介绍', handle: () => eventBus.emit('global-hotkeys-intro-toggle'), hide: settingsStore.mode !== 'pc' },

src/layouts/components/Topbar/Toolbar/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const breadcrumbList = computed(() => {
2121
const breadcrumbList = []
2222
if (settingsStore.settings.home.enable) {
2323
breadcrumbList.push({
24-
path: '/',
24+
path: settingsStore.settings.home.fullPath,
2525
title: settingsStore.settings.home.title,
2626
})
2727
}

src/router/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ router.beforeEach(async (to, from, next) => {
3434
// 如果已登录状态下,进入登录页会强制跳转到主页
3535
if (to.name === 'login') {
3636
next({
37-
name: 'home',
37+
path: settingsStore.settings.home.fullPath,
3838
replace: true,
3939
})
4040
}
4141
// 如果未开启主页,但进入的是主页,则会进入侧边栏导航第一个模块
42-
else if (!settingsStore.settings.home.enable && to.name === 'home') {
42+
else if (!settingsStore.settings.home.enable && to.fullPath === settingsStore.settings.home.fullPath) {
4343
if (menuStore.sidebarMenus.length > 0) {
4444
next({
4545
path: menuStore.sidebarMenusFirstDeepestPath,
@@ -105,7 +105,7 @@ router.beforeEach(async (to, from, next) => {
105105
next({
106106
name: 'login',
107107
query: {
108-
redirect: to.fullPath !== '/' ? to.fullPath : undefined,
108+
redirect: to.fullPath !== settingsStore.settings.home.fullPath ? to.fullPath : undefined,
109109
},
110110
})
111111
}

src/router/routes.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ const systemRoutes: RouteRecordRaw[] = [
3737
children: [
3838
{
3939
path: '',
40-
name: 'home',
4140
component: () => import('@/views/index.vue'),
4241
meta: {
4342
title: () => useSettingsStore().settings.home.title,

src/settings.default.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const globalSettingsDefault: RecursiveRequired<Settings.all> = {
1414
home: {
1515
enable: true,
1616
title: '主页',
17+
fullPath: '/',
1718
},
1819
layout: {
1920
enableMobileAdaptation: false,

src/store/modules/menu.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const useMenuStore = defineStore(
6464
const sidebarMenusFirstDeepestPath = computed(() => {
6565
return sidebarMenus.value.length > 0
6666
? getDeepestPath(sidebarMenus.value[0])
67-
: '/'
67+
: settingsStore.settings.home.fullPath
6868
})
6969
function getDeepestPath(menu: Menu.recordRaw, rootPath = '') {
7070
let retnPath = ''

src/store/modules/user.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import useSettingsStore from './settings'
12
import useRouteStore from './route'
23
import useMenuStore from './menu'
34
import router from '@/router'
@@ -7,6 +8,7 @@ const useUserStore = defineStore(
78
// 唯一ID
89
'user',
910
() => {
11+
const settingsStore = useSettingsStore()
1012
const routeStore = useRouteStore()
1113
const menuStore = useMenuStore()
1214

@@ -56,7 +58,7 @@ const useUserStore = defineStore(
5658
router.push({
5759
name: 'login',
5860
query: {
59-
...(router.currentRoute.value.path !== '/' && router.currentRoute.value.name !== 'login' && { redirect }),
61+
...(router.currentRoute.value.path !== settingsStore.settings.home.fullPath && router.currentRoute.value.name !== 'login' && { redirect }),
6062
},
6163
})
6264
}

src/types/global.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ declare namespace Settings {
5555
* @默认值 `'主页'`
5656
*/
5757
title?: string
58+
/**
59+
* 主页完整路径
60+
* @默认值 `'/'`
61+
*/
62+
fullPath?: string
5863
}
5964
interface layout {
6065
/**

0 commit comments

Comments
 (0)