index.js 147 KB

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