权限处理

dev_2022-05-11
e 3 years ago
parent 5d6a20c796
commit 7aec9afa0f
  1. 1
      src/App.vue
  2. 17
      src/layouts/navbar/index.vue
  3. 6
      src/main.js
  4. 1
      src/pages/account/login/index.vue
  5. 0
      src/pages/course/list/courseManagement/add.vue
  6. 0
      src/pages/course/list/courseManagement/contentSettings.vue
  7. 0
      src/pages/course/list/courseManagement/index.vue
  8. 0
      src/pages/course/list/courseManagement/preview.vue
  9. 0
      src/pages/course/list/index.vue
  10. 0
      src/pages/course/list/sortManagement/index.vue
  11. 2
      src/pages/evaluation/list/index.vue
  12. 0
      src/pages/information/list/columnManage/index.vue
  13. 0
      src/pages/information/list/contentManage/addArticle.vue
  14. 0
      src/pages/information/list/contentManage/contentList.vue
  15. 0
      src/pages/information/list/contentManage/index.vue
  16. 0
      src/pages/information/list/index.vue
  17. 2
      src/pages/match/add/index.vue
  18. 4
      src/pages/match/list/index.vue
  19. 446
      src/pages/match/list/manage/matchDetail.vue
  20. 2
      src/pages/match/manage/matchDetail.vue
  21. 1
      src/pages/project/list/index.vue
  22. 0
      src/pages/setting/list/index.vue
  23. 13
      src/pages/student/list/index.vue
  24. 90
      src/router/index.js
  25. 42
      src/router/routes.js
  26. 6
      src/setting.js
  27. 8
      src/store/index.js

@ -18,6 +18,7 @@ export default {
//vuexlocalStorage //vuexlocalStorage
window.addEventListener("beforeunload", () => { window.addEventListener("beforeunload", () => {
sessionStorage.removeItem('handelPermission')
util.local.get(Setting.tokenKey) && util.local.set(Setting.storeKey, this.$store.state); util.local.get(Setting.tokenKey) && util.local.set(Setting.storeKey, this.$store.state);
}); });
} }

