index.js 130 KB

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