Weather_wev8.js
2.67 KB
define("Weather_html",function(){return'<div id="NMEC_${id}" class="wev-comp-${compType}"> <div class="wev-weather-curr"> <img src="${defalutUrl}"> <p> <span></span> <span>${city}</span> </p> </div> <div class="wev-clearfix"> {@each i in range(0, 3)} <div class="wev-weather-next"> <span></span> <img/> <span></span> </div> {@/each} <div class="wev-loading"><span>loading...</span></div> </div></div>'}),define(["mUtil","Component","weatherHelper","amap"],function(p,t,o){return t.init(function(e){var n={};t.super(this,e),this.type="Weather",this.tpl=this.type+"_html",this.css=this.type+"_css";var r=this.viewModel={defalutUrl:o.getImageUrl("未知"),paramName:"",cityType:"1",city:"shanghai"};this.mounted=function(){if("1"!=r.cityType&&($p(r.paramName)||r.city&&!/{\w+}/.test(r.city)))r.city=$p(r.paramName)||r.city,this.loadData(r.city.toLowerCase());else{var a=this;AMap.plugin("AMap.CitySearch",function(){(new AMap.CitySearch).getLocalCity(function(e,t){"complete"===e&&"OK"===t.info&&t.bounds?(r.city=t.adcode,r.city=$p(r.paramName)||r.city,a.loadData(r.city.toLowerCase())):console.error(t.info)})})}},this.loadData=function(e){var t,a,r=o.getWeatherCityCode(e),i="https://restapi.amap.com/v3/weather/weatherInfo?key=fbbb3b85bc2133d171a6540deb92ca21&extensions=all&city="+e;t=e,a=this.$el,$(".wev-weather-next",a).hide(),$(".wev-weather-curr img",a).attr("src",o.getImageUrl("未知")),$(".wev-weather-curr span",a).eq(1).text(t||""),$(".wev-weather-curr span",a).eq(0).text("-- °"+"c".toUpperCase()),r&&(i="https://restapi.amap.com/v3/weather/weatherInfo?key=fbbb3b85bc2133d171a6540deb92ca21&extensions=all&city="+r),p.ajax(i,function(e){var t=!1;if("1"==e.status&&"0"!=e.count)return t=e.forecasts[0],n.configWeatherInfo(t);n.configWeatherInfo(!1)},{error:function(){n.configWeatherInfo(!1)}})},n.configWeatherInfo=function(e){var t,a=this.$el;if(!e)return t=$(".wev-weather-curr span",a).eq(1),p.getLabel(5279,"无法查询到#CITY#的天气信息。",function(e){t.text(e.replace("#CITY#",t.text()))}),t;var r,i=e.casts,n=$(".wev-weather-next",a);$(".wev-weather-curr img",a).attr("src",o.getImageUrl(e.casts[0].dayweather)),$(".wev-weather-curr span",a).eq(1).text(e.city),$(".wev-weather-curr span",a).eq(0).text((parseInt(e.casts[0].daytemp)+parseInt(e.casts[0].nighttemp))/2+" °"+"c".toUpperCase()),n.show();for(var s=0,c=n.size();s<c;s++)r=i[s+1],$("img",n[s]).attr("src",o.getImageUrl(r.dayweather)),$("span",n[s]).eq(0).text(r.date),$("span",n[s]).eq(1).text((parseInt(r.daytemp)+parseInt(r.nighttemp))/2+" °"+"c".toUpperCase())},n.configWeatherInfo=n.configWeatherInfo.bind(this)})});