import {
	fetch,
	fetchfile
} from "./fetch/interceptos.js"

const obj = {
	headerGET: {
		"Content-type": 'application/x-www-from-urlencoded',
		"Access-Control-Allow-Origin": "*"
	},
	headerPOST: {
		"Content-type": 'application/json'
	},
	headerFORM: {
		"Content-type": 'multipart/form-data'
	}
}

const http = {
	// get请求
	get(url: String, params: Object) {
		let opt = {
			header: obj['headerGET'],
			method: "GET",
			data: params
		}
		return fetch(url, opt)
	},
	oss(url: String, params: Object) {
		let opt = {
			header: obj['headerGET'],
			method: "GET",
			data: params,
			isFile:true
		}
		return fetch(url, opt)
	},

	// post请求
	post(action: String, params: Object) {
		let opt = {
			header: obj['headerPOST'],
			method: "POST",
			data: params
		}
		if (params) {
			opt.data = params
		}
		let apiname = action;
		// if (apiname.indexOf("Safe_") == 0) {
		// 	apiname = "ExecuteSafe";
		// }
		// else {
		// 	apiname = apiname === "Login" ? "Login" : "Execute"
		// }
		return fetch(apiname, opt)
	},
	// post请求
	upload(action: String, params: Object) {
		return fetchfile(action, params)
	}
}

export default http
