diff --git a/src/App.vue b/src/App.vue index ff6d150..d5535d4 100644 --- a/src/App.vue +++ b/src/App.vue @@ -18,6 +18,7 @@ export default { //在页面刷新时将vuex里的信息保存到localStorage里 window.addEventListener("beforeunload", () => { + sessionStorage.removeItem('handelPermission') util.local.get(Setting.tokenKey) && util.local.set(Setting.storeKey, this.$store.state); }); } diff --git a/src/layouts/navbar/index.vue b/src/layouts/navbar/index.vue index 100c131..d47cb17 100644 --- a/src/layouts/navbar/index.vue +++ b/src/layouts/navbar/index.vue @@ -94,8 +94,8 @@ export default { }; }, computed: { - ...mapState("auth", [ - "routes" + ...mapState([ + "routers" ]) }, watch: { @@ -112,16 +112,17 @@ export default { }, methods: { initMenu() { - if (Setting.dynamicRoute) { - let routes = this.routes; + // 原版的router是从vuex取得,需要把router数据再次存一份到vuex里即可。 + // if (Setting.dynamicRoute) { + // let routes = this.routes; let menus = []; this.defaultMenus.map(e => { - routes.find(n => n.path == e.index) && menus.push(e); + this.routers.find(n => n == e.index) && menus.push(e); }); this.menus = menus; - } else { - this.menus = this.defaultMenus; - } + // } else { + // this.menus = this.defaultMenus; + // } } } }; diff --git a/src/main.js b/src/main.js index 2f511f9..ba9cd52 100644 --- a/src/main.js +++ b/src/main.js @@ -36,13 +36,13 @@ const i18n = new VueI18n({ messages }); -function auth(values){ +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) } -Vue.use(auth)// 鉴权函数 new Vue({ mixins: [mixinApp], router, diff --git a/src/pages/account/login/index.vue b/src/pages/account/login/index.vue index e1edded..bfceb33 100644 --- a/src/pages/account/login/index.vue +++ b/src/pages/account/login/index.vue @@ -108,6 +108,7 @@ export default { this.login(this.param).then(() => { let redirect = this.$route.query.redirect ? decodeURIComponent(this.$route.query.redirect) : "/index"; this.$router.replace(redirect); + console.log(redirect) }).catch(res => { }); } else { diff --git a/src/pages/course/courseManagement/add.vue b/src/pages/course/list/courseManagement/add.vue similarity index 100% rename from src/pages/course/courseManagement/add.vue rename to src/pages/course/list/courseManagement/add.vue diff --git a/src/pages/course/courseManagement/contentSettings.vue b/src/pages/course/list/courseManagement/contentSettings.vue similarity index 100% rename from src/pages/course/courseManagement/contentSettings.vue rename to src/pages/course/list/courseManagement/contentSettings.vue diff --git a/src/pages/course/courseManagement/index.vue b/src/pages/course/list/courseManagement/index.vue similarity index 100% rename from src/pages/course/courseManagement/index.vue rename to src/pages/course/list/courseManagement/index.vue diff --git a/src/pages/course/courseManagement/preview.vue b/src/pages/course/list/courseManagement/preview.vue similarity index 100% rename from src/pages/course/courseManagement/preview.vue rename to src/pages/course/list/courseManagement/preview.vue diff --git a/src/pages/course/index.vue b/src/pages/course/list/index.vue similarity index 100% rename from src/pages/course/index.vue rename to src/pages/course/list/index.vue diff --git a/src/pages/course/sortManagement/index.vue b/src/pages/course/list/sortManagement/index.vue similarity index 100% rename from src/pages/course/sortManagement/index.vue rename to src/pages/course/list/sortManagement/index.vue diff --git a/src/pages/evaluation/list/index.vue b/src/pages/evaluation/list/index.vue index 4a19884..f023930 100644 --- a/src/pages/evaluation/list/index.vue +++ b/src/pages/evaluation/list/index.vue @@ -20,7 +20,7 @@
- 测评设置 + 测评设置 新增题目 批量上传 批量删除 diff --git a/src/pages/information/columnManage/index.vue b/src/pages/information/list/columnManage/index.vue similarity index 100% rename from src/pages/information/columnManage/index.vue rename to src/pages/information/list/columnManage/index.vue diff --git a/src/pages/information/contentManage/addArticle.vue b/src/pages/information/list/contentManage/addArticle.vue similarity index 100% rename from src/pages/information/contentManage/addArticle.vue rename to src/pages/information/list/contentManage/addArticle.vue diff --git a/src/pages/information/contentManage/contentList.vue b/src/pages/information/list/contentManage/contentList.vue similarity index 100% rename from src/pages/information/contentManage/contentList.vue rename to src/pages/information/list/contentManage/contentList.vue diff --git a/src/pages/information/contentManage/index.vue b/src/pages/information/list/contentManage/index.vue similarity index 100% rename from src/pages/information/contentManage/index.vue rename to src/pages/information/list/contentManage/index.vue diff --git a/src/pages/information/index.vue b/src/pages/information/list/index.vue similarity index 100% rename from src/pages/information/index.vue rename to src/pages/information/list/index.vue diff --git a/src/pages/match/add.vue b/src/pages/match/add/index.vue similarity index 99% rename from src/pages/match/add.vue rename to src/pages/match/add/index.vue index 29730da..c455285 100644 --- a/src/pages/match/add.vue +++ b/src/pages/match/add/index.vue @@ -440,7 +440,7 @@ $upload-lg-height: 150px; .remove { width: 16px; height: 16px; - background: url(../../assets/img/close.png) 0 0/cover no-repeat; + background: url("../../../assets/img/close.png") 0 0/cover no-repeat; cursor: pointer; } } diff --git a/src/pages/match/index.vue b/src/pages/match/list/index.vue similarity index 98% rename from src/pages/match/index.vue rename to src/pages/match/list/index.vue index 2b05065..2a17d6d 100644 --- a/src/pages/match/index.vue +++ b/src/pages/match/list/index.vue @@ -189,10 +189,10 @@ export default { this.getData(); }, add() { - this.$router.push("add"); + this.$router.push("/match/add"); }, manage(row) { - this.$router.push(`manage?id=${row.id}`); + this.$router.push(`/match/manage?id=${row.id}`); }, changeType() { diff --git a/src/pages/match/list/manage/matchDetail.vue b/src/pages/match/list/manage/matchDetail.vue new file mode 100644 index 0000000..9fa5dcd --- /dev/null +++ b/src/pages/match/list/manage/matchDetail.vue @@ -0,0 +1,446 @@ + + + + + \ No newline at end of file diff --git a/src/pages/match/manage/matchDetail.vue b/src/pages/match/manage/matchDetail.vue index dabbf69..b8fbc24 100644 --- a/src/pages/match/manage/matchDetail.vue +++ b/src/pages/match/manage/matchDetail.vue @@ -414,7 +414,7 @@ $upload-lg-height: 150px; .remove { width: 16px; height: 16px; - background: url(../../../assets/img/close.png) 0 0/cover no-repeat; + background: url("../../../assets/img/close.png") 0 0/cover no-repeat; cursor: pointer; } } diff --git a/src/pages/project/list/index.vue b/src/pages/project/list/index.vue index e9f21de..6b0a457 100644 --- a/src/pages/project/list/index.vue +++ b/src/pages/project/list/index.vue @@ -3,7 +3,6 @@ -
筛选
diff --git a/src/pages/setting/person/index.vue b/src/pages/setting/list/index.vue similarity index 100% rename from src/pages/setting/person/index.vue rename to src/pages/setting/list/index.vue diff --git a/src/pages/student/list/index.vue b/src/pages/student/list/index.vue index 16fc180..d861315 100644 --- a/src/pages/student/list/index.vue +++ b/src/pages/student/list/index.vue @@ -18,7 +18,7 @@
学生组织架构
- 添加 + 添加
@@ -37,12 +37,13 @@ {{ node.label }} @@ -97,9 +98,9 @@
- 新增学生 - 批量导入 - 批量删除 + 新增学生 + 批量导入 + 批量删除
@@ -362,6 +363,7 @@ export default { }, mounted() { this.getData(); + this.auth() }, watch: { keyword: function(val) { @@ -377,6 +379,7 @@ export default { } }, methods: { + handleNodeClick(data) { // 点击树节点查询列表数据 if (data.level === 3) { this.isRemove = true; diff --git a/src/router/index.js b/src/router/index.js index e499a33..e15e92a 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -6,6 +6,7 @@ import {get} from "@/plugins/requests/index.js"; import api from "@/api"; import util from "@/libs/util"; import { permission } from '@/router/permission'; +import BasicLayout from "@/layouts/home"; Vue.use(Router); @@ -51,19 +52,26 @@ export default router; ]; // 处理路由权限的方法 function getPermission(){ + sessionStorage.setItem('handelPermission',true)// 记录已处理权限 get(api.getUserRolesPermissionMenu).then(res => { - console.log(res,'权限的值') // 取得路由的值,使用addRouter添加进路由里 + // 该项目的路由实际上做了两层处理,一层指向了默认的路由,对应模块,用于基础布局的nav,下面一层才是实际上的路由跳转, + // 所以需要默认进行赋值,实际操作时根据path去禁用掉对应的nav即可。 + const arr = ['achievement','assessment','course',"evaluation",'information','match','project','setting','student','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) let obj = { path:e.path, - name:e.name, - component:`../pages${e.path}`, - meta:[], + name:arr[index]+'-list', + component:() => import(`@/pages${e.path}`), + meta:{title:e.name,btn:[]}, children:[] } let meta = [] @@ -72,28 +80,73 @@ function getPermission(){ if(e.children&&e.children.length>0){ e.children.forEach(i=>{ // 避免重复生成路由 - if(i.path&&!permissionRouters.some(e=>i.path===e.path)){ + if(i.path&&!permissionRouters[index].children.some(e=>i.path===e.path)){ + // console.log(i.path,'当前二级路由的路径') let obj = { path:i.path, - name:i.name, - component:`../pages${i.path}`, - meta:[], + name:arr[index]+'-'+i.path.split('/').pop(), + component:() => import(`@/pages${i.path}`), + meta:{title:i.name,btn:[]}, children:[] - } - permissionRouters.push(obj) // path是页面,要塞入上一级同级里,需要单独push进去生成路由 + } + // 没找到第一级就生成一个 + 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].children.some(e=>e.path===obj.path)){ + permissionRouters[nowIndex].children.push(obj) + } + } + // permissionRouters.push(obj) // path是页面,要塞入上一级同级里,需要单独push进去生成路由 }else{ // 其他的是归属于当前页的按钮级信息,以此为依据来做按钮权限即可 meta.push(i.name) } }) } - obj.meta = meta + obj.meta.btn = meta obj.children = children - // 处理好的路由 - permissionRouters.push(obj) + // 处理好的路由,需要进行一次匹配,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,'处理好的') // 把处理完成的路由,add到router里 - // router.addRoutes(permissionRouters) + // 记录一下路由的名称,用于nav + let nav = data.map(e=>e.path) + router.app.$options.store.commit('routers',nav) + router.addRoutes(permissionRouters) router.addRoutes(errorPage) } @@ -101,11 +154,16 @@ function getPermission(){ } // 权限 router.beforeEach(function(to,from,next){ + // console.log(router.app.$options.store.commit('routers'),'router.app.$options.store') + 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')){ + if(!sessionStorage.getItem('handelPermission')){// 是否已处理权限 getPermission() } }else{ @@ -115,6 +173,8 @@ router.beforeEach(function(to,from,next){ }) } } + // 根据路由元信息设置文档标题 + window.document.title = to.meta.title next() }) \ No newline at end of file diff --git a/src/router/routes.js b/src/router/routes.js index 3cd9282..ca0fdb2 100644 --- a/src/router/routes.js +++ b/src/router/routes.js @@ -1,14 +1,14 @@ -// 引入模块化的路由 -import assessment from "./modules/assessment"; -import achievement from "./modules/achievement"; -import evaluation from "./modules/evaluation"; -import project from "./modules/project"; -import student from "./modules/student"; -import system from "./modules/system"; -import setting from "./modules/setting"; -import course from "./modules/course"; -import match from "./modules/match"; -import information from "./modules/information"; +// // 引入模块化的路由 +// import assessment from "./modules/assessment"; +// import achievement from "./modules/achievement"; +// import evaluation from "./modules/evaluation"; +// import project from "./modules/project"; +// import student from "./modules/student"; +// import system from "./modules/system"; +// import setting from "./modules/setting"; +// import course from "./modules/course"; +// import match from "./modules/match"; +// import information from "./modules/information"; import BasicLayout from "@/layouts/home"; @@ -29,16 +29,16 @@ const frameIn = [ children: [] }, // 以下为引入的路由,权限写好直接删掉 - assessment, - achievement, - evaluation, - project, - student, - system, - setting, - course, - match, - information + // assessment, + // achievement, + // evaluation, + // project, + // student, + // system, + // setting, + // course, + // match, + // information ]; /** diff --git a/src/setting.js b/src/setting.js index 8a44dd5..6aff0d3 100644 --- a/src/setting.js +++ b/src/setting.js @@ -43,9 +43,9 @@ if (isHh) { } else if (isDev) { jumpPath = "http://192.168.31.154:8087/"; // host = "http://39.108.250.202:9000/"; // 中台测试服 - host = "http://192.168.31.151:9000/"; // 榕 + // host = "http://192.168.31.151:9000/"; // 榕 // host = "http://192.168.31.125:9000/"; // 坤 - // host = 'http://192.168.31.137:9000/'; // 赓 + host = 'http://192.168.31.137:9000/'; // 赓 title = "职站服务端管理系统"; schoolId = 2105; } else { @@ -107,7 +107,7 @@ const Setting = { // 相同路由,不同参数间进行切换,是否强力更新 sameRouteForceUpdate: false, // 是否使用动态路由(即角色权限,开启了的话就会取后端返回的权限树来显示头部导肮和页面按钮) - dynamicRoute: false, + dynamicRoute: true, // 文件上传 upload: { apiURL: "http://39.108.250.202:9000/", diff --git a/src/store/index.js b/src/store/index.js index c7fa585..6a509de 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -18,6 +18,14 @@ const modules = modulesFiles.keys().reduce((modules, modulePath) => { }, {}); const store = new Vuex.Store({ + state:{ + routers:[] + }, + mutations:{ + routers(s,v){ + s.routers = v + } + }, modules, getters });