token过期
							parent
							
								
									a4e2b8c0a2
								
							
						
					
					
						commit
						2b38ec4a7a
					
				| 
						 | 
				
			
			@ -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) => {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue