main.js 140 KB

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