From 517fb253f39bf8120f9bed693d35349727ae650c Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期二, 08 四月 2025 09:35:18 +0800
Subject: [PATCH] PDA添加完整URL判断
---
代码管理/NEWCode/WIDESEAWCS_PDA/uview-ui/libs/request/index.js | 31 +++++++++------
代码管理/NEWCode/WIDESEAWCS_PDA/common/http.interceptor.js | 59 ++++-------------------------
2 files changed, 27 insertions(+), 63 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..186e70a 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,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 @@
// 璇锋眰鎷︽埅锛岄厤缃甌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 (config.url.includes('http://') || config.url.includes('https://')) {
+ config.baseURL = '';
+ } else {
+ config.baseURL = baseUrl;
+ }
- // 鏂瑰紡浜岋紝濡傛灉娌℃湁浣跨敤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 +31,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 +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鍚庝笉鍐嶈繘鍏hen鍥炶皟锛屼絾浼氳繘鍏atch鍥炶皟
return false;
}
}
diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/NEWCode/WIDESEAWCS_PDA/uview-ui/libs/request/index.js" "b/\344\273\243\347\240\201\347\256\241\347\220\206/NEWCode/WIDESEAWCS_PDA/uview-ui/libs/request/index.js"
index 1f5f471..c07f38a 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/NEWCode/WIDESEAWCS_PDA/uview-ui/libs/request/index.js"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/NEWCode/WIDESEAWCS_PDA/uview-ui/libs/request/index.js"
@@ -15,7 +15,7 @@
let interceptorRequest = this.interceptor.request(options);
if (interceptorRequest === false) {
// 杩斿洖涓�涓浜巔ending鐘舵�佷腑鐨凱romise锛屾潵鍙栨秷鍘焢romise锛岄伩鍏嶈繘鍏hen()鍥炶皟
- return new Promise(()=>{});
+ return new Promise(() => {});
}
this.options = interceptorRequest;
}
@@ -34,7 +34,7 @@
clearTimeout(this.config.timer);
this.config.timer = null;
// 鍒ゆ柇鐢ㄦ埛瀵规嫤鎴繑鍥炴暟鎹殑瑕佹眰锛屽鏋渙riginalData涓簍rue锛岃繑鍥炴墍鏈夌殑鏁版嵁(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鐨則est.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鐨則est.js楠岃瘉搴撶殑url()鏂规硶
+ options.url = validate.url(options.url) ? options.url : (this.config.baseUrl + (options.url
+ .indexOf('/') == 0 ?
+ options.url : '/' + options.url));
+ }
+
// 鏄惁鏄剧ずloading
// 鍔犱竴涓槸鍚﹀凡鏈塼imer瀹氭椂鍣ㄧ殑鍒ゆ柇锛屽惁鍒欐湁涓や釜鍚屾椂璇锋眰鐨勬椂鍊欙紝鍚庤�呬細娓呴櫎鍓嶈�呯殑瀹氭椂鍣╥d
// 鑰屾病鏈夋竻闄ゅ墠鑰呯殑瀹氭椂鍣紝瀵艰嚧鍓嶈�呰秴鏃讹紝涓�鐩存樉绀簂oading
- 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, // 鏄惁鍦ㄦ嫤鎴櫒涓繑鍥炴湇鍔$鐨勫師濮嬫暟鎹紝瑙佹枃妗h鏄�
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
\ No newline at end of file
--
Gitblit v1.9.3