index.js 140 KB

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