index.js 20 KB

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