let app = getApp();

function requestbrest(method, url, data) {
	return new Promise((resolve) => {
		uni.request({
			method: method,
			url: url,
			data: data,
			header: {
				'Accept': "*/*",
				'content-type': 'application/json;charset=utf-8',
				'Authorization': app.globalData.brestToken, //有的时候这里不一定是 token 还可能是 Authorization
			},
			success(res) {
				resolve(res)
				if (res.statusCode == 401 || res.statusCode == 102068) {
					uni.showToast({
						title: '登录信息过期,请重新授权',
						icon: 'none',
						duration: 2000
					})
					app.globalData.brestUserInfo = '';
					app.globalData.brestToken = '';
					uni.reLaunch({
						url: '/pages/tabBar/home/home'
					})
				}
			},
			fail(err) {
				uni.showToast({
					title: '请求失败',
					icon: 'none',
					duration: 1500,
				})
				// uni.hideLoading()
			}
		})
	})
}

function POSTBREST(method, url, data) {
	return requestbrest(method, url, data)
}

module.exports = {
	POSTBREST
}
