权限修复

dev_2022-06-14
yujialong 2 years ago
parent f2439b1e30
commit 2819a9c0cc
  1. 43
      src/layouts/navbar/index.vue
  2. 28
      src/libs/auth/generateBtnPermission.js
  3. 23
      src/libs/route/addRoutes.js
  4. 8
      src/main.js
  5. 14
      src/pages/assessment/list/index.vue
  6. 16
      src/pages/evaluation/list/index.vue
  7. 13
      src/pages/match/add/index.vue
  8. 2
      src/pages/station/list/index.vue
  9. 25
      src/pages/student/list/index.vue
  10. 31
      src/pages/system/list/index.vue
  11. 10
      src/pages/system/list/role.vue
  12. 14
      src/pages/system/list/staff.vue
  13. 5
      src/pages/system/list/staffSide.vue
  14. 5
      src/plugins/auth/index.js
  15. 289
      src/router/index.js
  16. 33
      src/router/modules/achivement.js
  17. 29
      src/router/modules/assesment.js
  18. 41
      src/router/modules/course.js
  19. 23
      src/router/modules/evaluation.js
  20. 29
      src/router/modules/information.js
  21. 35
      src/router/modules/match.js
  22. 29
      src/router/modules/project.js
  23. 23
      src/router/modules/setting.js
  24. 29
      src/router/modules/station.js
  25. 23
      src/router/modules/student.js
  26. 23
      src/router/modules/system.js
  27. 14
      src/router/permission.js
  28. 55
      src/router/routes.js
  29. 4
      src/setting.js

