index.js 122 KB

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