DataTool.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. <!DOCTYPE html>
  2. <html class="x-admin-sm">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="renderer" content="webkit">
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  7. <meta name="viewport"
  8. content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
  9. <link rel="shortcut icon" href="https://osscold.baozhida.cn/favicon.ico">
  10. <link rel="bookmark" href="https://osscold.baozhida.cn/favicon.ico">
  11. <link rel="stylesheet" href="https://osscold.baozhida.cn/css/font.css">
  12. <link rel="stylesheet" href="https://osscold.baozhida.cn/css/xadmin.css">
  13. <script src="https://osscold.baozhida.cn/js/jquery.min.js"></script>
  14. <script src="https://osscold.baozhida.cn/js/jquery.cookie.min.js"></script>
  15. <script src="https://osscold.baozhida.cn/lib/layui/layui.js" charset="utf-8"></script>
  16. <script src="https://osscold.baozhida.cn/js/echarts.js" charset="utf-8"></script>
  17. <script type="text/javascript" src="https://osscold.baozhida.cn/js/xadmin.js"></script>
  18. <script type="text/javascript" src='https://osscold.baozhida.cn/js/xlsx.full.min.js'></script>
  19. <style>
  20. .kuangk{
  21. border:1px solid;padding: 2px 4px;
  22. color: #1E9FFF;
  23. font-size: 20px;
  24. }
  25. </style>
  26. </head>
  27. <body>
  28. <div class="layui-fluid">
  29. <div class="layui-row">
  30. <!-- // 传感器 选择-->
  31. <div class="layui-col-md12">
  32. <div class="layui-card">
  33. <div class="layui-card-body ">
  34. <div class="layui-input-inline layui-show-xs-block">
  35. <input id="lefile" type="file" hidden >
  36. <div onclick="document.getElementById('lefile').click();" class="layui-btn layui-btn-normal">
  37. <i class="layui-icon">导入数据</i>
  38. </div>
  39. </div>
  40. <div class="layui-input-inline layui-show-xs-block">
  41. <label class="layui-form-label">标题:</label>
  42. <div class="layui-input-block">
  43. <input type="text" onchange="onchanget(this)" name="" value="这里是标题" placeholder="这里是标题" autocomplete="off" class="layui-input">
  44. </div>
  45. </div>
  46. <div class="layui-input-inline layui-show-xs-block">
  47. <label class="layui-form-label">温度阈值:</label>
  48. <div class="layui-input-block">
  49. <input type="text" id="T_a" style="width: 50px;float: left;" value="2" autocomplete="off" class="layui-input">
  50. <input type="text" id="T_b" style="width: 50px;float: left;" value="30" autocomplete="off" class="layui-input">
  51. </div>
  52. </div>
  53. <div class="layui-input-inline layui-show-xs-block">
  54. <label class="layui-form-label">湿度阈值:</label>
  55. <div class="layui-input-block">
  56. <input type="text" id="H_a" style="width: 50px;float: left;" value="35" autocomplete="off" class="layui-input">
  57. <input type="text" id="H_b" style="width: 50px;float: left;" value="75" autocomplete="off" class="layui-input">
  58. </div>
  59. </div>
  60. <div class="layui-input-inline layui-show-xs-block" style="float: right">
  61. <div class="layui-btn layui-btn-normal" onclick="window.location.href = 'https://osscold.baozhida.cn/js/导入模板.xlsx';">
  62. <i class="layui-icon">下载导入模板</i>
  63. </div>
  64. </div>
  65. <hr>
  66. </div>
  67. <div class="layui-card-body " >
  68. <div style="width: 99%;height:105px;">
  69. <h2 id="T_html_H" style="text-align: center;margin-bottom: 20px;font-size: 25px;">这里是标题</h2>
  70. <h3 id="T_html_time" style="text-align: center;width: 33%;float: left;"></h3>
  71. <h3 id="T_myChart_1_title" style="text-align: center;width: 33%;float: left;"></h3>
  72. <h3 id="T_myChart_2_title" style="text-align: center;width: 33%;float: left;"></h3>
  73. </div>
  74. <div id="T_myChart_1" style="width: 99%;height:335px;"></div>
  75. <div style="width: 99%;height:35px;">
  76. </div>
  77. <div id="T_myChart_2" style="width: 99%;height:335px;"></div>
  78. <div style="width: 99%;height:35px;">
  79. </div>
  80. </div>
  81. </div>
  82. </div>
  83. </div>
  84. </div>
  85. </div>
  86. </body>
  87. <script>
  88. // 页面 加载完成后执行
  89. window.onload = function () {
  90. console.log("页面 加载完成后执行")
  91. f_myChart_todata_inte()
  92. }
  93. function onchanget(t) {
  94. $("#T_html_H").html(t.value)
  95. }
  96. </script>
  97. <script>
  98. var fileType = 0; //默认0(0不正确,1正确)
  99. var wb; //读取Excel的数据
  100. var rABS = false; //是否将文件读取为二进制字符串
  101. var excelTab; //Excel
  102. $("#lefile").on('change',function(){
  103. var file = $('#lefile').get(0); //得到文件对象
  104. var filename = $("#lefile").val();
  105. var idx = filename.lastIndexOf(".");
  106. if (idx != -1){
  107. ext = filename.substr(idx+1).toUpperCase();
  108. ext = ext.toLowerCase( );
  109. // alert("ext="+ext);
  110. if (ext != 'xls' && ext != 'xlsx' ){
  111. alert("只能上传.xls和.xlsx类型的文件!");
  112. fileType = 0;
  113. return;
  114. }else{
  115. fileType = 1;
  116. }
  117. if(fileType == 0){
  118. alert("只能上传.xls和.xlsx类型的文件!");
  119. return;
  120. }else{
  121. var file = $('#lefile').get(0); //得到文件对象
  122. importf(file); //进行读取操作
  123. }
  124. } else {
  125. alert("只能上传.xls和.xlsx类型的文件!");
  126. fileType = 0;
  127. return;
  128. }
  129. })
  130. function importf(obj) {
  131. if(!obj.files) {
  132. return;
  133. }
  134. var f = obj.files[0];
  135. var reader = new FileReader();
  136. reader.onload = function(e) {
  137. var data = e.target.result;
  138. if(rABS) {
  139. wb = XLSX.read(btoa(fixdata(data)), {//手动转化
  140. type: 'base64'
  141. });
  142. } else {
  143. wb = XLSX.read(data, {
  144. type: 'binary'
  145. });
  146. }
  147. excelTab = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]);
  148. console.log(excelTab);
  149. printData(excelTab);
  150. };
  151. if(rABS) {
  152. reader.readAsArrayBuffer(f);
  153. } else {
  154. reader.readAsBinaryString(f);
  155. }
  156. }
  157. function fixdata(data) { //文件流转BinaryString
  158. var o = "",
  159. l = 0,
  160. w = 10240;
  161. for(; l < data.byteLength / w; ++l) o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w, l * w + w)));
  162. o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w)));
  163. return o;
  164. }
  165. name_x = 1
  166. function printData(excelTab){
  167. dataList = []
  168. for( var i = 0; i < excelTab.length; i++ ){
  169. dataList.push({
  170. T_t:excelTab[i].温度,
  171. T_rh:excelTab[i].湿度,
  172. T_time:excelTab[i].记录时间,
  173. })
  174. }
  175. //例子2
  176. layer.prompt({
  177. formType: 0,
  178. value: '数据'+name_x,
  179. title: '请输入 监测点名称',
  180. // area: ['800px', '350px'] //自定义文本域宽高
  181. }, function(value, index, elem){
  182. layer.close(index);
  183. f_Data_to_myChart(value,dataList)
  184. name_x += 1
  185. });
  186. }
  187. </script>
  188. <!-- 多个 图表-->
  189. <script>
  190. // 最高温度、最低温度、平均温度、超标温度累积时长
  191. var T_myChart_List_M = []
  192. var H_myChart_List_M = []
  193. function f_myChart_todata_inte() {
  194. T_myChart_List_M = [] // 清空
  195. H_myChart_List_M = [] // 清空
  196. $("#T_myChart_2").show()
  197. $("#T_myChart_2_title").show()
  198. T_myChart = echarts.init(document.getElementById('T_myChart_1'));
  199. H_myChart = echarts.init(document.getElementById('T_myChart_2'));
  200. $("#T_myChart_1_title").html("")
  201. $("#T_myChart_2_title").html("")
  202. T_time_a = new Date("2099-05-08 00:00:00").getTime();
  203. T_time_b = new Date("2000-05-08 00:00:00").getTime();
  204. }
  205. var M_T_n_max = 0
  206. var M_T_n_min = 999
  207. var M_T_n_ave_num = 0
  208. var M_T_n_ave_sum = 0
  209. var M_H_n_max = 0
  210. var M_H_n_min = 999
  211. var M_H_n_ave_num = 0
  212. var M_H_n_ave_sum = 0
  213. var T_time_a = ""
  214. var T_time_b = ""
  215. function f_Data_to_myChart(List_name,data) {
  216. data_1 = []
  217. data_2 = []
  218. console.log(data)
  219. T_time_a
  220. for (let i = 0; i < data.length; i++) {
  221. startT = new Date(data[i].T_time).getTime();
  222. if(startT < T_time_a){
  223. T_time_a = startT
  224. $("#T_html_time").html("<spen class='kuangk'>时间:"+timestampToTime(T_time_a)+" ~ "+timestampToTime(T_time_b)+"</spen>")
  225. }
  226. if(startT > T_time_b){
  227. T_time_b = startT
  228. $("#T_html_time").html("<spen class='kuangk'>时间:"+timestampToTime(T_time_a)+" ~ "+timestampToTime(T_time_b)+"</spen>")
  229. }
  230. // 温度
  231. if (data[i].T_t == undefined) continue;
  232. if (data[i].T_t == "") continue;
  233. data[i].T_t = parseFloat(data[i].T_t)
  234. data_1.unshift([data[i].T_time,data[i].T_t])
  235. if(data[i].T_t > M_T_n_max){
  236. M_T_n_max = data[i].T_t
  237. }
  238. if(data[i].T_t < M_T_n_min){
  239. M_T_n_min = data[i].T_t
  240. }
  241. M_T_n_ave_num += 1
  242. M_T_n_ave_sum += data[i].T_t
  243. // 湿度
  244. if (data[i].T_rh == undefined) continue;
  245. if (data[i].T_rh == "") continue;
  246. data[i].T_rh = parseFloat(data[i].T_rh)
  247. data_2.unshift([data[i].T_time,data[i].T_rh])
  248. if(data[i].T_rh > M_H_n_max){
  249. M_H_n_max = data[i].T_rh
  250. }
  251. if(data[i].T_rh < M_H_n_min){
  252. M_H_n_min = data[i].T_rh
  253. }
  254. M_H_n_ave_num += 1
  255. M_H_n_ave_sum += data[i].T_rh
  256. }
  257. console.log("M_T_n_ave_num:",M_T_n_ave_num)
  258. console.log("M_T_n_ave_sum:",M_T_n_ave_sum)
  259. $("#T_myChart_1_title").html("<spen class='kuangk' style='width: 120px;'>最高温度:"+parseFloat(M_T_n_max).toFixed(1)+"℃</spen><spen class='kuangk' style='width: 120px;'>最低温度"+parseFloat(M_T_n_min).toFixed(1)+"℃</spen><spen class='kuangk' style='width: 120px;'>平均温度:"+parseFloat(M_T_n_ave_sum/M_T_n_ave_num).toFixed(1)+"℃</spen> ")
  260. $("#T_myChart_2_title").html("<spen class='kuangk' style='width: 120px;'>最高湿度:"+parseFloat(M_H_n_max).toFixed(1)+"%</spen><spen class='kuangk' style='width: 120px;'>最低湿度"+parseFloat(M_H_n_min).toFixed(1)+"%</spen><spen class='kuangk' style='width: 120px;'>平均湿度:"+parseFloat(M_H_n_ave_sum/M_H_n_ave_num).toFixed(1)+"%</spen> ")
  261. T_myChart_List_M.push({
  262. name: List_name,
  263. type: 'line',
  264. // stack: 'Total',
  265. smooth: true,
  266. data: data_1,
  267. // markLine: {
  268. // data: [
  269. // {
  270. // silent:true, //鼠标悬停事件 true没有,false有
  271. // lineStyle:{ //警戒线的样式 ,虚实 颜色
  272. // type:"solid",
  273. // color:"#FF4200",
  274. // width: 3,
  275. // },
  276. // label:{
  277. // position:'end',
  278. // formatter:"下限("+data[0].T_Tlower+"℃)"
  279. // },
  280. // yAxis:data[0].T_Tlower
  281. // },
  282. // {
  283. // silent:true, //鼠标悬停事件 true没有,false有
  284. // lineStyle:{ //警戒线的样式 ,虚实 颜色
  285. // type:"solid",
  286. // color:"#FF4200",
  287. // width: 3,
  288. // },
  289. // label:{
  290. // position:'end',
  291. // formatter:"上限("+data[0].T_Tupper+"℃)"
  292. // },
  293. // yAxis:data[0].T_Tupper
  294. // }
  295. // ]
  296. // }
  297. })
  298. H_myChart_List_M.push({
  299. name: List_name,
  300. type: 'line',
  301. // stack: 'Total',
  302. smooth: true,
  303. data: data_2,
  304. // markLine: {
  305. // data: [
  306. // {
  307. // silent:true, //鼠标悬停事件 true没有,false有
  308. // lineStyle:{ //警戒线的样式 ,虚实 颜色
  309. // type:"solid",
  310. // color:"#FF4200",
  311. // width: 3,
  312. // },
  313. // label:{
  314. // position:'end',
  315. // formatter:"下限("+data[0].T_RHlower+"℃)"
  316. // },
  317. // yAxis:data[0].T_RHlower
  318. // },
  319. // {
  320. // silent:true, //鼠标悬停事件 true没有,false有
  321. // lineStyle:{ //警戒线的样式 ,虚实 颜色
  322. // type:"solid",
  323. // color:"#FF4200",
  324. // width: 3,
  325. // },
  326. // label:{
  327. // position:'end',
  328. // formatter:"上限("+data[0].T_RHupper+"℃)"
  329. // },
  330. // yAxis:data[0].T_RHupper
  331. // }
  332. // ]
  333. // }
  334. })
  335. var T_myChart_option_1 = {
  336. // title: {
  337. // top: '50px',
  338. // text: T_name+"["+T_id+"]:" + $("#Time_start").val() + '~' + $("#Time_end").val(),
  339. // textStyle:{
  340. // fontSize:14,
  341. // }
  342. // },
  343. tooltip: {
  344. trigger: 'axis'
  345. },
  346. toolbox: {
  347. show: false,
  348. feature: {
  349. dataZoom: {
  350. yAxisIndex: 'none'
  351. },
  352. dataView: { readOnly: false },
  353. magicType: { type: ['line', 'bar'] },
  354. restore: {},
  355. saveAsImage: {}
  356. }
  357. },
  358. grid: {
  359. top: '40px',
  360. left: '10px',
  361. right: '10px',
  362. bottom: '50px',
  363. containLabel: true
  364. },
  365. legend: {
  366. textStyle:{
  367. color:"#7c7c7c"
  368. }
  369. },
  370. xAxis: {
  371. type: 'time',
  372. boundaryGap: false,
  373. },
  374. yAxis: {
  375. type: 'value',
  376. axisLabel: {
  377. formatter: '{value} °C'
  378. },
  379. boundaryGap: [0, '100%'],
  380. max:$("#T_a").val(),
  381. min:$("#T_b").val(),
  382. },
  383. dataZoom: [
  384. {
  385. type: 'inside',
  386. start: 0,
  387. end: 100
  388. },
  389. {
  390. start: 0,
  391. end: 100
  392. }
  393. ],
  394. markPoint: {
  395. // data: [ {
  396. // name: '最大值',
  397. // type: 'max'
  398. // },{
  399. // name: '最小值',
  400. // type: 'min'
  401. // }
  402. // ]
  403. },
  404. series: T_myChart_List_M
  405. };
  406. // 初始化 图表
  407. T_myChart.setOption(T_myChart_option_1);
  408. var T_myChart_option_2 = {
  409. // title: {
  410. // top: '50px',
  411. // text: T_name+"["+T_id+"]:" + $("#Time_start").val() + '~' + $("#Time_end").val(),
  412. // textStyle:{
  413. // fontSize:14,
  414. // }
  415. // },
  416. tooltip: {
  417. trigger: 'axis'
  418. },
  419. toolbox: {
  420. show: false,
  421. feature: {
  422. dataZoom: {
  423. yAxisIndex: 'none'
  424. },
  425. dataView: { readOnly: false },
  426. magicType: { type: ['line', 'bar'] },
  427. restore: {},
  428. saveAsImage: {}
  429. }
  430. },
  431. grid: {
  432. top: '40px',
  433. left: '10px',
  434. right: '10px',
  435. bottom: '50px',
  436. containLabel: true
  437. },
  438. legend: {
  439. textStyle:{
  440. color:"#7c7c7c"
  441. }
  442. },
  443. xAxis: {
  444. type: 'time',
  445. boundaryGap: false,
  446. },
  447. yAxis: {
  448. type: 'value',
  449. axisLabel: {
  450. formatter: '{value} %'
  451. },
  452. boundaryGap: [0, '100%'],
  453. max:$("#H_a").val(),
  454. min:$("#H_b").val(),
  455. },
  456. dataZoom: [
  457. {
  458. type: 'inside',
  459. start: 0,
  460. end: 100
  461. },
  462. {
  463. start: 0,
  464. end: 100
  465. }
  466. ],
  467. markPoint: {
  468. // data: [ {
  469. // name: '最大值',
  470. // type: 'max'
  471. // },{
  472. // name: '最小值',
  473. // type: 'min'
  474. // }
  475. // ]
  476. },
  477. series: H_myChart_List_M
  478. };
  479. // 初始化 图表
  480. H_myChart.setOption(T_myChart_option_2);
  481. }
  482. //
  483. // function f_Refresh_T_myChart_1() {
  484. // T_myChart_1.clear();
  485. // //
  486. // // T_myChart_option_1.title.text =
  487. // T_myChart_option_1.series = T_myChart_List_1
  488. // T_myChart_option_1.yAxis.max = T_myChart_max_1
  489. // T_myChart_option_1.yAxis.min = T_myChart_min_1
  490. // T_myChart_option_1.yAxis.axisLabel.formatter = '{value} ℃'
  491. // T_myChart_1.setOption(T_myChart_option_1);
  492. // }
  493. </script>
  494. <script>
  495. function timestampToTime(timestamp) {
  496. if(timestamp.length == 10) {
  497. timestamp = timestamp * 1000
  498. }
  499. var date = new Date(timestamp); //时间戳为10位需*1000,时间戳为13位的话不需乘1000
  500. var Y = date.getFullYear() + '-';
  501. var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
  502. var D = date.getDate()< 10 ? '0' +date.getDate() + ' ': date.getDate() + ' ';
  503. var h = date.getHours()< 10 ? '0' + date.getHours() + ':' : date.getHours() + ':';
  504. var m = date.getMinutes() < 10 ? '0' + date.getMinutes() + ':' : date.getMinutes() + ':';
  505. var s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds() ;
  506. return Y + M + D + h + m + s;
  507. }
  508. </script>
  509. </html>