Files
silk/miniapp/dist/pages/devices/index.js
T

1 line
8.5 KiB
JavaScript

"use strict";(wx["webpackJsonp"]=wx["webpackJsonp"]||[]).push([[197],{9717:function(e,n,c){var t=c(8774),a=c(2688),r=c(5861),i=c(9439),l=c(7294),o=c(1515),s=c(2954),d=c.n(s),_={devicesPage:"index-module__devicesPage___LDx2t",filterBar:"index-module__filterBar___ig8Mf",filterChip:"index-module__filterChip___jXrtW",filterChipActive:"index-module__filterChipActive___SrVeF",deviceList:"index-module__deviceList___Vl7O0",deviceCard:"index-module__deviceCard___vtbWu",deviceHeader:"index-module__deviceHeader___yPJva",deviceLeft:"index-module__deviceLeft___DbpfC",deviceIcon:"index-module__deviceIcon___rG88O",deviceInfo:"index-module__deviceInfo___oS2vD",deviceName:"index-module__deviceName___p2xuF",deviceKey:"index-module__deviceKey___OlhNs",deviceStatusBadge:"index-module__deviceStatusBadge___YnKOV",statusOnline:"index-module__statusOnline___kho3y",statusOffline:"index-module__statusOffline___IymXr",statusDot:"index-module__statusDot___hi0uq",deviceMeta:"index-module__deviceMeta___Spi_j",metaItem:"index-module__metaItem___W_n4b",metaLabel:"index-module__metaLabel___JinHX",controlRow:"index-module__controlRow___bRG0X",controlBtn:"index-module__controlBtn___FNxy5",controlBtnPrimary:"index-module__controlBtnPrimary___JnvOB",controlBtnSecondary:"index-module__controlBtnSecondary___IhwMG",controlBtnDanger:"index-module__controlBtnDanger___gT6kg",loadingWrap:"index-module__loadingWrap___WZE8L",loadingText:"index-module__loadingText___KDewg",errorWrap:"index-module__errorWrap____IhFx",errorIcon:"index-module__errorIcon___CoWdL",errorText:"index-module__errorText___TJ40S",retryBtn:"index-module__retryBtn___VWq1D",emptyWrap:"index-module__emptyWrap___iDI82",emptyIcon:"index-module__emptyIcon___Rd08R",emptyText:"index-module__emptyText___FVCDN"},u=c(5487),m=c(5387),x=c(151),v=c(5893),h=function(){var e=(0,l.useState)([]),n=(0,i.Z)(e,2),c=n[0],t=n[1],h=(0,l.useState)([]),f=(0,i.Z)(h,2),j=f[0],p=f[1],y=(0,l.useState)("all"),N=(0,i.Z)(y,2),g=N[0],k=N[1],B=(0,l.useState)(!0),G=(0,i.Z)(B,2),b=G[0],w=G[1],C=(0,l.useState)(""),I=(0,i.Z)(C,2),S=I[0],L=I[1],D=(0,l.useCallback)((0,r.Z)((0,a.Z)().m(function e(){var n,c,r,l,o;return(0,a.Z)().w(function(e){while(1)switch(e.p=e.n){case 0:return e.p=0,L(""),e.n=1,Promise.all([(0,u.PW)().catch(function(){return[]}),(0,m.A)().catch(function(){return[]})]);case 1:n=e.v,c=(0,i.Z)(n,2),r=c[0],l=c[1],t(r),p(l),e.n=3;break;case 2:e.p=2,o=e.v,console.error("[Devices] \u6570\u636e\u52a0\u8f7d\u5931\u8d25:",o),L(o instanceof Error?o.message:"\u6570\u636e\u52a0\u8f7d\u5931\u8d25");case 3:return e.p=3,w(!1),e.f(3);case 4:return e.a(2)}},e,null,[[0,2,3,4]])})),[]);(0,l.useEffect)(function(){D()},[D]),(0,s.useDidShow)(function(){c.length>0&&D()}),(0,s.usePullDownRefresh)(function(){D().then(function(){return d().stopPullDownRefresh()})});var P=function(){var e=(0,r.Z)((0,a.Z)().m(function e(n,c,t){var r;return(0,a.Z)().w(function(e){while(1)switch(e.p=e.n){case 0:return d().showLoading({title:"\u53d1\u9001\u6307\u4ee4..."}),e.p=1,e.n=2,(0,u.LE)({deviceKey:n.deviceKey,action:c,value:t});case 2:console.log("[Control] \u6307\u4ee4\u53d1\u9001\u6210\u529f:",n.deviceKey,c),d().showToast({title:"\u6307\u4ee4\u5df2\u53d1\u9001",icon:"success"}),e.n=4;break;case 3:e.p=3,r=e.v,console.error("[Control] \u6307\u4ee4\u53d1\u9001\u5931\u8d25:",r),d().showToast({title:r instanceof Error?r.message:"\u6307\u4ee4\u53d1\u9001\u5931\u8d25",icon:"none"});case 4:return e.p=4,d().hideLoading(),e.f(4);case 5:return e.a(2)}},e,null,[[1,3,4,5]])}));return function(n,c,t){return e.apply(this,arguments)}}(),T="all"===g?c:"online"===g?c.filter(function(e){return"online"===e.onlineStatus}):"offline"===g?c.filter(function(e){return"online"!==e.onlineStatus}):c.filter(function(e){return e.kind===g}),W=[{key:"all",label:"\u5168\u90e8"},{key:"online",label:"\u5728\u7ebf"},{key:"offline",label:"\u79bb\u7ebf"},{key:"sensor",label:"\u4f20\u611f\u5668"},{key:"actuator",label:"\u6267\u884c\u5668"},{key:"camera",label:"\u6444\u50cf\u5934"}],O=function(e){return"camera"===e?"\ud83d\udcf9":"sensor"===e?"\ud83c\udf21":"actuator"===e?"\u2699\ufe0f":"gateway"===e?"\ud83c\udf10":"\ud83d\udd0c"},R=function(e){if(!e)return null;var n=j.find(function(n){return n.id===e});return n?n.name:null},Z=function(e){return["actuator","controller","fan","ac","dehumidifier"].includes(e)},K=function(e){var n="deviceKey=".concat(encodeURIComponent(e.deviceKey),"&deviceName=").concat(encodeURIComponent(e.name));d().navigateTo({url:"/pages/devices/control/index?".concat(n)})};return b?(0,v.jsx)(o.G7,{className:_.devicesPage,children:(0,v.jsx)(o.G7,{className:_.loadingWrap,children:(0,v.jsx)(o.xv,{className:_.loadingText,children:"\u52a0\u8f7d\u4e2d..."})})}):S?(0,v.jsx)(o.G7,{className:_.devicesPage,children:(0,v.jsxs)(o.G7,{className:_.errorWrap,children:[(0,v.jsx)(o.xv,{className:_.errorIcon,children:"\u26a0\ufe0f"}),(0,v.jsx)(o.xv,{className:_.errorText,children:S}),(0,v.jsx)(o.G7,{className:_.retryBtn,onClick:D,children:(0,v.jsx)(o.xv,{style:{color:"#fff"},children:"\u91cd\u8bd5"})})]})}):(0,v.jsxs)(o.G7,{className:_.devicesPage,children:[(0,v.jsx)(o.pf,{scrollX:!0,className:_.filterBar,children:W.map(function(e){return(0,v.jsx)(o.G7,{className:"".concat(_.filterChip," ").concat(g===e.key?_.filterChipActive:""),onClick:function(){return k(e.key)},children:e.label},e.key)})}),0===T.length?(0,v.jsxs)(o.G7,{className:_.emptyWrap,children:[(0,v.jsx)(o.xv,{className:_.emptyIcon,children:"\ud83d\udce1"}),(0,v.jsx)(o.xv,{className:_.emptyText,children:"\u6682\u65e0\u8bbe\u5907"})]}):(0,v.jsx)(o.G7,{className:_.deviceList,children:T.map(function(e){var n=R(e.roomId),c="online"===e.onlineStatus;return(0,v.jsxs)(o.G7,{className:_.deviceCard,children:[(0,v.jsxs)(o.G7,{className:_.deviceHeader,children:[(0,v.jsxs)(o.G7,{className:_.deviceLeft,children:[(0,v.jsx)(o.G7,{className:_.deviceIcon,children:(0,v.jsx)(o.xv,{children:O(e.kind)})}),(0,v.jsxs)(o.G7,{className:_.deviceInfo,children:[(0,v.jsx)(o.xv,{className:_.deviceName,children:e.name}),(0,v.jsx)(o.xv,{className:_.deviceKey,children:e.deviceKey})]})]}),(0,v.jsxs)(o.G7,{className:"".concat(_.deviceStatusBadge," ").concat(c?_.statusOnline:_.statusOffline),children:[(0,v.jsx)(o.G7,{className:_.statusDot,style:{background:c?"#00b42a":"#c9cdd4"}}),(0,x.Vw)(e.onlineStatus)]})]}),(0,v.jsxs)(o.G7,{className:_.deviceMeta,children:[(0,v.jsxs)(o.G7,{className:_.metaItem,children:[(0,v.jsx)(o.xv,{className:_.metaLabel,children:"\u7c7b\u578b:"}),(0,v.jsx)(o.xv,{children:(0,x.RA)(e.kind)})]}),e.model&&(0,v.jsxs)(o.G7,{className:_.metaItem,children:[(0,v.jsx)(o.xv,{className:_.metaLabel,children:"\u578b\u53f7:"}),(0,v.jsx)(o.xv,{children:e.model})]}),n&&(0,v.jsxs)(o.G7,{className:_.metaItem,children:[(0,v.jsx)(o.xv,{className:_.metaLabel,children:"\u8695\u623f:"}),(0,v.jsx)(o.xv,{children:n})]}),e.lastSeen&&(0,v.jsxs)(o.G7,{className:_.metaItem,children:[(0,v.jsx)(o.xv,{className:_.metaLabel,children:"\u6700\u540e\u5728\u7ebf:"}),(0,v.jsx)(o.xv,{children:(0,x.SY)(e.lastSeen)})]})]}),c&&(0,v.jsxs)(o.G7,{className:_.controlRow,children:[Z(e.kind)&&(0,v.jsx)(o.G7,{className:"".concat(_.controlBtn," ").concat(_.controlBtnPrimary),onClick:function(){return K(e)},children:(0,v.jsx)(o.xv,{children:"\u8bbe\u5907\u63a7\u5236"})}),"actuator"===e.kind&&(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(o.G7,{className:"".concat(_.controlBtn," ").concat(_.controlBtnSecondary),onClick:function(){return P(e,"turn_on")},children:(0,v.jsx)(o.xv,{children:"\u5f00\u542f"})}),(0,v.jsx)(o.G7,{className:"".concat(_.controlBtn," ").concat(_.controlBtnSecondary),onClick:function(){return P(e,"turn_off")},children:(0,v.jsx)(o.xv,{children:"\u5173\u95ed"})})]}),"sensor"===e.kind&&(0,v.jsx)(o.G7,{className:"".concat(_.controlBtn," ").concat(_.controlBtnPrimary),onClick:function(){return P(e,"read")},children:(0,v.jsx)(o.xv,{children:"\u8bfb\u53d6\u6570\u636e"})}),"camera"===e.kind&&(0,v.jsx)(o.G7,{className:"".concat(_.controlBtn," ").concat(_.controlBtnPrimary),onClick:function(){return d().switchTab({url:"/pages/video/index"})},children:(0,v.jsx)(o.xv,{children:"\u67e5\u770b\u89c6\u9891"})}),"sensor"!==e.kind&&"actuator"!==e.kind&&"camera"!==e.kind&&!Z(e.kind)&&(0,v.jsx)(o.G7,{className:"".concat(_.controlBtn," ").concat(_.controlBtnSecondary),onClick:function(){return P(e,"status")},children:(0,v.jsx)(o.xv,{children:"\u67e5\u8be2\u72b6\u6001"})})]})]},e.id)})})]})},f=h,j={navigationBarTitleText:"\u8bbe\u5907",enablePullDownRefresh:!0},p=(0,t.R4)(f,"pages/devices/index",{root:{cn:[]}},j||{});f&&f.behaviors&&(p.behaviors=(p.behaviors||[]).concat(f.behaviors));Page(p)}},function(e){var n=function(n){return e(e.s=n)};e.O(0,[107,216,592],function(){return n(9717)});e.O()}]);