wanshenmean
2025-04-08 517fb253f39bf8120f9bed693d35349727ae650c
´úÂë¹ÜÀí/NEWCode/WIDESEAWCS_PDA/uview-ui/libs/request/index.js
@@ -15,7 +15,7 @@
         let interceptorRequest = this.interceptor.request(options);
         if (interceptorRequest === false) {
            // è¿”回一个处于pending状态中的Promise,来取消原promise,避免进入then()回调
            return new Promise(()=>{});
            return new Promise(() => {});
         }
         this.options = interceptorRequest;
      }
@@ -34,7 +34,7 @@
            clearTimeout(this.config.timer);
            this.config.timer = null;
            // åˆ¤æ–­ç”¨æˆ·å¯¹æ‹¦æˆªè¿”回数据的要求,如果originalData为true,返回所有的数据(response)到拦截器,否则只返回response.data
            if(this.config.originalData) {
            if (this.config.originalData) {
               // åˆ¤æ–­æ˜¯å¦å­˜åœ¨æ‹¦æˆªå™¨
               if (this.interceptor.response && typeof this.interceptor.response === 'function') {
                  let resInterceptors = this.interceptor.response(response);
@@ -51,7 +51,8 @@
               }
            } else {
               if (response.statusCode == 200) {
                  if (this.interceptor.response && typeof this.interceptor.response === 'function') {
                  if (this.interceptor.response && typeof this.interceptor.response ===
                     'function') {
                     let resInterceptors = this.interceptor.response(response.data);
                     if (resInterceptors !== false) {
                        resolve(resInterceptors);
@@ -74,14 +75,20 @@
            }
         }
         // åˆ¤æ–­ç”¨æˆ·ä¼ é€’çš„URL是否/开头,如果不是,加上/,这里使用了uView的test.js验证库的url()方法
         options.url = validate.url(options.url) ? options.url : (this.config.baseUrl + (options.url.indexOf('/') == 0 ?
            options.url : '/' + options.url));
         // åˆ¤æ–­æ˜¯å¦ä¸ºå®Œæ•´ URL,如果是则不使用 baseUrl
         if (options.url.includes('http://') || options.url.includes('https://')) {
            options.url = options.url;
         } else {
            // åˆ¤æ–­ç”¨æˆ·ä¼ é€’çš„URL是否/开头,如果不是,加上/,这里使用了uView的test.js验证库的url()方法
            options.url = validate.url(options.url) ? options.url : (this.config.baseUrl + (options.url
               .indexOf('/') == 0 ?
               options.url : '/' + options.url));
         }
         // æ˜¯å¦æ˜¾ç¤ºloading
         // åŠ ä¸€ä¸ªæ˜¯å¦å·²æœ‰timer定时器的判断,否则有两个同时请求的时候,后者会清除前者的定时器id
         // è€Œæ²¡æœ‰æ¸…除前者的定时器,导致前者超时,一直显示loading
         if(this.config.showLoading && !this.config.timer) {
         if (this.config.showLoading && !this.config.timer) {
            this.config.timer = setTimeout(() => {
               uni.showLoading({
                  title: this.config.loadingText,
@@ -116,7 +123,7 @@
         originalData: false, // æ˜¯å¦åœ¨æ‹¦æˆªå™¨ä¸­è¿”回服务端的原始数据,见文档说明
         loadingMask: true, // å±•示loading的时候,是否给一个透明的蒙层,防止触摸穿透
      }
      // æ‹¦æˆªå™¨
      this.interceptor = {
         // è¯·æ±‚前的拦截
@@ -144,7 +151,7 @@
            data
         })
      }
      // put请求,不支持支付宝小程序(HX2.6.15)
      this.put = (url, data = {}, header = {}) => {
         return this.request({
@@ -154,7 +161,7 @@
            data
         })
      }
      // delete请求,不支持支付宝和头条小程序(HX2.6.15)
      this.delete = (url, data = {}, header = {}) => {
         return this.request({
@@ -166,4 +173,4 @@
      }
   }
}
export default new Request
export default new Request