dcba8aa1 by yangwei

登录问题修改

1 parent ccbc2d34
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
43 onCancel () { 43 onCancel () {
44 logout() 44 logout()
45 .then((res) => { 45 .then((res) => {
46 sessionStorage.removeItem("token"); 46 localStorage.removeItem("token");
47 this.$store.dispatch("user/resetState"); 47 this.$store.dispatch("user/resetState");
48 this.$router.replace({ 48 this.$router.replace({
49 path: "/jg", 49 path: "/jg",
......
...@@ -18,13 +18,13 @@ router.beforeEach(async (to, from, next) => { ...@@ -18,13 +18,13 @@ router.beforeEach(async (to, from, next) => {
18 let hasUser = store.state.user.hasUser; 18 let hasUser = store.state.user.hasUser;
19 let hasAddRoute = store.state.permission.addRoutes; 19 let hasAddRoute = store.state.permission.addRoutes;
20 if (to.path == "/sb" || to.path == "/jg") { 20 if (to.path == "/sb" || to.path == "/jg") {
21 sessionStorage.removeItem("token"); 21 localStorage.removeItem("token");
22 sessionStorage.setItem("psth", to.path) 22 sessionStorage.setItem("psth", to.path)
23 next(); 23 next();
24 } else { 24 } else {
25 let code = sessionStorage.getItem("psth") == "/sb" ? "BDCSBPT" : "BDCJGPT" 25 let code = sessionStorage.getItem("psth") == "/sb" ? "BDCSBPT" : "BDCJGPT"
26 //判断token是否存在 26 //判断token是否存在
27 const hasToken = sessionStorage.getItem("token"); 27 const hasToken = localStorage.getItem("token");
28 if (hasToken) { 28 if (hasToken) {
29 //请求用户信息 29 //请求用户信息
30 if (!hasUser) { 30 if (!hasUser) {
......
1 /* 1 /*
2 * @Description: 2 * @Description:
3 * @Autor: renchao 3 * @Autor: renchao
4 * @LastEditTime: 2023-03-13 14:11:50 4 * @LastEditTime: 2023-03-14 14:39:24
5 */ 5 */
6 /** 6 /**
7 * 此文件主要创建 axios 实例,然后添加请求拦截器和响应拦截器 7 * 此文件主要创建 axios 实例,然后添加请求拦截器和响应拦截器
...@@ -25,7 +25,7 @@ const service = axios.create({ ...@@ -25,7 +25,7 @@ const service = axios.create({
25 service.interceptors.request.use( 25 service.interceptors.request.use(
26 (config) => { 26 (config) => {
27 //调用登录接口时无token,也不需要传token,其他接口都传入token 27 //调用登录接口时无token,也不需要传token,其他接口都传入token
28 config.headers.Authorization = sessionStorage.getItem("token") || ""; 28 config.headers.Authorization = localStorage.getItem("token") || "";
29 config.headers.Accept = "application/json"; 29 config.headers.Accept = "application/json";
30 return config; 30 return config;
31 }, 31 },
...@@ -35,6 +35,7 @@ service.interceptors.request.use( ...@@ -35,6 +35,7 @@ service.interceptors.request.use(
35 } 35 }
36 ); 36 );
37 37
38 window.tokenValid = true
38 // response interceptor 39 // response interceptor
39 service.interceptors.response.use( 40 service.interceptors.response.use(
40 (response) => { 41 (response) => {
...@@ -64,15 +65,20 @@ service.interceptors.response.use( ...@@ -64,15 +65,20 @@ service.interceptors.response.use(
64 //对错误信息的处理函数 65 //对错误信息的处理函数
65 function handleErrorData (status) { 66 function handleErrorData (status) {
66 switch (status) { 67 switch (status) {
67 // case 401: 68 case 401:
68 // Message.error("由于长时间未操作,请重新登录!"); 69 // 多个请求不重复提示错误信息
69 // router.replace({ 70 if (window.tokenValid) {
70 // path: "/login/jg", 71 window.tokenValid = false;
71 // query: { 72 Message.error("由于长时间未操作,请重新登录!");
72 // redirect: router.history.current.fullPath, 73 localStorage.removeItem("token");
73 // }, 74 router.replace({
74 // }); 75 path: "/jg",
75 // break; 76 query: {
77 redirect: router.history.current.fullPath,
78 },
79 });
80 }
81 break;
76 case 403: 82 case 403:
77 Message.error("拒绝访问"); 83 Message.error("拒绝访问");
78 break; 84 break;
......
...@@ -96,7 +96,7 @@ ...@@ -96,7 +96,7 @@
96 .then((res) => { 96 .then((res) => {
97 if (res.status === 1) { 97 if (res.status === 1) {
98 //存储token 98 //存储token
99 sessionStorage.setItem("token", `Bearer ${res.content}`); 99 localStorage.setItem("token", `Bearer ${res.content}`);
100 //登录成功后需判断有无重定向,没有重定向则跳转首页 100 //登录成功后需判断有无重定向,没有重定向则跳转首页
101 this.$router.replace(this.$route.query.redirect || "/"); 101 this.$router.replace(this.$route.query.redirect || "/");
102 } else { 102 } else {
......
...@@ -103,7 +103,7 @@ ...@@ -103,7 +103,7 @@
103 if (res.status === 1) { 103 if (res.status === 1) {
104 this.$store.dispatch('business/setInitRules', "layout1") 104 this.$store.dispatch('business/setInitRules', "layout1")
105 //存储token 105 //存储token
106 sessionStorage.setItem("token", `Bearer ${res.content}`); 106 localStorage.setItem("token", `Bearer ${res.content}`);
107 //登录成功后需判断有无重定向,没有重定向则跳转首页 107 //登录成功后需判断有无重定向,没有重定向则跳转首页
108 this.$router.replace(this.$route.query.redirect || "/"); 108 this.$router.replace(this.$route.query.redirect || "/");
109 } else { 109 } else {
......