token过期

main
wangqiujuan0808 2024-01-20 21:48:14 +08:00
parent a4e2b8c0a2
commit 2b38ec4a7a
2 changed files with 13 additions and 2 deletions

View File

@ -5,7 +5,8 @@ import { ElMessage } from "element-plus";
import router from "@/router/index";
import { localGet } from "./index";
import config from "~/config";
import { token } from '../proto/data/pd'
import { token,response } from '../proto/data/pd';
import { localRemove, pathMap } from "@/utils";
axios.defaults.baseURL = config[import.meta.env.MODE].baseUrl;
axios.defaults.withCredentials = true;
@ -31,6 +32,15 @@ function getNeedToken() {
//
axios.interceptors.response.use(
(res) => {
// token
const ret = response.decode(new Uint8Array(res.data));
if(ret.code ===40100 || ret.code ===40101) {
localRemove("token");
ElMessage.closeAll();
ElMessage.error(ret.msg || "Token过期请重新登录");
router.push({ path: "/login" });
return Promise.reject(ret);
}
return res.data;
},
(error) => {

View File

@ -24,7 +24,8 @@ export default ({ mode }) => defineConfig({
server: {
proxy: {
'/api': {
target: 'http://frp.shikicc.com:58951',
target: 'http://cdcm_test_api.shikicc.com:58909',
// target: 'http://frp.shikicc.com:58951',
// target: 'http://10.10.14.123',
// target: 'https://cdcmapi.shikicc.com',
changeOrigin: true,