index.js 147 KB

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