index.js 127 KB

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