import config from '@/config.js';
import sign from "@/libs/net/sign.js";


export function request(url, param, isShowLoading = "1", method = 'POST') {
	if (isShowLoading) {
		uni.showLoading({
			title: '正在加载...'
		})
	}
	param=sign(param);
	let header = {};
	// header['Current-Admin-Id'] = uni.getStorageSync('adminId');
	// header['Current-School-Id'] = uni.getStorageSync('schoolId');
	return new Promise((resolve, reject) => {
		uni.request({
			url: config.host + url,
			data: param,
			method: method,
			header: header,
			success(res) {
				//console.log(res);
				if (res.data.code === 0) { //找不到openid对应的用户
					resolve(res.data);
				} else if (res.data.code == 102) {
					reject(res.data);
				} else {
					reject(res.data);
				}
			},
			fail(err) {
				reject(err);
			},
			complete() {
				uni.hideLoading();
			}
		});
	});
}