退出登录

dev_2022-05-11
yujialong 3 years ago
parent 887da6c6f1
commit 6c6fa0c92f
  1. 15
      src/layouts/header/index.vue
  2. 17
      src/plugins/requests/index.js
  3. 16
      src/router/index.js
  4. 3
      src/setting.js
  5. 10
      src/store/modules/user.js

@ -16,7 +16,7 @@
</el-dropdown-menu>
</el-dropdown>
<el-divider direction="vertical"></el-divider>
<el-button type="text" class="ml20" @click="loginout">退出</el-button>
<el-button type="text" class="ml20" @click="logout">退出</el-button>
</div>
<el-dialog title="修改密码" :visible.sync="passwordVisible" :close-on-click-modal="false" :append-to-body="true" @close="resetPassword" width="30%">
<el-form ref="passwordForm" label-width="82px">
@ -63,19 +63,8 @@ export default {
},
methods: {
...mapActions("user", [
"setTitle", "setLogoUrl", "setAvatar", "setUserName"
"setTitle", "setLogoUrl", "setAvatar", "setUserName", 'logout'
]),
loginout() { // 退
localStorage.clear();
sessionStorage.clear();
//
if (this.fromClient) {
location.href = `${location.origin}/student`
// location.href = `http://192.168.31.125:8082/#/index/list`
} else {
location.reload()
}
},
getSystemDetail() { // logo
this.$get(this.api.logoDetail).then(res => {
if (res.data) {

@ -2,6 +2,7 @@ import axios from "axios";
import util from "@/libs/util";
import router from "@/router/index";
import Setting from "@/setting";
import store from '@/store'
const service = axios.create({
baseURL: Setting.apiBaseURL,
@ -20,7 +21,7 @@ service.interceptors.request.use(config => {
util.errorMsg({
message: "退出登陆",
onClose: function() {
router.push({ name: "/login" });
store.dispatch('user/logout')
}
});
return Promise.reject(err);
@ -52,12 +53,7 @@ service.interceptors.response.use(
util.local.remove(Setting.tokenKey);
util.errorMsg("登录过期,请重新登录");
setTimeout(() => {
router.replace({
path: "/login",
query: {
redirect: router.currentRoute.fullPath
}
});
store.dispatch('user/logout')
}, 1000);
break;
case 500:
@ -75,12 +71,7 @@ service.interceptors.response.use(
// store.commit('loginSuccess', null);
// 跳转登录页面,并将要浏览的页面fullPath传过去,登录成功后跳转需要访问的页面
setTimeout(() => {
router.replace({
path: "/login",
query: {
redirect: router.currentRoute.fullPath
}
});
store.dispatch('user/logout')
}, 1000);
break;
// 404请求不存在

@ -6,8 +6,6 @@ import { get } from "@/plugins/requests/index.js";
import api from "@/api";
import util from "@/libs/util";
import BasicLayout from "@/layouts/home";
import store from '@/store'
Vue.use(Router);
const createRouter = () => new Router({
mode: Setting.routerMode,
@ -61,6 +59,7 @@ function getPermission() {
let data = res.permissionMenu[0].children;
if (data.length > 0) {
console.log(11, data)
data.forEach(e => {
// 第一级路由,需要根据匹配到的path,塞进对应的路由children里
let str = e.path.split("/")[1];
@ -77,6 +76,7 @@ function getPermission() {
let children = [];
// 第二级是按钮级数据,一级归属当前页的同级页面,实际上一共就一级路由
if (e.children && e.children.length > 0) {
console.log(e.children)
e.children.forEach(i => {
// 避免重复生成路由
if (i.path && permissionRouters[index] && !permissionRouters[index].children.some(e => i.path === e.path)) {
@ -260,14 +260,10 @@ router.beforeEach(function(to, from, next) {
}
} else {
if (to.path !== "/login" && to.path !== '/redirect') {
if (store.state.user.fromClient) {
location.href = `${location.origin}/student`
} else {
next({
path: "/login",
query: { redirect: to.path }
});
}
next({
path: "/login",
query: { redirect: to.path }
})
}
}
// 根据路由元信息设置文档标题

@ -66,6 +66,9 @@ const Setting = {
cookiesExpires: 1, // Cookies 默认保存时间,单位:天
tokenExpires: 1296000000, // token在localStorage的时间(毫秒)
bankPath,
isDev,
isTest,
isPro,
/**
* localStorage里保存的token的key
*/

@ -88,7 +88,15 @@ export default {
return new Promise((resolve, reject) => {
util.local.remove(Setting.storeKey);
util.local.remove(Setting.tokenKey);
location.reload();
if (state.fromClient) {
location.href = Setting.isDev
? `http://192.168.31.125:8082/#/`
: Setting.isTest
? `${location.origin}/student/#/login`
: `${location.origin}/#/login`
} else {
location.reload()
}
resolve();
});
},

Loading…
Cancel
Save