Browse Source

统一拦截提示

test
liwei 3 years ago
parent
commit
f3a033c43c
5 changed files with 152 additions and 144 deletions
  1. +131
    -130
      src/components/Header.vue
  2. +10
    -3
      src/components/NavMenu.vue
  3. +6
    -6
      src/router/routers.js
  4. +4
    -0
      src/server/request.js
  5. +1
    -5
      src/views/login.vue

+ 131
- 130
src/components/Header.vue View File

@ -1,130 +1,131 @@
<template>
<div id="title-wrap">
<img :src="logo" />
<p>{{ title }}</p>
<el-dropdown>
<el-avatar shape="square" :size="32" fit="contain" :src="userLogo" />
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item @click="logOut">退出登录</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
<!-- <el-badge is-dot class="item">
<el-button
class="share-button"
icon="el-icon-message-solid"
type="primary"
></el-button>
</el-badge> -->
<!-- <el-button
class="question-button"
icon="el-icon-question"
type="primary"
></el-button> -->
</div>
</template>
<script>
export default {
name: "HelloWorld",
data() {
return {
logo: process.env["VUE_APP_LOGO"]
? require(process.env["VUE_APP_LOGO"])
: require("../assets/img/logo.png"),
title: process.env["VUE_APP_TITLE"]
? process.env["VUE_APP_TITLE"]
: "沈阳领新智科智能信息系统有限公司",
userLogo: require("../assets/img/logo.png"),
};
},
methods: {
// 退
logOut() {
this.$confirm("确定注销并退出系统吗?", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
}).then(() => {
localStorage.token = "";
this.$router.push({ path: "/login" });
});
},
},
};
</script>
<style lang="less">
#title-wrap {
.item {
.el-button--primary {
.el-icon-message-solid::before {
font-size: 22px;
}
}
sup {
background: #ce2b2b;
top: 13px;
right: 9px;
border: none;
}
}
.question-button {
.el-icon-question::before {
font-size: 22px;
}
}
.el-dropdown {
float: right;
margin-top: 8px;
margin-right: 24px;
}
}
</style>
<style scoped lang="less">
#title-wrap {
img {
float: left;
width: 25px;
height: 25px;
margin-top: 10px;
margin-left: 53px;
}
p {
float: left;
margin-left: 12px;
font-size: 16px;
font-family: PingFangSC-Semibold, PingFang SC;
font-weight: 600;
color: #ffffff;
line-height: 48px;
text-shadow: 0px -1px 0px #215c85;
}
.item {
float: right;
height: 30px;
margin-top: 4px;
margin-right: 30px;
.el-button--primary {
border: none;
background: none;
padding: 0;
}
}
.question-button {
float: right;
border: none;
background: none;
padding-right: 22px;
color: #fff;
box-shadow: none;
}
.share-button {
color: #fff;
box-shadow: none;
}
}
</style>
<template>
<div id="title-wrap">
<img :src="logo" />
<p>{{ title }}</p>
<el-dropdown>
<el-avatar shape="square" :size="32" fit="contain" :src="userLogo" />
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item @click="logOut">退出登录</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
<!-- <el-badge is-dot class="item">
<el-button
class="share-button"
icon="el-icon-message-solid"
type="primary"
></el-button>
</el-badge> -->
<!-- <el-button
class="question-button"
icon="el-icon-question"
type="primary"
></el-button> -->
</div>
</template>
<script>
export default {
name: "HelloWorld",
data() {
return {
logo: process.env["VUE_APP_LOGO"]
? require(process.env["VUE_APP_LOGO"])
: require("../assets/img/logo.png"),
title: process.env["VUE_APP_TITLE"]
? process.env["VUE_APP_TITLE"]
: "沈阳领新智科智能信息系统有限公司",
userLogo: require("../assets/img/logo.png"),
};
},
methods: {
// 退
logOut() {
this.$confirm("确定注销并退出系统吗?", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
}).then(() => {
localStorage.token = "";
localStorage.router = "";
this.$router.push({ path: "/login" });
});
},
},
};
</script>
<style lang="less">
#title-wrap {
.item {
.el-button--primary {
.el-icon-message-solid::before {
font-size: 22px;
}
}
sup {
background: #ce2b2b;
top: 13px;
right: 9px;
border: none;
}
}
.question-button {
.el-icon-question::before {
font-size: 22px;
}
}
.el-dropdown {
float: right;
margin-top: 8px;
margin-right: 24px;
}
}
</style>
<style scoped lang="less">
#title-wrap {
img {
float: left;
width: 25px;
height: 25px;
margin-top: 10px;
margin-left: 53px;
}
p {
float: left;
margin-left: 12px;
font-size: 16px;
font-family: PingFangSC-Semibold, PingFang SC;
font-weight: 600;
color: #ffffff;
line-height: 48px;
text-shadow: 0px -1px 0px #215c85;
}
.item {
float: right;
height: 30px;
margin-top: 4px;
margin-right: 30px;
.el-button--primary {
border: none;
background: none;
padding: 0;
}
}
.question-button {
float: right;
border: none;
background: none;
padding-right: 22px;
color: #fff;
box-shadow: none;
}
.share-button {
color: #fff;
box-shadow: none;
}
}
</style>

+ 10
- 3
src/components/NavMenu.vue View File

@ -27,6 +27,7 @@ export default {
},
activeMenu() {
const { path } = this.$route;
localStorage.router = path;
return path;
},
},
@ -59,17 +60,23 @@ export default {
return path;
},
//
getUserMenus(){
getUserMenus() {
get("/sysMenu").then(({ code, data }) => {
if (code == 200 && data) {
this.menus = data.map((e) => this.setMenus(e));
const router = this.defaultRouter(this.menus);
this.$router.push({ path: router });
console.log(localStorage.router);
this.$router.push({
path:
localStorage.router && localStorage.router != "/"
? localStorage.router
: router,
});
} else {
this.menus = [];
}
});
}
},
},
created() {
this.getUserMenus();


+ 6
- 6
src/router/routers.js View File

@ -24,12 +24,12 @@ const routes = [
title: "角色管理",
component: () => import("@/views/system/role"),
},
{
icon: "el-icon-document",
path: "/system/standard",
title: "标准定义",
component: () => import("@/views/system/standard"),
},
{
icon: "el-icon-document",
path: "/system/standard",
title: "标准定义",
component: () => import("@/views/system/standard"),
},
],
}
];


+ 4
- 0
src/server/request.js View File

@ -1,4 +1,5 @@
import axios from "axios";
import { ElMessage } from 'element-plus'
const service = axios.create({
baseURL: process.env.VUE_APP_BASE_URL || "http://101.201.121.115:9003/",
timeout: 20000, // request timeout
@ -26,7 +27,10 @@ service.interceptors.response.use(
error.response.data &&
error.response.data.code == 401
) {
localStorage.router = "";
location.href = `${location.origin}/#/login`;
}else{
ElMessage.error(error.response.data.msg);
}
return Promise.reject(error.response);
}


+ 1
- 5
src/views/login.vue View File

@ -69,13 +69,9 @@ export default {
this.$router.push({ path: "/" });
}
})
}else{
this.msgError(msg);
}
}
).catch(()=>{
this.msgError('登录失败');
});
)
},
//
getProject() {


Loading…
Cancel
Save