1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import Vue from 'vue'
import Router from 'vue-router'
import Store from './store'
import Layout from './views/Layout.vue'
import fileNotFound from './views/errors/fileNotFound.vue'
Vue.use(Router);
const router = new Router({
routes: [
builder('/authentication', 'login/authentication'),
builder('/login', 'login/login'),
builder('/go', 'codeGen/index'),
{
path: '/',
name: 'layout',
component: Layout,
meta: {
requiresAuth: true
},
children: [
...restBuilder('oper/log', 'system/log'), // 系统管理-操作日志
...restBuilder('validcode', 'system/validcode'), // 接入管理-接入信息
...restBuilder('menu', 'system/menu'), // 系统管理--菜单管理
...restBuilder('resource', 'system/resource'), // 系统管理--资源管理
...restBuilder('role', 'system/role'), // 系统管理--角色管理
...restBuilder('user', 'system/user'), // 用户管理 -- 管理用户
...restBuilder('param', 'system/param'), // 系统管理--参数管理
...restBuilder('task', 'system/task'), // 系统管理--任务管理
...restBuilder('area', 'system/area'), // 系统管理-区域管理
//工作流业务模块
...restBuilder('flowable/definition', 'flowable/definition'), // 流程定义类
builder('flowable/definition/model', 'flowable/definition/model'),//流程设计器
...restBuilder('form', 'flowable/task/form'),//表单列表
builder('tool/build/index', 'tool/build/index'),//表单设计器
builder('flowable/task/record/index', 'flowable/task/record/index'),//流程申请
...restBuilder('task/process', 'flowable/task/process'), //我的流程
...restBuilder('task/todo', 'flowable/task/todo'), //代办列表
...restBuilder('task/finish', 'flowable/task/finished'), //已办列表
...restBuilder('healthinfo/apply', 'healthinfo/apply'), //健康列表
...restBuilder('information', 'information'), //办件列表
...restBuilder('member', 'member'), // 一件事管理-微信人员
...restBuilder('yth/onething', 'onething'), // 一件事管理-微信人员提交审核材料
//在此添加业务模块
builder('/basics/index', 'basics/index'),//事项工作台
...restBuilder('basics', 'basics'), // 一件事管理-一件事
...restBuilder('basics/info', 'basics/info'), // 一件事管理-基本信息
...restBuilder('accept', 'accept'), // 一件事管理-申请条件
...restBuilder('flowlimit', 'flowlimit'), // 一件事管理-办理流程
//问题引导页面
builder('one/classify/list', 'one/classify/list'),//分类引导表
...restBuilder('datum', 'datum'), // 一件事管理-材料库
//以下为基础路由配置
builder('', 'Home'),
builder('index', 'Home'),
builder('login/updatePwd', 'login/updatePwd'),
builder('403', 'errors/403'),
builder('*', 'errors/404'),
]
},
]
})
/**
* rest路由生成器
*
* @param {string} path 路径
* @param {string} [component=path] 文件地址
* @returns {array} [] reset路由数组,包含list/edit/add/view
*/
function restBuilder(path, component = path) {
let arr = [];
arr.push(builder(`${path}/list`, `${component}/list`));
arr.push(builder(`${path}/edit`, `${component}/show`));
arr.push(builder(`${path}/add`, `${component}/show`));
arr.push(builder(`${path}/view`, `${component}/show`));
return arr;
}
/**
* 路由生成器
*
* @param {string} path 路径
* @param {string} [component=path] 文件地址
* @param {boolean} [requiresAuth=false] 是否登录后才能访问
* @returns {any} {} 路由对象
*/
function builder(path, component = path, requiresAuth = false) {
return {
path: path,
name: path || 'homepage',
component: getComponent(component),
meta: {
requiresAuth: requiresAuth
}
}
}
function getComponent(fileName) {
try {
return require('./views/' + fileName).default
} catch (error) {
return fileNotFound;
}
}
//检查是否跳转到sso地址
function ssoCheck (to, from, next) {
let redirect = (to.path === '/login/updatePwd') ? '/#/updatePwd' : ''
redirect = (redirect === '' && to.path === '/login') ? (location.protocol + '//' + location.host + '/#' + from.fullPath) : redirect
if (redirect != '') {
next(false)
window.location.href = '//' + location.host + '/m/login/logout?redirect=' + encodeURIComponent(redirect)
return true;
}
return false;
}
router.afterEach(() => {
document.body.scrollTop = 0
document.documentElement.scrollTop = 0
})
// 路由鉴权
router.beforeEach((to, from, next) => {
// if (ssoCheck(to, from, next)) { //sso鉴权检查
// return
// }
if (to.matched.some(record => record.meta.requiresAuth)) {
if (Store.state.isLogin) {
next();
} else {
next({
path: '/authentication',
query: {
redirect: to.fullPath
}
})
}
} else {
next();
}
})
export default router;