| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379 |
- // 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'
- }
- var humidityValue = 40;
- var humidityMax = 100;
- var humidityMin = 40;
- var humidityMarginLeft = 110;
- let chartCircularProgressBar;//圈圈
- function updateChartCircularProgressBarOption(rscore_desc, rscore_value, that) {
- if (chartCircularProgressBar) {
- setOption(chartCircularProgressBar);
- } else {
- // 假设这段代码在小程序的某个函数中执行
- // 创建查询对象
- const query = wx.createSelectorQuery();
- // 选择第一个id为mychart-dom-gauge的view
- query.select('#mychart-dom-gauge').boundingClientRect(function (res) {
- // 如果res不为null,则表示view存在
- if (res) {
- that.selectComponent('#mychart-dom-gauge').init((canvas, width, height, dpr) => {
- const chart = echarts.init(canvas, null, {
- width: width,
- height: height,
- devicePixelRatio: dpr // new
- });
- canvas.setChart(chart);
- setOption(chart);
- // 将图表实例绑定到 this 上,可以在其他成员函数(如 dispose)中访问
- chartCircularProgressBar = chart;
- // 注意这里一定要返回 chart 实例,否则会影响事件处理等
- return chart;
- });
- } else {
- console.log('view不存在');
- }
- }).exec(); // 执行查询
-
- }
- }
- function checkState(state) {
- return state == 'on' || state == 'off';
- }
- function setOption(chart) {
- var option = {
- backgroundColor: "#ffffff",
- series: [{
- name: '加湿器',
- type: 'gauge',
- startAngle: 230,
- endAngle: -50,
- splitNumber: 8,
- min: humidityMin || 40,
- max: humidityMax || 70,
- axisLine: {
- show: false
- },
- axisLabel: {
- show: false,
- },
- anchor: {
- show: false
- },
- splitLine: {
- distance: -10,
- length: 6,
- lineStyle: {
- width: 1.5,
- color: '#9499C3'
- }
- },
- pointer: {
- show: false
- },
- axisTick: {
- distance: -10,
- splitNumber: 5,
- lineStyle: {
- width: 1,
- color: '#9499C3'
- }
- },
- progress: {
- show: true,
- width: 10,
- itemStyle: {
- color: "#0BC3AA"
- }
- },
- title: {
- color: '#6C6970',
- offsetCenter: [0, '-50%'],
- lineHeight: 15,
- fontSize: 12
- },
- detail: {
- valueAnimation: true,
- width: '100%',
- offsetCenter: [0, '20%'],
- fontSize: "28px",
- fontWeight: 'bolder',
- formatter: function (value) {
- return `${value.toFixed(0) }` + '{units|%}'
- },
- color: '#3E3D44',
- rich: {
- units: {
- fontSize: "12px",
- padding: [10, 0, 0, 1],
- fontWeight: 'bolder',
- color: '#333333'
- },
- }
- },
- data: [{
- value: humidityValue || 0,
- name: '湿度',
- }]
- }]
- };
- chart.setOption(option);
- }
- // import Notify from '../../@vant/weapp/notify/notify';
- // import Dialog from '../../@vant/weapp/dialog/dialog';
- import Toast from '../../@vant/weapp/toast/toast';
- Page({
- data: {
- ecHumidifier: {
- lazyLoad: true, // 懒加载
- },
- //单选框
- radio_select: '10',
- radio_switch: '10',
- //倒计时时间
- Time: 0,
- //火灾时的呼吸效果变量
- breathNum: 0,
- currentMenuTabIndex: -1,
- currentDialogIndex: 0,
- menuTabDialogShow: false,
- //火灾头顶警示
- 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: [],//加湿器 图像
- listAromatherapyMachine: [],//香薰机 图像
- listSensor: [],//文字描述的
- listText: [],//文本框填写的
- isPlaying: false,
- currentTime: 0,
- currentIndex: 0,
- duration: 0,
- currentSongTitle: '--',
- currentSongArtist: '--',
- canPrev: true,
- canNext: true,
- songs: [], // 歌曲列表
- scrollValue: [],
- modelList1: [],//起床模式
- modelList2: [],//观影模式
- modelList3: [],//睡眠模式
- selectedIndex: 0, // 默认选中第一个选项
- home_room: [
- 'company_laboratory',
- '2802',
- ],
- climateMode: '',//空调模式:加热还是除湿。在空调增加按钮和减少按钮 时使用
- canvasWidth: 300, // 画布宽度
- canvasHeight: 150, // 画布高度
- value: 60, // 当前得分
- total: 100, // 总分值
- tvEntityId: '',// 电视实体Id
- tvEntityIds: [],// 电视实体
- entityName: '',//
- sleep_duration: '50',
- itemList: [
- { name: '1', data: [{ value: 10 }, { value: 1 }] },
- { name: '2', data: [{ value: 10 }, { value: 4 }] },
- { name: '3', data: [{ value: 10 }, { value: 7 }] },
- ],
- blackList: [
- // '指示灯','电视模式','电视音量','空调遥控','智能音箱','电视控制码','传感器模式','开关模式','耗电量','智能音箱会话'
- '加湿器', '空调', '音箱', '窗帘', '纱帘'
- ],
- temperatureHumidifyName: '温度',
- temperatureValue:0,
- 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: '',
- humidityMarginLeft: humidityMarginLeft
- },
- checkMenuTap(e) {
- // 三种模式
- console.log(e.currentTarget.dataset.index)
- const index = e.currentTarget.dataset.index;
- if (this.data.currentMenuTabIndex == index) {
- // 选中的打断
- return
- }
- if (index == 0 && !this.data.modelList1.length) {
- // 没有的打断
- return
- }
- if (index == 1 && !this.data.modelList2.length) {
- // 没有的打断
- return
- }
- if (index == 2 && !this.data.modelList3.length) {
- // 没有的打断
- return
- }
- this.setData({
- menuTabDialogShow: true,
- currentDialogIndex: index
- })
- },
- onClickHideMenuTabDialog() {
- this.setData({
- menuTabDialogShow: false
- })
- },
- onClickHideSureMenuTabDialog() {
- var item = null;
- if (this.data.currentDialogIndex == 0) {
- item = this.data.modelList1[0];
- } else if (this.data.currentDialogIndex == 1) {
- item = this.data.modelList2[0];
- } else if (this.data.currentDialogIndex == 2) {
- item = this.data.modelList3[0];
- }
- // 确认模式
- this.setData({
- menuTabDialogShow: false,
- currentMenuTabIndex: this.data.currentDialogIndex
- })
- wx.request({
- url: `${homeApi_https}/services/automation/trigger`,
- method: 'POST',
- data: {
- "entity_id": item.entity_id,
- "skip_condition": true,
- },
- header: {
- 'content-type': 'application/json', // 默认值
- 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
- },
- success(res) {
- },
- });
- },
- checkHumidityMarginLeft() {
- var proportion = 440;
- var percentage = (humidityValue - humidityMin) / (humidityMax - humidityMin);
- const value = percentage * proportion + humidityMarginLeft;
- this.setData({
- humidityMarginLeft: value
- })
- },
- // 加湿器
- handleTouchEndHumidifier: function (e) {
- this.setData({
- sliderValueHumidifier: '',
- });
- },
- // 加湿器更改湿度
- handleChangingHumidifier: function (e) {
- // 假设 slider 宽度为屏幕宽度(或某个固定值),这里需要根据实际情况调整
- const sliderValueHumidifier = e.detail.value;
- var proportion = 440;
- var percentage = (sliderValueHumidifier - humidityMin) / (humidityMax - humidityMin);
- const humidityMarginLeftValue = percentage * proportion + humidityMarginLeft;
- this.setData({
- sliderValueHumidifier: sliderValueHumidifier,
- humidityMarginLeft: humidityMarginLeftValue
- });
- },
- 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)
- // }
- },
- });
- },
- // switch
- onSelect_All(e) {
- var that = this;
- const tempListSwitch = that.data.listSwitch;
- // 获取绑定的参数
- 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 // 0 || 1;
- 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);
- if (param4 == '1') {
- tempListSwitch[param0].state = "on"
- } else {
- tempListSwitch[param0].state = "off"
- }
- that.setData({
- listSwitch: tempListSwitch
- })
- // 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)
- wx.request({
- url: `${homeApi_https}` + param1 + param2 + (e.detail ? '/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_AromatherapyMachine(e) {
- var that = this;
- const tempListSwitch = that.data.listAromatherapyMachine;
- // 获取绑定的参数
- 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 // 0 || 1;
- 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);
- if (param4 == '1') {
- tempListSwitch[param0].state = "on"
- } else {
- tempListSwitch[param0].state = "off"
- }
- that.setData({
- listAromatherapyMachine: tempListSwitch
- })
- // 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)
- wx.request({
- url: `${homeApi_https}` + param1 + param2 + (e.detail ? '/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)
- // }
- },
- });
- },
- onTap_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 事件,携带值为', param4)
- wx.request({
- url: `${homeApi_https}` + param1 + param2 + (param4 == '1' ? '/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);
- },
- initChartHumidifier(canvas, width, height, dpr) {
- console.log("humidityValue=>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", humidityValue);
- this.selectComponent('#mychart-dom-gauge').init((canvas, width, height, dpr) => {
- // 获取组件的 canvas、width、height 后的回调函数
- // 在这里初始化图表
- const chart = echarts.init(canvas, null, {
- width: width,
- height: height,
- devicePixelRatio: dpr // new
- });
- setOption(chart);
- // 将图表实例绑定到 this 上,可以在其他成员函数(如 dispose)中访问
- chartCircularProgressBar = chart;
- this.setData({
- isLoaded: true,
- isDisposed: false
- });
- // 注意这里一定要返回 chart 实例,否则会影响事件处理等
- return chart;
- });
- },
-
- //设备控制函数 开始
- 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 listAromatherapyMachineTemp = [];
- 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].attributes && resData[i].attributes.parent_entity_id && entityIdList
- && entityIdList.includes(resData[i].attributes.parent_entity_id)
- ) {
- 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('香薰机灯光')
- obj.isAromAtomization = obj.friendly_name.includes('香薰机雾化')
- obj.isAromatherapy = obj.friendly_name.endsWith('香薰机') || obj.friendly_name.endsWith('香薰机开关')
- if (obj.entity_id && obj.state && checkState(obj.state) && obj.friendly_name && obj.domain && !obj.isAromlight && !obj.isAromAtomization && !obj.isAromatherapy) {
- if (!obj.friendly_name.endsWith("电视")) {
- listSwitchTemp.push(obj)
- }
- } else if ((obj.isAromlight || obj.isAromAtomization || obj.isAromatherapy) && checkState(obj.state)) {
- listAromatherapyMachineTemp.push(obj)
- }
- }
- }
- }
- console.log('listSwitchTemp=' + JSON.stringify(listSwitchTemp));
- listSwitchTemp = that.checkTVList(listSwitchTemp);
- that.setData({
- listSwitch: listSwitchTemp,
- listAromatherapyMachine: listAromatherapyMachineTemp,
- })
- } 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;
- }
- })
- this.setData({
- listHumidifier: list
- })
- let data = {
- "entity_id": entity_id,
- "humidity": e.detail
- }
- 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 || 0;
- 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
- }
- console.log(e.currentTarget.dataset);
- 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);
- },
- // 拖动空调的值
- dragClimate(e) {
- var that = this;
- let state = e.currentTarget.dataset.state;
- console.log(e.detail.value);
- if (state == "auto") {
- return
- }
- let list = that.data.listClimate;//这里是将需要循环的数组赋值给list
- let indexS = Number(e.currentTarget.dataset.index);
- // 将本地缓存数据渲染到对应修改的案例
- for (let i = 0; i < list.length; i++) {
- var element = list[i];
- if (i == indexS) {
- element.temperatureTemp = e.detail.value;
- break;
- }
- }
- that.setData({
- listClimate: list
- })
- console.log(list);
- },
- // 更改空调的值
- changeClimate(e) {
- var that = this;
- let state = e.currentTarget.dataset.state;
- if (state == "auto") {
- return
- }
- 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;
- }
- })
- this.setData({
- listClimate: list
- })
- data = {
- "entity_id": entity_id,
- "temperature": e.detail,
- "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,
- "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,
- "hvac_mode": that.data.climateMode
- }
- this.getService("/services", "/" + domain, "/set_temperature", "POST", data);
- }
- },
- // 更改空调的值
- minusClimate(e) {
- var that = this;
- let state = e.currentTarget.dataset.state;
- if (state == "auto") {
- return
- }
- 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 temperature = e.currentTarget.dataset.temperature - 1;
- 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 = temperature;
- }
- })
- this.setData({
- listClimate: list
- })
- data = {
- "entity_id": entity_id,
- "temperature": temperature,
- "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": temperature,
- "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": temperature,
- "hvac_mode": that.data.climateMode
- }
- this.getService("/services", "/" + domain, "/set_temperature", "POST", data);
- }
- },
- // 更改空调的值
- addClimate(e) {
- var that = this;
- let state = e.currentTarget.dataset.state;
- if (state == "auto") {
- return
- }
- 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 temperature = e.currentTarget.dataset.temperature + 1;
- 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 = temperature;
- }
- })
- this.setData({
- listClimate: list
- })
- data = {
- "entity_id": entity_id,
- "temperature": temperature,
- "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": temperature,
- "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": temperature,
- "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 state = e.currentTarget.dataset.state;
- if (state == 'off') {
- // 如果是关闭的就开成自动
- this.onClimateAuto(e);
- return
- }
- 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 listAromatherapyMachineTemp = [];
- var modelList1 = [];
- var modelList2 = [];
- var modelList3 = [];
- var climateModeTemp = '';
- var temperatureHumidifyNameTemp = '温度';
- var humidityValueTemp = 0;
- var humidityMaxTemp = 0;
- var humidityMinTemp = 0;
- 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.friendly_name.includes("吸顶灯")) {
- obj.imgSrc = '/static/icons/ic_dd_1.svg';
- obj.selectedImgSrc = '/static/icons/ic_dd_2.svg';
- obj.bg = 'background: linear-gradient(180deg, #DFFFFB 0%, #FFFFFF 53%)';
- } else if (obj.friendly_name.includes("走廊灯")) {
- obj.imgSrc = '/static/icons/ic_zld_1.svg';
- obj.selectedImgSrc = '/static/icons/ic_zld_2.svg';
- obj.bg = 'background: linear-gradient(180deg, #FFEEFA 0%, #FFFFFF 50%)';
- } else if (obj.friendly_name.includes("筒灯")) {
- obj.imgSrc = '/static/icons/ic_td_1.svg';
- obj.selectedImgSrc = '/static/icons/ic_td_2.svg';
- obj.bg = 'background: linear-gradient(180deg, #EBF0FF 0%, #FFFFFF 50%)';
- } else if (obj.friendly_name.includes("主灯")) {
- obj.imgSrc = '/static/icons/ic_zd_1.svg';
- obj.selectedImgSrc = '/static/icons/ic_zd_2.svg';
- obj.bg = 'background: linear-gradient(180deg, #EFE7FF 0%, #FFFFFF 50%)';
- } else if (obj.friendly_name.includes("气扇")) {
- obj.imgSrc = '/static/icons/ic_pqs_1.svg';
- obj.selectedImgSrc = '/static/icons/ic_pqs_2.svg';
- obj.bg = 'background: linear-gradient(180deg, #E3FFE6 0%, #FFFFFF 53%)';
- } else if (obj.friendly_name.includes("电视")) {
- obj.imgSrc = '/static/icons/ic_ds_1.svg';
- obj.selectedImgSrc = '/static/icons/ic_ds_1.svg';
- obj.bg = 'background: linear-gradient(180deg, #FFF2DF 0%, #FFFFFF 53%)';
- } else if (obj.friendly_name.includes("空气净化器")) {
- obj.imgSrc = '/static/icons/ic_kqjhq_1.svg';
- obj.selectedImgSrc = '/static/icons/ic_kqjhq_2.svg';
- obj.bg = 'background: linear-gradient(180deg, #EBFAFF 0%, #FFFFFF 50%)';
- } else if (obj.friendly_name.includes("香薰机雾化")) {
- obj.imgSrc = '/static/icons/ic_xxjwh.svg';
- obj.selectedImgSrc = '/static/icons/ic_xxjwh.svg';
- } else if (obj.friendly_name.endsWith('香薰机') || obj.friendly_name.endsWith('香薰机开关')) {
- obj.imgSrc = '/static/icons/ic_xxj.svg';
- obj.selectedImgSrc = '/static/icons/ic_xxj.svg';
- } else if (obj.friendly_name.includes("灯")) {
- obj.imgSrc = '/static/icons/ic_dd_1.svg';
- obj.selectedImgSrc = '/static/icons/ic_dd_2.svg';
- obj.bg = 'background: linear-gradient(180deg, #DFFFFB 0%, #FFFFFF 53%)';
- } else {
- obj.imgSrc = '/static/icons/ic_ds_1.svg';
- obj.selectedImgSrc = '/static/icons/ic_ds_1.svg';
- obj.bg = 'background: linear-gradient(180deg, #FFF2DF 0%, #FFFFFF 53%)';
- }
- }
- if (resData[i].attributes && resData[i].attributes.home_room) {
- obj.home_room = resData[i].attributes.home_room.split(' ')[1]; //房间号
- }
- if (resData[i].state && 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('香薰机灯光')
- obj.isAromAtomization = obj.friendly_name.includes('香薰机雾化')
- obj.isAromatherapy = obj.friendly_name.endsWith('香薰机') || obj.friendly_name.endsWith('香薰机开关')
- if (obj.entity_id && obj.state && checkState(obj.state) && obj.friendly_name && obj.domain && obj.domain != 'automation' && !obj.isAromlight && !obj.isAromAtomization && !obj.isAromatherapy) {
- if (!obj.friendly_name.endsWith("电视")) {
- listSwitchTemp.push(obj)
- }
- } else if ((obj.isAromlight || obj.isAromAtomization || obj.isAromatherapy) && checkState(obj.state)) {
- listAromatherapyMachineTemp.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 && checkState(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.temperatureTemp = 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 && checkState(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.state == "playing" && 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 = obj.min_humidity;
- obj.max = obj.max_humidity;
- humidityValueTemp = obj.humidity;
- humidityMaxTemp = obj.max;
- humidityMinTemp = obj.min;
- // console.log('humidifier-obj=='+JSON.stringify(obj));
- if (obj.entity_id && obj.state && checkState(obj.state) && obj.friendly_name && obj.domain) {
- listHumidifierTemp.push(obj);
- }
- }
- if ((resData[i].state && obj.domain && obj.domain == 'automation')) {
- console.log("", resData[i].attributes.friendly_name);
- if (resData[i].attributes.friendly_name.endsWith('起床模式')) {
- modelList1.push(obj)
- } else if (resData[i].attributes.friendly_name.endsWith('观影模式')) {
- modelList2.push(obj)
- } else if (resData[i].attributes.friendly_name.endsWith('睡眠模式')) {
- modelList3.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)
- // }
- // }
- }
- listSwitchTemp = that.checkTVList(listSwitchTemp);
- 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'), //香薰液浓度
- modelList1,
- modelList2,
- modelList3,
- 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,
- listAromatherapyMachine: listAromatherapyMachineTemp,
- // ecHumidifier: {
- // onInit: that.initChartHumidifier
- // },
- sliderValueHumidifier: ''
- })
- if (listHumidifierTemp.length && humidityValue != humidityValueTemp) {
- humidityValue = humidityValueTemp || 40;
- humidityMin = humidityMinTemp;
- humidityMax = humidityMaxTemp;
- that.checkHumidityMarginLeft()
- updateChartCircularProgressBarOption()
- }
- 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 listAromatherapyMachineTemp = [];
- var humidityValueTemp = 0;
- var humidityMaxTemp = 0;
- var humidityMinTemp = 0;
- var climateModeTemp = '';
- var temperatureHumidifyNameTemp = '温度';
- var modelList1 = [];
- var modelList2 = [];
- var modelList3 = [];
- 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.friendly_name.includes("吸顶灯")) {
- obj.imgSrc = '/static/icons/ic_dd_1.svg';
- obj.selectedImgSrc = '/static/icons/ic_dd_2.svg';
- obj.bg = 'background: linear-gradient(180deg, #DFFFFB 0%, #FFFFFF 53%)';
- } else if (obj.friendly_name.includes("走廊灯")) {
- obj.imgSrc = '/static/icons/ic_zld_1.svg';
- obj.selectedImgSrc = '/static/icons/ic_zld_2.svg';
- obj.bg = 'background: linear-gradient(180deg, #FFEEFA 0%, #FFFFFF 50%)';
- } else if (obj.friendly_name.includes("筒灯")) {
- obj.imgSrc = '/static/icons/ic_td_1.svg';
- obj.selectedImgSrc = '/static/icons/ic_td_2.svg';
- obj.bg = 'background: linear-gradient(180deg, #EBF0FF 0%, #FFFFFF 50%)';
- } else if (obj.friendly_name.includes("主灯")) {
- obj.imgSrc = '/static/icons/ic_zd_1.svg';
- obj.selectedImgSrc = '/static/icons/ic_zd_2.svg';
- obj.bg = 'background: linear-gradient(180deg, #EFE7FF 0%, #FFFFFF 50%)';
- } else if (obj.friendly_name.includes("气扇")) {
- obj.imgSrc = '/static/icons/ic_pqs_1.svg';
- obj.selectedImgSrc = '/static/icons/ic_pqs_2.svg';
- obj.bg = 'background: linear-gradient(180deg, #E3FFE6 0%, #FFFFFF 53%)';
- } else if (obj.friendly_name.includes("电视")) {
- obj.imgSrc = '/static/icons/ic_ds_1.svg';
- obj.selectedImgSrc = '/static/icons/ic_ds_1.svg';
- obj.bg = 'background: linear-gradient(180deg, #FFF2DF 0%, #FFFFFF 53%)';
- } else if (obj.friendly_name.includes("空气净化器")) {
- obj.imgSrc = '/static/icons/ic_kqjhq_1.svg';
- obj.selectedImgSrc = '/static/icons/ic_kqjhq_2.svg';
- obj.bg = 'background: linear-gradient(180deg, #EBFAFF 0%, #FFFFFF 50%)';
- } else if (obj.friendly_name.includes("香薰机雾化")) {
- obj.imgSrc = '/static/icons/ic_xxjwh.svg';
- obj.selectedImgSrc = '/static/icons/ic_xxjwh.svg';
- } else if (obj.friendly_name.endsWith('香薰机') || obj.friendly_name.endsWith('香薰机开关')) {
- obj.imgSrc = '/static/icons/ic_xxj.svg';
- obj.selectedImgSrc = '/static/icons/ic_xxj.svg';
- }
- else if (obj.friendly_name.includes("灯")) {
- obj.imgSrc = '/static/icons/ic_dd_1.svg';
- obj.selectedImgSrc = '/static/icons/ic_dd_2.svg';
- obj.bg = 'background: linear-gradient(180deg, #DFFFFB 0%, #FFFFFF 53%)';
- }
- else {
- obj.imgSrc = '/static/icons/ic_ds_1.svg';
- obj.selectedImgSrc = '/static/icons/ic_ds_1.svg';
- obj.bg = 'background: linear-gradient(180deg, #FFF2DF 0%, #FFFFFF 53%)';
- }
- }
- 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('香薰机灯光')
- obj.isAromAtomization = obj.friendly_name.includes('香薰机雾化')
- obj.isAromatherapy = obj.friendly_name.endsWith('香薰机') || obj.friendly_name.endsWith('香薰机开关')
- if (obj.entity_id && obj.state && checkState(obj.state) && obj.friendly_name && obj.domain && obj.domain != 'automation' && obj.domain != 'automation' && !obj.isAromlight && !obj.isAromAtomization && !obj.isAromatherapy) {
-
- if (!obj.friendly_name.endsWith("电视")) {
- listSwitchTemp.push(obj)
- }
- } else if ((obj.isAromlight || obj.isAromAtomization || obj.isAromatherapy) && checkState(obj.state)) {
- listAromatherapyMachineTemp.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 && checkState(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.temperatureTemp = 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 && checkState(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.state == "playing" && 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 = obj.min_humidity;
- obj.max = obj.max_humidity;
- humidityValueTemp = obj.humidity;
- humidityMaxTemp = obj.max;
- humidityMinTemp = obj.min;
- // console.log('humidifier-obj=='+JSON.stringify(obj));
- if (obj.entity_id && obj.state && checkState(obj.state) && obj.friendly_name && obj.domain) {
- listHumidifierTemp.push(obj);
- }
- }
- if ((resData[i].state && obj.domain && obj.domain == 'automation')) {
- console.log("", resData[i].attributes.friendly_name);
- if (resData[i].attributes.friendly_name.endsWith('起床模式')) {
- modelList1.push(obj)
- } else if (resData[i].attributes.friendly_name.endsWith('观影模式')) {
- modelList2.push(obj)
- } else if (resData[i].attributes.friendly_name.endsWith('睡眠模式')) {
- modelList3.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)
- // }
- // }
- }
- listSwitchTemp = that.checkTVList(listSwitchTemp);
- 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'), //香薰液浓度
- modelList1,
- modelList2,
- modelList3,
- 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,
- listAromatherapyMachine: listAromatherapyMachineTemp,
- // ecHumidifier: {
- // onInit: that.initChartHumidifier
- // },
- sliderValueHumidifier: '',
- isLoading: false,
- })
- if (listHumidifierTemp.length && humidityValue != humidityValueTemp) {
- humidityValue = humidityValueTemp || 40;
- humidityMin = humidityMinTemp;
- humidityMax = humidityMaxTemp;
- that.checkHumidityMarginLeft()
- that.initChartHumidifier();
- }
- 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;
- },
- checkTVList(items = []) {
- // 创建一个新数组来存放不包含"电视"的对象
- let newItems = [];
- // 存放包含"电视"的对象
- let tvItems = [];
- // 遍历原数组
- items.forEach(item => {
- // 检查name是否包含"电视"
- if (item.friendly_name.includes("电视")) {
- tvItems.push(item);
- } else {
- newItems.push(item);
- }
- });
- // 将包含"电视"的对象添加到新数组的末尾
- newItems.push(...tvItems);
- // 如果需要,用新数组替换原数组
- items = newItems;
- return items;
- },
- imageLoad: function () {
- this.setData({
- isLoading: false,
- });
- console.log('图片渲染完成');
- },
- startInterval: function () {
- // 使用 setInterval 创建定时任务,每8秒执行一次 this.myMethod 方法
- var that = this;
- that.clearInterval();
- // 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);
- }, 5000);
- // 第二个定时器,每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() {
- const app = getApp();
- app.globalData.selectedTabIndex = 0;
- this.getTabBar().setData({
- selected: 0
- })
- var that = this;
- that.setData({
- currentMenuTabIndex: -1
- })
- that.startInterval();
- // that.setData({
- // ecHumidifier: {
- // onInit: initChartHumidifier
- // },
- // })
- //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) // 扫描结果
- // }
- // });
- }
- })
|