index.js 145 KB

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