index.js 141 KB

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