main.js 139 KB

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