This commit is contained in:
zhangzq
2026-08-11 10:47:41 +08:00
parent 57c1f4d8e9
commit 8d6458cdea
10 changed files with 307 additions and 296 deletions

View File

@@ -1,319 +1,65 @@
import router from './routers'
import store from '@/store'
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style
import { getToken } from '@/utils/auth' // getToken from cookie
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import { getToken } from '@/utils/auth'
import { filterAsyncRouter } from '@/store/modules/permission'
import { buildMenus } from '@/views/system/menu/menu'
const staticMenuData = [
{
name: '项目管理',
path: '/pms',
hidden: false,
redirect: 'noredirect',
component: 'Layout',
alwaysShow: true,
meta: {
title: '项目管理',
icon: 'system',
noCache: true
},
children: [
{
name: 'Project',
path: 'project',
hidden: false,
component: 'project/index',
meta: {
title: '项目管理',
icon: 'clipboard',
noCache: true
}
},
{
name: 'ProjectPlan',
path: 'project-plan',
hidden: false,
component: 'project/planIndex',
meta: {
title: '项目开发计划表',
icon: 'clipboard',
noCache: true
}
},
{
name: 'ProjectDelayRecord',
path: 'project-delay-records',
hidden: false,
component: 'project/delayRecordIndex',
meta: {
title: '项目延期记录管理',
icon: 'clipboard',
noCache: true
}
},
{
name: 'TemporaryWork',
path: 'temporary-work',
hidden: false,
component: 'project/temporaryWorkIndex',
meta: {
title: '我的临时工作管理',
icon: 'clipboard',
noCache: true
}
},
{
name: 'ProgressReport',
path: 'progress-report',
hidden: false,
component: 'project/progressReportIndex',
meta: {
title: '报工作业',
icon: 'clipboard',
noCache: true
}
}
]
},
{
name: '审批管理',
path: '/approval',
hidden: false,
redirect: 'noredirect',
component: 'Layout',
alwaysShow: true,
meta: {
title: '审批管理',
icon: 'system',
noCache: true
},
children: [
{
name: 'ProgressReportAudit',
path: 'progress-report-audit',
hidden: false,
component: 'project/progressReportAuditIndex',
meta: {
title: '报工审核',
icon: 'clipboard',
noCache: true
}
}
]
},
{
name: '系统管理',
path: '/system',
hidden: false,
redirect: 'noredirect',
component: 'Layout',
alwaysShow: true,
meta: {
title: '系统管理',
icon: 'system',
noCache: true
},
children: [
{
name: 'User',
path: 'user',
hidden: false,
component: 'system/user/index',
meta: {
title: '用户管理',
icon: 'peoples',
noCache: true
}
},
{
name: 'Role',
path: 'role',
hidden: false,
component: 'system/role/index',
meta: {
title: '角色管理',
icon: 'role',
noCache: true
}
},
{
name: 'Menu',
path: 'menu',
hidden: false,
component: 'system/menu/index',
meta: {
title: '菜单管理',
icon: 'menu',
noCache: true
}
},
{
name: 'Dept',
path: 'dept',
hidden: false,
component: 'system/dept/index',
meta: {
title: '部门管理',
icon: 'dept',
noCache: true
}
},
{
name: 'Dict',
path: 'dict',
hidden: false,
component: 'system/dict/index',
meta: {
title: '字典管理',
icon: 'dictionary',
noCache: true
}
},
{
name: 'Mock',
path: 'mock',
hidden: false,
component: 'system/mock/index',
meta: {
title: '接口mock',
icon: 'backup',
noCache: true
}
},
{
name: 'Param',
path: 'param',
hidden: false,
component: 'system/param/index',
meta: {
title: '系统参数',
icon: 'Steve-Jobs',
noCache: true
}
},
{
name: 'DataPermission',
path: 'dataPermission',
hidden: false,
component: 'system/dataPermission/index',
meta: {
title: '数据权限',
icon: 'Steve-Jobs',
noCache: true
}
},
{
name: 'Timing',
path: 'timing',
hidden: false,
component: 'system/timing/index',
meta: {
title: '任务调度',
icon: 'timing',
noCache: true
}
}
]
},
{
name: '系统监控',
path: '/monitor',
hidden: false,
redirect: 'noredirect',
component: 'Layout',
alwaysShow: true,
meta: {
title: '系统监控',
icon: 'monitor',
noCache: true
},
children: [
{
name: 'Redis',
path: 'redis',
hidden: false,
component: 'system/redis/index',
meta: {
title: 'Redis监控',
icon: 'radio',
noCache: true
}
},
{
name: 'SysNotice',
path: 'sysNotice',
hidden: false,
component: 'system/notice/index',
meta: {
title: '通知管理',
icon: 'develop',
noCache: true
}
}
]
}
]
const SYSTEM_TYPE = 1
NProgress.configure({ showSpinner: false })// NProgress Configuration
NProgress.configure({ showSpinner: false })
const whiteList = ['/login']// no redirect whitelist
const whiteList = ['/login']
router.beforeEach((to, from, next) => {
if (to.meta.title) {
// document.title = to.meta.title + ' - ' + Config.title
document.title = to.meta.title
}
NProgress.start()
if (getToken()) {
// 已登录且要跳转的页面是登录页
if (to.path === '/login') {
next({ path: '/' })
NProgress.done()
} else {
if (store.getters.roles.length === 0) { // 判断当前用户是否已拉取完user_info信息
store.dispatch('GetInfo').then(() => { // 拉取user_info
// 动态路由,拉取菜单
loadMenus(next, to)
}).catch(() => {
store.dispatch('LogOut').then(() => {
location.reload() // 为了重新实例化vue-router对象 避免bug
})
})
// 登录时未拉取 菜单,在此处拉取
} else if (store.getters.loadMenus) {
// 修改成false防止死循环
store.dispatch('updateLoadMenus')
loadMenus(next, to)
} else {
next()
}
}
} else {
/* has no token*/
if (whiteList.indexOf(to.path) !== -1) { // 在免登录白名单,直接进入
if (!getToken()) {
if (whiteList.includes(to.path)) {
next()
} else {
next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
next(`/login?redirect=${to.fullPath}`)
NProgress.done()
}
return
}
if (to.path === '/login') {
next({ path: '/' })
NProgress.done()
return
}
if (store.getters.roles.length === 0) {
store.dispatch('GetInfo').then(() => loadMenus(next, to)).catch(() => {
store.dispatch('LogOut').then(() => location.reload())
})
} else if (store.getters.loadMenus) {
store.dispatch('updateLoadMenus')
loadMenus(next, to)
} else {
next()
}
})
export const loadMenus = (next, to) => {
const sdata = JSON.parse(JSON.stringify(staticMenuData))
const rdata = JSON.parse(JSON.stringify(staticMenuData))
const sidebarRoutes = filterAsyncRouter(sdata)
const rewriteRoutes = filterAsyncRouter(rdata, false, true)
rewriteRoutes.push({ path: '*', redirect: '/404', hidden: true })
store.dispatch('GenerateRoutes', rewriteRoutes).then(() => {
router.addRoutes(rewriteRoutes)
next({ ...to, replace: true })
buildMenus(SYSTEM_TYPE).then(res => {
const menus = Array.isArray(res) ? res : (res.data || [])
const sidebarRoutes = filterAsyncRouter(JSON.parse(JSON.stringify(menus)))
const rewriteRoutes = filterAsyncRouter(JSON.parse(JSON.stringify(menus)), false, true)
rewriteRoutes.push({ path: '*', redirect: '/404', hidden: true })
store.dispatch('GenerateRoutes', rewriteRoutes).then(() => {
router.addRoutes(rewriteRoutes)
next({ ...to, replace: true })
})
store.dispatch('SetSidebarRouters', sidebarRoutes)
}).catch(() => {
NProgress.done()
next(false)
})
store.dispatch('SetSidebarRouters', sidebarRoutes)
}
router.afterEach(() => {
NProgress.done() // finish progress bar
NProgress.done()
})

View File

@@ -852,7 +852,7 @@ export default {
return match ? match.label : '未知'
},
reportRateLabel(rate) {
return ({ 1: '每日', 7: '每周', 30: '每月' })[rate] || '-'
return ({ 1: '每日', 7: '每周', 15: '每月' })[rate] || '-'
},
statusTagType(status) {
const typeMap = {

View File

@@ -361,7 +361,7 @@ export default {
return plan
},
reportRateLabel(rate) {
return ({ 1: '每日', 7: '每周', 30: '每月' })[rate] || '-'
return ({ 1: '每日', 7: '每周', 15: '每月' })[rate] || '-'
},
addMaster() {
this.plan.masters.push(this.createMaster())