export const APP_API = (import.meta.env.VITE_API_URL || "http://182.43.195.17:8010") //后台管理接口根地址
// export const QUICK_API = (import.meta.env.VITE_API_URL || "http://10.1.1.165:8000") //数/*  */据大屏接口根地址
export const QUICK_API = (import.meta.env.VITE_API_URL || "http://182.43.247.65:8081") //数据大屏接口根地址
// export const APP_API = (import.meta.env.VITE_API_URL || "http://192.168.11.48:8010") //本地
import { deleteLocalStorage, getLocalStorage } from "@/utils/cache";
export const Put = (url : any, param : any, host : any) => {
	return Request(url, "PUT", param, host)
}

export const Post = (url : any, param : any, host : any) => {
	return Request(url, "POST", param, host)
}

export const Get = (url : any, param : any, host : any) => {
	return Request(url, "GET", param, host)
}

export const Request = (url : any, method : any, param : any, host : any) => {
	let cacheKey = "token";
	const current = getLocalStorage(cacheKey);
	return new Promise(async (cback, reject) => {
		uni.request({
			url: host + url,
			data: param,
			method: method,
			header: {
				'Authorization': 'Bearer ' + current,
			},
		}).then(async response => {
			const status = response.statusCode.toString();
			const result : any = response.data
			if (status.charAt(0) === '2') {
				if (result.code == 401) {
					deleteLocalStorage('token')
					uni.reLaunch({
						url: '/pages/login/index'
					});
				} else {
					cback(result);
				}
			} else {
				// const msg = result.msg ? result.msg : '网络请求异常!'
				// uni.$u.toast(msg)
				reject(result)
			}
		}).catch(err => {
			reject(err)
		})
	})
}