index.js 129 KB

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