/**
 * 
 * 请求封装
 * 
 */


import config from './config.js'

const HEADER = {
	'content-type': 'application/json'
}; //头部
const baseURL = ''
const request = options => {
	let headerObj = HEADER;
	const token = uni.getStorageSync('token');
	if (token) {
		headerObj = {
			'Authorization': token,
			...HEADER
		}
	}
	if (options.data.header) {
		headerObj = Object.assign(headerObj, options.data.header || {})
	}
	return new Promise((resolve, reject) => {
		uni.request({
			url: baseURL + options.url,
			method: options.method || 'GET',
			header: headerObj,
			data: options.data || {},
			dataType: 'json',
			success: res => {
				if (res.statusCode != 200) {
					reject(res);
					return
				}
				resolve(res.data || false);
			},
			fail: err => {
				reject(err);
			}
		});
	});
};


export const requestGet = (url, data) => {
	return request({
		method: 'GET',
		url,
		data
	})
}

export const requestPost = (url, data) => {
	return request({
		method: 'POST',
		url,
		data
	})
}