// 接口前缀
const BASE_URL = "https://www.campussmartlife.com/smartApi"

export const myRequest = (options) => {
	uni.showLoading({
		title: "加载中",
		mask: true,
	});
	return new Promise((resolve, reject) => {
		uni.request({
			url: BASE_URL + options.url,
			method: options.method || "GET",
			header: options.header || {
				'token': uni.getStorageSync('token') || '',
				'user_head': uni.getStorageSync('userhead') || ''
			},
			data: options.data || {},
			timeout: 25000,
			success: (res) => {
				// if (res.data.code == 200) {
				// 	resolve(res.data)
				// }
				resolve(res.data)
			},
			fail: (err) => {
				uni.showToast({
					title: err.errMsg ? err.errMsg : "请求发送失败",
					icon: "none",
					mask: true
				})
				reject(err)
			},
			complete: (res) => {
				uni.hideLoading({
					complete: (hide) => {
						if (res.data.code == 200) {

						} else {
							uni.showToast({
								title: res.data.message ? res.data.message :
									'报错',
								icon: "none",
								mask: true,
								duration: 2000
							})
						}
					}
				});
			}
		})
	})
}