| | |
| | | let interceptorRequest = this.interceptor.request(options); |
| | | if (interceptorRequest === false) { |
| | | // è¿åä¸ä¸ªå¤äºpendingç¶æä¸çPromiseï¼æ¥åæ¶åpromiseï¼é¿å
è¿å
¥then()åè° |
| | | return new Promise(()=>{}); |
| | | return new Promise(() => {}); |
| | | } |
| | | this.options = interceptorRequest; |
| | | } |
| | |
| | | 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); |
| | |
| | | } |
| | | } 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); |
| | |
| | | } |
| | | } |
| | | |
| | | // å¤æç¨æ·ä¼ éç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, |
| | |
| | | originalData: false, // æ¯å¦å¨æ¦æªå¨ä¸è¿åæå¡ç«¯çåå§æ°æ®ï¼è§ææ¡£è¯´æ |
| | | loadingMask: true, // å±ç¤ºloadingçæ¶åï¼æ¯å¦ç»ä¸ä¸ªéæçèå±ï¼é²æ¢è§¦æ¸ç©¿é |
| | | } |
| | | |
| | | |
| | | // æ¦æªå¨ |
| | | this.interceptor = { |
| | | // 请æ±åçæ¦æª |
| | |
| | | data |
| | | }) |
| | | } |
| | | |
| | | |
| | | // put请æ±ï¼ä¸æ¯ææ¯ä»å®å°ç¨åº(HX2.6.15) |
| | | this.put = (url, data = {}, header = {}) => { |
| | | return this.request({ |
| | |
| | | data |
| | | }) |
| | | } |
| | | |
| | | |
| | | // delete请æ±ï¼ä¸æ¯ææ¯ä»å®å头æ¡å°ç¨åº(HX2.6.15) |
| | | this.delete = (url, data = {}, header = {}) => { |
| | | return this.request({ |
| | |
| | | } |
| | | } |
| | | } |
| | | export default new Request |
| | | export default new Request |