index.js 143 KB

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