1宫静、利用周末兩天的時間走净,參考小天氣的風格,擼了一個天氣小程序孤里,【小夭天氣】伏伯。
2、功能十分簡單捌袜,查看當前地區(qū)的天氣和搜索其他地區(qū)的天氣说搅,增加了可以生成圖片分享出去。
3虏等、上線后發(fā)現(xiàn)一個問題弄唧,就是極速提供的天氣接口對區(qū)級市沒有區(qū)分,例如 上海有寶山區(qū)霍衫,東北那也有一個候引。就沒有區(qū)分。這是一個bug
4敦跌、其他有什么問題歡迎大家提意見和建議澄干。
歡迎大家掃碼體驗
詳情如下
部分代碼如下:
<!-- 生成圖片 -->
<view class="saveimage" wx:if="{{canvasPic}}">
<view class="loading" wx:if="{{loading}}"><image src="../images/loading.gif" class="loading"></image></view>
<canvasdrawer painting="{{painting}}" bind:getImage="eventGetImage"/>
<view class="picbox">
<view class="saveimageCont"><image src="{{shareImage}}" mode="widthFix"></image></view>
<button class="keep" catchtap='eventSave'>{{shareText}}</button>
<text class="keep keep2" bindtap="closesaveimage">返回</text>
</view>
</view>
<!--選擇地區(qū)-->
<view class="selectArea {{getLotion === '' ? 'nomargin' :'' }}" wx:if="{{selectArea}}">
<!-- 返回 -->
<view class="selectAreaBox" :dss="getLotion">
<view class="back" wx:if="{{getLotion === 'null' || getLotion !== ''}}">
<view class="backIcon" bindtap="back">
<image src="../images/back.png" class="img"></image>
</view>
</view>
<view class="input">
<input type="text" class="Jinput" placeholder="請輸入地區(qū)" bindinput='writeArea' value="{{inpuText}}" ></input>
<image src="../images/serchicon.png" class="imgicon"></image>
<view class="clear" bindtap="clearInpuText"><image src="../images/clear.png" class="clearicon"></image></view>
<view class="sureBtn" bindtap="inputGoWeather"><image src="../images/surebtn.png" class="sureicon"></image></view>
</view>
<view class="tips">歷史記錄</view>
<view class="hisCity">
<view class="hisCityBtn" data-city="{{list}}" wx:for="{{historyArea}}" wx:for-item="list" wx:key wx:if="historyArea.length > 0" bindtap="goWeather">{{list}}</view>
</view>
<view class="tips">熱門城市</view>
<view class="recCity">
<view class="recCityBtn getLocation" bindtap="selectLocation"><image class="getLocationimg" src="../images/hoticon.png"></image>定位</view>
<view class="recCityBtn" data-city="{{list}}" wx:for="{{hotArea}}" wx:for-item="list" wx:key bindtap="goWeather">{{list}}</view>
</view>
</view>
</view>
getWeatherData:function(city){
var _this = this,
thisdata = this.data,
historyArea = thisdata.historyArea;
wx.request({
url: _this.data.api,
data: {
"city": city
},
method: 'get',
header: {
'Content-Type': 'application/json'
},
dataType: 'jsonp',
jsonp: 'callback',
success: function (res) {
var res = res.data
res = JSON.parse(res)
if (res.status === "0") {
var data = res['result']
data.img = '../images/condicon/'+data.img+'b.png'
_this.setData({
getSuccess: 'true',
getLotion: city,
realdata: data,
clock: data.updatetime,
aqi: data['aqi'],
aqiMsg: data.aqi.aqiinfo['affect'] + ',' + data.aqi.aqiinfo['measure'],
life: data['index'],
daily: data['daily'],
hourly: data['hourly'],
airPredict: '兩小時之后天氣' + data.hourly[2].weather + ' 柠傍,溫度 ' + data.hourly[2].temp + '°',
quality: data['aqi'].quality
})
// 搜索返回成功后 清除 輸入框麸俘,將搜索結(jié)果放入歷史記錄
// _this.$refs.clearText.value = ''
if (thisdata.inpuText !== '') {
if (thisdata.historyArea.indexOf(thisdata.inpuText) === -1) {
historyArea.push(thisdata.inpuText)
_this.setData({
historyArea: historyArea
})
}
}
_this.back()
} else {
wx.showModal({
title: '提示',
content: res.msg,
success: function (res) {
if (res.confirm) {
_this.setData({
msgText: '位置獲取失敗P<碴!請手動選擇',
loadingBtn: true
})
} else if (res.cancel) {
console.log('用戶點擊取消')
}
}
})
}
},
// 定位獲取
selectLocation: function () {
let _this = this
_this.getlocation();
},
getlocation: function () {
var _this = this
wx.getLocation({
type: 'wgs84',
success: function (res) {
console.log(res)
var latitude = res.latitude
var longitude = res.longitude
var speed = res.speed
var accuracy = res.accuracy
qqmapsdk.reverseGeocoder({
location: {
latitude: latitude,
longitude: longitude
},
success: function (res) {
console.log(res)
_this.setData({
getLotion: res.result.address_component.district ? res.result.address_component.district : res.result.address_component.city
})
wx.setNavigationBarTitle({
title: res.result.address_component.district
})
_this.getWeatherData(res.result.address_component.district)
}
})
},
fail:function(res){
_this.setData({
msgText: '位置獲取失斝旖簟>裁省!并级!請手動選擇',
loadingBtn:true
})
}
})
},