// var dataUrl ="http://192.168.0.110:8081/rearScreen/" //平台在线的球机 var onLineBallList = []; var token1 = localStorage.getItem("video_token1") layui.use(['form'], function() { $('#map').load('../../page/svg/svgMap_3D_index.svg'); //随机获取一个在线视频播放 getRandomVideo(); //获取接口状态数量x // interfaceStatus(); getPortStatusNum(); //智慧用电表格 // setTimeout(function(){ // var svg = Snap('#tesr222'); // console.log(svg); // svg.click(function() { // alert('你点击了SVG元素!'); // }); // },500) timeTask(); timeTaskVideo(); deviceNum(); // 空气质量检测 echartsInstrumentPanel(); environmentalMonitoring(1); // echartsEnvironmentalMonitor(); }); var timeout = false; //启动及关闭按钮 var timeoutVideo = false; //启动及关闭按钮 // 60 *5s 刷新一次 function timeTask() { if (!timeout) { timeout = true; } else { getPortStatusNum(); } setTimeout(timeTask, 1000 * 30); } function timeTaskVideo() { if (!timeoutVideo) { timeoutVideo = true; } else { getRandomVideo(); } setTimeout(timeTask, 1000 * 60 * 10); } //根据uuid绑定svg内部的id和每个防区的线条数量 const idMap = new Map([ ["83d8402f147a4752b533253a9b8efdcc",4], ["693b822a29c6485c89e20bf2f0361e71",8], ["d9d05050d8c54012b2888eb5c085c63a",4], ["0244961a68cb402a89081ef73947dc9a",12], ["399d97e087a84144a1e5cb41ab32e084",4], ["1de47425c6ff404883ac17b061f4d093",4], ["1de47425c6ff404883ac17b061f4d027",8] ]) /** * 由home.js调用 * 用于改变 -- 各防区线的颜色 */ function webscoketIndexSvg(strs){ var arr = strs.split(",");//uuid-code-status for (var i = 0; i < arr.length; i++) { var lineNum = idMap.get(arr[i].split("-")[0]);//防区线数量 var status = arr[i].split("-")[2];//防区状态 var lineColor = status == 5 ? "#FF3636" : "#23ee63"; if(arr[i].split("-")[1] == 2){ //第七房区 for (var k = 5; k <= 8; k++) { changColor("a_"+arr[i].split("-")[0] +"_"+ k,lineColor); } }else{ //1-6防区 for (var k = 1; k <= lineNum; k++) { changColor("a_"+arr[i].split("-")[0] +"_"+ k,lineColor); } } } } //修改防区线颜色 function changColor(code,lineColor){ var svg = Snap(`#${code}`); svg.attr({ stroke: lineColor, }); } function deviceNum() { $.ajax({ type: 'POST', url: dataUrl + 'electronicMap/deviceCount', data: "", dataType: 'json', success: function(res) { let deviceCount = res.obj.deviceCount; var Monitoring = parseInt(deviceCount[0].camera)-(parseInt(deviceCount[0].camera1) + parseInt(deviceCount[0].camera2) + parseInt(deviceCount[0].camera3) + parseInt(deviceCount[0].camera4)); $('#map').find('#svg_795').text(parseInt(deviceCount[0].camera1)); $('#map').find('#svg_793').text(parseInt(deviceCount[0].camera2)); $('#map').find('#svg_800').text(parseInt(deviceCount[0].camera3)); $('#map').find('#svg_803').text(Monitoring); $('#map').find('#svg_783').text(parseInt(deviceCount[0].camera4)); $('#map').find('#svg_801').text(parseInt(deviceCount[1].stand)); $('#map').find('#svg_796').text(parseInt(deviceCount[2].switch)); $('#map').find('#svg_804').text(parseInt(deviceCount[3].firefight-deviceCount[5].firefight3-deviceCount[4].firefight1)); //监控消防栓 $('#map').find('#svg_802').text(parseInt(deviceCount[5].firefight3)); //3号消防栓 $('#map').find('#svg_792').text(parseInt(deviceCount[4].firefight1)); //1号消防栓 } }); } /** * 点击首页视频监控的div跳转视频页面 */ var puid = ""; var videoBtn = document.getElementById('video1') videoBtn.addEventListener('click', function() { localStorage.setItem("video_puid",puid); window.parent.jumpVideo(); }); /** * 随机获取一个在线视频播放 */ function getRandomVideo(){ $.ajax({ type: 'POST', url: dataUrl + "index/getRandomVideo", data: "", dataType: 'json', // async:false, success: function(res) { if(res.resMsg = "数据获取成功"){ puid = res.obj.puid; var btn = document.getElementById('videoBtn') btn.addEventListener('click', function() { qxPlayVideo(puid,"0"); }); document.getElementById('videoBtn').click(); }else{ layer.msg("当前没有在线球机",{icon:0,time:2000}); } }, }); } /** * 播放视频 * @param puId * @param idx */ function qxPlayVideo(puId, idx) { setTimeout(function(){ readyPlay(puId, idx); },500); } var myPlayer = null; //开始播放视频 function readyPlay(puId, idx){ //若是清晰平台,删除连接对象 // mySet.delete(selectedScreen); let url = _cf_1.q2http_url + "stream.flv?puid=" + puId + "&idx=0&stream=0&token=" + token1; //循环视频播放列表 try{ if (myPlayer != null) { myPlayer.pause(); myPlayer.unload(); myPlayer.detachMediaElement(); myPlayer.destroy(); myPlayer = null; } myPlayer = flvjs.createPlayer({ type: 'flv', url: url, isLive: true, hasAudio: false }, { enableWorker: false, autoCleanupSourceBuffer: true, //清理缓冲区 enableStashBuffer: false, stashInitialSize: 128, // 减少首桢显示等待时长 statisticsInfoReportInterval: 600 }); myPlayer.attachMediaElement(document.getElementById('video1')); myPlayer.load(); setTimeout(function () { myPlayer.play(); }, 200); }catch(e){ alert("该视频不在线。。。"); } var selectedScreen = 'video1'; $('#video'+selectedScreen+'_html5_api').css("width", "100%"); $('#video'+selectedScreen+'_html5_api').css("height", "100%"); $('#video1').css("width", "85%"); $('#video1').css("height", "100%"); $('#video1').css("margin-left", "7%"); $('#video1').css("margin-top", "2%"); $('#video'+selectedScreen+'_html5_api').css("background-color","black"); $('.vjs-text-track-display').hide(); $('.vjs-loading-spinner').hide(); $('.vjs-big-play-button').hide(); $('.vjs-control-bar').hide(); $('.vjs-error-display').hide(); $('.vjs-error-display').hide(); $('.vjs-modal-dialog').hide(); $('.vjs-poster').removeAttr("class"); $('.video'+selectedScreen+'-dimensions').css("width", "100%"); $('.video'+selectedScreen+'-dimensions').css("height", "100%"); } window.onbeforeunload = function(e) { myPlayer.pause(); myPlayer.unload(); myPlayer.detachMediaElement(); myPlayer.destroy(); myPlayer = null; } /** * * @param {*} player 播放控件对象 * @param {*} index playBallList 下标,第几个 * @param {*} type 类型 1切换窗口关闭视频,2主动关闭视频 */ function stopVideo(player,index,type) { if(type == 1){ player.unload(); player.detachMediaElement(); player.destroy(); player = null; playBallList.splice(index, 1); }else{ $.each(playBallList, function (index, item) { if (!isEmpty(item)) { if (selectedScreen === item.selectedScreen) { let start = item.start; let player = item.myPlayer; if(start && player !== null){ player.unload(); player.detachMediaElement(); player.destroy(); player = null; playBallList.splice(index, 1); } } } }); } } /** * 获取接口状态数量 */ function interfaceStatus() { $.ajax({ type: 'POST', url: dataUrl + 'electricity/interfaceStatus', data: { type: "" }, dataType: 'json', success: function(res) { let interface = res.obj.electricityBean; document.getElementById('requestNum').innerText = parseInt(interface.requestNum); document.getElementById('successNum').innerText = parseInt(interface.successNum); document.getElementById('errorNum').innerText = parseInt(interface.errorNum); } }); } function getPortStatusNum() { $.ajax({ type: 'POST', async: false, // 默认异步true,false表示同步 url: dataUrl + 'index/getPortStatusNum', // 请求地址 dataType: 'json', // 服务器返回数据类型 data: {}, //获取提交的表单字段 success: function(data) { var resMsg = data.resMsg; if ("数据获取成功" == resMsg) { // let portInfo = data.obj.portStatusBean; let fireBeanInfo = data.obj.fireBean; let safeBeanInfo = data.obj.safeBean; // document.getElementById('requestNum').innerText = portInfo.requestNum; // document.getElementById('successNum').innerText = portInfo.successNum; // document.getElementById('errorNum').innerText = portInfo.errorNum; document.getElementById('fire_totalNum').innerText = parseInt(fireBeanInfo.warnNum); document.getElementById('fire_warnNum').innerText = parseInt(fireBeanInfo.totalNum) document.getElementById('safe_totalNum').innerText = parseInt(safeBeanInfo.totalNum); document.getElementById('safe_warnNum').innerText = parseInt(safeBeanInfo.warnNum) setTimeout(function () { //用电统计 powerStatChart(data.obj); //设备信息表格 deviceInfoList(data.obj); //每月预警 earlyWarnChart(data.obj); wisdomList(data.obj); },200) } }, error: function(XMLHttpRequest, textStatus, e) { // layer.close(loadingMsg); layer.msg('数据请求发生异常,请稍后重试', { icon: 16, scrollbar: false }); } }); } //用电统计获取数据 // function powerStatChartData() { // // $.ajax({ // // type: 'POST', // // url: dataUrl + "index/getElectricityConsumption", // // data: "", // // dataType: 'json', // // // async:false, // // success: function(res) { // // powerStatChart(res.obj); // // }, // // }); // // } //用电统计ECharts function powerStatChart(data) { echarts.init(document.getElementById('chart')).dispose(); // 销毁实例 const myChart = echarts.init(document.getElementById('chart')); const powerList = data.electricityList.map(function (date, index) { return {date: date, value: data.electricityConsumptionList[index]}; }).sort(function (a, b) { // 将日期转换为时间戳进行比较 const dateE = new Date("20" + a.date.replace("-", "/")).getTime(); const dateF = new Date("20" + b.date.replace("-", "/")).getTime(); return dateE - dateF; }); let month = powerList.map(function(pair) { return pair.date; }); let value = powerList.map(function(pair) { return pair.value; }); console.log(month) console.log(value) let color = ['#CC1CAA', '#8D67FF', '#00FFFF', '#48DE13', '#FFC516', '#DC3E14', '#8E16F8']; dom = 800; barWidth = dom / 60; let colors = [] for (let i = 0; i < 12; i++) { colors.push({ type: 'linear', x: 0, x2: 1, y: 0, y2: 0, colorStops: [{ offset: 0, color: 'rgba(19,130,188,0.8)' // 最左边 }, { offset: 0.5, color: 'rgba(19,130,188,0.8)' // 左边的右边 颜色 }, { offset: 0.5, color: 'rgba(23,208,249,0.8)' // 右边的左边 颜色 }, { offset: 1, color: 'rgba(23,208,249,0.8)' }] }) } option = { //提示框 title:{ left: '80%', top: '-6%', subtext: '用电统计:kw/h', subtextStyle: { fontSize: 12, color: '#fff' } }, tooltip: { trigger: 'axis', formatter: "{b} : {c}", axisPointer: { // 坐标轴指示器,坐标轴触发有效 type: 'shadow' // 默认为直线,可选为:'line' | 'shadow' } }, /**区域位置*/ grid: { left: '6%', right: '0', top: '10%', bottom: '15%', }, //X轴 xAxis: { data: month, type: 'category', axisLine: { show: true, lineStyle: { color: 'rgba(255,255,255,0.6)', shadowColor: 'rgba(255,255,255,0.6)', shadowOffsetX: '20', }, symbol: ['none', 'arrow'], symbolOffset: [0, 25] }, splitLine: { show: false, }, axisTick: { show: false }, axisLabel: { margin: 10, fontSize: 10, rotate: 45, }, }, yAxis: { show: true, splitNumber: 4, axisLine: { show: false, }, splitLine: { show: true, lineStyle: { type: 'dashed', color: '#075858' }, }, axisLabel: { color: 'rgba(255,255,255,0.6)', margin: 10, fontSize: 12, inside: true, margin: -26 }, }, series: [{ type: 'bar', barWidth: barWidth, itemStyle: { normal: { color: function(params) { return colors[params.dataIndex % 7]; } } }, label: { show: false, position: [barWidth / 2, -(barWidth + 20)], color: '#ffffff', fontSize: 12, fontStyle: 'bold', align: 'center', }, data: value }, { z: 2, type: 'pictorialBar', data: value, symbol: 'diamond', symbolOffset: [0, '50%'], symbolSize: [barWidth, barWidth * 0.5], itemStyle: { normal: { color: function(params) { return colors[params.dataIndex % 7]; }, } }, }, { z: 3, type: 'pictorialBar', symbolPosition: 'end', data: value, symbol: 'diamond', symbolOffset: [0, '-50%'], symbolSize: [barWidth, barWidth * 0.5], itemStyle: { normal: { borderWidth: 0, color: function(params) { return colors[params.dataIndex % 7].colorStops[0].color; }, } }, }, ], }; myChart.setOption(option); } //设备信息表格 function deviceInfoData() { $.ajax({ type: 'POST', url: dataUrl + "index/getEquipInfo", data: "", dataType: 'json', // async:false, success: function(res) { deviceInfoList(res.obj); }, }); } function deviceInfoList(data) { let equipNum = 6; if(data.equipList.length < equipNum){ equipNum = data.equipList.length; } var html = "" for (var i = 0; i < equipNum; i++) { html += "