c3afa824 by xiaomiao

路由前置守卫修改

1 parent 01fc196e
......@@ -8,10 +8,21 @@ export function getUserInfo () {
})
}
// // 获取菜单信息
// export function getMenuInfo () {
// return request({
// url: SERVER.SERVERAPI + '/rest/user/getUserAuthorizationMenus',
// method: 'get',
// })
// }
// 获取菜单信息
export function getMenuInfo () {
export function getMenuInfo (data) {
return request({
url: SERVER.SERVERAPI + '/rest/user/getUserAuthorizationMenus',
method: 'get',
params: {
productCode: data,
},
})
}
......
......@@ -16,26 +16,26 @@
<sidebarRight />
</div>
</div>
</div>
</div>
</template>
<script>
import sidebarLeft from "./Sidebar/sidebarLeft";
import sidebarRight from "./Sidebar/sidebarRight";
import { logout } from "@/api/login.js";
import { mapGetters } from "vuex";
export default {
import sidebarLeft from "./Sidebar/sidebarLeft";
import sidebarRight from "./Sidebar/sidebarRight";
import { logout } from "@/api/login.js";
import { mapGetters } from "vuex";
export default {
components: {
sidebarLeft,
sidebarRight,
},
computed: {
...mapGetters(["sidebar", "dicData","userInfo"]),
logoName() {
...mapGetters(["sidebar", "dicData", "userInfo"]),
logoName () {
return this.dicData['sysCode'] && this.dicData['sysCode'].filter(item =>
item.DCODE == "systemTitle"
)
},
userName(){
userName () {
return this.userInfo ? this.userInfo.name : ""
}
},
......@@ -46,7 +46,7 @@ export default {
sessionStorage.removeItem("token");
this.$store.dispatch("user/resetState");
this.$router.replace({
path: "/login/jg",
path: "/jg",
query: {
redirect: this.$route.fullPath,
},
......@@ -57,15 +57,15 @@ export default {
});
},
},
};
};
</script>
<style lang="scss" scoped>
/deep/.el-menu--horizontal {
/deep/.el-menu--horizontal {
display: flex;
align-items: center;
}
}
.menubg {
.menubg {
height: 34px;
width: 130px;
text-align: center;
......@@ -73,73 +73,73 @@ export default {
margin-right: 20px;
background: url("~@/image/navbar.png") no-repeat;
background-size: 100% 100%;
}
}
/deep/.el-menu-item {
/deep/.el-menu-item {
@extend .menubg;
}
}
/deep/.el-submenu {
/deep/.el-submenu {
@extend .menubg;
}
}
/deep/.el-submenu__title {
/deep/.el-submenu__title {
height: 34px;
color: #ffffff;
}
}
/deep/.el-submenu__title span {
/deep/.el-submenu__title span {
font-size: 14px;
}
}
.sidebarLeft {
.sidebarLeft {
position: relative;
top: 13px;
width: 30%;
}
}
/deep/.el-menu {
/deep/.el-menu {
display: flex;
justify-content: space-between;
}
}
/deep/.el-menu-item {
/deep/.el-menu-item {
flex: 1;
width: 100%;
}
}
.sidebarRight {
.sidebarRight {
position: relative;
top: 13px;
width: 30%;
padding-left: 20px;
}
}
// 导航选中背景色
.xuanzhong {
// 导航选中背景色
.xuanzhong {
background: url("~@/image/selNavbar.png") no-repeat;
background-size: 100% 100%;
color: #ffffff !important;
font-weight: 700;
}
}
/deep/.el-menu-item:hover {
/deep/.el-menu-item:hover {
@extend .xuanzhong;
}
}
/deep/.el-submenu__title:hover {
/deep/.el-submenu__title:hover {
@extend .xuanzhong;
}
}
/deep/.el-menu--horizontal .el-menu-item:not(.is-disabled):focus {
/deep/.el-menu--horizontal .el-menu-item:not(.is-disabled):focus {
@extend .xuanzhong;
}
}
/deep/.el-menu-item.is-active {
/deep/.el-menu-item.is-active {
@extend .xuanzhong;
}
}
.navbar {
.navbar {
height: $headerHeight;
overflow: hidden;
position: relative;
......@@ -258,5 +258,5 @@ export default {
}
}
}
}
}
</style>
......
/*
* @Description:
* @Autor: renchao
* @LastEditTime: 2023-03-09 21:06:38
*/
import router from "./router";
import store from "./store";
import { getMenuInfo } from "@/api/user";
import NProgress from "nprogress"; // progress bar
import "nprogress/nprogress.css"; // progress bar style
import getPageTitle from "@/utils/get-page-title";
import Cookies from "js-cookie";
NProgress.configure({ showSpinner: false }); // NProgress Configuration
router.beforeEach(async (to, from, next) => {
NProgress.start();
document.title = getPageTitle(to.meta.title);
let hasAddDict = store.state.dict.addDict;
let hasUser = store.state.user.hasUser;
let hasAddRoute = store.state.permission.addRoutes;
if (to.path == "/sb" || to.path == "/jg") {
sessionStorage.removeItem("token");
sessionStorage.setItem("psth", to.path)
next();
} else {
let code = sessionStorage.getItem("psth") == "/sb" ? "BDCSBPT" : "BDCJGPT"
//判断token是否存在
const hasToken = sessionStorage.getItem("token");
if (hasToken) {
//请求用户信息
if (!hasUser) {
store.dispatch("user/getUserInfo");
import("@/styles/public.scss");
}
if (hasAddRoute) {
next();
} else {
//请求菜单
const { result: getMenuData } = (await getMenuInfo(code)) || [];
const accessRoutes = await store.dispatch(
"permission/generateRoutes",
getMenuData
);
router.addRoutes([
...accessRoutes,
{ path: "*", redirect: "/404", hidden: true },
]);
const routeTo = Cookies.get("routerTo");
if (!hasAddDict) {
await store.dispatch("dict/generateDic");
}
if (routeTo && routeTo !== "/") {
next({ ...to, replace: true });
} else {
next("/home");
}
}
} else {
next(sessionStorage.getItem("psth"));
}
}
NProgress.done();
});
router.afterEach((to) => {
// 解决刷新页面报404问题
Cookies.set("routerTo", to.fullPath);
NProgress.done();
});
/*
* @Description:
* @Autor: renchao
* @LastEditTime: 2023-03-07 09:43:25
* @LastEditTime: 2023-03-09 21:06:38
*/
import router from "./router";
import store from "./store";
......@@ -18,50 +18,12 @@ router.beforeEach(async (to, from, next) => {
let hasAddDict = store.state.dict.addDict;
let hasUser = store.state.user.hasUser;
let hasAddRoute = store.state.permission.addRoutes;
if (to.path == "/login/sb") {
if (to.path == "/sb" || to.path == "/jg") {
sessionStorage.removeItem("token");
next();
} else if (to.path !== "/login/jg") {
//判断token是否存在
const hasToken = sessionStorage.getItem("token");
if (hasToken) {
//请求用户信息
if (!hasUser) {
store.dispatch("user/getUserInfo");
}
if (hasAddRoute) {
sessionStorage.setItem("psth", to.path)
next();
} else {
//请求菜单
const { result: getMenuData } = (await getMenuInfo()) || [];
const accessRoutes = await store.dispatch(
"permission/generateRoutes",
getMenuData
);
router.addRoutes([
...accessRoutes,
{ path: "*", redirect: "/404", hidden: true },
]);
const routeTo = Cookies.get("routerTo");
if (!hasAddDict) {
await store.dispatch("dict/generateDic");
}
if (routeTo && routeTo !== "/") {
next({ ...to, replace: true });
} else {
alert("上报")
next("/home");
}
}
} else {
next("/login/sb");
}
}
if (to.path == "/login/jg") {
sessionStorage.removeItem("token");
next();
} else if (to.path !== "/login/sb") {
let code = sessionStorage.getItem("psth") == "/sb" ? "BDCSBPT" : "BDCJGPT"
//判断token是否存在
const hasToken = sessionStorage.getItem("token");
if (hasToken) {
......@@ -74,7 +36,7 @@ router.beforeEach(async (to, from, next) => {
next();
} else {
//请求菜单
const { result: getMenuData } = (await getMenuInfo()) || [];
const { result: getMenuData } = (await getMenuInfo(code)) || [];
const accessRoutes = await store.dispatch(
"permission/generateRoutes",
getMenuData
......@@ -90,14 +52,16 @@ router.beforeEach(async (to, from, next) => {
if (routeTo && routeTo !== "/") {
next({ ...to, replace: true });
} else {
alert("监管")
next("/home");
}
}
} else if (sessionStorage.getItem("psth")) {
next(sessionStorage.getItem("psth"));
} else {
next("/login/jg");
next("/jg");
}
}
NProgress.done();
});
router.afterEach((to) => {
......
......@@ -24,12 +24,12 @@ export const constantRoutes = [
},
//登录
{
path: "/login/jg",
path: "/jg",
name: "loginjg",
component: () => import("@/views/loginjg/index.vue"),
},
{
path: "/login/sb",
path: "/sb",
name: "loginsb",
component: () => import("@/views/loginsb/index.vue"),
},
......
<template>
<div class="bg">
<div class="login-inner-bg login">
<h2>{{ productName }}</h2>
<div class="user_style">
<h3>欢迎登录</h3>
<el-form :model="user" :rules="rules" ref="user" id="loginform" class="demo-ruleForm">
<el-form-item prop="account">
<el-input class="username" v-model="user.account" placeholder="请输入用户名"></el-input>
</el-form-item>
<el-form-item prop="password">
<el-input type="password" class="password" @keyup.enter.native="login('user')" v-model="user.password"
placeholder="请输入密码"></el-input>
</el-form-item>
<el-form-item class="login-btn">
<el-button type="primary" style="width: 100%" @click="login('user')">登录</el-button>
</el-form-item>
</el-form>
</div>
</div>
</div>
</template>
<script>
import { loginIn } from "@/api/login.js";
import { api, getAction } from "@/api/manageApi";
export default {
name: "Login",
data () {
return {
user: {
account: "",
password: "",
checkStatus: false,
},
productName: "",
rules: {
account: [{ required: true, message: "请填写帐号", trigger: "blur" }],
password: [{ required: true, message: "请填写密码", trigger: "blur" }],
},
};
},
created () {
const params = {};
const queryOptions = {
conditionGroup: {
conditions: [
{
property: "code",
value: "BDCJGPT",
operator: "EQ",
},
],
queryRelation: "AND",
},
};
params.queryOptions = JSON.stringify(queryOptions);
//根据子系统code获取子系统详细信息
getAction(api.subsystem, params).then((res) => {
if (res.status === 1) {
this.productName = res.content[0].name;
this.$store.dispatch("products/setData", res.content[0]);
} else {
this.$message.error({ message: res.message, showClose: true });
}
});
},
mounted () {
// this.checkUserName();
},
methods: {
//记住用户名
checkUserName: function (flag) {
this.user.checkStatus = flag;
if (this.user.checkStatus) {
localStorage.setItem("accountId", this.user.account);
let name = localStorage.getItem("accountId");
if (name === "") {
return;
} else {
this.user.account = name;
}
} else {
this.user.account = localStorage.getItem("accountId");
}
},
login (user) {
var self = this;
this.$refs[user].validate((valid) => {
if (valid) {
loginIn(self.user.account, self.user.password)
.then((res) => {
if (res.status === 1) {
//存储token
sessionStorage.setItem("token", `Bearer ${res.content}`);
//登录成功后需判断有无重定向,没有重定向则跳转首页
this.$router.replace(this.$route.query.redirect || "/");
} else {
//错误处理
}
})
.catch((error) => {
// console.dir(error);
});
}
});
},
},
components: {},
};
</script>
<style scoped lang="scss">
.username,
.password {
position: relative;
&:before {
content: "";
display: block;
width: 16px;
height: 16px;
position: absolute;
left: 10px;
top: 7px;
background-size: 100% 100%;
}
/deep/ .el-input__inner {
text-indent: 24px;
border: 1px solid rgba(11, 161, 248, 0.4);
background-color: rgba(6, 135, 205, 0.3) !important;
}
}
.username::before {
background-image: url(../../image/username.png);
}
.password::before {
background-image: url(../../image/password.png);
}
.bg {
width: 100%;
height: 100%;
min-width: 1440px;
min-height: 560px;
background: url(../../image/loginBoxBg.png) no-repeat;
background-size: 100% 100%;
overflow: hidden;
position: relative;
}
.login-inner-bg {
background: url(../../image/loginBg.png) no-repeat;
width: 21.6%;
height: 43%;
min-width: 360px;
min-height: 380px;
top: 30%;
right: 20%;
position: absolute;
background-size: 100% 100%;
box-sizing: border-box;
padding: 56px;
h2 {
width: 100%;
font-size: 36px;
font-weight: 700;
color: #fff;
text-align: center;
white-space: nowrap;
position: absolute;
right: 0;
top: -70px;
background-image: linear-gradient(180deg,
rgba(99, 163, 255, 1) 0,
rgba(99, 163, 255, 1) 0,
rgba(182, 220, 255, 1) 49.731445%,
rgba(114, 190, 255, 1) 100%,
rgba(114, 190, 255, 1) 100%);
overflow-wrap: break-word;
color: rgba(255, 255, 255, 1);
font-size: 36px;
font-family: AlimamaShuHeiTi-Bold;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
}
.login {
.user_style {
h3 {
color: #fff;
font-size: 22px;
font-weight: normal;
text-align: center;
margin: 16px auto 34px;
font-weight: 400;
}
}
.btn {
width: 100%;
height: 6vh;
background-color: #00c2de;
border-radius: 5px;
font-size: 1.4vw;
color: #ffffff;
}
.btn:hover {
cursor: pointer;
background-color: #2d8cf0;
}
}
.login #loginform {
.el-form-item {
margin-bottom: 24px !important;
}
.login-btn {
margin-top: 40px !important;
}
.el-button {
font-size: 18px;
background: #0d8cc0 !important;
color: #ffffff !important;
cursor: pointer !important;
}
.el-input__inner {
width: 100% !important;
}
.el-checkbox__label {
color: #fff;
}
}
.inputUser .ivu-input {
padding: 6px 24px !important;
border: 1px solid #9f9f9f !important;
}
</style>
......@@ -60,7 +60,7 @@
getAction(api.subsystem, params).then((res) => {
if (res.status === 1) {
this.productName = res.content[0].name;
this.$store.dispatch("products/setData", res.content[0]);
this.$store.dispatch("products/setData", res.content[0].code);
} else {
this.$message.error({ message: res.message, showClose: true });
}
......
......@@ -67,7 +67,7 @@
getAction(api.subsystem, params).then((res) => {
if (res.status === 1) {
this.productName = res.content[0].name;
this.$store.dispatch("products/setData", res.content[0]);
this.$store.dispatch("products/setData", res.content[0].code);
} else {
this.$message.error({ message: res.message, showClose: true });
}
......
......@@ -77,14 +77,14 @@
userInfo: {
handler: function (val) {
if (val) {
this.getUserInfo(val.id)
this.getUserdata(val.id)
}
}
}
},
mounted () {
if (this.userInfo) {
this.getUserInfo(this.userInfo)
this.getUserdata(this.userInfo)
}
this.sexList = [
{
......@@ -105,7 +105,7 @@
]
},
methods: {
getUserInfo (p) {
getUserdata (p) {
getAction(`${api.users}/${p.id}`).then((res) => {
if (res.status === 1) {
this.form = res.content
......@@ -120,7 +120,7 @@
putAction(`${api.users}/${this.form.id}`, this.form).then((res) => {
if (res.status === 1) {
this.$message.success({ message: res.message, showClose: true })
this.getUserInfo(this.form.id)
this.getUserdata(this.form.id)
} else {
this.$message.error({ message: res.message, showClose: true })
}
......
......@@ -64,13 +64,13 @@
</template>
<script>
import Dialog from "@/components/Dialog/";
import { getParentMenuListAction } from '@/api/authorityManage'
import JsonEditor from '@/components/JsonEditors'
import IconList from '@/components/IconList'
import { validateCode } from '@/utils/validate';
import { api, httpAction } from '@/api/manageApi'
export default {
import Dialog from "@/components/Dialog/";
import { getParentMenuListAction } from '@/api/authorityManage'
import JsonEditor from '@/components/JsonEditors'
import IconList from '@/components/IconList'
import { validateCode } from '@/utils/validate';
import { api, httpAction } from '@/api/manageApi'
export default {
name: 'MenuModal',
components: {
IconList,
......@@ -197,6 +197,7 @@ export default {
method = 'put'
url = `${this.dataUrl}/${formData.id}`
}
debugger
httpAction(url, formData, method)
.then((res) => {
if (res.status === 1) {
......@@ -229,8 +230,8 @@ export default {
this.visible = false
}
}
}
}
</script>
<style scoped lang="scss">
// @import "~@/styles/public.scss";
// @import "~@/styles/public.scss";
</style>
......
......@@ -23,12 +23,13 @@
</div>
</template>
<script>
// 定时任务
import data from "./data";
import { deleteAction, getAction, api } from "@/api/manageApi";
import EditDialog from "./edit-dialog.vue";
// import authorizationdiglog from "./authorizationdiglog.vue";
export default {
// 定时任务
import data from "./data";
import { deleteAction, getAction, api } from "@/api/manageApi";
import EditDialog from "./edit-dialog.vue";
import { mapGetters } from "vuex";
// import authorizationdiglog from "./authorizationdiglog.vue";
export default {
name: "menus",
components: {
EditDialog,
......@@ -104,6 +105,9 @@ export default {
created () {
this.getTableList();
},
computed: {
...mapGetters(["products"]),
},
methods: {
// 加载表格数据
getTableList () {
......@@ -114,7 +118,7 @@ export default {
conditions: [
{
property: "code",
value: "BDCJGPT",
value: this.products,
operator: "EQ",
},
],
......@@ -223,17 +227,17 @@ export default {
this.getTableList()
},
},
};
};
</script>
<style scoped lang="scss">
@import "~@/styles/mixin.scss";
@import "~@/styles/mixin.scss";
// @import "~@/styles/public.scss";
.btnColRight {
// @import "~@/styles/public.scss";
.btnColRight {
margin-top: 20px;
}
}
/deep/.el-table__expand-icon {
/deep/.el-table__expand-icon {
color: #fff;
}
}
</style>
......
......@@ -11,11 +11,6 @@ class data extends filter {
width: 130
},
{
prop: "type",
label: "类别",
width: 200
},
{
prop: "description",
label: "备注"
}
......
......@@ -18,16 +18,6 @@
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="24">
<el-col :span="24">
<el-form-item label="角色类型:" prop="roleType">
<el-input
v-model="dialogForm.roleType"
clearable
placeholder="角色类型" />
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="24">
<el-form-item label="备注:" class="form-item-mb0">
......@@ -75,9 +65,6 @@
roleName: [
{ required: true, message: '请输入角色名称', trigger: 'blur' }
],
roleType: [
{ required: true, message: '请输入角色类型', trigger: 'blur' }
]
},
roleTypeOptions: [
{ name: '定制', value: '定制' },
......@@ -109,7 +96,6 @@
})
this.dialogForm = {
roleName: '',
roleType: ''
}
this.showAddEditDialog = val
this.$emit('ok', this.menuType)
......@@ -130,7 +116,6 @@
})
this.dialogForm = {
roleName: '',
roleType: ''
}
this.showAddEditDialog = val
this.$emit('ok', this.menuType)
......@@ -153,7 +138,6 @@
this.$refs.form.resetFields()
this.dialogForm = {
roleName: '',
roleType: ''
}
this.showAddEditDialog = false
}
......
......@@ -22,21 +22,22 @@
</div>
</template>
<script>
import {
import {
getUuid,
judgeSort,
realMove,
findParents,
removeTreeListItem,
} from "@/utils/operation";
import { getRolesById, getAuthorityListAction } from "@/api/authorityManage";
import { getUserRoles } from "@/api/personnelManage";
import data from "./data";
import { api, getAction, deleteAction } from "@/api/manageApi";
import tableMixin from "@/mixins/tableMixin.js";
import EditDialog from "./edit-dialog.vue";
import Roleslistdiglog from "./roleslistdiglog.vue";
export default {
} from "@/utils/operation";
import { getRolesById, getAuthorityListAction } from "@/api/authorityManage";
import { getUserRoles } from "@/api/personnelManage";
import data from "./data";
import { api, getAction, deleteAction } from "@/api/manageApi";
import tableMixin from "@/mixins/tableMixin.js";
import EditDialog from "./edit-dialog.vue";
import Roleslistdiglog from "./roleslistdiglog.vue";
import { mapGetters } from "vuex";
export default {
name: "menus",
mixins: [tableMixin],
components: {
......@@ -49,7 +50,7 @@ export default {
waitMemberList: [],
keyList: [],
listdata: [],
tableUrl: api.roles,
tableUrlroles: api.roles,
form: {
job_name: "",
currentPage: 1,
......@@ -212,7 +213,9 @@ export default {
data: [],
}
},
computed: {
...mapGetters(["products"]),
},
created () {
this.getTableData();
this.getTableList()
......@@ -229,7 +232,6 @@ export default {
Builtinrole = res.content;
getRolesById(2)
.then((res) => {
console.log("角色列表", res);
Publicrole = res.content;
this.listdata = Builtinrole.concat(Publicrole);
......@@ -249,7 +251,7 @@ export default {
conditions: [
{
property: "code",
value: "BDCJGPT",
value: this.products,
operator: "EQ",
},
],
......@@ -378,9 +380,10 @@ export default {
this.$refs.addEditDialog.menuType = this.menuType;
this.$refs.addEditDialog.roleId = value.id;
this.roleSort = value.sort ? value.sort : 0;
this.$refs.addEditDialog.dialogForm.roleType = this.products;
if (value.id) {
this.$refs.addEditDialog.dialogForm.roleName = value.name;
this.$refs.addEditDialog.dialogForm.roleType = value.type;
this.$refs.addEditDialog.dialogForm.roleTextArea = value.description;
}
this.$refs.addEditDialog.showAddEditDialog = true;
......@@ -421,14 +424,14 @@ export default {
}
)
.then(() => {
if (!this.tableUrl) {
if (!this.tableUrlroles) {
this.$message.error({
message: "请设置tableUrl属性为接口地址!",
showClose: true,
});
return;
}
const url = this.tableUrl + "/" + id;
const url = this.tableUrlroles + "/" + id;
deleteAction(url).then((res) => {
if (res.status === 1) {
this.$message.success({ message: res.message, showClose: true });
......@@ -445,14 +448,14 @@ export default {
this.getTableData();
},
},
};
};
</script>
<style scoped lang="scss">
@import "~@/styles/mixin.scss";
@import "~@/styles/mixin.scss";
// @import "~@/styles/public.scss";
.btnColRight {
// @import "~@/styles/public.scss";
.btnColRight {
margin-left: -30px;
margin-top: 20px;
}
}
</style>
......