@ -29,8 +29,9 @@
</template>
<script>
import { mapState } from "vuex";
import { mapState, mapActions } from "vuex";
import Setting from '@/setting'
import addRoutes from '@/libs/route/addRoutes'
export default {
data() {
return {
@ -97,8 +98,8 @@ export default {
};
},
computed: {
...mapState([
"routers"
...mapState('auth', [
'routes'
])
},
watch: {
@ -113,22 +114,34 @@ export default {
}
},
created() {
this.initMenu();
this.getPer()
},
methods: {
...mapActions('user', [
'logout'
]),
//
getPer() {
this.$get(`${this.api.getUserRolesPermissionMenu}?platformId=${Setting.platformId}`).then(res => {
const routes = res.permissionMenu[0].children
addRoutes(routes)
this.initMenu()
}).catch(({ status }) => {
status === 500 && this.logout()
})
},
initMenu() {
// routervuexroutervuex
// if (Setting.dynamicRoute) {
// let routes = this.routes;
let menus = [];
// store
if (Setting.dynamicRoute) {
const { routes } = this
const menus = []
this.defaultMenus.map(e => {
this.routers.find(n => n == e.index) && menus.push(e);
routes.find(n => n.path === e.index) && menus.push(e)
});
this.menus = menus;
// this.menus = this.defaultMenus
// } else {
// this.menus = this.defaultMenus;
// }
this.menus = menus
} else {
this.menus = this.defaultMenus
}
}
}
};

@ -2,21 +2,19 @@
* @description 生成按钮级别权限组
* */
import store from "@/store";
import store from '@/store'
export default function(data) {
let result = [];
const result = []
// 递归组合权限
function createAuth(data, auth) {
data.map(e => {
e.children.map(n => {
if (n.children.length) {
result.push(`${e.name}:${n.name}`);
n.children.map(j => {
e.menuUrl ? result.push(`${e.menuUrl}:${n.name}:${j.name}`) : result.push(`${n.menuUrl}:${j.name}`);
});
} else {
result.push(`${e.menuUrl}:${n.name}`);
}
});
});
store.dispatch("auth/addBtnAuth", result);
const text = (auth ? auth + ':' : '') + (auth ? e.name : e.path) // 第一级是路由,取path,子级取name
result.push(text)
e.children && e.children.length && createAuth(e.children, text)
})
}
export default function(data) {
createAuth(data)
store.dispatch('auth/addBtnAuth', result)
}

@ -1,27 +1,26 @@
import store from "@/store";
import router from "@/router";
import generateBtnPermission from "../auth/generateBtnPermission";
import store from '@/store'
import generateBtnPermission from '../auth/generateBtnPermission'
const newRoutes = [];
const newRoutes = []
function createMeta(item) {
let meta = { title: item.name };
return meta;
let meta = { title: item.name }
return meta
}
function createRoute(data) {
data.map(e => {
if (e.menuUrl) {
let meta = createMeta(e);
const { path } = e
if (path) {
let meta = createMeta(e)
newRoutes.push({
name: e.menuUrl,
path: e.menuUrl,
path,
meta
});
})
}
// 递归生成路由集合
e.children && e.children.length && createRoute(e.children);
});
})
}
export default function(data, path) {

@ -12,6 +12,7 @@ import { post, get, del, put } from "@/plugins/requests/index.js";
import api from "@/api";
import store from "@/store";
import Setting from "@/setting";
import permission from "@/router/permission";
// 插件
import plugins from "@/plugins";
@ -35,13 +36,6 @@ const i18n = new VueI18n({
messages
});
Vue.prototype.auth = function(values){
// 直接拿值进行匹配,取得当前router的mate信息,传入,返回一个boolean,以此进行vif判断
// router.meta 信息匹配传进来的value,用vif去进行按钮级权限配置即可。
// $router.currentRoute.meta
// console.log(router.currentRoute.meta,'当前路由的按钮权限数组')
return router.currentRoute.meta.btn.some(e=>e===values)
}
new Vue({
mixins: [mixinApp],
router,

@ -44,8 +44,8 @@
</ul>
<div>
<div>
<el-button v-if="auth('创建考核')" type="info" round @click="add" >创建考核</el-button>
<el-button v-if="auth('批量删除')" type="primary" round @click="delAllData">批量删除</el-button>
<el-button v-auth type="info" round @click="add" >创建考核</el-button>
<el-button v-auth type="primary" round @click="delAllData">批量删除</el-button>
</div>
</div>
</div>
@ -99,16 +99,16 @@
<el-table-column label="操作" width="170" align="center">
<template slot-scope="scope">
<template v-if="scope.row.status == 0 && (roleName.includes('超级') || roleName === scope.row.roleName || (roleName === '管理员' && !scope.row.roleName.includes('超级')))">
<el-button v-if="scope.row.type == 1" type="text" @click="start(scope.row)">启动</el-button>
<el-button v-if="auth('修改')" type="text" @click="edit(scope.row)">修改</el-button>
<el-button v-auth v-if="scope.row.type == 1" type="text" @click="start(scope.row)">启动</el-button>
<el-button v-auth type="text" @click="edit(scope.row)">修改</el-button>
</template>
<template v-else-if="scope.row.status == 1 && (roleName.includes('超级') || roleName === scope.row.roleName || (roleName === '管理员' && !scope.row.roleName.includes('超级')))">
<el-button v-if="auth('提前结束')" type="text" @click="finish(scope.row)">提前结束</el-button>
<el-button type="text" @click="finish(scope.row)">提前结束</el-button>
</template>
<template v-else-if="scope.row.status == 2">
<el-button v-if="auth('查看成绩')" type="text" @click="show(scope.row)">查看成绩</el-button>
<el-button v-auth type="text" @click="show(scope.row)">查看成绩</el-button>
</template>
<el-button v-if="(scope.row.status == 0 || scope.row.status == 2) && auth('删除') && (roleName.includes('超级') || roleName === scope.row.roleName || (roleName === '管理员' && !scope.row.roleName.includes('超级')))" type="text" @click="delData(scope.row)">删除</el-button>
<el-button v-auth v-if="(scope.row.status == 0 || scope.row.status == 2) && (roleName.includes('超级') || roleName === scope.row.roleName || (roleName === '管理员' && !scope.row.roleName.includes('超级')))" type="text" @click="delData(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>

@ -19,10 +19,10 @@
</li>
</ul>
<div>
<el-button v-if="auth('测评设置')" type="info" @click="getInfo">测评设置</el-button>
<el-button v-if="auth('新增题目')" type="info" @click="addTopics">新增题目</el-button>
<el-button v-if="auth('批量上传')" type="primary" @click="showBatchUpload">批量上传</el-button>
<el-button v-if="auth('批量删除')" type="primary" @click="delAllData">批量删除</el-button>
<el-button v-auth type="info" @click="getInfo">测评设置</el-button>
<el-button v-auth type="info" @click="addTopics">新增题目</el-button>
<el-button v-auth type="primary" @click="showBatchUpload">批量上传</el-button>
<el-button v-auth type="primary" @click="delAllData">批量删除</el-button>
</div>
</div>
@ -44,10 +44,10 @@
<el-table-column prop="updateTime" label="时间" align="center"></el-table-column>
<el-table-column label="操作" align="center">
<template slot-scope="scope">
<el-button v-if="auth('查看')" type="text" @click="showQues(scope.row)">查看</el-button>
<el-button v-if="auth('编辑')" type="text" @click="editQues(scope.row)">编辑</el-button>
<el-button v-auth type="text" @click="showQues(scope.row)">查看</el-button>
<el-button v-auth type="text" @click="editQues(scope.row)">编辑</el-button>
<el-switch
v-if="auth('禁用')"
v-auth="'禁用'"
v-model="scope.row.isEnable"
:active-text="!scope.row.isEnable ? '禁用' : '启用'"
:active-value="1"
@ -55,7 +55,7 @@
style="margin: 0 10px;"
@change="switchQues($event,scope.row,scope.$index)"
></el-switch>
<el-button v-if="auth('删除')" type="text" @click="delData(scope.row)">删除</el-button>
<el-button v-auth type="text" @click="delData(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>

@ -220,7 +220,6 @@ export default {
if (input && input.value) return false
const { level, value } = node
//
console.log('lazy', node, that.range)
if (!level) {
that.$get(that.api.queryProvince).then(({ list }) => {
const data = []
@ -346,7 +345,6 @@ export default {
range.push(item)
})
this.range = range
console.log("🚀 ~ file: matchDetail.vue ~ line 327 ~ this.$post ~ this.range", this.range)
}
// name
@ -428,10 +426,15 @@ export default {
//
uploadAnnexSuccess(res) {
const file = res.data.filesResult
this.form.contestAnnexList.push({
const { id } = this.form
const data = {
contestId: id || '',
fileName: this.fileName,
filePath: file.fileUrl || file.fileId
})
filePath: file.fileUrl
}
this.form.contestAnnexList.push(data)
//
id && this.$post(this.api.saveAnnex, data).then(res => {}).catch(res => {})
},
//
beforeUpload(file) {

@ -3,7 +3,7 @@
<div class="wrap">
<div class="search">
<h6>创新实验智能教学</h6>
<div class="input" v-if="auth('搜索')">
<div class="input" v-auth="'搜索'">
<img src="@/assets/img/search.png" alt="">
<input type="text" placeholder="请输入关键词" v-model="keyword">
</div>

@ -16,7 +16,7 @@
<div>
<div class="flex-between m-b-20">
<h6 class="p-title" style="margin-bottom: 0">学生组织架构</h6>
<el-button v-if="auth('学生组织架构添加')" type="text" @click="handleAdd">添加</el-button>
<el-button v-auth="'学生组织架构添加'" type="text" @click="handleAdd">添加</el-button>
</div>
<div style="height: 504px; max-height: 504px; overflow: auto">
@ -37,13 +37,14 @@
<span class="name" :title="node.label">{{ node.label }}</span>
<span>
<el-button
v-if="auth('学生组织架构编辑')"
v-auth="'学生组织架构编辑'"
type="text"
icon="el-icon-edit-outline"
@click="() => handleEdit(node, data)">
</el-button>
<el-button
v-if="auth('学生组织架构添加')&&node.level < 3"
v-auth="'学生组织架构添加'"
v-if="node.level < 3"
type="text"
icon="el-icon-circle-plus-outline"
@click="() => handleAdd(node, data)">
@ -95,9 +96,9 @@
</li>
</ul>
<div>
<el-button type="info" v-if="auth('新增学生')" @click="addStudent">新增学生</el-button>
<el-button type="primary" v-if="auth('批量导入')" @click="batchImport">批量导入</el-button>
<el-button type="primary" v-if="auth('批量删除')" @click="delAllSelection">批量删除</el-button>
<el-button type="info" v-auth @click="addStudent">新增学生</el-button>
<el-button type="primary" v-auth @click="batchImport">批量导入</el-button>
<el-button type="primary" v-auth @click="delAllSelection">批量删除</el-button>
</div>
</div>
@ -114,13 +115,13 @@
<el-table-column prop="lastLoginTime" label="上次登录时间" align="center" width="120"></el-table-column>
<el-table-column label="操作" align="center" width="300">
<template slot-scope="scope">
<el-button v-if="isRemove && auth('移除')" type="text" @click="removeStudent(scope.row)">移除</el-button>
<el-button v-if="auth('查看')" type="text" @click="editStudent(scope.row,true)">查看</el-button>
<el-button v-if="auth('编辑')" type="text" @click="editStudent(scope.row,false)">编辑</el-button>
<el-button v-if="auth('重置密码')" type="text" @click="resetPassword(scope.row)">重置密码</el-button>
<el-button v-if="auth('删除')" type="text" @click="handleDelete(scope.row)">删除</el-button>
<el-button v-auth v-if="isRemove" type="text" @click="removeStudent(scope.row)">移除</el-button>
<el-button v-auth type="text" @click="editStudent(scope.row,true)">查看</el-button>
<el-button v-auth type="text" @click="editStudent(scope.row,false)">编辑</el-button>
<el-button v-auth type="text" @click="resetPassword(scope.row)">重置密码</el-button>
<el-button v-auth type="text" @click="handleDelete(scope.row)">删除</el-button>
<el-switch
v-if="auth('禁用')"
v-auth="'禁用'"
v-model="scope.row.isEnable"
:active-value="1"
:inactive-value="0"

@ -11,7 +11,8 @@
</template>
<script>
import Setting from "@/setting";
import { mapState } from 'vuex'
import Setting from '@/setting'
import staff from "./staff";
import role from "./role";
import logo from "./logo";
@ -27,7 +28,9 @@ export default {
};
},
computed: {
...mapState('auth', [
'btns'
])
},
components: {
staff,
@ -35,26 +38,20 @@ export default {
logo
},
created() {
Setting.dynamicRoute && this.initTabs();
Setting.dynamicRoute && this.initTabs()
},
methods: {
tabChange(index) {
this.active = index;
this.active = index
},
initTabs() {
let tab1 = this.auth("员工管理");
let tab2 = this.auth("角色权限");
let tab3 = this.auth("系统logo设置");
if (!tab1) {
delete this.tabs.staff;
}
if (!tab2) {
delete this.tabs.role;
}
if (!tab3) {
delete this.tabs.logo;
}
const { btns } = this
const tab1 = btns.includes('/system/list:员工管理')
const tab2 = btns.includes('/system/list:角色权限')
const tab3 = btns.includes('/system/list:系统logo设置')
tab1 || delete this.tabs.staff
tab2 || delete this.tabs.role
tab3 || delete this.tabs.logo
}
}
};

@ -8,8 +8,8 @@
</li>
</ul>
<div>
<el-button v-if="auth('角色权限-新增角色')" type="info" round @click="addRole">新增角色</el-button>
<el-button v-if="auth('角色权限-批量删除')" type="primary" round @click="delAllSelection">批量删除</el-button>
<el-button v-auth="'角色权限:新增角色'" type="info" round @click="addRole">新增角色</el-button>
<el-button v-auth="'角色权限:批量删除'" type="primary" round @click="delAllSelection">批量删除</el-button>
</div>
</div>
@ -24,9 +24,9 @@
</el-table-column>
<el-table-column label="操作" align="center" width="200">
<template slot-scope="scope">
<el-button v-if="auth('角色权限-查看')" type="text" @click="showRole(scope.row)">查看</el-button>
<el-button v-if="auth('角色权限-编辑') && scope.row.roleName !== '超级管理员'" type="text" @click="editRole(scope.row)">编辑</el-button>
<el-button v-if="auth('角色权限-删除') && scope.row.roleName !== '超级管理员' && scope.row.roleName !== '管理员'" type="text" @click="handleDelete(scope.row)">删除</el-button>
<el-button v-auth="'角色权限:查看'" type="text" @click="showRole(scope.row)">查看</el-button>
<el-button v-auth="'角色权限:编辑'" v-if="scope.row.roleName !== '超级管理员'" type="text" @click="editRole(scope.row)">编辑</el-button>
<el-button v-auth="'角色权限:删除'" v-if="scope.row.roleName !== '超级管理员' && scope.row.roleName !== '管理员'" type="text" @click="handleDelete(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>

@ -13,9 +13,9 @@
</li>
</ul>
<div>
<el-button v-if="auth('员工管理-新增员工')" type="info" round @click="addTeacher">新增员工</el-button>
<el-button v-if="auth('员工管理-批量导入')" type="primary" round @click="batchImport">批量导入</el-button>
<el-button v-if="auth('员工管理-批量删除')" type="primary" round @click="delAllSelection">批量删除</el-button>
<el-button v-auth="'员工管理:新增员工'" type="info" round @click="addTeacher">新增员工</el-button>
<el-button v-auth="'员工管理:批量导入'" type="primary" round @click="batchImport">批量导入</el-button>
<el-button v-auth="'员工管理:批量删除'" type="primary" round @click="delAllSelection">批量删除</el-button>
</div>
</div>
@ -30,10 +30,10 @@
<el-table-column prop="lastLoginTime" label="上次登录时间" align="center"></el-table-column>
<el-table-column label="操作" width="200" align="center">
<template slot-scope="scope">
<el-button v-if="auth('员工管理-员工查看')" type="text" @click="showTeacher(scope.row)">查看</el-button>
<el-button v-if="auth('员工管理-员工编辑')" type="text" @click="editTeacher(scope.row)">编辑</el-button>
<el-button v-if="auth('员工管理-重置密码')" type="text" @click="resetPassword(scope.row)">重置密码</el-button>
<el-button v-if="auth('员工管理-员工删除')" type="text" @click="delTeacher(scope.row)">删除</el-button>
<el-button v-auth="'员工管理:员工查看'" type="text" @click="showTeacher(scope.row)">查看</el-button>
<el-button v-auth="'员工管理:员工编辑'" type="text" @click="editTeacher(scope.row)">编辑</el-button>
<el-button v-auth="'员工管理:重置密码'" type="text" @click="resetPassword(scope.row)">重置密码</el-button>
<el-button v-auth="'员工管理:员工删除'" type="text" @click="delTeacher(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>

@ -3,7 +3,7 @@
<div>
<div class="flex-between m-b-20">
<h6 class="p-title" style="margin-bottom: 0">员工组织架构</h6>
<el-button type="text" @click="addMajor">添加</el-button>
<el-button type="text" @click="addMajor" v-auth="'员工管理:新增专业'">添加</el-button>
</div>
<org-tree
:data="orgList"
@ -21,17 +21,20 @@
<span style="display: inline-block; margin-right: 20px">{{ node.label }}</span>
<span>
<el-button
v-auth="'员工管理:新增专业'"
type="text"
icon="el-icon-edit-outline"
@click="() => handleEdit(node, data)">
</el-button>
<el-button
v-auth="'员工管理:编辑专业'"
v-if="node.level === 1"
type="text"
icon="el-icon-circle-plus-outline"
@click="() => handleAdd(node, data)">
</el-button>
<el-button
v-auth="'员工管理:删除专业'"
type="text"
icon="el-icon-delete"
@click="() => handleDel(node, data)">

@ -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;

@ -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();
});
let router = createRouter()
export default router

@ -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: "实验报告" }
}
]
};

@ -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: "添加考核" }
}
]
};

@ -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: "内容设置" }
}
]
};

@ -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: "测评管理" }
}
]
};

@ -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: "新增文章" }
}
]
};

@ -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: "管理赛事" }
}
]
};

@ -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: "新增项目" }
}
]
};

@ -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: "个人中心" }
}
]
};

@ -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: "课程预览" }
}
]
};

@ -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: "学生管理" }
}
]
};

@ -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: "系统设置" }
}
]
};

@ -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()
}
});

@ -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
];

@ -48,6 +48,10 @@ const Setting = {
isDev,
isTest,
isPro,
/**
* 路由白名单
* */
whiteList: ['/login'],
/**
* localStorage里保存的token的key
*/

Loading…
Cancel
Save