index.js 144 KB

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