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.eyJpc3MiOiJodHRwczpcL1wvd3d3LnF6YWl3YW5nLmNvbSIsImlhdCI6MTU4OTMzNTEyOCwiZXhwIjoxNTkwMTk5MTI4LCJuYmYiOjE1ODkzMzUxMjgsInN1YiI6MTYsInBydiI6ImU5YTM5YzhhZjYwMWYyNGMzZjA3ZjQ0NjMyMmE1NmM4MDVjNWNkZTYifQ.Uec3pKa_Btj0u_6qR95YK_MzyhL9gEcczRd3FpG9xUg';
       if (token) { // 如果存在token 配置请求头
         options.header = {
           'X-TOKEN' : token,
		   'Content-Type' : 'application/x-www-form-urlencoded',
         };
        }else{	// 不存在token 跳转至登录
            return;
        }
     } catch (err) {
      console.log(err)
    }
    // 这里对response进行处理，
    // 401表示登录状态过期，需重新登录
	options.complete = (response) => {
		console.log(response)
		if(response.data.code != 1000) {
			uni.showToast({
				title: response.data.msg,
				duration: 2000,
				icon: 'none'
			});
		}
		return;
	}
    return uni.request(options);
  }
export default request;
