代码管理/NEWCode/WIDESEAWCS_PDA/common/http.interceptor.js | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
代码管理/NEWCode/WIDESEAWCS_PDA/uview-ui/libs/request/index.js | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
´úÂë¹ÜÀí/NEWCode/WIDESEAWCS_PDA/common/http.interceptor.js
@@ -1,7 +1,6 @@ //let baseUrl ='http://192.168.1.54:8098' //'http://192.168.11.58:8098' // let baseUrl = 'http://192.168.12.240:8098' let baseUrl = 'http://127.0.0.1:9291' const install = (Vue, vm) => { // æ¤ä¸ºèªå®ä¹é ç½®åæ°ï¼å ·ä½åæ°è§ä¸æ¹è¯´æ Vue.prototype.$u.http.setConfig({ baseUrl: baseUrl, @@ -13,22 +12,13 @@ // è¯·æ±æ¦æªï¼é ç½®Tokençåæ° Vue.prototype.$u.http.interceptor.request = (config) => { // å¼ç¨token // æ¹å¼ä¸ï¼åæ¾å¨vuexçtokenï¼å设使ç¨äºuViewå°è£ çvuexæ¹å¼ // è§ï¼https://uviewui.com/components/globalVariable.html // config.header.token = vm.token; // 夿æ¯å¦ä¸ºå®æ´ URLï¼å¦ææ¯åä¸ä½¿ç¨ baseUrl if (config.url.includes('http://') || config.url.includes('https://')) { config.baseURL = ''; } else { config.baseURL = baseUrl; } // æ¹å¼äºï¼å¦ææ²¡æä½¿ç¨uViewå°è£ çvuexæ¹æ³ï¼é£ä¹éè¦ä½¿ç¨$store.stateè·å // config.header.token = vm.$store.state.token; // æ¹å¼ä¸ï¼å¦ætokenæ¾å¨äºglobalDataï¼éè¿getApp().globalDataè·å // config.header.token = getApp().globalData.username; // æ¹å¼åï¼å¦ætokenæ¾å¨äºStorageæ¬å°åå¨ä¸ï¼æ¦æªæ¯æ¯æ¬¡è¯·æ±é½æ§è¡ç // æä»¥åªææ¨éæ°ç»å½ä¿®æ¹äºStorageï¼ä¸ä¸æ¬¡ç请æ±å°ä¼æ¯ææ°å¼ // const token = uni.getStorageSync('token'); // config.header.token = token; console.log(2) config.header.Token = 'xxxxxx'; config.header.Authorization = "Bearer " + uni.getStorageSync('jo_id_token'); // å¯ä»¥å¯¹æä¸ªurlè¿è¡ç¹å«å¤çï¼æ¤urlåæ°ä¸ºthis.$u.get(url)ä¸çurlå¼ @@ -41,9 +31,7 @@ // ååºæ¦æªï¼å¤æç¶æç æ¯å¦éè¿ Vue.prototype.$u.http.interceptor.response = (res) => { console.log(1) if (res.statusCode == 200) { console.log(0) // res为æå¡ç«¯è¿åå¼ï¼å¯è½æcodeï¼resultçåæ®µ // è¿é对res.resultè¿è¡è¿åï¼å°ä¼å¨this.$u.post(url).then(res => {})çthenåè°ä¸çresçå° // 妿é ç½®äºoriginalData为trueï¼è¯·çæè¿éçè¿åå¼ @@ -79,38 +67,7 @@ url: '/pages/login/login' }); }) // uni.request({ // url: "http://192.168.12.245:8099/api/User/replaceToken", // param: {}, // method: 'POST', // responseType: "text", // header: { // Authorization: "Bearer " + vm.vuex_token // }, // async: false, // success: function(x) { // if (x.data.status) { // vm.$u.vuex('vuex_token',x.data.data) // vm.$u.route({ // type: "navigateBack", // delta: -1 // }) // } else { // console.log(x.data.message); // vm.$u.toast('éªè¯è¿æï¼è¯·éæ°ç»å½'); // setTimeout(() => { // // æ¤ä¸ºuViewçæ¹æ³ï¼è¯¦è§è·¯ç±ç¸å ³ææ¡£ // vm.$u.route('/pages/user/login') // }, 1500) // } // }, // errror: function(ex) { // console.log(ex); // uni.reLaunch({ // url: '/pages/user/login' // }); // }, // }); // return false; // return falseåä¸åè¿å ¥thenåè°ï¼ä½ä¼è¿å ¥catchåè° return false; } } ´úÂë¹ÜÀí/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