Authored by 王涛

请求工具类优化,使大屏能单独使用;

  1 +import __global from "./global.js";
1 let http = { 2 let http = {
2 - proxy: null,  
3 isJson: function (obj) { 3 isJson: function (obj) {
4 var isjson = typeof (obj) == "object" && Object.prototype.toString.call(obj).toLowerCase() == 4 var isjson = typeof (obj) == "object" && Object.prototype.toString.call(obj).toLowerCase() ==
5 "[object object]" && 5 "[object object]" &&
@@ -14,23 +14,41 @@ let http = { @@ -14,23 +14,41 @@ let http = {
14 window.top.location.reload(); 14 window.top.location.reload();
15 //window.top.location.href = localStorage.getItem('loginUrl'); 15 //window.top.location.href = localStorage.getItem('loginUrl');
16 } else { 16 } else {
17 - http.proxy.$global.showMsg("服务异常,请联系管理员!","error"); 17 + __global.showMsg("服务异常,请联系管理员!","error");
18 } 18 }
19 }catch (e){ 19 }catch (e){
20 } 20 }
21 }, 21 },
22 - post: function (requestUrl, data, callback, errFunc,showLoadding,setToken) {  
23 - if (http.proxy == null) {  
24 - const {proxy} = Vue.getCurrentInstance()  
25 - http.proxy = proxy; 22 + getUrl: function (){
  23 + let gateWay = http.getGateWay();
  24 + if (gateWay && gateWay != null && gateWay != '') {
  25 + return;
26 } 26 }
  27 + http.get(window.location.origin + '/config/getConfig',{configName:'url'},function(res){
  28 + console.log(res);
  29 + debugger;
  30 + sessionStorage.setItem('domainName', res.gateway);
  31 + // sessionStorage.setItem('domainInspectionURI', res.inspection_web);
  32 + // sessionStorage.setItem('domainAssetsManage', res.assetsweb);
  33 + // sessionStorage.setItem('graphEditorOrigin', res.mxgraph_editor);
  34 + // sessionStorage.setItem('tingyun', res.tingyun);
  35 + // sessionStorage.setItem('bigScreen', res.bigScreen);
  36 + // sessionStorage.setItem('sxView', res.sxView);
  37 + // sessionStorage.setItem('workflow', res.workflow);
  38 + // sessionStorage.setItem('mp3', res.mp3);
  39 + // sessionStorage.setItem('jimuReport', res.jimuReport);
  40 + // sessionStorage.setItem('cmdbWeb', res.cmdbWeb);
  41 + })
  42 + },
  43 + post: function (requestUrl, data, callback, errFunc,showLoadding,setToken) {
  44 +
27 // 默认展示加载狂 45 // 默认展示加载狂
28 if(showLoadding == undefined){ 46 if(showLoadding == undefined){
29 showLoadding = true; 47 showLoadding = true;
30 } 48 }
31 let loading = null; 49 let loading = null;
32 if(showLoadding && showLoadding == true){ 50 if(showLoadding && showLoadding == true){
33 - loading = http.proxy.$global.showLoading(); 51 + loading = __global.showLoading();
34 } 52 }
35 if(setToken == undefined || setToken == true){ 53 if(setToken == undefined || setToken == true){
36 var access_token = 'access_token=' + http.getToken(); 54 var access_token = 'access_token=' + http.getToken();
@@ -41,7 +59,7 @@ let http = { @@ -41,7 +59,7 @@ let http = {
41 } 59 }
42 } 60 }
43 $.ajax({ 61 $.ajax({
44 - url: sessionStorage.getItem('domainName') + requestUrl, 62 + url: http.getGateWay() + requestUrl,
45 method: "post", 63 method: "post",
46 processData: false, 64 processData: false,
47 contentType: "application/json;charset=UTF-8", 65 contentType: "application/json;charset=UTF-8",
@@ -72,17 +90,14 @@ let http = { @@ -72,17 +90,14 @@ let http = {
72 90
73 }, 91 },
74 get: function (requestUrl, data, callback, errFunc,showLoadding,setToken) { 92 get: function (requestUrl, data, callback, errFunc,showLoadding,setToken) {
75 - if (http.proxy == null) {  
76 - const {proxy} = Vue.getCurrentInstance()  
77 - http.proxy = proxy;  
78 - } 93 +
79 // 默认展示加载狂 94 // 默认展示加载狂
80 if(showLoadding == undefined){ 95 if(showLoadding == undefined){
81 showLoadding = true; 96 showLoadding = true;
82 } 97 }
83 let loading = null; 98 let loading = null;
84 if(showLoadding == true){ 99 if(showLoadding == true){
85 - loading = http.proxy.$global.showLoading(); 100 + loading = __global.showLoading();
86 } 101 }
87 let header = {}; 102 let header = {};
88 if(setToken == undefined || setToken == true){ 103 if(setToken == undefined || setToken == true){
@@ -99,7 +114,7 @@ let http = { @@ -99,7 +114,7 @@ let http = {
99 } 114 }
100 115
101 $.ajax({ 116 $.ajax({
102 - url: sessionStorage.getItem('domainName') + requestUrl, 117 + url: http.getGateWay() + requestUrl,
103 method: "get", 118 method: "get",
104 headers: header, 119 headers: header,
105 data: data, 120 data: data,
@@ -128,11 +143,7 @@ let http = { @@ -128,11 +143,7 @@ let http = {
128 }, 143 },
129 144
130 uploadFile(requestUrl, parmas,callback) { 145 uploadFile(requestUrl, parmas,callback) {
131 - if (http.proxy == null) {  
132 - const {proxy} = Vue.getCurrentInstance()  
133 - http.proxy = proxy;  
134 - }  
135 - const loading = http.proxy.$global.showLoading(); 146 + const loading = __global.showLoading();
136 var access_token = 'access_token=' + http.getToken(); 147 var access_token = 'access_token=' + http.getToken();
137 if (requestUrl.indexOf('?') == -1) { 148 if (requestUrl.indexOf('?') == -1) {
138 requestUrl += '?' + access_token; 149 requestUrl += '?' + access_token;
@@ -146,7 +157,7 @@ let http = { @@ -146,7 +157,7 @@ let http = {
146 })(parmas); 157 })(parmas);
147 158
148 $.ajax({ 159 $.ajax({
149 - url: sessionStorage.getItem('domainName') + requestUrl, 160 + url: http.getGateWay() + requestUrl,
150 type: 'POST', 161 type: 'POST',
151 processData: false, 162 processData: false,
152 mimeType: "multipart/form-data", 163 mimeType: "multipart/form-data",
@@ -157,7 +168,7 @@ let http = { @@ -157,7 +168,7 @@ let http = {
157 loading.close(); 168 loading.close();
158 // console.log("==>", requestUrl, xhr, textStatus) 169 // console.log("==>", requestUrl, xhr, textStatus)
159 http.reqErr(xhr); 170 http.reqErr(xhr);
160 - http.proxy.$global.showMsg("上传失败,请您确认文件是否存在!","error"); 171 + __global.showMsg("上传失败,请您确认文件是否存在!","error");
161 172
162 }, 173 },
163 success: function (data, textStatus, jqXHR) { 174 success: function (data, textStatus, jqXHR) {
@@ -187,11 +198,16 @@ let http = { @@ -187,11 +198,16 @@ let http = {
187 return `${keys}`; 198 return `${keys}`;
188 } 199 }
189 let p = formart(parmas); 200 let p = formart(parmas);
190 - window.open(sessionStorage.getItem('domainName') + requestUrl + "&" + p); 201 + window.open( http.getGateWay() + requestUrl + "&" + p);
191 }, 202 },
192 getToken() { 203 getToken() {
193 return localStorage.getItem('access_token'); 204 return localStorage.getItem('access_token');
194 }, 205 },
  206 + getGateWay () {
  207 + let gateway = sessionStorage.getItem('domainName');
  208 + return gateway == null ? '' : gateway;
  209 + }
195 } 210 }
196 - 211 +// 获取url
  212 +http.getUrl();
197 export default http 213 export default http