index.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  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: '0%',
  324. bottom: '0%',
  325. left: '10%'
  326. },
  327. color: ['#6F99FA', '#EAF665', '#FF5801'],
  328. xAxis: [{
  329. show: false
  330. }],
  331. yAxis: [{
  332. axisTick: 'none',
  333. axisLine: 'none',
  334. axisLabel: {
  335. verticalAlign: 'bottom',
  336. align: 'left',
  337. padding: [0, 0, 15, 5],
  338. textStyle: {
  339. color: '#FFFFFF',
  340. }
  341. },
  342. data: ['总报警数', '已处置数', '待处置数'],
  343. },
  344. {
  345. //左侧柱状图的Y轴
  346. axisTick: 'none',
  347. axisLine: 'none',
  348. // data: [1357, 1260, 36],
  349. data: data,
  350. axisLabel: {
  351. show: true,
  352. verticalAlign: 'bottom',
  353. align: 'right',
  354. padding: [0, 45, 15, 0],
  355. textStyle: {
  356. color: '#fff',
  357. },
  358. formatter: function(value) {
  359. return value + '个'
  360. }
  361. }
  362. },
  363. ],
  364. series: [{
  365. type: 'bar',
  366. // data: [1357, , ],
  367. data: [totalNum, , ],
  368. barWidth: 10,
  369. itemStyle: {},
  370. z: 2
  371. }, {
  372. type: 'bar',
  373. // data: [, 1260, ],
  374. data: [, pie.is_handled, ],
  375. barWidth: 10,
  376. itemStyle: {},
  377. z: 2
  378. }, {
  379. type: 'bar',
  380. // data: [, , 36],
  381. data: [, , pie.wait_handle],
  382. barWidth: 10,
  383. itemStyle: {},
  384. z: 2
  385. },
  386. {
  387. type: 'bar',
  388. barGap: '-100%',
  389. // data: [1054, 1054, 1054],
  390. data: [totalNum, totalNum, totalNum],
  391. barWidth: 10,
  392. itemStyle: {
  393. normal: {
  394. color: 'rgba(255, 255, 255, 0.15)',
  395. // barBorderRadius: 6,
  396. }
  397. },
  398. z: 0
  399. },
  400. ]
  401. };
  402. myChartWaring.setOption(option);
  403. window.addEventListener("resize", function() {
  404. myChartWaring.resize();
  405. });
  406. })();
  407. // 设备隐患
  408. (function() {
  409. var colorGroup = ['color-green', 'color-red', 'color-yellow', 'color-blue'];
  410. var handle = result.handle
  411. var items = '';
  412. handle.forEach(function(item, key) {
  413. items += ' <li><div><p class="num-huan ' + colorGroup[key] + '">' + item.value + '</p><p class="des-huan">' + item.name + '</p><div></li>';
  414. })
  415. $('#pop').html(items)
  416. })();
  417. // 异常设备数
  418. (function() {
  419. var colorGroup = ['color-green', 'color-red', 'color-yellow', 'color-blue'];
  420. var Abnormal = result.Abnormal;
  421. var items = '';
  422. Abnormal.forEach(function(item, key) {
  423. var processClassName = item.status == '超时' ? 'unprocess' : 'processed';
  424. items += ` <tr>
  425. <td>${item.id}</td>
  426. <td>${item.name}</td>
  427. <td class="` + processClassName + `">${item.status}</td>
  428. <td>${item.time}</td>
  429. </tr>`
  430. })
  431. $('.abnormal').html(items)
  432. // setInterval(getDate(), 1000)
  433. })();
  434. }, function(errorMsg) {
  435. alert("请求数据失败!");
  436. })
  437. }
  438. //园区实时报警统计 时间获取
  439. (function() {
  440. time();
  441. var t = null;
  442. t = setTimeout(time, 1000);
  443. function time() {
  444. clearTimeout(t); //清除定时器
  445. dt = new Date();
  446. var h = Appendzero(dt.getHours()).toString().split(""); //获取时
  447. var m = Appendzero(dt.getMinutes()).toString().split(""); //获取分
  448. // var aa = h.toString().split("");
  449. // var bb = m.toString(h).split("");
  450. var times = h.concat(m)
  451. var list = "";
  452. for (var i = 0; i < times.length; i++) {
  453. list += `<div class="total-square">${times[i]}</div> `
  454. }
  455. document.querySelector(".total-squares").innerHTML = list;
  456. t = setTimeout(time, 1000); //设定定时器,循环运行
  457. }
  458. //个位数补零
  459. function Appendzero(obj) {
  460. if (obj < 10) return "0" + obj;
  461. else return obj;
  462. }
  463. })();
  464. // 实时告警信息
  465. (function() {
  466. function getDate() {
  467. $.ajax({
  468. url: "data/pie.json",
  469. type: "GET",
  470. dataType: "json", //返回数据格式为json
  471. beforeSend: function(XMLHttpRequest) {
  472. // $("#loading").html("<img src='images/loading.gif' />")
  473. },
  474. success: function(result) {
  475. var warningInfo = result.warningInfo;
  476. var items = '';
  477. warningInfo.forEach(function(item, key) {
  478. var statusMessage = item.status ? '已处理' : '未处理';
  479. var processClassName = item.status ? 'processed' : 'unprocess';
  480. items += ` <tr>
  481. <td>${item.id}</td>
  482. <td>${item.time}</td>
  483. <td> ${item.type} </td>
  484. <td>${item.details} </td>
  485. <td class="` + processClassName + `">${statusMessage}</td>
  486. </tr>`
  487. })
  488. $('.warning-info').html(items)
  489. },
  490. error: function(errorMsg) {
  491. // alert("图表请求数据失败!");
  492. $("#loading").empty();
  493. // myChart1.hideLoading();
  494. }
  495. });
  496. }
  497. getDate()
  498. // setInterval(getDate(), 1000)
  499. })();
  500. //实时告警信息 (websocket实时推送)
  501. (function() {
  502. var arrData = [];
  503. var wsUri = "wss://iot.usky.cn:55120";
  504. function initWebSocket() {
  505. try {
  506. if (typeof MozWebSocket == 'function')
  507. WebSocket = MozWebSocket;
  508. websocket = new WebSocket(wsUri);
  509. websocket.onopen = function(evt) {
  510. var json = {};
  511. json.agentid = 'admin';
  512. // console.log("Connected.");
  513. (function() {})()
  514. websocket.send(JSON.stringify(json));
  515. };
  516. websocket.onclose = function(evt) {
  517. // console.log("DisConnected.");
  518. (function() {})()
  519. initWebSocket();
  520. };
  521. websocket.onmessage = function(evt) {
  522. var warningInfo = eval('(' + evt.data + ')');
  523. if (warningInfo.dwtype) {
  524. arrData.push(warningInfo)
  525. // console.log('arrData')
  526. // console.log(arrData)
  527. }
  528. var items = '';
  529. arrData.forEach(function(item, index) {
  530. items += ` <tr>
  531. <td >${index+1}</td>
  532. <td >${item.time}</td>
  533. <td >${item.dwtype} </td>
  534. <td title="${item.evtname}"> ${item.evtname}</td>
  535. <td >${item.insertid} </td>
  536. </tr>`
  537. })
  538. $('.warning-info').html(items)
  539. };
  540. websocket.onerror = function(evt) {
  541. // console.log("Error:", evt.data);
  542. (function() {})()
  543. };
  544. } catch (exception) {
  545. // console.log("Exception:", exception);
  546. (function() {})()
  547. }
  548. }
  549. initWebSocket();
  550. })()