mtfosbot_web/src/components/showDonateBar/index.vue

67 lines
1.4 KiB
Vue

<template>
<div class="show-donate">
<DonateBar :title="title" :max="targetAmount" :timestamp="endDate" :now="total" />
</div>
</template>
<style lang="less">
html,body,#app {
background-color: inherit;
}
</style>
<style lang="less" scoped>
.show-donate {
padding: 5px 10px;
}
</style>
<script>
import DonateBar from '@/components/common/donate-bar'
import axios from 'axios'
import {apiUrl, toInt} from '@/tools'
export default {
name: 'PublicDonateBar',
components: {
DonateBar
},
data () {
return {
title: '',
targetAmount: 0,
endDate: 0,
total: 0
}
},
mounted () {
this.client = axios.create({
baseURL: apiUrl
})
this.getDonateInfo()
this.timer = setInterval(this.getDonateInfo.bind(this), 5000)
},
beforeDestroy () {
clearInterval(this.timer)
},
methods: {
getDonateInfo: function () {
this.client({
method: 'get',
url: `/api/twitch/channel/${this.$route.params.chid || ''}/opay/bar`
}).then(res => {
if ('data' in res && 'setting' in res.data && typeof res.data.setting === 'object') {
let tmp = res.data.setting
this.title = tmp.title || ''
this.targetAmount = tmp.target_amount || 0
let ets = 'end_date' in tmp ? new Date(tmp.end_date).getTime() : 0
this.endDate = ets
this.total = toInt(tmp.total, 0, 0) || 0
}
}).catch(err => {})
}
}
}
</script>