"use strict";(wx["webpackJsonp"]=wx["webpackJsonp"]||[]).push([[592],{195:function(n,t,e){e.d(t,{Rl:function(){return c},sP:function(){return u},uA:function(){return o}});var r=e(3183);function o(n){return(0,r.U2)("/alarms",n)}function c(n){return(0,r.v_)("/alarms/".concat(n,"/ack"))}function u(n){return(0,r.U2)("/alarms/".concat(n,"/clip"))}},8776:function(n,t,e){e.d(t,{t:function(){return c},x:function(){return o}});var r=e(3183);function o(n){return(0,r.v_)("/auth/login",n)}function c(){return(0,r.U2)("/auth/me")}},8106:function(n,t,e){e.d(t,{BQ:function(){return h},Kk:function(){return d},RU:function(){return l},bR:function(){return s},tY:function(){return f}});var r=e(2954),o=e.n(r),c=e(8004)["window"],u=!1,i=u?"/api/v1":"http://100.83.103.1:3000/api/v1",a="apiBaseUrl";function s(){var n=o().getStorageSync(a);return n||i}function f(n){n?o().setStorageSync(a,n):o().removeStorageSync(a)}function l(){var n=s();return n.replace(/\/api\/v1\/?$/,"")}function h(n){var t=s();if(t.startsWith("http")){var e=t.replace(/\/api\/v1\/?$/,""),r=e.replace(/^http/,"ws");return"".concat(r,"/ws?token=").concat(n)}if(u){var o="undefined"!==typeof c&&"https:"===c.location.protocol?"wss:":"ws:",i="undefined"!==typeof c?c.location.host:"localhost:3000";return"".concat(o,"//").concat(i,"/ws?token=").concat(n)}return"ws://100.83.103.1:3000/ws?token=".concat(n)}function d(n){if(n.startsWith("http://")||n.startsWith("https://"))return n;var t=s().replace(/\/api\/v1$/,"");return t+n}},5487:function(n,t,e){e.d(t,{LE:function(){return c},PW:function(){return o}});var r=e(3183);function o(n){return(0,r.U2)("/devices",n)}function c(n){return(0,r.v_)("/control/send",n)}},3183:function(n,t,e){e.d(t,{IV:function(){return g},U2:function(){return m},r$:function(){return p},v_:function(){return v}});var r=e(2688),o=e(1002),c=e(1413),u=e(5861),i=e(9439),a=e(2954),s=e.n(a),f=e(8106);function l(n){if(!n)return"";var t=Object.entries(n).filter(function(n){var t=(0,i.Z)(n,2),e=t[1];return void 0!==e&&null!==e&&""!==e});if(0===t.length)return"";var e=t.map(function(n){var t=(0,i.Z)(n,2),e=t[0],r=t[1];return"".concat(encodeURIComponent(e),"=").concat(encodeURIComponent(String(r)))}).join("&");return"?".concat(e)}function h(n){return d.apply(this,arguments)}function d(){return d=(0,u.Z)((0,r.Z)().m(function n(t){var e,u,i,a,h,d,m,v;return(0,r.Z)().w(function(n){while(1)switch(n.p=n.n){case 0:return e=s().getStorageSync("token"),u=(0,f.bR)(),i=l(t.params),a="".concat(u).concat(t.url).concat(i),h=(0,c.Z)({"Content-Type":"application/json"},t.header),e&&(h["Authorization"]="Bearer ".concat(e)),n.p=1,n.n=2,s().request({url:a,method:t.method||"GET",data:t.data,header:h,timeout:15e3});case 2:if(d=n.v,401!==d.statusCode){n.n=3;break}throw console.warn("[Request] 401 \u672a\u6388\u6743\uff0c\u6e05\u9664\u767b\u5f55\u72b6\u6001"),s().removeStorageSync("token"),s().removeStorageSync("refreshToken"),s().removeStorageSync("user"),s().reLaunch({url:"/pages/login/index"}),new Error("\u767b\u5f55\u5df2\u8fc7\u671f\uff0c\u8bf7\u91cd\u65b0\u767b\u5f55");case 3:if(!(d.statusCode>=400)){n.n=4;break}throw m=(d.data&&"object"===(0,o.Z)(d.data)&&"message"in d.data?String(d.data.message):null)||"\u8bf7\u6c42\u5931\u8d25 (".concat(d.statusCode,")"),console.error("[Request] ".concat(t.method||"GET"," ").concat(t.url," \u5931\u8d25:"),d.statusCode,d.data),new Error(m);case 4:return n.a(2,d.data);case 5:if(n.p=5,v=n.v,!(v instanceof Error&&"\u767b\u5f55\u5df2\u8fc7\u671f\uff0c\u8bf7\u91cd\u65b0\u767b\u5f55"===v.message)){n.n=6;break}throw v;case 6:throw console.error("[Request] ".concat(t.method||"GET"," ").concat(t.url," \u5f02\u5e38:"),v),v;case 7:return n.a(2)}},n,null,[[1,5]])})),d.apply(this,arguments)}function m(n,t){return h({url:n,method:"GET",params:t})}function v(n,t){return h({url:n,method:"POST",data:t})}function p(n,t){return h({url:n,method:"PATCH",data:t})}function g(n){return h({url:n,method:"DELETE"})}},5387:function(n,t,e){e.d(t,{A:function(){return o},w:function(){return c}});var r=e(3183);function o(){return(0,r.U2)("/rooms")}function c(n){return(0,r.U2)("/rooms/".concat(n))}},821:function(n,t,e){e.d(t,{c2:function(){return s},cU:function(){return l},k1:function(){return h},ml:function(){return f}});var r=e(2688),o=e(5861),c=e(9439),u=e(7762),i=e(3183),a=e(151);function s(n){return(0,i.U2)("/telemetry",n)}function f(n){return(0,i.U2)("/telemetry/".concat(n,"/latest"))}function l(n){var t,e=new Map,r=(0,u.Z)(n);try{for(r.s();!(t=r.n()).done;){var o=t.value,i=(0,a.nK)(o.metric),s=e.get(i);(!s||new Date(o.timestamp).getTime()>new Date(s.timestamp).getTime())&&e.set(i,o)}}catch(n){r.e(n)}finally{r.f()}return Array.from(e.entries()).map(function(n){var t=(0,c.Z)(n,2),e=t[0],r=t[1];return{key:e,name:(0,a.uJ)(e)||r.metric,value:Number(r.value),unit:(0,a.J7)(e)||"",status:(0,a.c_)(e,Number(r.value))}})}function h(){return d.apply(this,arguments)}function d(){return d=(0,o.Z)((0,r.Z)().m(function n(){var t,e,o,c,u=arguments;return(0,r.Z)().w(function(n){while(1)switch(n.n){case 0:return t=u.length>0&&void 0!==u[0]?u[0]:24,e=new Date,o=new Date(e.getTime()-3600*t*1e3),n.n=1,s({from:o.toISOString(),to:e.toISOString(),limit:1e3});case 1:return c=n.v,n.a(2,c.slice().reverse().reduce(function(n,t){var e,r=(0,a.nK)(t.metric);if(!["temp","humidity","co2"].includes(r))return n;var o=t.timestamp.slice(11,16),c=null!==(e=n.find(function(n){return n.time===o}))&&void 0!==e?e:{time:o};return c[r]=Number(t.value),n.includes(c)||n.push(c),n},[]))}},n)})),d.apply(this,arguments)}},9817:function(n,t,e){e.d(t,{Ki:function(){return c},sp:function(){return o}});var r=e(3183);function o(){return(0,r.U2)("/video/cameras")}function c(n){return(0,r.U2)("/video/clips",n)}},8944:function(n,t,e){e.d(t,{Z:function(){return a}});var r=e(3433),o=(e(7294),e(1515)),c={container:"index-module__container___shrmH",bar:"index-module__bar___aJN5t",barActive:"index-module__barActive___rMkol",empty:"index-module__empty___dSdl8",emptyText:"index-module__emptyText___NDPIc"},u=e(5893),i=function(n){var t=n.data,e=n.metric,i=void 0===e?"temp":e,a=n.height,s=void 0===a?200:a,f=n.color,l=void 0===f?"#10b981":f,h=t.map(function(n){return n[i]}).filter(function(n){return void 0!==n});if(0===h.length)return(0,u.jsx)(o.G7,{className:c.empty,style:{height:"".concat(s,"rpx")},children:(0,u.jsx)(o.xv,{className:c.emptyText,children:"\u6682\u65e0\u6570\u636e"})});var d=Math.min.apply(Math,(0,r.Z)(h)),m=Math.max.apply(Math,(0,r.Z)(h)),v=m-d||1;return(0,u.jsx)(o.G7,{className:c.container,style:{height:"".concat(s,"rpx")},children:h.map(function(n,t){var e=(n-d)/v*(s-40)+8;return(0,u.jsx)(o.G7,{className:"".concat(c.bar," ").concat(t===h.length-1?c.barActive:""),style:{height:"".concat(e,"rpx"),background:l}},t)})})},a=i},3851:function(n,t,e){e.d(t,{o:function(){return f}});var r=e(2688),o=e(5861),c=e(270),u=e(2954),i=e.n(u),a=e(8776),s=e(5616),f=(0,c.Ue)(function(n,t){return{token:i().getStorageSync("token")||null,refreshToken:i().getStorageSync("refreshToken")||null,user:i().getStorageSync("user")||null,isReady:!1,setAuth:function(t,e,r){i().setStorageSync("token",t),i().setStorageSync("refreshToken",e),i().setStorageSync("user",r),n({token:t,refreshToken:e,user:r}),s.X.connect(t)},logout:function(){s.X.close(),i().removeStorageSync("token"),i().removeStorageSync("refreshToken"),i().removeStorageSync("user"),n({token:null,refreshToken:null,user:null}),i().reLaunch({url:"/pages/login/index"})},isLoggedIn:function(){return!!t().token},restoreSession:function(){var e=(0,o.Z)((0,r.Z)().m(function e(){var o,c;return(0,r.Z)().w(function(e){while(1)switch(e.p=e.n){case 0:if(o=i().getStorageSync("token"),!o){e.n=4;break}return e.p=1,e.n=2,(0,a.t)();case 2:c=e.v,n({token:o,user:c}),s.X.connect(o),e.n=4;break;case 3:return e.p=3,e.v,e.n=4,t().logout();case 4:n({isReady:!0});case 5:return e.a(2)}},e,null,[[1,3]])}));function c(){return e.apply(this,arguments)}return c}()}})},151:function(n,t,e){e.d(t,{C8:function(){return f},J7:function(){return y},LU:function(){return w},RA:function(){return m},R_:function(){return l},SY:function(){return s},Vw:function(){return p},Wy:function(){return h},bX:function(){return d},c_:function(){return k},nK:function(){return g},o0:function(){return i},rZ:function(){return v},sS:function(){return _},uJ:function(){return S},uf:function(){return a}});var r=e(7484),o=e.n(r),c=e(4110),u=e.n(c);e(3852);function i(n){return n?o()(n).format("YYYY-MM-DD HH:mm:ss"):"-"}function a(n){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;return void 0===n||null===n?"-":Number(n).toFixed(t)}function s(n){if(!n)return"-";var t=o()(),e=o()(n),r=t.diff(e,"second");return r<60?"\u521a\u521a":r<3600?"".concat(Math.floor(r/60),"\u5206\u949f\u524d"):r<86400?"".concat(Math.floor(r/3600),"\u5c0f\u65f6\u524d"):"".concat(Math.floor(r/86400),"\u5929\u524d")}function f(n){var t={temperature:"\u6e29\u5ea6",humidity:"\u6e7f\u5ea6",co2:"CO\u2082",light:"\u5149\u7167",pressure:"\u6c14\u538b",pm25:"PM2.5",soil_moisture:"\u571f\u58e4\u6e7f\u5ea6",ph:"pH\u503c"};return t[n]||n}function l(n){var t={temperature:"\xb0C",humidity:"%",co2:"ppm",light:"lux",pressure:"hPa",pm25:"\u03bcg/m\xb3",soil_moisture:"%",ph:""};return t[n]||""}function h(n){if(void 0===n||null===n)return"-";var t=String(n).toLowerCase(),e={critical:"\u4e25\u91cd",high:"\u9ad8",medium:"\u4e2d",low:"\u4f4e",info:"\u4fe1\u606f",1:"\u4e25\u91cd",2:"\u9ad8",3:"\u4e2d",4:"\u4f4e",5:"\u4fe1\u606f"};return e[t]||String(n)}function d(n){if(void 0===n||null===n)return"#86909c";var t=String(n).toLowerCase(),e={critical:"#f53f3f",high:"#ff7d00",medium:"#ffc408",low:"#00b42a",info:"#165dff",1:"#f53f3f",2:"#ff7d00",3:"#ffc408",4:"#00b42a",5:"#165dff"};return e[t]||"#86909c"}function m(n){var t={sensor:"\u4f20\u611f\u5668",actuator:"\u6267\u884c\u5668",camera:"\u6444\u50cf\u5934",controller:"\u63a7\u5236\u5668",gateway:"\u7f51\u5173"};return t[n]||n}function v(n){var t={active:"\u8fd0\u884c\u4e2d",inactive:"\u672a\u542f\u7528",maintenance:"\u7ef4\u62a4\u4e2d",alarm:"\u544a\u8b66\u4e2d"};return t[n||""]||n||"\u672a\u77e5"}function p(n){var t={online:"\u5728\u7ebf",offline:"\u79bb\u7ebf",unknown:"\u672a\u77e5"};return t[n]||n}function g(n){return"temperature"===n?"temp":n}function S(n){return f(n)}function y(n){return l(n)}function k(n,t){return"temp"===n?t<20||t>30?"danger":t<22||t>28?"warn":"normal":"humidity"===n?t<55||t>85?"danger":t<60||t>80?"warn":"normal":"co2"===n?t>1500?"danger":t>1e3?"warn":"normal":"normal"}function w(n){if(!n||isNaN(n))return"-";if(n<60)return"".concat(n,"\u79d2");var t=Math.floor(n/60),e=n%60;return"".concat(t,"\u5206").concat(e,"\u79d2")}function _(n){if(void 0===n||null===n)return"-";var t="string"===typeof n?parseInt(n,10):n;return isNaN(t)?"-":t<1024?"".concat(t," B"):t<1048576?"".concat((t/1024).toFixed(1)," KB"):t<1073741824?"".concat((t/1048576).toFixed(1)," MB"):"".concat((t/1073741824).toFixed(1)," GB")}o().extend(u()),o().locale("zh-cn")},5616:function(n,t,e){e.d(t,{X:function(){return f}});var r=e(5671),o=e(3144),c=e(4942),u=e(2954),i=e.n(u),a=e(8106),s=function(){function n(){(0,r.Z)(this,n),(0,c.Z)(this,"connected",!1),(0,c.Z)(this,"handlers",new Map),(0,c.Z)(this,"token",""),(0,c.Z)(this,"reconnectAttempts",0),(0,c.Z)(this,"maxReconnectAttempts",5),(0,c.Z)(this,"reconnectTimer",null),(0,c.Z)(this,"isManualClose",!1)}return(0,o.Z)(n,[{key:"connect",value:function(n){this.token=n,this.isManualClose=!1,this.doConnect()}},{key:"doConnect",value:function(){var n=this;if(this.token){if(this.connected){try{i().closeSocket()}catch(n){}this.connected=!1}var t=(0,a.BQ)(this.token);console.log("[WS] \u6b63\u5728\u8fde\u63a5:",t),i().onSocketOpen(function(){console.log("[WS] \u8fde\u63a5\u5df2\u5efa\u7acb"),n.connected=!0,n.reconnectAttempts=0}),i().onSocketMessage(function(t){try{var e=JSON.parse(t.data),r=e.type||e.event||"default",o=n.handlers.get(r);o&&o.forEach(function(n){return n(e)});var c=n.handlers.get("*");c&&c.forEach(function(n){return n(e)})}catch(n){console.error("[WS] \u6d88\u606f\u89e3\u6790\u5931\u8d25:",n,t.data)}}),i().onSocketClose(function(){console.log("[WS] \u8fde\u63a5\u5df2\u5173\u95ed"),n.connected=!1,n.isManualClose||n.scheduleReconnect()}),i().onSocketError(function(n){console.error("[WS] \u8fde\u63a5\u9519\u8bef:",n)}),i().connectSocket({url:t,fail:function(t){console.error("[WS] \u8fde\u63a5\u5931\u8d25:",t),n.scheduleReconnect()}})}else console.warn("[WS] \u65e0 token\uff0c\u65e0\u6cd5\u8fde\u63a5 WebSocket")}},{key:"scheduleReconnect",value:function(){var n=this;if(!this.isManualClose)if(this.reconnectAttempts>=this.maxReconnectAttempts)console.warn("[WS] \u8fbe\u5230\u6700\u5927\u91cd\u8fde\u6b21\u6570\uff0c\u505c\u6b62\u91cd\u8fde");else{this.reconnectAttempts++;var t=Math.min(1e3*Math.pow(2,this.reconnectAttempts),3e4);console.log("[WS] ".concat(t,"ms \u540e\u7b2c ").concat(this.reconnectAttempts," \u6b21\u91cd\u8fde...")),this.reconnectTimer&&clearTimeout(this.reconnectTimer),this.reconnectTimer=setTimeout(function(){n.doConnect()},t)}}},{key:"on",value:function(n,t){var e=this;return this.handlers.has(n)||this.handlers.set(n,new Set),this.handlers.get(n).add(t),function(){var r;null===(r=e.handlers.get(n))||void 0===r||r.delete(t)}}},{key:"off",value:function(n,t){var e;t?null===(e=this.handlers.get(n))||void 0===e||e.delete(t):this.handlers.delete(n)}},{key:"send",value:function(n){this.connected?i().sendSocketMessage({data:"string"===typeof n?n:JSON.stringify(n),fail:function(n){console.error("[WS] \u53d1\u9001\u5931\u8d25:",n)}}):console.warn("[WS] WebSocket \u672a\u8fde\u63a5\uff0c\u65e0\u6cd5\u53d1\u9001\u6d88\u606f")}},{key:"close",value:function(){this.isManualClose=!0,this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.connected&&(i().closeSocket(),this.connected=!1),this.handlers.clear(),this.reconnectAttempts=0}},{key:"isConnected",value:function(){return this.connected}}])}(),f=new s}}]);