feat(router): 优化路由配置与注释说明

- 重构 constantRoutes 和 dynamicRoutes 中的路由结构,提升可读性
- 补充详细的路由配置项注释,便于后续维护
- 添加路由名称检查避免重复添加相同路由
- 更新数据库连接地址及 Redis 配置信息
- 完善 .gitignore 忽略文件列表,排除临时文件和日志
```
This commit is contained in:
2025-12-15 14:24:45 +08:00
parent c18c21ff4c
commit caf65e3113
6 changed files with 209 additions and 48 deletions

6
.gitignore vendored
View File

@@ -57,4 +57,8 @@
# 忽略设计书
PostgreSQL/openHis_DB设计书.xlsx
public.sql
public.sql
发版记录/2025-11-12/~$发版日志.docx
发版记录/2025-11-12/~$S-管理系统-调价管理.docx
发版记录/2025-11-12/发版日志.docx
.gitignore

View File

@@ -6,7 +6,7 @@ spring:
druid:
# 主库数据源
master:
url: jdbc:postgresql://47.116.196.11:15432/postgresql?currentSchema=hisdev&characterEncoding=UTF-8&client_encoding=UTF-8
url: jdbc:postgresql://192.168.110.252:15432/postgresql?currentSchema=hisdev&characterEncoding=UTF-8&client_encoding=UTF-8
username: postgresql
password: Jchl1528
# 从库数据源
@@ -64,9 +64,9 @@ spring:
# redis 配置
redis:
# 地址
host: 47.116.196.11
host: 192.168.110.252
# 端口默认为6379
port: 26379
port: 6379
# 数据库索引
database: 1
# 密码

View File

@@ -0,0 +1,96 @@
import Layout from '@/layout'
import router from './router'
import { ElMessage } from 'element-plus'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import { getToken } from '@/utils/auth'
import { isHttp } from '@/utils/validate'
import { isRelogin } from '@/utils/request'
import useUserStore from '@/store/modules/user'
import useSettingsStore from '@/store/modules/settings'
import usePermissionStore from '@/store/modules/permission'
NProgress.configure({ showSpinner: false });
const whiteList = ['/login', '/register'];
router.beforeEach((to, from, next) => {
NProgress.start()
if (getToken()) {
to.meta.title && useSettingsStore().setTitle(to.meta.title)
/* has token*/
if (to.path === '/login') {
next({ path: '/' })
NProgress.done()
} else if (whiteList.indexOf(to.path) !== -1) {
next()
} else {
if (useUserStore().roles.length === 0) {
isRelogin.show = true
// 判断当前用户是否已拉取完user_info信息
useUserStore().getInfo().then(() => {
isRelogin.show = false
usePermissionStore().generateRoutes().then(accessRoutes => {
// 根据roles权限生成可访问的路由表
accessRoutes.forEach(route => {
if (!isHttp(route.path)) {
// 检查是否已经存在同名路由
if (!router.hasRoute(route.name)) {
router.addRoute(route) // 动态添加可访问路由表
}
}
})
next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
})
}).catch(err => {
useUserStore().logOut().then(() => {
ElMessage.error(err)
next({ path: '/' })
})
})
} else {
next()
}
}
} else {
// 没有token
if (whiteList.indexOf(to.path) !== -1) {
// 在免登录白名单,直接进入
next()
} else {
next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
NProgress.done()
}
}
})
router.afterEach(() => {
NProgress.done()
})
const appointmentRouter = {
path: '/appointment',
component: Layout,
redirect: '/appointment/manage',
name: 'Appointment',
meta: {
title: '预约管理',
icon: 'calendar'
},
children: [
{
path: 'manage',
component: () => import('@/views/appointment/manage'),
name: 'AppointmentManage', // 修改名称,避免与父级重复
meta: { title: '预约管理', icon: 'list' }
},
{
path: 'setting',
component: () => import('@/views/appointment/setting'),
name: 'AppointmentSetting',
meta: { title: '预约设置', icon: 'setting' }
}
]
}
export default appointmentRouter

View File

@@ -33,7 +33,10 @@ router.beforeEach((to, from, next) => {
// 根据roles权限生成可访问的路由表
accessRoutes.forEach(route => {
if (!isHttp(route.path)) {
router.addRoute(route) // 动态添加可访问路由
// 检查是否已经存在同名路由
if (!router.hasRoute(route.name)) {
router.addRoute(route) // 动态添加可访问路由表
}
}
})
next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
@@ -62,4 +65,4 @@ router.beforeEach((to, from, next) => {
router.afterEach(() => {
NProgress.done()
})
})

View File

@@ -3,32 +3,69 @@ import { createWebHistory, createRouter } from 'vue-router'
import Layout from '@/layout'
/**
* Note: 路由配置项
* Note: 路由配置项说明
*
* hidden: true // 当设置 true 的时候该路由不会侧边栏出现 如401login等页面者如一些编辑页面/edit/1
* alwaysShow: true // 当你一个路由下的 children 声明的路由大于1个时自动会变成嵌套模式--如组件页面
* // 只有一个时,会将那个子路由当做根路由显示在侧边栏--如引导页面
* // 若想不管路由下面的 children 声明的个数都显示你的根路由
* // 你可以设置 alwaysShow: true这样它就会忽略之前定义的规则一直显示根路由
* redirect: noRedirect // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
* name:'router-name' // 设定路由的名字,一定要填写不然使用<keep-alive>时会出现各种问题
* hidden: true // 当设置 true 时,该路由不会侧边栏出现如401login等页面或一些编辑页面/edit/1
* alwaysShow: true // 当路由下的 children 声明的路由大于1个时自动变为嵌套模式如组件页面
* // 只有一个时,会将子路由作为根路由显示在侧边栏如引导页面
* // 若想不管 children 个数都显示根路由,可设置 alwaysShow: true忽略之前定义的规则
* redirect: noRedirect // 当设置 noRedirect 时,该路由在面包屑导航中不可点击
* name:'router-name' // 设定路由的名字,必须填写,否则使用<keep-alive>时会出现问题
* query: '{"id": 1, "name": "ry"}' // 访问路由的默认传递参数
* roles: ['admin', 'common'] // 访问路由的角色权限
* permissions: ['a:a:a', 'b:b:b'] // 访问路由的菜单权限
* meta : {
noCache: true // 如果设置为true则不会被 <keep-alive> 缓存(默认 false)
title: 'title' // 设置该路由在侧边栏和面包屑中展示的名字
icon: 'svg-name' // 设置该路由的图标对应路径src/assets/icons/svg
breadcrumb: false // 如果设置为false则不会在breadcrumb面包屑中显示
activeMenu: '/system/user' // 当路由设置了该属性,则会高亮对应的侧边栏
* meta: {
noCache: true // 如果设置为true则不会被 <keep-alive> 缓存默认 false
title: 'title' // 设置该路由在侧边栏和面包屑中展示的名字
icon: 'svg-name' // 设置该路由的图标对应路径src/assets/icons/svg
breadcrumb: false // 如果设置为false则不会在breadcrumb面包屑中显示
activeMenu: '/system/user' // 当路由设置了该属性,则会高亮对应的侧边栏
}
*/
// 公共路由
// 公共路由 - 所有用户均可访问的路由
export const constantRoutes = [
{ path: '/appoinmentmanage', component: Layout, redirect: '/appoinmentmanage', name: 'AppoinmentManage', hidden: true, meta: { title: '预约管理', icon: 'component' }, children: [{ path: '', component: () => import('@/views/appoinmentmanage/index.vue'), name: 'AppoinmentManageIndex', meta: { title: '预约管理' } }, { path: 'doctorschedule/:deptId', component: () => import('@/views/appoinmentmanage/doctorschedule/index.vue'), name: 'DoctorSchedule', hidden: true, meta: { title: '医生排班' } }] },
// 门诊医生站路由配置
{ path: '/doctorstation', component: Layout, redirect: '/doctorstation', name: 'DoctorStation', meta: { title: '门诊医生站', icon: 'doctorstation' }, children: [{ path: '', component: () => import('@/views/doctorstation/index.vue'), name: 'DoctorStationIndex', meta: { title: '门诊医生站', icon: 'doctorstation' } }] },
// 预约管理路由
{
path: '/appoinmentmanage',
component: Layout,
redirect: '/appoinmentmanage',
name: 'AppoinmentManageRoot',
hidden: true,
meta: { title: '预约管理', icon: 'component' },
children: [
{
path: '',
component: () => import('@/views/appoinmentmanage/index.vue'),
name: 'AppoinmentManage',
meta: { title: '预约管理' }
},
{
path: 'doctorschedule/:deptId',
component: () => import('@/views/appoinmentmanage/doctorschedule/index.vue'),
name: 'DoctorSchedule',
hidden: true,
meta: { title: '医生排班' }
}
]
},
// 门诊医生站路由
{
path: '/doctorstation',
component: Layout,
redirect: '/doctorstation',
name: 'DoctorStation',
meta: { title: '门诊医生站', icon: 'doctorstation' },
children: [
{
path: '',
component: () => import('@/views/doctorstation/index.vue'),
name: 'DoctorStationIndex',
meta: { title: '门诊医生站', icon: 'doctorstation' }
}
]
},
// 重定向路由
{
path: '/redirect',
component: Layout,
@@ -40,21 +77,25 @@ export const constantRoutes = [
}
]
},
// 登录路由
{
path: '/login',
component: () => import('@/views/login'),
hidden: true
},
// 注册路由
{
path: '/register',
component: () => import('@/views/register'),
hidden: true
},
// 401权限不足路由
{
path: '/401',
component: () => import('@/views/error/401'),
hidden: true
},
// 首页路由
{
path: '',
component: Layout,
@@ -68,6 +109,7 @@ export const constantRoutes = [
}
]
},
// 个人中心路由
{
path: '/user',
component: Layout,
@@ -82,7 +124,7 @@ export const constantRoutes = [
}
]
},
// 添加套餐管理相关路由到公共路由确保始终可用
// 套餐管理相关路由 - 添加到公共路由确保始终可用
{
path: '/maintainSystem/Inspection/PackageManagement',
component: Layout,
@@ -98,8 +140,9 @@ export const constantRoutes = [
}
]
// 动态路由基于用户权限动态加载
// 动态路由 - 基于用户权限动态加载的路由
export const dynamicRoutes = [
// 基础管理路由
{
path: '/basicmanage',
component: Layout,
@@ -115,7 +158,7 @@ export const dynamicRoutes = [
}
]
},
// 兼容系统业务管理路径
// 兼容系统业务管理路径的发票管理路由
{
path: '/system/ywgz',
component: Layout,
@@ -130,6 +173,7 @@ export const dynamicRoutes = [
}
]
},
// 维护系统路由
{
path: '/maintainSystem',
component: Layout,
@@ -139,22 +183,23 @@ export const dynamicRoutes = [
children: [
{
path: '',
redirect: 'chargeConfig'
redirect: 'chargeConfig',
name: 'MaintainSystemIndex' // 添加名称以解决警告
},
{
path: 'chargeConfig',
path: 'chargeConfig', // 收费配置路由
component: () => import('@/views/maintainSystem/chargeConfig/index.vue'),
name: 'ChargeConfig',
meta: { title: '挂号收费系统参数维护', icon: 'config', permissions: ['maintainSystem:chargeConfig:list'] }
},
{
path: 'Inspection',
path: 'Inspection', // 检验管理路由
component: () => import('@/views/maintainSystem/Inspection/index.vue'),
name: 'Inspection',
meta: { title: '检验管理', icon: 'inspection' },
children: [
{
path: 'PackageManagement',
path: 'PackageManagement', // 套餐管理路由
component: () => import('@/views/maintainSystem/Inspection/PackageManagement.vue'),
name: 'PackageManagement',
meta: { title: '套餐管理' }
@@ -163,6 +208,7 @@ export const dynamicRoutes = [
}
]
},
// 系统管理路由
{
path: '/system',
component: Layout,
@@ -171,61 +217,62 @@ export const dynamicRoutes = [
meta: { title: '系统管理', icon: 'system' },
children: [
{
path: 'user',
path: 'user', // 用户管理路由
component: () => import('@/views/system/user/index.vue'),
name: 'User',
meta: { title: '用户管理', icon: 'user', permissions: ['system:user:list'] }
},
{
path: 'role',
path: 'role', // 角色管理路由
component: () => import('@/views/system/role/index.vue'),
name: 'Role',
meta: { title: '角色管理', icon: 'role', permissions: ['system:role:list'] }
},
{
path: 'menu',
path: 'menu', // 菜单管理路由
component: () => import('@/views/system/menu/index.vue'),
name: 'Menu',
meta: { title: '菜单管理', icon: 'menu', permissions: ['system:menu:list'] }
},
{
path: 'dept',
path: 'dept', // 部门管理路由
component: () => import('@/views/system/dept/index.vue'),
name: 'Dept',
meta: { title: '部门管理', icon: 'dept', permissions: ['system:dept:list'] }
},
{
path: 'post',
path: 'post', // 岗位管理路由
component: () => import('@/views/system/post/index.vue'),
name: 'Post',
meta: { title: '岗位管理', icon: 'post', permissions: ['system:post:list'] }
},
{
path: 'dict',
path: 'dict', // 字典管理路由
component: () => import('@/views/system/dict/index.vue'),
name: 'Dict',
meta: { title: '字典管理', icon: 'dict', permissions: ['system:dict:list'] }
},
{
path: 'config',
path: 'config', // 参数配置路由
component: () => import('@/views/system/config/index.vue'),
name: 'Config',
meta: { title: '参数配置', icon: 'config', permissions: ['system:config:list'] }
},
{
path: 'notice',
path: 'notice', // 通知公告路由
component: () => import('@/views/system/notice/index.vue'),
name: 'Notice',
meta: { title: '通知公告', icon: 'notice', permissions: ['system:notice:list'] }
},
{
path: 'tenant',
path: 'tenant', // 租户管理路由
component: () => import('@/views/system/tenant/index.vue'),
name: 'Tenant',
meta: { title: '租户管理', icon: 'tenant', permissions: ['system:tenant:list'] }
}
]
},
// 租户用户设置路由
{
path: '/system/tenant-user',
component: Layout,
@@ -240,6 +287,7 @@ export const dynamicRoutes = [
}
]
},
// 租户合同管理路由
{
path: '/system/tenant-contract',
component: Layout,
@@ -254,6 +302,7 @@ export const dynamicRoutes = [
}
]
},
// 用户角色分配路由
{
path: '/system/user-auth',
component: Layout,
@@ -268,6 +317,7 @@ export const dynamicRoutes = [
}
]
},
// 角色用户分配路由
{
path: '/system/role-auth',
component: Layout,
@@ -282,6 +332,7 @@ export const dynamicRoutes = [
}
]
},
// 字典数据路由
{
path: '/system/dict-data',
component: Layout,
@@ -296,6 +347,7 @@ export const dynamicRoutes = [
}
]
},
// 系统监控路由
{
path: '/monitor',
component: Layout,
@@ -304,25 +356,26 @@ export const dynamicRoutes = [
meta: { title: '系统监控', icon: 'monitor' },
children: [
{
path: 'operlog',
path: 'operlog', // 操作日志路由
component: () => import('@/views/monitor/operlog/index.vue'),
name: 'Operlog',
meta: { title: '操作日志', icon: 'operlog', permissions: ['monitor:operlog:list'] }
},
{
path: 'logininfor',
path: 'logininfor', // 登录日志路由
component: () => import('@/views/monitor/logininfor/index.vue'),
name: 'Logininfor',
meta: { title: '登录日志', icon: 'logininfor', permissions: ['monitor:logininfor:list'] }
},
{
path: 'job',
path: 'job', // 定时任务路由
component: () => import('@/views/monitor/job/index.vue'),
name: 'Job',
meta: { title: '定时任务', icon: 'job', permissions: ['monitor:job:list'] }
}
]
},
// 系统工具路由
{
path: '/tool',
component: Layout,
@@ -331,13 +384,14 @@ export const dynamicRoutes = [
meta: { title: '系统工具', icon: 'tool' },
children: [
{
path: 'gen',
path: 'gen', // 代码生成路由
component: () => import('@/views/tool/gen/index.vue'),
name: 'Gen',
meta: { title: '代码生成', icon: 'gen', permissions: ['tool:gen:list'] }
}
]
},
// 定时任务日志路由
{
path: '/monitor/job-log',
component: Layout,
@@ -352,6 +406,7 @@ export const dynamicRoutes = [
}
]
},
// 代码生成编辑路由
{
path: '/tool/gen-edit',
component: Layout,
@@ -371,17 +426,19 @@ export const dynamicRoutes = [
// 合并常量路由和动态路由,确保所有路由都能被访问
const allRoutes = [...constantRoutes, ...dynamicRoutes];
// 添加404路由到所有路由的最后
// 添加404路由到所有路由的最后,确保捕获所有未匹配的路由
allRoutes.push({
path: "/:pathMatch(.*)*",
component: () => import('@/views/error/404'),
hidden: true
});
// 创建Vue Router实例
const router = createRouter({
history: createWebHistory(),
routes: allRoutes,
history: createWebHistory(), // 使用HTML5历史模式
routes: allRoutes, // 使用合并后的所有路由
scrollBehavior(to, from, savedPosition) {
// 页面滚动行为:如果有保存的位置则恢复,否则滚动到顶部
if (savedPosition) {
return savedPosition
} else {
@@ -390,4 +447,5 @@ const router = createRouter({
},
});
export default router;
// 导出路由实例
export default router;