ah_jjzhgd_webscreen/api/commonRequest.js

187 lines
5.6 KiB
JavaScript
Raw Normal View History

2025-07-24 20:08:34 +08:00
let aqEnnable = false; // 参数加密开关
2024-04-16 16:40:54 +08:00
//后端路径
2025-04-01 11:16:23 +08:00
// const commonUrl = "http://11.158.16.194:21624/zhgd/";
// const URL_IP="http://11.158.16.194:21624/zhgd-web"
2025-05-21 10:29:02 +08:00
// const commonUrl = "http://192.168.1.107:13030/zhgd/";
2025-07-17 09:30:49 +08:00
// const URL_IP="http://192.168.0.38:21624/zhgd-web"
//const URL_IP="http://sgwpdm.ah.sgcc.com.cn/jjgdweb/zhgd-web"
2025-07-24 00:04:42 +08:00
//const URL_IP="http://sgwpdm.ah.sgcc.com.cn/ahsfs/zhgd-web"
2024-08-22 17:00:16 +08:00
//前端
2025-07-24 20:08:34 +08:00
const URL_IP = "http://127.0.0.1:13030/ah_jjzhgd_webscreen";
2025-07-17 09:30:49 +08:00
// const commonUrl = "http://192.168.0.38:13030/zhgd/";
2025-07-24 20:08:34 +08:00
const commonUrl = "http://192.168.2.72:13030/zhgd/";
2025-07-24 00:04:42 +08:00
// const commonUrl = "http://192.168.1.105:18080/zhgd/";
2025-07-17 09:30:49 +08:00
// const imgUrl = "http://192.168.0.38:13030/zhgd/file/files/";
const imgUrl = "http://sgwpdm.ah.sgcc.com.cn/zhgd/file/files/";
2024-06-11 11:16:54 +08:00
// //前端路径
2024-11-13 23:44:52 +08:00
// let isc_login="http://iscssotest.ah.sgcc.com.cn/isc_sso/login?service=";
2024-03-25 20:21:14 +08:00
/* 登录相关 */
const login_url = commonUrl + "auth/login"; // 登录url
2025-06-20 18:22:25 +08:00
const sgcc_url = commonUrl + "auth/sgccLogin"; // 登录url
2024-03-25 20:21:14 +08:00
const login_out = commonUrl + "auth/logout"; // 登出url
2024-03-26 19:52:42 +08:00
const page_jump = commonUrl + "auth/pageJump"; // 登出url
2025-06-20 18:22:25 +08:00
2025-07-17 09:30:49 +08:00
// const back_url="http://192.168.0.38:9527/zhgd-ht/#/ywgllogin?token=";
//后台登录地址
2025-07-24 13:34:33 +08:00
// const back_url="http://sgwpdm.ah.sgcc.com.cn/jjgdweb/zhgd-ht/#/ywgllogin?token=";
2025-07-24 20:08:34 +08:00
const back_url =
"http://192.168.0.7:21624/zhgd-ht/#/login?redirect=%2Fdashboard";
2025-07-17 09:30:49 +08:00
// const screen_url="http://localhost:63343/ah_jjzhgd_webscreen/pages/web/index.html";
2025-07-24 20:08:34 +08:00
const screen_url =
"http://sgwpdm.ah.sgcc.com.cn/ahsfs/zhgd-web/pages/web/index.html";
2025-07-17 09:30:49 +08:00
//const screen_url="http://sgwpdm.ah.sgcc.com.cn/jjgdweb/zhgd-web/pages/web/index.html";
2025-06-20 18:22:25 +08:00
2025-07-24 20:08:34 +08:00
let SGCC_LOGIN_URL = "http://sgwpdm.ah.sgcc.com.cn/";
2024-08-22 17:00:16 +08:00
2025-07-24 20:08:34 +08:00
let sm4 = new SM4Util();
const login_sg_page = URL_IP + "/sg_login.html"; // 施工大屏登录页面
2025-06-20 18:22:25 +08:00
const login_sc_page = SGCC_LOGIN_URL; // 省侧大屏登录页面
2025-07-24 20:08:34 +08:00
const login_sg_index = SGCC_LOGIN_URL; // 施工大屏首页
2025-06-20 18:22:25 +08:00
2024-11-26 11:56:05 +08:00
/**
* 公钥
* @type {string}
*/
2025-07-24 20:08:34 +08:00
const public_key =
"04211520e8dc6d2051e67e6e770bd5550268c98105cd3b5b58e9c65958e78e627442343c9f237e01b3f316b1b63d7ddd70a8e6c0690a84c620b2903cb44cdfbe64";
2024-09-13 14:52:05 +08:00
// 修改响应数据的函数
function modifyResponseData(responseData) {
// 在这里对响应数据进行修改
2025-07-24 20:08:34 +08:00
if (responseData.decrypt) {
responseData = sm4.decryptDefault_CBC(responseData.data);
} else {
// responseData=responseData;
2024-09-13 14:52:05 +08:00
}
2025-07-24 20:08:34 +08:00
if (typeof responseData == "object") {
2024-09-13 14:52:05 +08:00
return responseData;
}
2025-07-24 20:08:34 +08:00
if (typeof responseData == "string") {
responseData = removePadding(responseData);
2024-09-13 14:52:05 +08:00
var responseData = JSON.parse(responseData);
var modifiedData = responseData;
return modifiedData;
}
return responseData;
}
function removePadding(decrypted) {
const lastByte = decrypted.charCodeAt(decrypted.length - 1);
if (lastByte <= 16) {
for (let i = decrypted.length - lastByte; i < decrypted.length; i++) {
if (decrypted.charCodeAt(i) !== lastByte) {
return decrypted; // 如果填充不正确,返回原始字符串
}
}
return decrypted.slice(0, -lastByte);
}
return decrypted;
}
2024-03-29 15:25:34 +08:00
/* POST 请求 */
2025-07-24 20:08:34 +08:00
function ajaxRequest(
url,
type,
data,
async,
beforeFn,
successFn,
errorFn,
contentType,
isAes
) {
2024-03-25 20:20:02 +08:00
$.ajax({
url: url,
type: type,
headers: {
2025-07-24 20:08:34 +08:00
authorization: sessionStorage.getItem("zhgd_token"),
decrypt: isAes ? "" : "decrypt",
2024-03-25 20:20:02 +08:00
},
data: data,
async: async,
beforeSend: beforeFn,
2025-07-24 20:08:34 +08:00
contentType:
contentType || "application/x-www-form-urlencoded; charset=utf-8",
success: function (event, xhr, settings, data) {
event = modifyResponseData(event);
2024-09-13 14:52:05 +08:00
successFn(event, xhr, settings, data);
},
2025-07-24 20:08:34 +08:00
error: function (event, xhr, settings, error) {
errorFn(event, xhr, settings, error);
},
2024-03-25 20:20:02 +08:00
});
2024-03-26 19:52:42 +08:00
}
/* 施工大屏跳转 ajax请求封装 */
function ajaxRequest2(url, type, token, successFn, errorFn) {
$.ajax({
url: url,
type: type,
headers: {
2025-07-24 20:08:34 +08:00
authorization: token,
decrypt: "decrypt",
2024-03-26 19:52:42 +08:00
},
2025-07-24 20:08:34 +08:00
success: function (event, xhr, settings, data) {
event = modifyResponseData(event);
2024-09-13 14:52:05 +08:00
successFn(event, xhr, settings, data);
},
2025-07-24 20:08:34 +08:00
error: function (event, xhr, settings, error) {
errorFn(event, xhr, settings, error);
},
2024-03-26 19:52:42 +08:00
});
2024-03-29 15:25:34 +08:00
}
/* GET请求 */
2024-04-01 09:12:20 +08:00
function ajaxRequestGet(url, type, async, beforeFn, successFn, errorFn, isAes) {
2024-03-29 15:25:34 +08:00
$.ajax({
url: url,
type: type,
headers: {
2025-07-24 20:08:34 +08:00
authorization: sessionStorage.getItem("zhgd_token"),
decrypt: isAes ? "" : "decrypt",
2024-03-29 15:25:34 +08:00
},
2024-04-09 18:05:53 +08:00
async: async,
beforeSend: beforeFn,
2025-07-24 20:08:34 +08:00
success: function (event, xhr, settings, data) {
event = modifyResponseData(event);
2024-09-13 14:52:05 +08:00
successFn(event, xhr, settings, data);
},
2025-07-24 20:08:34 +08:00
error: function (event, xhr, settings, error) {
errorFn(event, xhr, settings, error);
},
2024-04-09 18:05:53 +08:00
});
}
/* GET请求 */
2025-07-24 20:08:34 +08:00
function ajaxRequestGetExport(
url,
type,
async,
beforeFn,
successFn,
errorFn,
isAes
) {
2024-04-09 18:05:53 +08:00
$.ajax({
url: url,
type: type,
headers: {
2025-07-24 20:08:34 +08:00
encryption: "encryption",
authorization: sessionStorage.getItem("zhgd_token"),
decrypt: isAes ? "" : "decrypt",
2024-04-09 18:05:53 +08:00
},
xhrFields: {
2025-07-24 20:08:34 +08:00
responseType: "blob", // 告诉 xhr 我们期望返回的数据类型是 blob
2024-04-09 18:05:53 +08:00
},
2024-04-01 19:49:28 +08:00
async: async,
beforeSend: beforeFn,
2024-09-13 18:53:08 +08:00
success: successFn,
2025-07-24 20:08:34 +08:00
error: errorFn,
2024-04-01 19:49:28 +08:00
});
2025-04-01 11:16:23 +08:00
}