index.js 144 KB

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