2017-12-25 00:50:54 +01:00
|
|
|
Vue.component('dvb-weather', {
|
|
|
|
template: '#tmpl-dvb-weather',
|
|
|
|
props: {
|
|
|
|
offset: ['Number']
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2017-12-28 18:09:32 +01:00
|
|
|
hz: 30,
|
2017-12-25 00:50:54 +01:00
|
|
|
cur: '...',
|
2017-12-28 18:09:32 +01:00
|
|
|
zip: '01217',
|
2018-07-26 11:42:52 +02:00
|
|
|
url: '/cache',
|
2017-12-28 18:09:32 +01:00
|
|
|
mapping: {
|
|
|
|
1: 11,
|
|
|
|
2: 9,
|
|
|
|
3: 10,
|
|
|
|
4: 10,
|
|
|
|
9: 10,
|
|
|
|
10: 4,
|
|
|
|
11: 1,
|
|
|
|
13: 6,
|
|
|
|
50: 2,
|
2017-12-25 00:50:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
startWatcher() {
|
|
|
|
this.update()
|
|
|
|
this.watcherId = setInterval(this.update, this.hz * 1000)
|
|
|
|
},
|
|
|
|
stopWatcher() {
|
|
|
|
clearInterval(this.watcherId)
|
|
|
|
},
|
2017-12-28 18:09:32 +01: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-25 00:50:54 +01:00
|
|
|
},
|
|
|
|
created() {
|
|
|
|
this.startWatcher()
|
|
|
|
},
|
|
|
|
})
|