import baseurl from './baseurl.js'


var request = function(config) {
	return new Promise((resolve, rejected) => {
		uni.showLoading({
			title: ''
		});
		uni.request({
			url: baseurl + config.url,
			data: config.data,
			method: config.method,
			timeout: 50000,
			header: {
				'token': uni.getStorageSync('token'),
				'mobileLogin': true
			},
			success(res) {
				// console.log(res, '111')
				if (res.data.errorCode == 'B1002' && res.data.msg == '用户账号密码错误（或登录超时）') {
					uni.showToast({
						icon:'none',
					    title: res.data.msg,
					    duration: 1500
					});
					setTimeout(function() {
						uni.reLaunch({
							url: '/pages/login/login'
						})
						
						uni.removeStorageSync('token')
						
					}, 1500);
				
				}
				uni.hideLoading();
				resolve(res.data)
			},
			fail(err) {
				uni.hideLoading();
				rejected(err, 1)
			}
		})
	})
}

export default request
