index.js 142 KB

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