From 675f3f475a61dd0ad8ffb76e183baa9b78f14f45 Mon Sep 17 00:00:00 2001
From: renmingwang <renmingwang@hnkhzn.com>
Date: 星期一, 30 三月 2026 16:46:31 +0800
Subject: [PATCH] 修改任务下发

---
 项目代码/WMS/WIDESEA_WMSClient/src/api/http.js |  435 ++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 389 insertions(+), 46 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSClient/src/api/http.js" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSClient/src/api/http.js"
index 05cbb7e..75b844a 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSClient/src/api/http.js"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSClient/src/api/http.js"
@@ -1,3 +1,336 @@
+// import axios from 'axios'
+// import store from '../store/index'
+// // import {getCurrentInstance} from 'vue'
+// import { useRouter, useRoute } from 'vue-router'
+// const router = useRouter();
+// axios.defaults.timeout = 50000;
+// axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8';
+
+// import { ElLoading as Loading, ElMessage as Message } from 'element-plus';
+
+
+// let loadingInstance;
+// let loadingStatus = false;
+// http: //10.6.100.56:9290
+// if (process.env.NODE_ENV == 'development') {
+//     // axios.defaults.baseURL = 'http://10.6.100.142:9290';
+//     axios.defaults.baseURL = 'http://10.6.100.116:9290';
+// }
+// else if (process.env.NODE_ENV == 'debug') {
+//     axios.defaults.baseURL = 'http://10.6.100.116:9290';
+
+//     // axios.defaults.baseURL = 'http://127.0.0.1:9290';
+// }
+
+// else if (process.env.NODE_ENV == 'production') {
+//     axios.defaults.baseURL = 'http://10.6.100.116:9290';
+
+//     // axios.defaults.baseURL = 'http://127.0.0.1:9290';
+// }
+// if (!axios.defaults.baseURL.endsWith('/')) {
+//     axios.defaults.baseURL += "/";
+// }
+
+
+// let ipAddress = axios.defaults.baseURL;
+// axios.interceptors.request.use((config) => {
+//     return config;
+// }, (error) => {
+//     return Promise.reject(error);
+// });
+
+// axios.interceptors.response.use((res) => {
+
+//     closeLoading();
+
+//     checkResponse(res);
+
+//     return Promise.resolve(res);
+// }, (error) => {
+//     closeLoading();
+//     let httpMessage = '';
+//     if (error.response) {
+//         if (error.response.status == '401') {
+//             if (error.response.data && error.response.data.code == 401) {
+//                 if (!localStorage.getItem('user')) {
+//                     Message.error({
+//                         showClose: true,
+//                         message: '鐧婚檰宸茶繃鏈�',
+//                         type: 'error'
+//                     });
+//                 }
+//                 toLogin();
+//                 return;
+//             }
+
+//         }
+//         if (error.response.status == '404') {
+//             httpMessage = "鏈壘鍒拌姹傚湴鍧�";
+//         } else if (error.response.data && error.response.data.message) {
+//             httpMessage = error.response.data.message;
+//         }
+//     } else {
+//         httpMessage = '鏈嶅姟鍣ㄥ鐞嗗紓甯�'
+//     }
+//     redirect(httpMessage);
+//     return Promise.reject(error.response || {}, httpMessage);
+// });
+
+// function closeLoading() {
+//     if (loadingInstance) {
+//         loadingInstance.close();
+//     }
+//     if (loadingStatus) {
+//         loadingStatus = false;
+//         if (loadingInstance) {
+//             loadingInstance.close();
+//         }
+//     }
+
+// }
+
+// function checkResponse(res) {
+//     //鍒锋柊token
+//     if (!res.headers) {
+//         if (res.getResponseHeader("widesea_exp") == "1") {
+//             replaceToken();
+//         }
+//     } else if (res.headers.widesea_exp == "1") {
+//         replaceToken();
+//     }
+// }
+
+// const _Authorization = 'Authorization';
+
+// function showLoading(loading) {
+//     if (!loading || loadingStatus) {
+//         return;
+//     }
+//     loadingInstance = Loading.service({
+//         lock: true,
+//         text: 'Loading',
+//         customClass: "http-loading",
+//         background: typeof loading == "string" ? loading : '姝e湪澶勭悊.....',
+//         background: 'rgba(58, 61, 63, 0.32)'
+//     });
+// }
+
+// function getToken() {
+//     return store.getters.getToken();
+// }
+
+// /*
+//   url
+//   params璇锋眰鍚庡彴鐨勫弬鏁�,濡傦細{name:123,values:['a','b','c']}
+//   loading鏄惁鏄剧ず閬僵灞�,鍙互浼犲叆true.false.鍙婃彁绀烘枃鏈�
+//   config閰嶇疆淇℃伅,濡倇timeout:3000,headers:{token:123}}
+// */
+// function post(url, params, loading, config) {
+//     showLoading(loading);
+//     axios.defaults.headers[_Authorization] = getToken();
+//     return new Promise((resolve, reject) => {
+//         axios.post(url, params, config)
+//             .then(response => {
+//                 resolve(response.data);
+//             }, err => {
+//                 reject(err && err.data && err.data.message ? err.data.message : '鏈嶅姟鍣ㄥ鐞嗗紓甯�');
+//             })
+//             .catch((error) => {
+//                 reject(error)
+//             })
+//     })
+// }
+
+// //=true寮傛璇锋眰鏃朵細鏄剧ず閬僵灞�,=瀛楃涓诧紝寮傛璇锋眰鏃堕伄缃╁眰鏄剧ず褰撳墠瀛楃涓�
+// function get(url, param, loading, config) {
+//     showLoading(loading);
+//     axios.defaults.headers[_Authorization] = getToken();
+//     return new Promise((resolve, reject) => {
+//         axios.get(url, config)
+//             .then(response => {
+//                 // console.log(response)
+//                 resolve(response.data)
+//             }, err => {
+//                 reject(err)
+//             })
+//             .catch((error) => {
+//                 reject(error)
+//             })
+//     })
+// }
+
+// //url:url鍦板潃
+// //params:璇锋眰鍙傛暟
+// //fileName:涓嬭浇鐨勬枃浠跺悕
+// //loading:鏄惁鏄剧ず鍔犺浇鐘舵��
+// function download(url, params, fileName, loading, callback) {
+//     fileName = fileName.replace(">", "锛�").replace("<", "锛�");
+//     post(url, params, loading, { responseType: 'blob' }).then(content => {
+//         const blob = new Blob([content])
+//         if ('download' in document.createElement('a')) { // 闈濱E涓嬭浇
+//             const elink = document.createElement('a')
+//             elink.download = fileName
+//             elink.style.display = 'none'
+//             elink.href = URL.createObjectURL(blob)
+//             document.body.appendChild(elink)
+//             elink.click()
+//             URL.revokeObjectURL(elink.href) // 閲婃斁URL 瀵硅薄
+//             document.body.removeChild(elink)
+//         } else { // IE10+涓嬭浇
+//             navigator.msSaveBlob(blob, fileName)
+//         }
+//         callback && callback();
+//     })
+// }
+
+
+// function createXHR() {
+//     if (XMLHttpRequest) {
+//         return new XMLHttpRequest();
+//     }
+//     if (ActiveXObject) {
+//         if (typeof arguments.callee.activeXString != "string") {
+//             var versions = [
+//                 "MSXML2.XMLHttp.6.0",
+//                 "MSXML2.XMLHttp",
+//                 "MSXML2.XMLHttp.3.0"
+//             ];
+//             for (var i = 0; i < versions.length; i++) {
+//                 try {
+//                     new ActiveXObject(versions[i]);
+//                     arguments.callee.activeXString = versions[i];
+//                     break;
+//                 } catch (e) {
+//                     console.log(e);
+//                 }
+//             }
+//         }
+//         return new ActiveXObject(arguments.callee.activeXString);
+//     }
+// }
+
+// function redirect(responseText, message) {
+//     try {
+//         let responseData = typeof responseText == 'string' ? JSON.parse(responseText) : responseText;
+//         if ((responseData.hasOwnProperty('code') && responseData.code == 401) ||
+//             (responseData.data && responseData.data.code == 401)) {
+//             closeLoading();
+//             toLogin();
+//         } else {
+//             if (message) {
+//                 Message.error({
+//                     showClose: true,
+//                     message: message,
+//                     type: 'error'
+//                 });
+//             }
+//         }
+//     } catch (error) {
+//         console.log(error);
+//         Message.error({
+//             showClose: true,
+//             message: responseText,
+//             type: 'error'
+//         });
+//     }
+// }
+
+
+// function toLogin() {
+//     //  const vueinstance=  getCurrentInstance();
+//     if (window.location.hash) {
+//         window.location.href = window.location.origin + '/#/login'
+//         return
+//     }
+//     window.location.href = window.location.origin + '/login'
+//         //  router.push({ path: '/login', params: { r: Math.random() } });
+// }
+// //鍔ㄦ�佸埛鏂皌oken
+// function replaceToken() {
+//     ajax({
+//         url: "/api/User/replaceToken",
+//         param: {},
+//         json: true,
+//         success: function(x) {
+//             if (x.status) {
+//                 let userInfo = store.getters.getUserInfo();
+//                 userInfo.token = x.data;
+//                 store.commit('setUserInfo', userInfo);
+//             } else {
+//                 console.log(x.message);
+//                 toLogin();
+//             }
+//         },
+//         errror: function(ex) {
+//             console.log(ex);
+//             toLogin();
+//         },
+//         type: "post",
+//         async: false
+//     });
+
+
+// }
+
+// function ajax(param) {
+//     let httpParam =
+//         Object.assign({
+//             url: '',
+//             headers: {},
+//             param: {},
+//             json: true,
+//             success: function() {},
+//             errror: function() {},
+//             type: 'post',
+//             async: true
+//         }, param);
+
+//     httpParam.url = axios.defaults.baseURL + httpParam.url.replace(/\/?/, '');
+//     httpParam.headers[_Authorization] = getToken();
+//     var xhr = createXHR();
+//     xhr.onreadystatechange = function() {
+//         if (xhr.status == 403 || xhr.status == 401) {
+//             redirect(xhr.responseText);
+//             return;
+//         }
+//         checkResponse(xhr);
+//         if (xhr.readyState == 4 && xhr.status == 200) {
+//             httpParam.success(httpParam.json ? JSON.parse(xhr.responseText) : xhr.responseText);
+//             return;
+//         }
+//         if (xhr.status != 0 && xhr.readyState != 1) {
+//             httpParam.errror(xhr);
+//         }
+//     };
+//     //鍒濆鍖栬姹�
+//     xhr.open(
+//         httpParam.type,
+//         httpParam.url,
+//         httpParam.async
+//     );
+//     xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
+//     for (const key in httpParam.headers) {
+//         xhr.setRequestHeader(key, httpParam.headers[key]);
+//     }
+//     let dataStr = '';
+//     for (const key in httpParam.param) {
+//         dataStr += key + "=" + httpParam.param[key];
+//     }
+//     try {
+//         xhr.send(dataStr);
+//     } catch (error) {
+//         toLogin();
+//     }
+// }
+
+// ajax.post = function(url, param, success, errror) {
+//     ajax({ url: url, param: param, success: success, error: errror, type: 'post' })
+// }
+// ajax.get = function(url, param, success, errror) {
+//     ajax({ url: url, param: param, success: success, error: errror, type: 'get' })
+// }
+// export default { post, get, download, ajax, ipAddress }
+//-------------
 import axios from 'axios'
 import store from '../store/index'
 // import {getCurrentInstance} from 'vue'
