import baseUrl from './new_file.js'
const request = function(options) {
     options.url = baseUrl + options.url;
     try {
       // 获取放入缓存的字段token obj.header["token"] = userToken;
      const token = uni.getStorageSync('sessionId');
	  // const token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvd3d3LnF6YWl3YW5nLmNvbSIsImlhdCI6MTU5MTI0MDg5NiwiZXhwIjoxNTkyMTA0ODk2LCJuYmYiOjE1OTEyNDA4OTYsInN1YiI6MTAwLCJwcnYiOiJlOWEzOWM4YWY2MDFmMjRjM2YwN2Y0NDYzMjJhNTZjODA1YzVjZGU2In0.gJTUiEVvMtHv8GGzUWZO_OSsG0hSrJ4sQDdCrtqQcTM';
       if (token) { // 如果存在token 配置请求头
         options.header = {
           'X-TOKEN' : token,
		   'Content-Type' : 'application/x-www-form-urlencoded',
         };
        }else{	// 不存在token 跳转至登录
           // uni.navigateTo({
           // 	url:'/pages/myCenter/logion'
           // })
		 //return;
        }
     } catch (err) {
      console.log(err)
    }
    // 这里对response进行处理，
    // 401表示登录状态过期，需重新登录
	options.complete = (response) => {
		if(response.data.code != 1000) {
			uni.showToast({
				title: response.data.msg,
				duration: 2500,
				icon: 'none'
			});
		}
		return;
	}
    return uni.request(options);
  }
export default request;
