index.js 143 KB

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