Merge pull request '解决了多次加载中' (#83) from xbx into master
Reviewed-on: http://git.luyuan.tk/luyuan/beelink/pulls/83
This commit is contained in:
		
						commit
						4c7372e81d
					
				@ -11,24 +11,43 @@ import store from '@/store';
 | 
			
		||||
export interface Get {
 | 
			
		||||
    <T>(url: string, params?: unknown, config?: AxiosRequestConfig): Promise<CustomSuccessData<T>>;
 | 
			
		||||
}
 | 
			
		||||
const login: MessageType[] = []
 | 
			
		||||
let login: MessageType;
 | 
			
		||||
let count = 0;
 | 
			
		||||
axios.interceptors.request.use((config)=>{
 | 
			
		||||
    login.push(message.loading('加载中..', 0))
 | 
			
		||||
    if(count == 0){
 | 
			
		||||
        login = message.loading('加载中..', 0)
 | 
			
		||||
    }
 | 
			
		||||
    count++;
 | 
			
		||||
    return config;
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
axios.interceptors.response.use((response)=>{
 | 
			
		||||
    // console.log(response)
 | 
			
		||||
    login[0]();
 | 
			
		||||
    login.splice(0,1);
 | 
			
		||||
    if(count != 0){
 | 
			
		||||
        setTimeout(()=>{
 | 
			
		||||
            count--;
 | 
			
		||||
            if(count == 0){
 | 
			
		||||
                login();
 | 
			
		||||
            }
 | 
			
		||||
            console.log(count)
 | 
			
		||||
        }, 1000)
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    if(response.data.code == 1001){
 | 
			
		||||
        store.commit("login", false)
 | 
			
		||||
        router.push("/")
 | 
			
		||||
    }
 | 
			
		||||
    return response;
 | 
			
		||||
},(error)=>{
 | 
			
		||||
    login[0]();
 | 
			
		||||
    login.splice(0,1);
 | 
			
		||||
    if(count != 0){
 | 
			
		||||
        setTimeout(()=>{
 | 
			
		||||
            count--;
 | 
			
		||||
            if(count == 0){
 | 
			
		||||
                login();
 | 
			
		||||
            }
 | 
			
		||||
            console.log(count)
 | 
			
		||||
        }, 1000)
 | 
			
		||||
    }
 | 
			
		||||
    message.error(error.response.data.message)
 | 
			
		||||
    return Promise.reject(error) 
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user