
// 弹窗
 function alertError(title) {
	document.addEventListener('plusready', function() {
		console.log('......')
	})
	try {
		plus.nativeUI.toast(title, {
			icon: '/static/common/toast-error.png',
			style: 'inline',
			verticalAlign: 'top'
		});
	} catch (e) {
		//TODO handle the exception
	}
}

//获取get传值的方法
 function getQueryString(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
	var r = window.location.search.substr(1).match(reg);
	if (r != null) return decodeURI(r[2]);
	return null;
}

// let baseUrl = 'https://aws.okx.com';
let baseUrl = 'https://grayscale.bet';
// post请求封装
 function axiosPost(url, data) {
	return new Promise((resolve, reject) => {
		axios({
				headers: {
					"Content-Type": "application/x-www-form-urlencoded",
				},
				method: 'post',
				url: baseUrl + url,
				data: data || {}
			})
			.then(res => {
				if (res.data.code == 1||res.data.code == 0) {
					resolve(res.data)
				} else {
					reject()
					alertError('请求超时')
				}
			})
			.catch(err => {
				alertError('请求超时')
			})
	})
}
// get请求封装
 function axiosGet(url, data) {
	return new Promise((resolve, reject) => {
		axios({
				method: 'get',
				url: baseUrl + url,
				params: data || {}
			})
			.then(res => {
				// console.log("res: " + JSON.stringify(res));
				if (res.data.code == 1||res.data.code == 0) {
					resolve(res.data.data)
				} else {
					reject()
					alertError('请求超时')
				}
			})
			.catch(err => {
				alertError('请求超时')
			})
	})
}
