From 6cc35000a6e138cfad96e7b02f8aeddcdb4ba6bf Mon Sep 17 00:00:00 2001 From: wankeda <Administrator@DESKTOP-HAU3ST3> Date: 星期二, 24 六月 2025 09:57:25 +0800 Subject: [PATCH] 代码提交 --- 代码管理/NEWCode/WIDESEAWCS_PDA/common/http.interceptor.js | 89 ++++++++++++++++++-------------------------- 1 files changed, 36 insertions(+), 53 deletions(-) diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/NEWCode/WIDESEAWCS_PDA/common/http.interceptor.js" "b/\344\273\243\347\240\201\347\256\241\347\220\206/NEWCode/WIDESEAWCS_PDA/common/http.interceptor.js" index 1c5f2b4..5f5376b 100644 --- "a/\344\273\243\347\240\201\347\256\241\347\220\206/NEWCode/WIDESEAWCS_PDA/common/http.interceptor.js" +++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/NEWCode/WIDESEAWCS_PDA/common/http.interceptor.js" @@ -1,10 +1,10 @@ -//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' +let baseUrl = '' +const value = uni.getStorageSync('storage_key_ipAddress'); const install = (Vue, vm) => { + let resolvedBaseUrl = baseUrl === '' ? (value && value.WCSIP ? value.WCSIP : "") : baseUrl; // 姝や负鑷畾涔夐厤缃弬鏁帮紝鍏蜂綋鍙傛暟瑙佷笂鏂硅鏄� Vue.prototype.$u.http.setConfig({ - baseUrl: baseUrl, + baseUrl: resolvedBaseUrl, loadingText: '鍔姏鍔犺浇涓瓇', loadingTime: 5000, originalData: true, @@ -13,22 +13,38 @@ // 璇锋眰鎷︽埅锛岄厤缃甌oken绛夊弬鏁� Vue.prototype.$u.http.interceptor.request = (config) => { - // 寮曠敤token - // 鏂瑰紡涓�锛屽瓨鏀惧湪vuex鐨則oken锛屽亣璁句娇鐢ㄤ簡uView灏佽鐨剉uex鏂瑰紡 - // 瑙侊細https://uviewui.com/components/globalVariable.html - // config.header.token = vm.token; + // 鍒ゆ柇鏄惁涓哄畬鏁� URL锛屽鏋滄槸鍒欎笉浣跨敤 baseUrl + if (resolvedBaseUrl === '') { + if (config.url.includes('http://') || config.url.includes('https://')) { + config.baseURL = ''; + resolve(config); + } else { + const storedValue = uni.getStorageSync('storage_key_ipAddress'); + if (storedValue && storedValue.WCSIP) { + config.baseURL = storedValue.WCSIP; + baseUrl = storedValue.WCSIP; + } else { + vm.$u.toast('璇峰厛娣诲姞鍚庡彴IP鍦板潃'); + return false; // 鍙栨秷鏈璇锋眰 + } + // uni.getStorage({ + // key: 'storage_key_ipAddress', + // success: (res) => { + // debugger; + // console.log(res.data.WCSIP); + // config.baseURL = res.data.WCSIP; + // baseUrl = res.data.WCSIP + // }, + // fail: (err) => { + // debugger; + // vm.$u.toast('璇峰厛娣诲姞鍚庡彴IP鍦板潃'); + // }, + // }); + } + } else { + config.baseURL = resolvedBaseUrl; + } - // 鏂瑰紡浜岋紝濡傛灉娌℃湁浣跨敤uView灏佽鐨剉uex鏂规硶锛岄偅涔堥渶瑕佷娇鐢�$store.state鑾峰彇 - // config.header.token = vm.$store.state.token; - - // 鏂瑰紡涓夛紝濡傛灉token鏀惧湪浜唃lobalData锛岄�氳繃getApp().globalData鑾峰彇 - // config.header.token = getApp().globalData.username; - - // 鏂瑰紡鍥涳紝濡傛灉token鏀惧湪浜哠torage鏈湴瀛樺偍涓紝鎷︽埅鏄瘡娆¤姹傞兘鎵ц鐨� - // 鎵�浠ュ摢鎬曟偍閲嶆柊鐧诲綍淇敼浜哠torage锛屼笅涓�娆$殑璇锋眰灏嗕細鏄渶鏂板�� - // 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'); // 鍙互瀵规煇涓猽rl杩涜鐗瑰埆澶勭悊锛屾url鍙傛暟涓簍his.$u.get(url)涓殑url鍊� @@ -41,9 +57,7 @@ // 鍝嶅簲鎷︽埅锛屽垽鏂姸鎬佺爜鏄惁閫氳繃 Vue.prototype.$u.http.interceptor.response = (res) => { - console.log(1) if (res.statusCode == 200) { - console.log(0) // res涓烘湇鍔$杩斿洖鍊硷紝鍙兘鏈塩ode锛宺esult绛夊瓧娈� // 杩欓噷瀵箁es.result杩涜杩斿洖锛屽皢浼氬湪this.$u.post(url).then(res => {})鐨則hen鍥炶皟涓殑res鐨勫埌 // 濡傛灉閰嶇疆浜唎riginalData涓簍rue锛岃鐣欐剰杩欓噷鐨勮繑鍥炲�� @@ -79,38 +93,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鍚庝笉鍐嶈繘鍏hen鍥炶皟锛屼絾浼氳繘鍏atch鍥炶皟 return false; } } -- Gitblit v1.9.3