main.js 139 KB

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