xzw 4 gadi atpakaļ
vecāks
revīzija
3b50de5935
3 mainītis faili ar 107 papildinājumiem un 56 dzēšanām
  1. 1 0
      css/hardware.css
  2. 99 49
      js/main_2020_show.js
  3. 7 7
      js/showHardware.js

+ 1 - 0
css/hardware.css

@@ -6,6 +6,7 @@
   color: #000;
   padding: 20px;
   width: 30%;
+  min-Width:500px;
 }
 
 .hard-header{

+ 99 - 49
js/main_2020_show.js

@@ -8,7 +8,7 @@ hardwareHotList = {}
 
 //热点  设备控制
 
-$("#hotPannel .close").on('click',()=>{
+$("#hotPannel .close, #hotPannel .iconquxiao").on('click',()=>{
     $("#hotPannel>div").css("display","");
     window.hotNeedUpdatePannel = null;
      
@@ -16,29 +16,47 @@ $("#hotPannel .close").on('click',()=>{
 
 $("#hotPannel input.mui-switch").on('change',(e)=>{//灯
     var ifOn = $('#hotPannel input.mui-switch').is(':checked');
-    window.changeDeviceStatus(window.hotNeedUpdatePannel, '02', ifOn?'1':'0')
+    window.changeDeviceStatus(window.hotNeedUpdatePannel, '02', ifOn?'1':'0',  null, (a)=>{
+        $("#hotPannel input.mui-switch").prop("checked", !ifOn) //error
+    })
 })
-
-
-
-$.ajax({//设备类型列表
-    method: "GET",
-    headers: {
+var getAjax = function(url, success, errorString){
+    $.ajax({//获取设备状态
+      method: "GET",
+      headers: {
         "Content-Type": "application/json",
-    },
-    dataType: "json",
-    contentType: "application/json",
-    url: g_Prefix+`/api/device/getType`,
-    success: function (data) {
-        if (data.code === 0) { 
-            hardwareTypes = data.data 
-        } else {
-            console.error('设备类型列表获取失败')
+      },
+      dataType: "json",
+      contentType: "application/json",
+      url: `/api/device/getStatus/${hardware.code}`,
+        success: (data)=> {
+            success(data)
+        },
+        error:(e)=>{
+            alert(errorString)
         }
+    })
+}
+
+getAjax(g_Prefix+`/api/device/getType`, (data)=>{
+    if (data.code === 0) { 
+        hardwareTypes = data.data 
+    } else {
+        console.error('设备类型列表获取失败')
     }
-}) 
+},'设备类型列表获取失败')
 
 
+window.getDeviceInfo = function(deviceId, callback){
+    var userId = '77547f7af360c5d8e14932866b844d53' 
+    var url = `/api/device/list/${userId}` + (deviceId ? `?deviceId=${deviceId}` : '')
+    
+    getAjax(url, (data)=>{
+        if(data.code == 0){
+            callback(data.data)
+        }
+    },'设备列表获取失败') 
+}
 
 
 
@@ -15474,6 +15492,7 @@ window.Modernizr = function(n, e, t) {
                 if(id!= void 0){
                     window.hardwareHotList[id] = this//硬件列表
                 }
+                //得先获取最新的status 是否在线
             }
             
             
@@ -15564,21 +15583,31 @@ window.Modernizr = function(n, e, t) {
             this.titleElem = elem;
         } 
         
+        //在线状态 
+        hot.prototype.setDeviceStatus = function(status){
+            if(status){
+                this.mesh.material.uniforms.opacity.value = 1
+                this.dontShine = false
+            }else{
+                this.mesh.material.uniforms.opacity.value = 0.5
+                this.dontShine = true
+            } 
+            this.deviceStatus = status
+        }
         
         hot.prototype.showPannel = function(o={}){
             var hardware = this.infoAttribute.hardware
             console.log(window.hotNeedUpdatePannel)
             if(hardware && hardware.id!=void 0){ 
+                //获取设备状态
+                getDeviceInfo(hardware.id, (data)=>{
+                    hot.setDeviceStatus(data[0].status == 2)
 
-                $.ajax({//获取设备状态
-                  method: "GET",
-                  headers: {
-                    "Content-Type": "application/json",
-                  },
-                  dataType: "json",
-                  contentType: "application/json",
-                  url: `/api/device/getStatus/${hardware.code}`, 
-                  success: (data)=> {
+
+                    
+                })
+                
+                getAjax(`/api/device/getStatus/${hardware.code}`,  (data)=> {
                     console.log(data)  
                     if (data.code === 0) {
                         data = data.data;
@@ -15588,7 +15617,7 @@ window.Modernizr = function(n, e, t) {
                             $("#hotPannel>div[name='light']").removeClass("hide")
                             
                             var ifOn = data.find(e=>e.paramCode == '02').paramValue == '1'
-                            $("#hotPannel>input").prop('checked', ifOn);
+                            $("#hotPannel>div[name='light']  input").prop('checked', ifOn);
                               
                               
                               
@@ -15675,6 +15704,7 @@ window.Modernizr = function(n, e, t) {
                                 */
                             
                             
+                            
                             /* "code": 0,
                               "data": {
                                 "external": {
@@ -15695,24 +15725,16 @@ window.Modernizr = function(n, e, t) {
                                 }
                               },
                               "msg": "操作成功" */
-                             
-                             $.ajax({ 
-                              method: "GET",
-                              headers: {
-                                "Content-Type": "application/json",
-                              },
-                              dataType: "json",
-                              contentType: "application/json",
-                              url: `/api/device/getLive/${hardware.code}`, 
-                              success: (data2)=> {
+                             getAjax(`/api/device/getLive/${hardware.code}` (data2)=> {
                                   if(data2.code == 0){
                                     loadMonitor({
                                         id:"monitor",
-                                        url:  data2.data.external.wsFlv    //'http://14.215.216.123:18080/rtp/00A153DF/hls.m3u8'
+                                        url:  data2.data.external.hls    //'http://14.215.216.123:18080/rtp/00A153DF/hls.m3u8'
                                     }) 
                                   }
-                             }}
-                             )
+                             },"获取视频地址失败" )
+                              
+                              
                             
                             
                             
@@ -15761,10 +15783,10 @@ window.Modernizr = function(n, e, t) {
                             } 
                         } 
                     } else {
-                        alert('获取数据失败')
+                        
                     }
-                  } 
-                });
+                }, '获取数据失败')
+                 
 
                
               /*  $.ajax({//获取设备参数
@@ -17902,7 +17924,7 @@ window.Modernizr = function(n, e, t) {
 					func: function(e) {
 						var opa = e <= .5 ? 2 * e : -2 * e + 2
                         for(var i in this.hots){
-                            this.hots[i].mesh.material.uniforms.opac.value = opa;
+                            this.hots[i].dontShine || (this.hots[i].mesh.material.uniforms.opac.value = opa);
                         }
 					}.bind(this),
 					cycling: true,
@@ -17983,8 +18005,32 @@ window.Modernizr = function(n, e, t) {
                         } 
                         this.createHotItem(window.hotData, this.hots);
                         
-                        
-                        
+                        /* {
+                          "code": "34020000001320010024",
+                          "name": "鹰眼",
+                          "devTypeName": "摄像头",
+                          "id": "2855ab1ed6e7a9d3b35467673796bfa9",
+                          "devTypeId": "ab073575c1628d2b42e2e915f1bee384",
+                          "status": "2"
+                        },
+                        {
+                          "code": "34020000001320010025",
+                          "name": "鹰眼广角",
+                          "devTypeName": "摄像头",
+                          "id": "bd6eca7d285ee120b9f5e59f259d7bc5",
+                          "devTypeId": "ab073575c1628d2b42e2e915f1bee384",
+                          "status": "2"
+                        }, */
+                        getDeviceInfo(null,(data)=>{//更新状态
+                            for(var id in hardwareHotList){
+                                var hot = hardwareHotList[id];
+                                var info = data.find(item=>item.id == id)
+                                if(info){
+                                    hot.setDeviceStatus(info.status == 2)   
+                                }
+                            }
+                             
+                        })
                         
                         
                         
@@ -26757,10 +26803,14 @@ window.Modernizr = function(n, e, t) {
 					texture2:{ 
 						type: "t", 
 						value: null
-					}
+					},
+                    opacity:{
+						type: "f", 
+						value: 1
+					},
 				},
 				vertexShader:"varying vec2 vUv;\n\nvoid main() {\n\n vUv =  uv ;\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n}\n",
-				fragmentShader:"varying vec3 vNormal;\n\nvarying vec2 vUv;\n\nuniform float opac;\n\nuniform vec3 color;\n\nuniform sampler2D texture1;\n\nuniform sampler2D texture2;\n\nvoid main() {\n\nvec4 tcolor1 = texture2D( texture1, vUv );\n\nvec4 tcolor2 = texture2D( texture2, vUv );\n\ngl_FragColor = mix(tcolor1,tcolor2 ,opac) + tcolor2*0.2; }\n"
+				fragmentShader:"varying vec3 vNormal;\n\nvarying vec2 vUv;\n\nuniform float opac; uniform float opacity;\n\nuniform vec3 color;\n\nuniform sampler2D texture1;\n\nuniform sampler2D texture2;\n\nvoid main() {\n\nvec4 tcolor1 = texture2D( texture1, vUv );\n\nvec4 tcolor2 = texture2D( texture2, vUv );\n\n gl_FragColor = mix(tcolor1,tcolor2 ,opac) + tcolor2*0.2;  gl_FragColor.w *= opacity; }\n"
 			}, 
             modelOutside: {
                 uniforms: {

+ 7 - 7
js/showHardware.js

@@ -104,7 +104,7 @@ $(function () {
     });
   };
 
-  window.changeDeviceStatus = function (item, paramCode, paramValue) {//设置设备
+  window.changeDeviceStatus = function (item, paramCode, paramValue, success, fail) {//设置设备
     console.log(item);
    
     let tmp = item.infoAttribute.hardware
@@ -118,15 +118,15 @@ $(function () {
       url: url + `/api/device/control/${tmp.id}/${paramCode}/${paramValue}/03`,
        
       success: function (data) {
+          console.log(data.msg)
         if (data.code === 0) {
-          resolve({
-            ...data,
-            totals: data.data.length,
-          });
+           success && success()
         } else {
-          reject(data);
+           fail && fail()
         }
-      },
+      },error:function(){
+          fail && fail()
+      }
     });
   }