@@ -12,20 +345,19 @@
 let loadingInstance;
 let loadingStatus = false;
 if (process.env.NODE_ENV == 'development') {
-    // axios.defaults.baseURL = 'http://10.168.1.226:9290';
+    // axios.defaults.baseURL = 'http://10.6.100.142:9290';
     axios.defaults.baseURL = 'http://127.0.0.1:9290';
-}
-else if (process.env.NODE_ENV == 'debug') {
-    // axios.defaults.baseURL = 'http://10.168.1.226:9290';
-    axios.defaults.baseURL = 'http://127.0.0.1:9290';
-}
+} else if (process.env.NODE_ENV == 'debug') {
+    axios.defaults.baseURL = 'http://10.6.100.116:9290';
 
-else if (process.env.NODE_ENV == 'production') {
-    axios.defaults.baseURL = 'http://10.168.1.226:9290';
+    // axios.defaults.baseURL = 'http://127.0.0.1:9290';
+} else if (process.env.NODE_ENV == 'production') {
+    axios.defaults.baseURL = 'http://10.6.100.116:9290';
+
     // axios.defaults.baseURL = 'http://127.0.0.1:9290';
 }
 if (!axios.defaults.baseURL.endsWith('/')) {
-    axios.defaults.baseURL+="/";
+    axios.defaults.baseURL += "/";
 }
 
 
@@ -62,19 +394,27 @@
 
         }
         if (error.response.status == '404') {
-            httpMessage = "鏈壘鍒拌姹傚湴鍧�";
-        }
-        else if (error.response.data && error.response.data.message) {
+            httpMessage = `API璇锋眰鍦板潃鏈壘鍒�: ${error.config.url}`;
+        } else if (error.response.data && error.response.data.message) {
             httpMessage = error.response.data.message;
+        } else {
+            httpMessage = `鏈嶅姟鍣ㄩ敊璇� ${error.response.status}: ${error.response.statusText}`;
         }
