277 lines
8.4 KiB
JavaScript
277 lines
8.4 KiB
JavaScript
import { setTokenActive } from "./session.js";
|
|
import { getBoroughInfo } from "./orgApi/getboroughInfo.js";
|
|
import {getStationGrade} from "./orgApi/getStationGrade.js"
|
|
import {getStationsData } from "./orgApi/getStationsData.js";
|
|
import {getstationcount,stationInfoPageReq} from "./orgApi/getStationInfo.js";
|
|
import { drawSchoolMarker } from "./marker/schoolMarker.js";
|
|
import { timestampFormat,getWeekDate} from "../../../public/js/tool.js";
|
|
import {} from "./pageEventTool.js"
|
|
import { stationWebsocket } from "../api/stationDeviceWebsocket.js";
|
|
import { moveDeviceWebsocket } from "../api/moveDeviceWebsocket.js";
|
|
import { mapUrl } from "../../../public/js/url.js";
|
|
import { schoolStarRatingGetlist } from "./orgApi/schoolStarRatingGetlist.js";
|
|
import { getThreeColorAlarm } from "./orgApi/getThreeColorAlarm.js";
|
|
import { getSkynetIpcList,showSkynetIpcInfo } from "./orgApi/getSkynetIpcList.js";
|
|
import { showPushButtonInfo } from "./showPushButtonInfo.js";
|
|
import { initSosSdk } from "./sosVideoAndAudio.js";
|
|
var layuiObj={};
|
|
var mapPlugin={};
|
|
var loginInfo={};//登录信息
|
|
var boroughInfoArr=[];//派出所的信息
|
|
var stationGradeArr=[];//学校评分
|
|
var stationsInfoArr=[];//学校今天信息
|
|
var stationInfoTableList=[];//学校的基本信息
|
|
var skynetIpcInfo=[];//学校IPC的信息
|
|
var schoolStarRatinglistArr=[];
|
|
var schoolThreeColorAlarmList=[];
|
|
var mainMap = null;
|
|
layui.use(['carousel','table','form','laydate','slider','element'],function() {
|
|
layuiObj["layer"] = layui.layer;
|
|
layuiObj["carousel"] = layui.carousel;
|
|
layuiObj["layuitable"] = layui.table;
|
|
layuiObj["rate"] = layui.rate;
|
|
layuiObj["layuiForm"] = layui.form;
|
|
layuiObj["laydate"] =layui.laydate;
|
|
layuiObj["slider"] =layui.slider;
|
|
layuiObj["element"] =layui.element;
|
|
var loginJson=sessionStorage.getItem("unameInfoStr");
|
|
loginInfo=JSON.parse(loginJson);
|
|
axios.defaults.headers.common['Authorization'] = loginInfo["session"];
|
|
//这里需要调用session的饱和接口
|
|
initApi();
|
|
initTool();
|
|
//设置seesion有效时长
|
|
setTokenActive();
|
|
})
|
|
|
|
//1.获取微站的信息
|
|
async function initApi(){
|
|
|
|
//获取派出所的信息
|
|
var boroughRes=await getBoroughInfo();
|
|
boroughInfoArr=boroughRes.data.data;
|
|
|
|
//获取所有的学校评分
|
|
var stationGradeRes=await getStationGrade();
|
|
stationGradeArr=stationGradeRes.data.data;
|
|
|
|
//获取所有的学校信息
|
|
var stationsDataRes=await getStationsData();
|
|
stationsInfoArr=stationsDataRes.data.data;
|
|
|
|
//获取学校的信息
|
|
var stationcountRes=await getstationcount();
|
|
var stationcount=stationcountRes.data.data.count;
|
|
var stationlistRes= await stationInfoPageReq(stationcount)
|
|
|
|
stationlistRes.forEach(item=>{
|
|
var data=item.data.data;
|
|
for(let i=0;i<data.length;i++){
|
|
stationInfoTableList.push(data[i]);
|
|
}
|
|
})
|
|
//获取星级评定
|
|
getschoolStarRatingReq();
|
|
//获取三色预警
|
|
getThreeColorAlarmReq();
|
|
|
|
//获取报警按钮的信息
|
|
showPushButtonInfo();
|
|
|
|
//初始化地图
|
|
mapInit();
|
|
//获取学校IPC的数据
|
|
var skynetIpc=await getSkynetIpcList();
|
|
if(skynetIpc.data.data!=null){
|
|
skynetIpcInfo=skynetIpc.data.data;
|
|
showSkynetIpcInfo();
|
|
$(".school_ipc_number").html(skynetIpcInfo.length)
|
|
}
|
|
//连接websocket
|
|
connectWebsocket();
|
|
|
|
|
|
//连接报警器的对讲视频
|
|
initSosSdk();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function getschoolStarRatingReq(){
|
|
return new Promise(async (reject,resolve)=>{
|
|
//获取所有学校的评分
|
|
schoolStarRatinglistArr=[];
|
|
var schoolStarRatingRes=await schoolStarRatingGetlist();
|
|
var schoolStarRatingData=schoolStarRatingRes.data.data;
|
|
if(schoolStarRatingData!=null){
|
|
schoolStarRatingData.forEach(item=>{
|
|
item["scoreTotal"]=item["scoreTotal"]/10;
|
|
item["scoreBonus"]=item["scoreBonus"]/10;
|
|
item["scoreInsideManage"]=item["scoreInsideManage"]/10;
|
|
item["scoreOutsideManage"]=item["scoreOutsideManage"]/10;
|
|
item["scoreRiskManage"]=item["scoreRiskManage"]/10;
|
|
item["scoreLawEducation"]=item["scoreLawEducation"]/10;
|
|
item["scoreEmcManage"]=item["scoreEmcManage"]/10;
|
|
schoolStarRatinglistArr.push(item);
|
|
})
|
|
reject(schoolStarRatinglistArr)
|
|
}
|
|
})
|
|
}
|
|
|
|
function getThreeColorAlarmReq(){
|
|
return new Promise(async (reject,resolve)=>{
|
|
//获取三色预警
|
|
var threeColorRes=await getThreeColorAlarm();
|
|
var threeColorAlarmData=threeColorRes.data.data;
|
|
if(threeColorAlarmData!=null){
|
|
schoolThreeColorAlarmList=[];
|
|
threeColorAlarmData.forEach(item=>{
|
|
item["scoreTotal"]=item["scoreTotal"]/10;
|
|
item["scoreHuman"]=item["scoreHuman"]/10;
|
|
item["scoreDevices"]=item["scoreDevices"]/10;
|
|
item["scoreTech"]=item["scoreTech"]/10;
|
|
item["scoreDesire"]=item["scoreDesire"]/10;
|
|
item["scoreScheme"]=item["scoreScheme"]/10;
|
|
item["scoreCase"]=item["scoreCase"]/10;
|
|
schoolThreeColorAlarmList.push(item);
|
|
})
|
|
reject(schoolThreeColorAlarmList)
|
|
}
|
|
})
|
|
}
|
|
|
|
function connectWebsocket(){
|
|
//连接站点websocket
|
|
stationWebsocket().then((res)=>{
|
|
var code=res["code"];
|
|
if(code==0){
|
|
var stationWebsocketConnect=res["stationWebsocketConnect"];
|
|
createStationWebsocket(stationWebsocketConnect);
|
|
}
|
|
})
|
|
|
|
moveDeviceWebsocket().then((res)=>{
|
|
var code=res["code"];
|
|
if(code==0){
|
|
//发送数据
|
|
var mdWebsocketConnect=res["mdWebsocketConnect"];
|
|
createMdWebsocket(mdWebsocketConnect);
|
|
}
|
|
})
|
|
}
|
|
|
|
function createStationWebsocket(stationWebsocketConnect){
|
|
var stationTempArr=[];
|
|
stationInfoTableList.forEach((item)=>{
|
|
var name=item.name
|
|
stationTempArr.push(name);
|
|
if(stationTempArr.length>=500){
|
|
sendStationList(stationWebsocketConnect,stationTempArr);
|
|
stationTempArr=[];
|
|
}
|
|
})
|
|
sendStationList(stationWebsocketConnect,stationTempArr);
|
|
}
|
|
|
|
//获取传感器的列表
|
|
function sendStationList(stationWebsocketConnect,stationTempArr){
|
|
var getIot={
|
|
"msgcode":102,
|
|
"msgname":"station-sensor-list",
|
|
"message":stationTempArr
|
|
}
|
|
var msg = JSON.stringify(getIot);
|
|
stationWebsocketConnect.send(msg);
|
|
}
|
|
|
|
function createMdWebsocket(mdWebsocketConnect){
|
|
var mobileDeviceArr=[];
|
|
var messageObj = {
|
|
"msgcode":400,
|
|
"msgname":"stationlist"
|
|
}
|
|
stationInfoTableList.forEach((item)=>{
|
|
var name=item.name;
|
|
mobileDeviceArr.push(name);
|
|
if(mobileDeviceArr.length>=500){
|
|
messageObj["message"]=mobileDeviceArr;
|
|
moveDeviceSendData(mdWebsocketConnect,mobileDeviceArr)
|
|
mobileDeviceArr=[];
|
|
}
|
|
})
|
|
//告诉我需要推送那些移动设备给我
|
|
messageObj["message"]=mobileDeviceArr;
|
|
moveDeviceSendData(mdWebsocketConnect,messageObj);
|
|
sendstationMdevList402(mdWebsocketConnect,mobileDeviceArr)
|
|
}
|
|
|
|
//移动互联网的websocket
|
|
function moveDeviceSendData(mdWebsocketConnect,messageObj){
|
|
var msg = JSON.stringify(messageObj);
|
|
mdWebsocketConnect.send(msg);
|
|
}
|
|
|
|
//移动设备发送数据
|
|
function sendstationMdevList402(mdWebsocketConnect,mobileDeviceArr){
|
|
var getMD={
|
|
"msgcode":402,
|
|
"msgname":"station-mdev-list",
|
|
"message":mobileDeviceArr
|
|
}
|
|
moveDeviceSendData(mdWebsocketConnect,getMD);
|
|
}
|
|
|
|
function mapInit(){
|
|
mainMap = L.map('map',{
|
|
center: [28.19,113.03],
|
|
zoom: 15,
|
|
attributionControl:false,
|
|
zoomControl:false,
|
|
minZoom :1,
|
|
maxZoom :18
|
|
});
|
|
|
|
|
|
L.tileLayer(`${mapUrl}/roadmap/{z}/{x}/{y}.png`, {
|
|
attribution: ''
|
|
}).addTo(mainMap);
|
|
//缩放监听 当zoom>=10的时候再显示本图层。
|
|
mainMap.on('zoomend', function(e) {
|
|
|
|
});
|
|
drawSchoolMarker();
|
|
}
|
|
|
|
function initTool(){
|
|
$(".loginUser").html(`<img src="./pages/index/image/user.png">${loginInfo["user_name"]}`)
|
|
$(".currentTime>span:first-child").html(getWeekDate());
|
|
$(".currentTime>span:last-child").html(timestampFormat());
|
|
setInterval(() => {
|
|
$(".currentTime>span:last-child").html(timestampFormat());
|
|
}, 1000);
|
|
}
|
|
|
|
export {
|
|
layuiObj,
|
|
loginInfo,
|
|
boroughInfoArr,
|
|
stationGradeArr,
|
|
stationsInfoArr,
|
|
stationInfoTableList,
|
|
skynetIpcInfo,
|
|
mainMap,
|
|
mapPlugin,
|
|
connectWebsocket,
|
|
schoolStarRatinglistArr,
|
|
schoolThreeColorAlarmList,
|
|
getschoolStarRatingReq,
|
|
getThreeColorAlarmReq
|
|
}
|
|
|
|
|
|
|
|
|