更改动态路由

lijinlong^2
杜函宇 1 year ago
parent a8bfa0faea
commit c8a96bd24f

@ -6,12 +6,12 @@
class="hamburger-container"
@toggleClick="toggleSideBar"
/>
<breadcrumb
<!-- <breadcrumb
id="breadcrumb-container"
class="breadcrumb-container"
v-if="!topNav"
/>
<top-nav id="topmenu-container" class="topmenu-container" v-if="topNav" />
/> -->
<!-- <top-nav id="topmenu-container" class="topmenu-container" v-if="topNav" /> -->
<div class="right-menu">
<!-- <template v-if="device !== 'mobile'">
@ -138,7 +138,7 @@ export default {
})
.then(() => {
this.$store.dispatch("LogOut").then(() => {
location.href = "/index";
location.href = "/demo/suzhouyingjiPC/";
});
})
.catch(() => {});

@ -1,45 +1,90 @@
<template>
<div class="sidebar-logo-container" :class="{'collapse':collapse}" :style="{ backgroundColor: sideTheme === 'theme-dark' ? variables.menuBackground : variables.menuLightBackground }">
<div
class="sidebar-logo-container"
:class="{ collapse: collapse }"
:style="{
backgroundColor:
sideTheme === 'theme-dark'
? variables.menuBackground
: variables.menuLightBackground,
}"
>
<transition name="sidebarLogoFade">
<router-link v-if="collapse" key="collapse" class="sidebar-logo-link" to="/">
<div
v-if="collapse"
key="collapse"
class="sidebar-logo-link"
@click="toNewPage"
style="cursor: pointer;"
>
<img v-if="logo" :src="logo" class="sidebar-logo" />
<h1 v-else class="sidebar-title" :style="{ color: sideTheme === 'theme-dark' ? variables.logoTitleColor : variables.logoLightTitleColor }">{{ title }} </h1>
</router-link>
<router-link v-else key="expand" class="sidebar-logo-link" to="/">
<h1
v-else
class="sidebar-title"
:style="{
color:
sideTheme === 'theme-dark'
? variables.logoTitleColor
: variables.logoLightTitleColor,
}"
>
{{ title }}
</h1>
</div>
<div v-else key="expand" class="sidebar-logo-link" @click="toNewPage" style="cursor: pointer;">
<img v-if="logo" :src="logo" class="sidebar-logo" />
<h1 class="sidebar-title" :style="{ color: sideTheme === 'theme-dark' ? variables.logoTitleColor : variables.logoLightTitleColor }">{{ title }} </h1>
</router-link>
<h1
class="sidebar-title"
:style="{
color:
sideTheme === 'theme-dark'
? variables.logoTitleColor
: variables.logoLightTitleColor,
}"
>
{{ title }}
</h1>
</div>
</transition>
</div>
</template>
<script>
import logoImg from '@/assets/images/logo.png'
import variables from '@/assets/styles/variables.scss'
import logoImg from "@/assets/images/logo.png";
import variables from "@/assets/styles/variables.scss";
import { mapState } from "vuex";
export default {
name: 'SidebarLogo',
name: "SidebarLogo",
props: {
collapse: {
type: Boolean,
required: true
}
required: true,
},
},
computed: {
variables() {
return variables;
},
sideTheme() {
return this.$store.state.settings.sideTheme
}
return this.$store.state.settings.sideTheme;
},
...mapState({
new1: (state) => state.user.new1,
}),
},
methods: {
toNewPage() {
this.$router.push({path:this.new1[0]})
},
},
data() {
return {
title: process.env.VUE_APP_TITLE,
logo: logoImg
}
}
}
logo: logoImg,
};
},
};
</script>
<style lang="scss" scoped>

