import wxCode from '@/utils/lib/code.js'

export const apiResquest = (prams) => {

	return new Promise((resolve, reject) => {
		let url = getApp().globalData.webApi + prams.url;
		return uni.request({
			url: url,
			data: prams.query,
			method: prams.method,
			header: {
				'Authorization': uni.getStorageSync("token"),
			},
			success: (res) => {
				// uni.hideLoading()
				if (res.data.code != 200) {
					if (res.data.code == 402 || res.data.code == 401) {
						wxCode.codes()
					}
					uni.showToast({
						title: res.msg,
						duration: 1000,
						icon: "none"
					})
				}
				resolve(res.data);
			},
			fail: (err) => {
				reject(err);
			},
			complete: () => {
				console.log('请求完成')
			}
		});
	})
}