import { config } from "../config/config";
import { UserData } from "../stores/userDataManager";
export class http {
	//动态请求
	public static DynamicRequest(api:string,post_data:any,call_back:Function,isPost:boolean=true){
		uni.request({
		    url: config.url_addr.Dynamic + api, 
		    data:JSON.stringify(post_data),
			method:isPost?"POST":"GET",
		    header: {
				'Content-Type': 'application/json',
				'applet_id': config.applet_id,
		        'token': UserData().getUserToken() //自定义请求头信息
		    },	
		    success: (res) => {
				if(call_back!=null){
					call_back(null,res.data)
				}
		    },
			fail(res) {
				if(call_back!=null){
					call_back(res,null)
				}
			}
		});
	}
	//静态请求
	public static StaticRequest(api:string,call_back:Function){
		uni.request({
		    url: api, 
			method:"GET",
		    success: (res) => {
				if(call_back!=null){
					call_back(null,res.data)
				}
		    },
			fail(res) {
				if(call_back!=null){
					call_back(res,null)
				}
			}
		});
	}
	
	public static getStaticText(api:string,call_back:Function){
		uni.request({
			dataType: "text",
			responseType: "text",
		    url: api, 
			method:"GET",
			
		    success: (res) => {
				if(call_back!=null){
					call_back(null,res.data)
				}
		    },
			fail(res) {
				if(call_back!=null){
					call_back(res,null)
				}
			}
		});
	}
}