123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667 |
- <!DOCTYPE html>
- <html class="x-admin-sm" style="overflow-y: hidden;">
- <head>
- <meta charset="UTF-8">
- <meta name="renderer" content="webkit">
- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
- <meta name="viewport"
- content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
- <link rel="shortcut icon" href="https://osscold.baozhida.cn/favicon.ico">
- <link rel="bookmark" href="https://osscold.baozhida.cn/favicon.ico">
- <link rel="stylesheet" href="https://osscold.baozhida.cn/css/font.css">
- <link rel="stylesheet" href="https://osscold.baozhida.cn/css/xadmin.css">
- <link rel="stylesheet" href="https://osscold.baozhida.cn/layui/css/layui.css">
- <script type="text/javascript" src="https://osscold.baozhida.cn/layui/layui.js" charset="utf-8"></script>
- <script type="text/javascript" src="https://osscold.baozhida.cn/js/xadmin.js"></script>
- <script src="https://osscold.baozhida.cn/js/jquery.min.js"></script>
- <script src="https://osscold.baozhida.cn/js/jquery.cookie.min.js"></script>
- <!-- 让IE8/9支持媒体查询,从而兼容栅格 -->
- <!--[if lt IE 9]>
- <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
- <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
- <![endif]--></head>
- <style>
- .text_limit{
- overflow:hidden;
- text-overflow:ellipsis;
- white-space:nowrap
- }
- </style>
- <body>
- <div class="x-nav">
- <span class="layui-breadcrumb">
- <a href="">首页</a>
- <a><cite>宝智达</cite></a>
- </span>
- <a class="layui-btn layui-btn-normal" style="line-height:1.6em;margin-top:3px;float:right"
- onclick="location.reload()" title="刷新">
- <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
- </a>
- </div>
- <div class="layui-fluid" style="padding: 15px;">
- <div class="layui-row">
- <!-- // 传感器 选择-->
- <div class="layui-col-md4">
- <div class="layui-card">
- <div class="layui-card-body ">
- <div class="layui-row" style="margin: 0px 10px">
- <div class="layui-col">
- <div class="layui-input-inline layui-show-xs-block">
- <input value="" type="text" id="D_Name" name="D_Name" placeholder="请输入 名称"
- autocomplete="off"
- class="layui-input"></div>
- <div class="layui-input-inline layui-show-xs-block">
- <input value="" type="text" id="D_T_sn" name="D_T_sn" placeholder="请输入 SN"
- autocomplete="off"
- class="layui-input"></div>
- <div class="layui-input-inline layui-show-xs-block">
- <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="sreach"
- onclick="get_Device_list(0)">
- <i class="layui-icon"></i></button>
- </div>
- <div w id="Device_list" style="width: 98%; overflow: hidden;margin-top: 10px">
- <!--<div class="layui-col"style="height: 52px;background-color: #fafafa;border-radius:5px;padding-top: 2px;">-->
- <!-- <img style="float: left;width: 50px;margin: 0px 10px" src="https://osscold.baozhida.cn/images/设备管理-1.png" height="50"-->
- <!-- width="40"/>-->
- <!-- <div style="float: left;">-->
- <!-- <div style="margin-top: 4px;font-size: 15px">SN:KF20210510143443</div>-->
- <!-- <div style="margin-top: 1px;font-size: 15px">主机名称:士大夫撒地方递四方速递</div>-->
- <!-- </div>-->
- <!-- <div class="layui-card-header" style="float: right;">-->
- <!-- <button class="layui-btn layui-btn-normal" style="float: right;margin-top: 11px"-->
- <!-- onclick="">-->
- <!-- <i class="iconfont" style="margin-right: 4px"></i> 绑定-->
- <!-- </button>-->
- <!-- </div>-->
- <!--</div>-->
- </div>
- <div style="height: 70px">
- <div class="layui-card-body ">
- <div class="page">
- <div id="Device_list_Pages">
- <!-- <a class="prev" href=""><<</a>-->
- <!-- <a class="num" href="">1222</a>-->
- <!-- <span class="current">111</span>-->
- <!-- <a class="num" href="">444</a>-->
- <!-- <a class="next" href="">>></a>-->
- </div>
- </div>
- <div style="color: #1E9FFF;text-align: center" id="Device_list_Pages_x"></div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- <div class="layui-col-md8">
- <div class="layui-card" style="padding: 10px">
- <div style="margin: 10px" >
- <span id="T_time" style="font-size: 14px">更新时间:等待同步中.....</span><img style="margin-left: 2px"
- src="https://osscold.baozhida.cn/images/等待.gif" height="20"
- width="20"/>
- </div>
- <div class="layui-col" id="DeviceSensor_list" style="max-height: 663px;overflow-y: auto" >
- </div>
- </div>
- </div>
- </div>
- </div>
- <script>
- function ChangeDiv(e) {
- var divs = document.getElementsByClassName("ChangeDiv");
- var len = divs.length;
- for(var i=0;i<len;i++){
- divs[i].style.border = "1px solid #ffffff";
- }
- e.style.border = "1px solid #ed0000";
- }
- //获取url中的参数
- function getQueryString(name) {
- var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
- var r = window.location.search.substr(1).match(reg);
- if (r != null)
- return decodeURIComponent(r[2]);
- return null;
- }
- function timestampToTime(timestamp) {
- if(timestamp == undefined){
- return "<img src=\"https://osscold.baozhida.cn/images/等待.gif\" style='float: left' height=\"16\" width=\"16\"/>"
- }
- var date = new Date(timestamp * 1000);//时间戳为10位需*1000,时间戳为13位的话不需乘1000
- Y = date.getFullYear() + '-';
- M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
- D = date.getDate() + ' ';
- h = date.getHours() + ':';
- m = date.getMinutes() + ':';
- s = date.getSeconds();
- return Y + M + D + h + m + s;
- }
- function dateChangeFormat(format, date) {
- date = new Date(date);
- const dataItem = {
- 'Y+': date.getFullYear().toString(),
- 'm+': (date.getMonth() + 1).toString(),
- 'd+': date.getDate().toString(),
- 'H+': date.getHours().toString(),
- 'M+': date.getMinutes().toString(),
- 'S+': date.getSeconds().toString(),
- };
- Object.keys(dataItem).forEach((item) => {
- const ret = new RegExp(`(${item})`).exec(format);
- if (ret) {
- format = format.replace(ret[1], ret[1].length === 1 ? dataItem[item] : dataItem[item].padStart(ret[1].length, '0'));
- }
- });
- return format;
- }
- function dateChangeFormat_x(format, date) {
- date = new Date(date*1000);
- const dataItem = {
- 'Y+': date.getFullYear().toString(),
- 'm+': (date.getMonth() + 1).toString(),
- 'd+': date.getDate().toString(),
- 'H+': date.getHours().toString(),
- 'M+': date.getMinutes().toString(),
- 'S+': date.getSeconds().toString(),
- };
- Object.keys(dataItem).forEach((item) => {
- const ret = new RegExp(`(${item})`).exec(format);
- if (ret) {
- format = format.replace(ret[1], ret[1].length === 1 ? dataItem[item] : dataItem[item].padStart(ret[1].length, '0'));
- }
- });
- return format;
- }
- // 时间比较
- function dateChangeFormat_xiangcha( date) {
- // console.log("===========")
- a_t = (new Date(dateChangeFormat('YYYY-mm-dd HH:MM:SS', date)).getTime()/1000)
- b_t = ((new Date()) / 1000)
- // console.log("a_t:",a_t,"b_t:",b_t,">",b_t - a_t)
- return parseInt(b_t - a_t) ;
- }
- function To_str(data) {
- if(data == undefined){
- return "<img src=\"https://osscold.baozhida.cn/images/等待.gif\" style='float: left' height=\"16\" width=\"16\"/>"
- }
- if(data+"".length > 5){
- return data+"".slice(0,5);
- }
- return data;
- }
- function To_unm(data) {
- if(data == undefined){
- return "<img src=\"https://osscold.baozhida.cn/images/等待.gif\" style='float: left' height=\"16\" width=\"16\"/>"
- }
- return data.toFixed(1);
- }
- layui.use(['form', 'layer', "layedit"],
- function () {
- $ = layui.jquery;
- var form = layui.form,
- layer = layui.layer;
- var layedit = layui.layedit
- layedit.set({
- uploadImage: {
- url: '/UpFile' //接口url
- }
- });
- //构建一个默认的编辑器
- var index = layedit.build('T_text', {
- height: 580 //设置编辑器高度,
- });
- //监听提交
- form.on('submit(add)',
- function (data) {
- console.log("=== submit(add) ==");
- // loading = layer.load(0, {
- // shade: false,
- // time: 99 * 1000
- // });
- console.log(data);
- T_enwarning = 0
- if (data.field.enwarning != undefined) {
- T_enwarning = 1
- }
- return false;
- });
- // //监听指定开关
- // form.on('switch(switchTest)', function(data){
- // layer.msg('开关checked:'+ (this.checked ? 'true' : 'false'), {
- // offset: '6px'
- // });
- // layer.tips('温馨提示:请注意开关状态的文字可以随意定义,而不仅仅是ON|OFF', data.othis)
- // });
- //表单取值
- // layui.$('#LAY-component-form-getval').on('click', function(){
- // var data = form.val('example');
- // alert(JSON.stringify(data));
- // });
- // var loading = layer.load(0, {
- // shade: false,
- // time: 99 * 1000
- // });
- });
- var Device_list = []
- var Device_Sn = ""
- var timestamp_V = (new Date()) / 1000;
- /// 设备库
- get_Device_list(0)
- function get_Device_list(page) {
- $.ajax({
- type: 'POST',
- url: '/Device/DeviceBind_List',//发送请求
- data: {
- User_tokey: $.cookie("User_tokey"),
- Admin_uuid: "",
- // Class_1: $("#D_Name").val(),
- T_sn: $("#D_T_sn").val(),
- Name: $("#D_Name").val(),
- page: page,
- },
- success: function (result) {
- console.log(result)
- if (result.Code == 200) {
- $('#Device_list').html("")
- $('#Device_list_Pages').html("")
- $('#Device_list_Pages_x').html("")
- Device_list = result.Data.Device_lite
- if (Device_list.length == 0) {
- $('#Device_list').html("<div style=\"color: #1E9FFF;text-align: center;font-size: 15px;margin-top: 150px \">没有设备</div>")
- return
- }
- Add_Device_list(result.Data.Device_lite) // 列表
- Add_Device_list_Pages(result.Data.Pages) // 分页
- $('#Device_list_Pages_x').append("页数:" + result.Data.Page + "/" + result.Data.Page_size + " 总数:" + result.Data.Num);
- } else {
- }
- }
- });
- }
- function Add_Device_list(Device_lite) {
- Device_Sn = Device_lite[0].T_sn
- console.log(Device_Sn)
- for (let i = 0; i < Device_lite.length; i++) {
- $('#Device_list').append("" +
- "<div onclick=\"ChangeDiv(this);f_Sand('" + Device_lite[i].T_sn + "')\" class=\"layui-col ChangeDiv\"style=\"border: 1px solid #ffffff;height: 52px;background-color: #fafafa;border-radius:5px;padding-top: 2px;margin-top: 6px\">\n" +
- " <img style=\"float: left;width: 50px;margin: 0px 10px\" src=\"https://osscold.baozhida.cn/images/设备管理-1.png\" height=\"50\"\n" +
- " width=\"40\"/>\n" +
- " <div style=\"float: left;width: 69%\">\n" +
- " <div style=\"margin-top: 4px;font-size: 15px;\" >SN:" + Device_lite[i].T_sn + "</div>\n" +
- " <div style=\"margin-top: 1px;font-size: 15px;\">主机名称:" + Device_lite[i].T_devName + "</div>\n" +
- " </div>\n" +
- " <div class=\"layui-card-header\" style=\"float: right;margin-top: 6px;color: #1E9FFF\">\n" +
- " 》\n" +
- " </div>\n" +
- " </div>")
- }
- }
- function Add_Device_list_Pages(Pages) {
- for (let i = 0; i < Pages.length; i++) {
- elem = Pages[i]
- switch (elem.A) {
- case 1:
- $('#Device_list_Pages').append("<a class=\"prev\" onclick='get_Device_list(" + elem.V + ")' ><<</a>\n");
- break;
- case 2:
- $('#Device_list_Pages').append("<a class=\"num\" onclick='get_Device_list(" + elem.V + ")' >" + elem.V + "</a>\n");
- break;
- case 3:
- $('#Device_list_Pages').append("<span class=\"current\">" + elem.V + "</span>\n");
- break;
- case 4:
- $('#Device_list_Pages').append("<a class=\"num\" onclick='get_Device_list(" + elem.V + ")' >" + elem.V + "</a>\n");
- break;
- case 5:
- $('#Device_list_Pages').append("<a class=\"next\" onclick='get_Device_list(" + elem.V + ")' >>></a>\n");
- break;
- }
- }
- }
- function Add_DeviceSensor_list_DeviceSensor_List(){
- $.ajax({
- type: 'POST',
- url: '../Device/DeviceSensor_List',//发送请求
- data: {
- User_tokey: $.cookie("User_tokey"),
- Sn:Device_Sn,
- page_z:99999,
- },
- success: function (result) {
- console.log(result)
- if (result.Code == 200) {
- Add_DeviceSensor_list_g(result.Data.DeviceSensor_lite)
- } else {
- }
- }
- });
- }
- function Add_DeviceSensor_list_g(data) {
- $('#DeviceSensor_list').html("")
- for (let i = 0; i < data.length; i++) {
- // console.log(i," "+data[i].name)
- src_img = "温湿度传感器-1.png"
- Ds = data[i]
- x_ = dateChangeFormat_xiangcha(Ds.T_time)
- outtime = 60 * 5
- if(( 0 == Ds.T_Tlower && 0 == Ds.T_RHlower) && ( 0 == Ds.T_Tupper && 0 == Ds.T_RHupper) ){
- if(x_ < outtime) {
- // 传感器正常
- src_img = "温湿度传感器-1.png"
- }else {
- // 传感器超时
- src_img = "温湿度传感器-2.png"
- }
- }else if (x_ < outtime) {
- 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 ){
- // 传感器 超标
- src_img = "温湿度传感器-3.png"
- }else {
- // 传感器正常
- src_img = "温湿度传感器-1.png"
- }
- }else {
- // 传感器超时
- src_img = "温湿度传感器-2.png"
- }
- $('#DeviceSensor_list').append("" +
- "<div name='"+data[i].T_sn+"' class=\"layui-col-xs6 layui-col-sm4 layui-col-md3 layui-col-lg3\" style=\"height: 104px; \" >\n" +
- " <div name='"+data[i].T_id+"' style=\"margin: 4px;height: 96px; border-radius:5px;background-color:#f1f1f1;\"\n" +
- " >\n" +
- " <div class=\"layui-row\" style=\"text-align: center;font-size: 15px;background-color: #8ecbff;border-radius:5px;\">\n" +
- " <span style=\"float: left;background-color: #69d1ff;padding: 0px 2px;border-radius:5px;\">"+data[i].T_id+"</span>"+To_str(data[i].T_name)+"\n" +
- " </div>\n" +
- " <div class=\"layui-row\" >\n" +
- " <div class=\" layui-col-md4 \">\n" +
- " <img name='T_img' src=\"https://osscold.baozhida.cn/images/"+src_img+"\" height=\"50\" width=\"50\"/>\n" +
- " </div>\n" +
- " <div class=\"layui-col-md8\" style=\"margin-top: 3px;white-space:nowrap\">\n" +
- " <div style=\"width: 98%;height:20px;float: left;font-size: 15px;text-overflow:ellipsis; overflow:hidden;\">\n" +
- " <span name='T_t' style=\"width: 48px;float: left\">"+To_unm(data[i].T_t)+"℃</span>\n" +
- " <span name='T_T' style=\"font-size: 10px;float: left;margin-top: 4px;\">"+data[i].T_Tlower+"~"+data[i].T_Tupper+"</span>\n" +
- " </div>\n" +
- " <div style=\"width: 98%;height:20px;float: left;font-size: 15px;text-overflow:ellipsis; overflow:hidden;\">\n" +
- " <span name='T_rh' style=\"width: 48px;float: left\">"+To_unm(data[i].T_rh)+"%</span>\n" +
- " <span name='T_RH' style=\"font-size: 10px;float: left;margin-top: 4px;\">"+data[i].T_RHlower+"~"+data[i].T_RHupper+"</span>\n" +
- " </div>\n" +
- " </div>\n" +
- " <div class=\" layui-col-md12 \" style=\"padding-top: -2px;font-size: 16px;text-align: center;margin-top: -2px;border-top:1px solid #000\">\n" +
- " <span name='T_time'>"+dateChangeFormat('YYYY-mm-dd HH:MM:SS', data[i].T_time)+"</span>\n" +
- " </div>\n" +
- " </div>\n" +
- " </div>\n" +
- "</div>")
- }
- }
- function Pu_DeviceSensor_list_g(sn,data) {
- for (let i = 0; i < data.length; i++) {
- // console.log(i," "+data[i].name)
- sn_ = $("div[name='"+sn+"']")
- // console.log("sn_:",sn_.length)
- if(sn_.length > 0){
- id_ = sn_.find("div[name='"+data[i].id+"']")
- // console.log("id_:",sn_.length)
- if(id_.length > 0){
- rc_img = "温湿度传感器-1.png"
- Ds = data[i]
- x_ = dateChangeFormat_xiangcha(dateChangeFormat_x('YYYY-mm-dd HH:MM:SS', data[i].UT))
- outtime = 60 * 5
- if(( 0 == Ds.Tlower && 0 == Ds.RHlower) && ( 0 == Ds.Tupper && 0 == Ds.RHupper) ){
- if(x_ < outtime) {
- // 传感器正常
- src_img = "温湿度传感器-1.png"
- }else {
- // 传感器超时
- src_img = "温湿度传感器-2.png"
- }
- }else if (x_ < outtime) {
- if(Ds.T < Ds.Tlower || Ds.RH < Ds.RHlower || Ds.T > Ds.Tupper || Ds.RH > Ds.RHupper ){
- // 传感器 超标
- src_img = "温湿度传感器-3.png"
- }else {
- // 传感器正常
- src_img = "温湿度传感器-1.png"
- }
- }else {
- // 传感器超时
- src_img = "温湿度传感器-2.png"
- }
- id_.find("img")[0].src = "https://osscold.baozhida.cn/images/"+src_img
- id_.find("span")[1].innerHTML = To_unm(data[i].T)+"℃"
- id_.find("span")[2].innerHTML = data[i].Tlower+"~"+data[i].Tupper
- id_.find("span")[3].innerHTML = To_unm(data[i].RH)+"%"
- id_.find("span")[4].innerHTML = data[i].RHlower+"~"+data[i].RHupper
- id_.find("span")[5].innerHTML = dateChangeFormat_x('YYYY-mm-dd HH:MM:SS', data[i].UT)
- }
- }
- }
- }
- function Add_DeviceSensor_list(data) {
- $('#DeviceSensor_list').html("")
- for (let i = 0; i < data.length; i++) {
- // console.log(i," "+data[i].name)
- $('#DeviceSensor_list').append("" +
- "<div class=\"layui-col-xs6 layui-col-sm4 layui-col-md3 layui-col-lg3\" style=\"height: 104px; \" >\n" +
- " <div style=\"margin: 4px;height: 96px; border-radius:5px;background-color:#f1f1f1;\"\n" +
- " >\n" +
- " <div class=\"layui-row\" style=\"text-align: center;font-size: 15px;background-color: #8ecbff;border-radius:5px;\">\n" +
- " <span style=\"float: left;background-color: #69d1ff;padding: 0px 2px;border-radius:5px;\">"+data[i].id+"</span>"+To_str(data[i].name)+"\n" +
- " </div>\n" +
- " <div class=\"layui-row\" >\n" +
- " <div class=\" layui-col-md4 \">\n" +
- " <img src=\"https://osscold.baozhida.cn/images/温湿度传感器-1.png\" height=\"50\" width=\"50\"/>\n" +
- " </div>\n" +
- " <div class=\"layui-col-md8\" style=\"margin-top: 3px;white-space:nowrap\">\n" +
- " <div style=\"width: 98%;height:20px;float: left;font-size: 15px;text-overflow:ellipsis; overflow:hidden;\">\n" +
- " <span style=\"width: 48px;float: left\">"+To_unm(data[i].T)+"℃</span>\n" +
- " <span style=\"font-size: 10px;float: left;margin-top: 4px;\">"+data[i].Tlower+"~"+data[i].Tupper+"</span>\n" +
- " </div>\n" +
- " <div style=\"width: 98%;height:20px;float: left;font-size: 15px;text-overflow:ellipsis; overflow:hidden;\">\n" +
- " <span style=\"width: 48px;float: left\">"+To_unm(data[i].RH)+"%</span>\n" +
- " <span style=\"font-size: 10px;float: left;margin-top: 4px;\">"+data[i].RHlower+"~"+data[i].RHlower+"</span>\n" +
- " </div>\n" +
- " </div>\n" +
- " <div class=\" layui-col-md12 \" style=\"padding-top: -2px;font-size: 16px;text-align: center;margin-top: -2px;border-top:1px solid #000\">\n" +
- " "+timestampToTime(data[i].UT)+"\n" +
- " </div>\n" +
- " </div>\n" +
- " </div>\n" +
- "</div>")
- }
- }
- // 页面 加载完成后执行
- window.onload = function () {
- console.log("页面 加载完成后执行")
- setTimeout(function(){
- console.log("等待执行")
- f_Sand(Device_Sn)
- //要执行的代码
- },2000);
- }
- function f_Sand(sn) {
- console.log(sn)
- Device_Sn = sn
- $('#DeviceSensor_list').html("<img src=\"https://osscold.baozhida.cn/images/等待.gif\" style='margin: 20px auto;' height=\"36\" width=\"36\"/>")
- Add_DeviceSensor_list_DeviceSensor_List()
- websocket.send("{\"Sn\":\"" + sn + "\"}");
- }
- var websocket = null;
- //判断当前浏览器是否支持WebSocket
- run_WebSocket()
- function run_WebSocket() {
- console.log("run_WebSocket");
- if ('WebSocket' in window) {
- url = window.location.host
- if(url.indexOf("127.0.0.1") != -1){
- websocket = new WebSocket("ws://"+window.location.host+"/ws/join?User_tokey="+$.cookie('User_tokey'));
- }else {
- websocket = new WebSocket("wss://"+window.location.host+"/ws/join?User_tokey="+$.cookie('User_tokey'));
- }
- } else {
- alert('Dont support websocket')
- }
- }
- //连接成功建立的回调方法
- websocket.onopen = function () {
- console.log("open");
- // send("{\"Sn\":\"" + getQueryString("Sn") + "\"}")
- };
- //接收到消息的回调方法
- websocket.onmessage = function (event) {
- // console.log(event.data)
- var obj = JSON.parse(event.data);
- // console.log(obj.type)
- if(obj.sn != Device_Sn){
- console.log(obj.sn,"跳过。。 Device_Sn = ",Device_Sn)
- return
- }
- console.log(obj.sn,"进入。。 Device_Sn = ",Device_Sn)
- if (obj.type == 0 ) {
- console.log("data.length:",obj.sensor.length)
- console.log("data:",obj.sensor)
- Pu_DeviceSensor_list_g(obj.sn,obj.sensor)
- if(obj.type == 0 ){
- if(Math.abs(timestamp_V - obj.sensor[0].UT).toFixed(0) > 0){
- $("#T_time").html("刷新时间:" + timestampToTime(obj.sensor[0].UT) + " 上传刷新间隔:" + Math.abs(timestamp_V - obj.sensor[0].UT).toFixed(0) + "s")
- // console.log(timestamp_V, obj.sensor[0].UT, " 刷新间隔:" + (timestamp_V - obj.sensor[0].UT) + "s")
- timestamp_V = obj.sensor[0].UT
- }
- }
- }
- };
- //连接关闭的回调方法
- websocket.onclose = function () {
- console.log("close");
- setTimeout(function(){
- //要执行的代码
- run_WebSocket();
- },2000);
- };
- //连接发生错误的回调方法
- websocket.onerror = function () {
- console.log("error");
- setTimeout(function(){
- //要执行的代码
- run_WebSocket();
- },2000);
- };
- //监听窗口关闭事件,当窗口关闭时,主动去关闭websocket连接,防止连接还没断开就关闭窗口,server端会抛异常。
- window.onbeforeunload = function () {
- websocket.close();
- console.log("窗口关闭事件");
- };
- //关闭连接
- function closeWebSocket() {
- websocket.close();
- console.log("onbeforeunload");
- window.clearInterval(intervalId);
- }
- //发送消息
- function send(message) {
- websocket.send(message);
- }
- </script>
- </body>
- </html>
|