@ -94,8 +94,8 @@ export default {
}; };
}, },
computed: { computed: {
...mapState("auth", [ ...mapState([
"routes" "routers"
]) ])
}, },
watch: { watch: {
@ -112,16 +112,17 @@ export default {
}, },
methods: { methods: {
initMenu() { initMenu() {
if (Setting.dynamicRoute) { // routervuexroutervuex
let routes = this.routes; // if (Setting.dynamicRoute) {
// let routes = this.routes;
let menus = []; let menus = [];
this.defaultMenus.map(e => { 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; this.menus = menus;
} else { // } else {
this.menus = this.defaultMenus; // this.menus = this.defaultMenus;
} // }
} }
} }
}; };

@ -36,13 +36,13 @@ const i18n = new VueI18n({
messages messages
}); });
function auth(values){ Vue.prototype.auth = function(values){
// 直接拿值进行匹配,取得当前router的mate信息,传入,返回一个boolean,以此进行vif判断 // 直接拿值进行匹配,取得当前router的mate信息,传入,返回一个boolean,以此进行vif判断
// router.meta 信息匹配传进来的value,用vif去进行按钮级权限配置即可。 // router.meta 信息匹配传进来的value,用vif去进行按钮级权限配置即可。
// $router.currentRoute.meta // $router.currentRoute.meta
console.log(router.currentRoute.meta,'当前路由的按钮权限数组')
return router.currentRoute.meta.btn.some(e=>e===values)
} }
Vue.use(auth)// 鉴权函数
new Vue({ new Vue({
mixins: [mixinApp], mixins: [mixinApp],
router, router,

@ -108,6 +108,7 @@ export default {
this.login(this.param).then(() => { this.login(this.param).then(() => {
let redirect = this.$route.query.redirect ? decodeURIComponent(this.$route.query.redirect) : "/index"; let redirect = this.$route.query.redirect ? decodeURIComponent(this.$route.query.redirect) : "/index";
this.$router.replace(redirect); this.$router.replace(redirect);
console.log(redirect)
}).catch(res => { }).catch(res => {
}); });
} else { } else {

@ -20,7 +20,7 @@
</li> </li>
</ul> </ul>
<div> <div>
<el-button type="primary" size="small" @click="getInfo" v-auth>测评设置</el-button> <el-button type="primary" v-if="auth('测评设置')" size="small" @click="getInfo" v-auth>测评设置</el-button>
<el-button type="primary" size="small" @click="addTopics" v-auth>新增题目</el-button> <el-button type="primary" size="small" @click="addTopics" v-auth>新增题目</el-button>
<el-button type="primary" size="small" @click="showBatchUpload" v-auth>批量上传</el-button> <el-button type="primary" size="small" @click="showBatchUpload" v-auth>批量上传</el-button>
<el-button type="primary" size="small" @click="delAllData" v-auth>批量删除</el-button> <el-button type="primary" size="small" @click="delAllData" v-auth>批量删除</el-button>

@ -440,7 +440,7 @@ $upload-lg-height: 150px;
.remove { .remove {
width: 16px; width: 16px;
height: 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; cursor: pointer;
} }
} }

@ -189,10 +189,10 @@ export default {
this.getData(); this.getData();
}, },
add() { add() {
this.$router.push("add"); this.$router.push("/match/add");
}, },
manage(row) { manage(row) {
this.$router.push(`manage?id=${row.id}`); this.$router.push(`/match/manage?id=${row.id}`);
}, },
changeType() { changeType() {

@ -0,0 +1,446 @@
<template>
<!-- 大赛详情 -->
<div style="padding: 24px">
<div class="page-content">
<el-form label-width="170px" label-suffix=":" size="small">
<el-form-item label="竞赛封面(选填)">
<el-upload
class="avatar-uploader"
accept=".jpg,.png,.jpeg,.gif"
:on-remove="handleRemove"
:on-error="uploadError"
:on-success="uploadSuccess"
:before-remove="beforeRemove"
:limit="1"
:on-exceed="handleExceed"
:action="this.api.fileupload"
name="file"
>
<img v-if="coverUrl" :src="coverUrl" class="avatar">
<div class="uploader-default" v-else>
<i class="el-icon-plus"></i>
<p>上传封面</p>
</div>
<div slot="tip" class="el-upload__tip">
<p>展示宽度为220高度140JPG/PNG/GIF3MB以内</p>
</div>
</el-upload>
</el-form-item>
<el-form-item label="竞赛封面长图(选填)">
<el-upload
class="avatar-uploader avatar-uploader-lg"
accept=".jpg,.png,.jpeg,.gif"
:on-remove="handleLgRemove"
:on-error="uploadError"
:on-success="uploadLgSuccess"
:before-remove="beforeRemove"
:limit="1"
:on-exceed="handleExceed"
:action="this.api.fileupload"
name="file"
>
<img v-if="carouselUrl" :src="carouselUrl" class="avatar-lg">
<div class="uploader-default" v-else>
<i class="el-icon-plus"></i>
<p>上传封面</p>
</div>
<div slot="tip" class="el-upload__tip">
<p>展示宽度为1920高度300JPG/PNG/GIF3MB以内</p>
</div>
</el-upload>
</el-form-item>
<el-form-item label="竞赛名称">
<div class="d-inline-block">
<el-input placeholder="请输入竞赛名称" v-model="name" clearable></el-input>
</div>
</el-form-item>
<el-form-item label="主办方">
<div class="inline-input">
<div class="input-wrap" v-for="(item,index) in sponsorList" :key="index">
<el-input placeholder="主办方名称" v-model="sponsorList[index]"></el-input>
<i v-if="sponsorList.length > 1" class="remove" @click="delSponsor(index)"></i>
<button v-if="index == 0" class="add-btn" @click="addSponsor">
<i class="el-icon-plus"></i>
<span>添加</span>
</button>
</div>
</div>
</el-form-item>
<el-form-item label="承办方(选填)">
<div class="inline-input">
<div class="input-wrap" v-for="(item,index) in undertakerList" :key="index">
<el-input placeholder="承办方名称" v-model="undertakerList[index]"></el-input>
<i v-if="undertakerList.length > 1" class="remove" @click="delOrganizer(index)"></i>
<button v-if="index == 0" class="add-btn" @click="addOrganizer">
<i class="el-icon-plus"></i>
<span>添加</span>
</button>
</div>
</div>
<button v-if="!undertakerList.length" class="add-btn" @click="addOrganizer">
<i class="el-icon-plus"></i>
<span>添加</span>
</button>
</el-form-item>
<el-form-item label="报名时间">
<el-date-picker v-model="signupTime" value-format="yyyy-MM-dd HH:mm:ss" type="datetimerange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
</el-form-item>
<el-form-item label="竞赛时间">
<el-date-picker v-model="playTime" value-format="yyyy-MM-dd HH:mm:ss" type="datetimerange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
</el-form-item>
<el-form-item label="竞赛详情">
<quill :border="true" v-model="description" :height="400" />
</el-form-item>
<el-form-item>
<el-button size="small" v-throttle @click="save(1)">保存</el-button>
<el-button type="primary" v-if="publishStatus == 1" v-throttle @click="save(0)">发布</el-button>
</el-form-item>
</el-form>
</div>
</div>
</template>
<script>
import quill from "@/components/quill";
import util from "@/libs/util";
export default {
name: "matchDetail",
data() {
return {
id: this.$route.query.id,
coverUrl: "",
carouselUrl: "",
publishStatus: 0,
uploadList: [],
uploadDataList: [],
name: "",
sponsor: "",
sponsorList: [""],
undertaker: "",
undertakerList: [],
signUpStartTime: "",
signUpEndTime: "",
signupTime: "",
playTime: "",
playStartTime: "",
playEndTime: "",
description: ""
};
},
components: {
quill
},
watch: {
signupTime: function(val) {
if (val) {
this.signUpStartTime = val[0];
this.signUpEndTime = val[1];
} else {
this.signUpStartTime = "";
this.signUpEndTime = "";
}
},
playTime: function(val) {
if (val) {
this.playStartTime = val[0];
this.playEndTime = val[1];
} else {
this.playStartTime = "";
this.playEndTime = "";
}
}
},
mounted() {
this.getData();
this.commitId();
},
methods: {
save(status) {
this.sponsor = this.sponsorList.filter(d => d).join();
this.undertaker = this.undertakerList.filter(d => d).join();
if (!this.name) return util.warningMsg("请填写竞赛名称");
if (status == 0) {
if (!this.sponsor) return util.warningMsg("请填写主办方");
if (!this.signUpStartTime) return util.warningMsg("请选择报名时间");
}
let now = new Date().getTime();
let signUpStartTime = new Date(this.signUpStartTime).getTime();
let signUpEndTime = new Date(this.signUpEndTime).getTime();
let playStartTime = new Date(this.playStartTime).getTime();
// if(signUpStartTime && now > signUpStartTime) return this.$$message.warning('')
if (!this.playStartTime && status == 0) return util.warningMsg("请选择竞赛时间");
if (playStartTime && playStartTime < signUpEndTime) return util.warningMsg("竞赛时间不能早于报名结束时间");
if (!this.description && status == 0) return util.warningMsg("请填写竞赛详情");
let data = {
id: this.id,
coverUrl: this.coverUrl,
carouselUrl: this.carouselUrl,
description: this.description,
founderId: 1,
name: this.name,
playEndTime: this.playEndTime,
playStartTime: this.playStartTime,
publishStatus: status ? this.publishStatus : 0,
signUpEndTime: this.signUpEndTime,
signUpStartTime: this.signUpStartTime,
sponsor: this.sponsor,
undertaker: this.undertaker
};
if (this.id) {
this.$put(this.api.editContest, data).then(res => {
util.successMsg("修改成功");
this.$router.back();
})
.catch(err => {
});
} else {
this.$post(this.api.addContest, data).then(res => {
util.successMsg("创建成功");
this.$router.back();
})
.catch(err => {
});
}
},
getData() {
this.$get(this.api.getContest + "/" + this.id)
.then(res => {
let data = res.contest;
this.coverUrl = data.coverUrl;
this.carouselUrl = data.carouselUrl;
this.description = data.description;
this.name = data.name;
this.playEndTime = data.playEndTime;
this.playStartTime = data.playStartTime;
this.publishStatus = data.publishStatus;
this.signUpEndTime = data.signUpEndTime;
this.signUpStartTime = data.signUpStartTime;
this.sponsor = data.sponsor;
this.undertaker = data.undertaker;
this.signupTime = [data.signUpStartTime, data.signUpEndTime];
this.playTime = [data.playStartTime, data.playEndTime];
this.sponsorList = data.sponsor.split(",");
this.undertakerList = data.undertaker.split(",");
})
.catch(err => {
});
},
commitId() {
this.$store.commit("setMatchId", { matchId: this.id });
},
handleExceed(files, fileList) {
util.warningMsg(`当前限制选择 1 个文件,如需更换,请删除上一个文件再重新选择!`);
},
uploadSuccess(res, file, fileList) {
if (this.coverUrl) {
let fileName = this.coverUrl.replace("https://liuwanr.oss-cn-shenzhen.aliyuncs.com/", "");
this.$del(`${this.api.fileDeletion}?keys=${fileName}`).then(res => {
}).catch(res => {
});
}
this.coverUrl = res.data.filesResult.fileUrl;
},
uploadLgSuccess(res, file, fileList) {
if (this.carouselUrl) {
let fileName = this.carouselUrl.replace("https://liuwanr.oss-cn-shenzhen.aliyuncs.com/", "");
this.$del(`${this.api.fileDeletion}?keys=${fileName}`).then(res => {
}).catch(res => {
});
}
this.carouselUrl = res.data.filesResult.fileUrl;
},
uploadError(err, file, fileList) {
this.$message({
message: "上传出错,请重试!",
type: "error",
center: true
});
},
beforeRemove(file, fileList) {
return this.$confirm(`确定移除 ${file.name}`);
},
handleRemove(file, fileList) {
let fileName = this.coverUrl.replace("https://liuwanr.oss-cn-shenzhen.aliyuncs.com/", "");
this.$del(`${this.api.fileDeletion}?keys=${fileName}`).then(res => {
this.coverUrl = "";
}).catch(res => {
});
},
handleLgRemove(file, fileList) {
let fileName = this.carouselUrl.replace("https://liuwanr.oss-cn-shenzhen.aliyuncs.com/", "");
this.$del(`${this.api.fileDeletion}?keys=${fileName}`).then(res => {
this.carouselUrl = "";
}).catch(res => {
});
},
uploadSure() {
this.BatchUpload = false;
this.pageNo = 1;
this.keyword = "";
this.getData();
},
goback() {
this.$confirm("确定返回?未更新的信息将不会保存。", "提示", {
type: "warning"
})
.then(() => {
this.$router.push("/match");
})
.catch(() => {
});
},
addSponsor() {
this.sponsorList.push("");
},
delSponsor(index) {
this.sponsorList.splice(index, 1);
},
addOrganizer() {
this.undertakerList.push("");
},
delOrganizer(index) {
this.undertakerList.splice(index, 1);
}
}
};
</script>
<style scoped lang="scss">
$upload-width: 220px;
$upload-height: 140px;
$upload-lg-height: 150px;
/deep/ .avatar-uploader {
.el-upload {
position: relative;
width: $upload-width;
height: $upload-height;
border: 1px dashed #d9d9d9;
border-radius: 6px;
cursor: pointer;
overflow: hidden;
&:hover {
border-color: #cb221c;
}
.uploader-default {
display: flex;
height: $upload-height;
flex-direction: column;
justify-content: center;
text-align: center;
background: rgba(0, 0, 0, 0.04);
i {
font-size: 20px;
font-weight: bold;
color: #8c939d;
}
p {
margin-top: 10px;
font-size: 14px;
color: rgba(0, 0, 0, 0.65);
line-height: 1;
}
}
}
&.avatar-uploader-lg {
.el-upload {
width: 100%;
max-width: 960px;
height: $upload-lg-height;
.uploader-default {
height: $upload-lg-height;
}
}
}
.avatar {
display: block;
width: $upload-width;
height: $upload-height;
}
.avatar-lg {
display: block;
width: 100%;
height: $upload-lg-height;
}
.el-upload__tip {
margin-top: 0;
p {
font-size: 14px;
color: rgba(0, 0, 0, 0.45);
line-height: 1;
&:first-child {
margin-bottom: 5px;
}
}
}
}
/deep/ .d-inline-block {
width: 216px;
.el-select, .el-input {
width: 100%;
}
}
.inline-input {
.input-wrap {
display: flex;
align-items: center;
margin-bottom: 10px;
.el-input {
display: inline-block;
width: 216px;
margin-right: 8px;
}
.remove {
width: 16px;
height: 16px;
background: url("../../../../assets/img/close.png") 0 0/cover no-repeat;
cursor: pointer;
}
}
.add-btn {
margin-left: 32px;
}
}
.add-btn {
display: flex;
justify-content: center;
align-items: center;
width: 216px;
line-height: 32px;
font-size: 14px;
color: rgba(0, 0, 0, 0.65);
background-color: transparent;
border: 1px dashed rgba(0, 0, 0, 0.15);
border-radius: 4px;
cursor: pointer;
i {
margin-right: 8px;
font-size: 14px;
font-weight: bold;
}
}
</style>

@ -414,7 +414,7 @@ $upload-lg-height: 150px;
.remove { .remove {
width: 16px; width: 16px;
height: 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; cursor: pointer;
} }
} }

@ -3,7 +3,6 @@
<el-card v-if="showBack" shadow="hover" class="m-b-20"> <el-card v-if="showBack" shadow="hover" class="m-b-20">
<el-page-header content="实验项目管理" @back="goBack"></el-page-header> <el-page-header content="实验项目管理" @back="goBack"></el-page-header>
</el-card> </el-card>
<div class="page"> <div class="page">
<h6 class="p-title">筛选</h6> <h6 class="p-title">筛选</h6>
<div class="tool mul"> <div class="tool mul">

@ -18,7 +18,7 @@
<div> <div>
<div class="flex-between m-b-20"> <div class="flex-between m-b-20">
<h6 class="p-title" style="margin-bottom: 0">学生组织架构</h6> <h6 class="p-title" style="margin-bottom: 0">学生组织架构</h6>
<el-button type="text" @click="handleAdd">添加</el-button> <el-button v-if="auth('学生组织架构添加')" type="text" @click="handleAdd">添加</el-button>
</div> </div>
<div style="height: 500px; max-height: 500px; overflow: auto"> <div style="height: 500px; max-height: 500px; overflow: auto">
@ -37,12 +37,13 @@
<span style="display: inline-block; margin-right: 20px">{{ node.label }}</span> <span style="display: inline-block; margin-right: 20px">{{ node.label }}</span>
<span> <span>
<el-button <el-button
v-if="auth('学生组织架构编辑')"
type="text" type="text"
icon="el-icon-edit-outline" icon="el-icon-edit-outline"
@click="() => handleEdit(node, data)"> @click="() => handleEdit(node, data)">
</el-button> </el-button>
<el-button <el-button
v-if="node.level < 3" v-if="auth('新增学生')&&node.level < 3"
type="text" type="text"
icon="el-icon-circle-plus-outline" icon="el-icon-circle-plus-outline"
@click="() => handleAdd(node, data)"> @click="() => handleAdd(node, data)">
@ -97,9 +98,9 @@
</li> </li>
</ul> </ul>
<div> <div>
<el-button type="primary" size="small" v-auth @click="addStudent">新增学生</el-button> <el-button type="primary" v-if="auth('新增学生')" size="small" v-auth @click="addStudent">新增学生</el-button>
<el-button type="primary" size="small" v-auth @click="batchImport">批量导入</el-button> <el-button type="primary" v-if="auth('批量导入')" size="small" v-auth @click="batchImport">批量导入</el-button>
<el-button type="primary" size="small" v-auth @click="delAllSelection">批量删除</el-button> <el-button type="primary" v-if="auth('批量删除')" size="small" v-auth @click="delAllSelection">批量删除</el-button>
</div> </div>
</div> </div>
@ -362,6 +363,7 @@ export default {
}, },
mounted() { mounted() {
this.getData(); this.getData();
this.auth()
}, },
watch: { watch: {
keyword: function(val) { keyword: function(val) {
@ -377,6 +379,7 @@ export default {
} }
}, },
methods: { methods: {
handleNodeClick(data) { // handleNodeClick(data) { //
if (data.level === 3) { if (data.level === 3) {
this.isRemove = true; this.isRemove = true;

@ -6,6 +6,7 @@ import {get} from "@/plugins/requests/index.js";
import api from "@/api"; import api from "@/api";
import util from "@/libs/util"; import util from "@/libs/util";
import { permission } from '@/router/permission'; import { permission } from '@/router/permission';
import BasicLayout from "@/layouts/home";
Vue.use(Router); Vue.use(Router);
@ -51,19 +52,26 @@ export default router;
]; ];
// 处理路由权限的方法 // 处理路由权限的方法
function getPermission(){ function getPermission(){
sessionStorage.setItem('handelPermission',true)// 记录已处理权限
get(api.getUserRolesPermissionMenu).then(res => { get(api.getUserRolesPermissionMenu).then(res => {
console.log(res,'权限的值')
// 取得路由的值,使用addRouter添加进路由里 // 取得路由的值,使用addRouter添加进路由里
// 该项目的路由实际上做了两层处理,一层指向了默认的路由,对应模块,用于基础布局的nav,下面一层才是实际上的路由跳转,
// 所以需要默认进行赋值,实际操作时根据path去禁用掉对应的nav即可。
const arr = ['achievement','assessment','course',"evaluation",'information','match','project','setting','student','system']
let permissionRouters = [] // 最后处理好的路由数组 let permissionRouters = [] // 最后处理好的路由数组
let data = res.permissionMenu[0].children let data = res.permissionMenu[0].children
if(data.length>0){ if(data.length>0){
data.forEach(e=>{ data.forEach(e=>{
// 第一级路由 // 第一级路由,需要根据匹配到的path,塞进对应的路由children里
let str = e.path.split('/')[1]
let index = arr.indexOf(str)
let obj = { let obj = {
path:e.path, path:e.path,
name:e.name, name:arr[index]+'-list',
component:`../pages${e.path}`, component:() => import(`@/pages${e.path}`),
meta:[], meta:{title:e.name,btn:[]},
children:[] children:[]
} }
let meta = [] let meta = []
@ -72,28 +80,73 @@ function getPermission(){
if(e.children&&e.children.length>0){ if(e.children&&e.children.length>0){
e.children.forEach(i=>{ 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 = { let obj = {
path:i.path, path:i.path,
name:i.name, name:arr[index]+'-'+i.path.split('/').pop(),
component:`../pages${i.path}`, component:() => import(`@/pages${i.path}`),
meta:[], meta:{title:i.name,btn:[]},
children:[] 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{ }else{
// 其他的是归属于当前页的按钮级信息,以此为依据来做按钮权限即可 // 其他的是归属于当前页的按钮级信息,以此为依据来做按钮权限即可
meta.push(i.name) meta.push(i.name)
} }
}) })
} }
obj.meta = meta obj.meta.btn = meta
obj.children = children obj.children = children
// 处理好的路由 // 处理好的路由,需要进行一次匹配,arr中必然存在对应的路由,所以在此处才生成第一级路由,免得额外判断是否有children
permissionRouters.push(obj) 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里 // 把处理完成的路由,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) router.addRoutes(errorPage)
} }
@ -101,11 +154,16 @@ function getPermission(){
} }
// 权限 // 权限
router.beforeEach(function(to,from,next){ router.beforeEach(function(to,from,next){
// console.log(router.app.$options.store.commit('routers'),'router.app.$options.store')
if(to.path == '/login'){ if(to.path == '/login'){
localStorage.removeItem(Setting.tokenKey) 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(util.local.get(Setting.tokenKey)){
if(!sessionStorage.getItem('handelPermission')){ if(!sessionStorage.getItem('handelPermission')){// 是否已处理权限
getPermission() getPermission()
} }
}else{ }else{
@ -115,6 +173,8 @@ router.beforeEach(function(to,from,next){
}) })
} }
} }
// 根据路由元信息设置文档标题
window.document.title = to.meta.title
next() next()
}) })

@ -1,14 +1,14 @@
// 引入模块化的路由 // // 引入模块化的路由
import assessment from "./modules/assessment"; // import assessment from "./modules/assessment";
import achievement from "./modules/achievement"; // import achievement from "./modules/achievement";
import evaluation from "./modules/evaluation"; // import evaluation from "./modules/evaluation";
import project from "./modules/project"; // import project from "./modules/project";
import student from "./modules/student"; // import student from "./modules/student";
import system from "./modules/system"; // import system from "./modules/system";
import setting from "./modules/setting"; // import setting from "./modules/setting";
import course from "./modules/course"; // import course from "./modules/course";
import match from "./modules/match"; // import match from "./modules/match";
import information from "./modules/information"; // import information from "./modules/information";
import BasicLayout from "@/layouts/home"; import BasicLayout from "@/layouts/home";
@ -29,16 +29,16 @@ const frameIn = [
children: [] children: []
}, },
// 以下为引入的路由,权限写好直接删掉 // 以下为引入的路由,权限写好直接删掉
assessment, // assessment,
achievement, // achievement,
evaluation, // evaluation,
project, // project,
student, // student,
system, // system,
setting, // setting,
course, // course,
match, // match,
information // information
]; ];
/** /**

@ -43,9 +43,9 @@ if (isHh) {
} else if (isDev) { } else if (isDev) {
jumpPath = "http://192.168.31.154:8087/"; jumpPath = "http://192.168.31.154:8087/";
// host = "http://39.108.250.202:9000/"; // 中台测试服 // 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.125:9000/"; // 坤
// host = 'http://192.168.31.137:9000/'; // 赓 host = 'http://192.168.31.137:9000/'; // 赓
title = "职站服务端管理系统"; title = "职站服务端管理系统";
schoolId = 2105; schoolId = 2105;
} else { } else {
@ -107,7 +107,7 @@ const Setting = {
// 相同路由,不同参数间进行切换,是否强力更新 // 相同路由,不同参数间进行切换,是否强力更新
sameRouteForceUpdate: false, sameRouteForceUpdate: false,
// 是否使用动态路由(即角色权限,开启了的话就会取后端返回的权限树来显示头部导肮和页面按钮) // 是否使用动态路由(即角色权限,开启了的话就会取后端返回的权限树来显示头部导肮和页面按钮)
dynamicRoute: false, dynamicRoute: true,
// 文件上传 // 文件上传
upload: { upload: {
apiURL: "http://39.108.250.202:9000/", apiURL: "http://39.108.250.202:9000/",

@ -18,6 +18,14 @@ const modules = modulesFiles.keys().reduce((modules, modulePath) => {
}, {}); }, {});
const store = new Vuex.Store({ const store = new Vuex.Store({
state:{
routers:[]
},
mutations:{
routers(s,v){
s.routers = v
}
},
modules, modules,
getters getters
}); });

Loading…
Cancel
Save