dvb/app/res/js/vue/dvb-weather.js

50 lines
872 B
JavaScript
Raw Normal View History

2017-12-24 23:50:54 +00:00
Vue.component('dvb-weather', {
template: '#tmpl-dvb-weather',
props: {
offset: ['Number']
},
data() {
return {
2017-12-28 17:09:32 +00:00
hz: 30,
2017-12-24 23:50:54 +00:00
cur: '...',
2017-12-28 17:09:32 +00:00
zip: '01217',
2018-07-26 09:42:52 +00:00
url: '/cache',
2017-12-28 17:09:32 +00:00
mapping: {
1: 11,
2: 9,
3: 10,
4: 10,
9: 10,
10: 4,
11: 1,
13: 6,
50: 2,
2017-12-24 23:50:54 +00:00
}
}
},
methods: {
startWatcher() {
this.update()
this.watcherId = setInterval(this.update, this.hz * 1000)
},
stopWatcher() {
clearInterval(this.watcherId)
},
2017-12-28 17:09:32 +00:00
async update() {
fetch(`${this.url}/${this.zip}`, {
mode: 'cors',
cache: 'default'
}).then(res => res.json()).then(res => {
const data = res.list[this.offset]
const image = this.mapping[parseInt(data.weather[0].icon)]
this.$el.style.backgroundImage = `url('res/img/${image}.png')`
this.cur = data.main.temp
})
},
2017-12-24 23:50:54 +00:00
},
created() {
this.startWatcher()
},
})