DataRealCalss.html 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  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 type="text/javascript" src="https://osscold.baozhida.cn/js/xadmin.js"></script>
  17. </head>
  18. <body>
  19. <div class="x-nav">
  20. <span class="layui-breadcrumb">
  21. <a href="">首页</a>
  22. <a><cite>宝智达</cite></a>
  23. </span>
  24. <a class="layui-btn layui-btn-normal" style="line-height:1.6em;margin-top:3px;float:right"
  25. onclick="location.reload()" title="刷新">
  26. <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
  27. </a>
  28. </div>
  29. <div class="layui-fluid">
  30. <div class="layui-row">
  31. <!-- // 传感器 选择-->
  32. <div class="layui-col-md12">
  33. <div class="layui-card">
  34. <div class="layui-card-body ">
  35. <form class="layui-form layui-col-space5" οnsubmit="return false;">
  36. <div class="layui-input-inline layui-show-xs-block">
  37. <input value="" type="text" id="D_T_sn" name="D_T_sn" placeholder="请输入 SN"
  38. autocomplete="off"
  39. class="layui-input"></div>
  40. <div class="layui-input-inline layui-show-xs-block">
  41. <input value="" type="text" id="D_Name" name="D_Name" placeholder="请输入 传感器名称"
  42. autocomplete="off"
  43. class="layui-input"></div>
  44. <div class="layui-input-inline layui-show-xs-block">
  45. <select id="Class_1" name="Class_1">
  46. <option value=0>所有分类</option>
  47. {{range $index, $elem := .Class_List}}
  48. <option value={{$elem.Id}}>{{$elem.T_name}}
  49. </option>
  50. {{end}}
  51. </select>
  52. </div>
  53. <div class="layui-input-inline layui-show-xs-block">
  54. <div class="layui-btn layui-btn-normal"
  55. onclick="get_DeviceSensor_list(0)">
  56. <i class="layui-icon">&#xe615;</i></div>
  57. </div>
  58. </form>
  59. <hr>
  60. </div>
  61. <div class="layui-card-body " style="margin-top: -20px">
  62. <div id="DeviceSensor_list" style="width: 98%; overflow: hidden;">
  63. <div style="color: #1E9FFF;text-align: center;font-size: 15px;margin-top: 150px">加载中...</div>
  64. <!-- <div class="layui-col"-->
  65. <!-- style="height: 52px;background-color: #fafafa;border-radius:5px;padding-top: 2px;">-->
  66. <!-- <img style="float: left;width: 50px;margin: 0px 10px" src="https://osscold.baozhida.cn/images/温湿度传感器-1.png"-->
  67. <!-- height="50"-->
  68. <!-- width="40"/>-->
  69. <!-- <div style="float: left;">-->
  70. <!-- <div style="margin-top: 4px;font-size: 14px">士大夫撒地方递四方速递</div>-->
  71. <!-- <div style="margin-top: -3px;font-size: 12px">SN:KF20210510143443 [1]</div>-->
  72. <!-- </div>-->
  73. <!-- <div class="layui-card-header"-->
  74. <!-- style="float: right;padding-left: 0px;padding-top: 6px;color: #1E9FFF">-->
  75. <!-- 》-->
  76. <!-- </div>-->
  77. <!-- </div>-->
  78. </div>
  79. </div>
  80. <div class="layui-card-body " >
  81. <div style="height: 100px">
  82. <div >
  83. <span id="T_time" style="font-size: 14px">更新时间:等待同步中.....</span><img style="margin-left: 2px"
  84. src="https://osscold.baozhida.cn/images/等待.gif" height="20"
  85. width="20"/>
  86. </div>
  87. <div class="layui-card-body ">
  88. <div class="page">
  89. <div id="DeviceSensor_list_Pages">
  90. <!-- <a class="prev" href="">&lt;&lt;</a>-->
  91. <!-- <a class="num" href="">1222</a>-->
  92. <!-- <span class="current">111</span>-->
  93. <!-- <a class="num" href="">444</a>-->
  94. <!-- <a class="next" href="">&gt;&gt;</a>-->
  95. </div>
  96. </div>
  97. <div style="color: #1E9FFF;text-align: center" id="DeviceSensor_list_Pages_x"></div>
  98. </div>
  99. </div>
  100. </div>
  101. </div>
  102. </div>
  103. </div>
  104. </div>
  105. </div>
  106. </body>
  107. <script>
  108. //获取GET
  109. function getPar(par) {
  110. //获取当前URL
  111. var local_url = document.location.href;
  112. //获取要取得的get参数位置
  113. var get = local_url.indexOf(par + "=")
  114. ;
  115. if (get == -1) {
  116. return false;
  117. }
  118. //截取字符串
  119. //截取字符串
  120. var get_par = local_url.slice(par.length + get + 1);
  121. //判断截取后的字符串是否还有其他get参数
  122. var nextPar = get_par.indexOf("&")
  123. ;
  124. if (nextPar != -1) {
  125. get_par = get_par.slice(0, nextPar);
  126. }
  127. return get_par;
  128. }
  129. function timestampToTime(timestamp) {
  130. if(timestamp == undefined){
  131. return "<img src=\"https://osscold.baozhida.cn/images/等待.gif\" style='float: left' height=\"16\" width=\"16\"/>"
  132. }
  133. var date = new Date(timestamp * 1000);//时间戳为10位需*1000,时间戳为13位的话不需乘1000
  134. Y = date.getFullYear() + '-';
  135. M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
  136. D = date.getDate() + ' ';
  137. h = date.getHours() + ':';
  138. m = date.getMinutes() + ':';
  139. s = date.getSeconds();
  140. return Y + M + D + h + m + s;
  141. }
  142. function dateChangeFormat(format, date) {
  143. date = new Date(date);
  144. const dataItem = {
  145. 'Y+': date.getFullYear().toString(),
  146. 'm+': (date.getMonth() + 1).toString(),
  147. 'd+': date.getDate().toString(),
  148. 'H+': date.getHours().toString(),
  149. 'M+': date.getMinutes().toString(),
  150. 'S+': date.getSeconds().toString(),
  151. };
  152. Object.keys(dataItem).forEach((item) => {
  153. const ret = new RegExp(`(${item})`).exec(format);
  154. if (ret) {
  155. format = format.replace(ret[1], ret[1].length === 1 ? dataItem[item] : dataItem[item].padStart(ret[1].length, '0'));
  156. }
  157. });
  158. return format;
  159. }
  160. function dateChangeFormat_x(format, date) {
  161. date = new Date(date*1000);
  162. const dataItem = {
  163. 'Y+': date.getFullYear().toString(),
  164. 'm+': (date.getMonth() + 1).toString(),
  165. 'd+': date.getDate().toString(),
  166. 'H+': date.getHours().toString(),
  167. 'M+': date.getMinutes().toString(),
  168. 'S+': date.getSeconds().toString(),
  169. };
  170. Object.keys(dataItem).forEach((item) => {
  171. const ret = new RegExp(`(${item})`).exec(format);
  172. if (ret) {
  173. format = format.replace(ret[1], ret[1].length === 1 ? dataItem[item] : dataItem[item].padStart(ret[1].length, '0'));
  174. }
  175. });
  176. return format;
  177. }
  178. // 时间比较
  179. function dateChangeFormat_xiangcha( date) {
  180. console.log("===========")
  181. a_t = (new Date(dateChangeFormat('YYYY-mm-dd HH:MM:SS', date)).getTime()/1000)
  182. b_t = ((new Date()) / 1000)
  183. console.log("a_t:",a_t,"b_t:",b_t,">",b_t - a_t)
  184. return parseInt(b_t - a_t) ;
  185. }
  186. function To_str(data) {
  187. if(data == undefined){
  188. return "<img src=\"https://osscold.baozhida.cn/images/等待.gif\" style='float: left' height=\"16\" width=\"16\"/>"
  189. }
  190. if(data+"".length > 5){
  191. return data+"".slice(0,5);
  192. }
  193. return data;
  194. }
  195. function To_unm(data) {
  196. if(data == undefined){
  197. return "<img src=\"https://osscold.baozhida.cn/images/等待.gif\" style='float: left' height=\"16\" width=\"16\"/>"
  198. }
  199. return data.toFixed(1);
  200. }
  201. function To_time(data) {
  202. xx = dateChangeFormat_xiangcha(data)
  203. if(xx > Out_time){
  204. return "N";
  205. }
  206. return xx;
  207. }
  208. layui.use(['laydate', 'form'],
  209. function () {
  210. var laydate = layui.laydate;
  211. });
  212. var T_name = ""
  213. var T_sn = ""
  214. var T_class_id = 0
  215. var T_id = 0
  216. var T_sn_T_id = ""
  217. var Time_start = ""
  218. var Time_end = ""
  219. var T_sn_list = []
  220. var DeviceSensor_lite = []
  221. var DeviceSensor_data = []
  222. var timestamp_V = (new Date()) / 1000;
  223. var Out_time = 999;
  224. /// --------------- 传感器列表
  225. // 页面 加载完成后执行
  226. window.onload = function () {
  227. console.log("页面 加载完成后执行")
  228. setInterval(function(){
  229. //要执行的代码
  230. // console.log("setInterval===== 1S")
  231. xx = $("span[name='time_x']")
  232. for (let i = 0; i < xx.length; i++) {
  233. if(xx[i].innerHTML == "N"){
  234. continue;
  235. }
  236. if(xx[i].innerHTML > Out_time ){
  237. xx[i].innerHTML = "N"
  238. }
  239. xx[i].innerHTML = parseInt(xx[i].innerHTML) + 1
  240. }
  241. },1000);
  242. }
  243. function get_DeviceSensor_list(page) {
  244. T_sn = $("#D_T_sn").val();
  245. T_name = $("#D_Name").val();
  246. T_class_id = $("#Class_1").val();
  247. $.ajax({
  248. type: 'POST',
  249. url: 'Device_Sensor_List',//发送请求
  250. data: {
  251. User_tokey: $.cookie("User_tokey"),
  252. T_sn: T_sn,
  253. T_name: T_name,
  254. T_class_id: parseInt(T_class_id),
  255. page: page,
  256. page_z: 30,
  257. },
  258. success: function (result) {
  259. console.log(result)
  260. if (result.Code == 200) {
  261. $('#DeviceSensor_list').html("")
  262. $('#DeviceSensor_list_Pages').html("")
  263. $('#DeviceSensor_list_Pages_x').html("")
  264. DeviceSensor_lite = result.Data.DeviceSensor_lite
  265. if (DeviceSensor_lite.length == 0) {
  266. $('#DeviceSensor_list').html("<div style=\"color: #1E9FFF;text-align: center;font-size: 15px;margin-top: 150px\">没有设备</div>")
  267. return
  268. }
  269. Add_DeviceSensor_list(result.Data.DeviceSensor_lite) // 列表
  270. Add_DeviceSensor_list_Pages(result.Data.Pages) // 分页
  271. $('#DeviceSensor_list_Pages_x').append("页数:" + result.Data.Page + "/" + result.Data.Page_size + " 总数:" + result.Data.Num);
  272. } else {
  273. }
  274. }
  275. });
  276. return false
  277. }
  278. function Add_DeviceSensor_list(data) {
  279. $('#DeviceSensor_list').html("")
  280. for (let i = 0; i < data.length; i++) {
  281. if(T_sn_list.indexOf(data[i].T_sn) == -1 ){
  282. websocket.send("{\"Sn\":\"" + data[i].T_sn + "\"}");
  283. T_sn_list.push(data[i].T_sn)
  284. }
  285. src_img = "温湿度传感器-1.png"
  286. Ds = data[i]
  287. x_ = dateChangeFormat_xiangcha(Ds.T_time)
  288. outtime = 60 * 5
  289. if(( 0 == Ds.T_Tlower && 0 == Ds.T_RHlower) && ( 0 == Ds.T_Tupper && 0 == Ds.T_RHupper) ){
  290. if(x_ < outtime) {
  291. // 传感器正常
  292. src_img = "温湿度传感器-1.png"
  293. }else {
  294. // 传感器超时
  295. src_img = "温湿度传感器-2.png"
  296. }
  297. }else if (x_ < outtime) {
  298. if(Ds.T_t < Ds.T_Tlower || Ds.T_rh < Ds.T_RHlower || Ds.T_t > Ds.T_Tupper || Ds.T_rh > Ds.T_RHupper ){
  299. // 传感器 超标
  300. src_img = "温湿度传感器-3.png"
  301. }else {
  302. // 传感器正常
  303. src_img = "温湿度传感器-1.png"
  304. }
  305. }else {
  306. // 传感器超时
  307. src_img = "温湿度传感器-2.png"
  308. }
  309. $('#DeviceSensor_list').append("" +
  310. "<div name='"+data[i].T_sn+"' class=\"layui-col-xs5 layui-col-sm3 layui-col-md2 layui-col-lg2\" style=\"height: 104px; \" >\n" +
  311. " <div name='"+data[i].T_id+"' style=\"margin: 4px;height: 96px; border-radius:5px;background-color:#f1f1f1;\"\n" +
  312. " >\n" +
  313. " <div class=\"layui-row\" style=\"text-align: center;font-size: 15px;background-color: #8ecbff;border-radius:5px;\">\n" +
  314. " <span style=\"float: right;background-color: #AFFF005E;padding: 0px 2px;border-radius:5px;\" name='time_x' >"+To_time(data[i].T_time)+"</span>"+To_str(data[i].T_name)+"\n" +
  315. " </div>\n" +
  316. " <div class=\"layui-row\" >\n" +
  317. " <div class=\" layui-col-md4 \">\n" +
  318. " <img name='T_img' src=\"https://osscold.baozhida.cn/images/"+src_img+"\" height=\"50\" width=\"50\"/>\n" +
  319. " </div>\n" +
  320. " <div class=\"layui-col-md8\" style=\"margin-top: 3px;white-space:nowrap\">\n" +
  321. " <div style=\"width: 98%;height:20px;float: left;font-size: 15px;text-overflow:ellipsis; overflow:hidden;\">\n" +
  322. " <span name='T_t' style=\"width: 48px;float: left\">"+To_unm(data[i].T_t)+"℃</span>\n" +
  323. " <span name='T_T' style=\"font-size: 10px;float: left;margin-top: 1px;\">"+data[i].T_Tlower+"~"+data[i].T_Tupper+"</span>\n" +
  324. " </div>\n" +
  325. " <div style=\"width: 98%;height:20px;float: left;font-size: 15px;text-overflow:ellipsis; overflow:hidden;\">\n" +
  326. " <span name='T_rh' style=\"width: 48px;float: left\">"+To_unm(data[i].T_rh)+"%</span>\n" +
  327. " <span name='T_RH' style=\"font-size: 10px;float: left;margin-top: 1px;\">"+data[i].T_RHlower+"~"+data[i].T_RHupper+"</span>\n" +
  328. " </div>\n" +
  329. " </div>\n" +
  330. " <div class=\" layui-col-md12 \" style=\"padding-top: -2px;font-size: 16px;text-align: center;margin-top: -2px;border-top:1px solid #000\">\n" +
  331. " <span name='T_time'>"+dateChangeFormat('YYYY-mm-dd HH:MM:SS', data[i].T_time)+"</span>\n" +
  332. " </div>\n" +
  333. " </div>\n" +
  334. " </div>\n" +
  335. "</div>")
  336. }
  337. }
  338. function Add_DeviceSensor_list_Pages(Pages) {
  339. for (let i = 0; i < Pages.length; i++) {
  340. elem = Pages[i]
  341. switch (elem.A) {
  342. case 1:
  343. $('#DeviceSensor_list_Pages').append("<a class=\"prev\" onclick='get_DeviceSensor_list(" + elem.V + ")' >&lt;&lt;</a>\n");
  344. break;
  345. case 2:
  346. $('#DeviceSensor_list_Pages').append("<a class=\"num\" onclick='get_DeviceSensor_list(" + elem.V + ")' >" + elem.V + "</a>\n");
  347. break;
  348. case 3:
  349. $('#DeviceSensor_list_Pages').append("<span class=\"current\">" + elem.V + "</span>\n");
  350. break;
  351. case 4:
  352. $('#DeviceSensor_list_Pages').append("<a class=\"num\" onclick='get_DeviceSensor_list(" + elem.V + ")' >" + elem.V + "</a>\n");
  353. break;
  354. case 5:
  355. $('#DeviceSensor_list_Pages').append("<a class=\"next\" onclick='get_DeviceSensor_list(" + elem.V + ")' >&gt;&gt;</a>\n");
  356. break;
  357. }
  358. }
  359. }
  360. function Pu_DeviceSensor_list_g(sn,data) {
  361. for (let i = 0; i < data.length; i++) {
  362. // console.log(i," "+data[i].name)
  363. sn_ = $("div[name='"+sn+"']")
  364. // console.log("sn_:",sn_.length)
  365. if(sn_.length > 0){
  366. id_ = sn_.find("div[name='"+data[i].id+"']")
  367. // console.log("id_:",sn_.length)
  368. if(id_.length > 0){
  369. src_img = "温湿度传感器-1.png"
  370. Ds = data[i]
  371. x_ = dateChangeFormat_xiangcha(dateChangeFormat_x('YYYY-mm-dd HH:MM:SS', data[i].UT))
  372. outtime = 60 * 5
  373. if(( 0 == Ds.Tlower && 0 == Ds.RHlower) && ( 0 == Ds.Tupper && 0 == Ds.RHupper) ){
  374. if(x_ < outtime) {
  375. // 传感器正常
  376. src_img = "温湿度传感器-1.png"
  377. }else {
  378. // 传感器超时
  379. src_img = "温湿度传感器-2.png"
  380. }
  381. }else if (x_ < outtime) {
  382. if(Ds.T < Ds.Tlower || Ds.RH < Ds.RHlower || Ds.T > Ds.Tupper || Ds.RH > Ds.RHupper ){
  383. // 传感器 超标
  384. src_img = "温湿度传感器-3.png"
  385. }else {
  386. // 传感器正常
  387. src_img = "温湿度传感器-1.png"
  388. }
  389. }else {
  390. // 传感器超时
  391. src_img = "温湿度传感器-2.png"
  392. }
  393. id_.find("img")[0].src = "https://osscold.baozhida.cn/images/"+src_img
  394. id_.find("span")[0].innerHTML = "0"
  395. id_.find("span")[1].innerHTML = To_unm(data[i].T)+"℃"
  396. id_.find("span")[2].innerHTML = data[i].Tlower+"~"+data[i].Tupper
  397. id_.find("span")[3].innerHTML = To_unm(data[i].RH)+"%"
  398. id_.find("span")[4].innerHTML = data[i].RHlower+"~"+data[i].RHupper
  399. id_.find("span")[5].innerHTML = dateChangeFormat_x('YYYY-mm-dd HH:MM:SS', data[i].UT)
  400. console.log("更新:"+sn+">"+data[i].id)
  401. }
  402. }
  403. }
  404. }
  405. var websocket = null;
  406. //判断当前浏览器是否支持WebSocket
  407. run_WebSocket()
  408. function run_WebSocket() {
  409. console.log("run_WebSocket");
  410. if ('WebSocket' in window) {
  411. url = window.location.host
  412. if(url.indexOf("127.0.0.1") != -1){
  413. websocket = new WebSocket("ws://"+window.location.host+"/ws/join?User_tokey="+$.cookie('User_tokey'));
  414. }else {
  415. websocket = new WebSocket("wss://"+window.location.host+"/ws/join?User_tokey="+$.cookie('User_tokey'));
  416. }
  417. } else {
  418. alert('Dont support websocket')
  419. }
  420. }
  421. //连接成功建立的回调方法
  422. websocket.onopen = function () {
  423. console.log("open");
  424. get_DeviceSensor_list(0)
  425. // send("{\"Sn\":\"" + getQueryString("Sn") + "\"}")
  426. };
  427. //接收到消息的回调方法
  428. websocket.onmessage = function (event) {
  429. console.log(event.data)
  430. var obj = JSON.parse(event.data);
  431. // console.log(obj.type)
  432. // if(obj.sn != Device_Sn){
  433. // console.log(obj.sn,"跳过。。 Device_Sn = ",Device_Sn)
  434. // return
  435. // }
  436. // console.log(obj.sn,"进入。。 Device_Sn = ",Device_Sn)
  437. if (obj.type == 0 ) {
  438. // console.log("data.length:",obj.sensor.length)
  439. Pu_DeviceSensor_list_g(obj.sn,obj.sensor)
  440. if(obj.type == 0 ){
  441. $("#T_time").html("刷新时间:" + dateChangeFormat_x('YYYY-mm-dd HH:MM:SS', obj.sensor[0].UT) + " 上传刷新间隔:" + Math.abs(timestamp_V - obj.sensor[0].UT).toFixed(0) + "s")
  442. // console.log(timestamp_V, obj.sensor[0].UT, " 刷新间隔:" + (timestamp_V - obj.sensor[0].UT) + "s")
  443. timestamp_V = obj.sensor[0].UT
  444. }
  445. }
  446. };
  447. //连接关闭的回调方法
  448. websocket.onclose = function () {
  449. console.log("close");
  450. setTimeout(function(){
  451. //要执行的代码
  452. run_WebSocket();
  453. },2000);
  454. };
  455. //连接发生错误的回调方法
  456. websocket.onerror = function () {
  457. console.log("error");
  458. setTimeout(function(){
  459. //要执行的代码
  460. run_WebSocket();
  461. },2000);
  462. };
  463. //监听窗口关闭事件,当窗口关闭时,主动去关闭websocket连接,防止连接还没断开就关闭窗口,server端会抛异常。
  464. window.onbeforeunload = function () {
  465. websocket.close();
  466. console.log("窗口关闭事件");
  467. };
  468. //关闭连接
  469. function closeWebSocket() {
  470. websocket.close();
  471. console.log("onbeforeunload");
  472. window.clearInterval(intervalId);
  473. }
  474. //发送消息
  475. function send(message) {
  476. websocket.send(message);
  477. }
  478. </script>
  479. </html>