diff --git a/src/layouts/header/index.vue b/src/layouts/header/index.vue
index 0031c5e..115812c 100644
--- a/src/layouts/header/index.vue
+++ b/src/layouts/header/index.vue
@@ -16,7 +16,7 @@
- 退出
+ 退出
@@ -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) {
diff --git a/src/plugins/requests/index.js b/src/plugins/requests/index.js
index bfdcee3..ba9b134 100644
--- a/src/plugins/requests/index.js
+++ b/src/plugins/requests/index.js
@@ -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请求不存在
diff --git a/src/router/index.js b/src/router/index.js
index dd9a9a1..f3de9cf 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -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 }
+ })
}
}
// 根据路由元信息设置文档标题
diff --git a/src/setting.js b/src/setting.js
index 02a46e6..e2a5417 100644
--- a/src/setting.js
+++ b/src/setting.js
@@ -66,6 +66,9 @@ const Setting = {
cookiesExpires: 1, // Cookies 默认保存时间,单位:天
tokenExpires: 1296000000, // token在localStorage的时间(毫秒)
bankPath,
+ isDev,
+ isTest,
+ isPro,
/**
* localStorage里保存的token的key
*/
diff --git a/src/store/modules/user.js b/src/store/modules/user.js
index ca8c32a..06064f2 100644
--- a/src/store/modules/user.js
+++ b/src/store/modules/user.js
@@ -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();
});
},