| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904 |
- // index.js
- // 获取应用实例
- import * as echarts from '../../ec-canvas/echarts';
- // const { connect } = require("../../utils/mqtt4/mqtt");
- /******************* 必须要改!!不然得不到天气!! ******************/
- const hefengKey = " aa373d4025b0487196c15d8e6526cfcf"; // 和风天气Web api的key
- /******************* 可能需要你修改的部分 ******************/
- //const mqttHost = "broker.emqx.io"; //mqtt 服务器域名/IP
- // const mqttHost = "www.nekolee.top";
- const mqttHost = "haold.aidsleep.cn";
- // const mqttHost = "192.168.3.65";
- // const mqttPort = 8084; //mqtt 服务器域名/IP
- const mqttPort = 8083; //mqtt 服务器域名/IP
- const hefengVIP = false; // 和风天气是免费的api(false)还是付费api(true)
- const deviceSubTopic_LED = "/NekoHome/sub_LED"; // 设备订阅topic(小程序发布命令topic)
- const deviceSubTopic_BEEP = "/NekoHome/sub_BEEP";
- const deviceSubTopic_CU = "/NekoHome/sub_CU";
- const deviceSubTopic_DO = "/NekoHome/sub_DO";
- const deviceSubTopic_SAN = "/NekoHome/sub_SAN";
- const deviceSubTopic_Mode = "/NekoHome/sub_mode";
- // const devicePubTopic_env = "/NekoHome/pub/Environment"; // 设备发布topic(订阅环境参数)
- // const devicePubTopic_con = "/NekoHome/pub/Controll"; // 设备发布topic(订阅控制参数)
- const devicePubTopic_env = "testtopic/1"; // 设备发布topic(订阅环境参数)
- const devicePubTopic_con = "testtopic/1"; // 设备发布topic(订阅控制参数)
- /********************* 一般不用动这些 ********************/
- //小程序接收的主题
- const mpSubTopic_env = devicePubTopic_env;
- const mpSubTopic_con = devicePubTopic_con;
- //小程序发送的主题
- const mpPubTopic_LED = deviceSubTopic_LED;
- const mpPubTopic_BEEP = deviceSubTopic_BEEP;
- const mpPubTopic_CU = deviceSubTopic_CU;
- const mpPubTopic_DO = deviceSubTopic_DO;
- const mpPubTopic_SAN = deviceSubTopic_SAN;
- const mpPubTopic_Mode = deviceSubTopic_Mode;
- const mqttUrl = `wx://${mqttHost}:${mqttPort}/mqtt`; // mqtt连接路径
- const hefengApi = "https://api.qweather.com/v7"; // 和风天气付费API前缀
- const hefengFreeApi = "https://devapi.qweather.com/v7"; // 和风天气免费API前缀
- const hefengWeather = `${hefengVIP ? hefengApi : hefengFreeApi}/weather/now?`; // 和风天气实时天气api
- const hefengAir = `${hefengVIP ? hefengApi : hefengFreeApi}/air/now?`; // 和风天气空气质量api
- const geoApi = "https://geoapi.qweather.com/v2/city/lookup?" // 地理位置api(用来获取经纬度对应的城市/城区名字)
- var homeApi = "http://haold.aidsleep.cn:8123/api";
- var homeApiLater = "http://haold.aidsleep.cn:8123";
- var homeApi_https = "https://haold.aidsleep.cn/api";
- var homeApiLater_https = "https://haold.aidsleep.cn";
- var entity = "";
- // const token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJiN2JlOGE0MDExZjY0NjA2OGUxYjJiZTE4M2Y2NzU0NSIsImlhdCI6MTcxMTYxNDY2NCwiZXhwIjoyMDI2OTc0NjY0fQ.XJ73cXAoEsouTgvgpNVobq9oKdwlJr88TiAFLYlaahE";
- var token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJlZGVjOWI3YWQ0MTQ0ZTIxYWQ1NTE1Nzc5NTkzNjBjNiIsImlhdCI6MTcxMjEzNTM2MywiZXhwIjoyMDI3NDk1MzYzfQ.IfrvdiaVuhCKsdy69JvUYhJ64bnhMT8MI1hN8R38whc";
- const aipushApi = "https://aipush.aidsleep.cn";
- const token_push = "b74fd5754c5ef24cf600c39194abdaeb";
-
- const options = {
- connectTimeout:4000,//超时时间
- clientId:'emqx_ODAyNT',//随机生成ID
- username:'test1',
- password:'123456'
- }
- // let chart4;
- // function flushChart4(data) {
- // console.lg('111111112222222222222333333333');
- // var option = {
- // // title: {
- // // text: '睡眠与起床时间'
- // // },
- // title: {
- // text: '睡眠与清醒时间',
- // left: 'center',
- // textStyle: {
- // color: '#ffffff', // 字体颜色
- // fontStyle: 'normal', // 字体风格
- // // fontWeight: 'bold', // 字体粗细
- // fontFamily: 'sans-serif', // 字体族
- // fontSize: 18 // 字体大小
- // },
- // backgroundColor: '#ff5246'
- // },
- // tooltip: {},
- // series: [{
- // type: 'gauge',
- // detail: {formatter: '{value} 小时'},
- // data: [{"name":"睡眠时间","value":7},{"name":"清醒时间","value":1}]
- // }]
- // };
- // chart4.setOption(option, true);
- // }
- function initChartHumidifier(canvas, width, height ,data) {//这里多加一个参数
- const chart = echarts.init(canvas, null, {
- width: width,
- height: height
- })
- canvas.setChart(chart);
- var option = {
- //提示框组件。开发实际中去掉了指针,提示框可以不用设置。
- tooltip: {
- formatter: "{a} <br/>{b} : {c}%"
- },
- //工具栏。刷新,下载
- // toolbox: {
- // feature: {
- // restore: {},
- // saveAsImage: {}
- // }
- // },
- //下面属性才是仪表盘的核心!!反正我是这么认为的!!!
- series: [{
- //类型
- type: 'gauge',
- //半径
- radius: 150,
- //起始角度。圆心 正右手侧为0度,正上方为90度,正左手侧为180度。
- startAngle: 200,
- //结束角度。
- endAngle: -20,
- center: ['50%', '65%'],
- min:data.min_humidity,
- max:data.max_humidity,
- //仪表盘轴线相关配置。
- axisLine: {
- show: true,
- color: '#333',
- // 属性lineStyle控制线条样式
- lineStyle: {
- width: 20,
- color: [[data.humidity?(data.humidity / data.max_humidity):'', '#b8b8b8'], [1, '#ebebeb']]
- }
- },
- //分隔线样式。
- splitLine: {
- show: false,
- },
- //刻度样式。
- axisTick: {
- show: false,
- },
- //刻度标签。
- axisLabel: {
- show: false,
- },
- // 结尾的圆圈图标
- markPoint: {
- silent: true,
- data: [
- {
- name: '结束点',
- coord: ['100%', '0%'],
- itemStyle: {
- normal: {
- label: {
- show: false
- },
- borderRadius: 10,
- borderColor: '#aa00ff',
- borderWidth: 2,
- color: 'rgba(255, 255, 255, 0.3)'
- }
- }
- }
- ]
- },
- //仪表盘指针。
- pointer: {
- show: false,
- //指针长度
- length: '90%',
- width: 0,
- },
- //仪表盘标题。
- title: {
- show: true,
- offsetCenter: [0, '-40%'], // x, y,单位px
- textStyle: {
- color: '#000',
- fontSize: 30
- }
- },
- //仪表盘详情,用于显示数据。
- detail: {
- show: true,
- offsetCenter: [0, '-10%'],
- formatter: data.humidity,
- textStyle: {
- fontSize: 30,
- color: '#31e4f4'
- }
- },
- data: [{
- value: data.humidity?data.humidity:null,
- name: '湿度'
- }]
- }]
- };
- chart.setOption(option);
- return chart;
- }
- function initChartClimate(canvas, width, height ,data) {//这里多加一个参数
- const chart = echarts.init(canvas, null, {
- width: width,
- height: height
- })
- canvas.setChart(chart);
- var option = {
- //提示框组件。开发实际中去掉了指针,提示框可以不用设置。
- tooltip: {
- formatter: "{a} <br/>{b} : {c}%"
- },
- //工具栏。刷新,下载
- // toolbox: {
- // feature: {
- // restore: {},
- // saveAsImage: {}
- // }
- // },
- series: [{
- //类型
- type: 'gauge',
- //半径
- radius: 150,
- //起始角度。圆心 正右手侧为0度,正上方为90度,正左手侧为180度。
- startAngle: 200,
- //结束角度。
- endAngle: -20,
- center: ['50%', '65%'],
- min:data.min_temp,
- max:data.max_temp,
- //仪表盘轴线相关配置。
- axisLine: {
- show: true,
- color: '#333',
- // 属性lineStyle控制线条样式
- lineStyle: {
- width: 20,
- color: [[data.max_temp?(data.temperature / data.max_temp):0, '#b8b8b8'], [1, '#ebebeb']]
- }
- },
- //分隔线样式。
- splitLine: {
- show: false,
- },
- //刻度样式。
- axisTick: {
- show: false,
- },
- //刻度标签。
- axisLabel: {
- show: false,
- },
- // 结尾的圆圈图标
- markPoint: {
- silent: true,
- data: [
- {
- name: '结束点',
- coord: ['100%', '0%'],
- itemStyle: {
- normal: {
- label: {
- show: false
- },
- borderRadius: 10,
- borderColor: '#aa00ff',
- borderWidth: 2,
- color: 'rgba(255, 255, 255, 0.3)'
- }
- }
- }
- ]
- },
- //仪表盘指针。
- pointer: {
- show: false,
- //指针长度
- length: '90%',
- width: 0,
- },
- //仪表盘标题。
- title: {
- show: true,
- offsetCenter: [0, '-40%'], // x, y,单位px
- textStyle: {
- color: '#000',
- fontSize: 30
- }
- },
- //仪表盘详情,用于显示数据。
- detail: {
- show: true,
- offsetCenter: [0, '-10%'],
- formatter: data.temperature,
- textStyle: {
- fontSize: 30,
- color: '#31e4f4'
- }
- },
- data: [{
- value: data.temperature,
- name: '温度'
- }]
- }]
- };
- chart.setOption(option);
- return chart;
- }
- import Notify from '../../@vant/weapp/notify/notify';
- import Dialog from '../../@vant/weapp/dialog/dialog';
- import Toast from '../../@vant/weapp/toast/toast';
- Page({
- data: {
- //单选框
- radio_select: '10',
- radio_switch: '10',
- //倒计时时间
- Time: 0,
- //火灾时的呼吸效果变量
- breathNum:0,
- //火灾头顶警示
- topTips: true,
- hide: false,
- //火灾弹窗显示
- fire_show:false,
- //设备控制弹窗参数 开始
- show_led: false,
- show_beep: false,
- show_curtain:false,
- show_san:false,
- show_door:false,
- show_time: false,
- actions_led: [
- {
- name: '打开',
- subname: '打开客厅灯',
- id:1,
- url:'',
- entity_id:'',
- },
- {
- name: '关闭',
- subname: '关闭客厅灯',
- id:0,
- url:'',
- entity_id:'',
- },
-
- ],
- actions_beep: [
- {
- name: '打开',
- subname: '打开警报器',
- id:1,
- url:'/services/switch/turn_on',
- entity_id:'switch.deerma_jsq2g_392f_alarm',
- },
- {
- name: '关闭',
- subname: '关闭警报器',
- id:0,
- url:'/services/switch/turn_off',
- entity_id:'switch.deerma_jsq2g_392f_alarm',
- },
-
- ],
- actions_curtain: [
- {
- name: '打开',
- subname: '打开香薰机',
- id:90,
- url:'',
- entity_id:'',
- },
- {
- name: '关闭',
- subname: '关闭香薰机',
- id:0,
- url:'',
- entity_id:'',
- },
-
- ],
- actions_san: [
- {
- name: '打开',
- subname: '打开音响',
- id:1,
- url:'',
- entity_id:'',
- },
- {
- name: '关闭',
- subname: '关闭音响',
- id:0,
- url:'',
- entity_id:'',
- },
-
- ],
- actions_door: [
- {
- name: '打开',
- subname: '打开智能开关',
- id:90,
- url:'',
- entity_id:'',
- },
- {
- name: '关闭',
- subname: '关闭智能开关',
- id:0,
- url:'',
- entity_id:'',
- },
-
- ],
- //设备控制弹窗参数 结束
- client: {},
- //设备状态参数 开始
- status_beep: 0,
- status_led: 0,
- status_san: 0,
- status_curtain: 0,
- status_door: 0,
- status_fire: 0,
- status_light: 0,
- status_mode: 0,
- //设备状态参数 结束
- //设备环境参数 开始
- Temp: 0,
- Humi: 0,
- Voltage1: 0,
- Voltage2: 0,
- //设备环境参数 结束
-
- //香薰机参数 开始
- Light: 0,
- LiquidLevel: 0,
- //香薰机参数 开始
-
- area: "请求中", //城区
- city: "请求中", //城市
- airText: "请求中", //空气优良
- airValue: 0, //空气指数
- weather: "请求中", //天气
- //weatherAdvice: "今天天气不错", //天气建议
- time: 30 * 60 * 60 * 1000,
- gradientColor: {
- '0%': '#ffd01e',
- '100%': '#ee0a24',
- },
- value: 25,
- pickerValue: [0], // picker-view 的当前值,数组形式,表示选择器的当前位置
- array: ['0%', '10%', '20%', '30%', '40%', '50%', '60%', '70%', '80%', '90%', '100%'], // 滑动块可选的值
- items: ['0%', '10%', '20%', '30%', '40%', '50%', '60%', '70%', '80%', '90%', '100%'], // 滑动块可选的值
-
- scaleTextStyle:{
- show:true,
- size:12,
- color:''
- },
- indicatorTextStyle:{
- show:true,
- size:16,
- text:'湿度'
- },
- indicatorTextStyleClimate:{
- show:true,
- size:16,
- text:'温度'
- },
- indicatorValueStyle: {
- show: true,
- size: 55,
- color:''
- },
- indicatorCircleStyle:{
- show:true,
- boderColor:[
- {
- progress:0,
- value:"#4575e8"
- },
- {
- progress: 1,
- value: "#fff"
- }
- ]
- },
- listCover: [],//窗帘开关
- listSwitch: [],//开关
- listScroll: [],//滚动条
- listUnit: [],//rgb、%、minutes、w等
- listConversation: [],//智能音响
- listConversation1: [],//智能音响
- listHumidity: [],//加湿器
- listButton: [],//按钮 '按下'
- listSelect: [],//下拉框的
- listClimate: [],//空调控制 图像
-
- listMiotMediaPlayer: [],//智能音箱 图像
- listMitvMediaPlayer: [],//电视 图像
-
- listHumidifier: [],//加湿器 图像
- listSensor: [],//文字描述的
-
- listText: [],//文本框填写的
-
- isPlaying: false,
- currentTime: 0,
- currentIndex: 0,
- duration: 0,
- currentSongTitle: '--',
- currentSongArtist: '--',
- canPrev: true,
- canNext: true,
- songs: [], // 歌曲列表
- scrollValue: [],
- selectedIndex: 0, // 默认选中第一个选项
- home_room: [
- 'company_laboratory',
- '2802',
- ],
- climateMode: '',//空调模式:加热还是除湿。在空调增加按钮和减少按钮 时使用
-
- canvasWidth: 300, // 画布宽度
- canvasHeight: 150, // 画布高度
- value:60 , // 当前得分
- total:100, // 总分值
- tvEntityId:'',// 电视实体Id
- tvEntityIds:[],// 电视实体
- entityName:'',//
- sleep_duration:'50',
- ecHumidifier: {
- onInit: initChartHumidifier
- },
- ecClimate: {
- onInit: initChartClimate
- },
- itemList:[
- { name: '1', data: [{ value: 10 }, { value: 1 }] },
- { name: '2', data: [{ value: 10 }, { value: 4 }] },
- { name: '3', data: [{ value: 10 }, { value: 7 }] },
- ],
- blackList:[
- // '指示灯','电视模式','电视音量','空调遥控','智能音箱','电视控制码','传感器模式','开关模式','耗电量','智能音箱会话'
- '加湿器','空调','音箱','窗帘','纱帘'
- ],
- temperatureHumidifyName:'温度',
- isButtonPressedHumidityUp:false,
- isButtonPressedHumidityDown:false,
- isButtonPressedClimateUp:false,
- isButtonPressedClimateDown:false,
- tcp: '',
- w_temp: '',//温度
- w_humidity: '',//湿度
- imgSrc: '',//图片地址
- isLoading: false,
- observer: '',
- hotelcode: '',//酒店编码
- roomcode: '',//房间编码
- isClickedPrevSong: false,
- isClickedTogglePlayPause: false,
- isClickedNextSong: false,
- isClickedOnHumidifierUp: false,
- isClickedOnHumidifierDown: false,
- isClickedOnClimateAuto: false,
- isClickedOnClimateUp: false,
- isClickedToggleAromlight: false,//香薰机灯光
- intervalId1: null,
- intervalId2: null,
- sliderValueHumidifier: '',
- sliderValueClimate: '',
- },
- handleTouchEndHumidifier: function(e) {
- this.setData({
- sliderValueHumidifier: '',
- });
- },
- handleChangingHumidifier: function(e) {
- // 假设 slider 宽度为屏幕宽度(或某个固定值),这里需要根据实际情况调整
- const screenWidth = wx.getSystemInfoSync().windowWidth;
- const sliderValueHumidifier = e.detail.value;
- this.setData({
- sliderValueHumidifier: sliderValueHumidifier,
- });
- },
- handleTouchEndClimate: function(e) {
- this.setData({
- sliderValueClimate: '',
- });
- },
- handleChangingClimate: function(e) {
- // 假设 slider 宽度为屏幕宽度(或某个固定值),这里需要根据实际情况调整
- const screenWidth = wx.getSystemInfoSync().windowWidth;
- const sliderValueClimate = e.detail.value;
- this.setData({
- sliderValueClimate: sliderValueClimate,
- });
- },
- replaceAll: function(str, find, replace) {
- return str.replace(new RegExp(find, 'g'), replace);
- },
- checkFuzzyMatch: function(data) {
- var searchString = data.attributes.friendly_name
- var domain = data.entity_id.split(".")[0]
- var isMatched = true;
- var list = this.data.blackList;
- if(!searchString || !list) return false;
- for (var i = 0; i < list.length; i++) {
- if (searchString.indexOf(list[i]) !== -1) {
- isMatched = false;
- break;
- }
- }
- return isMatched;
- },
- onChange: function (e) {
- this.setData({
- pickerValue: e.detail.value, // 更新picker-view的值
- });
- // 在这里添加点击事件的处理逻辑
- // 根据pickerValue的变化执行相应的操作
- },
- swiperTap(e) {
- // 处理整个swiper的点击事件
- },
- itemTap(e) {
- // 处理swiper-item的点击事件
- const index = e.currentTarget.dataset.index;
- // 根据index执行其他操作
- },
- //定时组件
-
- start() {
- const countDown = this.selectComponent('.control-count-down');
- countDown.start();
- },
- pause() {
- const countDown = this.selectComponent('.control-count-down');
- countDown.pause();
- },
- reset() {
- const countDown = this.selectComponent('.control-count-down');
- countDown.reset();
- },
- set(){
- this.setData({
- show_time:true,
- })
- },
- onClose_TimeSet() {
- this.setData({ show_time: false });
- },
- onChange_Silder(event) {
- wx.showToast({
- icon: 'none',
- title: `定时:${event.detail}s`,
- });
- this.setData({
- Time:event.detail,
- })
- },
- onChange_Select(event) {
- this.setData({
- radio_select: event.detail,
- });
- },
- onChange_Switch(event) {
- this.setData({
- radio_switch: event.detail,
- });
- },
- finished() {
- var that = this;
- //定时开关哪个设备?
- if(that.data.radio_select == 2)
- {
- if(that.data.radio_switch == 1){
- console.log("选择了开");
- that.data.client.publish(mpPubTopic_LED, '{"target":"LED","value":1}', function (err) {
- if (!err) {
- console.log("成功下发命令——打开客厅灯");
- }
- });
- }else{
- console.log("选择了关");
- that.data.client.publish(mpPubTopic_LED, '{"target":"LED","value":0}', function (err) {
- if (!err) {
- console.log("成功下发命令——关闭客厅灯");
- }
- });
- }
- }else if(that.data.radio_select == 3){
- console.log("选择了BEEP");
- if(that.data.radio_switch == 1){
- console.log("选择了开");
- that.data.client.publish(mpPubTopic_BEEP, '{"target":"BEEP","value":1}', function (err) {
- if (!err) {
- console.log("成功下发命令——打开报警器");
- }
- });
- }else{
- console.log("选择了关");
- that.data.client.publish(mpPubTopic_BEEP, '{"target":"BEEP","value":0}', function (err) {
- if (!err) {
- console.log("成功下发命令——关闭报警器");
- }
- });
- }
- }else if(that.data.radio_select == 4){
- console.log("选择了CU");
- if(that.data.radio_switch == 1){
- console.log("选择了开");
- that.data.client.publish(mpPubTopic_CU, '{"target":"CU","value":1}', function (err) {
- if (!err) {
- console.log("成功下发命令——开窗帘");
- }
- });
- }else{
- console.log("选择了关");
- that.data.client.publish(mpPubTopic_CU, '{"target":"CU","value":0}', function (err) {
- if (!err) {
- console.log("成功下发命令——关窗帘");
- }
- });
- }
- }else if(that.data.radio_select == 5){
- console.log("选择了SAN");
- if(that.data.radio_switch == 1){
- console.log("选择了开");
- that.data.client.publish(mpPubTopic_SAN, '{"target":"SAN","value":1}', function (err) {
- if (!err) {
- console.log("成功下发命令——开风扇");
- }
- });
- }else{
- console.log("选择了关");
- that.data.client.publish(mpPubTopic_SAN, '{"target":"SAN","value":0}', function (err) {
- if (!err) {
- console.log("成功下发命令——关风扇");
- }
- });
- }
- }
-
- Toast('倒计时结束');
- },
- setTextBreathing: function(cls,e) {
- //使用记录呼吸效果
- var transparency = 10;
- var reduce = true; //记录当前做透明度增加或降低操作
- setInterval(function(){
- if (reduce === true){
- transparency -= 1;
- if (transparency === 0){
- reduce = false;
- }
- } else if (reduce === false){
- transparency += 1;
- if (transparency === 10){
- reduce = true;
- }
- }
- cls._defaultComponent.setData({
- breathNum:transparency/10
- })
- //通过setData的方式,设置breathNum的值
- },80)
- },
- // 各个设备弹窗逻辑
- onOpen_led() {
- this.setData({ show_led: true });
- },
- onClose_led(){
- this.setData({
- show_led:false
- })
- },
- onSelect_led(event) {
- console.log(event.detail.id);
- this.onLedChange(event.detail.id);
- },
- onOpen_beep() {
- this.setData({ show_beep: true });
- },
- onClose_beep(){
- this.setData({
- show_beep:false
- })
- },
- onSelect_beep(event) {
- console.log(event.detail.id);
- this.onBeepChange(event.detail.id,event.detail.url,event.detail.entity_id);
- },
- getRealApi(){
- // if(wx.getStorageSync('res').result && wx.getStorageSync('res').result.includes('辰悦颐养斋')){
- // homeApi = "http://zhh.aidsleep.cn:9123/api";
- // homeApiLater = "http://zhh.aidsleep.cn:9123";
- // homeApi_https = "https://zhh.aidsleep.cn/api";
- // homeApiLater_https = "https://zhh.aidsleep.cn";
- // entity = wx.getStorageSync('res').result=='company_laboratory'?'公司实验室':wx.getStorageSync('res').result
- // if(entity && entity.includes('-')){
- // entity = entity.slice(entity.indexOf('-')+1)
- // }
- // if(entity && entity.includes('|')){
- // entity = entity.slice(entity.indexOf('|')+1)
- // }
- // }else if(wx.getStorageSync('res').result && (!wx.getStorageSync('res').result.includes('辰悦颐养斋'))){
- // homeApi = "http://haold.aidsleep.cn:8123/api";
- // homeApiLater = "http://haold.aidsleep.cn:8123";
- // homeApi_https = "https://haold.aidsleep.cn/api";
- // homeApiLater_https = "https://haold.aidsleep.cn";
- // entity = wx.getStorageSync('res').result=='company_laboratory'?'公司实验室':wx.getStorageSync('res').result
- // if(entity && entity.includes('-')){
- // entity = str.slice(str.indexOf('-')+1)
- // }
- // if(entity && entity.includes('|')){
- // entity = str.slice(str.indexOf('|')+1)
- // }
- // }
-
- },
- onSelect_vangrid(url,entity_id) {
- // this.setData({
- // status_beep: Number(param4)
- // })
-
- wx.request({
- url: `${homeApi_https}`+url,
- method: 'POST',
- data: {
- "entity_id":entity_id
- },
- header: {
- 'content-type': 'application/json', // 默认值
- 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
- },
- success(res) {
- },
- });
-
- },
- tvFanChange(e) {
- var that = this;
- // 获取绑定的参数
- var entity_id = e.currentTarget.dataset.id;
- //模式
- var fan = e.currentTarget.dataset.fan;
- wx.request({
- url: `${homeApi_https}`+'/services/media_player/select_source',
- method: 'POST',
- data: {
- "entity_id":entity_id,
- "source": fan
- },
- header: {
- 'content-type': 'application/json', // 默认值
- 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
- },
- success(res) {
- // if(res.data){
- // that.getSwitch(res.data,that)
- // }
- },
- });
-
- },
-
- onSelect_All(e) {
- var that = this;
- // 获取绑定的参数
- var param0 = e.currentTarget.dataset.param0;
- var param1 = e.currentTarget.dataset.param1;
- var param2 = e.currentTarget.dataset.param2;
- // var param3 = e.currentTarget.dataset.param3;
- // var param4 = e.currentTarget.dataset.param4;
- var param5 = e.currentTarget.dataset.param5;
- console.log('param1='+param1);
- console.log('param2='+param2);
- // console.log('param3='+param3);
- // console.log('param4='+param4);
- console.log('param5='+param5);
- // this.setData({
- // status_beep: Number(param4)
- // })
- // if(param3 == "/turn_on"){
- // that.data.listSwitch[param0].state = "off";
- // that.data.listSwitch[param0].service = "turn_off";
- // }else if(param3 == "/turn_off"){
- // that.data.listSwitch[param0].state = "on";
- // that.data.listSwitch[param0].service = "turn_on";
- // }
- console.log('switch 发生 change 事件,携带值为', e.detail.value)
- wx.request({
- url: `${homeApi_https}`+param1+param2+(e.detail.value?'/turn_on':'/turn_off'),
- method: 'POST',
- data: {
- "entity_id":param5
- },
- header: {
- 'content-type': 'application/json', // 默认值
- 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
- },
- success(res) {
- // if(res.data){
- // that.getSwitch(res.data,that)
- // }
- },
- });
-
- },
- //香薰机灯光控制
- onSelect_All_aromlight(e) {
- var that = this;
- this.setData({
- isClickedToggleAromlight: true
- });
- // 获取绑定的参数
- var param0 = e.currentTarget.dataset.param0;
- var param1 = e.currentTarget.dataset.param1;
- var param2 = e.currentTarget.dataset.param2;
- // var param3 = e.currentTarget.dataset.param3;
- // var param4 = e.currentTarget.dataset.param4;
- var param5 = e.currentTarget.dataset.param5;
- console.log('param1='+param1);
- console.log('param2='+param2);
- // console.log('param3='+param3);
- // console.log('param4='+param4);
- console.log('param5='+param5);
- // this.setData({
- // status_beep: Number(param4)
- // })
- // if(param3 == "/turn_on"){
- // that.data.listSwitch[param0].state = "off";
- // that.data.listSwitch[param0].service = "turn_off";
- // }else if(param3 == "/turn_off"){
- // that.data.listSwitch[param0].state = "on";
- // that.data.listSwitch[param0].service = "turn_on";
- // }
- console.log('switch 发生 change 事件,携带值为', e.detail.value)
- wx.request({
- url: `${homeApi_https}`+param1+param2+'/turn_on',
- method: 'POST',
- data: {
- "entity_id":param5
- },
- header: {
- 'content-type': 'application/json', // 默认值
- 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
- },
- success(res) {
- // if(res.data){
- // that.getSwitch(res.data,that)
- // }
- },
- });
-
- },
- onSelect_Cover(e) {
- var that = this;
- // 获取绑定的参数
- var param0 = e.currentTarget.dataset.param0;
- var param1 = e.currentTarget.dataset.param1;
- var param2 = e.currentTarget.dataset.param2;
- // var param3 = e.currentTarget.dataset.param3;
- // var param4 = e.currentTarget.dataset.param4;
- var param5 = e.currentTarget.dataset.param5;
- console.log('param1='+param1);
- console.log('param2='+param2);
- // console.log('param3='+param3);
- // console.log('param4='+param4);
- console.log('param5='+param5);
- // this.setData({
- // status_beep: Number(param4)
- // })
- // if(param3 == "/turn_on"){
- // that.data.listSwitch[param0].state = "off";
- // that.data.listSwitch[param0].service = "turn_off";
- // }else if(param3 == "/turn_off"){
- // that.data.listSwitch[param0].state = "on";
- // that.data.listSwitch[param0].service = "turn_on";
- // }
- console.log('switch 发生 change 事件,携带值为', e.detail.value)
- wx.request({
- url: `${homeApi_https}`+param1+param2+(e.detail.value?'/open_cover':'/close_cover'),
- method: 'POST',
- data: {
- "entity_id":param5
- },
- header: {
- 'content-type': 'application/json', // 默认值
- 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
- },
- success(res) {
- // if(res.data){
- // that.getSwitch(res.data,that)
- // }
- },
- });
-
- },
- onStop_Cover(e) {
- var that = this;
- // 获取绑定的参数
- var param0 = e.currentTarget.dataset.param0;
- var param1 = e.currentTarget.dataset.param1;
- var param2 = e.currentTarget.dataset.param2;
- // var param3 = e.currentTarget.dataset.param3;
- // var param4 = e.currentTarget.dataset.param4;
- var param5 = e.currentTarget.dataset.param5;
- console.log('param1='+param1);
- console.log('param2='+param2);
- // console.log('param3='+param3);
- // console.log('param4='+param4);
- console.log('param5='+param5);
- // this.setData({
- // status_beep: Number(param4)
- // })
- // if(param3 == "/turn_on"){
- // that.data.listSwitch[param0].state = "off";
- // that.data.listSwitch[param0].service = "turn_off";
- // }else if(param3 == "/turn_off"){
- // that.data.listSwitch[param0].state = "on";
- // that.data.listSwitch[param0].service = "turn_on";
- // }
- console.log('switch 发生 change 事件,携带值为', e.detail.value)
- wx.request({
- url: `${homeApi_https}`+param1+param2+'/stop_cover',
- method: 'POST',
- data: {
- "entity_id":param5
- },
- header: {
- 'content-type': 'application/json', // 默认值
- 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
- },
- success(res) {
- // if(res.data){
- // that.getSwitch(res.data,that)
- // }
- },
- });
-
- },
- onPressButton(e) {
- var that = this;
- // 获取绑定的参数
- var param = e.currentTarget.dataset.param;
- console.log("sliderChange-param="+param);
- // wx.request({
- // url: `${homeApi_https}`+param1+param2+param3,
- // method: 'POST',
- // data: {
- // "entity_id":param5
- // },
- // header: {
- // 'content-type': 'application/json', // 默认值
- // 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
- // },
- // success(res) {
- // // if(res.data){
- // // that.getSwitch(res.data,that)
- // // }
- // console.log('res.data====='+JSON.stringify(res.data));
- // },
- // });
- let domain = e.currentTarget.dataset.domain;
- let entity_id = e.currentTarget.dataset.id;
- let data = {
- "entity_id":entity_id,
- // "value":newValue
- }
- this.getService("/services","/"+domain,"/press","POST",data);
- },
-
- onSelect_beep1(e) {
- // 获取绑定的参数
- var param1 = e.currentTarget.dataset.param1;
- var param2 = e.currentTarget.dataset.param2;
- var param3 = e.currentTarget.dataset.param3;
- var param4 = e.currentTarget.dataset.param4;
- var param5 = e.currentTarget.dataset.param5;
- console.log('param1='+param1);
- console.log('param2='+param2);
- console.log('param3='+param3);
- console.log('param4='+param4);
- console.log('param5='+param5);
- this.setData({
- status_beep: Number(param4)
- })
-
- wx.request({
- url: `${homeApi_https}`+param1+param2+param3,
- method: 'POST',
- data: {
- "entity_id":param5
- },
- header: {
- 'content-type': 'application/json', // 默认值
- 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
- },
- success(res) {
- console.log('res.data====='+JSON.stringify(res.data));
- },
- });
-
- },
- status_led1(e) {
- // 获取绑定的参数
- var param1 = e.currentTarget.dataset.param1;
- var param2 = e.currentTarget.dataset.param2;
- var param3 = e.currentTarget.dataset.param3;
- var param4 = e.currentTarget.dataset.param4;
- var param5 = e.currentTarget.dataset.param5;
- this.setData({
- status_led: Number(param4)
- })
-
- wx.request({
- url: `${homeApi_https}`+param1+param2+param3,
- method: 'POST',
- data: {
- "entity_id":param5
- },
- header: {
- 'content-type': 'application/json', // 默认值
- 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
- },
- success(res) {
- console.log('res.data====='+JSON.stringify(res.data));
- },
- });
-
- },
- status_san1(e) {
- // 获取绑定的参数
- var param1 = e.currentTarget.dataset.param1;
- var param2 = e.currentTarget.dataset.param2;
- var param3 = e.currentTarget.dataset.param3;
- var param4 = e.currentTarget.dataset.param4;
- var param5 = e.currentTarget.dataset.param5;
- this.setData({
- status_san: Number(param4)
- })
-
- wx.request({
- url: `${homeApi_https}`+param1+param2+param3,
- method: 'POST',
- data: {
- "entity_id":param5
- },
- header: {
- 'content-type': 'application/json', // 默认值
- 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
- },
- success(res) {
- console.log('res.data====='+JSON.stringify(res.data));
- },
- });
-
- },
- status_curtain1(e) {
- // 获取绑定的参数
- var param1 = e.currentTarget.dataset.param1;
- var param2 = e.currentTarget.dataset.param2;
- var param3 = e.currentTarget.dataset.param3;
- var param4 = e.currentTarget.dataset.param4;
- var param5 = e.currentTarget.dataset.param5;
- this.setData({
- status_curtain: Number(param4)
- })
-
- wx.request({
- url: `${homeApi_https}`+param1+param2+param3,
- method: 'POST',
- data: {
- "entity_id":param5
- },
- header: {
- 'content-type': 'application/json', // 默认值
- 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
- },
- success(res) {
- console.log('res.data====='+JSON.stringify(res.data));
- },
- });
-
- },
- status_door1(e) {
- // 获取绑定的参数
- var param1 = e.currentTarget.dataset.param1;
- var param2 = e.currentTarget.dataset.param2;
- var param3 = e.currentTarget.dataset.param3;
- var param4 = e.currentTarget.dataset.param4;
- var param5 = e.currentTarget.dataset.param5;
- this.setData({
- status_door: Number(param4)
- })
-
- wx.request({
- url: `${homeApi_https}`+param1+param2+param3,
- method: 'POST',
- data: {
- "entity_id":param5
- },
- header: {
- 'content-type': 'application/json', // 默认值
- 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
- },
- success(res) {
- console.log('res.data====='+JSON.stringify(res.data));
- },
- });
-
- },
- onOpen_curtain() {
- this.setData({ show_curtain: true });
- },
- onClose_curtain(){
- this.setData({
- show_curtain:false
- })
- },
- onSelect_curtain(event) {
- console.log(event.detail.id);
- this.onCurtainChange(event.detail.id);
- },
- onOpen_san() {
- this.setData({ show_san: true });
- },
- onClose_san(){
- this.setData({
- show_san:false
- })
- },
- onSelect_san(event) {
- console.log(event.detail.id);
- this.onSanChange(event.detail.id);
- },
- onOpen_door() {
- this.setData({ show_door: true });
- },
- onClose_door(){
- this.setData({
- show_door:false
- })
- },
- onSelect_door(event) {
- console.log(event.detail.id);
- this.onDoorChange(event.detail.id);
- },
-
- // 各个设备弹窗逻辑 结束
- //设备控制函数 开始
- onFireChange(event){
- var that = this;
- console.log(event);
- let sw = event;
- that.setData({
- status_led: sw
- })
-
- if (sw) {
- that.data.client.publish(mpPubTopic_LED, '{"target":"LED","value":1}', function (err) {
- if (!err) {
- console.log("成功下发命令——打开客厅灯");
- }
- });
- } else {
- that.data.client.publish(mpPubTopic_LED, '{"target":"LED","value":0}', function (err) {
- if (!err) {
- console.log("成功下发命令——关闭客厅灯");
- }
- });
- }
- },
- onLedChange(event) {
- var that = this;
- console.log(event);
- let sw = event;
- that.setData({
- status_led: sw
- })
-
- if (sw) {
- that.data.client.publish(mpPubTopic_LED, '{"target":"LED","value":1}', function (err) {
- if (!err) {
- console.log("成功下发命令——打开客厅灯");
- }
- });
- } else {
- that.data.client.publish(mpPubTopic_LED, '{"target":"LED","value":0}', function (err) {
- if (!err) {
- console.log("成功下发命令——关闭客厅灯");
- }
- });
- }
- },
- onBeepChange(event,url,entity_id) {
- var that = this;
- console.log(event);
- let sw = event;
- that.setData({
- status_beep: sw
- })
- console.log("event="+event);
- console.log("url="+url);
- console.log("entity_id="+entity_id);
- if (sw) {
- // that.data.client.publish(mpPubTopic_BEEP, '{"target":"BEEP","value":1}', function (err) {
- // if (!err) {
- // console.log("成功下发命令——打开报警器");
- // }
- // });
- this.onSelect_vangrid(url,entity_id);
- } else {
- // that.data.client.publish(mpPubTopic_BEEP, '{"target":"BEEP","value":0}', function (err) {
- // if (!err) {
- // console.log("成功下发命令——关闭报警器");
- // }
- // });
- this.onSelect_vangrid(url,entity_id);
- }
- },
- onCurtainChange(event) {
- var that = this;
- console.log(event);
- let sw = event;
- that.setData({
- status_curtain: sw
- })
- if (sw) {
- that.data.client.publish(mpPubTopic_CU, '{"target":"CU","value":1}', function (err) {
- if (!err) {
- console.log("成功下发命令——开窗帘");
- }
- });
- } else{
- that.data.client.publish(mpPubTopic_CU, '{"target":"CU","value":0}', function (err) {
- if (!err) {
- console.log("成功下发命令——关窗帘");
- }
- });
- }
- },
- onSanChange(event) {
- var that = this;
- console.log(event);
- let sw = event;
- that.setData({
- status_san: sw
- })
- if (sw) {
- that.data.client.publish(mpPubTopic_SAN, '{"target":"SAN","value":1}', function (err) {
- if (!err) {
- console.log("成功下发命令——开风扇");
- }
- });
- } else{
- that.data.client.publish(mpPubTopic_SAN, '{"target":"SAN","value":0}', function (err) {
- if (!err) {
- console.log("成功下发命令——关风扇");
- }
- });
- }
- },
- onDoorChange(event) {
- var that = this;
- console.log(event);
- let sw = event;
- that.setData({
- status_door: sw
- })
- if (sw) {
- that.data.client.publish(mpPubTopic_DO, '{"target":"DO","value":1}', function (err) {
- if (!err) {
- console.log("成功下发命令——开门");
- }
- });
- } else{
- that.data.client.publish(mpPubTopic_DO, '{"target":"DO","value":0}', function (err) {
- if (!err) {
- console.log("成功下发命令——关门");
- }
- });
- }
- },
- onModeChange(event) {
- var that = this;
- console.log(event);
- let sw = event.detail.value;
- console.log(sw);
- that.setData({
- status_mode: sw
- })
- if (sw) {
- that.data.client.publish(mpPubTopic_Mode, '{"target":"OUT","value":1}', function (err) {
- if (!err) {
- console.log("成功下发命令——离家模式");
- }
- });
- } else{
- that.data.client.publish(mpPubTopic_Mode, '{"target":"OUT","value":0}', function (err) {
- if (!err) {
- console.log("成功下发命令——居家模式");
- }
- });
- }
- },
- getEntityState(list,entity_id) {
- if(list==null) return null;
- var obj = list.find(function (obj) {
- return obj.entity_id === entity_id
- })
- console.log('getEntityState=='+obj?(obj.state=='on'?1:0):null);
- return obj?(obj.state=='on'?1:0):null;
- },
- getEntityStateValue(list,entity_id) {
- if(list==null) return null;
- var obj = list.find(function (obj) {
- return obj.entity_id === entity_id
- })
- console.log('getEntityStateValue=='+obj?obj.state:null);
- return obj?obj.state:null;
- },
-
- //扫码
- tapScan(){
- wx.scanCode({
- success: function(res) {
- console.log('扫码获取的参数',res)
- }
- })
- },
- getSwitch(resData,that) {
- try {
- var listSwitchTemp = [];
- var entityIdList = [];
- const res = wx.getStorageSync('res');
- const home_room = wx.getStorageSync('res').home_room;
- for(let i=0;i<resData.length;i++){
- if(resData[i].attributes && resData[i].attributes.home_room && resData[i].attributes.home_room.includes((entity))){
- entityIdList.push(resData[i].entity_id)
- }
- }
- console.log('entityIdList====='+JSON.stringify(entityIdList));
- for(let i=0;i<resData.length;i++){
- if((resData[i].attributes && resData[i].attributes.home_room && resData[i].attributes.home_room.includes((entity)))
- || (resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id))
- ){
- var obj={};
- obj.entity_id = resData[i].entity_id;//实体ID
- obj.parent_entity_id = resData[i].parent_entity_id;//父实体ID
- //api/services/<domain>/<service>
- if(resData[i].entity_id){
- obj.domain = resData[i].entity_id.split(".")[0];
- }
- obj.state = (resData[i].state=='unknown'?"未知":resData[i].state);
- if(resData[i].attributes && resData[i].attributes.friendly_name){
- obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name); //设备名称
- }
- if(resData[i].attributes && resData[i].attributes.home_room){
- obj.home_room = resData[i].attributes.home_room.split(' ')[1]; //房间号
- }
- if((resData[i].state && (resData[i].state=='on' || resData[i].state=='off'))||
- (resData[i].state && resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList
- && entityIdList.includes(resData[i].attributes.parent_entity_id) && (resData[i].state=='on' || resData[i].state=='off'))
- ){
- if(resData[i].state=='on'){
- obj.service = 'turn_on';
- }else if(resData[i].state=='off'){
- obj.service = 'turn_off';
- }
- //是否 是香薰机灯光
- obj.isAromlight = obj.friendly_name.includes('香薰机灯光')
- if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
- listSwitchTemp.push(obj)
- }
- }
- }
- }
- console.log('listSwitchTemp='+JSON.stringify(listSwitchTemp));
- that.setData({
- listSwitch:listSwitchTemp,
- })
- } catch (error) {
- console.error(error);
- }
- },
- //设备控制函数 结束
- sliderChange(e){
- let list = this.data.listScroll;//这里是将需要循环的数组赋值给list
- let indexS = Number(e.currentTarget.dataset.index);
- let domain = e.currentTarget.dataset.domain;
- let entity_id = e.currentTarget.dataset.id;
- // 将本地缓存数据渲染到对应修改的案例
- list.forEach(function (value,index, array){
-
- if (index == indexS) {
- array[index].state = e.detail.value;
- }
- })
- this.setData({
- listScroll: list
- })
- let data = {
- "entity_id":entity_id,
- "value":e.detail.value,
- }
- this.getService("/services","/"+domain,"/set_value","POST",data);
- // 设置两秒(2000毫秒)后的延迟
- // setTimeout(() => {
- // this.getMiotMediaPlayer(this);
- // }, 2000);
- },
- onArrowUp(e) {
- // 在这里处理向上箭头的点击事件
- // 例如,你可以增加文本框的值
- let currentValue = e.currentTarget.dataset.state;
- let newValue = parseInt(currentValue) + 1; // 假设文本框中的是数字
- // this.setData({
- // inputValue: newValue.toString()
- // });
-
- let list = this.data.listUnit;//这里是将需要循环的数组赋值给list
- let indexS = Number(e.currentTarget.dataset.index)
- let domain = e.currentTarget.dataset.domain;
- let entity_id = e.currentTarget.dataset.id;
- // 将本地缓存数据渲染到对应修改的案例
- list.forEach(function (value,index, array){
- if (index == indexS) {
- array[index].state = newValue;
- }
- })
- this.setData({
- listUnit: list
- })
- let data = {
- "entity_id":entity_id,
- "value":newValue
- }
- this.getService("/services","/"+domain,"/set_value","POST",data);
- },
- changeHumidity(e){
- let list = this.data.listHumidifier;//这里是将需要循环的数组赋值给list
- let indexS = Number(e.currentTarget.dataset.index);
- let domain = e.currentTarget.dataset.domain;
- let entity_id = e.currentTarget.dataset.id;
- // 将本地缓存数据渲染到对应修改的案例
- list.forEach(function (value,index, array){
-
- if (index == indexS) {
- array[index].humidity = e.detail.value;
- }
- })
- this.setData({
- listHumidifier: list
- })
- let data = {
- "entity_id":entity_id,
- "humidity":e.detail.value
- }
- this.getService("/services","/"+domain,"/set_humidity","POST",data);
- },
- onHumidifierDown(e) {
- var that = this;
- this.setData({
- isClickedOnHumidifierDown: true
- });
- // 在这里处理向下箭头的点击事件
- // 例如,你可以减少文本框的值
- let currentValue = e.currentTarget.dataset.humidity;
- let min = e.currentTarget.dataset.min;
- let max = e.currentTarget.dataset.max;
- let newValue = parseInt(currentValue) - 1; // 假设文本框中的是数字
- if(newValue<min){
- newValue = min;
- }
- // this.setData({
- // inputValue: newValue.toString()
- // });
-
- let list = this.data.listHumidifier;//这里是将需要循环的数组赋值给list
- let indexS = Number(e.currentTarget.dataset.index)
- let domain = e.currentTarget.dataset.domain;
- let entity_id = e.currentTarget.dataset.id;
- // 将本地缓存数据渲染到对应修改的案例
- list.forEach(function (value,index, array){
- if (index == indexS) {
- array[index].humidity = newValue;
- }
- })
- this.setData({
- listHumidifier: list,
- // isButtonPressedHumidityDown:!that.data.isButtonPressedHumidityDown
- })
- let data = {
- "entity_id":entity_id,
- "humidity":newValue
- }
- this.getService("/services","/"+domain,"/set_humidity","POST",data);
- },
- onHumidifierUp(e) {
- var that = this;
- this.setData({
- isClickedOnHumidifierUp: true
- });
- // 在这里处理向上箭头的点击事件
- // 例如,你可以增加文本框的值
- let currentValue = e.currentTarget.dataset.humidity;
- let min = e.currentTarget.dataset.min;
- let max = e.currentTarget.dataset.max;
- let newValue = parseInt(currentValue) + 1; // 假设文本框中的是数字
- if(newValue>max){
- newValue = max;
- }
- // this.setData({
- // inputValue: newValue.toString()
- // });
-
- let list = this.data.listHumidifier;//这里是将需要循环的数组赋值给list
- let indexS = Number(e.currentTarget.dataset.index)
- let domain = e.currentTarget.dataset.domain;
- let entity_id = e.currentTarget.dataset.id;
- // 将本地缓存数据渲染到对应修改的案例
- list.forEach(function (value,index, array){
- if (index == indexS) {
- array[index].humidity = newValue;
- }
- })
- this.setData({
- listHumidifier: list,
- // isButtonPressedHumidityUp:!that.data.isButtonPressedHumidityUp
- })
- let data = {
- "entity_id":entity_id,
- "humidity":newValue
- }
- this.getService("/services","/"+domain,"/set_humidity","POST",data);
- },
- onHumidifierOn(e) {
- let domain = e.currentTarget.dataset.domain;
- let entity_id = e.currentTarget.dataset.id;
- let data = {
- "entity_id":entity_id,
- }
- this.getService("/services","/"+domain,"/turn_on","POST",data);
- },
- onHumidifierOff(e) {
- let domain = e.currentTarget.dataset.domain;
- let entity_id = e.currentTarget.dataset.id;
- let min = e.currentTarget.dataset.min;
- let max = e.currentTarget.dataset.max;
- let data = {
- "entity_id":entity_id,
- }
- this.getService("/services","/"+domain,"/turn_off","POST",data);
- },
-
- changeClimate(e) {
- var that = this;
- this.setData({
- isClickedOnClimateUp: true
- });
- console.log('that.data.climateMode=='+that.data.climateMode);
- if(!that.data.climateMode){
- wx.showToast({
- title: '请先选择模式',
- icon: 'none'
- });
- return;
- }
- let currentValue = e.currentTarget.dataset.temperature;
- let fanMode = e.currentTarget.dataset.fanMode;
-
- let min = e.currentTarget.dataset.min;
- let max = e.currentTarget.dataset.max;
- let domain = e.currentTarget.dataset.domain;
- let entity_id = e.currentTarget.dataset.id;
- let data = {};
- if(that.data.climateMode=='heat' ||that.data.climateMode=='cool'){
- let newValue = parseInt(currentValue) + 1; // 假设文本框中的是数字
- if(newValue>max) newValue = max;
- let list = this.data.listClimate;//这里是将需要循环的数组赋值给list
- let indexS = Number(e.currentTarget.dataset.index);
- // 将本地缓存数据渲染到对应修改的案例
- list.forEach(function (value,index, array){
- if (index == indexS) {
- array[index].temperature = e.detail.value;
- }
- })
- this.setData({
- listClimate: list
- })
- data = {
- "entity_id":entity_id,
- "temperature":e.detail.value,
- "hvac_mode":that.data.climateMode
- }
- this.getService("/services","/"+domain,"/set_temperature","POST",data);
- }else if(that.data.climateMode=='dry'){
- let newValue = parseInt(currentValue) + 1; // 假设文本框中的是数字
- if(newValue>max) newValue = max;
- data = {
- "entity_id":entity_id,
- "temperature":e.detail.value,
- "hvac_mode":that.data.climateMode
- }
- this.getService("/services","/"+domain,"/set_temperature","POST",data);
- }else if(that.data.climateMode=='fan_only'){
- let newValue = parseInt(currentValue) + 1; // 假设文本框中的是数字
- if(newValue>max) newValue = max;
- data = {
- "entity_id":entity_id,
- // "fan_mode":(fanMode=='Fan Speed Up')?'Fan Speed Down':'Fan Speed Up',
- "temperature":e.detail.value,
- "hvac_mode":that.data.climateMode
- }
- this.getService("/services","/"+domain,"/set_temperature","POST",data);
- }
- },
- onClimateDown(e) {
- var that = this;
- if(!that.data.climateMode){
- wx.showToast({
- title: '请先选择模式',
- icon: 'none'
- });
- return;
- }
- console.log('that.data.climateMode=='+that.data.climateMode);
- let currentValue = e.currentTarget.dataset.temperature;
- let fanMode = e.currentTarget.dataset.fanMode;
- // let list = this.data.listClimate;
- // this.setData({
- // inputValue: newValue.toString()
- // });
-
-
- let domain = e.currentTarget.dataset.domain;
- let entity_id = e.currentTarget.dataset.id;
- let min = e.currentTarget.dataset.min;
- let max = e.currentTarget.dataset.max;
- // this.setData({
- // isButtonPressedClimateDown: !that.data.isButtonPressedClimateDown
- // })
- // 将本地缓存数据渲染到对应修改的案例
- // list.forEach(function (value,index, array){
- // if (index == indexS) {
- // array[index].temperature = newValue;
- // }
- // })
- // this.setData({
- // listClimate: list
- // })
- let data = {};
- if(that.data.climateMode=='heat' ||that.data.climateMode=='cool'){
- let newValue = parseInt(currentValue) - 1; // 假设文本框中的是数字
- if(newValue<min) newValue = min;
- let list = this.data.listClimate;//这里是将需要循环的数组赋值给list
- let indexS = Number(e.currentTarget.dataset.index);
- // 将本地缓存数据渲染到对应修改的案例
- list.forEach(function (value,index, array){
- if (index == indexS) {
- array[index].temperature = newValue;
- }
- })
- this.setData({
- listClimate: list
- })
- console.log('onClimateDown-entity_id='+entity_id);
- data = {
- "entity_id":entity_id,
- "temperature":newValue,
- "hvac_mode":that.data.climateMode
- }
- this.getService("/services","/"+domain,"/set_temperature","POST",data);
- }else if(that.data.climateMode=='dry'){
- let newValue = parseInt(currentValue) - 1; // 假设文本框中的是数字
- if(newValue<min) newValue = min;
- data = {
- "entity_id":entity_id,
- "temperature":newValue,
- "hvac_mode":that.data.climateMode
- }
- this.getService("/services","/"+domain,"/set_temperature","POST",data);
- }else if(that.data.climateMode=='fan_only'){
- let newValue = parseInt(currentValue) - 1; // 假设文本框中的是数字
- if(newValue<min) newValue = min;
- data = {
- "entity_id":entity_id,
- // "fan_mode":(fanMode=='Fan Speed Up')?'Fan Speed Down':'Fan Speed Up',
- "temperature":newValue,
- "hvac_mode":that.data.climateMode
- }
- this.getService("/services","/"+domain,"/set_temperature","POST",data);
- }
- },
- onClimateUp(e) {
- var that = this;
- this.setData({
- isClickedOnClimateUp: true
- });
- console.log('that.data.climateMode=='+that.data.climateMode);
- if(!that.data.climateMode){
- wx.showToast({
- title: '请先选择模式',
- icon: 'none'
- });
- return;
- }
- let currentValue = e.currentTarget.dataset.temperature;
- let fanMode = e.currentTarget.dataset.fanMode;
-
- let min = e.currentTarget.dataset.min;
- let max = e.currentTarget.dataset.max;
- // this.setData({
- // inputValue: newValue.toString()
- // });
-
- // let list = this.data.listClimate;//这里是将需要循环的数组赋值给list
- // let indexS = Number(e.currentTarget.dataset.index)
- let domain = e.currentTarget.dataset.domain;
- let entity_id = e.currentTarget.dataset.id;
- // this.setData({
- // isButtonPressedClimateUp: !that.data.isButtonPressedClimateUp
- // })
- // 将本地缓存数据渲染到对应修改的案例
- // list.forEach(function (value,index, array){
- // if (index == indexS) {
- // array[index].temperature = newValue;
- // }
- // })
- // this.setData({
- // listClimate: list
- // })
- let data = {};
- if(that.data.climateMode=='heat' ||that.data.climateMode=='cool'){
- let newValue = parseInt(currentValue) + 1; // 假设文本框中的是数字
- if(newValue>max) newValue = max;
- let list = this.data.listClimate;//这里是将需要循环的数组赋值给list
- let indexS = Number(e.currentTarget.dataset.index);
- // 将本地缓存数据渲染到对应修改的案例
- list.forEach(function (value,index, array){
- if (index == indexS) {
- array[index].temperature = newValue;
- }
- })
- this.setData({
- listClimate: list
- })
- data = {
- "entity_id":entity_id,
- "temperature":newValue,
- "hvac_mode":that.data.climateMode
- }
- this.getService("/services","/"+domain,"/set_temperature","POST",data);
- }else if(that.data.climateMode=='dry'){
- let newValue = parseInt(currentValue) + 1; // 假设文本框中的是数字
- if(newValue>max) newValue = max;
- data = {
- "entity_id":entity_id,
- "temperature":newValue,
- "hvac_mode":that.data.climateMode
- }
- this.getService("/services","/"+domain,"/set_temperature","POST",data);
- }else if(that.data.climateMode=='fan_only'){
- let newValue = parseInt(currentValue) + 1; // 假设文本框中的是数字
- if(newValue>max) newValue = max;
- data = {
- "entity_id":entity_id,
- // "fan_mode":(fanMode=='Fan Speed Up')?'Fan Speed Down':'Fan Speed Up',
- "temperature":newValue,
- "hvac_mode":that.data.climateMode
- }
- this.getService("/services","/"+domain,"/set_temperature","POST",data);
- }
- },
- onClimateAuto(e) {
- this.setData({
- isClickedOnClimateAuto: true
- });
- let domain = e.currentTarget.dataset.domain;
- let entity_id = e.currentTarget.dataset.id;
- let list = this.data.listClimate;//这里是将需要循环的数组赋值给list
- let indexS = Number(e.currentTarget.dataset.index);
- // 将本地缓存数据渲染到对应修改的案例
- list.forEach(function (value,index, array){
- if (index == indexS) {
- array[index].state = newValue;
- }
- })
- this.setData({
- temperatureHumidifyName:'自动',
- climateMode:'auto',
- listClimate: list
- })
- let data = {
- "entity_id":entity_id,
- "hvac_mode":'auto',
- }
- this.getService("/services","/"+domain,"/set_hvac_mode","POST",data);
- },
- onClimateHeat(e) {
- let domain = e.currentTarget.dataset.domain;
- let entity_id = e.currentTarget.dataset.id;
- let list = this.data.listClimate;//这里是将需要循环的数组赋值给list
- let indexS = Number(e.currentTarget.dataset.index);
- // 将本地缓存数据渲染到对应修改的案例
- list.forEach(function (value,index, array){
- if (index == indexS) {
- array[index].state = newValue;
- }
- })
- this.setData({
- temperatureHumidifyName:'制热',
- climateMode:'heat',
- listClimate: list
- })
- let data = {
- "entity_id":entity_id,
- "hvac_mode":'heat',
- }
- this.getService("/services","/"+domain,"/set_hvac_mode","POST",data);
- },
- onClimateCool(e) {
- let domain = e.currentTarget.dataset.domain;
- let entity_id = e.currentTarget.dataset.id;
- let list = this.data.listClimate;//这里是将需要循环的数组赋值给list
- let indexS = Number(e.currentTarget.dataset.index);
- // 将本地缓存数据渲染到对应修改的案例
- list.forEach(function (value,index, array){
- if (index == indexS) {
- array[index].state = newValue;
- }
- })
- this.setData({
- temperatureHumidifyName:'制冷',
- climateMode:'cool',
- listClimate: list
- })
- let data = {
- "entity_id":entity_id,
- "hvac_mode":'cool',
- }
- this.getService("/services","/"+domain,"/set_hvac_mode","POST",data);
- },
- onClimateDehumidify(e) {
- let domain = e.currentTarget.dataset.domain;
- let entity_id = e.currentTarget.dataset.id;
- let list = this.data.listClimate;//这里是将需要循环的数组赋值给list
- let indexS = Number(e.currentTarget.dataset.index);
- // 将本地缓存数据渲染到对应修改的案例
- list.forEach(function (value,index, array){
- if (index == indexS) {
- array[index].state = newValue;
- }
- })
- this.setData({
- temperatureHumidifyName:'除湿',
- climateMode:'dry',
- listClimate: list
- })
- let data = {
- "entity_id":entity_id,
- "hvac_mode":'dry',
- }
- this.getService("/services","/"+domain,"/set_hvac_mode","POST",data);
- },
- onClimateAirSupply(e) {
- let domain = e.currentTarget.dataset.domain;
- let entity_id = e.currentTarget.dataset.id;
- let list = this.data.listClimate;//这里是将需要循环的数组赋值给list
- let indexS = Number(e.currentTarget.dataset.index);
- // 将本地缓存数据渲染到对应修改的案例
- list.forEach(function (value,index, array){
- if (index == indexS) {
- array[index].state = newValue;
- }
- })
- this.setData({
- temperatureHumidifyName:'送风',
- climateMode:'fan_only',
- listClimate: list
- })
- let data = {
- "entity_id":entity_id,
- "hvac_mode":'fan_only',
- }
- this.getService("/services","/"+domain,"/set_hvac_mode","POST",data);
- },
- onClimateOff(e) {
- let domain = e.currentTarget.dataset.domain;
- let entity_id = e.currentTarget.dataset.id;
- let list = this.data.listClimate;//这里是将需要循环的数组赋值给list
- let indexS = Number(e.currentTarget.dataset.index);
- // 将本地缓存数据渲染到对应修改的案例
- list.forEach(function (value,index, array){
- if (index == indexS) {
- array[index].state = newValue;
- }
- })
- this.setData({
- temperatureHumidifyName:'关闭',
- climateMode:'off',
- listClimate: list
- })
- let data = {
- "entity_id":entity_id,
- }
- this.getService("/services","/"+domain,"/turn_off","POST",data);
- },
- handleInput: function(e) {
- // 这里你需要自己实现歌曲列表和切换逻辑
- // 例如,如果你有一个歌曲列表,你可以通过修改当前播放歌曲的索引来切换歌曲
- // 假设你有一个歌曲列表`songs`和一个当前歌曲索引`currentIndex`
- // if (this.data.currentIndex > 0) {
- // this.data.currentIndex--;
- // // 加载新歌曲并播放
- // this.loadAndPlaySong(this.data.currentIndex);
- // }
- let min = e.currentTarget.dataset.min;
- let max = e.currentTarget.dataset.max;
- if(e.detail.value && (e.detail.value.length>max || e.detail.value.length<min)){
- wx.showModal({
- title: '提示',
- content: '文本长度介于'+min+'~'+max+'长度之间',
- showCancel: false
- });
- return;
- }
- let domain = e.currentTarget.dataset.domain;
- let entity_id = e.currentTarget.dataset.id;
- let data = {
- "entity_id":entity_id,
- "value":e.detail.value,
- }
- this.getService("/services","/"+domain,"/set_value","POST",data);
- },
- onArrowDown(e) {
- // 在这里处理向下箭头的点击事件
- // 例如,你可以减少文本框的值
- let currentValue = e.currentTarget.dataset.state;
- let newValue = parseInt(currentValue) - 1; // 假设文本框中的是数字
- // this.setData({
- // inputValue: newValue.toString()
- // });
-
- let list = this.data.listUnit;//这里是将需要循环的数组赋值给list
- let indexS = Number(e.currentTarget.dataset.index)
- let domain = e.currentTarget.dataset.domain;
- let entity_id = e.currentTarget.dataset.id;
- // 将本地缓存数据渲染到对应修改的案例
- list.forEach(function (value,index, array){
- if (index == indexS) {
- array[index].state = newValue;
- }
- })
- this.setData({
- listUnit: list
- })
- let data = {
- "entity_id":entity_id,
- "value":newValue
- }
- this.getService("/services","/"+domain,"/set_value","POST",data);
- },
- prevSong: function(e) {
- // 这里你需要自己实现歌曲列表和切换逻辑
- // 例如,如果你有一个歌曲列表,你可以通过修改当前播放歌曲的索引来切换歌曲
- // 假设你有一个歌曲列表`songs`和一个当前歌曲索引`currentIndex`
- // if (this.data.currentIndex > 0) {
- // this.data.currentIndex--;
- // // 加载新歌曲并播放
- // this.loadAndPlaySong(this.data.currentIndex);
- // }
- this.setData({
- isClickedPrevSong: true
- });
- let domain = e.currentTarget.dataset.domain;
- let entity_id = e.currentTarget.dataset.id;
- let data = {
- "entity_id":entity_id,
- }
- this.getService("/services","/"+domain,"/media_previous_track","POST",data);
- // setTimeout(() => {
- // this.getMiotMediaPlayer(this);
- // }, 8000);
- },
-
- tvTurnOn: function(e) {
- let domain = e.currentTarget.dataset.domain;
- let entity_id = e.currentTarget.dataset.id;
- let data = {
- "entity_id":entity_id,
- }
- this.getService("/services","/"+domain,"/turn_on","POST",data);
- },
- tvTurnOff: function(e) {
- let domain = e.currentTarget.dataset.domain;
- let entity_id = e.currentTarget.dataset.id;
- let data = {
- "entity_id":entity_id,
- }
- this.getService("/services","/"+domain,"/turn_off","POST",data);
- },
-
- // 切换播放/暂停
- togglePlayPause: function(e) {
- // console.log("this.data.isPlaying="+this.data.isPlaying);
- // if (this.data.isPlaying) {
- // this.innerAudioContext.pause();
- // this.setData({ isPlaying: false });
- // this.getService("/services","/"+domain,"/media_pause","POST",null);
- // } else {
- // this.innerAudioContext.play();
- // this.setData({ isPlaying: true });
- // this.getService("/services","/"+domain,"/media_play","POST",null);
- // }
- // let list = this.data.listMiotMediaPlayer;//这里是将需要循环的数组赋值给list
- this.setData({
- isClickedTogglePlayPause: true
- });
- let indexS = Number(e.currentTarget.dataset.index)
- let domain = e.currentTarget.dataset.domain;
- let entity_id = e.currentTarget.dataset.id;
- let state = e.currentTarget.dataset.state;
- // 将本地缓存数据渲染到对应修改的案例
- // list.forEach(function (value,index, array){
- // if (index == indexS) {
- // array[index].state = (state=='playing'?'idle':'playing');
- // }
- // })
- // this.setData({
- // listMiotMediaPlayer: list
- // })
- let data = {
- "entity_id":entity_id,
- }
- this.getService("/services","/"+domain,"/media_play_pause","POST",data);
-
- // 设置两秒(2000毫秒)后的延迟
- // setTimeout(() => {
- // this.getMiotMediaPlayer(this);
- // }, 8000);
-
- },
-
- // 切换下一首歌曲
- nextSong: function(e) {
- // 和prevSong类似,你需要实现歌曲列表和切换逻辑
- // 假设歌曲列表为`songs`,当前歌曲索引为`currentIndex`
- // if (this.data.currentIndex < songs.length - 1) {
- // this.data.currentIndex++;
- // // 加载新歌曲并播放
- // this.loadAndPlaySong(this.data.currentIndex);
- // }
- this.setData({
- isClickedNextSong: true
- });
- let domain = e.currentTarget.dataset.domain;
- let entity_id = e.currentTarget.dataset.id;
- let data = {
- "entity_id":entity_id,
- }
- this.getService("/services","/"+domain,"/media_next_track","POST",data);
- // setTimeout(() => {
- // this.getMiotMediaPlayer(this);
- // }, 8000);
- },
-
- // 加载并播放指定索引的歌曲
- loadAndPlaySong: function(index) {
- // 假设你有一个歌曲列表`songs`,每个歌曲对象有`url`属性表示音频链接
- const song = songs[index];
- this.innerAudioContext.src = song.url;
- this.innerAudioContext.play();
- // 更新当前播放的歌曲信息(例如标题和艺术家)
- this.setData({
- currentSongTitle: song.title,
- currentSongArtist: song.artist
- });
- },
- base64Decode:function(input) {
- const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
- let str = '';
- let output = '';
- let chr1, chr2, chr3;
- let enc1, enc2, enc3, enc4;
- let i = 0;
-
- input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
-
- while (i < input.length) {
- enc1 = chars.indexOf(input.charAt(i++));
- enc2 = chars.indexOf(input.charAt(i++));
- enc3 = chars.indexOf(input.charAt(i++));
- enc4 = chars.indexOf(input.charAt(i++));
-
- chr1 = (enc1 << 2) | (enc2 >> 4);
- chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
- chr3 = ((enc3 & 3) << 6) | enc4;
-
- str += String.fromCharCode(chr1);
-
- if (enc3 != 64) {
- str += String.fromCharCode(chr2);
- }
- if (enc4 != 64) {
- str += String.fromCharCode(chr3);
- }
- }
-
- return str;
- },
- onPickerChange: function(e) {
- // this.setData({
- // selectedIndex: e.detail.value
- // });
- // // 可以在这里处理选中值的变化,比如发送请求等
- // console.log('选中的值是:', this.data.options[e.detail.value].value);
-
- let list = this.data.listSelect;//这里是将需要循环的数组赋值给list
- let indexS = Number(e.currentTarget.dataset.index)
- let domain = e.currentTarget.dataset.domain;
- let entity_id = e.currentTarget.dataset.id;
- // 将本地缓存数据渲染到对应修改的案例
- list.forEach(function (value,index, array){
- if (index == indexS) {
- array[index].selectedIndex = e.detail.value;
- }
- })
- this.setData({
- listSelect: list
- })
- let data = {
- "entity_id":entity_id,
- "option":e.detail.value,
- }
- this.getService("/services","/"+domain,"/select_option","POST",data);
- },
- getService(services,domain,service,method,data) {
- wx.request({
- url: `${homeApi_https}`+services+domain+service,
- method: method,
- data: data,
- header: {
- 'content-type': 'application/json', // 默认值
- 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
- },
- success(res) {
- console.log('res.data====='+JSON.stringify(res.data));
- },
- });
- },
- // 初始化时调用即可
- showCanvasRing() {
- try {
- //作画
- var ctx = wx.createCanvasContext("circleBar", this); //canvas组建封装,需要后加个this
- ctx.clearRect(0, 0, this.data.canvasWidth, this.data.canvasHeight); // 清除画布
-
- var circle_r = this.data.canvasWidth / 2 - 10; //画布的一半,用来找中心点和半径
- var scoreText = this.data.value; // 当前得分
- var total = this.data.total;// 总分值
-
- var score = (100 * scoreText) / total; // 满分为100时对应的值
- let that = this;
-
- //定义起始点
- ctx.translate(this.data.canvasWidth / 2, this.data.canvasWidth / 2 + 5);
- // 白边圆弧
- ctx.beginPath();
- ctx.setStrokeStyle("#FFFFFF");
- ctx.setLineWidth(16);
- ctx.setLineCap("round");
- ctx.arc(0, 0, circle_r - 15, 1 * Math.PI, 0, false);
- ctx.stroke();
- ctx.closePath();
-
- //灰色圆弧
- ctx.beginPath();
- ctx.setStrokeStyle("#D6E4FF");
- ctx.setLineWidth(12);
- ctx.setLineCap("round"); //线条结束端点样式 butt 平直 round 圆形 square 正方形
- ctx.arc(0, 0, circle_r - 15, 1 * Math.PI, 0, false);
- ctx.stroke();
- ctx.closePath();
-
- // 蓝色圆弧
- ctx.beginPath();
- ctx.setStrokeStyle("#3366FF");
- ctx.setLineWidth(16);
- ctx.arc(
- 0,
- 0,
- circle_r - 15,
- 1 * Math.PI,
- (score / 100 + 1) * Math.PI,
- false
- );
- ctx.stroke();
- ctx.closePath();
- // 指示器-外层
- let deg = 270 - score * 1.8;
- const xAxis = Math.sin(((2 * Math.PI) / 360) * deg) * (circle_r - 15);
- const yAxis = Math.cos(((2 * Math.PI) / 360) * deg) * (circle_r - 15);
- ctx.beginPath();
- ctx.arc(xAxis, yAxis, 11, 0, 2 * Math.PI);
- ctx.setFillStyle("#FFFFFF");
- ctx.fill();
- // 指示器-内层
- const xAxis2 = Math.sin(((2 * Math.PI) / 360) * deg) * (circle_r - 15);
- const yAxis2 = Math.cos(((2 * Math.PI) / 360) * deg) * (circle_r - 15); // circle_r - 10
- ctx.beginPath();
- ctx.arc(xAxis2, yAxis2, 6, 0, 2 * Math.PI);
- ctx.setFillStyle("#3366FF");
- ctx.fill();
-
- // 文字-总得分
- ctx.setTextAlign("center"); // 字体位置
- ctx.setFillStyle("#333333");
- ctx.font = "normal normal 16px Arial,sans-serif";
- ctx.fillText("总得分", 0, -30);
- // 文字-具体分数
- ctx.setTextAlign("center"); // 字体位置
- ctx.setFillStyle("#000000");
- ctx.font = "normal bold 36px Arial,sans-serif";
- ctx.fillText(scoreText, 0, 13);
-
- // 最低分
- ctx.setFillStyle("#666666");
- ctx.font = "normal normal 13px Arial,sans-serif";
- ctx.fillText(0, -circle_r + 10, 25);
- // 最高分
- ctx.setFillStyle("#666666");
- ctx.font = "normal normal 13px Arial,sans-serif";
- ctx.fillText(total, circle_r - 15, 25);
-
- // 绘图
- ctx.draw(false, function () {
- //将生成好的图片保存到本地
- wx.canvasToTempFilePath(
- {
- canvasId: "circleBar",
- success: function (res) {
- var tempFilePath = res.tempFilePath;
- that.setData({
- loadImagePath: tempFilePath,
- });
- },
- fail: function (res) {},
- },
- );
- });
- } catch (error) {
- }
- },
-
- getHAData(that,hotelcode,roomcode){
- let start = Date.now(); // 获取当前时间(毫秒)
- // console.log('start=='+start);
-
-
-
- wx.request({
- url: `${aipushApi}/getha`, //
- method: 'POST',
- // header: {
- // 'content-type': 'application/json', // 默认值
- // 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
- // },
- data:{
- "locations":hotelcode,"room":(hotelcode && hotelcode.includes('hotel'))?roomcode:"","token":token_push
- },
- success(ress) {
- if(!ress || !ress.data){
- console.error("getha(),没有获取到数据");
- return;
- }
- var resData = ress.data
- console.log("resData-=="+JSON.stringify(resData));
- console.log("resData.loc-=="+JSON.stringify(resData.loc));
- homeApi_https = resData.loc+"/api";
- homeApiLater_https = resData.loc;
- token = resData.token;
- // console.log('res.data='+JSON.stringify(resData));
- if (ress.data.code == "400") {
- console.error("400错误!");
- return;
- }
- if (ress.data.code == "401") {
- console.error("401错误!");
- return;
- }
- try {
-
- //获取HA 设备状态数据
- // wx.request({
- // url: `${homeApi_https}/states`, //获取空气数据
- // method: 'GET',
- // header: {
- // 'content-type': 'application/json', // 默认值
- // 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
- // },
- // success(res) {
- // if(!res || !res.data){
- // return;
- // }
- // var resData = res.data
- // // console.log('res.data='+JSON.stringify(resData));
- // if (res.data.code == "400") {
- // console.error("400错误!");
- // return;
- // }
- // if (res.data.code == "401") {
- // console.error("401错误 --- 请检查你的API或Key是否正确!");
- // return;
- // }
- // try {
-
-
- // const {
- // now
- // } = res.data;
- // console.log('res.data1='+JSON.stringify(resData));
- // res.data.find(function (obj) {
- // console.log('obj='+obj);
- // })
- // res.data.forEach((item, index) => {
- // console.log(index, item);
- // });
- var listCoverTemp = [];
- var listSwitchTemp = [];
- var listScrollTemp = [];
- var listUnitTemp = [];
- var listConversationTemp = [];
- var listConversation1Temp = [];
- var listHumidityTemp = [];
- var listButtonTemp = [];
- var listSelectTemp = [];
- var listClimateTemp = [];
- var listMiotMediaPlayerTemp = [];
- var listMitvMediaPlayerTemp = [];
- var listHumidifierTemp = [];
- var listSensorTemp = [];
- var listTextTemp = [];
-
- var tvEntityIdTemp = '';
- var tvEntityIdsTemp = [];
- var climateModeTemp = '';
- var temperatureHumidifyNameTemp = '温度';
-
- var entityIdList = [];
- const res = wx.getStorageSync('res');
- const home_room = wx.getStorageSync('res').home_room;
- // console.log('entity=====@==='+entity);
- wx.request({
- url: `${homeApi_https}/aidsleep/entity`, //获取空气数据
- method: 'POST',
- header: {
- 'content-type': 'application/json', // 默认值
- 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
- },
- //
- data:{
- "template": "{{ label_entities('"+(entity)+"') }}"
- },
- success(resTemplate) {
- let mid = Date.now(); // 再次获取当前时间(毫秒)
- // console.log('mid=='+mid);
- if(!resTemplate || !resTemplate.data){
- console.log('no data:'+mid);
- return;
- }
- let resData = resTemplate.data;
- // resData = resData.filter(item1 => {
- // return JSON.parse(that.replaceAll(resTemplate.data,'\'','\"')).find(item2 => item2 === item1.entity_id) !== undefined;
- // });
- // console.log('entityIdList-resTemplate====='+JSON.stringify(resTemplate.data));
- for(let i=0;i<resData.length;i++){
- // if(resTemplate.data.includes(resData[i].entity_id) && that.checkFuzzyMatch(resData[i])){
- var obj={};
- obj.entity_id = resData[i].entity_id;//实体ID
- obj.parent_entity_id = resData[i].parent_entity_id;//父实体ID
- //api/services/<domain>/<service>
- if(resData[i].entity_id){
- obj.domain = resData[i].entity_id.split(".")[0];
- }
- obj.state = (resData[i].state=='unknown'?"未知":resData[i].state);
- if(resData[i].attributes && resData[i].attributes.friendly_name){
- obj.friendly_name = resData[i].attributes.friendly_name; //设备名称
-
- if(obj.friendly_name.includes("灯")){
- obj.imgSrc = '/static/images/led.png';
- }else if(obj.friendly_name.includes("加湿器")){
- obj.imgSrc = '/static/images/hum.png';
- }else if(obj.friendly_name.includes("香薰机")){
- obj.imgSrc = '/static/images/light.png';
- }else if(obj.friendly_name.includes("排气扇")){
- obj.imgSrc = '/static/images/temp.png';
- }else if(obj.friendly_name.includes("空调")){
- obj.imgSrc = '/static/images/alarm.png';
- }else if(obj.friendly_name.includes("电视")){
- obj.imgSrc = '/static/images/light.png';
- }else{
- obj.imgSrc = '/static/images/temp.png';
- }
- }
- if(resData[i].attributes && resData[i].attributes.home_room){
- obj.home_room = resData[i].attributes.home_room.split(' ')[1]; //房间号
- }
- if((resData[i].state && (resData[i].state=='on' || resData[i].state=='off')) && that.checkFuzzyMatch(resData[i])
- ){
- if(resData[i].state=='on'){
- obj.service = 'turn_on';
- }else if(resData[i].state=='off'){
- obj.service = 'turn_off';
- }
- //截取字符串,防止开关设备名称过长
- obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
- //是否 是香薰机灯光
- obj.isAromlight = obj.friendly_name.includes('香薰机灯光')
- if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
- listSwitchTemp.push(obj)
- }
- }
-
- if((resData[i].state && obj.domain && obj.domain=='cover') && that.checkFuzzyMatch(resData[i])
- ){
- obj.current_position = resData[i].attributes.current_position;
- obj.target_position = resData[i].attributes.target_position;
- obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
- if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
- listCoverTemp.push(obj)
- }
- }
-
- // if((resData[i].state && obj.domain && obj.domain=='number')||
- // (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)
- // )
- // ){
- // obj.min = resData[i].attributes.min;
- // obj.max = resData[i].attributes.max;
- // obj.step = resData[i].attributes.step;
- // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
- // if(resData[i].state!='unknown'){
- // obj.unit_of_measurement = resData[i].attributes.unit_of_measurement;
- // }
- // if((resData[i].attributes.min || resData[i].attributes.max) && resData[i].attributes.unit_of_measurement!='rgb' && resData[i].attributes.unit_of_measurement!='minutes'){
- // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
- // listScrollTemp.push(obj);
- // }
- // }else if((resData[i].attributes.min || resData[i].attributes.max) && (resData[i].attributes.unit_of_measurement=='rgb' || resData[i].attributes.unit_of_measurement=='minutes')){
- // if(resData[i].state!='unknown'){
- // obj.unit_of_measurement = resData[i].attributes.unit_of_measurement;
- // }
- // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
- // listUnitTemp.push(obj);
- // }
- // }
- // }
- // if((resData[i].state && obj.domain && obj.domain=='button')||
- // (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)
- // )
- // ){
- // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
- // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
- // listButtonTemp.push(obj);
- // }
- // }
- // if((resData[i].state && obj.domain && obj.domain=='select')||
- // (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)
- // )
- // ){
- // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
- // obj.options = resData[i].attributes.options;
- // obj.selectedIndex = 0;
- // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
- // listSelectTemp.push(obj);
- // }
- // }
- if((resData[i].state && obj.domain && obj.domain=='climate' && resData[i].attributes.entity_class=='MiirClimateEntity')
- ){
- climateModeTemp = obj.state;
- obj.temperature = resData[i].attributes.temperature;
- obj.min_temp = resData[i].attributes.min_temp;
- obj.max_temp = resData[i].attributes.max_temp;
- obj.hvac_modes = resData[i].attributes.hvac_modes;
- obj.fan_modes = resData[i].attributes.fan_modes;
- obj.fan_mode = resData[i].attributes.fan_mode;
- obj.target_temp_step = resData[i].attributes.target_temp_step;
- if(obj.state=='auto'){
- temperatureHumidifyNameTemp = '自动';
- }
-
- if(obj.state=='heat'){
- temperatureHumidifyNameTemp = '制热';
- }
- if(obj.state=='cool'){
- temperatureHumidifyNameTemp = '制冷';
- }
- if(obj.state=='dry'){
- temperatureHumidifyNameTemp = '除湿';
- }
- if(obj.state=='fan_only'){
- temperatureHumidifyNameTemp = '送风';
- }
- if(obj.state=='off'){
- temperatureHumidifyNameTemp = '关闭';
- }
-
- if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
- listClimateTemp.push(obj);
- }
- }
- if((resData[i].state && obj.domain && obj.domain=='media_player' && resData[i].attributes.entity_class=='MiotMediaPlayerEntity') && that.checkFuzzyMatch(resData[i])
- ){
- // obj["speaker.volume"] = resData[i].attribute["speaker.volume"];
- obj.repeat = resData[i].attributes.repeat;
- 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;";
- obj.media_title = resData[i].attributes.media_title;
- obj.media_artist = resData[i].attributes.media_artist;
- obj.volume_level = resData[i].attributes.volume_level?(resData[i].attributes.volume_level * 100):0;
- obj.media_duration = resData[i].attributes.media_duration;
- obj.media_position = resData[i].attributes.media_position;
- obj.media_late = resData[i].attributes.media_position + '/' + resData[i].attributes.media_duration;
- // obj.microphone.mute = resData[i].attributes.microphone.mute;
- // obj.speaker.mute = resData[i].attributes.speaker.mute;
- // console.log('media-player-miot-obj=='+obj);
- if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
- listMiotMediaPlayerTemp.push(obj);
- }
- }
-
- // if((resData[i].state && obj.domain && obj.domain=='media_player' && resData[i].attributes.entity_class=='MitvMediaPlayerEntity')||
- // (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)
- // )
- // ){
- // obj.volume_level = resData[i].attributes.volume_level;
- // obj.is_volume_muted = resData[i].attributes.is_volume_muted;
- // obj.source = resData[i].attributes.source;
- // 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;";
- // obj.media_title = resData[i].attributes.media_title;
- // obj.media_artist = resData[i].attributes.media_artist;
- // obj.volume_level = resData[i].attributes.volume_level?(resData[i].attributes.volume_level * 100):0;
- // obj.media_duration = resData[i].attributes.media_duration;
- // obj.media_position = resData[i].attributes.media_position;
- // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
- // listMitvMediaPlayerTemp.push(obj);
- // }
- // }
-
- if((resData[i].state && obj.domain && obj.domain=='media_player') && that.checkFuzzyMatch(resData[i])
- ){
-
- obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
- 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('电视'))){
- obj.volume_level = resData[i].attributes.volume_level;
- obj.is_volume_muted = resData[i].attributes.is_volume_muted;
- obj.source = resData[i].attributes.source;
- 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;";
- obj.media_title = resData[i].attributes.media_title;
- obj.media_artist = resData[i].attributes.media_artist;
- obj.volume_level = resData[i].attributes.volume_level?(resData[i].attributes.volume_level * 100):0;
- obj.media_duration = resData[i].attributes.media_duration;
- obj.media_position = resData[i].attributes.media_position;
- obj.media_late = resData[i].attributes.media_position + '/' + resData[i].attributes.media_duration;
- // obj["speaker.volume"] = resData[i].attributes["speaker.volume"];
- // console.log('media-player-mitv-obj=='+obj);
- obj.device_class = resData[i].attributes.device_class;
- obj.app_id = resData[i].attributes.app_id;
- obj.app_name = resData[i].attributes.app_name;
- if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
- listMitvMediaPlayerTemp.push(obj);
- }
- obj.friendly_name1 = resData[i].attributes.friendly_name;
- tvEntityIdsTemp.push(obj);
- // let obj1 = {};
- // obj1.entity_id = obj.entity_id;
- // obj1.friendly_name1 = resData[i].attributes.friendly_name;
- // tvEntityIdsTemp.push(obj1);
- tvEntityIdTemp = obj.entity_id;
- // console.log('obj===='+obj);
- // console.log('tvEntityIdTemp='+tvEntityIdTemp);
- wx.setStorageSync('tvEntityId',tvEntityIdTemp);
- }
- }
-
- if((resData[i].state && obj.domain && obj.domain=='humidifier')
- ){
- obj.min_humidity = resData[i].attributes.min_humidity;
- obj.max_humidity = resData[i].attributes.max_humidity;
- obj.humidity = resData[i].attributes.humidity;
- obj.min = resData[i].attributes.min_humidity;
- obj.max = resData[i].attributes.max_humidity;
- // console.log('humidifier-obj=='+JSON.stringify(obj));
- if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
- listHumidifierTemp.push(obj);
- }
- }
-
- // if((resData[i].state && obj.domain && obj.domain=='sensor')||
- // (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)
- // )
- // ){
- // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
- // obj.unit_of_measurement = resData[i].attributes.unit_of_measurement;
- // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
- // listSensorTemp.push(obj);
- // }
- // }
-
- // if((resData[i].state && obj.domain && obj.domain=='text')||
- // (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)
- // )
- // ){
- // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
- // obj.min = resData[i].attributes.min;
- // obj.max = resData[i].attributes.max;
- // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
- // listTextTemp.push(obj);
- // }
- // }
-
- // if((resData[i].state && obj.friendly_name && obj.friendly_name.includes("智能音箱"))
- // || (resData[i].state && resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id)
- // && obj.friendly_name && obj.friendly_name.includes("智能音箱"))
- // ){
- // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
- // listConversationTemp.push(obj)
- // }
- // }
- // if((resData[i].state && resData[i].attributes && resData[i].attributes.speaker && resData[i].attributes.speaker.volume && obj.friendly_name && obj.friendly_name.includes("智能音箱"))||
- // (resData[i].state && resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id)
- // && resData[i].attributes.speaker && resData[i].attributes.speaker.volume && obj.friendly_name && obj.friendly_name.includes("智能音箱"))
- // ){
- // obj.volume = resData[i].attributes.speaker.volume;//音量
- // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
- // listConversation1Temp.push(obj)
- // }
- // }
- //加湿器单独拿出来
- // if((obj.friendly_name && obj.friendly_name.includes("加湿器"))||
- // (resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id)
- // && obj.friendly_name && obj.friendly_name.includes("加湿器"))
- // ){
- // listHumidityTemp.push(obj)
- // }
- // }
- }
-
- that.setData({
- // status_beep: that.getEntityState(res.data,'switch.xiaomi_pro3_02bd_left_switch_service'), //实验室主灯
- // status_led: that.getEntityState(res.data,'light.deerma_jsq2g_392f_indicator_light'), //加湿器 Indicator Light
- // status_san: that.getEntityState(res.data,'switch.xwhzp_xwxfj_a441_diffuser'), //香薰机 Diffuser
- // status_curtain: that.getEntityState(res.data,'switch.xiaomi_pro3_02bd_middle_switch_service'), //实验室侧灯
- // status_door: that.getEntityState(res.data,'remote.xiaomi_lx06_f593_wifispeaker_4'), //智能音箱
- // Temp: that.getEntityStateValue(res.data,'sensor.deerma_jsq2g_392f_temperature'), //加湿器温度
- // Humi: that.getEntityStateValue(res.data,'sensor.deerma_jsq2g_392f_relative_humidity'), //加湿器湿度
- // Light: that.getEntityStateValue(res.data,'number.xwhzp_xwxfj_a441_brightness'), //香薰机亮度
- // LiquidLevel: that.getEntityStateValue(res.data,'sensor.xwhzp_xwxfj_a441_fragrance_liquid_left_level'), //香薰液浓度
- listSwitch:listSwitchTemp,
- listUnit:listUnitTemp,
- listScroll:listScrollTemp,
- listConversation:listConversationTemp,
- listConversation1:listConversation1Temp,
- listHumidity:listHumidityTemp,
- listButton:listButtonTemp,
- listSelect:listSelectTemp,
- listClimate:listClimateTemp,
- listMiotMediaPlayer:listMiotMediaPlayerTemp,
- listMitvMediaPlayer:listMitvMediaPlayerTemp,
- listHumidifier:listHumidifierTemp,
- listSensor:listSensorTemp,
- listText:listTextTemp,
- tvEntityId:tvEntityIdTemp,
- tvEntityIds:tvEntityIdsTemp,
- climateMode:climateModeTemp,
- temperatureHumidifyName:temperatureHumidifyNameTemp,
- listCover:listCoverTemp,
- })
- wx.setStorageSync('tvEntityIds',tvEntityIdsTemp);
- // console.log('listMiotMediaPlayerTemp='+JSON.stringify(listMiotMediaPlayerTemp));
- // console.log('listHumidityTemp='+JSON.stringify(listHumidityTemp));
- // console.log('listClimateTemp='+JSON.stringify(listClimateTemp));
- // console.log('listSwitchTemp='+JSON.stringify(listSwitchTemp));
- console.log('tvEntityIdsTemp='+JSON.stringify(tvEntityIdsTemp));
- // console.log('listMitvMediaPlayerTemp='+JSON.stringify(listMitvMediaPlayerTemp));
- console.log('listHumidifierTemp='+JSON.stringify(listHumidifierTemp));
- },
- });
-
-
-
-
-
- // } catch (error) {
- // console.error(error);
- // }
-
- // },
- // });
-
- } catch (error) {
- console.error(error);
- }
-
- },
- fail: function (error) {
- console.error('error', error);
- that.setData({
- isLoading: false,
- });
- }
- });
-
-
-
- let end = Date.now(); // 再次获取当前时间(毫秒)
- // console.log('end=='+end);
- let executionTime = end - start;
- // console.log(`myFunctionToTest 执行时间为: ${executionTime} 毫秒`);
- return true;
- },
- getHADataStart(that,hotelcode,roomcode){
- let start = Date.now(); // 获取当前时间(毫秒)
- console.log('start=='+start);
- var that = this;
-
- wx.request({
- url: `${aipushApi}/getha`, //
- method: 'POST',
- // header: {
- // 'content-type': 'application/json', // 默认值
- // 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
- // },
- data:{
- "locations":hotelcode,"room":(hotelcode && hotelcode.includes('hotel'))?roomcode:"","token":token_push
- },
- success(ress) {
- if(!ress || !ress.data){
- console.error("getha(),没有获取到数据");
- return;
- }
- var resData = ress.data
- console.log("resData-=="+JSON.stringify(resData));
- console.log("resData.loc-=="+JSON.stringify(resData.loc));
- homeApi_https = resData.loc+"/api";
- homeApiLater_https = resData.loc;
- token = resData.token;
- // console.log('res.data='+JSON.stringify(resData));
- if (ress.data.code == "400") {
- console.error("400错误!");
- return;
- }
- if (ress.data.code == "401") {
- console.error("401错误!");
- return;
- }
- try {
- //获取HA 设备状态数据
- // wx.request({
- // url: `${homeApi_https}/states`,
- // method: 'GET',
- // header: {
- // 'content-type': 'application/json', // 默认值
- // 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
- // },
- // success(res) {
- // if(!res || !res.data){
- // that.setData({
- // isLoading: false,
- // });
- // return;
- // }
-
- // var resData = res.data
- // // console.log('res.data='+JSON.stringify(resData));
- // if (res.data.code == "400") {
- // console.error("400错误!");
- // return;
- // }
- // if (res.data.code == "401") {
- // console.error("401错误 --- 请检查你的API或Key是否正确!");
- // return;
- // }
- // try {
-
-
-
-
-
- // const {
- // now
- // } = res.data;
- // console.log('res.data1='+JSON.stringify(resData));
- // res.data.find(function (obj) {
- // console.log('obj='+obj);
- // })
- // res.data.forEach((item, index) => {
- // console.log(index, item);
- // });
- var listCoverTemp = [];
- var listSwitchTemp = [];
- var listScrollTemp = [];
- var listUnitTemp = [];
- var listConversationTemp = [];
- var listConversation1Temp = [];
- var listHumidityTemp = [];
- var listButtonTemp = [];
- var listSelectTemp = [];
- var listClimateTemp = [];
- var listMiotMediaPlayerTemp = [];
- var listMitvMediaPlayerTemp = [];
- var listHumidifierTemp = [];
- var listSensorTemp = [];
- var listTextTemp = [];
-
- var tvEntityIdTemp = '';
- var tvEntityIdsTemp = [];
-
- var climateModeTemp = '';
- var temperatureHumidifyNameTemp = '温度';
-
- var entityIdList = [];
- const res = wx.getStorageSync('res');
- const home_room = wx.getStorageSync('res').home_room;
- // console.log('entity=====@==='+entity);
- wx.request({
- url: `${homeApi_https}/aidsleep/entity`, //获取空气数据
- method: 'POST',
- header: {
- 'content-type': 'application/json', // 默认值
- 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
- },
- //
- data:{
- "template": "{{ label_entities('"+(entity)+"') }}"
- },
- success(resTemplate) {
- let mid = Date.now(); // 再次获取当前时间(毫秒)
- // console.log('mid=='+mid);
- if(!resTemplate || !resTemplate.data){
- console.log('no data:'+mid);
- return;
- }
- let resData = resTemplate.data;
- // resData = resData.filter(item1 => {
- // return JSON.parse(that.replaceAll(resTemplate.data,'\'','\"')).find(item2 => item2 === item1.entity_id) !== undefined;
- // });
- console.log("resData-union="+JSON.stringify(resData));
- // console.log('entityIdList-resTemplate====='+JSON.stringify(resTemplate.data));
- for(let i=0;i<resData.length;i++){
- // if(resTemplate.data.includes(resData[i].entity_id) && that.checkFuzzyMatch(resData[i])){
- var obj={};
- obj.entity_id = resData[i].entity_id;//实体ID
- obj.parent_entity_id = resData[i].parent_entity_id;//父实体ID
- //api/services/<domain>/<service>
- if(resData[i].entity_id){
- obj.domain = resData[i].entity_id.split(".")[0];
- }
- obj.state = (resData[i].state=='unknown'?"未知":resData[i].state);
- if(resData[i].attributes && resData[i].attributes.friendly_name){
- obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode); //设备名称
-
- if(obj.friendly_name.includes("灯")){
- obj.imgSrc = '/static/images/led.png';
- }else if(obj.friendly_name.includes("加湿器")){
- obj.imgSrc = '/static/images/hum.png';
- }else if(obj.friendly_name.includes("香薰机")){
- obj.imgSrc = '/static/images/light.png';
- }else if(obj.friendly_name.includes("排气扇")){
- obj.imgSrc = '/static/images/temp.png';
- }else if(obj.friendly_name.includes("空调")){
- obj.imgSrc = '/static/images/alarm.png';
- }else if(obj.friendly_name.includes("电视")){
- obj.imgSrc = '/static/images/light.png';
- }else{
- obj.imgSrc = '/static/images/temp.png';
- }
- }
- if(resData[i].attributes && resData[i].attributes.home_room){
- obj.home_room = resData[i].attributes.home_room.split(' ')[1]; //房间号
- }
- if((resData[i].state && (resData[i].state=='on' || resData[i].state=='off')) && that.checkFuzzyMatch(resData[i])
- ){
- if(resData[i].state=='on'){
- obj.service = 'turn_on';
- }else if(resData[i].state=='off'){
- obj.service = 'turn_off';
- }
- //截取字符串,防止开关设备名称过长
- obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
- //是否 是香薰机灯光
- obj.isAromlight = obj.friendly_name.includes('香薰机灯光')
- if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
- listSwitchTemp.push(obj)
- }
- }
-
- if((resData[i].state && obj.domain && obj.domain=='cover') && that.checkFuzzyMatch(resData[i])
- ){
- obj.current_position = resData[i].attributes.current_position;
- obj.target_position = resData[i].attributes.target_position;
- obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
- if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
- listCoverTemp.push(obj)
- }
- }
-
- // if((resData[i].state && obj.domain && obj.domain=='number')||
- // (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)
- // )
- // ){
- // obj.min = resData[i].attributes.min;
- // obj.max = resData[i].attributes.max;
- // obj.step = resData[i].attributes.step;
- // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
- // if(resData[i].state!='unknown'){
- // obj.unit_of_measurement = resData[i].attributes.unit_of_measurement;
- // }
- // if((resData[i].attributes.min || resData[i].attributes.max) && resData[i].attributes.unit_of_measurement!='rgb' && resData[i].attributes.unit_of_measurement!='minutes'){
- // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
- // listScrollTemp.push(obj);
- // }
- // }else if((resData[i].attributes.min || resData[i].attributes.max) && (resData[i].attributes.unit_of_measurement=='rgb' || resData[i].attributes.unit_of_measurement=='minutes')){
- // if(resData[i].state!='unknown'){
- // obj.unit_of_measurement = resData[i].attributes.unit_of_measurement;
- // }
- // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
- // listUnitTemp.push(obj);
- // }
- // }
- // }
- // if((resData[i].state && obj.domain && obj.domain=='button')||
- // (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)
- // )
- // ){
- // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
- // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
- // listButtonTemp.push(obj);
- // }
- // }
- // if((resData[i].state && obj.domain && obj.domain=='select')||
- // (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)
- // )
- // ){
- // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
- // obj.options = resData[i].attributes.options;
- // obj.selectedIndex = 0;
- // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
- // listSelectTemp.push(obj);
- // }
- // }
- if((resData[i].state && obj.domain && obj.domain=='climate' && resData[i].attributes.entity_class=='MiirClimateEntity')
- ){
- climateModeTemp = obj.state;
- obj.temperature = resData[i].attributes.temperature;
- obj.min_temp = resData[i].attributes.min_temp;
- obj.max_temp = resData[i].attributes.max_temp;
- obj.hvac_modes = resData[i].attributes.hvac_modes;
- obj.fan_modes = resData[i].attributes.fan_modes;
- obj.fan_mode = resData[i].attributes.fan_mode;
- obj.target_temp_step = resData[i].attributes.target_temp_step;
- if(obj.state=='auto'){
- temperatureHumidifyNameTemp = '自动';
- }
-
- if(obj.state=='heat'){
- temperatureHumidifyNameTemp = '制热';
- }
- if(obj.state=='cool'){
- temperatureHumidifyNameTemp = '制冷';
- }
- if(obj.state=='dry'){
- temperatureHumidifyNameTemp = '除湿';
- }
- if(obj.state=='fan_only'){
- temperatureHumidifyNameTemp = '送风';
- }
- if(obj.state=='off'){
- temperatureHumidifyNameTemp = '关闭';
- }
-
- if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
- listClimateTemp.push(obj);
- }
- }
- if((resData[i].state && obj.domain && obj.domain=='media_player' && resData[i].attributes.entity_class=='MiotMediaPlayerEntity') && that.checkFuzzyMatch(resData[i])
- ){
- // obj["speaker.volume"] = resData[i].attribute["speaker.volume"];
- obj.repeat = resData[i].attributes.repeat;
- 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;";
- obj.media_title = resData[i].attributes.media_title;
- obj.media_artist = resData[i].attributes.media_artist;
- obj.volume_level = resData[i].attributes.volume_level?(resData[i].attributes.volume_level * 100):0;
- obj.media_duration = resData[i].attributes.media_duration;
- obj.media_position = resData[i].attributes.media_position;
- obj.media_late = resData[i].attributes.media_position + '/' + resData[i].attributes.media_duration;
- // obj.microphone.mute = resData[i].attributes.microphone.mute;
- // obj.speaker.mute = resData[i].attributes.speaker.mute;
- // console.log('media-player-miot-obj=='+obj);
- if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
- listMiotMediaPlayerTemp.push(obj);
- }
- }
-
- // if((resData[i].state && obj.domain && obj.domain=='media_player' && resData[i].attributes.entity_class=='MitvMediaPlayerEntity')||
- // (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)
- // )
- // ){
- // obj.volume_level = resData[i].attributes.volume_level;
- // obj.is_volume_muted = resData[i].attributes.is_volume_muted;
- // obj.source = resData[i].attributes.source;
- // 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;";
- // obj.media_title = resData[i].attributes.media_title;
- // obj.media_artist = resData[i].attributes.media_artist;
- // obj.volume_level = resData[i].attributes.volume_level?(resData[i].attributes.volume_level * 100):0;
- // obj.media_duration = resData[i].attributes.media_duration;
- // obj.media_position = resData[i].attributes.media_position;
- // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
- // listMitvMediaPlayerTemp.push(obj);
- // }
- // }
-
- if((resData[i].state && obj.domain && obj.domain=='media_player') && that.checkFuzzyMatch(resData[i])
- ){
- obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
- if(obj.entity_id.includes('teevee') || (obj.friendly_name && obj.friendly_name.includes('电视'))){
- obj.volume_level = resData[i].attributes.volume_level;
- obj.is_volume_muted = resData[i].attributes.is_volume_muted;
- obj.source = resData[i].attributes.source;
- 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;";
- obj.media_title = resData[i].attributes.media_title;
- obj.media_artist = resData[i].attributes.media_artist;
- obj.volume_level = resData[i].attributes.volume_level?(resData[i].attributes.volume_level * 100):0;
- obj.media_duration = resData[i].attributes.media_duration;
- obj.media_position = resData[i].attributes.media_position;
- obj.media_late = resData[i].attributes.media_position + '/' + resData[i].attributes.media_duration;
- // obj["speaker.volume"] = resData[i].attributes["speaker.volume"];
- // console.log('media-player-mitv-obj=='+obj);
- obj.device_class = resData[i].attributes.device_class;
- obj.app_id = resData[i].attributes.app_id;
- obj.app_name = resData[i].attributes.app_name;
- if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
- listMitvMediaPlayerTemp.push(obj);
- }
- obj.friendly_name1 = resData[i].attributes.friendly_name;
- tvEntityIdsTemp.push(obj);
- // let obj1 = {};
- // obj1.entity_id = obj.entity_id;
- // obj1.friendly_name1 = resData[i].attributes.friendly_name;
- // tvEntityIdsTemp.push(obj1);
- tvEntityIdTemp = obj.entity_id;
- // console.log('obj===='+obj);
- // console.log('tvEntityIdTemp='+tvEntityIdTemp);
- wx.setStorageSync('tvEntityId',tvEntityIdTemp);
- }
- }
-
- if((resData[i].state && obj.domain && obj.domain=='humidifier')
- ){
- obj.min_humidity = resData[i].attributes.min_humidity;
- obj.max_humidity = resData[i].attributes.max_humidity;
- obj.humidity = resData[i].attributes.humidity;
- obj.min = resData[i].attributes.min_humidity;
- obj.max = resData[i].attributes.max_humidity;
- // console.log('humidifier-obj=='+JSON.stringify(obj));
- if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
- listHumidifierTemp.push(obj);
- }
- }
-
- // if((resData[i].state && obj.domain && obj.domain=='sensor')||
- // (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)
- // )
- // ){
- // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
- // obj.unit_of_measurement = resData[i].attributes.unit_of_measurement;
- // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
- // listSensorTemp.push(obj);
- // }
- // }
-
- // if((resData[i].state && obj.domain && obj.domain=='text')||
- // (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)
- // )
- // ){
- // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
- // obj.min = resData[i].attributes.min;
- // obj.max = resData[i].attributes.max;
- // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
- // listTextTemp.push(obj);
- // }
- // }
-
- // if((resData[i].state && obj.friendly_name && obj.friendly_name.includes("智能音箱"))
- // || (resData[i].state && resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id)
- // && obj.friendly_name && obj.friendly_name.includes("智能音箱"))
- // ){
- // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
- // listConversationTemp.push(obj)
- // }
- // }
- // if((resData[i].state && resData[i].attributes && resData[i].attributes.speaker && resData[i].attributes.speaker.volume && obj.friendly_name && obj.friendly_name.includes("智能音箱"))||
- // (resData[i].state && resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id)
- // && resData[i].attributes.speaker && resData[i].attributes.speaker.volume && obj.friendly_name && obj.friendly_name.includes("智能音箱"))
- // ){
- // obj.volume = resData[i].attributes.speaker.volume;//音量
- // if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
- // listConversation1Temp.push(obj)
- // }
- // }
- //加湿器单独拿出来
- // if((obj.friendly_name && obj.friendly_name.includes("加湿器"))||
- // (resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id)
- // && obj.friendly_name && obj.friendly_name.includes("加湿器"))
- // ){
- // listHumidityTemp.push(obj)
- // }
- // }
- }
-
- that.setData({
- // status_beep: that.getEntityState(res.data,'switch.xiaomi_pro3_02bd_left_switch_service'), //实验室主灯
- // status_led: that.getEntityState(res.data,'light.deerma_jsq2g_392f_indicator_light'), //加湿器 Indicator Light
- // status_san: that.getEntityState(res.data,'switch.xwhzp_xwxfj_a441_diffuser'), //香薰机 Diffuser
- // status_curtain: that.getEntityState(res.data,'switch.xiaomi_pro3_02bd_middle_switch_service'), //实验室侧灯
- // status_door: that.getEntityState(res.data,'remote.xiaomi_lx06_f593_wifispeaker_4'), //智能音箱
- // Temp: that.getEntityStateValue(res.data,'sensor.deerma_jsq2g_392f_temperature'), //加湿器温度
- // Humi: that.getEntityStateValue(res.data,'sensor.deerma_jsq2g_392f_relative_humidity'), //加湿器湿度
- // Light: that.getEntityStateValue(res.data,'number.xwhzp_xwxfj_a441_brightness'), //香薰机亮度
- // LiquidLevel: that.getEntityStateValue(res.data,'sensor.xwhzp_xwxfj_a441_fragrance_liquid_left_level'), //香薰液浓度
- listSwitch:listSwitchTemp,
- listUnit:listUnitTemp,
- listScroll:listScrollTemp,
- listConversation:listConversationTemp,
- listConversation1:listConversation1Temp,
- listHumidity:listHumidityTemp,
- listButton:listButtonTemp,
- listSelect:listSelectTemp,
- listClimate:listClimateTemp,
- listMiotMediaPlayer:listMiotMediaPlayerTemp,
- listMitvMediaPlayer:listMitvMediaPlayerTemp,
- listHumidifier:listHumidifierTemp,
- listSensor:listSensorTemp,
- listText:listTextTemp,
- tvEntityId:tvEntityIdTemp,
- tvEntityIds:tvEntityIdsTemp,
- climateMode:climateModeTemp,
- temperatureHumidifyName:temperatureHumidifyNameTemp,
- listCover:listCoverTemp,
- isLoading: false,
- })
- wx.setStorageSync('tvEntityIds',tvEntityIdsTemp);
- },
- });
- let mid = Date.now(); // 获取当前时间(毫秒)
- console.log('mid=='+mid);
- console.log('start=='+start);
- console.log('mid-start=='+(mid-start));
- // that.setData({
- // isLoading: true,
- // });
-
-
-
-
- // } catch (error) {
- // console.error(error);
- // }
-
- // },
- // fail: function (error) {
- // console.error('error', error);
- // that.setData({
- // isLoading: false,
- // });
- // }
- // });
-
-
- } catch (error) {
- console.error(error);
- that.setData({
- isLoading: false,
- });
- }
-
- },
- fail: function (error) {
- console.error('error', error);
- that.setData({
- isLoading: false,
- });
- }
- });
-
-
-
- let end = Date.now(); // 再次获取当前时间(毫秒)
- console.log('end=='+end);
- let executionTime = end - start;
- console.log(`myFunctionToTest 执行时间为: ${executionTime} 毫秒`);
- return true;
- },
- imageLoad: function () {
- this.setData({
- isLoading: false,
- });
- console.log('图片渲染完成');
- },
- startInterval: function () {
- // 使用 setInterval 创建定时任务,每8秒执行一次 this.myMethod 方法
- var that = this;
- // this.intervalId = setInterval(() => {
- // that.getHAData(that,that.data.hotelcode,that.data.roomcode);
- // }, 6000);
- this.data.intervalId1 = setInterval(() => {
- that.getHAData(that,that.data.hotelcode,that.data.roomcode);
- }, 6000);
-
- // 第二个定时器,每2秒执行一次
- this.data.intervalId2 = setInterval(() => {
- // 这里执行你的代码
- that.setData({
- isClickedPrevSong: false,
- isClickedTogglePlayPause: false,
- isClickedNextSong: false,
- isClickedOnHumidifierUp: false,
- isClickedOnHumidifierDown: false,
- isClickedOnClimateAuto: false,
- isClickedOnClimateUp: false,
- isClickedToggleAromlight: false,//香薰机灯光
- });
- }, 300);
- },
- clearInterval: function () {
- // 清除定时任务
- // if (this.intervalId) {
- // clearInterval(this.intervalId);
- // this.intervalId = null;
- // }
- if (this.data.intervalId1) {
- clearInterval(this.data.intervalId1);
- this.data.intervalId1 = null; // 可选,但建议清除以避免潜在的错误
- }
-
- // 停止第二个定时器
- if (this.data.intervalId2) {
- clearInterval(this.data.intervalId2);
- this.data.intervalId2 = null; // 可选,但建议清除以避免潜在的错误
- }
- },
- stopTouchMove: function(e) {
- return false;
- },
- truncateString: function(str,roomcode) {
- if(!str) return ''
- let strR = str.replace(roomcode, '')
- if (strR.length <= 6) {
- // 如果字符串长度小于等于5,直接返回原字符串
- return strR;
- } else{
- // 如果字符串长度在6到9之间,返回后6个字符(此时没有前部分可拼接)
- return strR.slice(-6);
- }
- },
- onLoad(option){
- console.log("index页面");
- // wx.clearStorage();
- // this.setTextBreathing(wx.createSelectorQuery(".header-title-fire"),this);
- //console.log('option.res='+JSON.stringify(wx.getStorageSync('res')));
- if(!wx.getStorageSync('res') || !wx.getStorageSync('res').result){
- wx.showModal({
- title: '提示',
- content: '请先扫描房间二维码',
- showCancel: false
- });
- setTimeout(function() {
- wx.reLaunch({
- url: '/pages/scan/scan',
- })
- }, 2000) // 设置延时时间,单位为毫秒
- }else{
-
-
- var that = this;
- // wx.request({
- // url: `${aipushApi}`+'/getbigreport',
- // method: 'POST',
- // header: {
- // 'content-type': 'application/json', // 默认值
- // 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
- // },
- // data:{
- // "sn":'',"tokens":token_push
- // },
- // success(ress) {
- // if(ress && ress.data){
- // wx.request({
- // url: `${homeApi_https}/states`, //获取空气数据
- // method: 'GET',
- // header: {
- // 'content-type': 'application/json', // 默认值
- // 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
- // },
- // success(res) {
- // if(!res || !res.data){
- // wx.showModal({
- // title: '提示',
- // content: '请先连接房间wi-fi,再次扫描',
- // showCancel: false
- // });
-
- // setTimeout(function() {
- // wx.reLaunch({
- // url: '/pages/scan/scan',
- // })
- // }, 2000) // 设置延时时间,单位为毫秒
- // }else{
- // // console.log("res.data====="+JSON.stringify(res.data));
- // }
- // },
- // });
- // }else{
- // wx.showModal({
- // title: '提示',
- // content: '请先连接房间wi-fi,再次扫描',
- // showCancel: false
- // });
-
- // setTimeout(function() {
- // wx.reLaunch({
- // url: '/pages/scan/scan',
- // })
- // }, 2000) // 设置延时时间,单位为毫秒
- // }
- // },
- // });
-
- // const socketUrl = 'http://192.168.3.65:8123';
- // wx.connectSocket({
- // url: socketUrl,
- // success: function (res) {
- // console.log('WebSocket连接成功', res);
- // },
- // fail: function (error) {
- // console.error('WebSocket连接打开失败', error);
- // }
- // });
- //wi-fi判断
- // wx.startWifi({
- // fail(error) {
- // console.log('初始化wifi-失败', error)
- // },
- // success(res) {
- // console.log('初始化wifi-成功', res)
- // },
- // });
-
-
- // const expiresAt = wx.getStorageSync('scanResultExpiresAt');
- // const now = Date.now()
- // console.log('expiresAt='+expiresAt);
- // console.log('now='+now);
- // if (expiresAt || expiresAt < now) {
- // // 扫码结果已过期
- // wx.showToast({
- // title: '扫码结果失效或已过期,请重新扫码',
- // icon: 'none'
- // });
- // // 清除过期的扫码结果
- // wx.removeStorageSync('scanResultExpiresAt');
- // setTimeout(function() {
- // wx.reLaunch({
- // url: '/pages/scan/scan',
- // })
- // }, 2000) // 设置延时时间,单位为毫秒
-
- // }else{
- // //续期
- // wx.setStorageSync('scanResultExpiresAt', Date.now() + 2 * 60 * 60 * 1000)
- // }
-
-
- let hotelcodeTemp = '';
- let roomcodeTemp = '';
- if(wx.getStorageSync('res').result.split('|').length != 2){
- wx.showModal({
- title: '提示',
- content: '房间二维码不正确,请重新扫码',
- showCancel: false
- });
-
- setTimeout(function() {
- wx.reLaunch({
- url: '/pages/scan/scan',
- })
- }, 2000) // 设置延时时间,单位为毫秒
- }
- hotelcodeTemp = wx.getStorageSync('res').result.split('|')[0];
- roomcodeTemp = wx.getStorageSync('res').result.split('|')[1];
- entity = roomcodeTemp;
- if(entity == 'labs'){
- entity = '公司实验室';
- wx.setStorageSync('roomname','604');
- }else{
- wx.setStorageSync('roomname',entity);
- }
- this.setData({
- isLoading: true,
- hotelcode: hotelcodeTemp,
- roomcode: roomcodeTemp,
- });
- if(this.getHADataStart(this,hotelcodeTemp,roomcodeTemp)){
- // 页面加载时开始定时任务
- // this.startInterval();
- }
-
- }
-
-
-
- // else if(!this.data.home_room.includes(wx.getStorageSync('res').result)){
- // wx.showModal({
- // title: '提示',
- // content: '房间二维码不正确,请重新扫描',
- // showCancel: false
- // });
-
- // setTimeout(function() {
- // wx.reLaunch({
- // url: '/pages/scan/scan',
- // })
- // }, 2000) // 设置延时时间,单位为毫秒
- // }
-
- // this.showCanvasRing();
-
- // 创建音频上下文
- // this.innerAudioContext = wx.createInnerAudioContext();
-
- // // 设置音频源
- // this.innerAudioContext.src = '你的音频文件链接'; // 替换为你的音频文件链接
-
- // // 监听播放状态
- // this.innerAudioContext.onPlay(() => {
- // this.setData({ isPlaying: true });
- // });
- // this.innerAudioContext.onPause(() => {
- // this.setData({ isPlaying: false });
- // });
- // this.innerAudioContext.onStop(() => {
- // this.setData({ isPlaying: false });
- // });
- // this.innerAudioContext.onError((res) => {
- // console.log('res.errorCode='+res.errorCode);
- // console.log('res.errorMsg='+res.errorMsg);
- // });
-
- // // 监听播放进度
- // this.innerAudioContext.onTimeUpdate(() => {
- // this.setData({
- // currentTime: this.innerAudioContext.currentTime,
- // duration: this.innerAudioContext.duration
- // });
- // });
- // // 初始化歌曲列表
- // this.setData({
- // songs: [
- // { id: 1, title: '歌曲1', artist: '歌手1', url: 'song1.mp3' },
- // { id: 2, title: '歌曲2', artist: '歌手2', url: 'song2.mp3' },
- // { id: 3, title: '歌曲3', artist: '歌手3', url: 'song3.mp3' }
- // ]
- // });
-
- },
- mounted() {
-
- },
- onHide(){
- // wx.clearStorage();
- // 页面卸载时清除定时任务
- this.clearInterval();
- // if(this.tcp){
- // this.tcp.onClose(() => {
- // // this.infoList.push('关闭')
- // console.log('tcp关闭');
- // this.tcp.close()
- // })
- // }
- },
- onUnload(){
- //wx.clearStorage();
- // 页面卸载时清除定时任务
- this.clearInterval();
- // if(this.tcp){
- // this.tcp.onClose(() => {
- // // this.infoList.push('关闭')
- // console.log('tcp关闭');
- // this.tcp.close()
- // })
- // }
- // if (this.data.observer) {
- // this.data.observer.disconnect();
- // }
- },
- onReady(){
- console.log('页面渲染完成')
- },
- showLoading:function(){
- wx.showToast({
- title:'加载中',
- icon:'loading',
- })
- },
- cancelLoading:function(){
- wx.hideToast()
- },
- onShow() {
-
- var that = this;
- that.startInterval();
- //mqtt程序,保留
- /* wx.showToast({
- title: "连接服务器....",
- icon: "loading",
- duration: 10000,
- mask: true,
- });
- let second = 10;
- var toastTimer = setInterval(() => {
- second--;
- if (second) {
- wx.showToast({
- title: `连接服务器...${second}`,
- icon: "loading",
- duration: 1000,
- mask: true,
- });
- } else {
- clearInterval(toastTimer);
- wx.showToast({
- title: "连接失败",
- icon: "error",
- mask: true,
- });
- }
- }, 1000);
- that.setData({
- client: connect(mqttUrl,options)
- })
- that.data.client.on("connect", function () {
- console.log("成功连接mqtt服务器!");
- clearInterval(toastTimer);
- wx.showToast({
- title: "连接成功",
- icon: "success",
- mask: true,
- });
- // 一秒后订阅主题
- setTimeout(() => {
- that.data.client.subscribe(mpSubTopic_env, function (err) {
- if (!err) {
- console.log("成功订阅设备上行数据环境Topic!");
- wx.showToast({
- title: "订阅成功",
- icon: "success",
- mask: true,
- });
- }
- });
- }, 500);
- });
- setTimeout(() => {
- that.data.client.subscribe(mpSubTopic_con, function (err) {
- if (!err) {
- console.log("成功订阅设备上行数据控制Topic!");
- wx.showToast({
- title: "订阅成功",
- icon: "success",
- mask: true,
- });
-
- }
- });
- }, 200);
-
- that.data.client.on("message", function (topic, message) {
- console.log(topic);
- // message是16进制的Buffer字节流
- let dataFromDev = {};
- console.log('message='+message);
- // 尝试进行JSON解析
- try {
- dataFromDev = JSON.parse(message);
- console.log(dataFromDev);
- that.setData({
- //环境状态
- Temp: dataFromDev.Temp,
- Humi: dataFromDev.Humi,
- Voltage1: dataFromDev.Voltage1,
- Voltage2: dataFromDev.Voltage2,
- //设备状态
- status_beep: dataFromDev.Beep_Flag,
- status_led: dataFromDev.Led_Flag,
- status_curtain: dataFromDev.Angle1,
- status_san: dataFromDev.San_Flag,
- status_door: dataFromDev.Angle2,
- status_fire: dataFromDev.Fire_Flag,
- status_light: dataFromDev.Light_Flag,
- status_mode: dataFromDev.Mode_Flag
- })
- } catch (error) {
- // 解析失败错误捕获并打印(错误捕获之后不会影响程序继续运行)
- console.log(error);
- }
- }) */
- // if(this.tcp){
- // this.tcp.onClose(() => {
- // // this.infoList.push('关闭')
- // console.log('tcp关闭');
- // this.tcp.close()
- // this.tcp = '';
- // })
- // }
- // // 初始化TCP实例
- // this.tcp = wx.createTCPSocket()
- // // tcp实例向服务端发起连接
- // this.tcp.connect({ address: '192.168.3.65', port: '81231' })
- // // this.infoList.push(`向${this.ip}:${~~this.port}建立链接`)
-
-
- // this.tcp.offClose(() => {
- // })
- // this.tcp.onConnect(() => {
- // // this.infoList.push('连接成功')
- // console.log('tcp连接成功');
- // })
- // this.tcp.offConnect(() => {
- // // this.infoList.push('offConnect')
- // console.log('tcp-offConnect');
- // })
- // this.tcp.onError(error => {
- // // this.infoList.push('异常:' + error)
- // console.log('tcp异常:' + error);
-
- // wx.showModal({
- // title: '提示',
- // content: '请先连接房间wi-fi,再次扫描',
- // showCancel: false
- // });
-
- // setTimeout(function() {
- // wx.reLaunch({
- // url: '/pages/scan/scan',
- // })
- // }, 2000) // 设置延时时间,单位为毫秒
- // })
- // this.tcp.onMessage(data => {
- // // this.infoList.push('tcp接收到数据: ' + transitionArrayBufferToString(data.message))
- // console.log('tcp接收到数据: ' + JSON.stringify(data.message));
- // })
-
- wx.getLocation({
- type: "wgs84",
- success(res) {
- const latitude = res.latitude;
- const longitude = res.longitude;
- const key = hefengKey;
- wx.request({
- url: `${geoApi}location=${longitude},${latitude}&key=${key}`, //获取地理位置
- success(res) {
- console.log('getLocation='+JSON.stringify(res.data));
- if (res.data.code == "401") {
- console.error("HUAQING --- 请检查你的和风天气API或Key是否正确!");
- return;
- }
- try {
- const {
- location
- } = res.data;
- that.setData({
- area: location[0].name, //城区
- city: location[0].adm2 //城市
- })
- } catch (error) {
- console.error(error);
- }
- },
- });
- wx.request({
- url: `${hefengWeather}location=${longitude},${latitude}&key=${key}`, //获取实时天气数据
- success(res) {
- console.log("实时天气=="+JSON.stringify(res.data));
- if (res.data.code == "401") {
- console.error("HUAQING --- 请检查你的和风天气API或Key是否正确!");
- return;
- }
- try {
- const {
- now
- } = res.data;
- that.setData({
- weather: now.text, // 天气
- w_temp: now.temp, // 温度
- w_humidity: now.humidity, // 湿度
- })
- } catch (error) {
- console.error(error);
- }
-
- },
- });
- wx.request({
- url: `${hefengAir}location=${longitude},${latitude}&key=${key}`, //获取空气数据
- success(res) {
- console.log("空气数据=="+JSON.stringify(res.data));
- if (res.data.code == "401") {
- console.error("HUAQING --- 请检查你的和风天气API或Key是否正确!");
- return;
- }
- try {
- const {
- now
- } = res.data;
- that.setData({
- airText: now.category, //空气质量
- airValue: now.aqi //空气指数
- })
- } catch (error) {
- console.error(error);
- }
-
- },
- });
- },
- });
- // 获取天气相关数据
-
- // wx.scanCode({
- // success: (res) => {
- // console.log('扫描结果:'+res.result) // 扫描结果
- // }
- // });
- }
- })
|