import dev from "@/env/dev.js"
import prod from "@/env/prod.js"
let baseUrl = ''
if (process.env.NODE_ENV === 'development') {
	baseUrl = dev.baseUrl
} else {
	baseUrl = prod.baseUrl
}
export const myRequest = (options) => {
	return new Promise((resolve, reject) => {
		let obj_url = ''
		let obj_method = 'GET'
		let obj_data = {}
		if (options) {
			obj_url = baseUrl + options.url
			obj_method = options.method
			obj_data = options.data
		}
		uni.request({
			url: obj_url,
			method: obj_method,
			data: obj_data,
			success: (res) => {
				if (res.data.code !== 0) {
					return uni.showToast({
						title: '获取数据失败',
						icon: "error"
					})
				}
				resolve(res)
			},
			fail: (err) => {
				uni.showToast({
					title: "请求接口失败",
					icon: "error"
				})
				reject(err)
			}
		})
	})
}
