index.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. //实时温湿度曲线
  2. $(".single .list").delegate("li","click",function(event){
  3. //var target = $(event.target);
  4. var i = $(this).attr("build-index");
  5. var title = $(this).find('.room_num').text();
  6. var deviceId = $(this).attr("device-id");
  7. $(".window-ssqx .window-title").text(title)
  8. $(".window-ssqx").show();
  9. myChart_ssqx.resize();
  10. var date = new Date();
  11. var fromDate = date.setHours(0,0,0,0)/1000;
  12. var toDate = date.setHours(24,0,0,0)/1000;
  13. if(deviceId != ''){
  14. var date = new Date();
  15. var getTempLineUrl="/analyse/hm/device/history/by-device-id";
  16. var getTempLineParam={
  17. deviceId:deviceId,
  18. type:1,
  19. fromDate:fromDate,
  20. toDate:toDate
  21. }
  22. var getHumiLineParam={
  23. deviceId:deviceId,
  24. type:2,
  25. fromDate:fromDate,
  26. toDate:toDate
  27. }
  28. //
  29. var xAxis = [];
  30. var nowHour = moment.getHours();
  31. for(var i=0;i<=nowHour;++i){
  32. xAxis[i] = (i<10?"0"+i:i)+":00";
  33. }
  34. var humiArr = [];
  35. var series = [];
  36. option_ssqx.series = series;
  37. myChart_ssqx.setOption(option_ssqx, true);
  38. getData(getTempLineUrl,getTempLineParam,"GET").then(res => {
  39. var xAxis = [];
  40. var contentlen = res.content!=undefined?res.content.length:0;
  41. var tempChannel = [];//构建多路温度曲线
  42. for(var i=0;i<contentlen;++i){
  43. var d = new Date(res.content[i].created)
  44. var h = d.getHours();
  45. var m = d.getMinutes();
  46. var oneXaxis = (h<10?"0"+h:h)+":"+(m<10?"0"+m:m)
  47. if(xAxis.indexOf(oneXaxis)<0){
  48. xAxis.push(oneXaxis);
  49. }
  50. var channelNo = 'channel-'+res.content[i].channelNo;
  51. if(tempChannel[channelNo]==undefined){
  52. tempChannel[channelNo] = [];
  53. //多路温度传感器
  54. }
  55. tempChannel[channelNo].push({
  56. value:res.content[i].value,
  57. name:'℃('+channelNo+')'
  58. })
  59. }
  60. for(var k in tempChannel){
  61. var seriesData = {
  62. name:'温度',
  63. type:'line',
  64. smooth: true,
  65. data:tempChannel[k],
  66. lineStyle:{
  67. normal:{
  68. color:'#ef1a0f'
  69. }
  70. }
  71. }
  72. series.push(seriesData);
  73. }
  74. option_ssqx.xAxis.data = xAxis.reverse();
  75. option_ssqx.series = series;
  76. console.log(xAxis)
  77. myChart_ssqx.setOption(option_ssqx, true);
  78. })
  79. getData(getTempLineUrl,getHumiLineParam,"GET").then(res => {
  80. var xAxis = [];
  81. var contentlen = res.content!=undefined?res.content.length:0;
  82. var humiChannel = [];//构建多路湿度曲线
  83. for(var i=0;i<contentlen;++i){
  84. var d = new Date(res.content[i].created)
  85. var h = d.getHours();
  86. var m = d.getMinutes();
  87. var oneXaxis = (h<10?"0"+h:h)+":"+(m<10?"0"+m:m)
  88. if(xAxis.indexOf(oneXaxis)<0){
  89. xAxis.push(oneXaxis);
  90. }
  91. var channelNo = 'channel-'+res.content[i].channelNo;
  92. if(humiChannel[channelNo]==undefined){
  93. humiChannel[channelNo] = [];
  94. //多湿度传感器
  95. }
  96. humiChannel[channelNo].push({
  97. value:res.content[i].value,
  98. name:'RH('+channelNo+')'
  99. })
  100. }
  101. for(var k in humiChannel){
  102. var seriesData = {
  103. name:'湿度',
  104. type:'line',
  105. smooth: true,
  106. data:humiChannel[k],
  107. lineStyle:{
  108. normal:{
  109. color:'#0fc6ef'
  110. }
  111. }
  112. }
  113. series.push(seriesData);
  114. }
  115. //console.log(series)
  116. option_ssqx.series = series;
  117. option_ssqx.xAxis.data = xAxis.reverse();
  118. console.log(xAxis)
  119. myChart_ssqx.setOption(option_ssqx, true);
  120. })
  121. }
  122. })
  123. $("#dataSet").click(function(){
  124. //$(".windows-dataset").show();
  125. })
  126. //播放器
  127. var player=null;
  128. $(".open-box-container").on('click',function(){
  129. $(this).hide();
  130. if(player!=null){
  131. player.stop();
  132. player.destroy()
  133. player=null;
  134. }
  135. })
  136. //ESC 关闭layer弹窗
  137. $(window).keyup(function (e) {
  138. if (e.keyCode == 27) {
  139. $(".open-box-container").hide();
  140. if(player!=null){
  141. ///console.log(player)
  142. player.stop();
  143. player.destroy();
  144. player=null;
  145. }
  146. }
  147. });
  148. $(".open-lauer-box").on('click',function(){
  149. event.stopPropagation();
  150. })
  151. //地图热点
  152. var img_width = $(".img_window").width();
  153. var img_height = $(".img_window").height();
  154. $("#diagonal").attr('width',img_width+'px');
  155. $("#diagonal").attr('height',img_height+'px');
  156. var videoDevice = [1,2,4,5,10,11,13,14,21,24,26,33,34,42,45,46,47,48];
  157. var tempDevice = [0,2,5,6,8,13,21,24,26];
  158. $("#img_map").delegate("area","click",function(event){
  159. var canvers = document.getElementById("diagonal");//为了区域现形做一个画布
  160. var context = canvers.getContext("2d");
  161. context.globalAlpha = 0.5;
  162. context.clearRect(0, 0, 1010, 468);
  163. var target = $(event.target);
  164. var i = target.index();
  165. console.log(i)
  166. var n = videoDevice.indexOf(i);//是否有视频设备
  167. var m = tempDevice.indexOf(i);//是否有监测设备
  168. if(n>=0){
  169. //有视频
  170. var title = target.attr('title');
  171. var channel = target.attr('channel-data');
  172. $(".windows-spjk .window-title").text(title);
  173. $(".windows-spjk").show();
  174. //获取设备信息
  175. //监控设备
  176. var d = JSON.parse(channel);
  177. if(currIp==loginIp){
  178. //登录IP和设备IP一致
  179. videoIp = lanIp
  180. player = play(0,d[0].rtsp,d[0].size);
  181. }else{
  182. //用普清
  183. videoIp = currIp;
  184. player = play(0,d[1].rtsp,d[1].size)
  185. }
  186. }
  187. if(m>=0){
  188. //有监测
  189. $(".single .list li").removeClass('select')
  190. $(".single .list li.buildEnv-"+m).addClass('select')
  191. //15S后移除
  192. setTimeout(function(){
  193. $(".single .list li").removeClass('select');
  194. context.clearRect(0, 0, 1130, 476);
  195. },15000)
  196. }
  197. context.beginPath();
  198. var strs = new Array(); //定义一数组
  199. var coords = target.attr('coords');
  200. coords=coords.replace("\"","");
  201. coords=coords.replace("\"","");
  202. strs = coords.split(",");
  203. //console.log(strs);
  204. var i1, i2;
  205. for (var i = 0; i < strs.length; i++) {
  206. //console.log(strs[i])
  207. if (i % 2 == 0) {
  208. i1 = strs[i];
  209. }
  210. if (i % 2 == 1) {
  211. i2 = strs[i];
  212. if (i == 1) {
  213. context.moveTo(i1, i2);
  214. }
  215. else {
  216. context.lineTo(i1, i2);
  217. }
  218. }
  219. }
  220. context.fillStyle = "#f00";
  221. context.fill();
  222. //console.log(context);
  223. context.closePath(); //闭合
  224. })
  225. /**
  226.   * 小数保留n位,四舍五入
  227.   * @param  {[type]} decimal [十进制小数]
  228.   * @param  {[type]} n       [保留小数点后有效位]
  229.   * @return {[type]}         [十进制保留小数点后n位]
  230.   */
  231. function decimal_common(decimal,n){
  232. var pv = Math.pow(10,n);
  233. return Math.round(decimal*pv)/pv;
  234. }
  235. /**
  236.  * [根据比例系数数组重新计算位置坐标coords]
  237.  * @param  {[type]} class_      [area的class]
  238.  * @param  {[type]} ratio_Array [area的比例系数数组]
  239.  * @param  {[type]} shape       [area的shape属性]
  240.  * @param  {[type]} radius      [area为circle时的半径]
  241.  * @return {[type]}             [description]
  242.  */
  243. function reCoords_(class_,ratio_Array,shape,radius){
  244. var picw = $("#pic").width(); //当前图片的宽度
  245. var pich = $("#pic").height(); //当前图片的高度
  246. if(shape=="rect"){
  247. //根据每个area标签的位置比例系数计算出新的坐标位置
  248. var xy_arr = ratio_Array.map(function(item,index){
  249. if(index % 2 === 0){ //X坐标值
  250. //console.log(picw)
  251. return parseInt(picw*item);
  252. }else{ //Y坐标值
  253. return parseInt(pich*item);
  254. }
  255. });
  256. var xy_str = xy_arr.join(","); //拼接出新的坐标位置coords
  257. $("."+class_).attr("coords",'"'+xy_str+'"');
  258. }else if(shape=="poly"){
  259. //根据每个area标签的位置比例系数计算出新的坐标位置
  260. //console.log(picw)
  261. var xy_arr = ratio_Array.map(function(item,index){
  262. if(index % 2 === 0){ //X坐标值
  263. return parseInt(picw*item);
  264. }else{ //Y坐标值
  265. return parseInt(pich*item);
  266. }
  267. });
  268. var xy_str = xy_arr.join(","); //拼接出新的坐标位置coords
  269. $("."+class_).attr("coords",'"'+xy_str+'"');
  270. }else if(shape=="circle"){
  271. //根据每个area标签的位置比例系数计算出新的坐标位置
  272. var xy_arr = ratio_Array.map(function(item,index){
  273. if(index == 0){ //X坐标值
  274. return parseInt(picw*item);
  275. }else if(index == 1){ //Y坐标值
  276. return parseInt(pich*item);
  277. }else{
  278. return parseInt(radius*item);
  279. }
  280. });
  281. var xy_str = xy_arr.join(","); //拼接出新的坐标位置coords
  282. $("."+class_).attr("coords",'"'+xy_str+'"');
  283. }
  284. }
  285. //热点图片自适应坐标
  286. var oldPicW = 1130; //原始图片宽
  287. var oldPicH = 476; //原始图片高
  288. /********************************计算area标签的位置比例系数************************************/
  289. //获取map标签里的所有area标签
  290. var $area = $("#buildmap").find("area");
  291. $.each($area,function(index,data){
  292. var shape = $(data).attr("shape"); //获取area标签的shape属性(矩形rect,圆形circle,多边形poly)
  293. var coordsArray  = $(data).attr("coords").replace(/\"/g,"").split(","); //将area标签的coords转换成数组
  294. var class_ = $(data).attr("class"); //获取area标签的class属性
  295. if(shape=="rect"){ //矩形rect
  296. //根据每个area标签的位置坐标计算出在整张图片的位置比例系数
  297. var coords_Array = [],ratio_Array = []; //coords_Array用于存放根据coords计算出来的比例系数数组
  298. for(var j=0,len=coordsArray.length;j<len;j++){
  299. if(j % 2 === 0){ //X坐标值
  300. coords_Array.push(decimal_common(coordsArray[j]/oldPicW,4));
  301. }else{ //Y坐标值
  302. coords_Array.push(decimal_common(coordsArray[j]/oldPicH,4));
  303. }
  304. }
  305. //ratio_Array作为比例系数数组形参重新计算位置坐标
  306. ratio_Array = coords_Array.concat(ratio_Array);
  307. reCoords_(class_,ratio_Array,shape,0);
  308. $(window).resize(function() {
  309. reCoords_(class_,ratio_Array,shape,0);
  310. });
  311. }else if(shape=="poly"){ //多边形poly
  312. //根据每个area标签的位置坐标计算出在整张图片的位置比例系数
  313. var coords_Array = [],ratio_Array = [];
  314. for(var j=0,len=coordsArray.length;j<len;j++){
  315. if(j % 2 === 0){ //X坐标值
  316. coords_Array.push(decimal_common(coordsArray[j]/oldPicW,4));
  317. }else{ //Y坐标值
  318. coords_Array.push(decimal_common(coordsArray[j]/oldPicH,4));
  319. }
  320. }
  321. ratio_Array = coords_Array.concat(ratio_Array);
  322. reCoords_(class_,ratio_Array,shape,0);
  323. $(window).resize(function() {
  324. reCoords_(class_,ratio_Array,shape,0);
  325. });
  326. }else if(shape=="circle"){ //圆形circle
  327. //根据每个area标签的位置坐标计算出在整张图片的位置比例系数
  328. var coords_Array = [],ratio_Array = [];
  329. for(var j=0;j<2;j++){ //圆只有两个坐标值和一个半径,半径以最大的比率去缩放
  330. if(j % 2 === 0){ //X坐标值
  331. coords_Array.push(decimal_common(coordsArray[j]/oldPicW,4));
  332. }else{ //Y坐标值
  333. coords_Array.push(decimal_common(coordsArray[j]/oldPicH,4));
  334. }
  335. }
  336. coords_Array.push(coords_Array[0]>=coords_Array[1]?coords_Array[0]:coords_Array[1]);//设置半径的比率
  337. ratio_Array = coords_Array.concat(ratio_Array);
  338. reCoords_(class_,ratio_Array,shape,coordsArray[2]);
  339. $(window).resize(function() {
  340. reCoords_(class_,ratio_Array,shape,coordsArray[2]);
  341. });
  342. }
  343. });
  344. ////////////////////////////////////////////////
  345. let step = 0.1;
  346. let INNER = false;
  347. let SCALE = 1;
  348. /*function $(select) {
  349. return document.querySelector(select);
  350. }*/
  351. // 鼠标相对页面的位置
  352. function getMousePos(event) {
  353. let e = event || window.event;
  354. let scrollX =
  355. document.documentElement.scrollLeft || document.body.scrollLeft;
  356. let scrollY =
  357. document.documentElement.scrollTop || document.body.scrollTop;
  358. let x = e.pageX || e.clientX + scrollX;
  359. let y = e.pageY || e.clientY + scrollY;
  360. //alert('x: ' + x + '\ny: ' + y);
  361. return { x: x, y: y };
  362. }
  363. function getElementPosition(select) {
  364. let dom = document.querySelector(select);
  365. let scrollX =
  366. document.documentElement.scrollLeft || document.body.scrollLeft;
  367. let scrollY =
  368. document.documentElement.scrollTop || document.body.scrollTop;
  369. let rect = dom.getBoundingClientRect();
  370. let x = scrollX + dom.getBoundingClientRect().left;
  371. let y = scrollY + dom.getBoundingClientRect().top;
  372. let height = dom.getBoundingClientRect().height;
  373. let width = dom.getBoundingClientRect().width;
  374. return { x: x, y: y, height: height, width: width };
  375. }
  376. function mouseIndom(event) {
  377. let mouseMsg = getMousePos(event);
  378. let domMsg = getElementPosition('#img_map');
  379. let flagX = mouseMsg.x > domMsg.x && mouseMsg.x < domMsg.x + domMsg.width;
  380. let flagY =
  381. mouseMsg.y > domMsg.y && mouseMsg.y < domMsg.y + domMsg.height;
  382. if (flagX && flagY) {
  383. //console.log('鼠标位于元素里面啦!');
  384. return true;
  385. } else {
  386. //console.log('鼠标位于元素外面拉!');
  387. return false;
  388. }
  389. }
  390. // 文档鼠标移动
  391. document.onmousemove = function(event) {
  392. INNER = mouseIndom(event);
  393. //console.log(INNER)
  394. };
  395. if (window.addEventListener)
  396. //FF,火狐浏览器会识别该方法
  397. window.addEventListener('DOMMouseScroll', wheel, { passive: false });
  398. window.onmousewheel = document.onmousewheel = wheel; //W3C
  399. //统一处理滚轮滚动事件
  400. function wheel(event) {
  401. //console.log(mouseIndom(event));
  402. var delta = 0;
  403. if (!event) event = window.event;
  404. if (event.wheelDelta) {
  405. //IE、chrome浏览器使用的是wheelDelta,并且值为“正负120”
  406. delta = event.wheelDelta / 120;
  407. if (window.opera) delta = -delta; //因为IE、chrome等向下滚动是负值,FF是正值,为了处理一致性,在此取反处理
  408. } else if (event.detail) {
  409. //FF浏览器使用的是detail,其值为“正负3”
  410. delta = -event.detail / 3;
  411. }
  412. if (delta) handle(delta, event);
  413. }
  414. //上下滚动时的具体处理函数
  415. function handle(delta, event) {
  416. if (INNER) {
  417. if (delta < 0) {
  418. //向下滚动
  419. console.log('向下滚动');
  420. let scale =
  421. Number.parseFloat(document.querySelector('#box').style.transform.replace('scale(', '')) +
  422. step;
  423. if(scale>5){
  424. return;
  425. }
  426. SCALE = scale;
  427. document.querySelector('#box').style.webkitTransform = 'scale(' + scale + ')';
  428. //$('#box').innerText = '缩小了' + scale;
  429. } else {
  430. //向上滚动
  431. console.log('向上滚动');
  432. let scale =
  433. Number.parseFloat(document.querySelector('#box').style.transform.replace('scale(', '')) -
  434. step;
  435. if(scale<1){
  436. return;
  437. }
  438. SCALE = scale;
  439. document.querySelector('#box').style.webkitTransform = 'scale(' + scale + ')';
  440. //$('#box').innerText = '放大了' + scale;
  441. }
  442. //event.preventDefault();
  443. event.stopPropagation();
  444. return;
  445. }
  446. }
  447. window.onload=function() {
  448. var disX = disY = 0; // 鼠标距离div的左距离和上距离
  449. var div1 = document.getElementById("box"); // 得到div1对象
  450. // 鼠标按下div1时
  451. div1.onmousedown = function(e) {
  452. var evnt = e || event; // 得到鼠标事件
  453. disX = evnt.clientX - div1.offsetLeft; // 鼠标横坐标 - div1的left
  454. console.log("evnt.clientX:"+evnt.clientX)
  455. console.log("box.offsetLeft:"+div1.offsetLeft)
  456. disY = evnt.clientY - div1.offsetTop; // 鼠标纵坐标 - div1的top
  457. if($("#box").css("transform") == "matrix(1, 0, 0, 1, 0, 0)" && $("#box").css("left")=="0px" && $("#box").css("top")=="0px"){
  458. return;
  459. }
  460. // 鼠标移动时
  461. document.onmousemove = function(e) {
  462. var evnt = e || event;
  463. var x = evnt.clientX - disX;
  464. var y = evnt.clientY - disY;
  465. //var window_width = document.documentElement.clientWidth - div1.offsetWidth;
  466. //var window_height = document.documentElement.clientHeight - div1.offsetHeight;
  467. //x = ( x < 0 ) ? 0 : x; // 当div1到窗口最左边时
  468. //x = ( x > window_width ) ? window_width : x; // 当div1到窗口最右边时
  469. //y = ( y < 0 ) ? 0 : y; // 当div1到窗口最上边时
  470. //y = ( y > window_height ) ? window_height : y; // 当div1到窗口最下边时
  471. div1.style.left = x + "px";
  472. div1.style.top = y + "px";
  473. };
  474. // 鼠标抬起时
  475. document.onmouseup = function() {
  476. document.onmousemove =null;
  477. document.onmouup = null;
  478. };
  479. return false;
  480. };
  481. $("#box").on('dblclick',function(e){
  482. //双击还原
  483. div1.style.webkitTransform = 'scale(1)';
  484. div1.style.left = "0px";
  485. div1.style.top = "0px";
  486. //INNER = false;
  487. document.onmousemove = function(event) {
  488. INNER = mouseIndom(event);
  489. console.log(INNER)
  490. };
  491. });
  492. };