import axios from 'axios';
// var baseURL='https://www.scxjc.club'
var baseURL = ''
axios.interceptors.request.use(
	config => {
		const token = localStorage.getItem('token');
		// if (config.url.indexOf('downloadzip') >= 0) {
		// if (token) { // 判断是否存在token，如果存在的话，则每个http header都加上token                      
		// 	config.headers.Authorization = `${token}`;   
		// } else {
		// 	//未登录
		// 	window.location.hash = "/login";
		// }
		// } 
		return config;
	},
	err => {
		return Promise.reject(err);
	});
axios.interceptors.response.use(function (response) {
	// console.log(response.headers)
	// IE 8-9 
	if (response.data == null && response.config.responseType === 'json' && response.request.responseText != null) {
		try {
			// eslint-disable-next-line no-param-reassign
			response.data = JSON.parse(response.request.responseText);
		} catch (e) {
			// ignored
		}
	}
	// 对响应数据做点什么
	if (response.data.code == 401) {
		// window.location.hash = "/login";
		// window.location.hash = "/";
	}
	if (response.data.code == 305) {
		// window.location.hash = "/";
	}
	return response;
}, function (error) {
	// 对响应错误做点什么
	if (error.request.status == 403) {
		// window.location.hash = "/login";
		window.location.hash = "/";
	}
	// console.log(Object.getOwnPropertyNames(error))
	// console.log(error.request,error.message)
	return Promise.reject(error);
});
export default {
	//登录
	login: params => {
		return axios.post(`${baseURL}/api/account/login`, params);
	},
	logout: params => {
		return axios.post(`${baseURL}/api/account/logout`, params);
	},
	// 全局账号信息
	getAccountInfo: params => {
		return axios.get(`${baseURL}/api/account/info`)
	},
	// 验证码
	getCode: params => {
		return axios.get(`${baseURL}/api/account/imgcode`)
	},
	// 账号
	getUserList: params => {
		return axios.get(`${baseURL}/api/admin/user/list`, { params: params })
	},
	getAllSysUserList: params => {
		return axios.get(`${baseURL}/api/admin/user/all`, { params: params })
	},
	getUserinfoList: params => {
		return axios.get(`${baseURL}/api/admin/userinfo/list`, { params: params })
	},
	// 获取用户待选期刊列表
	getUserJournals: () => {
		return axios.get(`${baseURL}/api/admin/user/journals`)
	},
	// 获取用户待选角色列表
	getUserRoles: () => {
		return axios.get(`${baseURL}/api/admin/user/roles`)
	},

	//新增管理员
	addUser: params => {
		return axios.post(`${baseURL}/api/admin/user`, params);
	},
	// 修改管理员
	editUser: params => {
		return axios.put(`${baseURL}/api/admin/user`, params);
	},
	// 删除管理员
	delUser: params => {
		return axios.delete(`${baseURL}/api/admin/user`, { params: params });
	},
	// 获取数据
	getPlayerRecord: params => {
		return axios.get(`${baseURL}/api/admin/player/record/list`, { params: params });
	},
	addRecord: params => {
		return axios.post(`${baseURL}/api/admin/player/record`, params);
	},
	editRecord: params => {
		return axios.put(`${baseURL}/api/admin/player/record`, params);
	},
	// 比赛搜索列表
	getMatchList: params => {
		return axios.get(`${baseURL}/api/admin/match/search`, { params: params })
	},
	// 选手列表
	getPlayerList: params => {
		return axios.get(`${baseURL}/api/admin/player/search`, { params: params })
	},
	// 分组列表
	getGroupList: params => {
		return axios.get(`${baseURL}/api/admin/match/group/search`, { params: params })
	},
	// 股票列表
	getStockList: params => {
		return axios.get(`${baseURL}/api/admin/stock/search`, { params: params })
	},
	//获取所有模板列表
	getAllTemplateList: params => {
		return axios.get(`${baseURL}/api/admin/message/template/all`, { params: params })
	},
	// 新增角色
	addRole: params => {
		return axios.post(`${baseURL}/api/admin/role`, params);
	},
	// 修改角色
	editRole: params => {
		return axios.put(`${baseURL}/api/admin/role`, params);
	},
	delRole: params => {
		return axios.delete(`${baseURL}/api/admin/role`, { params: params });
	},
	// 获取角色列表
	getRoleList: params => {
		return axios.get(`${baseURL}/api/admin/role/list`, { params: params });
	},
	// 获取角色详情
	getRoleInfo: params => {
		return axios.get(`${baseURL}/api/admin/role`, { params: params });
	},

}