import axios from "axios";
const request = axios.create({
	baseURL: process.env.NODE_ENV  === "production" ? "https://nbjk.zzxcx.net/nbjk-admin" : "https://nbjk1.zzxcx.net/nbjk-admin",
	//"/prod-api" : "/dev-api"
});
request.interceptors.request.use(config => {
	const token = window.localStorage.getItem("token") || ""
	if (config.headers.isToken === "0") {
		config.headers["Authorization"] = ""
	}

	else {
		config.headers["Authorization"] = token?"Bearer " + token:"";
                                                                              
	}
	// 让每个请求携带自定义token 请根据实际情况自行修改
	// config.headers["Authorization"]="Bearer " +token;

	return config;

})
request.interceptors.response.use((res) => {
	// if (res && res.data) {

	// 	switch (res.data.code) {
	// 		case 200:
	// 			break;
	// 		case 401:
	// 			// Toast("登录失败,需要再次登录")
	// 			window.setTimeout(() => {

	// 				switch (import.meta.env.MODE) {
	// 					case "development":
	// 						location.replace(`https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx3043c2c1decb01ed&redirect_uri=https://sdjk-h5.zzxcx.net/&response_type=code&scope=snsapi_userinfo&state=LOGIN#wechat_redirect`)
	// 						break;
	// 					case "test":
	// 						location.replace(`https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx3043c2c1decb01ed&redirect_uri=https://sdjk-h51.zzxcx.net/&response_type=code&scope=snsapi_userinfo&state=LOGIN#wechat_redirect`)
	// 						break;
	// 					case "production":
	// 						location.replace(`https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx3043c2c1decb01ed&redirect_uri=https://sdjk-h5.zzxcx.net/&response_type=code&scope=snsapi_userinfo&state=LOGIN#wechat_redirect`);
	// 						break;
	// 				}
	// 			}, 2000)
				
	// 			break;
	// 		case 502:
	// 			console.log('进入502')
	// 			if (res.data.msg == "微信授权无效，请重新授权") {
	// 				location.replace("https://coach.zzxcx.net/")
	// 				return
	// 			}
			
	// 			Toast.fail(res.data.msg)
				

	// 			break;
	// 		default:
	// 			Toast.fail(res.data.msg)
				
	// 			break;
	// 	}
	// }

	// console.log(res)

	return res;
},(error=>{
	
}));

export default request;