+    } else if (error.request) {
+        // 璇锋眰宸插彂鍑猴紝浣嗘病鏈夋敹鍒板搷搴�
+        httpMessage = `鏃犳硶杩炴帴鍒版湇鍔″櫒: ${axios.defaults.baseURL}`;
+    } else {
+        httpMessage = `璇锋眰閿欒: ${error.message}`;
     }
-    else {
-        httpMessage = '鏈嶅姟鍣ㄥ鐞嗗紓甯�'
-    }
-    redirect(httpMessage);
+    Message.error({
+        showClose: true,
+        message: httpMessage,
+        type: 'error'
+    });
     return Promise.reject(error.response || {}, httpMessage);
 });
-function closeLoading () {
+
+function closeLoading() {
     if (loadingInstance) {
         loadingInstance.close();
     }
@@ -86,34 +426,34 @@
     }
 
 }
-function checkResponse (res) {
+
+function checkResponse(res) {
     //鍒锋柊token
     if (!res.headers) {
         if (res.getResponseHeader("widesea_exp") == "1") {
             replaceToken();
         }
-    }
-    else if (res.headers.widesea_exp == "1") {
+    } else if (res.headers.widesea_exp == "1") {
         replaceToken();
     }
 }
 
 const _Authorization = 'Authorization';
 
-function showLoading (loading) {
+function showLoading(loading) {
     if (!loading || loadingStatus) {
         return;
     }
     loadingInstance = Loading.service({
         lock: true,
         text: 'Loading',
-        customClass:"http-loading",
+        customClass: "http-loading",
         background: typeof loading == "string" ? loading : '姝e湪澶勭悊.....',
         background: 'rgba(58, 61, 63, 0.32)'
     });
 }
 
-function getToken () {
+function getToken() {
     return store.getters.getToken();
 }
 
@@ -123,7 +463,7 @@
   loading鏄惁鏄剧ず閬僵灞�,鍙互浼犲叆true.false.鍙婃彁绀烘枃鏈�
   config閰嶇疆淇℃伅,濡倇timeout:3000,headers:{token:123}}
 */
-function post (url, params, loading, config) {
+function post(url, params, loading, config) {
     showLoading(loading);
     axios.defaults.headers[_Authorization] = getToken();
     return new Promise((resolve, reject) => {
@@ -140,7 +480,7 @@
 }
 
 //=true寮傛璇锋眰鏃朵細鏄剧ず閬僵灞�,=瀛楃涓诧紝寮傛璇锋眰鏃堕伄缃╁眰鏄剧ず褰撳墠瀛楃涓�
-function get (url, param, loading, config) {
+function get(url, param, loading, config) {
     showLoading(loading);
     axios.defaults.headers[_Authorization] = getToken();
     return new Promise((resolve, reject) => {
@@ -161,7 +501,7 @@
 //params:璇锋眰鍙傛暟
 //fileName:涓嬭浇鐨勬枃浠跺悕
 //loading:鏄惁鏄剧ず鍔犺浇鐘舵��
-function download (url, params, fileName, loading,callback) {
+function download(url, params, fileName, loading, callback) {
     fileName = fileName.replace(">", "锛�").replace("<", "锛�");
     post(url, params, loading, { responseType: 'blob' }).then(content => {
         const blob = new Blob([content])
@@ -177,12 +517,12 @@
         } else { // IE10+涓嬭浇
             navigator.msSaveBlob(blob, fileName)
         }
-        callback&&callback();
+        callback && callback();
     })
 }
 
 
-function createXHR () {
+function createXHR() {
     if (XMLHttpRequest) {
         return new XMLHttpRequest();
     }
@@ -207,11 +547,11 @@
     }
 }
 
-function redirect (responseText, message) {
+function redirect(responseText, message) {
     try {
         let responseData = typeof responseText == 'string' ? JSON.parse(responseText) : responseText;
-        if ((responseData.hasOwnProperty('code') && responseData.code == 401)
-            || (responseData.data && responseData.data.code == 401)) {
+        if ((responseData.hasOwnProperty('code') && responseData.code == 401) ||
+            (responseData.data && responseData.data.code == 401)) {
             closeLoading();
             toLogin();
         } else {
@@ -234,22 +574,22 @@
 }
 
 
-function toLogin () {
+function toLogin() {
     //  const vueinstance=  getCurrentInstance();
     if (window.location.hash) {
         window.location.href = window.location.origin + '/#/login'
         return
     }
     window.location.href = window.location.origin + '/login'
-    //  router.push({ path: '/login', params: { r: Math.random() } });
+        //  router.push({ path: '/login', params: { r: Math.random() } });
 }
 //鍔ㄦ�佸埛鏂皌oken
-function replaceToken () {
+function replaceToken() {
     ajax({
         url: "/api/User/replaceToken",
         param: {},
         json: true,
-        success: function (x) {
+        success: function(x) {
             if (x.status) {
                 let userInfo = store.getters.getUserInfo();
                 userInfo.token = x.data;
@@ -259,7 +599,7 @@
                 toLogin();
             }
         },
-        errror: function (ex) {
+        errror: function(ex) {
             console.log(ex);
             toLogin();
         },
@@ -270,20 +610,23 @@
 
 }
 
-function ajax (param) {
+function ajax(param) {
     let httpParam =
         Object.assign({
-            url: '', headers: {},
-            param: {}, json: true,
-            success: function () { },
-            errror: function () { },
-            type: 'post', async: true
+            url: '',
+            headers: {},
+            param: {},
+            json: true,
+            success: function() {},
+            errror: function() {},
+            type: 'post',
+            async: true
         }, param);
 
     httpParam.url = axios.defaults.baseURL + httpParam.url.replace(/\/?/, '');
     httpParam.headers[_Authorization] = getToken();
     var xhr = createXHR();
-    xhr.onreadystatechange = function () {
+    xhr.onreadystatechange = function() {
         if (xhr.status == 403 || xhr.status == 401) {
             redirect(xhr.responseText);
             return;
@@ -318,10 +661,10 @@
     }
 }
 
-ajax.post = function (url, param, success, errror) {
+ajax.post = function(url, param, success, errror) {
     ajax({ url: url, param: param, success: success, error: errror, type: 'post' })
 }
-ajax.get = function (url, param, success, errror) {
+ajax.get = function(url, param, success, errror) {
     ajax({ url: url, param: param, success: success, error: errror, type: 'get' })
 }
-export default { post, get,download, ajax, ipAddress }
+export default { post, get, download, ajax, ipAddress }
\ No newline at end of file

--
Gitblit v1.9.3