退出登录

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. 10
      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-menu>
</el-dropdown> </el-dropdown>
<el-divider direction="vertical"></el-divider> <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> </div>
<el-dialog title="修改密码" :visible.sync="passwordVisible" :close-on-click-modal="false" :append-to-body="true" @close="resetPassword" width="30%"> <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"> <el-form ref="passwordForm" label-width="82px">
@ -63,19 +63,8 @@ export default {
}, },
methods: { methods: {
...mapActions("user", [ ...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 getSystemDetail() { // logo
this.$get(this.api.logoDetail).then(res => { this.$get(this.api.logoDetail).then(res => {
if (res.data) { if (res.data) {

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

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

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

@ -88,7 +88,15 @@ export default {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
util.local.remove(Setting.storeKey); util.local.remove(Setting.storeKey);
util.local.remove(Setting.tokenKey); 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(); resolve();
}); });
}, },

Loading…
Cancel
Save