diff --git a/src/layouts/navbar/index.vue b/src/layouts/navbar/index.vue
index 9e6a68b..ae2e378 100644
--- a/src/layouts/navbar/index.vue
+++ b/src/layouts/navbar/index.vue
@@ -29,8 +29,9 @@
diff --git a/src/pages/system/list/role.vue b/src/pages/system/list/role.vue
index 0c9f0c2..1f96721 100644
--- a/src/pages/system/list/role.vue
+++ b/src/pages/system/list/role.vue
@@ -8,8 +8,8 @@
- 新增角色
- 批量删除
+ 新增角色
+ 批量删除
@@ -24,9 +24,9 @@
- 查看
- 编辑
- 删除
+ 查看
+ 编辑
+ 删除
diff --git a/src/pages/system/list/staff.vue b/src/pages/system/list/staff.vue
index 8947157..3063830 100644
--- a/src/pages/system/list/staff.vue
+++ b/src/pages/system/list/staff.vue
@@ -13,9 +13,9 @@
- 新增员工
- 批量导入
- 批量删除
+ 新增员工
+ 批量导入
+ 批量删除
@@ -30,10 +30,10 @@
- 查看
- 编辑
- 重置密码
- 删除
+ 查看
+ 编辑
+ 重置密码
+ 删除
diff --git a/src/pages/system/list/staffSide.vue b/src/pages/system/list/staffSide.vue
index fb3cd74..3c816bd 100644
--- a/src/pages/system/list/staffSide.vue
+++ b/src/pages/system/list/staffSide.vue
@@ -3,7 +3,7 @@
员工组织架构
- 添加
+ 添加
{{ node.label }}
handleEdit(node, data)">
handleAdd(node, data)">
handleDel(node, data)">
diff --git a/src/plugins/auth/index.js b/src/plugins/auth/index.js
index dd70ecf..4f362fe 100644
--- a/src/plugins/auth/index.js
+++ b/src/plugins/auth/index.js
@@ -9,10 +9,11 @@ export default {
inserted(el, binding, vnode) {
let btnText = "";
// 如果有传值,就取传的值,否则,就取页面路由和按钮名字拼接起来
+ const route = vnode.context.$route.path
if (binding.value) {
- btnText = binding.value;
+ btnText = route + ':' + binding.value
} else {
- btnText = `${vnode.context.$route.path}:${el.innerText}`;
+ btnText = route + ':' + el.innerText
}
const btnPermissions = store.state.auth.btns;
diff --git a/src/router/index.js b/src/router/index.js
index 97f3b80..5a18b62 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -2,10 +2,6 @@ import Vue from "vue";
import Router from "vue-router";
import routes from "./routes";
import Setting from "@/setting";
-import { get } from "@/plugins/requests/index.js";
-import api from "@/api";
-import util from "@/libs/util";
-import BasicLayout from "@/layouts/home";
Vue.use(Router);
const createRouter = () => new Router({
mode: Setting.routerMode,
@@ -16,286 +12,7 @@ const createRouter = () => new Router({
export function resetRouter() {
const newRouter = createRouter();
- router.matcher = newRouter.matcher;
+ router.matcher = newRouter.matcher
}
-
-let router = createRouter();
-
-
-export default router;
-
-
-/**
- * 错误页面
- */
-const errorPage = [
- {
- path: "/403",
- name: "403",
- meta: {
- title: "403"
- },
- component: () => import("@/pages/exception/error/403")
- },
- {
- path: "*",
- name: "404",
- meta: {
- title: "404"
- },
- component: () => import("@/pages/exception/error/404")
- }
-];
-
-// 处理路由权限的方法
-function getPermission() {
- sessionStorage.setItem("handelPermission", true);// 记录已处理权限
- get(`${api.getUserRolesPermissionMenu}?platformId=${Setting.platformId}`).then(res => {
- // 取得路由的值,使用addRouter添加进路由里
- // 该项目的路由实际上做了两层处理,一层指向了默认的路由,对应模块,用于基础布局的nav,下面一层才是实际上的路由跳转,
- // 所以需要默认进行赋值,实际操作时根据path去禁用掉对应的nav即可。
- const arr = ['achievement','assessment','course',"evaluation",'information','match','project','setting','student', 'station','system'];
- let permissionRouters = []; // 最后处理好的路由数组
-
- let data = res.permissionMenu[0].children;
- if (data.length > 0) {
- data.forEach(e => {
- // 第一级路由,需要根据匹配到的path,塞进对应的路由children里
- let str = e.path.split("/")[1];
- let index = arr.indexOf(str);
- if (index !== -1) {
- let obj = {
- path: e.path,
- name: arr[index] + "-list",
- component: () => import(`@/pages${e.path}`),
- meta: { title: e.name, btn: [] },
- children: []
- };
- let meta = [];
- let children = [];
- // 第二级是按钮级数据,一级归属当前页的同级页面,实际上一共就一级路由
- if (e.children && e.children.length > 0) {
- e.children.forEach(i => {
- // 避免重复生成路由
- if (i.path && permissionRouters[index] && !permissionRouters[index].children.some(e => i.path === e.path)) {
- let obj = {
- path: i.path,
- name: arr[index] + "-" + i.path.split("/").pop(),
- component: () => import(`@/pages${i.path}`),
- meta: { title: i.name, btn: [] },
- children: []
- };
- // 没找到第一级就生成一个
- if (!permissionRouters.some(e => e.path === `/${str}`)) {
- let one = {
- path: "/" + arr[index],
- name: arr[index],
- redirect: {
- name: `${arr[index]}-list`
- },
- component: BasicLayout,
- children: []// 传来的路由实际上传入对应的children中
- };
- one.children.push(obj);
- permissionRouters.push(one);
- } else {
- // 找到第一级,判断没有重复地址直接塞进去
- let nowIndex = permissionRouters.findIndex(e => {
- return e.path === `/${str}`;
- });
- if (nowIndex != -1 && permissionRouters[nowIndex] && !permissionRouters[nowIndex].children.some(e => e.path === obj.path)) {
- permissionRouters[nowIndex].children.push(obj);
- }
- }
- // permissionRouters.push(obj) // path是页面,要塞入上一级同级里,需要单独push进去生成路由
- meta.push(i.name);
- } else {
- meta.push(i.name);
- }
-
- if (i.children && i.children.length) {
- i.children.forEach(j => {
- if (j.path && permissionRouters[index] && !permissionRouters[index].children.some(e => j.path === e.path)) {
- // console.log(j.path,'当前三级路由的路径')
- let obj = {
- path: j.path,
- name: arr[index] + "-" + j.path.split("/").pop(),
- component: () => import(`@/pages${j.path}`),
- meta: { title: j.name, btn: [] },
- children: []
- };
- // 没找到第一级就生成一个
- if (!permissionRouters.some(e => e.path === `/${str}`)) {
- let one = {
- path: "/" + arr[index],
- name: arr[index],
- redirect: {
- name: `${arr[index]}-list`
- },
- component: BasicLayout,
- children: []// 传来的路由实际上传入对应的children中
- };
- one.children.push(obj);
- permissionRouters.push(one);
- } else {
- // 找到第一级,判断没有重复地址直接塞进去
- let nowIndex = permissionRouters.findIndex(e => {
- return e.path === `/${str}`;
- });
- if (nowIndex != -1 && permissionRouters[nowIndex] && !permissionRouters[nowIndex].children.some(e => e.path === obj.path)) {
- permissionRouters[nowIndex].children.push(obj);
- }
- }
- // permissionRouters.push(obj) // path是页面,要塞入上一级同级里,需要单独push进去生成路由
- meta.push(i.name+"-"+j.name);
- } else {
- meta.push(i.name+"-"+j.name);
- }
-
- if (j.children && j.children.length) {
- j.children.forEach(k => {
- if (k.path && permissionRouters[index] && !permissionRouters[index].children.some(e => k.path === e.path)) {
- // console.log(j.path,'当前四级路由的路径')
- let obj = {
- path: k.path,
- name: arr[index] + "-" + k.path.split("/").pop(),
- component: () => import(`@/pages${k.path}`),
- meta: { title: k.name, btn: [] },
- children: []
- };
- // 没找到第一级就生成一个
- if (!permissionRouters.some(e => e.path === `/${str}`)) {
- let one = {
- path: "/" + arr[index],
- name: arr[index],
- redirect: {
- name: `${arr[index]}-list`
- },
- component: BasicLayout,
- children: []// 传来的路由实际上传入对应的children中
- };
- one.children.push(obj);
- permissionRouters.push(one);
- } else {
- // 找到第一级,判断没有重复地址直接塞进去
- let nowIndex = permissionRouters.findIndex(e => {
- return e.path === `/${str}`;
- });
- if (nowIndex != -1 && permissionRouters[nowIndex] && !permissionRouters[nowIndex].children.some(e => e.path === obj.path)) {
- permissionRouters[nowIndex].children.push(obj);
- }
- }
- // permissionRouters.push(obj) // path是页面,要塞入上一级同级里,需要单独push进去生成路由
- meta.push(j.name+"-"+k.name);
- } else {
- meta.push(j.name+"-"+k.name);
- }
- })
- }
- })
- }
- });
- }
- obj.meta.btn = meta;
- obj.children = children;
- // 处理好的路由,需要进行一次匹配,arr中必然存在对应的路由,所以在此处才生成第一级路由,免得额外判断是否有children
- if (permissionRouters.length === 0 || !permissionRouters.some(e => e.path === `/${str}`)) {
- // 生成第一级
- let one = {
- path: "/" + arr[index],
- name: arr[index],
- redirect: {
- name: `${arr[index]}-list`
- },
- component: BasicLayout,
- children: []// 传来的路由实际上传入对应的children中
- };
- one.children.push(obj);
- permissionRouters.push(one);
- // console.log(one,'当前的第一级别',obj,'第二级别')
- } else {
- // 找到第一级直接塞进去
- let nowIndex = permissionRouters.findIndex(e => {
- return e.path === `/${str}`;
- });
- if (nowIndex != -1) {
- permissionRouters[nowIndex].children.push(obj);
- }
- }
- }
- });
- console.log(permissionRouters, "处理好的");
- const station = permissionRouters.findIndex(e => e.name === 'station')
- if (station !== -1) {
- permissionRouters[station].children.push({
- name: `stationPreview`,
- path: `/station/preview`,
- component: () => import("@/pages/station/preview"),
- meta: { title: "实验台" }
- })
- }
- const assessment = permissionRouters.findIndex(e => e.name === 'assessment')
- if (assessment !== -1) {
- permissionRouters[assessment].children.push({
- name: `assessment-add`,
- path: `/assessment/add`,
- component: () => import("@/pages/assessment/add"),
- meta: { title: "创建考核" }
- })
- }
- const notice = permissionRouters.findIndex(e => e.name === 'match')
- if (notice !== -1) {
- const match = [
- {
- name: `noticeDetail`,
- path: `/match/noticeDetail`,
- component: () => import("@/pages/match/manage/noticeDetail"),
- meta: { title: "通知公告" }
- }
- ]
- permissionRouters[notice].children.push(...match)
- }
- // 把处理完成的路由,add到router里
- // 记录一下路由的名称,用于nav
- let nav = data.map(e => e.path);
- router.app.$options.store.commit("routers", nav);
- let redirect = [{
- path: "/index",
- redirect: station !== -1 ? '/station' : permissionRouters[0].path
- }];
- router.addRoutes(redirect);
- router.addRoutes(permissionRouters);
- router.addRoutes(errorPage);
- }
-
- });
-}
-
-// 权限
-router.beforeEach(function(to, from, next) {
- // console.log(router.app.$options.store.commit('routers'),'router.app.$options.store')
- document.title = Setting.titleSuffix;
- if (to.path == "/login") {
- localStorage.removeItem(Setting.tokenKey);
- sessionStorage.removeItem("handelPermission");
- }
- // console.log(util.local.get(Setting.tokenKey),'token')
- // console.log(sessionStorage.getItem('handelPermission'),'保存的是否处理')
- if (util.local.get(Setting.tokenKey)) {
- if (!sessionStorage.getItem("handelPermission")) {// 是否已处理权限
- getPermission();
- }
- } else {
- if (to.path !== "/login" && to.path !== '/redirect') {
- next({
- path: "/login",
- query: { redirect: to.path }
- })
- }
- }
- // 根据路由元信息设置文档标题
- // window.document.title = to.meta.title ? to.meta.title : "";
- window.document.title = "教师管理端"
- next();
-
-});
\ No newline at end of file
+let router = createRouter()
+export default router
\ No newline at end of file
diff --git a/src/router/modules/achivement.js b/src/router/modules/achivement.js
new file mode 100644
index 0000000..948eea9
--- /dev/null
+++ b/src/router/modules/achivement.js
@@ -0,0 +1,33 @@
+import BasicLayout from "@/layouts/home";
+
+const meta = {};
+
+const pre = "achievement-";
+
+export default {
+ path: "/achievement",
+ name: "achievement",
+ redirect: {
+ name: `${pre}list`
+ },
+ meta,
+ component: BasicLayout,
+ children: [
+ {
+ name: `${pre}list`,
+ path: `list`,
+ component: () => import("@/pages/achievement/list"),
+ meta: { title: "成绩管理" }
+ }, {
+ name: `${pre}teach`,
+ path: `teach`,
+ component: () => import("@/pages/achievement/teach"),
+ meta: { title: "成绩管理" }
+ }, {
+ name: `${pre}show`,
+ path: `show`,
+ component: () => import("@/pages/achievement/show"),
+ meta: { title: "实验报告" }
+ }
+ ]
+};
diff --git a/src/router/modules/assesment.js b/src/router/modules/assesment.js
new file mode 100644
index 0000000..0c62983
--- /dev/null
+++ b/src/router/modules/assesment.js
@@ -0,0 +1,29 @@
+import BasicLayout from "@/layouts/home";
+
+const meta = {};
+
+const pre = "assessment-";
+
+export default {
+ path: "/assessment",
+ name: "assessment",
+ redirect: {
+ name: `${pre}list`
+ },
+ meta,
+ component: BasicLayout,
+ children: [
+ {
+ name: `${pre}list`,
+ path: `list`,
+ component: () => import("@/pages/assessment/list"),
+ meta: { title: "考核管理" }
+ },
+ {
+ name: `${pre}add`,
+ path: `add`,
+ component: () => import("@/pages/assessment/add/index.vue"),
+ meta: { title: "添加考核" }
+ }
+ ]
+};
diff --git a/src/router/modules/course.js b/src/router/modules/course.js
new file mode 100644
index 0000000..f88048a
--- /dev/null
+++ b/src/router/modules/course.js
@@ -0,0 +1,41 @@
+import BasicLayout from "@/layouts/home";
+
+const meta = {};
+
+const pre = "course-";
+
+export default {
+ path: "/course",
+ name: "course",
+ redirect: {
+ name: `${pre}list`
+ },
+ meta,
+ component: BasicLayout,
+ children: [
+ {
+ name: `${pre}list`,
+ path: `list`,
+ component: () => import("@/pages/course/list"),
+ meta: { title: "理论课程管理" }
+ },
+ {
+ name: `${pre}add`,
+ path: `add`,
+ component: () => import("@/pages/course/add"),
+ meta: { title: "新增课程" }
+ },
+ {
+ name: `${pre}preview`,
+ path: `preview`,
+ component: () => import("@/pages/course/preview"),
+ meta: { title: "课程预览" }
+ },
+ {
+ name: `${pre}contentSettings`,
+ path: `contentSettings`,
+ component: () => import("@/pages/course/contentSettings"),
+ meta: { title: "内容设置" }
+ }
+ ]
+};
\ No newline at end of file
diff --git a/src/router/modules/evaluation.js b/src/router/modules/evaluation.js
new file mode 100644
index 0000000..55f5aa6
--- /dev/null
+++ b/src/router/modules/evaluation.js
@@ -0,0 +1,23 @@
+import BasicLayout from "@/layouts/home";
+
+const meta = {};
+
+const pre = "evaluation-";
+
+export default {
+ path: "/evaluation",
+ name: "evaluation",
+ redirect: {
+ name: `${pre}list`
+ },
+ meta,
+ component: BasicLayout,
+ children: [
+ {
+ name: `${pre}list`,
+ path: `list`,
+ component: () => import("@/pages/evaluation/list"),
+ meta: { title: "测评管理" }
+ }
+ ]
+};
diff --git a/src/router/modules/information.js b/src/router/modules/information.js
new file mode 100644
index 0000000..26024cc
--- /dev/null
+++ b/src/router/modules/information.js
@@ -0,0 +1,29 @@
+import BasicLayout from "@/layouts/home";
+
+const meta = {};
+
+const pre = "information-";
+
+export default {
+ path: "/information",
+ name: "information",
+ redirect: {
+ name: `${pre}list`
+ },
+ meta,
+ component: BasicLayout,
+ children: [
+ {
+ name: `${pre}list`,
+ path: `list`,
+ component: () => import("@/pages/information/list"),
+ meta: { title: "资讯管理" }
+ },
+ {
+ name: `${pre}addArticle`,
+ path: `addArticle`,
+ component: () => import("@/pages/information/addArticle"),
+ meta: { title: "新增文章" }
+ }
+ ]
+};
\ No newline at end of file
diff --git a/src/router/modules/match.js b/src/router/modules/match.js
new file mode 100644
index 0000000..0db5d7b
--- /dev/null
+++ b/src/router/modules/match.js
@@ -0,0 +1,35 @@
+import BasicLayout from "@/layouts/home";
+
+const meta = {};
+
+const pre = "match-";
+
+export default {
+ path: "/match",
+ name: "match",
+ redirect: {
+ name: `${pre}list`
+ },
+ meta,
+ component: BasicLayout,
+ children: [
+ {
+ name: `${pre}list`,
+ path: `list`,
+ component: () => import("@/pages/match/list"),
+ meta: { title: "赛事管理" }
+ },
+ {
+ name: `${pre}add`,
+ path: `add`,
+ component: () => import("@/pages/match/add"),
+ meta: { title: "创建赛事" }
+ },
+ {
+ name: `${pre}manage`,
+ path: `manage`,
+ component: () => import("@/pages/match/manage"),
+ meta: { title: "管理赛事" }
+ }
+ ]
+};
\ No newline at end of file
diff --git a/src/router/modules/project.js b/src/router/modules/project.js
new file mode 100644
index 0000000..80e22b7
--- /dev/null
+++ b/src/router/modules/project.js
@@ -0,0 +1,29 @@
+import BasicLayout from "@/layouts/home";
+
+const meta = {};
+
+const pre = "project-";
+
+export default {
+ path: "/project",
+ name: "project",
+ redirect: {
+ name: `${pre}list`
+ },
+ meta,
+ component: BasicLayout,
+ children: [
+ {
+ name: `${pre}list`,
+ path: `list`,
+ component: () => import("@/pages/project/list"),
+ meta: { title: "实验项目管理" }
+ },
+ {
+ name: `${pre}add`,
+ path: `add`,
+ component: () => import("@/pages/project/add"),
+ meta: { title: "新增项目" }
+ }
+ ]
+};
diff --git a/src/router/modules/setting.js b/src/router/modules/setting.js
new file mode 100644
index 0000000..22be52f
--- /dev/null
+++ b/src/router/modules/setting.js
@@ -0,0 +1,23 @@
+import BasicLayout from "@/layouts/home";
+
+const meta = {};
+
+const pre = "setting-";
+
+export default {
+ path: "/setting",
+ name: "setting",
+ redirect: {
+ name: `${pre}person`
+ },
+ meta,
+ component: BasicLayout,
+ children: [
+ {
+ name: `${pre}person`,
+ path: `person`,
+ component: () => import("@/pages/setting/list"),
+ meta: { title: "个人中心" }
+ }
+ ]
+};
\ No newline at end of file
diff --git a/src/router/modules/station.js b/src/router/modules/station.js
new file mode 100644
index 0000000..5bd4a42
--- /dev/null
+++ b/src/router/modules/station.js
@@ -0,0 +1,29 @@
+import BasicLayout from "@/layouts/home";
+
+const meta = {};
+
+const pre = "station-";
+
+export default {
+ path: "/station",
+ name: "station",
+ redirect: {
+ name: `${pre}list`
+ },
+ meta,
+ component: BasicLayout,
+ children: [
+ {
+ name: `${pre}person`,
+ path: `list`,
+ component: () => import("@/pages/station/list"),
+ meta: { title: "实验台" }
+ },
+ {
+ name: `${pre}preview`,
+ path: `preview`,
+ component: () => import("@/pages/station/preview"),
+ meta: { title: "课程预览" }
+ }
+ ]
+};
\ No newline at end of file
diff --git a/src/router/modules/student.js b/src/router/modules/student.js
new file mode 100644
index 0000000..7eda2b1
--- /dev/null
+++ b/src/router/modules/student.js
@@ -0,0 +1,23 @@
+import BasicLayout from "@/layouts/home";
+
+const meta = {};
+
+const pre = "student-";
+
+export default {
+ path: "/student",
+ name: "student",
+ redirect: {
+ name: `${pre}list`
+ },
+ meta,
+ component: BasicLayout,
+ children: [
+ {
+ name: `${pre}list`,
+ path: `list`,
+ component: () => import("@/pages/student/list"),
+ meta: { title: "学生管理" }
+ }
+ ]
+};
diff --git a/src/router/modules/system.js b/src/router/modules/system.js
new file mode 100644
index 0000000..d7753e6
--- /dev/null
+++ b/src/router/modules/system.js
@@ -0,0 +1,23 @@
+import BasicLayout from "@/layouts/home";
+
+const meta = {};
+
+const pre = "system-";
+
+export default {
+ path: "/system",
+ name: "system",
+ redirect: {
+ name: `${pre}list`
+ },
+ meta,
+ component: BasicLayout,
+ children: [
+ {
+ name: `${pre}list`,
+ path: `list`,
+ component: () => import("@/pages/system/list"),
+ meta: { title: "系统设置" }
+ }
+ ]
+};
diff --git a/src/router/permission.js b/src/router/permission.js
new file mode 100644
index 0000000..c7197a6
--- /dev/null
+++ b/src/router/permission.js
@@ -0,0 +1,14 @@
+import router from "./index";
+import Setting from "@/setting";
+import util from "@/libs/util";
+
+const whiteList = Setting.whiteList // 白名单
+router.beforeEach((to, from, next) => {
+ document.title = Setting.titleSuffix;
+ const role = util.local.get(Setting.tokenKey);
+ if (!role && !whiteList.includes(to.path)) {
+ next('/login')
+ } else {
+ next()
+ }
+});
\ No newline at end of file
diff --git a/src/router/routes.js b/src/router/routes.js
index 583e096..8661945 100644
--- a/src/router/routes.js
+++ b/src/router/routes.js
@@ -1,6 +1,13 @@
+import BasicLayout from '@/layouts/home'
-import BasicLayout from "@/layouts/home";
-
+/**
+ * 读取./modules下的所有js文件并注册模块
+ */
+const requireModule = require.context('./modules', false, /\.js$/)
+const modules = []
+requireModule.keys().forEach(fileName => {
+ modules.push(requireModule(fileName).default)
+})
const frameIn = [
// 默认路由配置
{
@@ -13,22 +20,7 @@ const frameIn = [
meta: { title: "首页" },
children: []
},
- {
- path: "/setting",
- name: "setting",
- redirect: {
- name: `/setting-person`
- },
- component: BasicLayout,
- children: [
- {
- name: `setting-person`,
- path: `person`,
- component: () => import("@/pages/setting/list"),
- meta: { title: "个人中心" }
- }
- ]
- }
+ ...modules
];
/**
@@ -57,13 +49,32 @@ const frameOut = [
meta: { title: "赛事预览" }
}
];
+/**
+ * 错误页面
+ */
-
-// 导出需要显示菜单的
-export const frameInRoutes = frameIn;
+const errorPage = [
+ {
+ path: '/403',
+ name: '403',
+ meta: {
+ title: '403'
+ },
+ component: () => import('@/pages/exception/error/403')
+ },
+ {
+ path: '*',
+ name: '404',
+ meta: {
+ title: '404'
+ },
+ component: () => import('@/pages/exception/error/404')
+ }
+]
// 重新组织后导出
export default [
...frameIn,
- ...frameOut
+ ...frameOut,
+ ...errorPage
];
\ No newline at end of file
diff --git a/src/setting.js b/src/setting.js
index 4c4f4ff..6baae75 100644
--- a/src/setting.js
+++ b/src/setting.js
@@ -48,6 +48,10 @@ const Setting = {
isDev,
isTest,
isPro,
+ /**
+ * 路由白名单
+ * */
+ whiteList: ['/login'],
/**
* localStorage里保存的token的key
*/