index.js 140 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210
  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: 10,
  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: 32,
  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. this.setData({
  1615. isClickedOnClimateUp: true
  1616. });
  1617. console.log('that.data.climateMode==' + that.data.climateMode);
  1618. if (!that.data.climateMode) {
  1619. wx.showToast({
  1620. title: '请先选择模式',
  1621. icon: 'none'
  1622. });
  1623. return;
  1624. }
  1625. let currentValue = e.currentTarget.dataset.temperature;
  1626. let fanMode = e.currentTarget.dataset.fanMode;
  1627. let min = e.currentTarget.dataset.min;
  1628. let max = e.currentTarget.dataset.max;
  1629. let domain = e.currentTarget.dataset.domain;
  1630. let entity_id = e.currentTarget.dataset.id;
  1631. let data = {};
  1632. if (that.data.climateMode == 'heat' || that.data.climateMode == 'cool') {
  1633. let newValue = parseInt(currentValue) + 1; // 假设文本框中的是数字
  1634. if (newValue > max) newValue = max;
  1635. let list = this.data.listClimate;//这里是将需要循环的数组赋值给list
  1636. let indexS = Number(e.currentTarget.dataset.index);
  1637. // 将本地缓存数据渲染到对应修改的案例
  1638. list.forEach(function (value, index, array) {
  1639. if (index == indexS) {
  1640. array[index].temperature = e.detail;
  1641. }
  1642. })
  1643. this.setData({
  1644. listClimate: list
  1645. })
  1646. data = {
  1647. "entity_id": entity_id,
  1648. "temperature": e.detail,
  1649. "hvac_mode": that.data.climateMode
  1650. }
  1651. this.getService("/services", "/" + domain, "/set_temperature", "POST", data);
  1652. } else if (that.data.climateMode == 'dry') {
  1653. let newValue = parseInt(currentValue) + 1; // 假设文本框中的是数字
  1654. if (newValue > max) newValue = max;
  1655. data = {
  1656. "entity_id": entity_id,
  1657. "temperature": e.detail,
  1658. "hvac_mode": that.data.climateMode
  1659. }
  1660. this.getService("/services", "/" + domain, "/set_temperature", "POST", data);
  1661. } else if (that.data.climateMode == 'fan_only') {
  1662. let newValue = parseInt(currentValue) + 1; // 假设文本框中的是数字
  1663. if (newValue > max) newValue = max;
  1664. data = {
  1665. "entity_id": entity_id,
  1666. // "fan_mode":(fanMode=='Fan Speed Up')?'Fan Speed Down':'Fan Speed Up',
  1667. "temperature": e.detail,
  1668. "hvac_mode": that.data.climateMode
  1669. }
  1670. this.getService("/services", "/" + domain, "/set_temperature", "POST", data);
  1671. }
  1672. },
  1673. // 更改空调的值
  1674. minusClimate(e) {
  1675. var that = this;
  1676. this.setData({
  1677. isClickedOnClimateUp: true
  1678. });
  1679. console.log('that.data.climateMode==' + that.data.climateMode);
  1680. if (!that.data.climateMode) {
  1681. wx.showToast({
  1682. title: '请先选择模式',
  1683. icon: 'none'
  1684. });
  1685. return;
  1686. }
  1687. let currentValue = e.currentTarget.dataset.temperature;
  1688. let fanMode = e.currentTarget.dataset.fanMode;
  1689. let min = e.currentTarget.dataset.min;
  1690. let max = e.currentTarget.dataset.max;
  1691. let domain = e.currentTarget.dataset.domain;
  1692. let temperature = e.currentTarget.dataset.temperature - 1;
  1693. let entity_id = e.currentTarget.dataset.id;
  1694. let data = {};
  1695. if (that.data.climateMode == 'heat' || that.data.climateMode == 'cool') {
  1696. let newValue = parseInt(currentValue) + 1; // 假设文本框中的是数字
  1697. if (newValue > max) newValue = max;
  1698. let list = this.data.listClimate;//这里是将需要循环的数组赋值给list
  1699. let indexS = Number(e.currentTarget.dataset.index);
  1700. // 将本地缓存数据渲染到对应修改的案例
  1701. list.forEach(function (value, index, array) {
  1702. if (index == indexS) {
  1703. array[index].temperature = temperature;
  1704. }
  1705. })
  1706. this.setData({
  1707. listClimate: list
  1708. })
  1709. data = {
  1710. "entity_id": entity_id,
  1711. "temperature": temperature,
  1712. "hvac_mode": that.data.climateMode
  1713. }
  1714. this.getService("/services", "/" + domain, "/set_temperature", "POST", data);
  1715. } else if (that.data.climateMode == 'dry') {
  1716. let newValue = parseInt(currentValue) + 1; // 假设文本框中的是数字
  1717. if (newValue > max) newValue = max;
  1718. data = {
  1719. "entity_id": entity_id,
  1720. "temperature": temperature,
  1721. "hvac_mode": that.data.climateMode
  1722. }
  1723. this.getService("/services", "/" + domain, "/set_temperature", "POST", data);
  1724. } else if (that.data.climateMode == 'fan_only') {
  1725. let newValue = parseInt(currentValue) + 1; // 假设文本框中的是数字
  1726. if (newValue > max) newValue = max;
  1727. data = {
  1728. "entity_id": entity_id,
  1729. // "fan_mode":(fanMode=='Fan Speed Up')?'Fan Speed Down':'Fan Speed Up',
  1730. "temperature": temperature,
  1731. "hvac_mode": that.data.climateMode
  1732. }
  1733. this.getService("/services", "/" + domain, "/set_temperature", "POST", data);
  1734. }
  1735. },
  1736. // 更改空调的值
  1737. addClimate(e) {
  1738. var that = this;
  1739. this.setData({
  1740. isClickedOnClimateUp: true
  1741. });
  1742. console.log('that.data.climateMode==' + that.data.climateMode);
  1743. if (!that.data.climateMode) {
  1744. wx.showToast({
  1745. title: '请先选择模式',
  1746. icon: 'none'
  1747. });
  1748. return;
  1749. }
  1750. let currentValue = e.currentTarget.dataset.temperature;
  1751. let fanMode = e.currentTarget.dataset.fanMode;
  1752. let min = e.currentTarget.dataset.min;
  1753. let max = e.currentTarget.dataset.max;
  1754. let domain = e.currentTarget.dataset.domain;
  1755. let temperature = e.currentTarget.dataset.temperature + 1;
  1756. let entity_id = e.currentTarget.dataset.id;
  1757. let data = {};
  1758. if (that.data.climateMode == 'heat' || that.data.climateMode == 'cool') {
  1759. let newValue = parseInt(currentValue) + 1; // 假设文本框中的是数字
  1760. if (newValue > max) newValue = max;
  1761. let list = this.data.listClimate;//这里是将需要循环的数组赋值给list
  1762. let indexS = Number(e.currentTarget.dataset.index);
  1763. // 将本地缓存数据渲染到对应修改的案例
  1764. list.forEach(function (value, index, array) {
  1765. if (index == indexS) {
  1766. array[index].temperature = temperature;
  1767. }
  1768. })
  1769. this.setData({
  1770. listClimate: list
  1771. })
  1772. data = {
  1773. "entity_id": entity_id,
  1774. "temperature": temperature,
  1775. "hvac_mode": that.data.climateMode
  1776. }
  1777. this.getService("/services", "/" + domain, "/set_temperature", "POST", data);
  1778. } else if (that.data.climateMode == 'dry') {
  1779. let newValue = parseInt(currentValue) + 1; // 假设文本框中的是数字
  1780. if (newValue > max) newValue = max;
  1781. data = {
  1782. "entity_id": entity_id,
  1783. "temperature": temperature,
  1784. "hvac_mode": that.data.climateMode
  1785. }
  1786. this.getService("/services", "/" + domain, "/set_temperature", "POST", data);
  1787. } else if (that.data.climateMode == 'fan_only') {
  1788. let newValue = parseInt(currentValue) + 1; // 假设文本框中的是数字
  1789. if (newValue > max) newValue = max;
  1790. data = {
  1791. "entity_id": entity_id,
  1792. // "fan_mode":(fanMode=='Fan Speed Up')?'Fan Speed Down':'Fan Speed Up',
  1793. "temperature": temperature,
  1794. "hvac_mode": that.data.climateMode
  1795. }
  1796. this.getService("/services", "/" + domain, "/set_temperature", "POST", data);
  1797. }
  1798. },
  1799. onClimateDown(e) {
  1800. var that = this;
  1801. if (!that.data.climateMode) {
  1802. wx.showToast({
  1803. title: '请先选择模式',
  1804. icon: 'none'
  1805. });
  1806. return;
  1807. }
  1808. console.log('that.data.climateMode==' + that.data.climateMode);
  1809. let currentValue = e.currentTarget.dataset.temperature;
  1810. let fanMode = e.currentTarget.dataset.fanMode;
  1811. // let list = this.data.listClimate;
  1812. // this.setData({
  1813. // inputValue: newValue.toString()
  1814. // });
  1815. let domain = e.currentTarget.dataset.domain;
  1816. let entity_id = e.currentTarget.dataset.id;
  1817. let min = e.currentTarget.dataset.min;
  1818. let max = e.currentTarget.dataset.max;
  1819. // this.setData({
  1820. // isButtonPressedClimateDown: !that.data.isButtonPressedClimateDown
  1821. // })
  1822. // 将本地缓存数据渲染到对应修改的案例
  1823. // list.forEach(function (value,index, array){
  1824. // if (index == indexS) {
  1825. // array[index].temperature = newValue;
  1826. // }
  1827. // })
  1828. // this.setData({
  1829. // listClimate: list
  1830. // })
  1831. let data = {};
  1832. if (that.data.climateMode == 'heat' || that.data.climateMode == 'cool') {
  1833. let newValue = parseInt(currentValue) - 1; // 假设文本框中的是数字
  1834. if (newValue < min) newValue = min;
  1835. let list = this.data.listClimate;//这里是将需要循环的数组赋值给list
  1836. let indexS = Number(e.currentTarget.dataset.index);
  1837. // 将本地缓存数据渲染到对应修改的案例
  1838. list.forEach(function (value, index, array) {
  1839. if (index == indexS) {
  1840. array[index].temperature = newValue;
  1841. }
  1842. })
  1843. this.setData({
  1844. listClimate: list
  1845. })
  1846. console.log('onClimateDown-entity_id=' + entity_id);
  1847. data = {
  1848. "entity_id": entity_id,
  1849. "temperature": newValue,
  1850. "hvac_mode": that.data.climateMode
  1851. }
  1852. this.getService("/services", "/" + domain, "/set_temperature", "POST", data);
  1853. } else if (that.data.climateMode == 'dry') {
  1854. let newValue = parseInt(currentValue) - 1; // 假设文本框中的是数字
  1855. if (newValue < min) newValue = min;
  1856. data = {
  1857. "entity_id": entity_id,
  1858. "temperature": newValue,
  1859. "hvac_mode": that.data.climateMode
  1860. }
  1861. this.getService("/services", "/" + domain, "/set_temperature", "POST", data);
  1862. } else if (that.data.climateMode == 'fan_only') {
  1863. let newValue = parseInt(currentValue) - 1; // 假设文本框中的是数字
  1864. if (newValue < min) newValue = min;
  1865. data = {
  1866. "entity_id": entity_id,
  1867. // "fan_mode":(fanMode=='Fan Speed Up')?'Fan Speed Down':'Fan Speed Up',
  1868. "temperature": newValue,
  1869. "hvac_mode": that.data.climateMode
  1870. }
  1871. this.getService("/services", "/" + domain, "/set_temperature", "POST", data);
  1872. }
  1873. },
  1874. onClimateUp(e) {
  1875. var that = this;
  1876. this.setData({
  1877. isClickedOnClimateUp: true
  1878. });
  1879. console.log('that.data.climateMode==' + that.data.climateMode);
  1880. if (!that.data.climateMode) {
  1881. wx.showToast({
  1882. title: '请先选择模式',
  1883. icon: 'none'
  1884. });
  1885. return;
  1886. }
  1887. let currentValue = e.currentTarget.dataset.temperature;
  1888. let fanMode = e.currentTarget.dataset.fanMode;
  1889. let min = e.currentTarget.dataset.min;
  1890. let max = e.currentTarget.dataset.max;
  1891. // this.setData({
  1892. // inputValue: newValue.toString()
  1893. // });
  1894. // let list = this.data.listClimate;//这里是将需要循环的数组赋值给list
  1895. // let indexS = Number(e.currentTarget.dataset.index)
  1896. let domain = e.currentTarget.dataset.domain;
  1897. let entity_id = e.currentTarget.dataset.id;
  1898. // this.setData({
  1899. // isButtonPressedClimateUp: !that.data.isButtonPressedClimateUp
  1900. // })
  1901. // 将本地缓存数据渲染到对应修改的案例
  1902. // list.forEach(function (value,index, array){
  1903. // if (index == indexS) {
  1904. // array[index].temperature = newValue;
  1905. // }
  1906. // })
  1907. // this.setData({
  1908. // listClimate: list
  1909. // })
  1910. let data = {};
  1911. if (that.data.climateMode == 'heat' || that.data.climateMode == 'cool') {
  1912. let newValue = parseInt(currentValue) + 1; // 假设文本框中的是数字
  1913. if (newValue > max) newValue = max;
  1914. let list = this.data.listClimate;//这里是将需要循环的数组赋值给list
  1915. let indexS = Number(e.currentTarget.dataset.index);
  1916. // 将本地缓存数据渲染到对应修改的案例
  1917. list.forEach(function (value, index, array) {
  1918. if (index == indexS) {
  1919. array[index].temperature = newValue;
  1920. }
  1921. })
  1922. this.setData({
  1923. listClimate: list
  1924. })
  1925. data = {
  1926. "entity_id": entity_id,
  1927. "temperature": newValue,
  1928. "hvac_mode": that.data.climateMode
  1929. }
  1930. this.getService("/services", "/" + domain, "/set_temperature", "POST", data);
  1931. } else if (that.data.climateMode == 'dry') {
  1932. let newValue = parseInt(currentValue) + 1; // 假设文本框中的是数字
  1933. if (newValue > max) newValue = max;
  1934. data = {
  1935. "entity_id": entity_id,
  1936. "temperature": newValue,
  1937. "hvac_mode": that.data.climateMode
  1938. }
  1939. this.getService("/services", "/" + domain, "/set_temperature", "POST", data);
  1940. } else if (that.data.climateMode == 'fan_only') {
  1941. let newValue = parseInt(currentValue) + 1; // 假设文本框中的是数字
  1942. if (newValue > max) newValue = max;
  1943. data = {
  1944. "entity_id": entity_id,
  1945. // "fan_mode":(fanMode=='Fan Speed Up')?'Fan Speed Down':'Fan Speed Up',
  1946. "temperature": newValue,
  1947. "hvac_mode": that.data.climateMode
  1948. }
  1949. this.getService("/services", "/" + domain, "/set_temperature", "POST", data);
  1950. }
  1951. },
  1952. onClimateAuto(e) {
  1953. this.setData({
  1954. isClickedOnClimateAuto: true
  1955. });
  1956. let domain = e.currentTarget.dataset.domain;
  1957. let entity_id = e.currentTarget.dataset.id;
  1958. let list = this.data.listClimate;//这里是将需要循环的数组赋值给list
  1959. let indexS = Number(e.currentTarget.dataset.index);
  1960. // 将本地缓存数据渲染到对应修改的案例
  1961. list.forEach(function (value, index, array) {
  1962. if (index == indexS) {
  1963. array[index].state = newValue;
  1964. }
  1965. })
  1966. this.setData({
  1967. temperatureHumidifyName: '自动',
  1968. climateMode: 'auto',
  1969. listClimate: list
  1970. })
  1971. let data = {
  1972. "entity_id": entity_id,
  1973. "hvac_mode": 'auto',
  1974. }
  1975. this.getService("/services", "/" + domain, "/set_hvac_mode", "POST", data);
  1976. },
  1977. onClimateHeat(e) {
  1978. let domain = e.currentTarget.dataset.domain;
  1979. let entity_id = e.currentTarget.dataset.id;
  1980. let list = this.data.listClimate;//这里是将需要循环的数组赋值给list
  1981. let indexS = Number(e.currentTarget.dataset.index);
  1982. // 将本地缓存数据渲染到对应修改的案例
  1983. list.forEach(function (value, index, array) {
  1984. if (index == indexS) {
  1985. array[index].state = newValue;
  1986. }
  1987. })
  1988. this.setData({
  1989. temperatureHumidifyName: '制热',
  1990. climateMode: 'heat',
  1991. listClimate: list
  1992. })
  1993. let data = {
  1994. "entity_id": entity_id,
  1995. "hvac_mode": 'heat',
  1996. }
  1997. this.getService("/services", "/" + domain, "/set_hvac_mode", "POST", data);
  1998. },
  1999. onClimateCool(e) {
  2000. let domain = e.currentTarget.dataset.domain;
  2001. let entity_id = e.currentTarget.dataset.id;
  2002. let list = this.data.listClimate;//这里是将需要循环的数组赋值给list
  2003. let indexS = Number(e.currentTarget.dataset.index);
  2004. // 将本地缓存数据渲染到对应修改的案例
  2005. list.forEach(function (value, index, array) {
  2006. if (index == indexS) {
  2007. array[index].state = newValue;
  2008. }
  2009. })
  2010. this.setData({
  2011. temperatureHumidifyName: '制冷',
  2012. climateMode: 'cool',
  2013. listClimate: list
  2014. })
  2015. let data = {
  2016. "entity_id": entity_id,
  2017. "hvac_mode": 'cool',
  2018. }
  2019. this.getService("/services", "/" + domain, "/set_hvac_mode", "POST", data);
  2020. },
  2021. onClimateDehumidify(e) {
  2022. let domain = e.currentTarget.dataset.domain;
  2023. let entity_id = e.currentTarget.dataset.id;
  2024. let list = this.data.listClimate;//这里是将需要循环的数组赋值给list
  2025. let indexS = Number(e.currentTarget.dataset.index);
  2026. // 将本地缓存数据渲染到对应修改的案例
  2027. list.forEach(function (value, index, array) {
  2028. if (index == indexS) {
  2029. array[index].state = newValue;
  2030. }
  2031. })
  2032. this.setData({
  2033. temperatureHumidifyName: '除湿',
  2034. climateMode: 'dry',
  2035. listClimate: list
  2036. })
  2037. let data = {
  2038. "entity_id": entity_id,
  2039. "hvac_mode": 'dry',
  2040. }
  2041. this.getService("/services", "/" + domain, "/set_hvac_mode", "POST", data);
  2042. },
  2043. onClimateAirSupply(e) {
  2044. let domain = e.currentTarget.dataset.domain;
  2045. let entity_id = e.currentTarget.dataset.id;
  2046. let list = this.data.listClimate;//这里是将需要循环的数组赋值给list
  2047. let indexS = Number(e.currentTarget.dataset.index);
  2048. // 将本地缓存数据渲染到对应修改的案例
  2049. list.forEach(function (value, index, array) {
  2050. if (index == indexS) {
  2051. array[index].state = newValue;
  2052. }
  2053. })
  2054. this.setData({
  2055. temperatureHumidifyName: '送风',
  2056. climateMode: 'fan_only',
  2057. listClimate: list
  2058. })
  2059. let data = {
  2060. "entity_id": entity_id,
  2061. "hvac_mode": 'fan_only',
  2062. }
  2063. this.getService("/services", "/" + domain, "/set_hvac_mode", "POST", data);
  2064. },
  2065. onClimateOff(e) {
  2066. let state = e.currentTarget.dataset.state;
  2067. if (state == 'off') {
  2068. // 如果是关闭的就开成自动
  2069. this.onClimateAuto(e);
  2070. return
  2071. }
  2072. let domain = e.currentTarget.dataset.domain;
  2073. let entity_id = e.currentTarget.dataset.id;
  2074. let list = this.data.listClimate;//这里是将需要循环的数组赋值给list
  2075. let indexS = Number(e.currentTarget.dataset.index);
  2076. // 将本地缓存数据渲染到对应修改的案例
  2077. list.forEach(function (value, index, array) {
  2078. if (index == indexS) {
  2079. array[index].state = newValue;
  2080. }
  2081. })
  2082. this.setData({
  2083. temperatureHumidifyName: '关闭',
  2084. climateMode: 'off',
  2085. listClimate: list
  2086. })
  2087. let data = {
  2088. "entity_id": entity_id,
  2089. }
  2090. this.getService("/services", "/" + domain, "/turn_off", "POST", data);
  2091. },
  2092. handleInput: function (e) {
  2093. // 这里你需要自己实现歌曲列表和切换逻辑
  2094. // 例如,如果你有一个歌曲列表,你可以通过修改当前播放歌曲的索引来切换歌曲
  2095. // 假设你有一个歌曲列表`songs`和一个当前歌曲索引`currentIndex`
  2096. // if (this.data.currentIndex > 0) {
  2097. // this.data.currentIndex--;
  2098. // // 加载新歌曲并播放
  2099. // this.loadAndPlaySong(this.data.currentIndex);
  2100. // }
  2101. let min = e.currentTarget.dataset.min;
  2102. let max = e.currentTarget.dataset.max;
  2103. if (e.detail.value && (e.detail.value.length > max || e.detail.value.length < min)) {
  2104. wx.showModal({
  2105. title: '提示',
  2106. content: '文本长度介于' + min + '~' + max + '长度之间',
  2107. showCancel: false
  2108. });
  2109. return;
  2110. }
  2111. let domain = e.currentTarget.dataset.domain;
  2112. let entity_id = e.currentTarget.dataset.id;
  2113. let data = {
  2114. "entity_id": entity_id,
  2115. "value": e.detail.value,
  2116. }
  2117. this.getService("/services", "/" + domain, "/set_value", "POST", data);
  2118. },
  2119. onArrowDown(e) {
  2120. // 在这里处理向下箭头的点击事件
  2121. // 例如,你可以减少文本框的值
  2122. let currentValue = e.currentTarget.dataset.state;
  2123. let newValue = parseInt(currentValue) - 1; // 假设文本框中的是数字
  2124. // this.setData({
  2125. // inputValue: newValue.toString()
  2126. // });
  2127. let list = this.data.listUnit;//这里是将需要循环的数组赋值给list
  2128. let indexS = Number(e.currentTarget.dataset.index)
  2129. let domain = e.currentTarget.dataset.domain;
  2130. let entity_id = e.currentTarget.dataset.id;
  2131. // 将本地缓存数据渲染到对应修改的案例
  2132. list.forEach(function (value, index, array) {
  2133. if (index == indexS) {
  2134. array[index].state = newValue;
  2135. }
  2136. })
  2137. this.setData({
  2138. listUnit: list
  2139. })
  2140. let data = {
  2141. "entity_id": entity_id,
  2142. "value": newValue
  2143. }
  2144. this.getService("/services", "/" + domain, "/set_value", "POST", data);
  2145. },
  2146. prevSong: function (e) {
  2147. // 这里你需要自己实现歌曲列表和切换逻辑
  2148. // 例如,如果你有一个歌曲列表,你可以通过修改当前播放歌曲的索引来切换歌曲
  2149. // 假设你有一个歌曲列表`songs`和一个当前歌曲索引`currentIndex`
  2150. // if (this.data.currentIndex > 0) {
  2151. // this.data.currentIndex--;
  2152. // // 加载新歌曲并播放
  2153. // this.loadAndPlaySong(this.data.currentIndex);
  2154. // }
  2155. this.setData({
  2156. isClickedPrevSong: true
  2157. });
  2158. let domain = e.currentTarget.dataset.domain;
  2159. let entity_id = e.currentTarget.dataset.id;
  2160. let data = {
  2161. "entity_id": entity_id,
  2162. }
  2163. this.getService("/services", "/" + domain, "/media_previous_track", "POST", data);
  2164. // setTimeout(() => {
  2165. // this.getMiotMediaPlayer(this);
  2166. // }, 8000);
  2167. },
  2168. tvTurnOn: function (e) {
  2169. let domain = e.currentTarget.dataset.domain;
  2170. let entity_id = e.currentTarget.dataset.id;
  2171. let data = {
  2172. "entity_id": entity_id,
  2173. }
  2174. this.getService("/services", "/" + domain, "/turn_on", "POST", data);
  2175. },
  2176. tvTurnOff: function (e) {
  2177. let domain = e.currentTarget.dataset.domain;
  2178. let entity_id = e.currentTarget.dataset.id;
  2179. let data = {
  2180. "entity_id": entity_id,
  2181. }
  2182. this.getService("/services", "/" + domain, "/turn_off", "POST", data);
  2183. },
  2184. // 切换播放/暂停
  2185. togglePlayPause: function (e) {
  2186. // console.log("this.data.isPlaying="+this.data.isPlaying);
  2187. // if (this.data.isPlaying) {
  2188. // this.innerAudioContext.pause();
  2189. // this.setData({ isPlaying: false });
  2190. // this.getService("/services","/"+domain,"/media_pause","POST",null);
  2191. // } else {
  2192. // this.innerAudioContext.play();
  2193. // this.setData({ isPlaying: true });
  2194. // this.getService("/services","/"+domain,"/media_play","POST",null);
  2195. // }
  2196. // let list = this.data.listMiotMediaPlayer;//这里是将需要循环的数组赋值给list
  2197. this.setData({
  2198. isClickedTogglePlayPause: true
  2199. });
  2200. let indexS = Number(e.currentTarget.dataset.index)
  2201. let domain = e.currentTarget.dataset.domain;
  2202. let entity_id = e.currentTarget.dataset.id;
  2203. let state = e.currentTarget.dataset.state;
  2204. // 将本地缓存数据渲染到对应修改的案例
  2205. // list.forEach(function (value,index, array){
  2206. // if (index == indexS) {
  2207. // array[index].state = (state=='playing'?'idle':'playing');
  2208. // }
  2209. // })
  2210. // this.setData({
  2211. // listMiotMediaPlayer: list
  2212. // })
  2213. let data = {
  2214. "entity_id": entity_id,
  2215. }
  2216. this.getService("/services", "/" + domain, "/media_play_pause", "POST", data);
  2217. // 设置两秒(2000毫秒)后的延迟
  2218. // setTimeout(() => {
  2219. // this.getMiotMediaPlayer(this);
  2220. // }, 8000);
  2221. },
  2222. // 切换下一首歌曲
  2223. nextSong: function (e) {
  2224. // 和prevSong类似,你需要实现歌曲列表和切换逻辑
  2225. // 假设歌曲列表为`songs`,当前歌曲索引为`currentIndex`
  2226. // if (this.data.currentIndex < songs.length - 1) {
  2227. // this.data.currentIndex++;
  2228. // // 加载新歌曲并播放
  2229. // this.loadAndPlaySong(this.data.currentIndex);
  2230. // }
  2231. this.setData({
  2232. isClickedNextSong: true
  2233. });
  2234. let domain = e.currentTarget.dataset.domain;
  2235. let entity_id = e.currentTarget.dataset.id;
  2236. let data = {
  2237. "entity_id": entity_id,
  2238. }
  2239. this.getService("/services", "/" + domain, "/media_next_track", "POST", data);
  2240. // setTimeout(() => {
  2241. // this.getMiotMediaPlayer(this);
  2242. // }, 8000);
  2243. },
  2244. // 加载并播放指定索引的歌曲
  2245. loadAndPlaySong: function (index) {
  2246. // 假设你有一个歌曲列表`songs`,每个歌曲对象有`url`属性表示音频链接
  2247. const song = songs[index];
  2248. this.innerAudioContext.src = song.url;
  2249. this.innerAudioContext.play();
  2250. // 更新当前播放的歌曲信息(例如标题和艺术家)
  2251. this.setData({
  2252. currentSongTitle: song.title,
  2253. currentSongArtist: song.artist
  2254. });
  2255. },
  2256. base64Decode: function (input) {
  2257. const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  2258. let str = '';
  2259. let output = '';
  2260. let chr1, chr2, chr3;
  2261. let enc1, enc2, enc3, enc4;
  2262. let i = 0;
  2263. input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
  2264. while (i < input.length) {
  2265. enc1 = chars.indexOf(input.charAt(i++));
  2266. enc2 = chars.indexOf(input.charAt(i++));
  2267. enc3 = chars.indexOf(input.charAt(i++));
  2268. enc4 = chars.indexOf(input.charAt(i++));
  2269. chr1 = (enc1 << 2) | (enc2 >> 4);
  2270. chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
  2271. chr3 = ((enc3 & 3) << 6) | enc4;
  2272. str += String.fromCharCode(chr1);
  2273. if (enc3 != 64) {
  2274. str += String.fromCharCode(chr2);
  2275. }
  2276. if (enc4 != 64) {
  2277. str += String.fromCharCode(chr3);
  2278. }
  2279. }
  2280. return str;
  2281. },
  2282. onPickerChange: function (e) {
  2283. // this.setData({
  2284. // selectedIndex: e.detail.value
  2285. // });
  2286. // // 可以在这里处理选中值的变化,比如发送请求等
  2287. // console.log('选中的值是:', this.data.options[e.detail.value].value);
  2288. let list = this.data.listSelect;//这里是将需要循环的数组赋值给list
  2289. let indexS = Number(e.currentTarget.dataset.index)
  2290. let domain = e.currentTarget.dataset.domain;
  2291. let entity_id = e.currentTarget.dataset.id;
  2292. // 将本地缓存数据渲染到对应修改的案例
  2293. list.forEach(function (value, index, array) {
  2294. if (index == indexS) {
  2295. array[index].selectedIndex = e.detail.value;
  2296. }
  2297. })
  2298. this.setData({
  2299. listSelect: list
  2300. })
  2301. let data = {
  2302. "entity_id": entity_id,
  2303. "option": e.detail.value,
  2304. }
  2305. this.getService("/services", "/" + domain, "/select_option", "POST", data);
  2306. },
  2307. getService(services, domain, service, method, data) {
  2308. wx.request({
  2309. url: `${homeApi_https}` + services + domain + service,
  2310. method: method,
  2311. data: data,
  2312. header: {
  2313. 'content-type': 'application/json', // 默认值
  2314. 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  2315. },
  2316. success(res) {
  2317. console.log('res.data=====' + JSON.stringify(res.data));
  2318. },
  2319. });
  2320. },
  2321. // 初始化时调用即可
  2322. showCanvasRing() {
  2323. try {
  2324. //作画
  2325. var ctx = wx.createCanvasContext("circleBar", this); //canvas组建封装,需要后加个this
  2326. ctx.clearRect(0, 0, this.data.canvasWidth, this.data.canvasHeight); // 清除画布
  2327. var circle_r = this.data.canvasWidth / 2 - 10; //画布的一半,用来找中心点和半径
  2328. var scoreText = this.data.value; // 当前得分
  2329. var total = this.data.total;// 总分值
  2330. var score = (100 * scoreText) / total; // 满分为100时对应的值
  2331. let that = this;
  2332. //定义起始点
  2333. ctx.translate(this.data.canvasWidth / 2, this.data.canvasWidth / 2 + 5);
  2334. // 白边圆弧
  2335. ctx.beginPath();
  2336. ctx.setStrokeStyle("#FFFFFF");
  2337. ctx.setLineWidth(16);
  2338. ctx.setLineCap("round");
  2339. ctx.arc(0, 0, circle_r - 15, 1 * Math.PI, 0, false);
  2340. ctx.stroke();
  2341. ctx.closePath();
  2342. //灰色圆弧
  2343. ctx.beginPath();
  2344. ctx.setStrokeStyle("#D6E4FF");
  2345. ctx.setLineWidth(12);
  2346. ctx.setLineCap("round"); //线条结束端点样式 butt 平直 round 圆形 square 正方形
  2347. ctx.arc(0, 0, circle_r - 15, 1 * Math.PI, 0, false);
  2348. ctx.stroke();
  2349. ctx.closePath();
  2350. // 蓝色圆弧
  2351. ctx.beginPath();
  2352. ctx.setStrokeStyle("#3366FF");
  2353. ctx.setLineWidth(16);
  2354. ctx.arc(
  2355. 0,
  2356. 0,
  2357. circle_r - 15,
  2358. 1 * Math.PI,
  2359. (score / 100 + 1) * Math.PI,
  2360. false
  2361. );
  2362. ctx.stroke();
  2363. ctx.closePath();
  2364. // 指示器-外层
  2365. let deg = 270 - score * 1.8;
  2366. const xAxis = Math.sin(((2 * Math.PI) / 360) * deg) * (circle_r - 15);
  2367. const yAxis = Math.cos(((2 * Math.PI) / 360) * deg) * (circle_r - 15);
  2368. ctx.beginPath();
  2369. ctx.arc(xAxis, yAxis, 11, 0, 2 * Math.PI);
  2370. ctx.setFillStyle("#FFFFFF");
  2371. ctx.fill();
  2372. // 指示器-内层
  2373. const xAxis2 = Math.sin(((2 * Math.PI) / 360) * deg) * (circle_r - 15);
  2374. const yAxis2 = Math.cos(((2 * Math.PI) / 360) * deg) * (circle_r - 15); // circle_r - 10
  2375. ctx.beginPath();
  2376. ctx.arc(xAxis2, yAxis2, 6, 0, 2 * Math.PI);
  2377. ctx.setFillStyle("#3366FF");
  2378. ctx.fill();
  2379. // 文字-总得分
  2380. ctx.setTextAlign("center"); // 字体位置
  2381. ctx.setFillStyle("#333333");
  2382. ctx.font = "normal normal 16px Arial,sans-serif";
  2383. ctx.fillText("总得分", 0, -30);
  2384. // 文字-具体分数
  2385. ctx.setTextAlign("center"); // 字体位置
  2386. ctx.setFillStyle("#000000");
  2387. ctx.font = "normal bold 36px Arial,sans-serif";
  2388. ctx.fillText(scoreText, 0, 13);
  2389. // 最低分
  2390. ctx.setFillStyle("#666666");
  2391. ctx.font = "normal normal 13px Arial,sans-serif";
  2392. ctx.fillText(0, -circle_r + 10, 25);
  2393. // 最高分
  2394. ctx.setFillStyle("#666666");
  2395. ctx.font = "normal normal 13px Arial,sans-serif";
  2396. ctx.fillText(total, circle_r - 15, 25);
  2397. // 绘图
  2398. ctx.draw(false, function () {
  2399. //将生成好的图片保存到本地
  2400. wx.canvasToTempFilePath(
  2401. {
  2402. canvasId: "circleBar",
  2403. success: function (res) {
  2404. var tempFilePath = res.tempFilePath;
  2405. that.setData({
  2406. loadImagePath: tempFilePath,
  2407. });
  2408. },
  2409. fail: function (res) { },
  2410. },
  2411. );
  2412. });
  2413. } catch (error) {
  2414. }
  2415. },
  2416. getHAData(that, hotelcode, roomcode) {
  2417. let start = Date.now(); // 获取当前时间(毫秒)
  2418. // console.log('start=='+start);
  2419. wx.request({
  2420. url: `${aipushApi}/getha`, //
  2421. method: 'POST',
  2422. // header: {
  2423. // 'content-type': 'application/json', // 默认值
  2424. // 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  2425. // },
  2426. data: {
  2427. "locations": hotelcode, "room": (hotelcode && hotelcode.includes('hotel')) ? roomcode : "", "token": token_push
  2428. },
  2429. success(ress) {
  2430. if (!ress || !ress.data) {
  2431. console.error("getha(),没有获取到数据");
  2432. return;
  2433. }
  2434. var resData = ress.data
  2435. console.log("resData-==" + JSON.stringify(resData));
  2436. console.log("resData.loc-==" + JSON.stringify(resData.loc));
  2437. homeApi_https = resData.loc + "/api";
  2438. homeApiLater_https = resData.loc;
  2439. token = resData.token;
  2440. // console.log('res.data='+JSON.stringify(resData));
  2441. if (ress.data.code == "400") {
  2442. console.error("400错误!");
  2443. return;
  2444. }
  2445. if (ress.data.code == "401") {
  2446. console.error("401错误!");
  2447. return;
  2448. }
  2449. try {
  2450. //获取HA 设备状态数据
  2451. // wx.request({
  2452. // url: `${homeApi_https}/states`, //获取空气数据
  2453. // method: 'GET',
  2454. // header: {
  2455. // 'content-type': 'application/json', // 默认值
  2456. // 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  2457. // },
  2458. // success(res) {
  2459. // if(!res || !res.data){
  2460. // return;
  2461. // }
  2462. // var resData = res.data
  2463. // // console.log('res.data='+JSON.stringify(resData));
  2464. // if (res.data.code == "400") {
  2465. // console.error("400错误!");
  2466. // return;
  2467. // }
  2468. // if (res.data.code == "401") {
  2469. // console.error("401错误 --- 请检查你的API或Key是否正确!");
  2470. // return;
  2471. // }
  2472. // try {
  2473. // const {
  2474. // now
  2475. // } = res.data;
  2476. // console.log('res.data1='+JSON.stringify(resData));
  2477. // res.data.find(function (obj) {
  2478. // console.log('obj='+obj);
  2479. // })
  2480. // res.data.forEach((item, index) => {
  2481. // console.log(index, item);
  2482. // });
  2483. var listCoverTemp = [];
  2484. var listSwitchTemp = [];
  2485. var listScrollTemp = [];
  2486. var listUnitTemp = [];
  2487. var listConversationTemp = [];
  2488. var listConversation1Temp = [];
  2489. var listHumidityTemp = [];
  2490. var listButtonTemp = [];
  2491. var listSelectTemp = [];
  2492. var listClimateTemp = [];
  2493. var listMiotMediaPlayerTemp = [];
  2494. var listMitvMediaPlayerTemp = [];
  2495. var listHumidifierTemp = [];
  2496. var listSensorTemp = [];
  2497. var listTextTemp = [];
  2498. var tvEntityIdTemp = '';
  2499. var tvEntityIdsTemp = [];
  2500. var listAromatherapyMachineTemp = [];
  2501. var modelList1 = [];
  2502. var modelList2 = [];
  2503. var modelList3 = [];
  2504. var climateModeTemp = '';
  2505. var temperatureHumidifyNameTemp = '温度';
  2506. var humidityValueTemp = 0;
  2507. var humidityMaxTemp = 0;
  2508. var humidityMinTemp = 0;
  2509. var entityIdList = [];
  2510. const res = wx.getStorageSync('res');
  2511. const home_room = wx.getStorageSync('res').home_room;
  2512. // console.log('entity=====@==='+entity);
  2513. wx.request({
  2514. url: `${homeApi_https}/aidsleep/entity`, //获取空气数据
  2515. method: 'POST',
  2516. header: {
  2517. 'content-type': 'application/json', // 默认值
  2518. 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  2519. },
  2520. //
  2521. data: {
  2522. "template": "{{ label_entities('" + (entity) + "') }}"
  2523. },
  2524. success(resTemplate) {
  2525. let mid = Date.now(); // 再次获取当前时间(毫秒)
  2526. // console.log('mid=='+mid);
  2527. if (!resTemplate || !resTemplate.data) {
  2528. console.log('no data:' + mid);
  2529. return;
  2530. }
  2531. let resData = resTemplate.data;
  2532. // resData = resData.filter(item1 => {
  2533. // return JSON.parse(that.replaceAll(resTemplate.data,'\'','\"')).find(item2 => item2 === item1.entity_id) !== undefined;
  2534. // });
  2535. // console.log('entityIdList-resTemplate====='+JSON.stringify(resTemplate.data));
  2536. for (let i = 0; i < resData.length; i++) {
  2537. // if(resTemplate.data.includes(resData[i].entity_id) && that.checkFuzzyMatch(resData[i])){
  2538. var obj = {};
  2539. obj.entity_id = resData[i].entity_id;//实体ID
  2540. obj.parent_entity_id = resData[i].parent_entity_id;//父实体ID
  2541. //api/services/<domain>/<service>
  2542. if (resData[i].entity_id) {
  2543. obj.domain = resData[i].entity_id.split(".")[0];
  2544. }
  2545. obj.state = (resData[i].state == 'unknown' ? "未知" : resData[i].state);
  2546. if (resData[i].attributes && resData[i].attributes.friendly_name) {
  2547. obj.friendly_name = resData[i].attributes.friendly_name; //设备名称
  2548. if (obj.friendly_name.includes("灯带") || obj.friendly_name.includes("吸顶灯")) {
  2549. obj.imgSrc = '/static/icons/ic_dd_1.svg';
  2550. obj.selectedImgSrc = '/static/icons/ic_dd_2.svg';
  2551. obj.bg = 'background: linear-gradient(180deg, #DFFFFB 0%, #FFFFFF 53%)';
  2552. } else if (obj.friendly_name.includes("走廊灯")) {
  2553. obj.imgSrc = '/static/icons/ic_zld_1.svg';
  2554. obj.selectedImgSrc = '/static/icons/ic_zld_2.svg';
  2555. obj.bg = 'background: linear-gradient(180deg, #FFEEFA 0%, #FFFFFF 50%)';
  2556. } else if (obj.friendly_name.includes("筒灯")) {
  2557. obj.imgSrc = '/static/icons/ic_td_1.svg';
  2558. obj.selectedImgSrc = '/static/icons/ic_td_2.svg';
  2559. obj.bg = 'background: linear-gradient(180deg, #EBF0FF 0%, #FFFFFF 50%)';
  2560. } else if (obj.friendly_name.includes("主灯")) {
  2561. obj.imgSrc = '/static/icons/ic_zd_1.svg';
  2562. obj.selectedImgSrc = '/static/icons/ic_zd_2.svg';
  2563. obj.bg = 'background: linear-gradient(180deg, #EFE7FF 0%, #FFFFFF 50%)';
  2564. } else if (obj.friendly_name.includes("气扇")) {
  2565. obj.imgSrc = '/static/icons/ic_pqs_1.svg';
  2566. obj.selectedImgSrc = '/static/icons/ic_pqs_2.svg';
  2567. obj.bg = 'background: linear-gradient(180deg, #E3FFE6 0%, #FFFFFF 53%)';
  2568. } else if (obj.friendly_name.includes("电视")) {
  2569. obj.imgSrc = '/static/icons/ic_ds_1.svg';
  2570. obj.selectedImgSrc = '/static/icons/ic_ds_1.svg';
  2571. obj.bg = 'background: linear-gradient(180deg, #FFF2DF 0%, #FFFFFF 53%)';
  2572. } else if (obj.friendly_name.includes("空气净化器")) {
  2573. obj.imgSrc = '/static/icons/ic_kqjhq_1.svg';
  2574. obj.selectedImgSrc = '/static/icons/ic_kqjhq_2.svg';
  2575. obj.bg = 'background: linear-gradient(180deg, #EBFAFF 0%, #FFFFFF 50%)';
  2576. } else if (obj.friendly_name.includes("香薰机雾化")) {
  2577. obj.imgSrc = '/static/icons/ic_xxjwh.svg';
  2578. obj.selectedImgSrc = '/static/icons/ic_xxjwh.svg';
  2579. } else if (obj.friendly_name.endsWith('香薰机')) {
  2580. obj.imgSrc = '/static/icons/ic_xxj.svg';
  2581. obj.selectedImgSrc = '/static/icons/ic_xxj.svg';
  2582. } else if (obj.friendly_name.includes("灯")) {
  2583. obj.imgSrc = '/static/icons/ic_dd_1.svg';
  2584. obj.selectedImgSrc = '/static/icons/ic_dd_2.svg';
  2585. obj.bg = 'background: linear-gradient(180deg, #DFFFFB 0%, #FFFFFF 53%)';
  2586. } else {
  2587. obj.imgSrc = '/static/icons/ic_ds_1.svg';
  2588. obj.selectedImgSrc = '/static/icons/ic_ds_1.svg';
  2589. obj.bg = 'background: linear-gradient(180deg, #FFF2DF 0%, #FFFFFF 53%)';
  2590. }
  2591. }
  2592. if (resData[i].attributes && resData[i].attributes.home_room) {
  2593. obj.home_room = resData[i].attributes.home_room.split(' ')[1]; //房间号
  2594. }
  2595. if (resData[i].state && that.checkFuzzyMatch(resData[i])
  2596. ) {
  2597. if (resData[i].state == 'on') {
  2598. obj.service = 'turn_on';
  2599. } else if (resData[i].state == 'off') {
  2600. obj.service = 'turn_off';
  2601. }
  2602. //截取字符串,防止开关设备名称过长
  2603. obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name, roomcode);
  2604. //是否 是香薰机灯光
  2605. obj.isAromlight = obj.friendly_name.includes('香薰机灯光')
  2606. obj.isAromAtomization = obj.friendly_name.includes('香薰机雾化')
  2607. obj.isAromatherapy = obj.friendly_name.endsWith('香薰机')
  2608. if (obj.entity_id && obj.state && checkState(obj.state) && obj.friendly_name && obj.domain && obj.domain != 'automation' && !obj.isAromlight && !obj.isAromAtomization && !obj.isAromatherapy) {
  2609. listSwitchTemp.push(obj)
  2610. } else if ((obj.isAromlight || obj.isAromAtomization || obj.isAromatherapy) && checkState(obj.state)) {
  2611. listAromatherapyMachineTemp.push(obj)
  2612. }
  2613. }
  2614. if ((resData[i].state && obj.domain && obj.domain == 'cover') && that.checkFuzzyMatch(resData[i])
  2615. ) {
  2616. obj.current_position = resData[i].attributes.current_position;
  2617. obj.target_position = resData[i].attributes.target_position;
  2618. obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name, roomcode);
  2619. if (obj.entity_id && obj.state && checkState(obj.state) && obj.friendly_name && obj.domain) {
  2620. listCoverTemp.push(obj)
  2621. }
  2622. }
  2623. // if((resData[i].state && obj.domain && obj.domain=='number')||
  2624. // (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)
  2625. // )
  2626. // ){
  2627. // obj.min = resData[i].attributes.min;
  2628. // obj.max = resData[i].attributes.max;
  2629. // obj.step = resData[i].attributes.step;
  2630. // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
  2631. // if(resData[i].state!='unknown'){
  2632. // obj.unit_of_measurement = resData[i].attributes.unit_of_measurement;
  2633. // }
  2634. // if((resData[i].attributes.min || resData[i].attributes.max) && resData[i].attributes.unit_of_measurement!='rgb' && resData[i].attributes.unit_of_measurement!='minutes'){
  2635. // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
  2636. // listScrollTemp.push(obj);
  2637. // }
  2638. // }else if((resData[i].attributes.min || resData[i].attributes.max) && (resData[i].attributes.unit_of_measurement=='rgb' || resData[i].attributes.unit_of_measurement=='minutes')){
  2639. // if(resData[i].state!='unknown'){
  2640. // obj.unit_of_measurement = resData[i].attributes.unit_of_measurement;
  2641. // }
  2642. // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
  2643. // listUnitTemp.push(obj);
  2644. // }
  2645. // }
  2646. // }
  2647. // if((resData[i].state && obj.domain && obj.domain=='button')||
  2648. // (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)
  2649. // )
  2650. // ){
  2651. // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
  2652. // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
  2653. // listButtonTemp.push(obj);
  2654. // }
  2655. // }
  2656. // if((resData[i].state && obj.domain && obj.domain=='select')||
  2657. // (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)
  2658. // )
  2659. // ){
  2660. // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
  2661. // obj.options = resData[i].attributes.options;
  2662. // obj.selectedIndex = 0;
  2663. // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
  2664. // listSelectTemp.push(obj);
  2665. // }
  2666. // }
  2667. if ((resData[i].state && obj.domain && obj.domain == 'climate' && resData[i].attributes.entity_class == 'MiirClimateEntity')
  2668. ) {
  2669. climateModeTemp = obj.state;
  2670. obj.temperature = resData[i].attributes.temperature;
  2671. obj.min_temp = resData[i].attributes.min_temp;
  2672. obj.max_temp = resData[i].attributes.max_temp;
  2673. obj.hvac_modes = resData[i].attributes.hvac_modes;
  2674. obj.fan_modes = resData[i].attributes.fan_modes;
  2675. obj.fan_mode = resData[i].attributes.fan_mode;
  2676. obj.target_temp_step = resData[i].attributes.target_temp_step;
  2677. if (obj.state == 'auto') {
  2678. temperatureHumidifyNameTemp = '自动';
  2679. }
  2680. if (obj.state == 'heat') {
  2681. temperatureHumidifyNameTemp = '制热';
  2682. }
  2683. if (obj.state == 'cool') {
  2684. temperatureHumidifyNameTemp = '制冷';
  2685. }
  2686. if (obj.state == 'dry') {
  2687. temperatureHumidifyNameTemp = '除湿';
  2688. }
  2689. if (obj.state == 'fan_only') {
  2690. temperatureHumidifyNameTemp = '送风';
  2691. }
  2692. if (obj.state == 'off') {
  2693. temperatureHumidifyNameTemp = '关闭';
  2694. }
  2695. if (obj.entity_id && obj.state && obj.friendly_name && obj.domain) {
  2696. listClimateTemp.push(obj);
  2697. }
  2698. }
  2699. if ((resData[i].state && obj.domain && obj.domain == 'media_player' && resData[i].attributes.entity_class == 'MiotMediaPlayerEntity') && that.checkFuzzyMatch(resData[i])
  2700. ) {
  2701. // obj["speaker.volume"] = resData[i].attribute["speaker.volume"];
  2702. obj.repeat = resData[i].attributes.repeat;
  2703. 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;";
  2704. obj.media_title = resData[i].attributes.media_title;
  2705. obj.media_artist = resData[i].attributes.media_artist;
  2706. obj.volume_level = resData[i].attributes.volume_level ? (resData[i].attributes.volume_level * 100) : 0;
  2707. obj.media_duration = resData[i].attributes.media_duration;
  2708. obj.media_position = resData[i].attributes.media_position;
  2709. obj.media_late = resData[i].attributes.media_position + '/' + resData[i].attributes.media_duration;
  2710. // obj.microphone.mute = resData[i].attributes.microphone.mute;
  2711. // obj.speaker.mute = resData[i].attributes.speaker.mute;
  2712. // console.log('media-player-miot-obj=='+obj);
  2713. if (obj.entity_id && obj.state && checkState(obj.state) && obj.friendly_name && obj.domain ) {
  2714. listMiotMediaPlayerTemp.push(obj);
  2715. }
  2716. }
  2717. // if((resData[i].state && obj.domain && obj.domain=='media_player' && resData[i].attributes.entity_class=='MitvMediaPlayerEntity')||
  2718. // (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)
  2719. // )
  2720. // ){
  2721. // obj.volume_level = resData[i].attributes.volume_level;
  2722. // obj.is_volume_muted = resData[i].attributes.is_volume_muted;
  2723. // obj.source = resData[i].attributes.source;
  2724. // 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;";
  2725. // obj.media_title = resData[i].attributes.media_title;
  2726. // obj.media_artist = resData[i].attributes.media_artist;
  2727. // obj.volume_level = resData[i].attributes.volume_level?(resData[i].attributes.volume_level * 100):0;
  2728. // obj.media_duration = resData[i].attributes.media_duration;
  2729. // obj.media_position = resData[i].attributes.media_position;
  2730. // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
  2731. // listMitvMediaPlayerTemp.push(obj);
  2732. // }
  2733. // }
  2734. if ((resData[i].state && obj.domain && obj.domain == 'media_player') && that.checkFuzzyMatch(resData[i])
  2735. ) {
  2736. obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name, roomcode);
  2737. 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('电视'))) {
  2738. obj.volume_level = resData[i].attributes.volume_level;
  2739. obj.is_volume_muted = resData[i].attributes.is_volume_muted;
  2740. obj.source = resData[i].attributes.source;
  2741. 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;";
  2742. obj.media_title = resData[i].attributes.media_title;
  2743. obj.media_artist = resData[i].attributes.media_artist;
  2744. obj.volume_level = resData[i].attributes.volume_level ? (resData[i].attributes.volume_level * 100) : 0;
  2745. obj.media_duration = resData[i].attributes.media_duration;
  2746. obj.media_position = resData[i].attributes.media_position;
  2747. obj.media_late = resData[i].attributes.media_position + '/' + resData[i].attributes.media_duration;
  2748. // obj["speaker.volume"] = resData[i].attributes["speaker.volume"];
  2749. // console.log('media-player-mitv-obj=='+obj);
  2750. obj.device_class = resData[i].attributes.device_class;
  2751. obj.app_id = resData[i].attributes.app_id;
  2752. obj.app_name = resData[i].attributes.app_name;
  2753. if (obj.entity_id && obj.state && checkState(obj.state) && obj.friendly_name && obj.domain) {
  2754. listMitvMediaPlayerTemp.push(obj);
  2755. }
  2756. obj.friendly_name1 = resData[i].attributes.friendly_name;
  2757. tvEntityIdsTemp.push(obj);
  2758. // let obj1 = {};
  2759. // obj1.entity_id = obj.entity_id;
  2760. // obj1.friendly_name1 = resData[i].attributes.friendly_name;
  2761. // tvEntityIdsTemp.push(obj1);
  2762. tvEntityIdTemp = obj.entity_id;
  2763. // console.log('obj===='+obj);
  2764. // console.log('tvEntityIdTemp='+tvEntityIdTemp);
  2765. wx.setStorageSync('tvEntityId', tvEntityIdTemp);
  2766. }
  2767. }
  2768. if ((resData[i].state && obj.domain && obj.domain == 'humidifier')
  2769. ) {
  2770. // 加湿器
  2771. obj.min_humidity = resData[i].attributes.min_humidity;
  2772. obj.max_humidity = resData[i].attributes.max_humidity;
  2773. obj.humidity = resData[i].attributes.humidity;
  2774. obj.min = obj.min_humidity;
  2775. obj.max = obj.max_humidity;
  2776. humidityValueTemp = obj.humidity;
  2777. humidityMaxTemp = obj.max;
  2778. humidityMinTemp = obj.min;
  2779. // console.log('humidifier-obj=='+JSON.stringify(obj));
  2780. if (obj.entity_id && obj.state && checkState(obj.state) && obj.friendly_name && obj.domain) {
  2781. listHumidifierTemp.push(obj);
  2782. }
  2783. }
  2784. if ((resData[i].state && obj.domain && obj.domain == 'automation')) {
  2785. console.log("", resData[i].attributes.friendly_name);
  2786. if (resData[i].attributes.friendly_name.endsWith('起床模式')) {
  2787. modelList1.push(obj)
  2788. } else if (resData[i].attributes.friendly_name.endsWith('观影模式')) {
  2789. modelList2.push(obj)
  2790. } else if (resData[i].attributes.friendly_name.endsWith('睡眠模式')) {
  2791. modelList3.push(obj)
  2792. }
  2793. }
  2794. // if((resData[i].state && obj.domain && obj.domain=='sensor')||
  2795. // (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)
  2796. // )
  2797. // ){
  2798. // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
  2799. // obj.unit_of_measurement = resData[i].attributes.unit_of_measurement;
  2800. // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
  2801. // listSensorTemp.push(obj);
  2802. // }
  2803. // }
  2804. // if((resData[i].state && obj.domain && obj.domain=='text')||
  2805. // (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)
  2806. // )
  2807. // ){
  2808. // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
  2809. // obj.min = resData[i].attributes.min;
  2810. // obj.max = resData[i].attributes.max;
  2811. // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
  2812. // listTextTemp.push(obj);
  2813. // }
  2814. // }
  2815. // if((resData[i].state && obj.friendly_name && obj.friendly_name.includes("智能音箱"))
  2816. // || (resData[i].state && resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id)
  2817. // && obj.friendly_name && obj.friendly_name.includes("智能音箱"))
  2818. // ){
  2819. // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
  2820. // listConversationTemp.push(obj)
  2821. // }
  2822. // }
  2823. // if((resData[i].state && resData[i].attributes && resData[i].attributes.speaker && resData[i].attributes.speaker.volume && obj.friendly_name && obj.friendly_name.includes("智能音箱"))||
  2824. // (resData[i].state && resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id)
  2825. // && resData[i].attributes.speaker && resData[i].attributes.speaker.volume && obj.friendly_name && obj.friendly_name.includes("智能音箱"))
  2826. // ){
  2827. // obj.volume = resData[i].attributes.speaker.volume;//音量
  2828. // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
  2829. // listConversation1Temp.push(obj)
  2830. // }
  2831. // }
  2832. //加湿器单独拿出来
  2833. // if((obj.friendly_name && obj.friendly_name.includes("加湿器"))||
  2834. // (resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id)
  2835. // && obj.friendly_name && obj.friendly_name.includes("加湿器"))
  2836. // ){
  2837. // listHumidityTemp.push(obj)
  2838. // }
  2839. // }
  2840. }
  2841. that.setData({
  2842. // status_beep: that.getEntityState(res.data,'switch.xiaomi_pro3_02bd_left_switch_service'), //实验室主灯
  2843. // status_led: that.getEntityState(res.data,'light.deerma_jsq2g_392f_indicator_light'), //加湿器 Indicator Light
  2844. // status_san: that.getEntityState(res.data,'switch.xwhzp_xwxfj_a441_diffuser'), //香薰机 Diffuser
  2845. // status_curtain: that.getEntityState(res.data,'switch.xiaomi_pro3_02bd_middle_switch_service'), //实验室侧灯
  2846. // status_door: that.getEntityState(res.data,'remote.xiaomi_lx06_f593_wifispeaker_4'), //智能音箱
  2847. // Temp: that.getEntityStateValue(res.data,'sensor.deerma_jsq2g_392f_temperature'), //加湿器温度
  2848. // Humi: that.getEntityStateValue(res.data,'sensor.deerma_jsq2g_392f_relative_humidity'), //加湿器湿度
  2849. // Light: that.getEntityStateValue(res.data,'number.xwhzp_xwxfj_a441_brightness'), //香薰机亮度
  2850. // LiquidLevel: that.getEntityStateValue(res.data,'sensor.xwhzp_xwxfj_a441_fragrance_liquid_left_level'), //香薰液浓度
  2851. modelList1,
  2852. modelList2,
  2853. modelList3,
  2854. listSwitch: listSwitchTemp,
  2855. listUnit: listUnitTemp,
  2856. listScroll: listScrollTemp,
  2857. listConversation: listConversationTemp,
  2858. listConversation1: listConversation1Temp,
  2859. listHumidity: listHumidityTemp,
  2860. listButton: listButtonTemp,
  2861. listSelect: listSelectTemp,
  2862. listClimate: listClimateTemp,
  2863. listMiotMediaPlayer: listMiotMediaPlayerTemp,
  2864. listMitvMediaPlayer: listMitvMediaPlayerTemp,
  2865. listHumidifier: listHumidifierTemp,
  2866. listSensor: listSensorTemp,
  2867. listText: listTextTemp,
  2868. tvEntityId: tvEntityIdTemp,
  2869. tvEntityIds: tvEntityIdsTemp,
  2870. climateMode: climateModeTemp,
  2871. temperatureHumidifyName: temperatureHumidifyNameTemp,
  2872. listCover: listCoverTemp,
  2873. listAromatherapyMachine: listAromatherapyMachineTemp,
  2874. // ecHumidifier: {
  2875. // onInit: that.initChartHumidifier
  2876. // },
  2877. sliderValueHumidifier: ''
  2878. })
  2879. if (listHumidifierTemp.length && humidityValue != humidityValueTemp) {
  2880. humidityValue = humidityValueTemp;
  2881. humidityMin = humidityMinTemp;
  2882. humidityMax = humidityMaxTemp;
  2883. that.checkHumidityMarginLeft()
  2884. that.initChartHumidifier();
  2885. }
  2886. wx.setStorageSync('tvEntityIds', tvEntityIdsTemp);
  2887. // console.log('listMiotMediaPlayerTemp='+JSON.stringify(listMiotMediaPlayerTemp));
  2888. // console.log('listHumidityTemp='+JSON.stringify(listHumidityTemp));
  2889. // console.log('listClimateTemp='+JSON.stringify(listClimateTemp));
  2890. // console.log('listSwitchTemp='+JSON.stringify(listSwitchTemp));
  2891. console.log('tvEntityIdsTemp=' + JSON.stringify(tvEntityIdsTemp));
  2892. // console.log('listMitvMediaPlayerTemp='+JSON.stringify(listMitvMediaPlayerTemp));
  2893. console.log('listHumidifierTemp=' + JSON.stringify(listHumidifierTemp));
  2894. },
  2895. });
  2896. // } catch (error) {
  2897. // console.error(error);
  2898. // }
  2899. // },
  2900. // });
  2901. } catch (error) {
  2902. console.error(error);
  2903. }
  2904. },
  2905. fail: function (error) {
  2906. console.error('error', error);
  2907. that.setData({
  2908. isLoading: false,
  2909. });
  2910. }
  2911. });
  2912. let end = Date.now(); // 再次获取当前时间(毫秒)
  2913. // console.log('end=='+end);
  2914. let executionTime = end - start;
  2915. // console.log(`myFunctionToTest 执行时间为: ${executionTime} 毫秒`);
  2916. return true;
  2917. },
  2918. getHADataStart(that, hotelcode, roomcode) {
  2919. let start = Date.now(); // 获取当前时间(毫秒)
  2920. console.log('start==' + start);
  2921. var that = this;
  2922. wx.request({
  2923. url: `${aipushApi}/getha`, //
  2924. method: 'POST',
  2925. // header: {
  2926. // 'content-type': 'application/json', // 默认值
  2927. // 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  2928. // },
  2929. data: {
  2930. "locations": hotelcode, "room": (hotelcode && hotelcode.includes('hotel')) ? roomcode : "", "token": token_push
  2931. },
  2932. success(ress) {
  2933. if (!ress || !ress.data) {
  2934. console.error("getha(),没有获取到数据");
  2935. return;
  2936. }
  2937. var resData = ress.data
  2938. console.log("resData-==" + JSON.stringify(resData));
  2939. console.log("resData.loc-==" + JSON.stringify(resData.loc));
  2940. homeApi_https = resData.loc + "/api";
  2941. homeApiLater_https = resData.loc;
  2942. token = resData.token;
  2943. // console.log('res.data='+JSON.stringify(resData));
  2944. if (ress.data.code == "400") {
  2945. console.error("400错误!");
  2946. return;
  2947. }
  2948. if (ress.data.code == "401") {
  2949. console.error("401错误!");
  2950. return;
  2951. }
  2952. try {
  2953. //获取HA 设备状态数据
  2954. // wx.request({
  2955. // url: `${homeApi_https}/states`,
  2956. // method: 'GET',
  2957. // header: {
  2958. // 'content-type': 'application/json', // 默认值
  2959. // 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  2960. // },
  2961. // success(res) {
  2962. // if(!res || !res.data){
  2963. // that.setData({
  2964. // isLoading: false,
  2965. // });
  2966. // return;
  2967. // }
  2968. // var resData = res.data
  2969. // // console.log('res.data='+JSON.stringify(resData));
  2970. // if (res.data.code == "400") {
  2971. // console.error("400错误!");
  2972. // return;
  2973. // }
  2974. // if (res.data.code == "401") {
  2975. // console.error("401错误 --- 请检查你的API或Key是否正确!");
  2976. // return;
  2977. // }
  2978. // try {
  2979. // const {
  2980. // now
  2981. // } = res.data;
  2982. // console.log('res.data1='+JSON.stringify(resData));
  2983. // res.data.find(function (obj) {
  2984. // console.log('obj='+obj);
  2985. // })
  2986. // res.data.forEach((item, index) => {
  2987. // console.log(index, item);
  2988. // });
  2989. var listCoverTemp = [];
  2990. var listSwitchTemp = [];
  2991. var listScrollTemp = [];
  2992. var listUnitTemp = [];
  2993. var listConversationTemp = [];
  2994. var listConversation1Temp = [];
  2995. var listHumidityTemp = [];
  2996. var listButtonTemp = [];
  2997. var listSelectTemp = [];
  2998. var listClimateTemp = [];
  2999. var listMiotMediaPlayerTemp = [];
  3000. var listMitvMediaPlayerTemp = [];
  3001. var listHumidifierTemp = [];
  3002. var listSensorTemp = [];
  3003. var listTextTemp = [];
  3004. var tvEntityIdTemp = '';
  3005. var tvEntityIdsTemp = [];
  3006. var listAromatherapyMachineTemp = [];
  3007. var humidityValueTemp = 0;
  3008. var humidityMaxTemp = 0;
  3009. var humidityMinTemp = 0;
  3010. var climateModeTemp = '';
  3011. var temperatureHumidifyNameTemp = '温度';
  3012. var modelList1 = [];
  3013. var modelList2 = [];
  3014. var modelList3 = [];
  3015. var entityIdList = [];
  3016. const res = wx.getStorageSync('res');
  3017. const home_room = wx.getStorageSync('res').home_room;
  3018. // console.log('entity=====@==='+entity);
  3019. wx.request({
  3020. url: `${homeApi_https}/aidsleep/entity`, //获取空气数据
  3021. method: 'POST',
  3022. header: {
  3023. 'content-type': 'application/json', // 默认值
  3024. 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  3025. },
  3026. //
  3027. data: {
  3028. "template": "{{ label_entities('" + (entity) + "') }}"
  3029. },
  3030. success(resTemplate) {
  3031. let mid = Date.now(); // 再次获取当前时间(毫秒)
  3032. // console.log('mid=='+mid);
  3033. if (!resTemplate || !resTemplate.data) {
  3034. console.log('no data:' + mid);
  3035. return;
  3036. }
  3037. let resData = resTemplate.data;
  3038. // resData = resData.filter(item1 => {
  3039. // return JSON.parse(that.replaceAll(resTemplate.data,'\'','\"')).find(item2 => item2 === item1.entity_id) !== undefined;
  3040. // });
  3041. console.log("resData-union=" + JSON.stringify(resData));
  3042. // console.log('entityIdList-resTemplate====='+JSON.stringify(resTemplate.data));
  3043. for (let i = 0; i < resData.length; i++) {
  3044. // if(resTemplate.data.includes(resData[i].entity_id) && that.checkFuzzyMatch(resData[i])){
  3045. var obj = {};
  3046. obj.entity_id = resData[i].entity_id;//实体ID
  3047. obj.parent_entity_id = resData[i].parent_entity_id;//父实体ID
  3048. //api/services/<domain>/<service>
  3049. if (resData[i].entity_id) {
  3050. obj.domain = resData[i].entity_id.split(".")[0];
  3051. }
  3052. obj.state = (resData[i].state == 'unknown' ? "未知" : resData[i].state);
  3053. if (resData[i].attributes && resData[i].attributes.friendly_name) {
  3054. obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name, roomcode); //设备名称
  3055. if (obj.friendly_name.includes("灯带") || obj.friendly_name.includes("吸顶灯")) {
  3056. obj.imgSrc = '/static/icons/ic_dd_1.svg';
  3057. obj.selectedImgSrc = '/static/icons/ic_dd_2.svg';
  3058. obj.bg = 'background: linear-gradient(180deg, #DFFFFB 0%, #FFFFFF 53%)';
  3059. } else if (obj.friendly_name.includes("走廊灯")) {
  3060. obj.imgSrc = '/static/icons/ic_zld_1.svg';
  3061. obj.selectedImgSrc = '/static/icons/ic_zld_2.svg';
  3062. obj.bg = 'background: linear-gradient(180deg, #FFEEFA 0%, #FFFFFF 50%)';
  3063. } else if (obj.friendly_name.includes("筒灯")) {
  3064. obj.imgSrc = '/static/icons/ic_td_1.svg';
  3065. obj.selectedImgSrc = '/static/icons/ic_td_2.svg';
  3066. obj.bg = 'background: linear-gradient(180deg, #EBF0FF 0%, #FFFFFF 50%)';
  3067. } else if (obj.friendly_name.includes("主灯")) {
  3068. obj.imgSrc = '/static/icons/ic_zd_1.svg';
  3069. obj.selectedImgSrc = '/static/icons/ic_zd_2.svg';
  3070. obj.bg = 'background: linear-gradient(180deg, #EFE7FF 0%, #FFFFFF 50%)';
  3071. } else if (obj.friendly_name.includes("气扇")) {
  3072. obj.imgSrc = '/static/icons/ic_pqs_1.svg';
  3073. obj.selectedImgSrc = '/static/icons/ic_pqs_2.svg';
  3074. obj.bg = 'background: linear-gradient(180deg, #E3FFE6 0%, #FFFFFF 53%)';
  3075. } else if (obj.friendly_name.includes("电视")) {
  3076. obj.imgSrc = '/static/icons/ic_ds_1.svg';
  3077. obj.selectedImgSrc = '/static/icons/ic_ds_1.svg';
  3078. obj.bg = 'background: linear-gradient(180deg, #FFF2DF 0%, #FFFFFF 53%)';
  3079. } else if (obj.friendly_name.includes("空气净化器")) {
  3080. obj.imgSrc = '/static/icons/ic_kqjhq_1.svg';
  3081. obj.selectedImgSrc = '/static/icons/ic_kqjhq_2.svg';
  3082. obj.bg = 'background: linear-gradient(180deg, #EBFAFF 0%, #FFFFFF 50%)';
  3083. } else if (obj.friendly_name.includes("香薰机雾化")) {
  3084. obj.imgSrc = '/static/icons/ic_xxjwh.svg';
  3085. obj.selectedImgSrc = '/static/icons/ic_xxjwh.svg';
  3086. } else if (obj.friendly_name.endsWith('香薰机')) {
  3087. obj.imgSrc = '/static/icons/ic_xxj.svg';
  3088. obj.selectedImgSrc = '/static/icons/ic_xxj.svg';
  3089. }
  3090. else if (obj.friendly_name.includes("灯")) {
  3091. obj.imgSrc = '/static/icons/ic_dd_1.svg';
  3092. obj.selectedImgSrc = '/static/icons/ic_dd_2.svg';
  3093. obj.bg = 'background: linear-gradient(180deg, #DFFFFB 0%, #FFFFFF 53%)';
  3094. }
  3095. else {
  3096. obj.imgSrc = '/static/icons/ic_ds_1.svg';
  3097. obj.selectedImgSrc = '/static/icons/ic_ds_1.svg';
  3098. obj.bg = 'background: linear-gradient(180deg, #FFF2DF 0%, #FFFFFF 53%)';
  3099. }
  3100. }
  3101. if (resData[i].attributes && resData[i].attributes.home_room) {
  3102. obj.home_room = resData[i].attributes.home_room.split(' ')[1]; //房间号
  3103. }
  3104. if ((resData[i].state && (resData[i].state == 'on' || resData[i].state == 'off')) && that.checkFuzzyMatch(resData[i])
  3105. ) {
  3106. if (resData[i].state == 'on') {
  3107. obj.service = 'turn_on';
  3108. } else if (resData[i].state == 'off') {
  3109. obj.service = 'turn_off';
  3110. }
  3111. //截取字符串,防止开关设备名称过长
  3112. obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name, roomcode);
  3113. //是否 是香薰机灯光
  3114. obj.isAromlight = obj.friendly_name.includes('香薰机灯光')
  3115. obj.isAromAtomization = obj.friendly_name.includes('香薰机雾化')
  3116. obj.isAromatherapy = obj.friendly_name.endsWith('香薰机')
  3117. 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) {
  3118. listSwitchTemp.push(obj)
  3119. } else if ((obj.isAromlight || obj.isAromAtomization || obj.isAromatherapy) && checkState(obj.state)) {
  3120. listAromatherapyMachineTemp.push(obj)
  3121. }
  3122. }
  3123. if ((resData[i].state && obj.domain && obj.domain == 'cover') && that.checkFuzzyMatch(resData[i])
  3124. ) {
  3125. obj.current_position = resData[i].attributes.current_position;
  3126. obj.target_position = resData[i].attributes.target_position;
  3127. obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name, roomcode);
  3128. if (obj.entity_id && obj.state && checkState(obj.state) && obj.friendly_name && obj.domain) {
  3129. listCoverTemp.push(obj)
  3130. }
  3131. }
  3132. // if((resData[i].state && obj.domain && obj.domain=='number')||
  3133. // (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)
  3134. // )
  3135. // ){
  3136. // obj.min = resData[i].attributes.min;
  3137. // obj.max = resData[i].attributes.max;
  3138. // obj.step = resData[i].attributes.step;
  3139. // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
  3140. // if(resData[i].state!='unknown'){
  3141. // obj.unit_of_measurement = resData[i].attributes.unit_of_measurement;
  3142. // }
  3143. // if((resData[i].attributes.min || resData[i].attributes.max) && resData[i].attributes.unit_of_measurement!='rgb' && resData[i].attributes.unit_of_measurement!='minutes'){
  3144. // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
  3145. // listScrollTemp.push(obj);
  3146. // }
  3147. // }else if((resData[i].attributes.min || resData[i].attributes.max) && (resData[i].attributes.unit_of_measurement=='rgb' || resData[i].attributes.unit_of_measurement=='minutes')){
  3148. // if(resData[i].state!='unknown'){
  3149. // obj.unit_of_measurement = resData[i].attributes.unit_of_measurement;
  3150. // }
  3151. // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
  3152. // listUnitTemp.push(obj);
  3153. // }
  3154. // }
  3155. // }
  3156. // if((resData[i].state && obj.domain && obj.domain=='button')||
  3157. // (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)
  3158. // )
  3159. // ){
  3160. // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
  3161. // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
  3162. // listButtonTemp.push(obj);
  3163. // }
  3164. // }
  3165. // if((resData[i].state && obj.domain && obj.domain=='select')||
  3166. // (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)
  3167. // )
  3168. // ){
  3169. // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
  3170. // obj.options = resData[i].attributes.options;
  3171. // obj.selectedIndex = 0;
  3172. // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
  3173. // listSelectTemp.push(obj);
  3174. // }
  3175. // }
  3176. if ((resData[i].state && obj.domain && obj.domain == 'climate' && resData[i].attributes.entity_class == 'MiirClimateEntity')
  3177. ) {
  3178. climateModeTemp = obj.state;
  3179. obj.temperature = resData[i].attributes.temperature;
  3180. obj.min_temp = resData[i].attributes.min_temp;
  3181. obj.max_temp = resData[i].attributes.max_temp;
  3182. obj.hvac_modes = resData[i].attributes.hvac_modes;
  3183. obj.fan_modes = resData[i].attributes.fan_modes;
  3184. obj.fan_mode = resData[i].attributes.fan_mode;
  3185. obj.target_temp_step = resData[i].attributes.target_temp_step;
  3186. if (obj.state == 'auto') {
  3187. temperatureHumidifyNameTemp = '自动';
  3188. }
  3189. if (obj.state == 'heat') {
  3190. temperatureHumidifyNameTemp = '制热';
  3191. }
  3192. if (obj.state == 'cool') {
  3193. temperatureHumidifyNameTemp = '制冷';
  3194. }
  3195. if (obj.state == 'dry') {
  3196. temperatureHumidifyNameTemp = '除湿';
  3197. }
  3198. if (obj.state == 'fan_only') {
  3199. temperatureHumidifyNameTemp = '送风';
  3200. }
  3201. if (obj.state == 'off') {
  3202. temperatureHumidifyNameTemp = '关闭';
  3203. }
  3204. if (obj.entity_id && obj.state && obj.friendly_name && obj.domain) {
  3205. listClimateTemp.push(obj);
  3206. }
  3207. }
  3208. if ((resData[i].state && obj.domain && obj.domain == 'media_player' && resData[i].attributes.entity_class == 'MiotMediaPlayerEntity') && that.checkFuzzyMatch(resData[i])
  3209. ) {
  3210. // obj["speaker.volume"] = resData[i].attribute["speaker.volume"];
  3211. obj.repeat = resData[i].attributes.repeat;
  3212. 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;";
  3213. obj.media_title = resData[i].attributes.media_title;
  3214. obj.media_artist = resData[i].attributes.media_artist;
  3215. obj.volume_level = resData[i].attributes.volume_level ? (resData[i].attributes.volume_level * 100) : 0;
  3216. obj.media_duration = resData[i].attributes.media_duration;
  3217. obj.media_position = resData[i].attributes.media_position;
  3218. obj.media_late = resData[i].attributes.media_position + '/' + resData[i].attributes.media_duration;
  3219. // obj.microphone.mute = resData[i].attributes.microphone.mute;
  3220. // obj.speaker.mute = resData[i].attributes.speaker.mute;
  3221. // console.log('media-player-miot-obj=='+obj);
  3222. if (obj.entity_id && obj.state && checkState(obj.state) && obj.friendly_name && obj.domain) {
  3223. listMiotMediaPlayerTemp.push(obj);
  3224. }
  3225. }
  3226. // if((resData[i].state && obj.domain && obj.domain=='media_player' && resData[i].attributes.entity_class=='MitvMediaPlayerEntity')||
  3227. // (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)
  3228. // )
  3229. // ){
  3230. // obj.volume_level = resData[i].attributes.volume_level;
  3231. // obj.is_volume_muted = resData[i].attributes.is_volume_muted;
  3232. // obj.source = resData[i].attributes.source;
  3233. // 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;";
  3234. // obj.media_title = resData[i].attributes.media_title;
  3235. // obj.media_artist = resData[i].attributes.media_artist;
  3236. // obj.volume_level = resData[i].attributes.volume_level?(resData[i].attributes.volume_level * 100):0;
  3237. // obj.media_duration = resData[i].attributes.media_duration;
  3238. // obj.media_position = resData[i].attributes.media_position;
  3239. // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
  3240. // listMitvMediaPlayerTemp.push(obj);
  3241. // }
  3242. // }
  3243. if ((resData[i].state && obj.domain && obj.domain == 'media_player') && that.checkFuzzyMatch(resData[i])
  3244. ) {
  3245. obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name, roomcode);
  3246. if (obj.entity_id.includes('teevee') || (obj.friendly_name && obj.friendly_name.includes('电视'))) {
  3247. obj.volume_level = resData[i].attributes.volume_level;
  3248. obj.is_volume_muted = resData[i].attributes.is_volume_muted;
  3249. obj.source = resData[i].attributes.source;
  3250. 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;";
  3251. obj.media_title = resData[i].attributes.media_title;
  3252. obj.media_artist = resData[i].attributes.media_artist;
  3253. obj.volume_level = resData[i].attributes.volume_level ? (resData[i].attributes.volume_level * 100) : 0;
  3254. obj.media_duration = resData[i].attributes.media_duration;
  3255. obj.media_position = resData[i].attributes.media_position;
  3256. obj.media_late = resData[i].attributes.media_position + '/' + resData[i].attributes.media_duration;
  3257. // obj["speaker.volume"] = resData[i].attributes["speaker.volume"];
  3258. // console.log('media-player-mitv-obj=='+obj);
  3259. obj.device_class = resData[i].attributes.device_class;
  3260. obj.app_id = resData[i].attributes.app_id;
  3261. obj.app_name = resData[i].attributes.app_name;
  3262. if (obj.entity_id && obj.state && checkState(obj.state) && obj.friendly_name && obj.domain) {
  3263. listMitvMediaPlayerTemp.push(obj);
  3264. }
  3265. obj.friendly_name1 = resData[i].attributes.friendly_name;
  3266. tvEntityIdsTemp.push(obj);
  3267. // let obj1 = {};
  3268. // obj1.entity_id = obj.entity_id;
  3269. // obj1.friendly_name1 = resData[i].attributes.friendly_name;
  3270. // tvEntityIdsTemp.push(obj1);
  3271. tvEntityIdTemp = obj.entity_id;
  3272. // console.log('obj===='+obj);
  3273. // console.log('tvEntityIdTemp='+tvEntityIdTemp);
  3274. wx.setStorageSync('tvEntityId', tvEntityIdTemp);
  3275. }
  3276. }
  3277. if ((resData[i].state && obj.domain && obj.domain == 'humidifier')
  3278. ) {
  3279. obj.min_humidity = resData[i].attributes.min_humidity;
  3280. obj.max_humidity = resData[i].attributes.max_humidity;
  3281. obj.humidity = resData[i].attributes.humidity;
  3282. obj.min = obj.min_humidity;
  3283. obj.max = obj.max_humidity;
  3284. humidityValueTemp = obj.humidity;
  3285. humidityMaxTemp = obj.max;
  3286. humidityMinTemp = obj.min;
  3287. // console.log('humidifier-obj=='+JSON.stringify(obj));
  3288. if (obj.entity_id && obj.state && checkState(obj.state) && obj.friendly_name && obj.domain) {
  3289. listHumidifierTemp.push(obj);
  3290. }
  3291. }
  3292. if ((resData[i].state && obj.domain && obj.domain == 'automation')) {
  3293. console.log("", resData[i].attributes.friendly_name);
  3294. if (resData[i].attributes.friendly_name.endsWith('起床模式')) {
  3295. modelList1.push(obj)
  3296. } else if (resData[i].attributes.friendly_name.endsWith('观影模式')) {
  3297. modelList2.push(obj)
  3298. } else if (resData[i].attributes.friendly_name.endsWith('睡眠模式')) {
  3299. modelList3.push(obj)
  3300. }
  3301. }
  3302. // if((resData[i].state && obj.domain && obj.domain=='sensor')||
  3303. // (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)
  3304. // )
  3305. // ){
  3306. // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
  3307. // obj.unit_of_measurement = resData[i].attributes.unit_of_measurement;
  3308. // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
  3309. // listSensorTemp.push(obj);
  3310. // }
  3311. // }
  3312. // if((resData[i].state && obj.domain && obj.domain=='text')||
  3313. // (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)
  3314. // )
  3315. // ){
  3316. // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
  3317. // obj.min = resData[i].attributes.min;
  3318. // obj.max = resData[i].attributes.max;
  3319. // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
  3320. // listTextTemp.push(obj);
  3321. // }
  3322. // }
  3323. // if((resData[i].state && obj.friendly_name && obj.friendly_name.includes("智能音箱"))
  3324. // || (resData[i].state && resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id)
  3325. // && obj.friendly_name && obj.friendly_name.includes("智能音箱"))
  3326. // ){
  3327. // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
  3328. // listConversationTemp.push(obj)
  3329. // }
  3330. // }
  3331. // if((resData[i].state && resData[i].attributes && resData[i].attributes.speaker && resData[i].attributes.speaker.volume && obj.friendly_name && obj.friendly_name.includes("智能音箱"))||
  3332. // (resData[i].state && resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id)
  3333. // && resData[i].attributes.speaker && resData[i].attributes.speaker.volume && obj.friendly_name && obj.friendly_name.includes("智能音箱"))
  3334. // ){
  3335. // obj.volume = resData[i].attributes.speaker.volume;//音量
  3336. // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
  3337. // listConversation1Temp.push(obj)
  3338. // }
  3339. // }
  3340. //加湿器单独拿出来
  3341. // if((obj.friendly_name && obj.friendly_name.includes("加湿器"))||
  3342. // (resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id)
  3343. // && obj.friendly_name && obj.friendly_name.includes("加湿器"))
  3344. // ){
  3345. // listHumidityTemp.push(obj)
  3346. // }
  3347. // }
  3348. }
  3349. that.setData({
  3350. // status_beep: that.getEntityState(res.data,'switch.xiaomi_pro3_02bd_left_switch_service'), //实验室主灯
  3351. // status_led: that.getEntityState(res.data,'light.deerma_jsq2g_392f_indicator_light'), //加湿器 Indicator Light
  3352. // status_san: that.getEntityState(res.data,'switch.xwhzp_xwxfj_a441_diffuser'), //香薰机 Diffuser
  3353. // status_curtain: that.getEntityState(res.data,'switch.xiaomi_pro3_02bd_middle_switch_service'), //实验室侧灯
  3354. // status_door: that.getEntityState(res.data,'remote.xiaomi_lx06_f593_wifispeaker_4'), //智能音箱
  3355. // Temp: that.getEntityStateValue(res.data,'sensor.deerma_jsq2g_392f_temperature'), //加湿器温度
  3356. // Humi: that.getEntityStateValue(res.data,'sensor.deerma_jsq2g_392f_relative_humidity'), //加湿器湿度
  3357. // Light: that.getEntityStateValue(res.data,'number.xwhzp_xwxfj_a441_brightness'), //香薰机亮度
  3358. // LiquidLevel: that.getEntityStateValue(res.data,'sensor.xwhzp_xwxfj_a441_fragrance_liquid_left_level'), //香薰液浓度
  3359. modelList1,
  3360. modelList2,
  3361. modelList3,
  3362. listSwitch: listSwitchTemp,
  3363. listUnit: listUnitTemp,
  3364. listScroll: listScrollTemp,
  3365. listConversation: listConversationTemp,
  3366. listConversation1: listConversation1Temp,
  3367. listHumidity: listHumidityTemp,
  3368. listButton: listButtonTemp,
  3369. listSelect: listSelectTemp,
  3370. listClimate: listClimateTemp,
  3371. listMiotMediaPlayer: listMiotMediaPlayerTemp,
  3372. listMitvMediaPlayer: listMitvMediaPlayerTemp,
  3373. listHumidifier: listHumidifierTemp,
  3374. listSensor: listSensorTemp,
  3375. listText: listTextTemp,
  3376. tvEntityId: tvEntityIdTemp,
  3377. tvEntityIds: tvEntityIdsTemp,
  3378. climateMode: climateModeTemp,
  3379. temperatureHumidifyName: temperatureHumidifyNameTemp,
  3380. listCover: listCoverTemp,
  3381. listAromatherapyMachine: listAromatherapyMachineTemp,
  3382. // ecHumidifier: {
  3383. // onInit: that.initChartHumidifier
  3384. // },
  3385. sliderValueHumidifier: '',
  3386. isLoading: false,
  3387. })
  3388. if (listHumidifierTemp.length && humidityValue != humidityValueTemp) {
  3389. humidityValue = humidityValueTemp;
  3390. humidityMin = humidityMinTemp;
  3391. humidityMax = humidityMaxTemp;
  3392. that.checkHumidityMarginLeft()
  3393. that.initChartHumidifier();
  3394. }
  3395. wx.setStorageSync('tvEntityIds', tvEntityIdsTemp);
  3396. },
  3397. });
  3398. let mid = Date.now(); // 获取当前时间(毫秒)
  3399. console.log('mid==' + mid);
  3400. console.log('start==' + start);
  3401. console.log('mid-start==' + (mid - start));
  3402. // that.setData({
  3403. // isLoading: true,
  3404. // });
  3405. // } catch (error) {
  3406. // console.error(error);
  3407. // }
  3408. // },
  3409. // fail: function (error) {
  3410. // console.error('error', error);
  3411. // that.setData({
  3412. // isLoading: false,
  3413. // });
  3414. // }
  3415. // });
  3416. } catch (error) {
  3417. console.error(error);
  3418. that.setData({
  3419. isLoading: false,
  3420. });
  3421. }
  3422. },
  3423. fail: function (error) {
  3424. console.error('error', error);
  3425. that.setData({
  3426. isLoading: false,
  3427. });
  3428. }
  3429. });
  3430. let end = Date.now(); // 再次获取当前时间(毫秒)
  3431. console.log('end==' + end);
  3432. let executionTime = end - start;
  3433. console.log(`myFunctionToTest 执行时间为: ${executionTime} 毫秒`);
  3434. return true;
  3435. },
  3436. imageLoad: function () {
  3437. this.setData({
  3438. isLoading: false,
  3439. });
  3440. console.log('图片渲染完成');
  3441. },
  3442. startInterval: function () {
  3443. // 使用 setInterval 创建定时任务,每8秒执行一次 this.myMethod 方法
  3444. var that = this;
  3445. // this.intervalId = setInterval(() => {
  3446. // that.getHAData(that,that.data.hotelcode,that.data.roomcode);
  3447. // }, 6000);
  3448. this.data.intervalId1 = setInterval(() => {
  3449. that.getHAData(that, that.data.hotelcode, that.data.roomcode);
  3450. }, 6000);
  3451. // 第二个定时器,每2秒执行一次
  3452. this.data.intervalId2 = setInterval(() => {
  3453. // 这里执行你的代码
  3454. that.setData({
  3455. isClickedPrevSong: false,
  3456. isClickedTogglePlayPause: false,
  3457. isClickedNextSong: false,
  3458. isClickedOnHumidifierUp: false,
  3459. isClickedOnHumidifierDown: false,
  3460. isClickedOnClimateAuto: false,
  3461. isClickedOnClimateUp: false,
  3462. isClickedToggleAromlight: false,//香薰机灯光
  3463. });
  3464. }, 300);
  3465. },
  3466. clearInterval: function () {
  3467. // 清除定时任务
  3468. // if (this.intervalId) {
  3469. // clearInterval(this.intervalId);
  3470. // this.intervalId = null;
  3471. // }
  3472. if (this.data.intervalId1) {
  3473. clearInterval(this.data.intervalId1);
  3474. this.data.intervalId1 = null; // 可选,但建议清除以避免潜在的错误
  3475. }
  3476. // 停止第二个定时器
  3477. if (this.data.intervalId2) {
  3478. clearInterval(this.data.intervalId2);
  3479. this.data.intervalId2 = null; // 可选,但建议清除以避免潜在的错误
  3480. }
  3481. },
  3482. stopTouchMove: function (e) {
  3483. return false;
  3484. },
  3485. truncateString: function (str, roomcode) {
  3486. if (!str) return ''
  3487. let strR = str.replace(roomcode, '')
  3488. if (strR.length <= 6) {
  3489. // 如果字符串长度小于等于5,直接返回原字符串
  3490. return strR;
  3491. } else {
  3492. // 如果字符串长度在6到9之间,返回后6个字符(此时没有前部分可拼接)
  3493. return strR.slice(-6);
  3494. }
  3495. },
  3496. onLoad(option) {
  3497. console.log("index页面");
  3498. // wx.clearStorage();
  3499. // this.setTextBreathing(wx.createSelectorQuery(".header-title-fire"),this);
  3500. //console.log('option.res='+JSON.stringify(wx.getStorageSync('res')));
  3501. if (!wx.getStorageSync('res') || !wx.getStorageSync('res').result) {
  3502. wx.showModal({
  3503. title: '提示',
  3504. content: '请先扫描房间二维码',
  3505. showCancel: false
  3506. });
  3507. setTimeout(function () {
  3508. wx.reLaunch({
  3509. url: '/pages/scan/scan',
  3510. })
  3511. }, 2000) // 设置延时时间,单位为毫秒
  3512. } else {
  3513. var that = this;
  3514. // wx.request({
  3515. // url: `${aipushApi}`+'/getbigreport',
  3516. // method: 'POST',
  3517. // header: {
  3518. // 'content-type': 'application/json', // 默认值
  3519. // 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  3520. // },
  3521. // data:{
  3522. //     "sn":'',"tokens":token_push
  3523. // },
  3524. // success(ress) {
  3525. // if(ress && ress.data){
  3526. // wx.request({
  3527. // url: `${homeApi_https}/states`, //获取空气数据
  3528. // method: 'GET',
  3529. // header: {
  3530. // 'content-type': 'application/json', // 默认值
  3531. // 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  3532. // },
  3533. // success(res) {
  3534. // if(!res || !res.data){
  3535. // wx.showModal({
  3536. // title: '提示',
  3537. // content: '请先连接房间wi-fi,再次扫描',
  3538. // showCancel: false
  3539. // });
  3540. // setTimeout(function() {
  3541. // wx.reLaunch({
  3542. // url: '/pages/scan/scan',
  3543. // })
  3544. // }, 2000) // 设置延时时间,单位为毫秒
  3545. // }else{
  3546. // // console.log("res.data====="+JSON.stringify(res.data));
  3547. // }
  3548. // },
  3549. // });
  3550. // }else{
  3551. // wx.showModal({
  3552. // title: '提示',
  3553. // content: '请先连接房间wi-fi,再次扫描',
  3554. // showCancel: false
  3555. // });
  3556. // setTimeout(function() {
  3557. // wx.reLaunch({
  3558. // url: '/pages/scan/scan',
  3559. // })
  3560. // }, 2000) // 设置延时时间,单位为毫秒
  3561. // }
  3562. // },
  3563. // });
  3564. // const socketUrl = 'http://192.168.3.65:8123';
  3565. // wx.connectSocket({
  3566. // url: socketUrl,
  3567. // success: function (res) {
  3568. // console.log('WebSocket连接成功', res);
  3569. // },
  3570. // fail: function (error) {
  3571. // console.error('WebSocket连接打开失败', error);
  3572. // }
  3573. // });
  3574. //wi-fi判断
  3575. // wx.startWifi({
  3576. // fail(error) {
  3577. // console.log('初始化wifi-失败', error)
  3578. // },
  3579. // success(res) {
  3580. // console.log('初始化wifi-成功', res)
  3581. // },
  3582. // });
  3583. // const expiresAt = wx.getStorageSync('scanResultExpiresAt');
  3584. // const now = Date.now()
  3585. // console.log('expiresAt='+expiresAt);
  3586. // console.log('now='+now);
  3587. // if (expiresAt || expiresAt < now) {
  3588. // // 扫码结果已过期
  3589. // wx.showToast({
  3590. // title: '扫码结果失效或已过期,请重新扫码',
  3591. // icon: 'none'
  3592. // });
  3593. // // 清除过期的扫码结果
  3594. // wx.removeStorageSync('scanResultExpiresAt');
  3595. // setTimeout(function() {
  3596. // wx.reLaunch({
  3597. // url: '/pages/scan/scan',
  3598. // })
  3599. // }, 2000) // 设置延时时间,单位为毫秒
  3600. // }else{
  3601. // //续期
  3602. // wx.setStorageSync('scanResultExpiresAt', Date.now() + 2 * 60 * 60 * 1000)
  3603. // }
  3604. let hotelcodeTemp = '';
  3605. let roomcodeTemp = '';
  3606. if (wx.getStorageSync('res').result.split('|').length != 2) {
  3607. wx.showModal({
  3608. title: '提示',
  3609. content: '房间二维码不正确,请重新扫码',
  3610. showCancel: false
  3611. });
  3612. setTimeout(function () {
  3613. wx.reLaunch({
  3614. url: '/pages/scan/scan',
  3615. })
  3616. }, 2000) // 设置延时时间,单位为毫秒
  3617. }
  3618. hotelcodeTemp = wx.getStorageSync('res').result.split('|')[0];
  3619. roomcodeTemp = wx.getStorageSync('res').result.split('|')[1];
  3620. entity = roomcodeTemp;
  3621. if (entity == 'labs') {
  3622. entity = '公司实验室';
  3623. wx.setStorageSync('roomname', '604');
  3624. } else {
  3625. wx.setStorageSync('roomname', entity);
  3626. }
  3627. this.setData({
  3628. isLoading: true,
  3629. hotelcode: hotelcodeTemp,
  3630. roomcode: roomcodeTemp,
  3631. });
  3632. if (this.getHADataStart(this, hotelcodeTemp, roomcodeTemp)) {
  3633. // 页面加载时开始定时任务
  3634. // this.startInterval();
  3635. }
  3636. }
  3637. // else if(!this.data.home_room.includes(wx.getStorageSync('res').result)){
  3638. // wx.showModal({
  3639. // title: '提示',
  3640. // content: '房间二维码不正确,请重新扫描',
  3641. // showCancel: false
  3642. // });
  3643. // setTimeout(function() {
  3644. // wx.reLaunch({
  3645. // url: '/pages/scan/scan',
  3646. // })
  3647. // }, 2000) // 设置延时时间,单位为毫秒
  3648. // }
  3649. // this.showCanvasRing();
  3650. // 创建音频上下文
  3651. // this.innerAudioContext = wx.createInnerAudioContext();
  3652. // // 设置音频源
  3653. // this.innerAudioContext.src = '你的音频文件链接'; // 替换为你的音频文件链接
  3654. // // 监听播放状态
  3655. // this.innerAudioContext.onPlay(() => {
  3656. // this.setData({ isPlaying: true });
  3657. // });
  3658. // this.innerAudioContext.onPause(() => {
  3659. // this.setData({ isPlaying: false });
  3660. // });
  3661. // this.innerAudioContext.onStop(() => {
  3662. // this.setData({ isPlaying: false });
  3663. // });
  3664. // this.innerAudioContext.onError((res) => {
  3665. // console.log('res.errorCode='+res.errorCode);
  3666. // console.log('res.errorMsg='+res.errorMsg);
  3667. // });
  3668. // // 监听播放进度
  3669. // this.innerAudioContext.onTimeUpdate(() => {
  3670. // this.setData({
  3671. // currentTime: this.innerAudioContext.currentTime,
  3672. // duration: this.innerAudioContext.duration
  3673. // });
  3674. // });
  3675. // // 初始化歌曲列表
  3676. // this.setData({
  3677. // songs: [
  3678. // { id: 1, title: '歌曲1', artist: '歌手1', url: 'song1.mp3' },
  3679. // { id: 2, title: '歌曲2', artist: '歌手2', url: 'song2.mp3' },
  3680. // { id: 3, title: '歌曲3', artist: '歌手3', url: 'song3.mp3' }
  3681. // ]
  3682. // });
  3683. },
  3684. mounted() {
  3685. },
  3686. onHide() {
  3687. // wx.clearStorage();
  3688. // 页面卸载时清除定时任务
  3689. this.clearInterval();
  3690. // if(this.tcp){
  3691. // this.tcp.onClose(() => {
  3692. // // this.infoList.push('关闭')
  3693. // console.log('tcp关闭');
  3694. // this.tcp.close()
  3695. // })
  3696. // }
  3697. },
  3698. onUnload() {
  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. // if (this.data.observer) {
  3710. // this.data.observer.disconnect();
  3711. // }
  3712. },
  3713. onReady() {
  3714. console.log('页面渲染完成')
  3715. // 获取组件
  3716. // 确保页面渲染完成后查找节点
  3717. },
  3718. showLoading: function () {
  3719. wx.showToast({
  3720. title: '加载中',
  3721. icon: 'loading',
  3722. })
  3723. },
  3724. cancelLoading: function () {
  3725. wx.hideToast()
  3726. },
  3727. onShow() {
  3728. const app = getApp();
  3729. app.globalData.selectedTabIndex = 0;
  3730. this.getTabBar().setData({
  3731. selected: 0
  3732. })
  3733. var that = this;
  3734. that.setData({
  3735. currentMenuTabIndex: -1
  3736. })
  3737. that.startInterval();
  3738. // that.setData({
  3739. // ecHumidifier: {
  3740. // onInit: initChartHumidifier
  3741. // },
  3742. // })
  3743. //mqtt程序,保留
  3744. /* wx.showToast({
  3745. title: "连接服务器....",
  3746. icon: "loading",
  3747. duration: 10000,
  3748. mask: true,
  3749. });
  3750. let second = 10;
  3751. var toastTimer = setInterval(() => {
  3752. second--;
  3753. if (second) {
  3754. wx.showToast({
  3755. title: `连接服务器...${second}`,
  3756. icon: "loading",
  3757. duration: 1000,
  3758. mask: true,
  3759. });
  3760. } else {
  3761. clearInterval(toastTimer);
  3762. wx.showToast({
  3763. title: "连接失败",
  3764. icon: "error",
  3765. mask: true,
  3766. });
  3767. }
  3768. }, 1000);
  3769. that.setData({
  3770. client: connect(mqttUrl,options)
  3771. })
  3772. that.data.client.on("connect", function () {
  3773. console.log("成功连接mqtt服务器!");
  3774. clearInterval(toastTimer);
  3775. wx.showToast({
  3776. title: "连接成功",
  3777. icon: "success",
  3778. mask: true,
  3779. });
  3780. // 一秒后订阅主题
  3781. setTimeout(() => {
  3782. that.data.client.subscribe(mpSubTopic_env, function (err) {
  3783. if (!err) {
  3784. console.log("成功订阅设备上行数据环境Topic!");
  3785. wx.showToast({
  3786. title: "订阅成功",
  3787. icon: "success",
  3788. mask: true,
  3789. });
  3790. }
  3791. });
  3792. }, 500);
  3793. });
  3794. setTimeout(() => {
  3795. that.data.client.subscribe(mpSubTopic_con, function (err) {
  3796. if (!err) {
  3797. console.log("成功订阅设备上行数据控制Topic!");
  3798. wx.showToast({
  3799. title: "订阅成功",
  3800. icon: "success",
  3801. mask: true,
  3802. });
  3803. }
  3804. });
  3805. }, 200);
  3806. that.data.client.on("message", function (topic, message) {
  3807. console.log(topic);
  3808. // message是16进制的Buffer字节流
  3809. let dataFromDev = {};
  3810. console.log('message='+message);
  3811. // 尝试进行JSON解析
  3812. try {
  3813. dataFromDev = JSON.parse(message);
  3814. console.log(dataFromDev);
  3815. that.setData({
  3816. //环境状态
  3817. Temp: dataFromDev.Temp,
  3818. Humi: dataFromDev.Humi,
  3819. Voltage1: dataFromDev.Voltage1,
  3820. Voltage2: dataFromDev.Voltage2,
  3821. //设备状态
  3822. status_beep: dataFromDev.Beep_Flag,
  3823. status_led: dataFromDev.Led_Flag,
  3824. status_curtain: dataFromDev.Angle1,
  3825. status_san: dataFromDev.San_Flag,
  3826. status_door: dataFromDev.Angle2,
  3827. status_fire: dataFromDev.Fire_Flag,
  3828. status_light: dataFromDev.Light_Flag,
  3829. status_mode: dataFromDev.Mode_Flag
  3830. })
  3831. } catch (error) {
  3832. // 解析失败错误捕获并打印(错误捕获之后不会影响程序继续运行)
  3833. console.log(error);
  3834. }
  3835. }) */
  3836. // if(this.tcp){
  3837. // this.tcp.onClose(() => {
  3838. // // this.infoList.push('关闭')
  3839. // console.log('tcp关闭');
  3840. // this.tcp.close()
  3841. // this.tcp = '';
  3842. // })
  3843. // }
  3844. // // 初始化TCP实例
  3845. // this.tcp = wx.createTCPSocket()
  3846. // // tcp实例向服务端发起连接
  3847. // this.tcp.connect({ address: '192.168.3.65', port: '81231' })
  3848. // // this.infoList.push(`向${this.ip}:${~~this.port}建立链接`)
  3849. // this.tcp.offClose(() => {
  3850. // })
  3851. // this.tcp.onConnect(() => {
  3852. // // this.infoList.push('连接成功')
  3853. // console.log('tcp连接成功');
  3854. // })
  3855. // this.tcp.offConnect(() => {
  3856. // // this.infoList.push('offConnect')
  3857. // console.log('tcp-offConnect');
  3858. // })
  3859. // this.tcp.onError(error => {
  3860. // // this.infoList.push('异常:' + error)
  3861. // console.log('tcp异常:' + error);
  3862. // wx.showModal({
  3863. // title: '提示',
  3864. // content: '请先连接房间wi-fi,再次扫描',
  3865. // showCancel: false
  3866. // });
  3867. // setTimeout(function() {
  3868. // wx.reLaunch({
  3869. // url: '/pages/scan/scan',
  3870. // })
  3871. // }, 2000) // 设置延时时间,单位为毫秒
  3872. // })
  3873. // this.tcp.onMessage(data => {
  3874. // // this.infoList.push('tcp接收到数据: ' + transitionArrayBufferToString(data.message))
  3875. // console.log('tcp接收到数据: ' + JSON.stringify(data.message));
  3876. // })
  3877. wx.getLocation({
  3878. type: "wgs84",
  3879. success(res) {
  3880. const latitude = res.latitude;
  3881. const longitude = res.longitude;
  3882. const key = hefengKey;
  3883. wx.request({
  3884. url: `${geoApi}location=${longitude},${latitude}&key=${key}`, //获取地理位置
  3885. success(res) {
  3886. console.log('getLocation=' + JSON.stringify(res.data));
  3887. if (res.data.code == "401") {
  3888. console.error("HUAQING --- 请检查你的和风天气API或Key是否正确!");
  3889. return;
  3890. }
  3891. try {
  3892. const {
  3893. location
  3894. } = res.data;
  3895. that.setData({
  3896. area: location[0].name, //城区
  3897. city: location[0].adm2 //城市
  3898. })
  3899. } catch (error) {
  3900. console.error(error);
  3901. }
  3902. },
  3903. });
  3904. wx.request({
  3905. url: `${hefengWeather}location=${longitude},${latitude}&key=${key}`, //获取实时天气数据
  3906. success(res) {
  3907. console.log("实时天气==" + JSON.stringify(res.data));
  3908. if (res.data.code == "401") {
  3909. console.error("HUAQING --- 请检查你的和风天气API或Key是否正确!");
  3910. return;
  3911. }
  3912. try {
  3913. const {
  3914. now
  3915. } = res.data;
  3916. that.setData({
  3917. weather: now.text, // 天气
  3918. w_temp: now.temp, // 温度
  3919. w_humidity: now.humidity, // 湿度
  3920. })
  3921. } catch (error) {
  3922. console.error(error);
  3923. }
  3924. },
  3925. });
  3926. wx.request({
  3927. url: `${hefengAir}location=${longitude},${latitude}&key=${key}`, //获取空气数据
  3928. success(res) {
  3929. console.log("空气数据==" + JSON.stringify(res.data));
  3930. if (res.data.code == "401") {
  3931. console.error("HUAQING --- 请检查你的和风天气API或Key是否正确!");
  3932. return;
  3933. }
  3934. try {
  3935. const {
  3936. now
  3937. } = res.data;
  3938. that.setData({
  3939. airText: now.category, //空气质量
  3940. airValue: now.aqi //空气指数
  3941. })
  3942. } catch (error) {
  3943. console.error(error);
  3944. }
  3945. },
  3946. });
  3947. },
  3948. });
  3949. // 获取天气相关数据
  3950. // wx.scanCode({
  3951. // success: (res) => {
  3952. // console.log('扫描结果:'+res.result) // 扫描结果
  3953. // }
  3954. // });
  3955. }
  3956. })