@ -9,7 +9,7 @@
<div class="nav-text">执法计划管理系统</div>
</nav>
<div
v-for="(item, index) in myRouter"
v-for="(item, index) in newRouter"
:key="index"
@click="changePath(index, item)"
>
@ -49,7 +49,11 @@
<el-dropdown-item @click.native="logout">退出登录</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
<div class="showGLstyle" v-if="roles && roles[0]=='admin'" @click="toNewPage">
<div
class="showGLstyle"
v-if="roles && roles[0] == 'admin'"
@click="toNewPage"
>
进入管理平台
</div>
</header>
@ -61,56 +65,29 @@
</template>
<script>
import { mapState } from "vuex";
export default {
data() {
return {
routerIndex: 0,
avatarFlag: false,
myRouter: [
{
path: "/home",
name: "首页",
icon1: require("../assets/images/index1.png"),
icon2: require("../assets/images/index1-change.png"),
},
{
path: "/planManage",
name: "计划管理",
icon1: require("../assets/images/jihua.png"),
icon2: require("../assets/images/jihua-change.png"),
},
{
path: "/enforcing",
name: "执法结果",
icon1: require("../assets/images/zhifa.png"),
icon2: require("../assets/images/zhifa-change.png"),
},
{
path: "/enterprise",
name: "企业名录",
icon1: require("../assets/images/qiye.png"),
icon2: require("../assets/images/qiye-change.png"),
},
{
path: "/focusEnter",
name: "省重点企业",
icon1: require("../assets/images/qiye.png"),
icon2: require("../assets/images/qiye-change.png"),
},
],
};
},
computed: {
...mapState({
dept: (state) => state.user.dept,
username: (state) => state.user.name,
roles:(state) => state.user.roles,
roles: (state) => state.user.roles,
newRouter:(state) => state.user.newRouter,
new1:(state) => state.user.new1,
}),
},
created() {
},
watch: {
$route: {
handler(newRouter, oldRouter) {
this.routerIndex = newRouter.meta.index;
handler(n, o) {
this.routerIndex = this.new1.indexOf(n.path);
},
immediate: true,
},

@ -20,25 +20,35 @@ router.beforeEach((to, from, next) => {
NProgress.done()
} else {
if (store.getters.roles.length === 0) {
// console.log(router.options);
isRelogin.show = true
// 判断当前用户是否已拉取完user_info信息
store.dispatch('GetInfo').then(() => {
store.dispatch('GetInfo').then((res) => {
isRelogin.show = false
store.dispatch('GenerateRoutes').then(accessRoutes => {
console.log(accessRoutes);
// 根据roles权限生成可访问的路由表
console.log(res);
router.addRoutes(accessRoutes) // 动态添加可访问路由表
next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
//刷新之后,要去的路由肯定是自己已经保存过的新路由
let refresh = ''
if (store.state.user.new1.indexOf(to.path) != -1) {
refresh = to.path
}
console.log(to.path);
//进入添加的第一个路由
next({ path: refresh || res[0].path })
})
}).catch(err => {
store.dispatch('LogOut').then(() => {
Message.error(err)
next({ path: '/' })
})
store.dispatch('LogOut').then(() => {
Message.error(err)
next({ path: '/' })
})
})
} else {
next()
if (store.state.user.old1.indexOf(to.path) != -1 && store.state.user.new1.indexOf(to.path) == -1) {
next({ path: '/404' })
} else {
next()
}
}
}
} else {
@ -47,7 +57,7 @@ router.beforeEach((to, from, next) => {
// 在免登录白名单,直接进入
next()
} else {
next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
next(`/login`) // 否则全部重定向到登录页
NProgress.done()
}
}

@ -11,7 +11,7 @@ const permission = {
addRoutes: [],
defaultRoutes: [],
topbarRouters: [],
sidebarRouters: []
sidebarRouters: [],
},
mutations: {
SET_ROUTES: (state, routes) => {
@ -45,7 +45,7 @@ const permission = {
commit('SET_SIDEBAR_ROUTERS', constantRoutes.concat(sidebarRoutes))
commit('SET_DEFAULT_ROUTES', sidebarRoutes)
commit('SET_TOPBAR_ROUTES', sidebarRoutes)
resolve(rewriteRoutes)
resolve(rewriteRoutes,1)
})
})
}
@ -59,6 +59,7 @@ function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) {
route.children = filterChildren(route.children)
}
if (route.component) {
// Layout ParentView 组件特殊处理
if (route.component === 'Layout') {
route.component = Layout

@ -9,10 +9,27 @@ const user = {
roles: [],
permissions: [],
//存储用户id
dept: null
dept: null,
//存储路由
oldRouter: [],
newRouter: [],
old1: [],
new1: []
},
mutations: {
setOld: (state, route) => {
state.old1 = route
},
setNew: (state, route) => {
state.new1 = route
},
getOldRouter: (state, route) => {
state.oldRouter = route
},
getNewRouter: (state, route) => {
state.newRouter = route
},
get_dept: (state, id) => {
state.dept = id;
},
@ -89,9 +106,73 @@ const user = {
} else {
commit("SET_ROLES", ["ROLE_DEFAULT"]);
}
let arr1 = [
{
path: "/home",
name: "首页",
icon1: require("../../assets/images/index1.png"),
icon2: require("../../assets/images/index1-change.png"),
},
{
path: "/planManage",
name: "计划管理",
icon1: require("../../assets/images/jihua.png"),
icon2: require("../../assets/images/jihua-change.png"),
},
{
path: "/enforcing",
name: "执法结果",
icon1: require("../../assets/images/zhifa.png"),
icon2: require("../../assets/images/zhifa-change.png"),
},
{
path: "/enterprise",
name: "企业名录",
icon1: require("../../assets/images/qiye.png"),
icon2: require("../../assets/images/qiye-change.png"),
},
{
path: "/focusEnter",
name: "省重点企业",
icon1: require("../../assets/images/qiye.png"),
icon2: require("../../assets/images/qiye-change.png"),
},
]
let arr2 = []
let A1 = []
let A2 = []
let toRouter = ''
commit("getOldRouter", arr1)
arr1.forEach((value) => {
A1.push(value.path)
})
commit("setOld", A1)
if (res.roles.indexOf('admin') != -1) {
commit("getNewRouter", arr1)
commit("setNew", A1)
toRouter = arr1
} else {
//区级和镇级
if (user.dept.parentId == 100 || user.dept.parentId == 101) {
arr2 = arr1.filter((value) => {
return value.path == "/planManage";
});
arr2.forEach((value) => {
A2.push(value.path)
})
commit("getNewRouter", arr2)
commit("setNew", A2)
toRouter = arr2
} else {
commit("getNewRouter", arr1)
commit("setNew", A1)
toRouter = arr1
}
}
commit("SET_NAME", user.userName);
commit("SET_AVATAR", avatar);
resolve(res);
resolve(toRouter);
})
.catch((error) => {
reject(error);

@ -177,7 +177,7 @@ export default {
this.$store
.dispatch("Login", this.loginForm)
.then(() => {
this.$router.push({ path: this.redirect || "/" }).catch(() => {});
this.$router.push({ path: "/" });
})
.catch(() => {
this.loading = false;

@ -27,12 +27,8 @@
size="small"
v-model="form.district"
:options="compartment"
:show-all-levels="false"
:props="{
value: 'subdistrict', //id
label: 'institutionName', //name
children: 'children',
}"
:disabled="isNoneDivision"
:props="props"
></el-cascader>
</div>
<div class="my-checkbox">
@ -47,7 +43,11 @@
<div class="export" @click="searchList" style="margin-right: 10px">
<span>搜索</span>
</div>
<div class="export" @click="chongzhiList" style="margin-right: 10px;background-color: #FDAB5B;">
<div
class="export"
@click="chongzhiList"
style="margin-right: 10px; background-color: #fdab5b"
>
<span>重置</span>
</div>
<div class="export" @click="exportFile">
@ -99,7 +99,11 @@
<el-table-column label="操作" header-align="center">
<template slot-scope="scope">
<div class="tabs-btns">
<div class="look" @click="look(scope.row)">
<div
class="look"
v-if="scope.row.checkStatus == 1"
@click="look(scope.row)"
>
<span>查看执法详情</span>
</div>
</div>
@ -159,6 +163,7 @@ import {
enforcingDetail,
xzTree,
} from "@/api/yingji/keyEnterprise.js";
import { mapState } from "vuex";
export default {
components: { myPagination },
name: "Article",
@ -168,6 +173,7 @@ export default {
loads: true,
total: 0,
options: [],
props: {},
//
form: {
district: [],
@ -303,20 +309,29 @@ export default {
addShow: false,
detailLoad: true,
compartment: [],
//
isNoneDivision: false,
newQHList: [],
};
},
created() {
this.getList();
this.xzList();
// console.log(this.dept);
console.log(this.form.district);
},
computed: {
...mapState({
//dept.parentId
dept: (state) => state.user.dept,
}),
},
methods: {
//
reset() {
this.form = {
district: [],
plannedYear: "",
//
checkStatus: "",
};
this.form.plannedYear = "";
this.form.checkStatus = "";
this.searchBefore = {
pageSize: 10,
pageNum: 1,
@ -333,10 +348,43 @@ export default {
console.log(res);
this.compartment = res.data;
this.filterComparment(this.compartment);
//
if (this.dept.parentId == 0) {
this.isNoneDivision = false;
}
//
if (this.dept.parentId == 100) {
this.props = {
checkStrictly: true,
value: "county", //id
label: "institutionName", //name
children: "children",
};
let arr1 = this.newQHList.filter((value) => {
return value.institutionName == this.dept.deptName;
});
this.form.district.push(arr1[0].county);
this.isNoneDivision = true;
}
//
if (this.dept.parentId == 101) {
this.props = {
checkStrictly: true,
value: "subdistrict", //id
label: "institutionName", //name
children: "children",
};
let arr1 = this.newQHList.filter((value) => {
return value.institutionName == this.dept.deptName;
});
this.form.district.push(null, arr1[0].subdistrict);
this.isNoneDivision = true;
}
});
},
filterComparment(e) {
e.forEach((value, index) => {
this.newQHList.push(value);
if (value.children.length >= 1) {
this.filterComparment(value.children);
} else {
@ -368,6 +416,7 @@ export default {
);
},
searchList() {
console.log(this.form.district);
this.form.district = this.form.district[this.form.district.length - 1];
this.searchBefore = { ...this.searchBefore, ...this.form };
this.getList();

@ -141,7 +141,7 @@
header-align="center"
>
</el-table-column>
<el-table-column prop="isPoint" label="是否重点" header-align="center">
<!-- <el-table-column prop="isPoint" label="是否重点" header-align="center">
<template slot-scope="scope">
<div
style="font-family: 'Alibaba PuHuiTi'"
@ -151,7 +151,7 @@
<span v-if="scope.row.isPoint == '0'"></span>
</div>
</template>
</el-table-column>
</el-table-column> -->
<el-table-column label="操作" header-align="center">
<template slot-scope="scope">
<div class="tabs-btns">

Loading…
Cancel
Save