index.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. getIndexDate()
  2. /* ajax请求数据 */
  3. // setInterval(getIndexDate(), 1000)
  4. // ajax请求
  5. function getIndexDate(queryParam = {}) {
  6. ajaxRequest(INDEX_LIST, "POST", queryParam, function(result) {
  7. /* 饼图 */
  8. (function() {
  9. //饼图数据赋值
  10. var pie = result.pie;
  11. $("#loading").empty()
  12. var totalNum = 0;
  13. pie.forEach(function(value) {
  14. totalNum += value.value;
  15. })
  16. /* 饼图初始化 */
  17. var myChartPie = echarts.init(document.querySelector(".pie-bar .chart"));
  18. optionPie = {
  19. grid: {
  20. // width:'20%'
  21. },
  22. title: [{
  23. //text: '{name|3800}\n{val|设备总数}',
  24. text: '{name|' + totalNum + '}\n{val|设备总数}',
  25. top: 'center',
  26. left: 'center',
  27. textStyle: {
  28. rich: {
  29. name: {
  30. fontSize: 25,
  31. fontWeight: 'normal',
  32. color: '#37FF01',
  33. },
  34. val: {
  35. fontSize: 14,
  36. fontWeight: 'bold',
  37. color: '#02DDF2',
  38. }
  39. }
  40. }
  41. }],
  42. tooltip: {
  43. trigger: 'item',
  44. formatter: function(params) {
  45. return params.name + ':' + params.value + '<br>占比:' + params.percent.toFixed(2) + '%'
  46. }
  47. },
  48. series: [{
  49. label: {
  50. "normal": {
  51. "show": true,
  52. "formatter": ' {b}:{c} '
  53. },
  54. "emphasis": {
  55. "show": true
  56. }
  57. },
  58. name: '访问来源',
  59. radius: ['45%', '60%'],
  60. type: 'pie', // 设置图表类型为饼图
  61. // data: []
  62. data: pie,
  63. }],
  64. color: ['#EAF665', '#FF5801', '#6F99FA']
  65. };
  66. myChartPie.setOption(optionPie);
  67. window.addEventListener("resize", function() {
  68. myChartPie.resize();
  69. });
  70. })();
  71. /* 柱状图 */
  72. (function() {
  73. //bar柱状图 赋值
  74. var bar = result.bar
  75. var barName = []
  76. var barValue = []
  77. for (var key in bar) {
  78. barName.push(key)
  79. barValue.push(bar[key])
  80. }
  81. /* 柱状图初始化*/
  82. var myChartBar = echarts.init(document.querySelector(".pie.chart"));
  83. var optionBar = {
  84. grid: {
  85. left: '4%',
  86. bottom: '16%',
  87. top: '15',
  88. // height: "70%",
  89. // right: '4%',
  90. containLabel: true
  91. },
  92. tooltip: {
  93. trigger: 'axis',
  94. formatter: "{b} <br/> {c}",
  95. axisPointer: { // 坐标轴指示器,坐标轴触发有效
  96. type: 'line' // 默认为直线,可选为:'line' | 'shadow'
  97. }
  98. },
  99. textStyle: {
  100. "color": "red",
  101. "fontSize": 14 //20 14 15字体大小
  102. },
  103. //"color": ["#63caff", "#49beff", "#03387a"],
  104. color: ["rgba(0,212,233,.2)", "rgba(0,212,233,.2)"],
  105. xAxis: {
  106. "nameTextStyle": {
  107. "color": "#c0c3cd",
  108. "padding": [0, 0, -10, 0],
  109. "fontSize": 100
  110. },
  111. "axisLabel": {
  112. "color": "#c0c3cd",
  113. "fontSize": 14,
  114. "interval": 0
  115. },
  116. "axisLine": {
  117. "show": false
  118. },
  119. // "data": [],
  120. "data": barName,
  121. "type": "category"
  122. },
  123. yAxis: {
  124. show: false
  125. },
  126. series: [{
  127. // "data": [20, 40, 15],
  128. "data": barValue,
  129. "type": "bar",
  130. "barMaxWidth": "auto",
  131. "barWidth": 20,
  132. "itemStyle": {
  133. "color": '#00D4E9',
  134. 'barBorderRadius': [30, 30, 0, 0],
  135. },
  136. "label": { //aa标签数值
  137. "show": true,
  138. "position": "top",
  139. "distance": 10, //标签数值的距离 20 40 15
  140. "color": "#fff"
  141. }
  142. }, {
  143. "data": [100, 100, 100],
  144. "type": "bar",
  145. "barMaxWidth": "auto",
  146. "barWidth": 20,
  147. "barGap": "-100%",
  148. "zlevel": -1
  149. }, ],
  150. };
  151. myChartBar.setOption(optionBar);
  152. window.addEventListener("resize", function() {
  153. myChartBar.resize();
  154. });
  155. })();
  156. /* 折线图 */
  157. (function() {
  158. //折线图数据赋值
  159. var line = result.line;
  160. var lineData = [];
  161. for (var key in line) {
  162. for (const key2 in line[key]) {
  163. lineData.indexOf
  164. }
  165. }
  166. var lineDate = []
  167. var seriesData = []
  168. for (var key in line) {
  169. var lineKey = [];
  170. for (var date in line[key]) {
  171. if ($.inArray(date, lineDate) == -1) {
  172. lineDate.push(date)
  173. }
  174. lineKey.push(line[key][date])
  175. }
  176. seriesData.push({ 'name': key, 'data': lineKey });
  177. }
  178. // console.log(seriesData)
  179. /* 折线图初始化 */
  180. var myChart = echarts.init(document.querySelector(".line .chart"));
  181. var option = {
  182. legend: {
  183. itemGap: 20, // 图例每项之间的间隔。
  184. icon: 'stack',
  185. padding: 0, // 图例内边距
  186. textStyle: {
  187. color: '#fff',
  188. align: 'center',
  189. },
  190. },
  191. color: ['#6F99FA', '#FF5801', '#EAF665'],
  192. grid: {
  193. bottom: '0',
  194. right: '10',
  195. left: '10',
  196. top: '35',
  197. containLabel: true,
  198. },
  199. tooltip: {
  200. trigger: 'axis',
  201. confine: true,
  202. textStyle: {
  203. fontSize: 12
  204. }
  205. },
  206. xAxis: {
  207. type: "category",
  208. boundaryGap: false,
  209. // data: ["12:00", "13:00", "14:00", "15:00", "16:00", "17:00"],
  210. data: lineDate,
  211. "axisLabel": {
  212. "color": "#c0c3cd",
  213. },
  214. "axisLine": {
  215. lineStyle: {
  216. color: 'rgba(0,130,255,.2)'
  217. }
  218. },
  219. axisTick: {
  220. show: false
  221. },
  222. },
  223. yAxis: {
  224. type: "value",
  225. "axisLabel": {
  226. "color": "#c0c3cd",
  227. },
  228. axisTick: {
  229. show: false
  230. },
  231. "axisLine": {
  232. lineStyle: {
  233. color: 'rgba(0,130,255,.2)'
  234. }
  235. },
  236. "splitLine": {
  237. lineStyle: {
  238. color: "rgba(255,255,255,.1)"
  239. }
  240. }
  241. },
  242. series: [{
  243. // name: "火灾",
  244. name: seriesData[0].name,
  245. type: "line",
  246. areaStyle: {
  247. normal: {
  248. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  249. offset: 0,
  250. color: 'rgba(111,153,250,0.3)'
  251. },
  252. {
  253. offset: 1,
  254. color: 'rgba(111,153,250,0)'
  255. }
  256. ], false),
  257. shadowColor: 'rgba(111,153,250, 0.9)',
  258. shadowBlur: 20
  259. }
  260. },
  261. data: seriesData[0].data
  262. //data: [1, 5, 8, 3, 3, 5]
  263. }, {
  264. // name: "水系统",
  265. name: seriesData[1].name,
  266. type: "line",
  267. areaStyle: {
  268. normal: {
  269. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  270. offset: 0,
  271. color: 'rgba(255,88,1,0.3)'
  272. },
  273. {
  274. offset: 1,
  275. color: 'rgba(255,88,1,0)'
  276. }
  277. ], false),
  278. shadowColor: 'rgba(255,88,1, 0.9)',
  279. shadowBlur: 20
  280. }
  281. },
  282. //data: [9, 5, 3, 7, 6, 3]
  283. data: seriesData[1].data
  284. }, {
  285. //name: "烟雾",
  286. name: seriesData[2].name,
  287. type: "line",
  288. areaStyle: {
  289. normal: {
  290. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  291. offset: 0,
  292. color: 'rgba(234,246,101,0.3)'
  293. },
  294. {
  295. offset: 1,
  296. color: 'rgba(234,246,101,0)'
  297. }
  298. ], false),
  299. shadowColor: 'rgba(234,246,101, 0.9)',
  300. shadowBlur: 20
  301. }
  302. },
  303. data: seriesData[1].data
  304. //data: [4, 6, 3, 9, 7, 3]
  305. }]
  306. };
  307. myChart.setOption(option);
  308. myChart.setOption(option);
  309. window.addEventListener("resize", function() {
  310. myChart.resize();
  311. });
  312. })();
  313. /* 横向柱状图 */
  314. (function() {
  315. var pie = result.warning;
  316. var totalNum = pie.wait_handle + pie.is_handled;
  317. var data = [totalNum, pie.is_handled, pie.wait_handle]
  318. var myChartWaring = echarts.init(document.querySelector(".right-top .chart"));
  319. option = {
  320. grid: {
  321. // width: '100%',
  322. top: '15%',
  323. right: '10%',
  324. bottom: '0%',
  325. left: '10%'
  326. },
  327. color: ['#6F99FA', '#EAF665', '#FF5801'],
  328. xAxis: [{
  329. show: false,
  330. max: totalNum ? totalNum : 100,
  331. }],
  332. yAxis: [{
  333. axisTick: 'none',
  334. axisLine: 'none',
  335. axisLabel: {
  336. verticalAlign: 'bottom',
  337. align: 'left',
  338. padding: [0, 0, 15, 5],
  339. textStyle: {
  340. color: '#FFFFFF',
  341. }
  342. },
  343. data: ['总报警数', '已处置数', '待处置数'],
  344. },
  345. {
  346. //左侧柱状图的Y轴
  347. axisTick: 'none',
  348. axisLine: 'none',
  349. // data: [1357, 1260, 36],
  350. data: data,
  351. axisLabel: {
  352. show: true,
  353. verticalAlign: 'bottom',
  354. align: 'right',
  355. padding: [0, 15, 15, 0],
  356. textStyle: {
  357. color: '#fff',
  358. },
  359. formatter: function(value) {
  360. return value + '个'
  361. }
  362. }
  363. },
  364. ],
  365. series: [{
  366. type: 'bar',
  367. // data: [1357, , ],
  368. data: [totalNum, , ],
  369. barWidth: 10,
  370. itemStyle: {},
  371. z: 2
  372. }, {
  373. type: 'bar',
  374. // data: [, 1260, ],
  375. data: [, pie.is_handled, ],
  376. barWidth: 10,
  377. itemStyle: {},
  378. z: 2
  379. }, {
  380. type: 'bar',
  381. // data: [, , 36],
  382. data: [, , pie.wait_handle],
  383. barWidth: 10,
  384. itemStyle: {},
  385. z: 2
  386. },
  387. {
  388. type: 'bar',
  389. barGap: '-100%',
  390. // data: [1054, 1054, 1054],
  391. // data: [totalNum, totalNum, totalNum],
  392. data: totalNum ? [totalNum, totalNum, totalNum] : [100, 100, 100],
  393. barWidth: 10,
  394. itemStyle: {
  395. normal: {
  396. color: 'rgba(255, 255, 255, 0.15)',
  397. // barBorderRadius: 6,
  398. }
  399. },
  400. z: 0
  401. },
  402. ]
  403. };
  404. myChartWaring.setOption(option);
  405. window.addEventListener("resize", function() {
  406. myChartWaring.resize();
  407. });
  408. })();
  409. // 设备隐患
  410. (function() {
  411. var colorGroup = ['color-green', 'color-red', 'color-yellow', 'color-blue'];
  412. var handle = result.handle
  413. var items = '';
  414. handle.forEach(function(item, key) {
  415. items += ' <li><div><p class="num-huan ' + colorGroup[key] + '">' + item.value + '</p><p class="des-huan">' + item.name + '</p><div></li>';
  416. })
  417. $('#pop').html(items)
  418. })();
  419. // 异常设备数
  420. (function() {
  421. var colorGroup = ['color-green', 'color-red', 'color-yellow', 'color-blue'];
  422. var Abnormal = result.Abnormal;
  423. var items = '';
  424. Abnormal.forEach(function(item, key) {
  425. var processClassName = item.status == '超时' ? 'unprocess' : 'processed';
  426. items += ` <tr>
  427. <td>${item.id}</td>
  428. <td>${item.name}</td>
  429. <td class="` + processClassName + `">${item.status}</td>
  430. <td>${item.time}</td>
  431. </tr>`
  432. })
  433. $('.abnormal').html(items)
  434. // setInterval(getDate(), 1000)
  435. })();
  436. }, function(errorMsg) {
  437. alert("请求数据失败!");
  438. })
  439. }
  440. //园区实时报警统计 时间获取
  441. (function() {
  442. time();
  443. var t = null;
  444. t = setTimeout(time, 1000);
  445. function time() {
  446. clearTimeout(t); //清除定时器
  447. dt = new Date();
  448. var h = Appendzero(dt.getHours()).toString().split(""); //获取时
  449. var m = Appendzero(dt.getMinutes()).toString().split(""); //获取分
  450. // var aa = h.toString().split("");
  451. // var bb = m.toString(h).split("");
  452. var times = h.concat(m)
  453. var list = "";
  454. for (var i = 0; i < times.length; i++) {
  455. list += `<div class="total-square">${times[i]}</div> `
  456. }
  457. document.querySelector(".total-squares").innerHTML = list;
  458. t = setTimeout(time, 1000); //设定定时器,循环运行
  459. }
  460. //个位数补零
  461. function Appendzero(obj) {
  462. if (obj < 10) return "0" + obj;
  463. else return obj;
  464. }
  465. })();
  466. // 实时告警信息
  467. (function() {
  468. function getDate() {
  469. $.ajax({
  470. url: "data/pie.json",
  471. type: "GET",
  472. dataType: "json", //返回数据格式为json
  473. beforeSend: function(XMLHttpRequest) {
  474. // $("#loading").html("<img src='images/loading.gif' />")
  475. },
  476. success: function(result) {
  477. var warningInfo = result.warningInfo;
  478. var items = '';
  479. warningInfo.forEach(function(item, key) {
  480. var statusMessage = item.status ? '已处理' : '未处理';
  481. var processClassName = item.status ? 'processed' : 'unprocess';
  482. items += ` <tr>
  483. <td>${item.id}</td>
  484. <td>${item.time}</td>
  485. <td> ${item.type} </td>
  486. <td>${item.details} </td>
  487. <td class="` + processClassName + `">${statusMessage}</td>
  488. </tr>`
  489. })
  490. $('.warning-info').html(items)
  491. },
  492. error: function(errorMsg) {
  493. // alert("图表请求数据失败!");
  494. $("#loading").empty();
  495. // myChart1.hideLoading();
  496. }
  497. });
  498. }
  499. getDate()
  500. // setInterval(getDate(), 1000)
  501. })();
  502. //实时告警信息 (websocket实时推送)
  503. (function() {
  504. var arrData = [];
  505. var wsUri = "wss://iot.usky.cn:55120";
  506. function initWebSocket() {
  507. try {
  508. if (typeof MozWebSocket == 'function')
  509. WebSocket = MozWebSocket;
  510. websocket = new WebSocket(wsUri);
  511. websocket.onopen = function(evt) {
  512. var json = {};
  513. json.agentid = 'admin';
  514. // console.log("Connected.");
  515. (function() {})()
  516. websocket.send(JSON.stringify(json));
  517. };
  518. websocket.onclose = function(evt) {
  519. // console.log("DisConnected.");
  520. (function() {})()
  521. initWebSocket();
  522. };
  523. websocket.onmessage = function(evt) {
  524. var warningInfo = eval('(' + evt.data + ')');
  525. if (warningInfo.dwtype) {
  526. arrData.push(warningInfo)
  527. console.log('arrData')
  528. // console.log(arrData)
  529. }
  530. var items = '';
  531. arrData.forEach(function(item, index) {
  532. items += ` <tr>
  533. <td >${index+1}</td>
  534. <td >${item.time}</td>
  535. <td >${item.dwtype} </td>
  536. <td title="${item.evtname}"> ${item.evtname}</td>
  537. <td >${item.insertid} </td>
  538. </tr>`
  539. })
  540. $('.warning-info').html(items)
  541. };
  542. websocket.onerror = function(evt) {
  543. // console.log("Error:", evt.data);
  544. (function() {})()
  545. };
  546. } catch (exception) {
  547. // console.log("Exception:", exception);
  548. (function() {})()
  549. }
  550. }
  551. initWebSocket();
  552. })()