index.js 131 KB

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