var appConfig = {
|
// baseUrl: "http://114.215.109.124:8805/",
|
// baseUrl: "http://47.100.191.150:9029/",
|
// baseUrl: "http://localhost:8080/",
|
baseUrl: 'http://192.168.0.138:8084/',
|
};
|
|
var service = {
|
getRealtimeData: 'air/realtime/sec',
|
getNextData: 'air/realtime/sec/next',
|
importData: 'air/realtime/import',
|
importJinAnData: 'air/realtime/import/jinan',
|
downloadJinAnTemplate: 'air/realtime/import/jinan/download/template',
|
|
getElectricData: 'electric/data/company',
|
getMinuteData: 'electric/data/minute2',
|
getElectricityInfo: 'electric/data/info',
|
dailyStatistics: 'electric/data/analysis/daily',
|
|
getCompanyInfo: 'air/company/info',
|
getCompany: 'air/company/id',
|
getEPWResult: 'air/company/epw',
|
getComplaint: 'air/company/complaint',
|
getAssessment: 'air/company/assessment',
|
|
getMission: 'air/mission/type',
|
createMission: 'air/mission/create',
|
deleteMission: 'air/mission/delete',
|
deleteMissionAndData: 'air/mission/delete/data/vehicle',
|
|
getGridEPWResult: 'air/analysis/epw',
|
|
getDeviceInfo: 'air/device/all',
|
};
|
|
function _requst(params) {
|
var s = Util.deepCopy(params);
|
var _success = function (data) {
|
console.log(s.url);
|
console.log(data);
|
if (data.success) {
|
if (s.page != undefined) {
|
s.page(data.head);
|
}
|
s.success(data.data);
|
} else {
|
if (s.fail != undefined) {
|
s.fail(data.message);
|
}
|
}
|
};
|
params.success = _success;
|
return $.ajax(params);
|
}
|
|
var HttpService = {
|
_get: function (url, data, success, onPage) {
|
return _requst({
|
type: 'GET',
|
url: appConfig.baseUrl + url,
|
data: data,
|
contentType: 'application/json',
|
success: success,
|
page: onPage,
|
fail: function (error) {
|
console.log(error);
|
},
|
});
|
},
|
|
_post: function (url, params, body, success, fail, onPage) {
|
var _url = appConfig.baseUrl + url;
|
for (const key in params) {
|
if (_url == appConfig.baseUrl + url) {
|
_url += '?';
|
} else {
|
_url += '&';
|
}
|
|
_url += key + '=' + params[key];
|
}
|
return _requst({
|
type: 'POST',
|
url: _url,
|
data: JSON.stringify(body),
|
contentType: 'application/json',
|
success: success,
|
fail: fail,
|
page: onPage,
|
});
|
},
|
|
/**
|
* 获取实时数据
|
* 返回结果按照采样时间升序排列
|
* @param {*} deviceCode
|
* @param {*} page
|
* @param {*} perPage
|
* @param {*} success
|
* @param {*} type 数据精度,0:秒级;1:分钟级
|
*/
|
getRealtimeData: function (deviceCode, perPage, success, page, type) {
|
var data = {
|
perPage: perPage,
|
};
|
if (deviceCode != undefined) {
|
data.deviceCode = deviceCode;
|
}
|
if (page != undefined) {
|
data.page = page;
|
}
|
if (type != undefined) {
|
data.type = type;
|
}
|
this._get(service.getRealtimeData, data, success);
|
},
|
|
getHistoryData: function (
|
deviceCode,
|
startTime,
|
endTime,
|
page,
|
perPage,
|
success,
|
onPage,
|
type
|
) {
|
var data = {
|
deviceCode: deviceCode,
|
startTime: startTime,
|
page: page,
|
perPage: perPage,
|
};
|
if (endTime != undefined) {
|
data.endTime = endTime;
|
}
|
if (type != undefined) {
|
data.type = type;
|
}
|
this._get(service.getRealtimeData, data, success, onPage);
|
},
|
|
getCompanyInfo: function (success) {
|
this._get(service.getCompanyInfo, {}, success);
|
},
|
|
getCompany: function (cId, success) {
|
var data = {
|
cId: cId,
|
};
|
this._get(service.getCompany, data, success);
|
},
|
|
getEPWResult: function (deviceCode, startTime, endTime, companyIds, success) {
|
var data = {
|
deviceCode: deviceCode,
|
startTime: startTime,
|
endTime: endTime,
|
};
|
if (companyIds != undefined) {
|
data.companyIds = companyIds;
|
}
|
this._get(service.getEPWResult, data, success);
|
},
|
|
getComplaint: function (success) {
|
this._get(service.getComplaint, {}, success);
|
},
|
|
getAssessment: function (success) {
|
this._get(service.getAssessment, {}, success);
|
},
|
|
getNextData: function (deviceCode, updateTime, perPage, success) {
|
var data = {
|
deviceCode: deviceCode,
|
updateTime: updateTime,
|
page: 1,
|
perPage: perPage == undefined ? 2 : perPage,
|
};
|
this._get(service.getNextData, data, success);
|
},
|
|
importData: function (file, success, fail) {
|
var type = 'excel';
|
var formData = new FormData(); //这里需要实例化一个FormData来进行文件上传
|
formData.append(type, file);
|
_requst({
|
type: 'post',
|
url: appConfig.baseUrl + service.importData,
|
data: formData,
|
processData: false,
|
contentType: false,
|
success: success,
|
fail: fail,
|
});
|
},
|
|
importJinAnData: function (code, file, success, fail) {
|
var type = 'excel';
|
var formData = new FormData(); //这里需要实例化一个FormData来进行文件上传
|
formData.append('code', code);
|
formData.append(type, file);
|
_requst({
|
type: 'post',
|
url: appConfig.baseUrl + service.importJinAnData,
|
data: formData,
|
processData: false,
|
contentType: false,
|
success: success,
|
fail: fail,
|
});
|
},
|
|
downloadJinAnTemplate: function (success, fail) {
|
var method = 'post'; //请求方法
|
var url = appConfig.baseUrl + service.downloadJinAnTemplate;
|
var xhr = new XMLHttpRequest(); //定义一个XMLHttpRequest对象
|
xhr.open(method, url, true);
|
xhr.responseType = 'blob'; //设置ajax的响应类型为blob
|
xhr.setRequestHeader('Content-Type', 'application/json;charset=utf-8');
|
xhr.onload = function () //当请求完成,响应就绪进入
|
{
|
if (this.status == 200) {
|
//当响应状态码为200时进入
|
var blob = this.response; //获取响应返回的blob对象
|
//这一段用来判断是否是IE浏览器,因为下面有些代码不支持IE
|
if (typeof window.navigator.msSaveBlob !== 'undefined') {
|
window.navigator.msSaveBlob(blob, 'NPI_PROJECT.xlsx');
|
return;
|
}
|
const name = this.getResponseHeader('filename');
|
// const fileName = Base64.decode(name)
|
const fileName = 'JinAn-Template.xlsx';
|
var a = document.createElement('a'); //在dom树上创建一个a标签
|
var url = window.URL.createObjectURL(blob); //我的理解是生成一个相对于浏览器的虚拟url,用于指向传入的blob对象,让浏览器可以通过这个url找到这个blob对象
|
a.href = url; //将url赋值给a标签的href属性
|
a.download = decodeURIComponent(fileName); //设置设置下载文件的名称
|
a.click(); //主动触发a标签点击事件
|
}
|
};
|
xhr.send(); //附带参数发送请求
|
},
|
|
getElectricData: function (cId, success) {
|
var data = {
|
cId: cId,
|
};
|
this._get(service.getElectricData, data, success);
|
},
|
|
getLatestMinuteData: function (deviceCode, perPage, success, page) {
|
var data = {
|
perPage: perPage,
|
};
|
if (deviceCode != undefined) {
|
data.deviceCode = deviceCode;
|
}
|
if (page != undefined) {
|
data.page = page;
|
}
|
this._get(service.getMinuteData, data, success);
|
},
|
|
getMinuteData: function (
|
deviceCode,
|
startTime,
|
endTime,
|
page,
|
perPage,
|
success,
|
onPage
|
) {
|
var data = {
|
deviceCode: deviceCode,
|
startTime: startTime,
|
page: page,
|
perPage: perPage,
|
};
|
if (endTime != undefined) {
|
data.endTime = endTime;
|
}
|
this._get(service.getMinuteData, data, success, onPage);
|
},
|
|
getElectricityInfo: function (
|
cId,
|
startTime,
|
endTime,
|
page,
|
perPage,
|
success,
|
onPage
|
) {
|
var data = {
|
cId: cId,
|
startTime: startTime,
|
page: page,
|
perPage: perPage,
|
};
|
if (endTime != undefined) {
|
data.endTime = endTime;
|
}
|
this._get(service.getElectricityInfo, data, success, onPage);
|
},
|
|
dailyStatistics: function (cId, startTime, endTime, success) {
|
var data = {
|
cId: cId,
|
};
|
if (startTime != undefined) {
|
data.startTime = startTime;
|
}
|
if (endTime != undefined) {
|
data.endTime = endTime;
|
}
|
this._get(service.dailyStatistics, data, success);
|
},
|
|
getMission: function (type, page, perPage, success) {
|
var data = {
|
page: page,
|
perPage: perPage,
|
};
|
if (type != undefined) {
|
data.type = type;
|
}
|
this._get(service.getMission, data, success);
|
},
|
|
createMission: function (mission, success, fail) {
|
this._post(service.createMission, {}, mission, success, fail);
|
},
|
|
deleteMission: function (missionCode, success, fail) {
|
this._post(
|
service.deleteMission,
|
{
|
missionCode: missionCode,
|
},
|
{},
|
success,
|
fail
|
);
|
},
|
|
deleteMissionAndData: function (missionCode, success, fail) {
|
this._post(
|
service.deleteMissionAndData,
|
{
|
missionCode: missionCode,
|
},
|
{},
|
success,
|
fail
|
);
|
},
|
|
login: function (name, pwd, success, fail) {
|
if (userInfo[name] == pwd) {
|
success();
|
} else {
|
fail();
|
}
|
},
|
|
getGridEPWResult: function (deviceCode, startTime, endTime, len, success) {
|
var data = {
|
deviceCode: deviceCode,
|
startTime: startTime,
|
endTime: endTime,
|
len: len,
|
};
|
this._get(service.getGridEPWResult, data, success);
|
},
|
|
getDeviceInfo: function (success) {
|
var data = {};
|
this._get(service.getDeviceInfo, data, success);
|
},
|
};
|
|
var appConfig2 = {
|
// baseUrl: 'http://47.100.191.150:9005/',
|
baseUrl: 'http://192.168.0.138:8082/',
|
};
|
|
var service2 = {
|
getInsideSite: 'scense/find/coor',
|
};
|
|
const HttpService_2 = {
|
/**
|
* 获取坐标范围内的监测站点
|
* @param lng 圆心坐标点经度(高德地图坐标系)
|
* @param lat 圆心坐标点纬度(高德地图坐标系)
|
* @param radius 半径
|
*/
|
getInsideSite(lng, lat, radius, success) {
|
const param = `?lng=${lng}&lat=${lat}&radius=${radius}`;
|
const _url = appConfig2.baseUrl + service2.getInsideSite + param;
|
return _requst({
|
type: 'POST',
|
url: _url,
|
contentType: 'application/json',
|
success: success,
|
});
|
},
|
};
|