index.js 145 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365
  1. // index.js
  2. // 获取应用实例
  3. import * as echarts from '../../ec-canvas/echarts';
  4. // const { connect } = require("../../utils/mqtt4/mqtt");
  5. /******************* 必须要改!!不然得不到天气!! ******************/
  6. const hefengKey = " aa373d4025b0487196c15d8e6526cfcf"; // 和风天气Web api的key
  7. /******************* 可能需要你修改的部分 ******************/
  8. //const mqttHost = "broker.emqx.io"; //mqtt 服务器域名/IP
  9. // const mqttHost = "www.nekolee.top";
  10. const mqttHost = "haold.aidsleep.cn";
  11. // const mqttHost = "192.168.3.65";
  12. // const mqttPort = 8084; //mqtt 服务器域名/IP
  13. const mqttPort = 8083; //mqtt 服务器域名/IP
  14. const hefengVIP = false; // 和风天气是免费的api(false)还是付费api(true)
  15. const deviceSubTopic_LED = "/NekoHome/sub_LED"; // 设备订阅topic(小程序发布命令topic)
  16. const deviceSubTopic_BEEP = "/NekoHome/sub_BEEP";
  17. const deviceSubTopic_CU = "/NekoHome/sub_CU";
  18. const deviceSubTopic_DO = "/NekoHome/sub_DO";
  19. const deviceSubTopic_SAN = "/NekoHome/sub_SAN";
  20. const deviceSubTopic_Mode = "/NekoHome/sub_mode";
  21. // const devicePubTopic_env = "/NekoHome/pub/Environment"; // 设备发布topic(订阅环境参数)
  22. // const devicePubTopic_con = "/NekoHome/pub/Controll"; // 设备发布topic(订阅控制参数)
  23. const devicePubTopic_env = "testtopic/1"; // 设备发布topic(订阅环境参数)
  24. const devicePubTopic_con = "testtopic/1"; // 设备发布topic(订阅控制参数)
  25. /********************* 一般不用动这些 ********************/
  26. //小程序接收的主题
  27. const mpSubTopic_env = devicePubTopic_env;
  28. const mpSubTopic_con = devicePubTopic_con;
  29. //小程序发送的主题
  30. const mpPubTopic_LED = deviceSubTopic_LED;
  31. const mpPubTopic_BEEP = deviceSubTopic_BEEP;
  32. const mpPubTopic_CU = deviceSubTopic_CU;
  33. const mpPubTopic_DO = deviceSubTopic_DO;
  34. const mpPubTopic_SAN = deviceSubTopic_SAN;
  35. const mpPubTopic_Mode = deviceSubTopic_Mode;
  36. const mqttUrl = `wx://${mqttHost}:${mqttPort}/mqtt`; // mqtt连接路径
  37. const hefengApi = "https://api.qweather.com/v7"; // 和风天气付费API前缀
  38. const hefengFreeApi = "https://devapi.qweather.com/v7"; // 和风天气免费API前缀
  39. const hefengWeather = `${hefengVIP ? hefengApi : hefengFreeApi}/weather/now?`; // 和风天气实时天气api
  40. const hefengAir = `${hefengVIP ? hefengApi : hefengFreeApi}/air/now?`; // 和风天气空气质量api
  41. const geoApi = "https://geoapi.qweather.com/v2/city/lookup?" // 地理位置api(用来获取经纬度对应的城市/城区名字)
  42. var homeApi = "http://haold.aidsleep.cn:8123/api";
  43. var homeApiLater = "http://haold.aidsleep.cn:8123";
  44. var homeApi_https = "https://haold.aidsleep.cn/api";
  45. var homeApiLater_https = "https://haold.aidsleep.cn";
  46. var entity = "";
  47. // const token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJiN2JlOGE0MDExZjY0NjA2OGUxYjJiZTE4M2Y2NzU0NSIsImlhdCI6MTcxMTYxNDY2NCwiZXhwIjoyMDI2OTc0NjY0fQ.XJ73cXAoEsouTgvgpNVobq9oKdwlJr88TiAFLYlaahE";
  48. var token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJlZGVjOWI3YWQ0MTQ0ZTIxYWQ1NTE1Nzc5NTkzNjBjNiIsImlhdCI6MTcxMjEzNTM2MywiZXhwIjoyMDI3NDk1MzYzfQ.IfrvdiaVuhCKsdy69JvUYhJ64bnhMT8MI1hN8R38whc";
  49. const aipushApi = "https://aipush.aidsleep.cn";
  50. const token_push = "b74fd5754c5ef24cf600c39194abdaeb";
  51. const options = {
  52. connectTimeout: 4000,//超时时间
  53. clientId: 'emqx_ODAyNT',//随机生成ID
  54. username: 'test1',
  55. password: '123456'
  56. }
  57. var humidityValue = 40;
  58. var humidityMax = 100;
  59. var humidityMin = 40;
  60. var humidityMarginLeft = 110;
  61. let chartCircularProgressBar;//圈圈
  62. function updateChartCircularProgressBarOption(rscore_desc, rscore_value, that) {
  63. if (chartCircularProgressBar) {
  64. setOption(chartCircularProgressBar);
  65. } else {
  66. that.selectComponent('#mychart-dom-gauge').init((canvas, width, height, dpr) => {
  67. const chart = echarts.init(canvas, null, {
  68. width: width,
  69. height: height,
  70. devicePixelRatio: dpr // new
  71. });
  72. canvas.setChart(chart);
  73. setOption(chart);
  74. // 将图表实例绑定到 this 上,可以在其他成员函数(如 dispose)中访问
  75. chartCircularProgressBar = chart;
  76. // 注意这里一定要返回 chart 实例,否则会影响事件处理等
  77. return chart;
  78. });
  79. }
  80. }
  81. function checkState(state) {
  82. return state == 'on' || state == 'off';
  83. }
  84. function setOption(chart) {
  85. var option = {
  86. backgroundColor: "#ffffff",
  87. series: [{
  88. name: '加湿器',
  89. type: 'gauge',
  90. startAngle: 230,
  91. endAngle: -50,
  92. splitNumber: 8,
  93. min: humidityMin || 40,
  94. max: humidityMax || 70,
  95. axisLine: {
  96. show: false
  97. },
  98. axisLabel: {
  99. show: false,
  100. },
  101. anchor: {
  102. show: false
  103. },
  104. splitLine: {
  105. distance: -10,
  106. length: 6,
  107. lineStyle: {
  108. width: 1.5,
  109. color: '#9499C3'
  110. }
  111. },
  112. pointer: {
  113. show: false
  114. },
  115. axisTick: {
  116. distance: -10,
  117. splitNumber: 5,
  118. lineStyle: {
  119. width: 1,
  120. color: '#9499C3'
  121. }
  122. },
  123. progress: {
  124. show: true,
  125. width: 10,
  126. itemStyle: {
  127. color: "#0BC3AA"
  128. }
  129. },
  130. title: {
  131. color: '#6C6970',
  132. offsetCenter: [0, '-50%'],
  133. lineHeight: 15,
  134. fontSize: 12
  135. },
  136. detail: {
  137. valueAnimation: true,
  138. width: '100%',
  139. offsetCenter: [0, '20%'],
  140. fontSize: "28px",
  141. fontWeight: 'bolder',
  142. formatter: function (value) {
  143. return `${value.toFixed(0) }` + '{units|%}'
  144. },
  145. color: '#3E3D44',
  146. rich: {
  147. units: {
  148. fontSize: "12px",
  149. padding: [10, 0, 0, 1],
  150. fontWeight: 'bolder',
  151. color: '#333333'
  152. },
  153. }
  154. },
  155. data: [{
  156. value: humidityValue || 0,
  157. name: '湿度',
  158. }]
  159. }]
  160. };
  161. chart.setOption(option);
  162. }
  163. // import Notify from '../../@vant/weapp/notify/notify';
  164. // import Dialog from '../../@vant/weapp/dialog/dialog';
  165. import Toast from '../../@vant/weapp/toast/toast';
  166. Page({
  167. data: {
  168. ecHumidifier: {
  169. lazyLoad: true, // 懒加载
  170. },
  171. //单选框
  172. radio_select: '10',
  173. radio_switch: '10',
  174. //倒计时时间
  175. Time: 0,
  176. //火灾时的呼吸效果变量
  177. breathNum: 0,
  178. currentMenuTabIndex: -1,
  179. currentDialogIndex: 0,
  180. menuTabDialogShow: false,
  181. //火灾头顶警示
  182. topTips: true,
  183. hide: false,
  184. //火灾弹窗显示
  185. fire_show: false,
  186. //设备控制弹窗参数 开始
  187. show_led: false,
  188. show_beep: false,
  189. show_curtain: false,
  190. show_san: false,
  191. show_door: false,
  192. show_time: false,
  193. actions_led: [
  194. {
  195. name: '打开',
  196. subname: '打开客厅灯',
  197. id: 1,
  198. url: '',
  199. entity_id: '',
  200. },
  201. {
  202. name: '关闭',
  203. subname: '关闭客厅灯',
  204. id: 0,
  205. url: '',
  206. entity_id: '',
  207. },
  208. ],
  209. actions_beep: [
  210. {
  211. name: '打开',
  212. subname: '打开警报器',
  213. id: 1,
  214. url: '/services/switch/turn_on',
  215. entity_id: 'switch.deerma_jsq2g_392f_alarm',
  216. },
  217. {
  218. name: '关闭',
  219. subname: '关闭警报器',
  220. id: 0,
  221. url: '/services/switch/turn_off',
  222. entity_id: 'switch.deerma_jsq2g_392f_alarm',
  223. },
  224. ],
  225. actions_curtain: [
  226. {
  227. name: '打开',
  228. subname: '打开香薰机',
  229. id: 90,
  230. url: '',
  231. entity_id: '',
  232. },
  233. {
  234. name: '关闭',
  235. subname: '关闭香薰机',
  236. id: 0,
  237. url: '',
  238. entity_id: '',
  239. },
  240. ],
  241. actions_san: [
  242. {
  243. name: '打开',
  244. subname: '打开音响',
  245. id: 1,
  246. url: '',
  247. entity_id: '',
  248. },
  249. {
  250. name: '关闭',
  251. subname: '关闭音响',
  252. id: 0,
  253. url: '',
  254. entity_id: '',
  255. },
  256. ],
  257. actions_door: [
  258. {
  259. name: '打开',
  260. subname: '打开智能开关',
  261. id: 90,
  262. url: '',
  263. entity_id: '',
  264. },
  265. {
  266. name: '关闭',
  267. subname: '关闭智能开关',
  268. id: 0,
  269. url: '',
  270. entity_id: '',
  271. },
  272. ],
  273. //设备控制弹窗参数 结束
  274. client: {},
  275. //设备状态参数 开始
  276. status_beep: 0,
  277. status_led: 0,
  278. status_san: 0,
  279. status_curtain: 0,
  280. status_door: 0,
  281. status_fire: 0,
  282. status_light: 0,
  283. status_mode: 0,
  284. //设备状态参数 结束
  285. //设备环境参数 开始
  286. Temp: 0,
  287. Humi: 0,
  288. Voltage1: 0,
  289. Voltage2: 0,
  290. //设备环境参数 结束
  291. //香薰机参数 开始
  292. Light: 0,
  293. LiquidLevel: 0,
  294. //香薰机参数 开始
  295. area: "请求中", //城区
  296. city: "请求中", //城市
  297. airText: "请求中", //空气优良
  298. airValue: 0, //空气指数
  299. weather: "请求中", //天气
  300. //weatherAdvice: "今天天气不错", //天气建议
  301. time: 30 * 60 * 60 * 1000,
  302. gradientColor: {
  303. '0%': '#ffd01e',
  304. '100%': '#ee0a24',
  305. },
  306. value: 25,
  307. pickerValue: [0], // picker-view 的当前值,数组形式,表示选择器的当前位置
  308. array: ['0%', '10%', '20%', '30%', '40%', '50%', '60%', '70%', '80%', '90%', '100%'], // 滑动块可选的值
  309. items: ['0%', '10%', '20%', '30%', '40%', '50%', '60%', '70%', '80%', '90%', '100%'], // 滑动块可选的值
  310. scaleTextStyle: {
  311. show: true,
  312. size: 12,
  313. color: ''
  314. },
  315. indicatorTextStyle: {
  316. show: true,
  317. size: 16,
  318. text: '湿度'
  319. },
  320. indicatorTextStyleClimate: {
  321. show: true,
  322. size: 16,
  323. text: '温度'
  324. },
  325. indicatorValueStyle: {
  326. show: true,
  327. size: 55,
  328. color: ''
  329. },
  330. indicatorCircleStyle: {
  331. show: true,
  332. boderColor: [
  333. {
  334. progress: 0,
  335. value: "#4575e8"
  336. },
  337. {
  338. progress: 1,
  339. value: "#fff"
  340. }
  341. ]
  342. },
  343. listCover: [],//窗帘开关
  344. listSwitch: [],//开关
  345. listScroll: [],//滚动条
  346. listUnit: [],//rgb、%、minutes、w等
  347. listConversation: [],//智能音响
  348. listConversation1: [],//智能音响
  349. listHumidity: [],//加湿器
  350. listButton: [],//按钮 '按下'
  351. listSelect: [],//下拉框的
  352. listClimate: [],//空调控制 图像
  353. listMiotMediaPlayer: [],//智能音箱 图像
  354. listMitvMediaPlayer: [],//电视 图像
  355. listHumidifier: [],//加湿器 图像
  356. listAromatherapyMachine: [],//香薰机 图像
  357. listSensor: [],//文字描述的
  358. listText: [],//文本框填写的
  359. isPlaying: false,
  360. currentTime: 0,
  361. currentIndex: 0,
  362. duration: 0,
  363. currentSongTitle: '--',
  364. currentSongArtist: '--',
  365. canPrev: true,
  366. canNext: true,
  367. songs: [], // 歌曲列表
  368. scrollValue: [],
  369. modelList1: [],//起床模式
  370. modelList2: [],//观影模式
  371. modelList3: [],//睡眠模式
  372. selectedIndex: 0, // 默认选中第一个选项
  373. home_room: [
  374. 'company_laboratory',
  375. '2802',
  376. ],
  377. climateMode: '',//空调模式:加热还是除湿。在空调增加按钮和减少按钮 时使用
  378. canvasWidth: 300, // 画布宽度
  379. canvasHeight: 150, // 画布高度
  380. value: 60, // 当前得分
  381. total: 100, // 总分值
  382. tvEntityId: '',// 电视实体Id
  383. tvEntityIds: [],// 电视实体
  384. entityName: '',//
  385. sleep_duration: '50',
  386. itemList: [
  387. { name: '1', data: [{ value: 10 }, { value: 1 }] },
  388. { name: '2', data: [{ value: 10 }, { value: 4 }] },
  389. { name: '3', data: [{ value: 10 }, { value: 7 }] },
  390. ],
  391. blackList: [
  392. // '指示灯','电视模式','电视音量','空调遥控','智能音箱','电视控制码','传感器模式','开关模式','耗电量','智能音箱会话'
  393. '加湿器', '空调', '音箱', '窗帘', '纱帘'
  394. ],
  395. temperatureHumidifyName: '温度',
  396. temperatureValue:0,
  397. isButtonPressedHumidityUp: false,
  398. isButtonPressedHumidityDown: false,
  399. isButtonPressedClimateUp: false,
  400. isButtonPressedClimateDown: false,
  401. tcp: '',
  402. w_temp: '',//温度
  403. w_humidity: '',//湿度
  404. imgSrc: '',//图片地址
  405. isLoading: false,
  406. observer: '',
  407. hotelcode: '',//酒店编码
  408. roomcode: '',//房间编码
  409. isClickedPrevSong: false,
  410. isClickedTogglePlayPause: false,
  411. isClickedNextSong: false,
  412. isClickedOnHumidifierUp: false,
  413. isClickedOnHumidifierDown: false,
  414. isClickedOnClimateAuto: false,
  415. isClickedOnClimateUp: false,
  416. isClickedToggleAromlight: false,//香薰机灯光
  417. intervalId1: null,
  418. intervalId2: null,
  419. sliderValueHumidifier: '',
  420. sliderValueClimate: '',
  421. humidityMarginLeft: humidityMarginLeft
  422. },
  423. checkMenuTap(e) {
  424. // 三种模式
  425. console.log(e.currentTarget.dataset.index)
  426. const index = e.currentTarget.dataset.index;
  427. if (this.data.currentMenuTabIndex == index) {
  428. // 选中的打断
  429. return
  430. }
  431. if (index == 0 && !this.data.modelList1.length) {
  432. // 没有的打断
  433. return
  434. }
  435. if (index == 1 && !this.data.modelList2.length) {
  436. // 没有的打断
  437. return
  438. }
  439. if (index == 2 && !this.data.modelList3.length) {
  440. // 没有的打断
  441. return
  442. }
  443. this.setData({
  444. menuTabDialogShow: true,
  445. currentDialogIndex: index
  446. })
  447. },
  448. onClickHideMenuTabDialog() {
  449. this.setData({
  450. menuTabDialogShow: false
  451. })
  452. },
  453. onClickHideSureMenuTabDialog() {
  454. var item = null;
  455. if (this.data.currentDialogIndex == 0) {
  456. item = this.data.modelList1[0];
  457. } else if (this.data.currentDialogIndex == 1) {
  458. item = this.data.modelList2[0];
  459. } else if (this.data.currentDialogIndex == 2) {
  460. item = this.data.modelList3[0];
  461. }
  462. // 确认模式
  463. this.setData({
  464. menuTabDialogShow: false,
  465. currentMenuTabIndex: this.data.currentDialogIndex
  466. })
  467. wx.request({
  468. url: `${homeApi_https}/services/automation/trigger`,
  469. method: 'POST',
  470. data: {
  471. "entity_id": item.entity_id,
  472. "skip_condition": true,
  473. },
  474. header: {
  475. 'content-type': 'application/json', // 默认值
  476. 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  477. },
  478. success(res) {
  479. },
  480. });
  481. },
  482. checkHumidityMarginLeft() {
  483. var proportion = 440;
  484. var percentage = (humidityValue - humidityMin) / (humidityMax - humidityMin);
  485. const value = percentage * proportion + humidityMarginLeft;
  486. this.setData({
  487. humidityMarginLeft: value
  488. })
  489. },
  490. // 加湿器
  491. handleTouchEndHumidifier: function (e) {
  492. this.setData({
  493. sliderValueHumidifier: '',
  494. });
  495. },
  496. // 加湿器更改湿度
  497. handleChangingHumidifier: function (e) {
  498. // 假设 slider 宽度为屏幕宽度(或某个固定值),这里需要根据实际情况调整
  499. const sliderValueHumidifier = e.detail.value;
  500. var proportion = 440;
  501. var percentage = (sliderValueHumidifier - humidityMin) / (humidityMax - humidityMin);
  502. const humidityMarginLeftValue = percentage * proportion + humidityMarginLeft;
  503. this.setData({
  504. sliderValueHumidifier: sliderValueHumidifier,
  505. humidityMarginLeft: humidityMarginLeftValue
  506. });
  507. },
  508. handleTouchEndClimate: function (e) {
  509. this.setData({
  510. sliderValueClimate: '',
  511. });
  512. },
  513. handleChangingClimate: function (e) {
  514. // 假设 slider 宽度为屏幕宽度(或某个固定值),这里需要根据实际情况调整
  515. const screenWidth = wx.getSystemInfoSync().windowWidth;
  516. const sliderValueClimate = e.detail.value;
  517. this.setData({
  518. sliderValueClimate: sliderValueClimate
  519. })
  520. },
  521. replaceAll: function (str, find, replace) {
  522. return str.replace(new RegExp(find, 'g'), replace);
  523. },
  524. checkFuzzyMatch: function (data) {
  525. var searchString = data.attributes.friendly_name
  526. var domain = data.entity_id.split(".")[0]
  527. var isMatched = true;
  528. var list = this.data.blackList;
  529. if (!searchString || !list) return false;
  530. for (var i = 0; i < list.length; i++) {
  531. if (searchString.indexOf(list[i]) !== -1) {
  532. isMatched = false;
  533. break;
  534. }
  535. }
  536. return isMatched;
  537. },
  538. onChange: function (e) {
  539. this.setData({
  540. pickerValue: e.detail.value, // 更新picker-view的值
  541. });
  542. // 在这里添加点击事件的处理逻辑
  543. // 根据pickerValue的变化执行相应的操作
  544. },
  545. swiperTap(e) {
  546. // 处理整个swiper的点击事件
  547. },
  548. itemTap(e) {
  549. // 处理swiper-item的点击事件
  550. const index = e.currentTarget.dataset.index;
  551. // 根据index执行其他操作
  552. },
  553. //定时组件
  554. start() {
  555. const countDown = this.selectComponent('.control-count-down');
  556. countDown.start();
  557. },
  558. pause() {
  559. const countDown = this.selectComponent('.control-count-down');
  560. countDown.pause();
  561. },
  562. reset() {
  563. const countDown = this.selectComponent('.control-count-down');
  564. countDown.reset();
  565. },
  566. set() {
  567. this.setData({
  568. show_time: true,
  569. })
  570. },
  571. onClose_TimeSet() {
  572. this.setData({ show_time: false });
  573. },
  574. onChange_Silder(event) {
  575. wx.showToast({
  576. icon: 'none',
  577. title: `定时:${event.detail}s`,
  578. });
  579. this.setData({
  580. Time: event.detail,
  581. })
  582. },
  583. onChange_Select(event) {
  584. this.setData({
  585. radio_select: event.detail,
  586. });
  587. },
  588. onChange_Switch(event) {
  589. this.setData({
  590. radio_switch: event.detail,
  591. });
  592. },
  593. finished() {
  594. var that = this;
  595. //定时开关哪个设备?
  596. if (that.data.radio_select == 2) {
  597. if (that.data.radio_switch == 1) {
  598. console.log("选择了开");
  599. that.data.client.publish(mpPubTopic_LED, '{"target":"LED","value":1}', function (err) {
  600. if (!err) {
  601. console.log("成功下发命令——打开客厅灯");
  602. }
  603. });
  604. } else {
  605. console.log("选择了关");
  606. that.data.client.publish(mpPubTopic_LED, '{"target":"LED","value":0}', function (err) {
  607. if (!err) {
  608. console.log("成功下发命令——关闭客厅灯");
  609. }
  610. });
  611. }
  612. } else if (that.data.radio_select == 3) {
  613. console.log("选择了BEEP");
  614. if (that.data.radio_switch == 1) {
  615. console.log("选择了开");
  616. that.data.client.publish(mpPubTopic_BEEP, '{"target":"BEEP","value":1}', function (err) {
  617. if (!err) {
  618. console.log("成功下发命令——打开报警器");
  619. }
  620. });
  621. } else {
  622. console.log("选择了关");
  623. that.data.client.publish(mpPubTopic_BEEP, '{"target":"BEEP","value":0}', function (err) {
  624. if (!err) {
  625. console.log("成功下发命令——关闭报警器");
  626. }
  627. });
  628. }
  629. } else if (that.data.radio_select == 4) {
  630. console.log("选择了CU");
  631. if (that.data.radio_switch == 1) {
  632. console.log("选择了开");
  633. that.data.client.publish(mpPubTopic_CU, '{"target":"CU","value":1}', function (err) {
  634. if (!err) {
  635. console.log("成功下发命令——开窗帘");
  636. }
  637. });
  638. } else {
  639. console.log("选择了关");
  640. that.data.client.publish(mpPubTopic_CU, '{"target":"CU","value":0}', function (err) {
  641. if (!err) {
  642. console.log("成功下发命令——关窗帘");
  643. }
  644. });
  645. }
  646. } else if (that.data.radio_select == 5) {
  647. console.log("选择了SAN");
  648. if (that.data.radio_switch == 1) {
  649. console.log("选择了开");
  650. that.data.client.publish(mpPubTopic_SAN, '{"target":"SAN","value":1}', function (err) {
  651. if (!err) {
  652. console.log("成功下发命令——开风扇");
  653. }
  654. });
  655. } else {
  656. console.log("选择了关");
  657. that.data.client.publish(mpPubTopic_SAN, '{"target":"SAN","value":0}', function (err) {
  658. if (!err) {
  659. console.log("成功下发命令——关风扇");
  660. }
  661. });
  662. }
  663. }
  664. Toast('倒计时结束');
  665. },
  666. setTextBreathing: function (cls, e) {
  667. //使用记录呼吸效果
  668. var transparency = 10;
  669. var reduce = true; //记录当前做透明度增加或降低操作
  670. setInterval(function () {
  671. if (reduce === true) {
  672. transparency -= 1;
  673. if (transparency === 0) {
  674. reduce = false;
  675. }
  676. } else if (reduce === false) {
  677. transparency += 1;
  678. if (transparency === 10) {
  679. reduce = true;
  680. }
  681. }
  682. cls._defaultComponent.setData({
  683. breathNum: transparency / 10
  684. })
  685. //通过setData的方式,设置breathNum的值
  686. }, 80)
  687. },
  688. // 各个设备弹窗逻辑
  689. onOpen_led() {
  690. this.setData({ show_led: true });
  691. },
  692. onClose_led() {
  693. this.setData({
  694. show_led: false
  695. })
  696. },
  697. onSelect_led(event) {
  698. console.log(event.detail.id);
  699. this.onLedChange(event.detail.id);
  700. },
  701. onOpen_beep() {
  702. this.setData({ show_beep: true });
  703. },
  704. onClose_beep() {
  705. this.setData({
  706. show_beep: false
  707. })
  708. },
  709. onSelect_beep(event) {
  710. console.log(event.detail.id);
  711. this.onBeepChange(event.detail.id, event.detail.url, event.detail.entity_id);
  712. },
  713. getRealApi() {
  714. // if(wx.getStorageSync('res').result && wx.getStorageSync('res').result.includes('辰悦颐养斋')){
  715. // homeApi = "http://zhh.aidsleep.cn:9123/api";
  716. // homeApiLater = "http://zhh.aidsleep.cn:9123";
  717. // homeApi_https = "https://zhh.aidsleep.cn/api";
  718. // homeApiLater_https = "https://zhh.aidsleep.cn";
  719. // entity = wx.getStorageSync('res').result=='company_laboratory'?'公司实验室':wx.getStorageSync('res').result
  720. // if(entity && entity.includes('-')){
  721. // entity = entity.slice(entity.indexOf('-')+1)
  722. // }
  723. // if(entity && entity.includes('|')){
  724. // entity = entity.slice(entity.indexOf('|')+1)
  725. // }
  726. // }else if(wx.getStorageSync('res').result && (!wx.getStorageSync('res').result.includes('辰悦颐养斋'))){
  727. // homeApi = "http://haold.aidsleep.cn:8123/api";
  728. // homeApiLater = "http://haold.aidsleep.cn:8123";
  729. // homeApi_https = "https://haold.aidsleep.cn/api";
  730. // homeApiLater_https = "https://haold.aidsleep.cn";
  731. // entity = wx.getStorageSync('res').result=='company_laboratory'?'公司实验室':wx.getStorageSync('res').result
  732. // if(entity && entity.includes('-')){
  733. // entity = str.slice(str.indexOf('-')+1)
  734. // }
  735. // if(entity && entity.includes('|')){
  736. // entity = str.slice(str.indexOf('|')+1)
  737. // }
  738. // }
  739. },
  740. onSelect_vangrid(url, entity_id) {
  741. // this.setData({
  742. // status_beep: Number(param4)
  743. // })
  744. wx.request({
  745. url: `${homeApi_https}` + url,
  746. method: 'POST',
  747. data: {
  748. "entity_id": entity_id
  749. },
  750. header: {
  751. 'content-type': 'application/json', // 默认值
  752. 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  753. },
  754. success(res) {
  755. },
  756. });
  757. },
  758. tvFanChange(e) {
  759. var that = this;
  760. // 获取绑定的参数
  761. var entity_id = e.currentTarget.dataset.id;
  762. //模式
  763. var fan = e.currentTarget.dataset.fan;
  764. wx.request({
  765. url: `${homeApi_https}` + '/services/media_player/select_source',
  766. method: 'POST',
  767. data: {
  768. "entity_id": entity_id,
  769. "source": fan
  770. },
  771. header: {
  772. 'content-type': 'application/json', // 默认值
  773. 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  774. },
  775. success(res) {
  776. // if(res.data){
  777. // that.getSwitch(res.data,that)
  778. // }
  779. },
  780. });
  781. },
  782. // switch
  783. onSelect_All(e) {
  784. var that = this;
  785. const tempListSwitch = that.data.listSwitch;
  786. // 获取绑定的参数
  787. var param0 = e.currentTarget.dataset.param0;
  788. var param1 = e.currentTarget.dataset.param1;
  789. var param2 = e.currentTarget.dataset.param2;
  790. // var param3 = e.currentTarget.dataset.param3;
  791. var param4 = e.currentTarget.dataset.param4 // 0 || 1;
  792. var param5 = e.currentTarget.dataset.param5;
  793. console.log('param1=' + param1);
  794. console.log('param2=' + param2);
  795. // console.log('param3='+param3);
  796. // console.log('param4='+param4);
  797. console.log('param5=' + param5);
  798. if (param4 == '1') {
  799. tempListSwitch[param0].state = "on"
  800. } else {
  801. tempListSwitch[param0].state = "off"
  802. }
  803. that.setData({
  804. listSwitch: tempListSwitch
  805. })
  806. // this.setData({
  807. // status_beep: Number(param4)
  808. // })
  809. // if(param3 == "/turn_on"){
  810. // that.data.listSwitch[param0].state = "off";
  811. // that.data.listSwitch[param0].service = "turn_off";
  812. // }else if(param3 == "/turn_off"){
  813. // that.data.listSwitch[param0].state = "on";
  814. // that.data.listSwitch[param0].service = "turn_on";
  815. // }
  816. console.log('switch 发生 change 事件,携带值为', e.detail)
  817. wx.request({
  818. url: `${homeApi_https}` + param1 + param2 + (e.detail ? '/turn_on' : '/turn_off'),
  819. method: 'POST',
  820. data: {
  821. "entity_id": param5
  822. },
  823. header: {
  824. 'content-type': 'application/json', // 默认值
  825. 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  826. },
  827. success(res) {
  828. // if(res.data){
  829. // that.getSwitch(res.data,that)
  830. // }
  831. },
  832. });
  833. },
  834. // 香薰机开关
  835. onSelect_All_AromatherapyMachine(e) {
  836. var that = this;
  837. const tempListSwitch = that.data.listAromatherapyMachine;
  838. // 获取绑定的参数
  839. var param0 = e.currentTarget.dataset.param0;
  840. var param1 = e.currentTarget.dataset.param1;
  841. var param2 = e.currentTarget.dataset.param2;
  842. // var param3 = e.currentTarget.dataset.param3;
  843. var param4 = e.currentTarget.dataset.param4 // 0 || 1;
  844. var param5 = e.currentTarget.dataset.param5;
  845. console.log('param1=' + param1);
  846. console.log('param2=' + param2);
  847. // console.log('param3='+param3);
  848. // console.log('param4='+param4);
  849. console.log('param5=' + param5);
  850. if (param4 == '1') {
  851. tempListSwitch[param0].state = "on"
  852. } else {
  853. tempListSwitch[param0].state = "off"
  854. }
  855. that.setData({
  856. listAromatherapyMachine: tempListSwitch
  857. })
  858. // this.setData({
  859. // status_beep: Number(param4)
  860. // })
  861. // if(param3 == "/turn_on"){
  862. // that.data.listSwitch[param0].state = "off";
  863. // that.data.listSwitch[param0].service = "turn_off";
  864. // }else if(param3 == "/turn_off"){
  865. // that.data.listSwitch[param0].state = "on";
  866. // that.data.listSwitch[param0].service = "turn_on";
  867. // }
  868. console.log('switch 发生 change 事件,携带值为', e.detail)
  869. wx.request({
  870. url: `${homeApi_https}` + param1 + param2 + (e.detail ? '/turn_on' : '/turn_off'),
  871. method: 'POST',
  872. data: {
  873. "entity_id": param5
  874. },
  875. header: {
  876. 'content-type': 'application/json', // 默认值
  877. 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  878. },
  879. success(res) {
  880. // if(res.data){
  881. // that.getSwitch(res.data,that)
  882. // }
  883. },
  884. });
  885. },
  886. onTap_All(e) {
  887. var that = this;
  888. // 获取绑定的参数
  889. var param0 = e.currentTarget.dataset.param0;
  890. var param1 = e.currentTarget.dataset.param1;
  891. var param2 = e.currentTarget.dataset.param2;
  892. // var param3 = e.currentTarget.dataset.param3;
  893. var param4 = e.currentTarget.dataset.param4;
  894. var param5 = e.currentTarget.dataset.param5;
  895. console.log('param1=' + param1);
  896. console.log('param2=' + param2);
  897. // console.log('param3='+param3);
  898. // console.log('param4='+param4);
  899. console.log('param5=' + param5);
  900. // this.setData({
  901. // status_beep: Number(param4)
  902. // })
  903. // if(param3 == "/turn_on"){
  904. // that.data.listSwitch[param0].state = "off";
  905. // that.data.listSwitch[param0].service = "turn_off";
  906. // }else if(param3 == "/turn_off"){
  907. // that.data.listSwitch[param0].state = "on";
  908. // that.data.listSwitch[param0].service = "turn_on";
  909. // }
  910. console.log('switch 发生 change 事件,携带值为', param4)
  911. wx.request({
  912. url: `${homeApi_https}` + param1 + param2 + (param4 == '1' ? '/turn_on' : '/turn_off'),
  913. method: 'POST',
  914. data: {
  915. "entity_id": param5
  916. },
  917. header: {
  918. 'content-type': 'application/json', // 默认值
  919. 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  920. },
  921. success(res) {
  922. // if(res.data){
  923. // that.getSwitch(res.data,that)
  924. // }
  925. },
  926. });
  927. },
  928. //香薰机灯光控制
  929. onSelect_All_aromlight(e) {
  930. var that = this;
  931. this.setData({
  932. isClickedToggleAromlight: true
  933. });
  934. // 获取绑定的参数
  935. var param0 = e.currentTarget.dataset.param0;
  936. var param1 = e.currentTarget.dataset.param1;
  937. var param2 = e.currentTarget.dataset.param2;
  938. // var param3 = e.currentTarget.dataset.param3;
  939. // var param4 = e.currentTarget.dataset.param4;
  940. var param5 = e.currentTarget.dataset.param5;
  941. console.log('param1=' + param1);
  942. console.log('param2=' + param2);
  943. // console.log('param3='+param3);
  944. // console.log('param4='+param4);
  945. console.log('param5=' + param5);
  946. // this.setData({
  947. // status_beep: Number(param4)
  948. // })
  949. // if(param3 == "/turn_on"){
  950. // that.data.listSwitch[param0].state = "off";
  951. // that.data.listSwitch[param0].service = "turn_off";
  952. // }else if(param3 == "/turn_off"){
  953. // that.data.listSwitch[param0].state = "on";
  954. // that.data.listSwitch[param0].service = "turn_on";
  955. // }
  956. // console.log('switch 发生 change 事件,携带值为', e.detail.value)
  957. wx.request({
  958. url: `${homeApi_https}` + param1 + param2 + '/turn_on',
  959. method: 'POST',
  960. data: {
  961. "entity_id": param5
  962. },
  963. header: {
  964. 'content-type': 'application/json', // 默认值
  965. 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  966. },
  967. success(res) {
  968. // if(res.data){
  969. // that.getSwitch(res.data,that)
  970. // }
  971. },
  972. });
  973. },
  974. onSelect_Cover(e) {
  975. var that = this;
  976. // 获取绑定的参数
  977. var param0 = e.currentTarget.dataset.param0;
  978. var param1 = e.currentTarget.dataset.param1;
  979. var param2 = e.currentTarget.dataset.param2;
  980. // var param3 = e.currentTarget.dataset.param3;
  981. // var param4 = e.currentTarget.dataset.param4;
  982. var param5 = e.currentTarget.dataset.param5;
  983. console.log('param1=' + param1);
  984. console.log('param2=' + param2);
  985. // console.log('param3='+param3);
  986. // console.log('param4='+param4);
  987. console.log('param5=' + param5);
  988. // this.setData({
  989. // status_beep: Number(param4)
  990. // })
  991. // if(param3 == "/turn_on"){
  992. // that.data.listSwitch[param0].state = "off";
  993. // that.data.listSwitch[param0].service = "turn_off";
  994. // }else if(param3 == "/turn_off"){
  995. // that.data.listSwitch[param0].state = "on";
  996. // that.data.listSwitch[param0].service = "turn_on";
  997. // }
  998. console.log('switch 发生 change 事件,携带值为', e.detail.value)
  999. wx.request({
  1000. url: `${homeApi_https}` + param1 + param2 + (e.detail.value ? '/open_cover' : '/close_cover'),
  1001. method: 'POST',
  1002. data: {
  1003. "entity_id": param5
  1004. },
  1005. header: {
  1006. 'content-type': 'application/json', // 默认值
  1007. 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  1008. },
  1009. success(res) {
  1010. // if(res.data){
  1011. // that.getSwitch(res.data,that)
  1012. // }
  1013. },
  1014. });
  1015. },
  1016. onStop_Cover(e) {
  1017. var that = this;
  1018. // 获取绑定的参数
  1019. var param0 = e.currentTarget.dataset.param0;
  1020. var param1 = e.currentTarget.dataset.param1;
  1021. var param2 = e.currentTarget.dataset.param2;
  1022. // var param3 = e.currentTarget.dataset.param3;
  1023. // var param4 = e.currentTarget.dataset.param4;
  1024. var param5 = e.currentTarget.dataset.param5;
  1025. console.log('param1=' + param1);
  1026. console.log('param2=' + param2);
  1027. // console.log('param3='+param3);
  1028. // console.log('param4='+param4);
  1029. console.log('param5=' + param5);
  1030. // this.setData({
  1031. // status_beep: Number(param4)
  1032. // })
  1033. // if(param3 == "/turn_on"){
  1034. // that.data.listSwitch[param0].state = "off";
  1035. // that.data.listSwitch[param0].service = "turn_off";
  1036. // }else if(param3 == "/turn_off"){
  1037. // that.data.listSwitch[param0].state = "on";
  1038. // that.data.listSwitch[param0].service = "turn_on";
  1039. // }
  1040. console.log('switch 发生 change 事件,携带值为', e.detail.value)
  1041. wx.request({
  1042. url: `${homeApi_https}` + param1 + param2 + '/stop_cover',
  1043. method: 'POST',
  1044. data: {
  1045. "entity_id": param5
  1046. },
  1047. header: {
  1048. 'content-type': 'application/json', // 默认值
  1049. 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  1050. },
  1051. success(res) {
  1052. // if(res.data){
  1053. // that.getSwitch(res.data,that)
  1054. // }
  1055. },
  1056. });
  1057. },
  1058. onPressButton(e) {
  1059. var that = this;
  1060. // 获取绑定的参数
  1061. var param = e.currentTarget.dataset.param;
  1062. console.log("sliderChange-param=" + param);
  1063. // wx.request({
  1064. // url: `${homeApi_https}`+param1+param2+param3,
  1065. // method: 'POST',
  1066. // data: {
  1067. // "entity_id":param5
  1068. // },
  1069. // header: {
  1070. // 'content-type': 'application/json', // 默认值
  1071. // 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  1072. // },
  1073. // success(res) {
  1074. // // if(res.data){
  1075. // // that.getSwitch(res.data,that)
  1076. // // }
  1077. // console.log('res.data====='+JSON.stringify(res.data));
  1078. // },
  1079. // });
  1080. let domain = e.currentTarget.dataset.domain;
  1081. let entity_id = e.currentTarget.dataset.id;
  1082. let data = {
  1083. "entity_id": entity_id,
  1084. // "value":newValue
  1085. }
  1086. this.getService("/services", "/" + domain, "/press", "POST", data);
  1087. },
  1088. onSelect_beep1(e) {
  1089. // 获取绑定的参数
  1090. var param1 = e.currentTarget.dataset.param1;
  1091. var param2 = e.currentTarget.dataset.param2;
  1092. var param3 = e.currentTarget.dataset.param3;
  1093. var param4 = e.currentTarget.dataset.param4;
  1094. var param5 = e.currentTarget.dataset.param5;
  1095. console.log('param1=' + param1);
  1096. console.log('param2=' + param2);
  1097. console.log('param3=' + param3);
  1098. console.log('param4=' + param4);
  1099. console.log('param5=' + param5);
  1100. this.setData({
  1101. status_beep: Number(param4)
  1102. })
  1103. wx.request({
  1104. url: `${homeApi_https}` + param1 + param2 + param3,
  1105. method: 'POST',
  1106. data: {
  1107. "entity_id": param5
  1108. },
  1109. header: {
  1110. 'content-type': 'application/json', // 默认值
  1111. 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  1112. },
  1113. success(res) {
  1114. console.log('res.data=====' + JSON.stringify(res.data));
  1115. },
  1116. });
  1117. },
  1118. status_led1(e) {
  1119. // 获取绑定的参数
  1120. var param1 = e.currentTarget.dataset.param1;
  1121. var param2 = e.currentTarget.dataset.param2;
  1122. var param3 = e.currentTarget.dataset.param3;
  1123. var param4 = e.currentTarget.dataset.param4;
  1124. var param5 = e.currentTarget.dataset.param5;
  1125. this.setData({
  1126. status_led: Number(param4)
  1127. })
  1128. wx.request({
  1129. url: `${homeApi_https}` + param1 + param2 + param3,
  1130. method: 'POST',
  1131. data: {
  1132. "entity_id": param5
  1133. },
  1134. header: {
  1135. 'content-type': 'application/json', // 默认值
  1136. 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  1137. },
  1138. success(res) {
  1139. console.log('res.data=====' + JSON.stringify(res.data));
  1140. },
  1141. });
  1142. },
  1143. status_san1(e) {
  1144. // 获取绑定的参数
  1145. var param1 = e.currentTarget.dataset.param1;
  1146. var param2 = e.currentTarget.dataset.param2;
  1147. var param3 = e.currentTarget.dataset.param3;
  1148. var param4 = e.currentTarget.dataset.param4;
  1149. var param5 = e.currentTarget.dataset.param5;
  1150. this.setData({
  1151. status_san: Number(param4)
  1152. })
  1153. wx.request({
  1154. url: `${homeApi_https}` + param1 + param2 + param3,
  1155. method: 'POST',
  1156. data: {
  1157. "entity_id": param5
  1158. },
  1159. header: {
  1160. 'content-type': 'application/json', // 默认值
  1161. 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  1162. },
  1163. success(res) {
  1164. console.log('res.data=====' + JSON.stringify(res.data));
  1165. },
  1166. });
  1167. },
  1168. status_curtain1(e) {
  1169. // 获取绑定的参数
  1170. var param1 = e.currentTarget.dataset.param1;
  1171. var param2 = e.currentTarget.dataset.param2;
  1172. var param3 = e.currentTarget.dataset.param3;
  1173. var param4 = e.currentTarget.dataset.param4;
  1174. var param5 = e.currentTarget.dataset.param5;
  1175. this.setData({
  1176. status_curtain: Number(param4)
  1177. })
  1178. wx.request({
  1179. url: `${homeApi_https}` + param1 + param2 + param3,
  1180. method: 'POST',
  1181. data: {
  1182. "entity_id": param5
  1183. },
  1184. header: {
  1185. 'content-type': 'application/json', // 默认值
  1186. 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  1187. },
  1188. success(res) {
  1189. console.log('res.data=====' + JSON.stringify(res.data));
  1190. },
  1191. });
  1192. },
  1193. status_door1(e) {
  1194. // 获取绑定的参数
  1195. var param1 = e.currentTarget.dataset.param1;
  1196. var param2 = e.currentTarget.dataset.param2;
  1197. var param3 = e.currentTarget.dataset.param3;
  1198. var param4 = e.currentTarget.dataset.param4;
  1199. var param5 = e.currentTarget.dataset.param5;
  1200. this.setData({
  1201. status_door: Number(param4)
  1202. })
  1203. wx.request({
  1204. url: `${homeApi_https}` + param1 + param2 + param3,
  1205. method: 'POST',
  1206. data: {
  1207. "entity_id": param5
  1208. },
  1209. header: {
  1210. 'content-type': 'application/json', // 默认值
  1211. 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  1212. },
  1213. success(res) {
  1214. console.log('res.data=====' + JSON.stringify(res.data));
  1215. },
  1216. });
  1217. },
  1218. onOpen_curtain() {
  1219. this.setData({ show_curtain: true });
  1220. },
  1221. onClose_curtain() {
  1222. this.setData({
  1223. show_curtain: false
  1224. })
  1225. },
  1226. onSelect_curtain(event) {
  1227. console.log(event.detail.id);
  1228. this.onCurtainChange(event.detail.id);
  1229. },
  1230. onOpen_san() {
  1231. this.setData({ show_san: true });
  1232. },
  1233. onClose_san() {
  1234. this.setData({
  1235. show_san: false
  1236. })
  1237. },
  1238. onSelect_san(event) {
  1239. console.log(event.detail.id);
  1240. this.onSanChange(event.detail.id);
  1241. },
  1242. onOpen_door() {
  1243. this.setData({ show_door: true });
  1244. },
  1245. onClose_door() {
  1246. this.setData({
  1247. show_door: false
  1248. })
  1249. },
  1250. onSelect_door(event) {
  1251. console.log(event.detail.id);
  1252. this.onDoorChange(event.detail.id);
  1253. },
  1254. initChartHumidifier(canvas, width, height, dpr) {
  1255. console.log("humidityValue=>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", humidityValue);
  1256. this.selectComponent('#mychart-dom-gauge').init((canvas, width, height, dpr) => {
  1257. // 获取组件的 canvas、width、height 后的回调函数
  1258. // 在这里初始化图表
  1259. const chart = echarts.init(canvas, null, {
  1260. width: width,
  1261. height: height,
  1262. devicePixelRatio: dpr // new
  1263. });
  1264. setOption(chart);
  1265. // 将图表实例绑定到 this 上,可以在其他成员函数(如 dispose)中访问
  1266. chartCircularProgressBar = chart;
  1267. this.setData({
  1268. isLoaded: true,
  1269. isDisposed: false
  1270. });
  1271. // 注意这里一定要返回 chart 实例,否则会影响事件处理等
  1272. return chart;
  1273. });
  1274. },
  1275. //设备控制函数 开始
  1276. onFireChange(event) {
  1277. var that = this;
  1278. console.log(event);
  1279. let sw = event;
  1280. that.setData({
  1281. status_led: sw
  1282. })
  1283. if (sw) {
  1284. that.data.client.publish(mpPubTopic_LED, '{"target":"LED","value":1}', function (err) {
  1285. if (!err) {
  1286. console.log("成功下发命令——打开客厅灯");
  1287. }
  1288. });
  1289. } else {
  1290. that.data.client.publish(mpPubTopic_LED, '{"target":"LED","value":0}', function (err) {
  1291. if (!err) {
  1292. console.log("成功下发命令——关闭客厅灯");
  1293. }
  1294. });
  1295. }
  1296. },
  1297. onLedChange(event) {
  1298. var that = this;
  1299. console.log(event);
  1300. let sw = event;
  1301. that.setData({
  1302. status_led: sw
  1303. })
  1304. if (sw) {
  1305. that.data.client.publish(mpPubTopic_LED, '{"target":"LED","value":1}', function (err) {
  1306. if (!err) {
  1307. console.log("成功下发命令——打开客厅灯");
  1308. }
  1309. });
  1310. } else {
  1311. that.data.client.publish(mpPubTopic_LED, '{"target":"LED","value":0}', function (err) {
  1312. if (!err) {
  1313. console.log("成功下发命令——关闭客厅灯");
  1314. }
  1315. });
  1316. }
  1317. },
  1318. onBeepChange(event, url, entity_id) {
  1319. var that = this;
  1320. console.log(event);
  1321. let sw = event;
  1322. that.setData({
  1323. status_beep: sw
  1324. })
  1325. console.log("event=" + event);
  1326. console.log("url=" + url);
  1327. console.log("entity_id=" + entity_id);
  1328. if (sw) {
  1329. // that.data.client.publish(mpPubTopic_BEEP, '{"target":"BEEP","value":1}', function (err) {
  1330. // if (!err) {
  1331. // console.log("成功下发命令——打开报警器");
  1332. // }
  1333. // });
  1334. this.onSelect_vangrid(url, entity_id);
  1335. } else {
  1336. // that.data.client.publish(mpPubTopic_BEEP, '{"target":"BEEP","value":0}', function (err) {
  1337. // if (!err) {
  1338. // console.log("成功下发命令——关闭报警器");
  1339. // }
  1340. // });
  1341. this.onSelect_vangrid(url, entity_id);
  1342. }
  1343. },
  1344. onCurtainChange(event) {
  1345. var that = this;
  1346. console.log(event);
  1347. let sw = event;
  1348. that.setData({
  1349. status_curtain: sw
  1350. })
  1351. if (sw) {
  1352. that.data.client.publish(mpPubTopic_CU, '{"target":"CU","value":1}', function (err) {
  1353. if (!err) {
  1354. console.log("成功下发命令——开窗帘");
  1355. }
  1356. });
  1357. } else {
  1358. that.data.client.publish(mpPubTopic_CU, '{"target":"CU","value":0}', function (err) {
  1359. if (!err) {
  1360. console.log("成功下发命令——关窗帘");
  1361. }
  1362. });
  1363. }
  1364. },
  1365. onSanChange(event) {
  1366. var that = this;
  1367. console.log(event);
  1368. let sw = event;
  1369. that.setData({
  1370. status_san: sw
  1371. })
  1372. if (sw) {
  1373. that.data.client.publish(mpPubTopic_SAN, '{"target":"SAN","value":1}', function (err) {
  1374. if (!err) {
  1375. console.log("成功下发命令——开风扇");
  1376. }
  1377. });
  1378. } else {
  1379. that.data.client.publish(mpPubTopic_SAN, '{"target":"SAN","value":0}', function (err) {
  1380. if (!err) {
  1381. console.log("成功下发命令——关风扇");
  1382. }
  1383. });
  1384. }
  1385. },
  1386. onDoorChange(event) {
  1387. var that = this;
  1388. console.log(event);
  1389. let sw = event;
  1390. that.setData({
  1391. status_door: sw
  1392. })
  1393. if (sw) {
  1394. that.data.client.publish(mpPubTopic_DO, '{"target":"DO","value":1}', function (err) {
  1395. if (!err) {
  1396. console.log("成功下发命令——开门");
  1397. }
  1398. });
  1399. } else {
  1400. that.data.client.publish(mpPubTopic_DO, '{"target":"DO","value":0}', function (err) {
  1401. if (!err) {
  1402. console.log("成功下发命令——关门");
  1403. }
  1404. });
  1405. }
  1406. },
  1407. onModeChange(event) {
  1408. var that = this;
  1409. console.log(event);
  1410. let sw = event.detail.value;
  1411. console.log(sw);
  1412. that.setData({
  1413. status_mode: sw
  1414. })
  1415. if (sw) {
  1416. that.data.client.publish(mpPubTopic_Mode, '{"target":"OUT","value":1}', function (err) {
  1417. if (!err) {
  1418. console.log("成功下发命令——离家模式");
  1419. }
  1420. });
  1421. } else {
  1422. that.data.client.publish(mpPubTopic_Mode, '{"target":"OUT","value":0}', function (err) {
  1423. if (!err) {
  1424. console.log("成功下发命令——居家模式");
  1425. }
  1426. });
  1427. }
  1428. },
  1429. getEntityState(list, entity_id) {
  1430. if (list == null) return null;
  1431. var obj = list.find(function (obj) {
  1432. return obj.entity_id === entity_id
  1433. })
  1434. console.log('getEntityState==' + obj ? (obj.state == 'on' ? 1 : 0) : null);
  1435. return obj ? (obj.state == 'on' ? 1 : 0) : null;
  1436. },
  1437. getEntityStateValue(list, entity_id) {
  1438. if (list == null) return null;
  1439. var obj = list.find(function (obj) {
  1440. return obj.entity_id === entity_id
  1441. })
  1442. console.log('getEntityStateValue==' + obj ? obj.state : null);
  1443. return obj ? obj.state : null;
  1444. },
  1445. //扫码
  1446. tapScan() {
  1447. wx.scanCode({
  1448. success: function (res) {
  1449. console.log('扫码获取的参数', res)
  1450. }
  1451. })
  1452. },
  1453. getSwitch(resData, that) {
  1454. try {
  1455. var listSwitchTemp = [];
  1456. var listAromatherapyMachineTemp = [];
  1457. var entityIdList = [];
  1458. const res = wx.getStorageSync('res');
  1459. const home_room = wx.getStorageSync('res').home_room;
  1460. for (let i = 0; i < resData.length; i++) {
  1461. if (resData[i].attributes && resData[i].attributes.home_room && resData[i].attributes.home_room.includes((entity))) {
  1462. entityIdList.push(resData[i].entity_id)
  1463. }
  1464. }
  1465. console.log('entityIdList=====' + JSON.stringify(entityIdList));
  1466. for (let i = 0; i < resData.length; i++) {
  1467. if ((resData[i].attributes && resData[i].attributes.home_room && resData[i].attributes.home_room.includes((entity)))
  1468. || (resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id))
  1469. ) {
  1470. var obj = {};
  1471. obj.entity_id = resData[i].entity_id;//实体ID
  1472. obj.parent_entity_id = resData[i].parent_entity_id;//父实体ID
  1473. //api/services/<domain>/<service>
  1474. if (resData[i].entity_id) {
  1475. obj.domain = resData[i].entity_id.split(".")[0];
  1476. }
  1477. obj.state = (resData[i].state == 'unknown' ? "未知" : resData[i].state);
  1478. if (resData[i].attributes && resData[i].attributes.friendly_name) {
  1479. obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name); //设备名称
  1480. }
  1481. if (resData[i].attributes && resData[i].attributes.home_room) {
  1482. obj.home_room = resData[i].attributes.home_room.split(' ')[1]; //房间号
  1483. }
  1484. if (
  1485. resData[i].state && resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList
  1486. && entityIdList.includes(resData[i].attributes.parent_entity_id)
  1487. ) {
  1488. if (resData[i].state == 'on') {
  1489. obj.service = 'turn_on';
  1490. } else if (resData[i].state == 'off') {
  1491. obj.service = 'turn_off';
  1492. }
  1493. //是否 是香薰机灯光
  1494. obj.isAromlight = obj.friendly_name.includes('香薰机灯光')
  1495. obj.isAromAtomization = obj.friendly_name.includes('香薰机雾化')
  1496. obj.isAromatherapy = obj.friendly_name.endsWith('香薰机') || obj.friendly_name.endsWith('香薰机开关')
  1497. if (obj.entity_id && obj.state && checkState(obj.state) && obj.friendly_name && obj.domain && !obj.isAromlight && !obj.isAromAtomization && !obj.isAromatherapy) {
  1498. if (!obj.friendly_name.endsWith("电视")) {
  1499. listSwitchTemp.push(obj)
  1500. }
  1501. } else if ((obj.isAromlight || obj.isAromAtomization || obj.isAromatherapy) && checkState(obj.state)) {
  1502. listAromatherapyMachineTemp.push(obj)
  1503. }
  1504. }
  1505. }
  1506. }
  1507. console.log('listSwitchTemp=' + JSON.stringify(listSwitchTemp));
  1508. listSwitchTemp = that.checkTVList(listSwitchTemp);
  1509. that.setData({
  1510. listSwitch: listSwitchTemp,
  1511. listAromatherapyMachine: listAromatherapyMachineTemp,
  1512. })
  1513. } catch (error) {
  1514. console.error(error);
  1515. }
  1516. },
  1517. //设备控制函数 结束
  1518. sliderChange(e) {
  1519. let list = this.data.listScroll;//这里是将需要循环的数组赋值给list
  1520. let indexS = Number(e.currentTarget.dataset.index);
  1521. let domain = e.currentTarget.dataset.domain;
  1522. let entity_id = e.currentTarget.dataset.id;
  1523. // 将本地缓存数据渲染到对应修改的案例
  1524. list.forEach(function (value, index, array) {
  1525. if (index == indexS) {
  1526. array[index].state = e.detail.value;
  1527. }
  1528. })
  1529. this.setData({
  1530. listScroll: list
  1531. })
  1532. let data = {
  1533. "entity_id": entity_id,
  1534. "value": e.detail.value,
  1535. }
  1536. this.getService("/services", "/" + domain, "/set_value", "POST", data);
  1537. // 设置两秒(2000毫秒)后的延迟
  1538. // setTimeout(() => {
  1539. // this.getMiotMediaPlayer(this);
  1540. // }, 2000);
  1541. },
  1542. onArrowUp(e) {
  1543. // 在这里处理向上箭头的点击事件
  1544. // 例如,你可以增加文本框的值
  1545. let currentValue = e.currentTarget.dataset.state;
  1546. let newValue = parseInt(currentValue) + 1; // 假设文本框中的是数字
  1547. // this.setData({
  1548. // inputValue: newValue.toString()
  1549. // });
  1550. let list = this.data.listUnit;//这里是将需要循环的数组赋值给list
  1551. let indexS = Number(e.currentTarget.dataset.index)
  1552. let domain = e.currentTarget.dataset.domain;
  1553. let entity_id = e.currentTarget.dataset.id;
  1554. // 将本地缓存数据渲染到对应修改的案例
  1555. list.forEach(function (value, index, array) {
  1556. if (index == indexS) {
  1557. array[index].state = newValue;
  1558. }
  1559. })
  1560. this.setData({
  1561. listUnit: list
  1562. })
  1563. let data = {
  1564. "entity_id": entity_id,
  1565. "value": newValue
  1566. }
  1567. this.getService("/services", "/" + domain, "/set_value", "POST", data);
  1568. },
  1569. // 加湿器
  1570. changeHumidity(e) {
  1571. let list = this.data.listHumidifier;//这里是将需要循环的数组赋值给list
  1572. let indexS = Number(e.currentTarget.dataset.index);
  1573. let domain = e.currentTarget.dataset.domain;
  1574. let entity_id = e.currentTarget.dataset.id;
  1575. // 将本地缓存数据渲染到对应修改的案例
  1576. list.forEach(function (value, index, array) {
  1577. if (index == indexS) {
  1578. array[index].humidity = e.detail;
  1579. }
  1580. })
  1581. this.setData({
  1582. listHumidifier: list
  1583. })
  1584. let data = {
  1585. "entity_id": entity_id,
  1586. "humidity": e.detail
  1587. }
  1588. this.getService("/services", "/" + domain, "/set_humidity", "POST", data);
  1589. },
  1590. //加湿器
  1591. onHumidifierDown(e) {
  1592. var that = this;
  1593. this.setData({
  1594. isClickedOnHumidifierDown: true
  1595. });
  1596. // 在这里处理向下箭头的点击事件
  1597. // 例如,你可以减少文本框的值
  1598. let currentValue = e.currentTarget.dataset.humidity;
  1599. let min = e.currentTarget.dataset.min;
  1600. let max = e.currentTarget.dataset.max;
  1601. let newValue = parseInt(currentValue) - 1; // 假设文本框中的是数字
  1602. if (newValue < min) {
  1603. newValue = min;
  1604. }
  1605. // this.setData({
  1606. // inputValue: newValue.toString()
  1607. // });
  1608. let list = this.data.listHumidifier;//这里是将需要循环的数组赋值给list
  1609. let indexS = Number(e.currentTarget.dataset.index)
  1610. let domain = e.currentTarget.dataset.domain;
  1611. let entity_id = e.currentTarget.dataset.id;
  1612. // 将本地缓存数据渲染到对应修改的案例
  1613. list.forEach(function (value, index, array) {
  1614. if (index == indexS) {
  1615. array[index].humidity = newValue;
  1616. }
  1617. })
  1618. this.setData({
  1619. listHumidifier: list,
  1620. // isButtonPressedHumidityDown:!that.data.isButtonPressedHumidityDown
  1621. })
  1622. let data = {
  1623. "entity_id": entity_id,
  1624. "humidity": newValue
  1625. }
  1626. this.getService("/services", "/" + domain, "/set_humidity", "POST", data);
  1627. },
  1628. //加湿器
  1629. onHumidifierUp(e) {
  1630. var that = this;
  1631. this.setData({
  1632. isClickedOnHumidifierUp: true
  1633. });
  1634. // 在这里处理向上箭头的点击事件
  1635. // 例如,你可以增加文本框的值
  1636. let currentValue = e.currentTarget.dataset.humidity || 0;
  1637. let min = e.currentTarget.dataset.min;
  1638. let max = e.currentTarget.dataset.max;
  1639. let newValue = parseInt(currentValue) + 1; // 假设文本框中的是数字
  1640. if (newValue > max) {
  1641. newValue = max;
  1642. }
  1643. // this.setData({
  1644. // inputValue: newValue.toString()
  1645. // });
  1646. let list = this.data.listHumidifier;//这里是将需要循环的数组赋值给list
  1647. let indexS = Number(e.currentTarget.dataset.index)
  1648. let domain = e.currentTarget.dataset.domain;
  1649. let entity_id = e.currentTarget.dataset.id;
  1650. // 将本地缓存数据渲染到对应修改的案例
  1651. list.forEach(function (value, index, array) {
  1652. if (index == indexS) {
  1653. array[index].humidity = newValue;
  1654. }
  1655. })
  1656. this.setData({
  1657. listHumidifier: list,
  1658. // isButtonPressedHumidityUp:!that.data.isButtonPressedHumidityUp
  1659. })
  1660. let data = {
  1661. "entity_id": entity_id,
  1662. "humidity": newValue
  1663. }
  1664. console.log(e.currentTarget.dataset);
  1665. this.getService("/services", "/" + domain, "/set_humidity", "POST", data);
  1666. },
  1667. //加湿器
  1668. onHumidifierOn(e) {
  1669. let domain = e.currentTarget.dataset.domain;
  1670. let entity_id = e.currentTarget.dataset.id;
  1671. let data = {
  1672. "entity_id": entity_id,
  1673. }
  1674. this.getService("/services", "/" + domain, "/turn_on", "POST", data);
  1675. },
  1676. //加湿器
  1677. onHumidifierOff(e) {
  1678. let domain = e.currentTarget.dataset.domain;
  1679. let entity_id = e.currentTarget.dataset.id;
  1680. let min = e.currentTarget.dataset.min;
  1681. let max = e.currentTarget.dataset.max;
  1682. let data = {
  1683. "entity_id": entity_id,
  1684. }
  1685. this.getService("/services", "/" + domain, "/turn_off", "POST", data);
  1686. },
  1687. // 拖动空调的值
  1688. dragClimate(e) {
  1689. var that = this;
  1690. let state = e.currentTarget.dataset.state;
  1691. console.log(e.detail.value);
  1692. if (state == "auto") {
  1693. return
  1694. }
  1695. let list = that.data.listClimate;//这里是将需要循环的数组赋值给list
  1696. let indexS = Number(e.currentTarget.dataset.index);
  1697. // 将本地缓存数据渲染到对应修改的案例
  1698. for (let i = 0; i < list.length; i++) {
  1699. var element = list[i];
  1700. if (i == indexS) {
  1701. element.temperatureTemp = e.detail.value;
  1702. break;
  1703. }
  1704. }
  1705. that.setData({
  1706. listClimate: list
  1707. })
  1708. console.log(list);
  1709. },
  1710. // 更改空调的值
  1711. changeClimate(e) {
  1712. var that = this;
  1713. let state = e.currentTarget.dataset.state;
  1714. if (state == "auto") {
  1715. return
  1716. }
  1717. this.setData({
  1718. isClickedOnClimateUp: true
  1719. });
  1720. console.log('that.data.climateMode==' + that.data.climateMode);
  1721. if (!that.data.climateMode) {
  1722. wx.showToast({
  1723. title: '请先选择模式',
  1724. icon: 'none'
  1725. });
  1726. return;
  1727. }
  1728. let currentValue = e.currentTarget.dataset.temperature;
  1729. let fanMode = e.currentTarget.dataset.fanMode;
  1730. let min = e.currentTarget.dataset.min;
  1731. let max = e.currentTarget.dataset.max;
  1732. let domain = e.currentTarget.dataset.domain;
  1733. let entity_id = e.currentTarget.dataset.id;
  1734. let data = {};
  1735. if (that.data.climateMode == 'heat' || that.data.climateMode == 'cool') {
  1736. let newValue = parseInt(currentValue) + 1; // 假设文本框中的是数字
  1737. if (newValue > max) newValue = max;
  1738. let list = this.data.listClimate;//这里是将需要循环的数组赋值给list
  1739. let indexS = Number(e.currentTarget.dataset.index);
  1740. // 将本地缓存数据渲染到对应修改的案例
  1741. list.forEach(function (value, index, array) {
  1742. if (index == indexS) {
  1743. array[index].temperature = e.detail;
  1744. }
  1745. })
  1746. this.setData({
  1747. listClimate: list
  1748. })
  1749. data = {
  1750. "entity_id": entity_id,
  1751. "temperature": e.detail,
  1752. "hvac_mode": that.data.climateMode
  1753. }
  1754. this.getService("/services", "/" + domain, "/set_temperature", "POST", data);
  1755. } else if (that.data.climateMode == 'dry') {
  1756. let newValue = parseInt(currentValue) + 1; // 假设文本框中的是数字
  1757. if (newValue > max) newValue = max;
  1758. data = {
  1759. "entity_id": entity_id,
  1760. "temperature": e.detail,
  1761. "hvac_mode": that.data.climateMode
  1762. }
  1763. this.getService("/services", "/" + domain, "/set_temperature", "POST", data);
  1764. } else if (that.data.climateMode == 'fan_only') {
  1765. let newValue = parseInt(currentValue) + 1; // 假设文本框中的是数字
  1766. if (newValue > max) newValue = max;
  1767. data = {
  1768. "entity_id": entity_id,
  1769. // "fan_mode":(fanMode=='Fan Speed Up')?'Fan Speed Down':'Fan Speed Up',
  1770. "temperature": e.detail,
  1771. "hvac_mode": that.data.climateMode
  1772. }
  1773. this.getService("/services", "/" + domain, "/set_temperature", "POST", data);
  1774. }
  1775. },
  1776. // 更改空调的值
  1777. minusClimate(e) {
  1778. var that = this;
  1779. let state = e.currentTarget.dataset.state;
  1780. if (state == "auto") {
  1781. return
  1782. }
  1783. this.setData({
  1784. isClickedOnClimateUp: true
  1785. });
  1786. console.log('that.data.climateMode==' + that.data.climateMode);
  1787. if (!that.data.climateMode) {
  1788. wx.showToast({
  1789. title: '请先选择模式',
  1790. icon: 'none'
  1791. });
  1792. return;
  1793. }
  1794. let currentValue = e.currentTarget.dataset.temperature;
  1795. let fanMode = e.currentTarget.dataset.fanMode;
  1796. let min = e.currentTarget.dataset.min;
  1797. let max = e.currentTarget.dataset.max;
  1798. let domain = e.currentTarget.dataset.domain;
  1799. let temperature = e.currentTarget.dataset.temperature - 1;
  1800. let entity_id = e.currentTarget.dataset.id;
  1801. let data = {};
  1802. if (that.data.climateMode == 'heat' || that.data.climateMode == 'cool') {
  1803. let newValue = parseInt(currentValue) + 1; // 假设文本框中的是数字
  1804. if (newValue > max) newValue = max;
  1805. let list = this.data.listClimate;//这里是将需要循环的数组赋值给list
  1806. let indexS = Number(e.currentTarget.dataset.index);
  1807. // 将本地缓存数据渲染到对应修改的案例
  1808. list.forEach(function (value, index, array) {
  1809. if (index == indexS) {
  1810. array[index].temperature = temperature;
  1811. }
  1812. })
  1813. this.setData({
  1814. listClimate: list
  1815. })
  1816. data = {
  1817. "entity_id": entity_id,
  1818. "temperature": temperature,
  1819. "hvac_mode": that.data.climateMode
  1820. }
  1821. this.getService("/services", "/" + domain, "/set_temperature", "POST", data);
  1822. } else if (that.data.climateMode == 'dry') {
  1823. let newValue = parseInt(currentValue) + 1; // 假设文本框中的是数字
  1824. if (newValue > max) newValue = max;
  1825. data = {
  1826. "entity_id": entity_id,
  1827. "temperature": temperature,
  1828. "hvac_mode": that.data.climateMode
  1829. }
  1830. this.getService("/services", "/" + domain, "/set_temperature", "POST", data);
  1831. } else if (that.data.climateMode == 'fan_only') {
  1832. let newValue = parseInt(currentValue) + 1; // 假设文本框中的是数字
  1833. if (newValue > max) newValue = max;
  1834. data = {
  1835. "entity_id": entity_id,
  1836. // "fan_mode":(fanMode=='Fan Speed Up')?'Fan Speed Down':'Fan Speed Up',
  1837. "temperature": temperature,
  1838. "hvac_mode": that.data.climateMode
  1839. }
  1840. this.getService("/services", "/" + domain, "/set_temperature", "POST", data);
  1841. }
  1842. },
  1843. // 更改空调的值
  1844. addClimate(e) {
  1845. var that = this;
  1846. let state = e.currentTarget.dataset.state;
  1847. if (state == "auto") {
  1848. return
  1849. }
  1850. this.setData({
  1851. isClickedOnClimateUp: true
  1852. });
  1853. console.log('that.data.climateMode==' + that.data.climateMode);
  1854. if (!that.data.climateMode) {
  1855. wx.showToast({
  1856. title: '请先选择模式',
  1857. icon: 'none'
  1858. });
  1859. return;
  1860. }
  1861. let currentValue = e.currentTarget.dataset.temperature;
  1862. let fanMode = e.currentTarget.dataset.fanMode;
  1863. let min = e.currentTarget.dataset.min;
  1864. let max = e.currentTarget.dataset.max;
  1865. let domain = e.currentTarget.dataset.domain;
  1866. let temperature = e.currentTarget.dataset.temperature + 1;
  1867. let entity_id = e.currentTarget.dataset.id;
  1868. let data = {};
  1869. if (that.data.climateMode == 'heat' || that.data.climateMode == 'cool') {
  1870. let newValue = parseInt(currentValue) + 1; // 假设文本框中的是数字
  1871. if (newValue > max) newValue = max;
  1872. let list = this.data.listClimate;//这里是将需要循环的数组赋值给list
  1873. let indexS = Number(e.currentTarget.dataset.index);
  1874. // 将本地缓存数据渲染到对应修改的案例
  1875. list.forEach(function (value, index, array) {
  1876. if (index == indexS) {
  1877. array[index].temperature = temperature;
  1878. }
  1879. })
  1880. this.setData({
  1881. listClimate: list
  1882. })
  1883. data = {
  1884. "entity_id": entity_id,
  1885. "temperature": temperature,
  1886. "hvac_mode": that.data.climateMode
  1887. }
  1888. this.getService("/services", "/" + domain, "/set_temperature", "POST", data);
  1889. } else if (that.data.climateMode == 'dry') {
  1890. let newValue = parseInt(currentValue) + 1; // 假设文本框中的是数字
  1891. if (newValue > max) newValue = max;
  1892. data = {
  1893. "entity_id": entity_id,
  1894. "temperature": temperature,
  1895. "hvac_mode": that.data.climateMode
  1896. }
  1897. this.getService("/services", "/" + domain, "/set_temperature", "POST", data);
  1898. } else if (that.data.climateMode == 'fan_only') {
  1899. let newValue = parseInt(currentValue) + 1; // 假设文本框中的是数字
  1900. if (newValue > max) newValue = max;
  1901. data = {
  1902. "entity_id": entity_id,
  1903. // "fan_mode":(fanMode=='Fan Speed Up')?'Fan Speed Down':'Fan Speed Up',
  1904. "temperature": temperature,
  1905. "hvac_mode": that.data.climateMode
  1906. }
  1907. this.getService("/services", "/" + domain, "/set_temperature", "POST", data);
  1908. }
  1909. },
  1910. onClimateDown(e) {
  1911. var that = this;
  1912. if (!that.data.climateMode) {
  1913. wx.showToast({
  1914. title: '请先选择模式',
  1915. icon: 'none'
  1916. });
  1917. return;
  1918. }
  1919. console.log('that.data.climateMode==' + that.data.climateMode);
  1920. let currentValue = e.currentTarget.dataset.temperature;
  1921. let fanMode = e.currentTarget.dataset.fanMode;
  1922. // let list = this.data.listClimate;
  1923. // this.setData({
  1924. // inputValue: newValue.toString()
  1925. // });
  1926. let domain = e.currentTarget.dataset.domain;
  1927. let entity_id = e.currentTarget.dataset.id;
  1928. let min = e.currentTarget.dataset.min;
  1929. let max = e.currentTarget.dataset.max;
  1930. // this.setData({
  1931. // isButtonPressedClimateDown: !that.data.isButtonPressedClimateDown
  1932. // })
  1933. // 将本地缓存数据渲染到对应修改的案例
  1934. // list.forEach(function (value,index, array){
  1935. // if (index == indexS) {
  1936. // array[index].temperature = newValue;
  1937. // }
  1938. // })
  1939. // this.setData({
  1940. // listClimate: list
  1941. // })
  1942. let data = {};
  1943. if (that.data.climateMode == 'heat' || that.data.climateMode == 'cool') {
  1944. let newValue = parseInt(currentValue) - 1; // 假设文本框中的是数字
  1945. if (newValue < min) newValue = min;
  1946. let list = this.data.listClimate;//这里是将需要循环的数组赋值给list
  1947. let indexS = Number(e.currentTarget.dataset.index);
  1948. // 将本地缓存数据渲染到对应修改的案例
  1949. list.forEach(function (value, index, array) {
  1950. if (index == indexS) {
  1951. array[index].temperature = newValue;
  1952. }
  1953. })
  1954. this.setData({
  1955. listClimate: list
  1956. })
  1957. console.log('onClimateDown-entity_id=' + entity_id);
  1958. data = {
  1959. "entity_id": entity_id,
  1960. "temperature": newValue,
  1961. "hvac_mode": that.data.climateMode
  1962. }
  1963. this.getService("/services", "/" + domain, "/set_temperature", "POST", data);
  1964. } else if (that.data.climateMode == 'dry') {
  1965. let newValue = parseInt(currentValue) - 1; // 假设文本框中的是数字
  1966. if (newValue < min) newValue = min;
  1967. data = {
  1968. "entity_id": entity_id,
  1969. "temperature": newValue,
  1970. "hvac_mode": that.data.climateMode
  1971. }
  1972. this.getService("/services", "/" + domain, "/set_temperature", "POST", data);
  1973. } else if (that.data.climateMode == 'fan_only') {
  1974. let newValue = parseInt(currentValue) - 1; // 假设文本框中的是数字
  1975. if (newValue < min) newValue = min;
  1976. data = {
  1977. "entity_id": entity_id,
  1978. // "fan_mode":(fanMode=='Fan Speed Up')?'Fan Speed Down':'Fan Speed Up',
  1979. "temperature": newValue,
  1980. "hvac_mode": that.data.climateMode
  1981. }
  1982. this.getService("/services", "/" + domain, "/set_temperature", "POST", data);
  1983. }
  1984. },
  1985. onClimateUp(e) {
  1986. var that = this;
  1987. this.setData({
  1988. isClickedOnClimateUp: true
  1989. });
  1990. console.log('that.data.climateMode==' + that.data.climateMode);
  1991. if (!that.data.climateMode) {
  1992. wx.showToast({
  1993. title: '请先选择模式',
  1994. icon: 'none'
  1995. });
  1996. return;
  1997. }
  1998. let currentValue = e.currentTarget.dataset.temperature;
  1999. let fanMode = e.currentTarget.dataset.fanMode;
  2000. let min = e.currentTarget.dataset.min;
  2001. let max = e.currentTarget.dataset.max;
  2002. // this.setData({
  2003. // inputValue: newValue.toString()
  2004. // });
  2005. // let list = this.data.listClimate;//这里是将需要循环的数组赋值给list
  2006. // let indexS = Number(e.currentTarget.dataset.index)
  2007. let domain = e.currentTarget.dataset.domain;
  2008. let entity_id = e.currentTarget.dataset.id;
  2009. // this.setData({
  2010. // isButtonPressedClimateUp: !that.data.isButtonPressedClimateUp
  2011. // })
  2012. // 将本地缓存数据渲染到对应修改的案例
  2013. // list.forEach(function (value,index, array){
  2014. // if (index == indexS) {
  2015. // array[index].temperature = newValue;
  2016. // }
  2017. // })
  2018. // this.setData({
  2019. // listClimate: list
  2020. // })
  2021. let data = {};
  2022. if (that.data.climateMode == 'heat' || that.data.climateMode == 'cool') {
  2023. let newValue = parseInt(currentValue) + 1; // 假设文本框中的是数字
  2024. if (newValue > max) newValue = max;
  2025. let list = this.data.listClimate;//这里是将需要循环的数组赋值给list
  2026. let indexS = Number(e.currentTarget.dataset.index);
  2027. // 将本地缓存数据渲染到对应修改的案例
  2028. list.forEach(function (value, index, array) {
  2029. if (index == indexS) {
  2030. array[index].temperature = newValue;
  2031. }
  2032. })
  2033. this.setData({
  2034. listClimate: list
  2035. })
  2036. data = {
  2037. "entity_id": entity_id,
  2038. "temperature": newValue,
  2039. "hvac_mode": that.data.climateMode
  2040. }
  2041. this.getService("/services", "/" + domain, "/set_temperature", "POST", data);
  2042. } else if (that.data.climateMode == 'dry') {
  2043. let newValue = parseInt(currentValue) + 1; // 假设文本框中的是数字
  2044. if (newValue > max) newValue = max;
  2045. data = {
  2046. "entity_id": entity_id,
  2047. "temperature": newValue,
  2048. "hvac_mode": that.data.climateMode
  2049. }
  2050. this.getService("/services", "/" + domain, "/set_temperature", "POST", data);
  2051. } else if (that.data.climateMode == 'fan_only') {
  2052. let newValue = parseInt(currentValue) + 1; // 假设文本框中的是数字
  2053. if (newValue > max) newValue = max;
  2054. data = {
  2055. "entity_id": entity_id,
  2056. // "fan_mode":(fanMode=='Fan Speed Up')?'Fan Speed Down':'Fan Speed Up',
  2057. "temperature": newValue,
  2058. "hvac_mode": that.data.climateMode
  2059. }
  2060. this.getService("/services", "/" + domain, "/set_temperature", "POST", data);
  2061. }
  2062. },
  2063. onClimateAuto(e) {
  2064. this.setData({
  2065. isClickedOnClimateAuto: true
  2066. });
  2067. let domain = e.currentTarget.dataset.domain;
  2068. let entity_id = e.currentTarget.dataset.id;
  2069. let list = this.data.listClimate;//这里是将需要循环的数组赋值给list
  2070. let indexS = Number(e.currentTarget.dataset.index);
  2071. // 将本地缓存数据渲染到对应修改的案例
  2072. list.forEach(function (value, index, array) {
  2073. if (index == indexS) {
  2074. array[index].state = newValue;
  2075. }
  2076. })
  2077. this.setData({
  2078. temperatureHumidifyName: '自动',
  2079. climateMode: 'auto',
  2080. listClimate: list
  2081. })
  2082. let data = {
  2083. "entity_id": entity_id,
  2084. "hvac_mode": 'auto',
  2085. }
  2086. this.getService("/services", "/" + domain, "/set_hvac_mode", "POST", data);
  2087. },
  2088. onClimateHeat(e) {
  2089. let domain = e.currentTarget.dataset.domain;
  2090. let entity_id = e.currentTarget.dataset.id;
  2091. let list = this.data.listClimate;//这里是将需要循环的数组赋值给list
  2092. let indexS = Number(e.currentTarget.dataset.index);
  2093. // 将本地缓存数据渲染到对应修改的案例
  2094. list.forEach(function (value, index, array) {
  2095. if (index == indexS) {
  2096. array[index].state = newValue;
  2097. }
  2098. })
  2099. this.setData({
  2100. temperatureHumidifyName: '制热',
  2101. climateMode: 'heat',
  2102. listClimate: list
  2103. })
  2104. let data = {
  2105. "entity_id": entity_id,
  2106. "hvac_mode": 'heat',
  2107. }
  2108. this.getService("/services", "/" + domain, "/set_hvac_mode", "POST", data);
  2109. },
  2110. onClimateCool(e) {
  2111. let domain = e.currentTarget.dataset.domain;
  2112. let entity_id = e.currentTarget.dataset.id;
  2113. let list = this.data.listClimate;//这里是将需要循环的数组赋值给list
  2114. let indexS = Number(e.currentTarget.dataset.index);
  2115. // 将本地缓存数据渲染到对应修改的案例
  2116. list.forEach(function (value, index, array) {
  2117. if (index == indexS) {
  2118. array[index].state = newValue;
  2119. }
  2120. })
  2121. this.setData({
  2122. temperatureHumidifyName: '制冷',
  2123. climateMode: 'cool',
  2124. listClimate: list
  2125. })
  2126. let data = {
  2127. "entity_id": entity_id,
  2128. "hvac_mode": 'cool',
  2129. }
  2130. this.getService("/services", "/" + domain, "/set_hvac_mode", "POST", data);
  2131. },
  2132. onClimateDehumidify(e) {
  2133. let domain = e.currentTarget.dataset.domain;
  2134. let entity_id = e.currentTarget.dataset.id;
  2135. let list = this.data.listClimate;//这里是将需要循环的数组赋值给list
  2136. let indexS = Number(e.currentTarget.dataset.index);
  2137. // 将本地缓存数据渲染到对应修改的案例
  2138. list.forEach(function (value, index, array) {
  2139. if (index == indexS) {
  2140. array[index].state = newValue;
  2141. }
  2142. })
  2143. this.setData({
  2144. temperatureHumidifyName: '除湿',
  2145. climateMode: 'dry',
  2146. listClimate: list
  2147. })
  2148. let data = {
  2149. "entity_id": entity_id,
  2150. "hvac_mode": 'dry',
  2151. }
  2152. this.getService("/services", "/" + domain, "/set_hvac_mode", "POST", data);
  2153. },
  2154. onClimateAirSupply(e) {
  2155. let domain = e.currentTarget.dataset.domain;
  2156. let entity_id = e.currentTarget.dataset.id;
  2157. let list = this.data.listClimate;//这里是将需要循环的数组赋值给list
  2158. let indexS = Number(e.currentTarget.dataset.index);
  2159. // 将本地缓存数据渲染到对应修改的案例
  2160. list.forEach(function (value, index, array) {
  2161. if (index == indexS) {
  2162. array[index].state = newValue;
  2163. }
  2164. })
  2165. this.setData({
  2166. temperatureHumidifyName: '送风',
  2167. climateMode: 'fan_only',
  2168. listClimate: list
  2169. })
  2170. let data = {
  2171. "entity_id": entity_id,
  2172. "hvac_mode": 'fan_only',
  2173. }
  2174. this.getService("/services", "/" + domain, "/set_hvac_mode", "POST", data);
  2175. },
  2176. onClimateOff(e) {
  2177. let state = e.currentTarget.dataset.state;
  2178. if (state == 'off') {
  2179. // 如果是关闭的就开成自动
  2180. this.onClimateAuto(e);
  2181. return
  2182. }
  2183. let domain = e.currentTarget.dataset.domain;
  2184. let entity_id = e.currentTarget.dataset.id;
  2185. let list = this.data.listClimate;//这里是将需要循环的数组赋值给list
  2186. let indexS = Number(e.currentTarget.dataset.index);
  2187. // 将本地缓存数据渲染到对应修改的案例
  2188. list.forEach(function (value, index, array) {
  2189. if (index == indexS) {
  2190. array[index].state = newValue;
  2191. }
  2192. })
  2193. this.setData({
  2194. temperatureHumidifyName: '关闭',
  2195. climateMode: 'off',
  2196. listClimate: list
  2197. })
  2198. let data = {
  2199. "entity_id": entity_id,
  2200. }
  2201. this.getService("/services", "/" + domain, "/turn_off", "POST", data);
  2202. },
  2203. handleInput: function (e) {
  2204. // 这里你需要自己实现歌曲列表和切换逻辑
  2205. // 例如,如果你有一个歌曲列表,你可以通过修改当前播放歌曲的索引来切换歌曲
  2206. // 假设你有一个歌曲列表`songs`和一个当前歌曲索引`currentIndex`
  2207. // if (this.data.currentIndex > 0) {
  2208. // this.data.currentIndex--;
  2209. // // 加载新歌曲并播放
  2210. // this.loadAndPlaySong(this.data.currentIndex);
  2211. // }
  2212. let min = e.currentTarget.dataset.min;
  2213. let max = e.currentTarget.dataset.max;
  2214. if (e.detail.value && (e.detail.value.length > max || e.detail.value.length < min)) {
  2215. wx.showModal({
  2216. title: '提示',
  2217. content: '文本长度介于' + min + '~' + max + '长度之间',
  2218. showCancel: false
  2219. });
  2220. return;
  2221. }
  2222. let domain = e.currentTarget.dataset.domain;
  2223. let entity_id = e.currentTarget.dataset.id;
  2224. let data = {
  2225. "entity_id": entity_id,
  2226. "value": e.detail.value,
  2227. }
  2228. this.getService("/services", "/" + domain, "/set_value", "POST", data);
  2229. },
  2230. onArrowDown(e) {
  2231. // 在这里处理向下箭头的点击事件
  2232. // 例如,你可以减少文本框的值
  2233. let currentValue = e.currentTarget.dataset.state;
  2234. let newValue = parseInt(currentValue) - 1; // 假设文本框中的是数字
  2235. // this.setData({
  2236. // inputValue: newValue.toString()
  2237. // });
  2238. let list = this.data.listUnit;//这里是将需要循环的数组赋值给list
  2239. let indexS = Number(e.currentTarget.dataset.index)
  2240. let domain = e.currentTarget.dataset.domain;
  2241. let entity_id = e.currentTarget.dataset.id;
  2242. // 将本地缓存数据渲染到对应修改的案例
  2243. list.forEach(function (value, index, array) {
  2244. if (index == indexS) {
  2245. array[index].state = newValue;
  2246. }
  2247. })
  2248. this.setData({
  2249. listUnit: list
  2250. })
  2251. let data = {
  2252. "entity_id": entity_id,
  2253. "value": newValue
  2254. }
  2255. this.getService("/services", "/" + domain, "/set_value", "POST", data);
  2256. },
  2257. prevSong: function (e) {
  2258. // 这里你需要自己实现歌曲列表和切换逻辑
  2259. // 例如,如果你有一个歌曲列表,你可以通过修改当前播放歌曲的索引来切换歌曲
  2260. // 假设你有一个歌曲列表`songs`和一个当前歌曲索引`currentIndex`
  2261. // if (this.data.currentIndex > 0) {
  2262. // this.data.currentIndex--;
  2263. // // 加载新歌曲并播放
  2264. // this.loadAndPlaySong(this.data.currentIndex);
  2265. // }
  2266. this.setData({
  2267. isClickedPrevSong: true
  2268. });
  2269. let domain = e.currentTarget.dataset.domain;
  2270. let entity_id = e.currentTarget.dataset.id;
  2271. let data = {
  2272. "entity_id": entity_id,
  2273. }
  2274. this.getService("/services", "/" + domain, "/media_previous_track", "POST", data);
  2275. // setTimeout(() => {
  2276. // this.getMiotMediaPlayer(this);
  2277. // }, 8000);
  2278. },
  2279. tvTurnOn: function (e) {
  2280. let domain = e.currentTarget.dataset.domain;
  2281. let entity_id = e.currentTarget.dataset.id;
  2282. let data = {
  2283. "entity_id": entity_id,
  2284. }
  2285. this.getService("/services", "/" + domain, "/turn_on", "POST", data);
  2286. },
  2287. tvTurnOff: function (e) {
  2288. let domain = e.currentTarget.dataset.domain;
  2289. let entity_id = e.currentTarget.dataset.id;
  2290. let data = {
  2291. "entity_id": entity_id,
  2292. }
  2293. this.getService("/services", "/" + domain, "/turn_off", "POST", data);
  2294. },
  2295. // 切换播放/暂停
  2296. togglePlayPause: function (e) {
  2297. // console.log("this.data.isPlaying="+this.data.isPlaying);
  2298. // if (this.data.isPlaying) {
  2299. // this.innerAudioContext.pause();
  2300. // this.setData({ isPlaying: false });
  2301. // this.getService("/services","/"+domain,"/media_pause","POST",null);
  2302. // } else {
  2303. // this.innerAudioContext.play();
  2304. // this.setData({ isPlaying: true });
  2305. // this.getService("/services","/"+domain,"/media_play","POST",null);
  2306. // }
  2307. // let list = this.data.listMiotMediaPlayer;//这里是将需要循环的数组赋值给list
  2308. this.setData({
  2309. isClickedTogglePlayPause: true
  2310. });
  2311. let indexS = Number(e.currentTarget.dataset.index)
  2312. let domain = e.currentTarget.dataset.domain;
  2313. let entity_id = e.currentTarget.dataset.id;
  2314. let state = e.currentTarget.dataset.state;
  2315. // 将本地缓存数据渲染到对应修改的案例
  2316. // list.forEach(function (value,index, array){
  2317. // if (index == indexS) {
  2318. // array[index].state = (state=='playing'?'idle':'playing');
  2319. // }
  2320. // })
  2321. // this.setData({
  2322. // listMiotMediaPlayer: list
  2323. // })
  2324. let data = {
  2325. "entity_id": entity_id,
  2326. }
  2327. this.getService("/services", "/" + domain, "/media_play_pause", "POST", data);
  2328. // 设置两秒(2000毫秒)后的延迟
  2329. // setTimeout(() => {
  2330. // this.getMiotMediaPlayer(this);
  2331. // }, 8000);
  2332. },
  2333. // 切换下一首歌曲
  2334. nextSong: function (e) {
  2335. // 和prevSong类似,你需要实现歌曲列表和切换逻辑
  2336. // 假设歌曲列表为`songs`,当前歌曲索引为`currentIndex`
  2337. // if (this.data.currentIndex < songs.length - 1) {
  2338. // this.data.currentIndex++;
  2339. // // 加载新歌曲并播放
  2340. // this.loadAndPlaySong(this.data.currentIndex);
  2341. // }
  2342. this.setData({
  2343. isClickedNextSong: true
  2344. });
  2345. let domain = e.currentTarget.dataset.domain;
  2346. let entity_id = e.currentTarget.dataset.id;
  2347. let data = {
  2348. "entity_id": entity_id,
  2349. }
  2350. this.getService("/services", "/" + domain, "/media_next_track", "POST", data);
  2351. // setTimeout(() => {
  2352. // this.getMiotMediaPlayer(this);
  2353. // }, 8000);
  2354. },
  2355. // 加载并播放指定索引的歌曲
  2356. loadAndPlaySong: function (index) {
  2357. // 假设你有一个歌曲列表`songs`,每个歌曲对象有`url`属性表示音频链接
  2358. const song = songs[index];
  2359. this.innerAudioContext.src = song.url;
  2360. this.innerAudioContext.play();
  2361. // 更新当前播放的歌曲信息(例如标题和艺术家)
  2362. this.setData({
  2363. currentSongTitle: song.title,
  2364. currentSongArtist: song.artist
  2365. });
  2366. },
  2367. base64Decode: function (input) {
  2368. const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  2369. let str = '';
  2370. let output = '';
  2371. let chr1, chr2, chr3;
  2372. let enc1, enc2, enc3, enc4;
  2373. let i = 0;
  2374. input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
  2375. while (i < input.length) {
  2376. enc1 = chars.indexOf(input.charAt(i++));
  2377. enc2 = chars.indexOf(input.charAt(i++));
  2378. enc3 = chars.indexOf(input.charAt(i++));
  2379. enc4 = chars.indexOf(input.charAt(i++));
  2380. chr1 = (enc1 << 2) | (enc2 >> 4);
  2381. chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
  2382. chr3 = ((enc3 & 3) << 6) | enc4;
  2383. str += String.fromCharCode(chr1);
  2384. if (enc3 != 64) {
  2385. str += String.fromCharCode(chr2);
  2386. }
  2387. if (enc4 != 64) {
  2388. str += String.fromCharCode(chr3);
  2389. }
  2390. }
  2391. return str;
  2392. },
  2393. onPickerChange: function (e) {
  2394. // this.setData({
  2395. // selectedIndex: e.detail.value
  2396. // });
  2397. // // 可以在这里处理选中值的变化,比如发送请求等
  2398. // console.log('选中的值是:', this.data.options[e.detail.value].value);
  2399. let list = this.data.listSelect;//这里是将需要循环的数组赋值给list
  2400. let indexS = Number(e.currentTarget.dataset.index)
  2401. let domain = e.currentTarget.dataset.domain;
  2402. let entity_id = e.currentTarget.dataset.id;
  2403. // 将本地缓存数据渲染到对应修改的案例
  2404. list.forEach(function (value, index, array) {
  2405. if (index == indexS) {
  2406. array[index].selectedIndex = e.detail.value;
  2407. }
  2408. })
  2409. this.setData({
  2410. listSelect: list
  2411. })
  2412. let data = {
  2413. "entity_id": entity_id,
  2414. "option": e.detail.value,
  2415. }
  2416. this.getService("/services", "/" + domain, "/select_option", "POST", data);
  2417. },
  2418. getService(services, domain, service, method, data) {
  2419. wx.request({
  2420. url: `${homeApi_https}` + services + domain + service,
  2421. method: method,
  2422. data: data,
  2423. header: {
  2424. 'content-type': 'application/json', // 默认值
  2425. 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  2426. },
  2427. success(res) {
  2428. console.log('res.data=====' + JSON.stringify(res.data));
  2429. },
  2430. });
  2431. },
  2432. // 初始化时调用即可
  2433. showCanvasRing() {
  2434. try {
  2435. //作画
  2436. var ctx = wx.createCanvasContext("circleBar", this); //canvas组建封装,需要后加个this
  2437. ctx.clearRect(0, 0, this.data.canvasWidth, this.data.canvasHeight); // 清除画布
  2438. var circle_r = this.data.canvasWidth / 2 - 10; //画布的一半,用来找中心点和半径
  2439. var scoreText = this.data.value; // 当前得分
  2440. var total = this.data.total;// 总分值
  2441. var score = (100 * scoreText) / total; // 满分为100时对应的值
  2442. let that = this;
  2443. //定义起始点
  2444. ctx.translate(this.data.canvasWidth / 2, this.data.canvasWidth / 2 + 5);
  2445. // 白边圆弧
  2446. ctx.beginPath();
  2447. ctx.setStrokeStyle("#FFFFFF");
  2448. ctx.setLineWidth(16);
  2449. ctx.setLineCap("round");
  2450. ctx.arc(0, 0, circle_r - 15, 1 * Math.PI, 0, false);
  2451. ctx.stroke();
  2452. ctx.closePath();
  2453. //灰色圆弧
  2454. ctx.beginPath();
  2455. ctx.setStrokeStyle("#D6E4FF");
  2456. ctx.setLineWidth(12);
  2457. ctx.setLineCap("round"); //线条结束端点样式 butt 平直 round 圆形 square 正方形
  2458. ctx.arc(0, 0, circle_r - 15, 1 * Math.PI, 0, false);
  2459. ctx.stroke();
  2460. ctx.closePath();
  2461. // 蓝色圆弧
  2462. ctx.beginPath();
  2463. ctx.setStrokeStyle("#3366FF");
  2464. ctx.setLineWidth(16);
  2465. ctx.arc(
  2466. 0,
  2467. 0,
  2468. circle_r - 15,
  2469. 1 * Math.PI,
  2470. (score / 100 + 1) * Math.PI,
  2471. false
  2472. );
  2473. ctx.stroke();
  2474. ctx.closePath();
  2475. // 指示器-外层
  2476. let deg = 270 - score * 1.8;
  2477. const xAxis = Math.sin(((2 * Math.PI) / 360) * deg) * (circle_r - 15);
  2478. const yAxis = Math.cos(((2 * Math.PI) / 360) * deg) * (circle_r - 15);
  2479. ctx.beginPath();
  2480. ctx.arc(xAxis, yAxis, 11, 0, 2 * Math.PI);
  2481. ctx.setFillStyle("#FFFFFF");
  2482. ctx.fill();
  2483. // 指示器-内层
  2484. const xAxis2 = Math.sin(((2 * Math.PI) / 360) * deg) * (circle_r - 15);
  2485. const yAxis2 = Math.cos(((2 * Math.PI) / 360) * deg) * (circle_r - 15); // circle_r - 10
  2486. ctx.beginPath();
  2487. ctx.arc(xAxis2, yAxis2, 6, 0, 2 * Math.PI);
  2488. ctx.setFillStyle("#3366FF");
  2489. ctx.fill();
  2490. // 文字-总得分
  2491. ctx.setTextAlign("center"); // 字体位置
  2492. ctx.setFillStyle("#333333");
  2493. ctx.font = "normal normal 16px Arial,sans-serif";
  2494. ctx.fillText("总得分", 0, -30);
  2495. // 文字-具体分数
  2496. ctx.setTextAlign("center"); // 字体位置
  2497. ctx.setFillStyle("#000000");
  2498. ctx.font = "normal bold 36px Arial,sans-serif";
  2499. ctx.fillText(scoreText, 0, 13);
  2500. // 最低分
  2501. ctx.setFillStyle("#666666");
  2502. ctx.font = "normal normal 13px Arial,sans-serif";
  2503. ctx.fillText(0, -circle_r + 10, 25);
  2504. // 最高分
  2505. ctx.setFillStyle("#666666");
  2506. ctx.font = "normal normal 13px Arial,sans-serif";
  2507. ctx.fillText(total, circle_r - 15, 25);
  2508. // 绘图
  2509. ctx.draw(false, function () {
  2510. //将生成好的图片保存到本地
  2511. wx.canvasToTempFilePath(
  2512. {
  2513. canvasId: "circleBar",
  2514. success: function (res) {
  2515. var tempFilePath = res.tempFilePath;
  2516. that.setData({
  2517. loadImagePath: tempFilePath,
  2518. });
  2519. },
  2520. fail: function (res) { },
  2521. },
  2522. );
  2523. });
  2524. } catch (error) {
  2525. }
  2526. },
  2527. getHAData(that, hotelcode, roomcode) {
  2528. let start = Date.now(); // 获取当前时间(毫秒)
  2529. // console.log('start=='+start);
  2530. wx.request({
  2531. url: `${aipushApi}/getha`, //
  2532. method: 'POST',
  2533. // header: {
  2534. // 'content-type': 'application/json', // 默认值
  2535. // 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  2536. // },
  2537. data: {
  2538. "locations": hotelcode, "room": (hotelcode && hotelcode.includes('hotel')) ? roomcode : "", "token": token_push
  2539. },
  2540. success(ress) {
  2541. if (!ress || !ress.data) {
  2542. console.error("getha(),没有获取到数据");
  2543. return;
  2544. }
  2545. var resData = ress.data
  2546. console.log("resData-==" + JSON.stringify(resData));
  2547. console.log("resData.loc-==" + JSON.stringify(resData.loc));
  2548. homeApi_https = resData.loc + "/api";
  2549. homeApiLater_https = resData.loc;
  2550. token = resData.token;
  2551. // console.log('res.data='+JSON.stringify(resData));
  2552. if (ress.data.code == "400") {
  2553. console.error("400错误!");
  2554. return;
  2555. }
  2556. if (ress.data.code == "401") {
  2557. console.error("401错误!");
  2558. return;
  2559. }
  2560. try {
  2561. //获取HA 设备状态数据
  2562. // wx.request({
  2563. // url: `${homeApi_https}/states`, //获取空气数据
  2564. // method: 'GET',
  2565. // header: {
  2566. // 'content-type': 'application/json', // 默认值
  2567. // 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  2568. // },
  2569. // success(res) {
  2570. // if(!res || !res.data){
  2571. // return;
  2572. // }
  2573. // var resData = res.data
  2574. // // console.log('res.data='+JSON.stringify(resData));
  2575. // if (res.data.code == "400") {
  2576. // console.error("400错误!");
  2577. // return;
  2578. // }
  2579. // if (res.data.code == "401") {
  2580. // console.error("401错误 --- 请检查你的API或Key是否正确!");
  2581. // return;
  2582. // }
  2583. // try {
  2584. // const {
  2585. // now
  2586. // } = res.data;
  2587. // console.log('res.data1='+JSON.stringify(resData));
  2588. // res.data.find(function (obj) {
  2589. // console.log('obj='+obj);
  2590. // })
  2591. // res.data.forEach((item, index) => {
  2592. // console.log(index, item);
  2593. // });
  2594. var listCoverTemp = [];
  2595. var listSwitchTemp = [];
  2596. var listScrollTemp = [];
  2597. var listUnitTemp = [];
  2598. var listConversationTemp = [];
  2599. var listConversation1Temp = [];
  2600. var listHumidityTemp = [];
  2601. var listButtonTemp = [];
  2602. var listSelectTemp = [];
  2603. var listClimateTemp = [];
  2604. var listMiotMediaPlayerTemp = [];
  2605. var listMitvMediaPlayerTemp = [];
  2606. var listHumidifierTemp = [];
  2607. var listSensorTemp = [];
  2608. var listTextTemp = [];
  2609. var tvEntityIdTemp = '';
  2610. var tvEntityIdsTemp = [];
  2611. var listAromatherapyMachineTemp = [];
  2612. var modelList1 = [];
  2613. var modelList2 = [];
  2614. var modelList3 = [];
  2615. var climateModeTemp = '';
  2616. var temperatureHumidifyNameTemp = '温度';
  2617. var humidityValueTemp = 0;
  2618. var humidityMaxTemp = 0;
  2619. var humidityMinTemp = 0;
  2620. var entityIdList = [];
  2621. const res = wx.getStorageSync('res');
  2622. const home_room = wx.getStorageSync('res').home_room;
  2623. // console.log('entity=====@==='+entity);
  2624. wx.request({
  2625. url: `${homeApi_https}/aidsleep/entity`, //获取空气数据
  2626. method: 'POST',
  2627. header: {
  2628. 'content-type': 'application/json', // 默认值
  2629. 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  2630. },
  2631. //
  2632. data: {
  2633. "template": "{{ label_entities('" + (entity) + "') }}"
  2634. },
  2635. success(resTemplate) {
  2636. let mid = Date.now(); // 再次获取当前时间(毫秒)
  2637. // console.log('mid=='+mid);
  2638. if (!resTemplate || !resTemplate.data) {
  2639. console.log('no data:' + mid);
  2640. return;
  2641. }
  2642. let resData = resTemplate.data;
  2643. // resData = resData.filter(item1 => {
  2644. // return JSON.parse(that.replaceAll(resTemplate.data,'\'','\"')).find(item2 => item2 === item1.entity_id) !== undefined;
  2645. // });
  2646. // console.log('entityIdList-resTemplate====='+JSON.stringify(resTemplate.data));
  2647. for (let i = 0; i < resData.length; i++) {
  2648. // if(resTemplate.data.includes(resData[i].entity_id) && that.checkFuzzyMatch(resData[i])){
  2649. var obj = {};
  2650. obj.entity_id = resData[i].entity_id;//实体ID
  2651. obj.parent_entity_id = resData[i].parent_entity_id;//父实体ID
  2652. //api/services/<domain>/<service>
  2653. if (resData[i].entity_id) {
  2654. obj.domain = resData[i].entity_id.split(".")[0];
  2655. }
  2656. obj.state = (resData[i].state == 'unknown' ? "未知" : resData[i].state);
  2657. if (resData[i].attributes && resData[i].attributes.friendly_name) {
  2658. obj.friendly_name = resData[i].attributes.friendly_name; //设备名称
  2659. if (obj.friendly_name.includes("灯带") || obj.friendly_name.includes("吸顶灯")) {
  2660. obj.imgSrc = '/static/icons/ic_dd_1.svg';
  2661. obj.selectedImgSrc = '/static/icons/ic_dd_2.svg';
  2662. obj.bg = 'background: linear-gradient(180deg, #DFFFFB 0%, #FFFFFF 53%)';
  2663. } else if (obj.friendly_name.includes("走廊灯")) {
  2664. obj.imgSrc = '/static/icons/ic_zld_1.svg';
  2665. obj.selectedImgSrc = '/static/icons/ic_zld_2.svg';
  2666. obj.bg = 'background: linear-gradient(180deg, #FFEEFA 0%, #FFFFFF 50%)';
  2667. } else if (obj.friendly_name.includes("筒灯")) {
  2668. obj.imgSrc = '/static/icons/ic_td_1.svg';
  2669. obj.selectedImgSrc = '/static/icons/ic_td_2.svg';
  2670. obj.bg = 'background: linear-gradient(180deg, #EBF0FF 0%, #FFFFFF 50%)';
  2671. } else if (obj.friendly_name.includes("主灯")) {
  2672. obj.imgSrc = '/static/icons/ic_zd_1.svg';
  2673. obj.selectedImgSrc = '/static/icons/ic_zd_2.svg';
  2674. obj.bg = 'background: linear-gradient(180deg, #EFE7FF 0%, #FFFFFF 50%)';
  2675. } else if (obj.friendly_name.includes("气扇")) {
  2676. obj.imgSrc = '/static/icons/ic_pqs_1.svg';
  2677. obj.selectedImgSrc = '/static/icons/ic_pqs_2.svg';
  2678. obj.bg = 'background: linear-gradient(180deg, #E3FFE6 0%, #FFFFFF 53%)';
  2679. } else if (obj.friendly_name.includes("电视")) {
  2680. obj.imgSrc = '/static/icons/ic_ds_1.svg';
  2681. obj.selectedImgSrc = '/static/icons/ic_ds_1.svg';
  2682. obj.bg = 'background: linear-gradient(180deg, #FFF2DF 0%, #FFFFFF 53%)';
  2683. } else if (obj.friendly_name.includes("空气净化器")) {
  2684. obj.imgSrc = '/static/icons/ic_kqjhq_1.svg';
  2685. obj.selectedImgSrc = '/static/icons/ic_kqjhq_2.svg';
  2686. obj.bg = 'background: linear-gradient(180deg, #EBFAFF 0%, #FFFFFF 50%)';
  2687. } else if (obj.friendly_name.includes("香薰机雾化")) {
  2688. obj.imgSrc = '/static/icons/ic_xxjwh.svg';
  2689. obj.selectedImgSrc = '/static/icons/ic_xxjwh.svg';
  2690. } else if (obj.friendly_name.endsWith('香薰机') || obj.friendly_name.endsWith('香薰机开关')) {
  2691. obj.imgSrc = '/static/icons/ic_xxj.svg';
  2692. obj.selectedImgSrc = '/static/icons/ic_xxj.svg';
  2693. } else if (obj.friendly_name.includes("灯")) {
  2694. obj.imgSrc = '/static/icons/ic_dd_1.svg';
  2695. obj.selectedImgSrc = '/static/icons/ic_dd_2.svg';
  2696. obj.bg = 'background: linear-gradient(180deg, #DFFFFB 0%, #FFFFFF 53%)';
  2697. } else {
  2698. obj.imgSrc = '/static/icons/ic_ds_1.svg';
  2699. obj.selectedImgSrc = '/static/icons/ic_ds_1.svg';
  2700. obj.bg = 'background: linear-gradient(180deg, #FFF2DF 0%, #FFFFFF 53%)';
  2701. }
  2702. }
  2703. if (resData[i].attributes && resData[i].attributes.home_room) {
  2704. obj.home_room = resData[i].attributes.home_room.split(' ')[1]; //房间号
  2705. }
  2706. if (resData[i].state && that.checkFuzzyMatch(resData[i])
  2707. ) {
  2708. if (resData[i].state == 'on') {
  2709. obj.service = 'turn_on';
  2710. } else if (resData[i].state == 'off') {
  2711. obj.service = 'turn_off';
  2712. }
  2713. //截取字符串,防止开关设备名称过长
  2714. obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name, roomcode);
  2715. //是否 是香薰机灯光
  2716. obj.isAromlight = obj.friendly_name.includes('香薰机灯光')
  2717. obj.isAromAtomization = obj.friendly_name.includes('香薰机雾化')
  2718. obj.isAromatherapy = obj.friendly_name.endsWith('香薰机') || obj.friendly_name.endsWith('香薰机开关')
  2719. if (obj.entity_id && obj.state && checkState(obj.state) && obj.friendly_name && obj.domain && obj.domain != 'automation' && !obj.isAromlight && !obj.isAromAtomization && !obj.isAromatherapy) {
  2720. if (!obj.friendly_name.endsWith("电视")) {
  2721. listSwitchTemp.push(obj)
  2722. }
  2723. } else if ((obj.isAromlight || obj.isAromAtomization || obj.isAromatherapy) && checkState(obj.state)) {
  2724. listAromatherapyMachineTemp.push(obj)
  2725. }
  2726. }
  2727. if ((resData[i].state && obj.domain && obj.domain == 'cover') && that.checkFuzzyMatch(resData[i])
  2728. ) {
  2729. obj.current_position = resData[i].attributes.current_position;
  2730. obj.target_position = resData[i].attributes.target_position;
  2731. obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name, roomcode);
  2732. if (obj.entity_id && obj.state && checkState(obj.state) && obj.friendly_name && obj.domain) {
  2733. listCoverTemp.push(obj)
  2734. }
  2735. }
  2736. // if((resData[i].state && obj.domain && obj.domain=='number')||
  2737. // (resData[i].state && obj.domain && obj.domain=='number' && resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id)
  2738. // )
  2739. // ){
  2740. // obj.min = resData[i].attributes.min;
  2741. // obj.max = resData[i].attributes.max;
  2742. // obj.step = resData[i].attributes.step;
  2743. // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
  2744. // if(resData[i].state!='unknown'){
  2745. // obj.unit_of_measurement = resData[i].attributes.unit_of_measurement;
  2746. // }
  2747. // if((resData[i].attributes.min || resData[i].attributes.max) && resData[i].attributes.unit_of_measurement!='rgb' && resData[i].attributes.unit_of_measurement!='minutes'){
  2748. // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
  2749. // listScrollTemp.push(obj);
  2750. // }
  2751. // }else if((resData[i].attributes.min || resData[i].attributes.max) && (resData[i].attributes.unit_of_measurement=='rgb' || resData[i].attributes.unit_of_measurement=='minutes')){
  2752. // if(resData[i].state!='unknown'){
  2753. // obj.unit_of_measurement = resData[i].attributes.unit_of_measurement;
  2754. // }
  2755. // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
  2756. // listUnitTemp.push(obj);
  2757. // }
  2758. // }
  2759. // }
  2760. // if((resData[i].state && obj.domain && obj.domain=='button')||
  2761. // (resData[i].state && obj.domain && obj.domain=='button' && resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id)
  2762. // )
  2763. // ){
  2764. // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
  2765. // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
  2766. // listButtonTemp.push(obj);
  2767. // }
  2768. // }
  2769. // if((resData[i].state && obj.domain && obj.domain=='select')||
  2770. // (resData[i].state && obj.domain && obj.domain=='select' && resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id)
  2771. // )
  2772. // ){
  2773. // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
  2774. // obj.options = resData[i].attributes.options;
  2775. // obj.selectedIndex = 0;
  2776. // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
  2777. // listSelectTemp.push(obj);
  2778. // }
  2779. // }
  2780. if ((resData[i].state && obj.domain && obj.domain == 'climate' && resData[i].attributes.entity_class == 'MiirClimateEntity')
  2781. ) {
  2782. climateModeTemp = obj.state;
  2783. obj.temperature = resData[i].attributes.temperature;
  2784. obj.temperatureTemp = resData[i].attributes.temperature;
  2785. obj.min_temp = resData[i].attributes.min_temp;
  2786. obj.max_temp = resData[i].attributes.max_temp;
  2787. obj.hvac_modes = resData[i].attributes.hvac_modes;
  2788. obj.fan_modes = resData[i].attributes.fan_modes;
  2789. obj.fan_mode = resData[i].attributes.fan_mode;
  2790. obj.target_temp_step = resData[i].attributes.target_temp_step;
  2791. if (obj.state == 'auto') {
  2792. temperatureHumidifyNameTemp = '自动';
  2793. }
  2794. if (obj.state == 'heat') {
  2795. temperatureHumidifyNameTemp = '制热';
  2796. }
  2797. if (obj.state == 'cool') {
  2798. temperatureHumidifyNameTemp = '制冷';
  2799. }
  2800. if (obj.state == 'dry') {
  2801. temperatureHumidifyNameTemp = '除湿';
  2802. }
  2803. if (obj.state == 'fan_only') {
  2804. temperatureHumidifyNameTemp = '送风';
  2805. }
  2806. if (obj.state == 'off') {
  2807. temperatureHumidifyNameTemp = '关闭';
  2808. }
  2809. if (obj.entity_id && obj.state && obj.friendly_name && obj.domain) {
  2810. listClimateTemp.push(obj);
  2811. }
  2812. }
  2813. if ((resData[i].state && obj.domain && obj.domain == 'media_player' && resData[i].attributes.entity_class == 'MiotMediaPlayerEntity') && that.checkFuzzyMatch(resData[i])
  2814. ) {
  2815. // obj["speaker.volume"] = resData[i].attribute["speaker.volume"];
  2816. obj.repeat = resData[i].attributes.repeat;
  2817. obj.entity_picture = resData[i].attributes.entity_picture ? "background-image: url('" + `${homeApiLater_https}` + resData[i].attributes.entity_picture + "');width: 100%; height: 100%;background-size: cover;background-repeat: no-repeat;background-position: center;" : "background: radial-gradient(circle at center, #ff0000, #0000ff);border-radius: 30rpx;";
  2818. obj.media_title = resData[i].attributes.media_title;
  2819. obj.media_artist = resData[i].attributes.media_artist;
  2820. obj.volume_level = resData[i].attributes.volume_level ? (resData[i].attributes.volume_level * 100) : 0;
  2821. obj.media_duration = resData[i].attributes.media_duration;
  2822. obj.media_position = resData[i].attributes.media_position;
  2823. obj.media_late = resData[i].attributes.media_position + '/' + resData[i].attributes.media_duration;
  2824. // obj.microphone.mute = resData[i].attributes.microphone.mute;
  2825. // obj.speaker.mute = resData[i].attributes.speaker.mute;
  2826. // console.log('media-player-miot-obj=='+obj);
  2827. if (obj.entity_id && obj.state && checkState(obj.state) && obj.friendly_name && obj.domain) {
  2828. listMiotMediaPlayerTemp.push(obj);
  2829. }
  2830. }
  2831. // if((resData[i].state && obj.domain && obj.domain=='media_player' && resData[i].attributes.entity_class=='MitvMediaPlayerEntity')||
  2832. // (resData[i].state && obj.domain && obj.domain=='media_player' && resData[i].attributes.entity_class=='MitvMediaPlayerEntity' && resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id)
  2833. // )
  2834. // ){
  2835. // obj.volume_level = resData[i].attributes.volume_level;
  2836. // obj.is_volume_muted = resData[i].attributes.is_volume_muted;
  2837. // obj.source = resData[i].attributes.source;
  2838. // obj.entity_picture = resData[i].attributes.entity_picture?"background-image: url('"+`${homeApiLater_https}`+resData[i].attributes.entity_picture+"');width: 100%; height: 100%;background-size: cover;background-repeat: no-repeat;background-position: center;":"background: radial-gradient(circle at center, #ff0000, #0000ff);border-radius: 30rpx;";
  2839. // obj.media_title = resData[i].attributes.media_title;
  2840. // obj.media_artist = resData[i].attributes.media_artist;
  2841. // obj.volume_level = resData[i].attributes.volume_level?(resData[i].attributes.volume_level * 100):0;
  2842. // obj.media_duration = resData[i].attributes.media_duration;
  2843. // obj.media_position = resData[i].attributes.media_position;
  2844. // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
  2845. // listMitvMediaPlayerTemp.push(obj);
  2846. // }
  2847. // }
  2848. if ((resData[i].state && obj.domain && obj.domain == 'media_player') && that.checkFuzzyMatch(resData[i])
  2849. ) {
  2850. obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name, roomcode);
  2851. if (obj.entity_id.includes('teevee') || (obj.entity_id.includes('media_player') && obj.entity_id.includes('tv_dlna_') && obj.friendly_name && obj.friendly_name.includes('电视'))) {
  2852. obj.volume_level = resData[i].attributes.volume_level;
  2853. obj.is_volume_muted = resData[i].attributes.is_volume_muted;
  2854. obj.source = resData[i].attributes.source;
  2855. obj.entity_picture = resData[i].attributes.entity_picture ? "background-image: url('" + `${homeApiLater_https}` + resData[i].attributes.entity_picture + "');width: 100%; height: 100%;background-size: cover;background-repeat: no-repeat;background-position: center;" : "background: radial-gradient(circle at center, #ff0000, #0000ff);border-radius: 30rpx;";
  2856. obj.media_title = resData[i].attributes.media_title;
  2857. obj.media_artist = resData[i].attributes.media_artist;
  2858. obj.volume_level = resData[i].attributes.volume_level ? (resData[i].attributes.volume_level * 100) : 0;
  2859. obj.media_duration = resData[i].attributes.media_duration;
  2860. obj.media_position = resData[i].attributes.media_position;
  2861. obj.media_late = resData[i].attributes.media_position + '/' + resData[i].attributes.media_duration;
  2862. // obj["speaker.volume"] = resData[i].attributes["speaker.volume"];
  2863. // console.log('media-player-mitv-obj=='+obj);
  2864. obj.device_class = resData[i].attributes.device_class;
  2865. obj.app_id = resData[i].attributes.app_id;
  2866. obj.app_name = resData[i].attributes.app_name;
  2867. if (obj.entity_id && obj.state && checkState(obj.state) && obj.friendly_name && obj.domain) {
  2868. listMitvMediaPlayerTemp.push(obj);
  2869. }
  2870. obj.friendly_name1 = resData[i].attributes.friendly_name;
  2871. tvEntityIdsTemp.push(obj);
  2872. // let obj1 = {};
  2873. // obj1.entity_id = obj.entity_id;
  2874. // obj1.friendly_name1 = resData[i].attributes.friendly_name;
  2875. // tvEntityIdsTemp.push(obj1);
  2876. tvEntityIdTemp = obj.entity_id;
  2877. // console.log('obj===='+obj);
  2878. // console.log('tvEntityIdTemp='+tvEntityIdTemp);
  2879. wx.setStorageSync('tvEntityId', tvEntityIdTemp);
  2880. }
  2881. }
  2882. if ((resData[i].state && obj.domain && obj.domain == 'humidifier')
  2883. ) {
  2884. // 加湿器
  2885. obj.min_humidity = resData[i].attributes.min_humidity;
  2886. obj.max_humidity = resData[i].attributes.max_humidity;
  2887. obj.humidity = resData[i].attributes.humidity;
  2888. obj.min = obj.min_humidity;
  2889. obj.max = obj.max_humidity;
  2890. humidityValueTemp = obj.humidity;
  2891. humidityMaxTemp = obj.max;
  2892. humidityMinTemp = obj.min;
  2893. // console.log('humidifier-obj=='+JSON.stringify(obj));
  2894. if (obj.entity_id && obj.state && checkState(obj.state) && obj.friendly_name && obj.domain) {
  2895. listHumidifierTemp.push(obj);
  2896. }
  2897. }
  2898. if ((resData[i].state && obj.domain && obj.domain == 'automation')) {
  2899. console.log("", resData[i].attributes.friendly_name);
  2900. if (resData[i].attributes.friendly_name.endsWith('起床模式')) {
  2901. modelList1.push(obj)
  2902. } else if (resData[i].attributes.friendly_name.endsWith('观影模式')) {
  2903. modelList2.push(obj)
  2904. } else if (resData[i].attributes.friendly_name.endsWith('睡眠模式')) {
  2905. modelList3.push(obj)
  2906. }
  2907. }
  2908. // if((resData[i].state && obj.domain && obj.domain=='sensor')||
  2909. // (resData[i].state && obj.domain && obj.domain=='sensor' && resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id)
  2910. // )
  2911. // ){
  2912. // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
  2913. // obj.unit_of_measurement = resData[i].attributes.unit_of_measurement;
  2914. // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
  2915. // listSensorTemp.push(obj);
  2916. // }
  2917. // }
  2918. // if((resData[i].state && obj.domain && obj.domain=='text')||
  2919. // (resData[i].state && obj.domain && obj.domain=='text' && resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id)
  2920. // )
  2921. // ){
  2922. // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
  2923. // obj.min = resData[i].attributes.min;
  2924. // obj.max = resData[i].attributes.max;
  2925. // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
  2926. // listTextTemp.push(obj);
  2927. // }
  2928. // }
  2929. // if((resData[i].state && obj.friendly_name && obj.friendly_name.includes("智能音箱"))
  2930. // || (resData[i].state && resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id)
  2931. // && obj.friendly_name && obj.friendly_name.includes("智能音箱"))
  2932. // ){
  2933. // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
  2934. // listConversationTemp.push(obj)
  2935. // }
  2936. // }
  2937. // if((resData[i].state && resData[i].attributes && resData[i].attributes.speaker && resData[i].attributes.speaker.volume && obj.friendly_name && obj.friendly_name.includes("智能音箱"))||
  2938. // (resData[i].state && resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id)
  2939. // && resData[i].attributes.speaker && resData[i].attributes.speaker.volume && obj.friendly_name && obj.friendly_name.includes("智能音箱"))
  2940. // ){
  2941. // obj.volume = resData[i].attributes.speaker.volume;//音量
  2942. // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
  2943. // listConversation1Temp.push(obj)
  2944. // }
  2945. // }
  2946. //加湿器单独拿出来
  2947. // if((obj.friendly_name && obj.friendly_name.includes("加湿器"))||
  2948. // (resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id)
  2949. // && obj.friendly_name && obj.friendly_name.includes("加湿器"))
  2950. // ){
  2951. // listHumidityTemp.push(obj)
  2952. // }
  2953. // }
  2954. }
  2955. listSwitchTemp = that.checkTVList(listSwitchTemp);
  2956. that.setData({
  2957. // status_beep: that.getEntityState(res.data,'switch.xiaomi_pro3_02bd_left_switch_service'), //实验室主灯
  2958. // status_led: that.getEntityState(res.data,'light.deerma_jsq2g_392f_indicator_light'), //加湿器 Indicator Light
  2959. // status_san: that.getEntityState(res.data,'switch.xwhzp_xwxfj_a441_diffuser'), //香薰机 Diffuser
  2960. // status_curtain: that.getEntityState(res.data,'switch.xiaomi_pro3_02bd_middle_switch_service'), //实验室侧灯
  2961. // status_door: that.getEntityState(res.data,'remote.xiaomi_lx06_f593_wifispeaker_4'), //智能音箱
  2962. // Temp: that.getEntityStateValue(res.data,'sensor.deerma_jsq2g_392f_temperature'), //加湿器温度
  2963. // Humi: that.getEntityStateValue(res.data,'sensor.deerma_jsq2g_392f_relative_humidity'), //加湿器湿度
  2964. // Light: that.getEntityStateValue(res.data,'number.xwhzp_xwxfj_a441_brightness'), //香薰机亮度
  2965. // LiquidLevel: that.getEntityStateValue(res.data,'sensor.xwhzp_xwxfj_a441_fragrance_liquid_left_level'), //香薰液浓度
  2966. modelList1,
  2967. modelList2,
  2968. modelList3,
  2969. listSwitch: listSwitchTemp,
  2970. listUnit: listUnitTemp,
  2971. listScroll: listScrollTemp,
  2972. listConversation: listConversationTemp,
  2973. listConversation1: listConversation1Temp,
  2974. listHumidity: listHumidityTemp,
  2975. listButton: listButtonTemp,
  2976. listSelect: listSelectTemp,
  2977. listClimate: listClimateTemp,
  2978. listMiotMediaPlayer: listMiotMediaPlayerTemp,
  2979. listMitvMediaPlayer: listMitvMediaPlayerTemp,
  2980. listHumidifier: listHumidifierTemp,
  2981. listSensor: listSensorTemp,
  2982. listText: listTextTemp,
  2983. tvEntityId: tvEntityIdTemp,
  2984. tvEntityIds: tvEntityIdsTemp,
  2985. climateMode: climateModeTemp,
  2986. temperatureHumidifyName: temperatureHumidifyNameTemp,
  2987. listCover: listCoverTemp,
  2988. listAromatherapyMachine: listAromatherapyMachineTemp,
  2989. // ecHumidifier: {
  2990. // onInit: that.initChartHumidifier
  2991. // },
  2992. sliderValueHumidifier: ''
  2993. })
  2994. if (listHumidifierTemp.length && humidityValue != humidityValueTemp) {
  2995. humidityValue = humidityValueTemp || 40;
  2996. humidityMin = humidityMinTemp;
  2997. humidityMax = humidityMaxTemp;
  2998. that.checkHumidityMarginLeft()
  2999. updateChartCircularProgressBarOption()
  3000. }
  3001. wx.setStorageSync('tvEntityIds', tvEntityIdsTemp);
  3002. // console.log('listMiotMediaPlayerTemp='+JSON.stringify(listMiotMediaPlayerTemp));
  3003. // console.log('listHumidityTemp='+JSON.stringify(listHumidityTemp));
  3004. // console.log('listClimateTemp='+JSON.stringify(listClimateTemp));
  3005. // console.log('listSwitchTemp='+JSON.stringify(listSwitchTemp));
  3006. console.log('tvEntityIdsTemp=' + JSON.stringify(tvEntityIdsTemp));
  3007. // console.log('listMitvMediaPlayerTemp='+JSON.stringify(listMitvMediaPlayerTemp));
  3008. console.log('listHumidifierTemp=' + JSON.stringify(listHumidifierTemp));
  3009. },
  3010. });
  3011. // } catch (error) {
  3012. // console.error(error);
  3013. // }
  3014. // },
  3015. // });
  3016. } catch (error) {
  3017. console.error(error);
  3018. }
  3019. },
  3020. fail: function (error) {
  3021. console.error('error', error);
  3022. that.setData({
  3023. isLoading: false,
  3024. });
  3025. }
  3026. });
  3027. let end = Date.now(); // 再次获取当前时间(毫秒)
  3028. // console.log('end=='+end);
  3029. let executionTime = end - start;
  3030. // console.log(`myFunctionToTest 执行时间为: ${executionTime} 毫秒`);
  3031. return true;
  3032. },
  3033. getHADataStart(that, hotelcode, roomcode) {
  3034. let start = Date.now(); // 获取当前时间(毫秒)
  3035. console.log('start==' + start);
  3036. var that = this;
  3037. wx.request({
  3038. url: `${aipushApi}/getha`, //
  3039. method: 'POST',
  3040. // header: {
  3041. // 'content-type': 'application/json', // 默认值
  3042. // 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  3043. // },
  3044. data: {
  3045. "locations": hotelcode, "room": (hotelcode && hotelcode.includes('hotel')) ? roomcode : "", "token": token_push
  3046. },
  3047. success(ress) {
  3048. if (!ress || !ress.data) {
  3049. console.error("getha(),没有获取到数据");
  3050. return;
  3051. }
  3052. var resData = ress.data
  3053. console.log("resData-==" + JSON.stringify(resData));
  3054. console.log("resData.loc-==" + JSON.stringify(resData.loc));
  3055. homeApi_https = resData.loc + "/api";
  3056. homeApiLater_https = resData.loc;
  3057. token = resData.token;
  3058. // console.log('res.data='+JSON.stringify(resData));
  3059. if (ress.data.code == "400") {
  3060. console.error("400错误!");
  3061. return;
  3062. }
  3063. if (ress.data.code == "401") {
  3064. console.error("401错误!");
  3065. return;
  3066. }
  3067. try {
  3068. //获取HA 设备状态数据
  3069. // wx.request({
  3070. // url: `${homeApi_https}/states`,
  3071. // method: 'GET',
  3072. // header: {
  3073. // 'content-type': 'application/json', // 默认值
  3074. // 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  3075. // },
  3076. // success(res) {
  3077. // if(!res || !res.data){
  3078. // that.setData({
  3079. // isLoading: false,
  3080. // });
  3081. // return;
  3082. // }
  3083. // var resData = res.data
  3084. // // console.log('res.data='+JSON.stringify(resData));
  3085. // if (res.data.code == "400") {
  3086. // console.error("400错误!");
  3087. // return;
  3088. // }
  3089. // if (res.data.code == "401") {
  3090. // console.error("401错误 --- 请检查你的API或Key是否正确!");
  3091. // return;
  3092. // }
  3093. // try {
  3094. // const {
  3095. // now
  3096. // } = res.data;
  3097. // console.log('res.data1='+JSON.stringify(resData));
  3098. // res.data.find(function (obj) {
  3099. // console.log('obj='+obj);
  3100. // })
  3101. // res.data.forEach((item, index) => {
  3102. // console.log(index, item);
  3103. // });
  3104. var listCoverTemp = [];
  3105. var listSwitchTemp = [];
  3106. var listScrollTemp = [];
  3107. var listUnitTemp = [];
  3108. var listConversationTemp = [];
  3109. var listConversation1Temp = [];
  3110. var listHumidityTemp = [];
  3111. var listButtonTemp = [];
  3112. var listSelectTemp = [];
  3113. var listClimateTemp = [];
  3114. var listMiotMediaPlayerTemp = [];
  3115. var listMitvMediaPlayerTemp = [];
  3116. var listHumidifierTemp = [];
  3117. var listSensorTemp = [];
  3118. var listTextTemp = [];
  3119. var tvEntityIdTemp = '';
  3120. var tvEntityIdsTemp = [];
  3121. var listAromatherapyMachineTemp = [];
  3122. var humidityValueTemp = 0;
  3123. var humidityMaxTemp = 0;
  3124. var humidityMinTemp = 0;
  3125. var climateModeTemp = '';
  3126. var temperatureHumidifyNameTemp = '温度';
  3127. var modelList1 = [];
  3128. var modelList2 = [];
  3129. var modelList3 = [];
  3130. var entityIdList = [];
  3131. const res = wx.getStorageSync('res');
  3132. const home_room = wx.getStorageSync('res').home_room;
  3133. // console.log('entity=====@==='+entity);
  3134. wx.request({
  3135. url: `${homeApi_https}/aidsleep/entity`, //获取空气数据
  3136. method: 'POST',
  3137. header: {
  3138. 'content-type': 'application/json', // 默认值
  3139. 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  3140. },
  3141. //
  3142. data: {
  3143. "template": "{{ label_entities('" + (entity) + "') }}"
  3144. },
  3145. success(resTemplate) {
  3146. let mid = Date.now(); // 再次获取当前时间(毫秒)
  3147. // console.log('mid=='+mid);
  3148. if (!resTemplate || !resTemplate.data) {
  3149. console.log('no data:' + mid);
  3150. return;
  3151. }
  3152. let resData = resTemplate.data;
  3153. // resData = resData.filter(item1 => {
  3154. // return JSON.parse(that.replaceAll(resTemplate.data,'\'','\"')).find(item2 => item2 === item1.entity_id) !== undefined;
  3155. // });
  3156. console.log("resData-union=" + JSON.stringify(resData));
  3157. // console.log('entityIdList-resTemplate====='+JSON.stringify(resTemplate.data));
  3158. for (let i = 0; i < resData.length; i++) {
  3159. // if(resTemplate.data.includes(resData[i].entity_id) && that.checkFuzzyMatch(resData[i])){
  3160. var obj = {};
  3161. obj.entity_id = resData[i].entity_id;//实体ID
  3162. obj.parent_entity_id = resData[i].parent_entity_id;//父实体ID
  3163. //api/services/<domain>/<service>
  3164. if (resData[i].entity_id) {
  3165. obj.domain = resData[i].entity_id.split(".")[0];
  3166. }
  3167. obj.state = (resData[i].state == 'unknown' ? "未知" : resData[i].state);
  3168. if (resData[i].attributes && resData[i].attributes.friendly_name) {
  3169. obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name, roomcode); //设备名称
  3170. if (obj.friendly_name.includes("灯带") || obj.friendly_name.includes("吸顶灯")) {
  3171. obj.imgSrc = '/static/icons/ic_dd_1.svg';
  3172. obj.selectedImgSrc = '/static/icons/ic_dd_2.svg';
  3173. obj.bg = 'background: linear-gradient(180deg, #DFFFFB 0%, #FFFFFF 53%)';
  3174. } else if (obj.friendly_name.includes("走廊灯")) {
  3175. obj.imgSrc = '/static/icons/ic_zld_1.svg';
  3176. obj.selectedImgSrc = '/static/icons/ic_zld_2.svg';
  3177. obj.bg = 'background: linear-gradient(180deg, #FFEEFA 0%, #FFFFFF 50%)';
  3178. } else if (obj.friendly_name.includes("筒灯")) {
  3179. obj.imgSrc = '/static/icons/ic_td_1.svg';
  3180. obj.selectedImgSrc = '/static/icons/ic_td_2.svg';
  3181. obj.bg = 'background: linear-gradient(180deg, #EBF0FF 0%, #FFFFFF 50%)';
  3182. } else if (obj.friendly_name.includes("主灯")) {
  3183. obj.imgSrc = '/static/icons/ic_zd_1.svg';
  3184. obj.selectedImgSrc = '/static/icons/ic_zd_2.svg';
  3185. obj.bg = 'background: linear-gradient(180deg, #EFE7FF 0%, #FFFFFF 50%)';
  3186. } else if (obj.friendly_name.includes("气扇")) {
  3187. obj.imgSrc = '/static/icons/ic_pqs_1.svg';
  3188. obj.selectedImgSrc = '/static/icons/ic_pqs_2.svg';
  3189. obj.bg = 'background: linear-gradient(180deg, #E3FFE6 0%, #FFFFFF 53%)';
  3190. } else if (obj.friendly_name.includes("电视")) {
  3191. obj.imgSrc = '/static/icons/ic_ds_1.svg';
  3192. obj.selectedImgSrc = '/static/icons/ic_ds_1.svg';
  3193. obj.bg = 'background: linear-gradient(180deg, #FFF2DF 0%, #FFFFFF 53%)';
  3194. } else if (obj.friendly_name.includes("空气净化器")) {
  3195. obj.imgSrc = '/static/icons/ic_kqjhq_1.svg';
  3196. obj.selectedImgSrc = '/static/icons/ic_kqjhq_2.svg';
  3197. obj.bg = 'background: linear-gradient(180deg, #EBFAFF 0%, #FFFFFF 50%)';
  3198. } else if (obj.friendly_name.includes("香薰机雾化")) {
  3199. obj.imgSrc = '/static/icons/ic_xxjwh.svg';
  3200. obj.selectedImgSrc = '/static/icons/ic_xxjwh.svg';
  3201. } else if (obj.friendly_name.endsWith('香薰机') || obj.friendly_name.endsWith('香薰机开关')) {
  3202. obj.imgSrc = '/static/icons/ic_xxj.svg';
  3203. obj.selectedImgSrc = '/static/icons/ic_xxj.svg';
  3204. }
  3205. else if (obj.friendly_name.includes("灯")) {
  3206. obj.imgSrc = '/static/icons/ic_dd_1.svg';
  3207. obj.selectedImgSrc = '/static/icons/ic_dd_2.svg';
  3208. obj.bg = 'background: linear-gradient(180deg, #DFFFFB 0%, #FFFFFF 53%)';
  3209. }
  3210. else {
  3211. obj.imgSrc = '/static/icons/ic_ds_1.svg';
  3212. obj.selectedImgSrc = '/static/icons/ic_ds_1.svg';
  3213. obj.bg = 'background: linear-gradient(180deg, #FFF2DF 0%, #FFFFFF 53%)';
  3214. }
  3215. }
  3216. if (resData[i].attributes && resData[i].attributes.home_room) {
  3217. obj.home_room = resData[i].attributes.home_room.split(' ')[1]; //房间号
  3218. }
  3219. if ((resData[i].state && (resData[i].state == 'on' || resData[i].state == 'off')) && that.checkFuzzyMatch(resData[i])
  3220. ) {
  3221. if (resData[i].state == 'on') {
  3222. obj.service = 'turn_on';
  3223. } else if (resData[i].state == 'off') {
  3224. obj.service = 'turn_off';
  3225. }
  3226. //截取字符串,防止开关设备名称过长
  3227. obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name, roomcode);
  3228. //是否 是香薰机灯光
  3229. obj.isAromlight = obj.friendly_name.includes('香薰机灯光')
  3230. obj.isAromAtomization = obj.friendly_name.includes('香薰机雾化')
  3231. obj.isAromatherapy = obj.friendly_name.endsWith('香薰机') || obj.friendly_name.endsWith('香薰机开关')
  3232. if (obj.entity_id && obj.state && checkState(obj.state) && obj.friendly_name && obj.domain && obj.domain != 'automation' && obj.domain != 'automation' && !obj.isAromlight && !obj.isAromAtomization && !obj.isAromatherapy) {
  3233. if (!obj.friendly_name.endsWith("电视")) {
  3234. listSwitchTemp.push(obj)
  3235. }
  3236. } else if ((obj.isAromlight || obj.isAromAtomization || obj.isAromatherapy) && checkState(obj.state)) {
  3237. listAromatherapyMachineTemp.push(obj)
  3238. }
  3239. }
  3240. if ((resData[i].state && obj.domain && obj.domain == 'cover') && that.checkFuzzyMatch(resData[i])
  3241. ) {
  3242. obj.current_position = resData[i].attributes.current_position;
  3243. obj.target_position = resData[i].attributes.target_position;
  3244. obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name, roomcode);
  3245. if (obj.entity_id && obj.state && checkState(obj.state) && obj.friendly_name && obj.domain) {
  3246. listCoverTemp.push(obj)
  3247. }
  3248. }
  3249. // if((resData[i].state && obj.domain && obj.domain=='number')||
  3250. // (resData[i].state && obj.domain && obj.domain=='number' && resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id)
  3251. // )
  3252. // ){
  3253. // obj.min = resData[i].attributes.min;
  3254. // obj.max = resData[i].attributes.max;
  3255. // obj.step = resData[i].attributes.step;
  3256. // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
  3257. // if(resData[i].state!='unknown'){
  3258. // obj.unit_of_measurement = resData[i].attributes.unit_of_measurement;
  3259. // }
  3260. // if((resData[i].attributes.min || resData[i].attributes.max) && resData[i].attributes.unit_of_measurement!='rgb' && resData[i].attributes.unit_of_measurement!='minutes'){
  3261. // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
  3262. // listScrollTemp.push(obj);
  3263. // }
  3264. // }else if((resData[i].attributes.min || resData[i].attributes.max) && (resData[i].attributes.unit_of_measurement=='rgb' || resData[i].attributes.unit_of_measurement=='minutes')){
  3265. // if(resData[i].state!='unknown'){
  3266. // obj.unit_of_measurement = resData[i].attributes.unit_of_measurement;
  3267. // }
  3268. // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
  3269. // listUnitTemp.push(obj);
  3270. // }
  3271. // }
  3272. // }
  3273. // if((resData[i].state && obj.domain && obj.domain=='button')||
  3274. // (resData[i].state && obj.domain && obj.domain=='button' && resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id)
  3275. // )
  3276. // ){
  3277. // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
  3278. // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
  3279. // listButtonTemp.push(obj);
  3280. // }
  3281. // }
  3282. // if((resData[i].state && obj.domain && obj.domain=='select')||
  3283. // (resData[i].state && obj.domain && obj.domain=='select' && resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id)
  3284. // )
  3285. // ){
  3286. // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
  3287. // obj.options = resData[i].attributes.options;
  3288. // obj.selectedIndex = 0;
  3289. // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
  3290. // listSelectTemp.push(obj);
  3291. // }
  3292. // }
  3293. if ((resData[i].state && obj.domain && obj.domain == 'climate' && resData[i].attributes.entity_class == 'MiirClimateEntity')
  3294. ) {
  3295. climateModeTemp = obj.state;
  3296. obj.temperature = resData[i].attributes.temperature;
  3297. obj.temperatureTemp = resData[i].attributes.temperature;
  3298. obj.min_temp = resData[i].attributes.min_temp;
  3299. obj.max_temp = resData[i].attributes.max_temp;
  3300. obj.hvac_modes = resData[i].attributes.hvac_modes;
  3301. obj.fan_modes = resData[i].attributes.fan_modes;
  3302. obj.fan_mode = resData[i].attributes.fan_mode;
  3303. obj.target_temp_step = resData[i].attributes.target_temp_step;
  3304. if (obj.state == 'auto') {
  3305. temperatureHumidifyNameTemp = '自动';
  3306. }
  3307. if (obj.state == 'heat') {
  3308. temperatureHumidifyNameTemp = '制热';
  3309. }
  3310. if (obj.state == 'cool') {
  3311. temperatureHumidifyNameTemp = '制冷';
  3312. }
  3313. if (obj.state == 'dry') {
  3314. temperatureHumidifyNameTemp = '除湿';
  3315. }
  3316. if (obj.state == 'fan_only') {
  3317. temperatureHumidifyNameTemp = '送风';
  3318. }
  3319. if (obj.state == 'off') {
  3320. temperatureHumidifyNameTemp = '关闭';
  3321. }
  3322. if (obj.entity_id && obj.state && obj.friendly_name && obj.domain) {
  3323. listClimateTemp.push(obj);
  3324. }
  3325. }
  3326. if ((resData[i].state && obj.domain && obj.domain == 'media_player' && resData[i].attributes.entity_class == 'MiotMediaPlayerEntity') && that.checkFuzzyMatch(resData[i])
  3327. ) {
  3328. // obj["speaker.volume"] = resData[i].attribute["speaker.volume"];
  3329. obj.repeat = resData[i].attributes.repeat;
  3330. obj.entity_picture = resData[i].attributes.entity_picture ? "background-image: url('" + `${homeApiLater_https}` + resData[i].attributes.entity_picture + "');width: 100%; height: 100%;background-size: cover;background-repeat: no-repeat;background-position: center;" : "background: radial-gradient(circle at center, #ff0000, #0000ff);border-radius: 30rpx;";
  3331. obj.media_title = resData[i].attributes.media_title;
  3332. obj.media_artist = resData[i].attributes.media_artist;
  3333. obj.volume_level = resData[i].attributes.volume_level ? (resData[i].attributes.volume_level * 100) : 0;
  3334. obj.media_duration = resData[i].attributes.media_duration;
  3335. obj.media_position = resData[i].attributes.media_position;
  3336. obj.media_late = resData[i].attributes.media_position + '/' + resData[i].attributes.media_duration;
  3337. // obj.microphone.mute = resData[i].attributes.microphone.mute;
  3338. // obj.speaker.mute = resData[i].attributes.speaker.mute;
  3339. // console.log('media-player-miot-obj=='+obj);
  3340. if (obj.entity_id && obj.state && checkState(obj.state) && obj.friendly_name && obj.domain) {
  3341. listMiotMediaPlayerTemp.push(obj);
  3342. }
  3343. }
  3344. // if((resData[i].state && obj.domain && obj.domain=='media_player' && resData[i].attributes.entity_class=='MitvMediaPlayerEntity')||
  3345. // (resData[i].state && obj.domain && obj.domain=='media_player' && resData[i].attributes.entity_class=='MitvMediaPlayerEntity' && resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id)
  3346. // )
  3347. // ){
  3348. // obj.volume_level = resData[i].attributes.volume_level;
  3349. // obj.is_volume_muted = resData[i].attributes.is_volume_muted;
  3350. // obj.source = resData[i].attributes.source;
  3351. // obj.entity_picture = resData[i].attributes.entity_picture?"background-image: url('"+`${homeApiLater_https}`+resData[i].attributes.entity_picture+"');width: 100%; height: 100%;background-size: cover;background-repeat: no-repeat;background-position: center;":"background: radial-gradient(circle at center, #ff0000, #0000ff);border-radius: 30rpx;";
  3352. // obj.media_title = resData[i].attributes.media_title;
  3353. // obj.media_artist = resData[i].attributes.media_artist;
  3354. // obj.volume_level = resData[i].attributes.volume_level?(resData[i].attributes.volume_level * 100):0;
  3355. // obj.media_duration = resData[i].attributes.media_duration;
  3356. // obj.media_position = resData[i].attributes.media_position;
  3357. // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
  3358. // listMitvMediaPlayerTemp.push(obj);
  3359. // }
  3360. // }
  3361. if ((resData[i].state && obj.domain && obj.domain == 'media_player') && that.checkFuzzyMatch(resData[i])
  3362. ) {
  3363. obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name, roomcode);
  3364. if (obj.entity_id.includes('teevee') || (obj.friendly_name && obj.friendly_name.includes('电视'))) {
  3365. obj.volume_level = resData[i].attributes.volume_level;
  3366. obj.is_volume_muted = resData[i].attributes.is_volume_muted;
  3367. obj.source = resData[i].attributes.source;
  3368. obj.entity_picture = resData[i].attributes.entity_picture ? "background-image: url('" + `${homeApiLater_https}` + resData[i].attributes.entity_picture + "');width: 100%; height: 100%;background-size: cover;background-repeat: no-repeat;background-position: center;" : "background: radial-gradient(circle at center, #ff0000, #0000ff);border-radius: 30rpx;";
  3369. obj.media_title = resData[i].attributes.media_title;
  3370. obj.media_artist = resData[i].attributes.media_artist;
  3371. obj.volume_level = resData[i].attributes.volume_level ? (resData[i].attributes.volume_level * 100) : 0;
  3372. obj.media_duration = resData[i].attributes.media_duration;
  3373. obj.media_position = resData[i].attributes.media_position;
  3374. obj.media_late = resData[i].attributes.media_position + '/' + resData[i].attributes.media_duration;
  3375. // obj["speaker.volume"] = resData[i].attributes["speaker.volume"];
  3376. // console.log('media-player-mitv-obj=='+obj);
  3377. obj.device_class = resData[i].attributes.device_class;
  3378. obj.app_id = resData[i].attributes.app_id;
  3379. obj.app_name = resData[i].attributes.app_name;
  3380. if (obj.entity_id && obj.state && checkState(obj.state) && obj.friendly_name && obj.domain) {
  3381. listMitvMediaPlayerTemp.push(obj);
  3382. }
  3383. obj.friendly_name1 = resData[i].attributes.friendly_name;
  3384. tvEntityIdsTemp.push(obj);
  3385. // let obj1 = {};
  3386. // obj1.entity_id = obj.entity_id;
  3387. // obj1.friendly_name1 = resData[i].attributes.friendly_name;
  3388. // tvEntityIdsTemp.push(obj1);
  3389. tvEntityIdTemp = obj.entity_id;
  3390. // console.log('obj===='+obj);
  3391. // console.log('tvEntityIdTemp='+tvEntityIdTemp);
  3392. wx.setStorageSync('tvEntityId', tvEntityIdTemp);
  3393. }
  3394. }
  3395. if ((resData[i].state && obj.domain && obj.domain == 'humidifier')
  3396. ) {
  3397. obj.min_humidity = resData[i].attributes.min_humidity;
  3398. obj.max_humidity = resData[i].attributes.max_humidity;
  3399. obj.humidity = resData[i].attributes.humidity;
  3400. obj.min = obj.min_humidity;
  3401. obj.max = obj.max_humidity;
  3402. humidityValueTemp = obj.humidity;
  3403. humidityMaxTemp = obj.max;
  3404. humidityMinTemp = obj.min;
  3405. // console.log('humidifier-obj=='+JSON.stringify(obj));
  3406. if (obj.entity_id && obj.state && checkState(obj.state) && obj.friendly_name && obj.domain) {
  3407. listHumidifierTemp.push(obj);
  3408. }
  3409. }
  3410. if ((resData[i].state && obj.domain && obj.domain == 'automation')) {
  3411. console.log("", resData[i].attributes.friendly_name);
  3412. if (resData[i].attributes.friendly_name.endsWith('起床模式')) {
  3413. modelList1.push(obj)
  3414. } else if (resData[i].attributes.friendly_name.endsWith('观影模式')) {
  3415. modelList2.push(obj)
  3416. } else if (resData[i].attributes.friendly_name.endsWith('睡眠模式')) {
  3417. modelList3.push(obj)
  3418. }
  3419. }
  3420. // if((resData[i].state && obj.domain && obj.domain=='sensor')||
  3421. // (resData[i].state && obj.domain && obj.domain=='sensor' && resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id)
  3422. // )
  3423. // ){
  3424. // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
  3425. // obj.unit_of_measurement = resData[i].attributes.unit_of_measurement;
  3426. // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
  3427. // listSensorTemp.push(obj);
  3428. // }
  3429. // }
  3430. // if((resData[i].state && obj.domain && obj.domain=='text')||
  3431. // (resData[i].state && obj.domain && obj.domain=='text' && resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id)
  3432. // )
  3433. // ){
  3434. // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
  3435. // obj.min = resData[i].attributes.min;
  3436. // obj.max = resData[i].attributes.max;
  3437. // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
  3438. // listTextTemp.push(obj);
  3439. // }
  3440. // }
  3441. // if((resData[i].state && obj.friendly_name && obj.friendly_name.includes("智能音箱"))
  3442. // || (resData[i].state && resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id)
  3443. // && obj.friendly_name && obj.friendly_name.includes("智能音箱"))
  3444. // ){
  3445. // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
  3446. // listConversationTemp.push(obj)
  3447. // }
  3448. // }
  3449. // if((resData[i].state && resData[i].attributes && resData[i].attributes.speaker && resData[i].attributes.speaker.volume && obj.friendly_name && obj.friendly_name.includes("智能音箱"))||
  3450. // (resData[i].state && resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id)
  3451. // && resData[i].attributes.speaker && resData[i].attributes.speaker.volume && obj.friendly_name && obj.friendly_name.includes("智能音箱"))
  3452. // ){
  3453. // obj.volume = resData[i].attributes.speaker.volume;//音量
  3454. // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
  3455. // listConversation1Temp.push(obj)
  3456. // }
  3457. // }
  3458. //加湿器单独拿出来
  3459. // if((obj.friendly_name && obj.friendly_name.includes("加湿器"))||
  3460. // (resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id)
  3461. // && obj.friendly_name && obj.friendly_name.includes("加湿器"))
  3462. // ){
  3463. // listHumidityTemp.push(obj)
  3464. // }
  3465. // }
  3466. }
  3467. listSwitchTemp = that.checkTVList(listSwitchTemp);
  3468. that.setData({
  3469. // status_beep: that.getEntityState(res.data,'switch.xiaomi_pro3_02bd_left_switch_service'), //实验室主灯
  3470. // status_led: that.getEntityState(res.data,'light.deerma_jsq2g_392f_indicator_light'), //加湿器 Indicator Light
  3471. // status_san: that.getEntityState(res.data,'switch.xwhzp_xwxfj_a441_diffuser'), //香薰机 Diffuser
  3472. // status_curtain: that.getEntityState(res.data,'switch.xiaomi_pro3_02bd_middle_switch_service'), //实验室侧灯
  3473. // status_door: that.getEntityState(res.data,'remote.xiaomi_lx06_f593_wifispeaker_4'), //智能音箱
  3474. // Temp: that.getEntityStateValue(res.data,'sensor.deerma_jsq2g_392f_temperature'), //加湿器温度
  3475. // Humi: that.getEntityStateValue(res.data,'sensor.deerma_jsq2g_392f_relative_humidity'), //加湿器湿度
  3476. // Light: that.getEntityStateValue(res.data,'number.xwhzp_xwxfj_a441_brightness'), //香薰机亮度
  3477. // LiquidLevel: that.getEntityStateValue(res.data,'sensor.xwhzp_xwxfj_a441_fragrance_liquid_left_level'), //香薰液浓度
  3478. modelList1,
  3479. modelList2,
  3480. modelList3,
  3481. listSwitch: listSwitchTemp,
  3482. listUnit: listUnitTemp,
  3483. listScroll: listScrollTemp,
  3484. listConversation: listConversationTemp,
  3485. listConversation1: listConversation1Temp,
  3486. listHumidity: listHumidityTemp,
  3487. listButton: listButtonTemp,
  3488. listSelect: listSelectTemp,
  3489. listClimate: listClimateTemp,
  3490. listMiotMediaPlayer: listMiotMediaPlayerTemp,
  3491. listMitvMediaPlayer: listMitvMediaPlayerTemp,
  3492. listHumidifier: listHumidifierTemp,
  3493. listSensor: listSensorTemp,
  3494. listText: listTextTemp,
  3495. tvEntityId: tvEntityIdTemp,
  3496. tvEntityIds: tvEntityIdsTemp,
  3497. climateMode: climateModeTemp,
  3498. temperatureHumidifyName: temperatureHumidifyNameTemp,
  3499. listCover: listCoverTemp,
  3500. listAromatherapyMachine: listAromatherapyMachineTemp,
  3501. // ecHumidifier: {
  3502. // onInit: that.initChartHumidifier
  3503. // },
  3504. sliderValueHumidifier: '',
  3505. isLoading: false,
  3506. })
  3507. if (listHumidifierTemp.length && humidityValue != humidityValueTemp) {
  3508. humidityValue = humidityValueTemp || 40;
  3509. humidityMin = humidityMinTemp;
  3510. humidityMax = humidityMaxTemp;
  3511. that.checkHumidityMarginLeft()
  3512. that.initChartHumidifier();
  3513. }
  3514. wx.setStorageSync('tvEntityIds', tvEntityIdsTemp);
  3515. },
  3516. });
  3517. let mid = Date.now(); // 获取当前时间(毫秒)
  3518. console.log('mid==' + mid);
  3519. console.log('start==' + start);
  3520. console.log('mid-start==' + (mid - start));
  3521. // that.setData({
  3522. // isLoading: true,
  3523. // });
  3524. // } catch (error) {
  3525. // console.error(error);
  3526. // }
  3527. // },
  3528. // fail: function (error) {
  3529. // console.error('error', error);
  3530. // that.setData({
  3531. // isLoading: false,
  3532. // });
  3533. // }
  3534. // });
  3535. } catch (error) {
  3536. console.error(error);
  3537. that.setData({
  3538. isLoading: false,
  3539. });
  3540. }
  3541. },
  3542. fail: function (error) {
  3543. console.error('error', error);
  3544. that.setData({
  3545. isLoading: false,
  3546. });
  3547. }
  3548. });
  3549. let end = Date.now(); // 再次获取当前时间(毫秒)
  3550. console.log('end==' + end);
  3551. let executionTime = end - start;
  3552. console.log(`myFunctionToTest 执行时间为: ${executionTime} 毫秒`);
  3553. return true;
  3554. },
  3555. checkTVList(items = []) {
  3556. // 创建一个新数组来存放不包含"电视"的对象
  3557. let newItems = [];
  3558. // 存放包含"电视"的对象
  3559. let tvItems = [];
  3560. // 遍历原数组
  3561. items.forEach(item => {
  3562. // 检查name是否包含"电视"
  3563. if (item.friendly_name.includes("电视")) {
  3564. tvItems.push(item);
  3565. } else {
  3566. newItems.push(item);
  3567. }
  3568. });
  3569. // 将包含"电视"的对象添加到新数组的末尾
  3570. newItems.push(...tvItems);
  3571. // 如果需要,用新数组替换原数组
  3572. items = newItems;
  3573. return items;
  3574. },
  3575. imageLoad: function () {
  3576. this.setData({
  3577. isLoading: false,
  3578. });
  3579. console.log('图片渲染完成');
  3580. },
  3581. startInterval: function () {
  3582. // 使用 setInterval 创建定时任务,每8秒执行一次 this.myMethod 方法
  3583. var that = this;
  3584. that.clearInterval();
  3585. // this.intervalId = setInterval(() => {
  3586. // that.getHAData(that,that.data.hotelcode,that.data.roomcode);
  3587. // }, 6000);
  3588. this.data.intervalId1 = setInterval(() => {
  3589. that.getHAData(that, that.data.hotelcode, that.data.roomcode);
  3590. }, 5000);
  3591. // 第二个定时器,每2秒执行一次
  3592. this.data.intervalId2 = setInterval(() => {
  3593. // 这里执行你的代码
  3594. that.setData({
  3595. isClickedPrevSong: false,
  3596. isClickedTogglePlayPause: false,
  3597. isClickedNextSong: false,
  3598. isClickedOnHumidifierUp: false,
  3599. isClickedOnHumidifierDown: false,
  3600. isClickedOnClimateAuto: false,
  3601. isClickedOnClimateUp: false,
  3602. isClickedToggleAromlight: false,//香薰机灯光
  3603. });
  3604. }, 300);
  3605. },
  3606. clearInterval: function () {
  3607. // 清除定时任务
  3608. // if (this.intervalId) {
  3609. // clearInterval(this.intervalId);
  3610. // this.intervalId = null;
  3611. // }
  3612. if (this.data.intervalId1) {
  3613. clearInterval(this.data.intervalId1);
  3614. this.data.intervalId1 = null; // 可选,但建议清除以避免潜在的错误
  3615. }
  3616. // 停止第二个定时器
  3617. if (this.data.intervalId2) {
  3618. clearInterval(this.data.intervalId2);
  3619. this.data.intervalId2 = null; // 可选,但建议清除以避免潜在的错误
  3620. }
  3621. },
  3622. stopTouchMove: function (e) {
  3623. return false;
  3624. },
  3625. truncateString: function (str, roomcode) {
  3626. if (!str) return ''
  3627. let strR = str.replace(roomcode, '')
  3628. if (strR.length <= 6) {
  3629. // 如果字符串长度小于等于5,直接返回原字符串
  3630. return strR;
  3631. } else {
  3632. // 如果字符串长度在6到9之间,返回后6个字符(此时没有前部分可拼接)
  3633. return strR.slice(-6);
  3634. }
  3635. },
  3636. onLoad(option) {
  3637. console.log("index页面");
  3638. // wx.clearStorage();
  3639. // this.setTextBreathing(wx.createSelectorQuery(".header-title-fire"),this);
  3640. //console.log('option.res='+JSON.stringify(wx.getStorageSync('res')));
  3641. if (!wx.getStorageSync('res') || !wx.getStorageSync('res').result) {
  3642. wx.showModal({
  3643. title: '提示',
  3644. content: '请先扫描房间二维码',
  3645. showCancel: false
  3646. });
  3647. setTimeout(function () {
  3648. wx.reLaunch({
  3649. url: '/pages/scan/scan',
  3650. })
  3651. }, 2000) // 设置延时时间,单位为毫秒
  3652. } else {
  3653. var that = this;
  3654. // wx.request({
  3655. // url: `${aipushApi}`+'/getbigreport',
  3656. // method: 'POST',
  3657. // header: {
  3658. // 'content-type': 'application/json', // 默认值
  3659. // 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  3660. // },
  3661. // data:{
  3662. //     "sn":'',"tokens":token_push
  3663. // },
  3664. // success(ress) {
  3665. // if(ress && ress.data){
  3666. // wx.request({
  3667. // url: `${homeApi_https}/states`, //获取空气数据
  3668. // method: 'GET',
  3669. // header: {
  3670. // 'content-type': 'application/json', // 默认值
  3671. // 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  3672. // },
  3673. // success(res) {
  3674. // if(!res || !res.data){
  3675. // wx.showModal({
  3676. // title: '提示',
  3677. // content: '请先连接房间wi-fi,再次扫描',
  3678. // showCancel: false
  3679. // });
  3680. // setTimeout(function() {
  3681. // wx.reLaunch({
  3682. // url: '/pages/scan/scan',
  3683. // })
  3684. // }, 2000) // 设置延时时间,单位为毫秒
  3685. // }else{
  3686. // // console.log("res.data====="+JSON.stringify(res.data));
  3687. // }
  3688. // },
  3689. // });
  3690. // }else{
  3691. // wx.showModal({
  3692. // title: '提示',
  3693. // content: '请先连接房间wi-fi,再次扫描',
  3694. // showCancel: false
  3695. // });
  3696. // setTimeout(function() {
  3697. // wx.reLaunch({
  3698. // url: '/pages/scan/scan',
  3699. // })
  3700. // }, 2000) // 设置延时时间,单位为毫秒
  3701. // }
  3702. // },
  3703. // });
  3704. // const socketUrl = 'http://192.168.3.65:8123';
  3705. // wx.connectSocket({
  3706. // url: socketUrl,
  3707. // success: function (res) {
  3708. // console.log('WebSocket连接成功', res);
  3709. // },
  3710. // fail: function (error) {
  3711. // console.error('WebSocket连接打开失败', error);
  3712. // }
  3713. // });
  3714. //wi-fi判断
  3715. // wx.startWifi({
  3716. // fail(error) {
  3717. // console.log('初始化wifi-失败', error)
  3718. // },
  3719. // success(res) {
  3720. // console.log('初始化wifi-成功', res)
  3721. // },
  3722. // });
  3723. // const expiresAt = wx.getStorageSync('scanResultExpiresAt');
  3724. // const now = Date.now()
  3725. // console.log('expiresAt='+expiresAt);
  3726. // console.log('now='+now);
  3727. // if (expiresAt || expiresAt < now) {
  3728. // // 扫码结果已过期
  3729. // wx.showToast({
  3730. // title: '扫码结果失效或已过期,请重新扫码',
  3731. // icon: 'none'
  3732. // });
  3733. // // 清除过期的扫码结果
  3734. // wx.removeStorageSync('scanResultExpiresAt');
  3735. // setTimeout(function() {
  3736. // wx.reLaunch({
  3737. // url: '/pages/scan/scan',
  3738. // })
  3739. // }, 2000) // 设置延时时间,单位为毫秒
  3740. // }else{
  3741. // //续期
  3742. // wx.setStorageSync('scanResultExpiresAt', Date.now() + 2 * 60 * 60 * 1000)
  3743. // }
  3744. let hotelcodeTemp = '';
  3745. let roomcodeTemp = '';
  3746. if (wx.getStorageSync('res').result.split('|').length != 2) {
  3747. wx.showModal({
  3748. title: '提示',
  3749. content: '房间二维码不正确,请重新扫码',
  3750. showCancel: false
  3751. });
  3752. setTimeout(function () {
  3753. wx.reLaunch({
  3754. url: '/pages/scan/scan',
  3755. })
  3756. }, 2000) // 设置延时时间,单位为毫秒
  3757. }
  3758. hotelcodeTemp = wx.getStorageSync('res').result.split('|')[0];
  3759. roomcodeTemp = wx.getStorageSync('res').result.split('|')[1];
  3760. entity = roomcodeTemp;
  3761. if (entity == 'labs') {
  3762. entity = '公司实验室';
  3763. wx.setStorageSync('roomname', '604');
  3764. } else {
  3765. wx.setStorageSync('roomname', entity);
  3766. }
  3767. this.setData({
  3768. isLoading: true,
  3769. hotelcode: hotelcodeTemp,
  3770. roomcode: roomcodeTemp,
  3771. });
  3772. if (this.getHADataStart(this, hotelcodeTemp, roomcodeTemp)) {
  3773. // 页面加载时开始定时任务
  3774. // this.startInterval();
  3775. }
  3776. }
  3777. // else if(!this.data.home_room.includes(wx.getStorageSync('res').result)){
  3778. // wx.showModal({
  3779. // title: '提示',
  3780. // content: '房间二维码不正确,请重新扫描',
  3781. // showCancel: false
  3782. // });
  3783. // setTimeout(function() {
  3784. // wx.reLaunch({
  3785. // url: '/pages/scan/scan',
  3786. // })
  3787. // }, 2000) // 设置延时时间,单位为毫秒
  3788. // }
  3789. // this.showCanvasRing();
  3790. // 创建音频上下文
  3791. // this.innerAudioContext = wx.createInnerAudioContext();
  3792. // // 设置音频源
  3793. // this.innerAudioContext.src = '你的音频文件链接'; // 替换为你的音频文件链接
  3794. // // 监听播放状态
  3795. // this.innerAudioContext.onPlay(() => {
  3796. // this.setData({ isPlaying: true });
  3797. // });
  3798. // this.innerAudioContext.onPause(() => {
  3799. // this.setData({ isPlaying: false });
  3800. // });
  3801. // this.innerAudioContext.onStop(() => {
  3802. // this.setData({ isPlaying: false });
  3803. // });
  3804. // this.innerAudioContext.onError((res) => {
  3805. // console.log('res.errorCode='+res.errorCode);
  3806. // console.log('res.errorMsg='+res.errorMsg);
  3807. // });
  3808. // // 监听播放进度
  3809. // this.innerAudioContext.onTimeUpdate(() => {
  3810. // this.setData({
  3811. // currentTime: this.innerAudioContext.currentTime,
  3812. // duration: this.innerAudioContext.duration
  3813. // });
  3814. // });
  3815. // // 初始化歌曲列表
  3816. // this.setData({
  3817. // songs: [
  3818. // { id: 1, title: '歌曲1', artist: '歌手1', url: 'song1.mp3' },
  3819. // { id: 2, title: '歌曲2', artist: '歌手2', url: 'song2.mp3' },
  3820. // { id: 3, title: '歌曲3', artist: '歌手3', url: 'song3.mp3' }
  3821. // ]
  3822. // });
  3823. },
  3824. mounted() {
  3825. },
  3826. onHide() {
  3827. // wx.clearStorage();
  3828. // 页面卸载时清除定时任务
  3829. this.clearInterval();
  3830. // if(this.tcp){
  3831. // this.tcp.onClose(() => {
  3832. // // this.infoList.push('关闭')
  3833. // console.log('tcp关闭');
  3834. // this.tcp.close()
  3835. // })
  3836. // }
  3837. },
  3838. onUnload() {
  3839. //wx.clearStorage();
  3840. // 页面卸载时清除定时任务
  3841. this.clearInterval();
  3842. // if(this.tcp){
  3843. // this.tcp.onClose(() => {
  3844. // // this.infoList.push('关闭')
  3845. // console.log('tcp关闭');
  3846. // this.tcp.close()
  3847. // })
  3848. // }
  3849. // if (this.data.observer) {
  3850. // this.data.observer.disconnect();
  3851. // }
  3852. },
  3853. onReady() {
  3854. console.log('页面渲染完成')
  3855. // 获取组件
  3856. // 确保页面渲染完成后查找节点
  3857. },
  3858. showLoading: function () {
  3859. wx.showToast({
  3860. title: '加载中',
  3861. icon: 'loading',
  3862. })
  3863. },
  3864. cancelLoading: function () {
  3865. wx.hideToast()
  3866. },
  3867. onShow() {
  3868. const app = getApp();
  3869. app.globalData.selectedTabIndex = 0;
  3870. this.getTabBar().setData({
  3871. selected: 0
  3872. })
  3873. var that = this;
  3874. that.setData({
  3875. currentMenuTabIndex: -1
  3876. })
  3877. that.startInterval();
  3878. // that.setData({
  3879. // ecHumidifier: {
  3880. // onInit: initChartHumidifier
  3881. // },
  3882. // })
  3883. //mqtt程序,保留
  3884. /* wx.showToast({
  3885. title: "连接服务器....",
  3886. icon: "loading",
  3887. duration: 10000,
  3888. mask: true,
  3889. });
  3890. let second = 10;
  3891. var toastTimer = setInterval(() => {
  3892. second--;
  3893. if (second) {
  3894. wx.showToast({
  3895. title: `连接服务器...${second}`,
  3896. icon: "loading",
  3897. duration: 1000,
  3898. mask: true,
  3899. });
  3900. } else {
  3901. clearInterval(toastTimer);
  3902. wx.showToast({
  3903. title: "连接失败",
  3904. icon: "error",
  3905. mask: true,
  3906. });
  3907. }
  3908. }, 1000);
  3909. that.setData({
  3910. client: connect(mqttUrl,options)
  3911. })
  3912. that.data.client.on("connect", function () {
  3913. console.log("成功连接mqtt服务器!");
  3914. clearInterval(toastTimer);
  3915. wx.showToast({
  3916. title: "连接成功",
  3917. icon: "success",
  3918. mask: true,
  3919. });
  3920. // 一秒后订阅主题
  3921. setTimeout(() => {
  3922. that.data.client.subscribe(mpSubTopic_env, function (err) {
  3923. if (!err) {
  3924. console.log("成功订阅设备上行数据环境Topic!");
  3925. wx.showToast({
  3926. title: "订阅成功",
  3927. icon: "success",
  3928. mask: true,
  3929. });
  3930. }
  3931. });
  3932. }, 500);
  3933. });
  3934. setTimeout(() => {
  3935. that.data.client.subscribe(mpSubTopic_con, function (err) {
  3936. if (!err) {
  3937. console.log("成功订阅设备上行数据控制Topic!");
  3938. wx.showToast({
  3939. title: "订阅成功",
  3940. icon: "success",
  3941. mask: true,
  3942. });
  3943. }
  3944. });
  3945. }, 200);
  3946. that.data.client.on("message", function (topic, message) {
  3947. console.log(topic);
  3948. // message是16进制的Buffer字节流
  3949. let dataFromDev = {};
  3950. console.log('message='+message);
  3951. // 尝试进行JSON解析
  3952. try {
  3953. dataFromDev = JSON.parse(message);
  3954. console.log(dataFromDev);
  3955. that.setData({
  3956. //环境状态
  3957. Temp: dataFromDev.Temp,
  3958. Humi: dataFromDev.Humi,
  3959. Voltage1: dataFromDev.Voltage1,
  3960. Voltage2: dataFromDev.Voltage2,
  3961. //设备状态
  3962. status_beep: dataFromDev.Beep_Flag,
  3963. status_led: dataFromDev.Led_Flag,
  3964. status_curtain: dataFromDev.Angle1,
  3965. status_san: dataFromDev.San_Flag,
  3966. status_door: dataFromDev.Angle2,
  3967. status_fire: dataFromDev.Fire_Flag,
  3968. status_light: dataFromDev.Light_Flag,
  3969. status_mode: dataFromDev.Mode_Flag
  3970. })
  3971. } catch (error) {
  3972. // 解析失败错误捕获并打印(错误捕获之后不会影响程序继续运行)
  3973. console.log(error);
  3974. }
  3975. }) */
  3976. // if(this.tcp){
  3977. // this.tcp.onClose(() => {
  3978. // // this.infoList.push('关闭')
  3979. // console.log('tcp关闭');
  3980. // this.tcp.close()
  3981. // this.tcp = '';
  3982. // })
  3983. // }
  3984. // // 初始化TCP实例
  3985. // this.tcp = wx.createTCPSocket()
  3986. // // tcp实例向服务端发起连接
  3987. // this.tcp.connect({ address: '192.168.3.65', port: '81231' })
  3988. // // this.infoList.push(`向${this.ip}:${~~this.port}建立链接`)
  3989. // this.tcp.offClose(() => {
  3990. // })
  3991. // this.tcp.onConnect(() => {
  3992. // // this.infoList.push('连接成功')
  3993. // console.log('tcp连接成功');
  3994. // })
  3995. // this.tcp.offConnect(() => {
  3996. // // this.infoList.push('offConnect')
  3997. // console.log('tcp-offConnect');
  3998. // })
  3999. // this.tcp.onError(error => {
  4000. // // this.infoList.push('异常:' + error)
  4001. // console.log('tcp异常:' + error);
  4002. // wx.showModal({
  4003. // title: '提示',
  4004. // content: '请先连接房间wi-fi,再次扫描',
  4005. // showCancel: false
  4006. // });
  4007. // setTimeout(function() {
  4008. // wx.reLaunch({
  4009. // url: '/pages/scan/scan',
  4010. // })
  4011. // }, 2000) // 设置延时时间,单位为毫秒
  4012. // })
  4013. // this.tcp.onMessage(data => {
  4014. // // this.infoList.push('tcp接收到数据: ' + transitionArrayBufferToString(data.message))
  4015. // console.log('tcp接收到数据: ' + JSON.stringify(data.message));
  4016. // })
  4017. wx.getLocation({
  4018. type: "wgs84",
  4019. success(res) {
  4020. const latitude = res.latitude;
  4021. const longitude = res.longitude;
  4022. const key = hefengKey;
  4023. wx.request({
  4024. url: `${geoApi}location=${longitude},${latitude}&key=${key}`, //获取地理位置
  4025. success(res) {
  4026. console.log('getLocation=' + JSON.stringify(res.data));
  4027. if (res.data.code == "401") {
  4028. console.error("HUAQING --- 请检查你的和风天气API或Key是否正确!");
  4029. return;
  4030. }
  4031. try {
  4032. const {
  4033. location
  4034. } = res.data;
  4035. that.setData({
  4036. area: location[0].name, //城区
  4037. city: location[0].adm2 //城市
  4038. })
  4039. } catch (error) {
  4040. console.error(error);
  4041. }
  4042. },
  4043. });
  4044. wx.request({
  4045. url: `${hefengWeather}location=${longitude},${latitude}&key=${key}`, //获取实时天气数据
  4046. success(res) {
  4047. console.log("实时天气==" + JSON.stringify(res.data));
  4048. if (res.data.code == "401") {
  4049. console.error("HUAQING --- 请检查你的和风天气API或Key是否正确!");
  4050. return;
  4051. }
  4052. try {
  4053. const {
  4054. now
  4055. } = res.data;
  4056. that.setData({
  4057. weather: now.text, // 天气
  4058. w_temp: now.temp, // 温度
  4059. w_humidity: now.humidity, // 湿度
  4060. })
  4061. } catch (error) {
  4062. console.error(error);
  4063. }
  4064. },
  4065. });
  4066. wx.request({
  4067. url: `${hefengAir}location=${longitude},${latitude}&key=${key}`, //获取空气数据
  4068. success(res) {
  4069. console.log("空气数据==" + JSON.stringify(res.data));
  4070. if (res.data.code == "401") {
  4071. console.error("HUAQING --- 请检查你的和风天气API或Key是否正确!");
  4072. return;
  4073. }
  4074. try {
  4075. const {
  4076. now
  4077. } = res.data;
  4078. that.setData({
  4079. airText: now.category, //空气质量
  4080. airValue: now.aqi //空气指数
  4081. })
  4082. } catch (error) {
  4083. console.error(error);
  4084. }
  4085. },
  4086. });
  4087. },
  4088. });
  4089. // 获取天气相关数据
  4090. // wx.scanCode({
  4091. // success: (res) => {
  4092. // console.log('扫描结果:'+res.result) // 扫描结果
  4093. // }
  4094. // });
  4095. }
  4096. })