index.js 146 KB

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