import axios from 'axios'
import { Notification } from 'element-ui'

var remoteURL = 'http://jingkongyun.com:8000/';

const service = axios.create({
	baseURL: remoteURL,
	timeout: 30000,
})

service.interceptors.response.use(
	response => {
		return response.data
	},

	error => {
		if (error.response.status) {
			const responseCode = error.response.status

			switch (responseCode) {
				case 400:
					break
				//  token 过期
				case 401:
					Notification({
						title: '登录过期，请重新登录',
						duration: 2000,
						type: 'warning',
					})

					setTimeout(() => {
						window.localStorage.removeItem('token')
						window.location = '#/'
					}, 1000)

					break

				default:
					break
			}
			return error.response.data
		}
	}
)

export default service
