mand-mobile/components/scroll-view/refresh.vue

98 lines
2.1 KiB
Vue
Raw Permalink Normal View History

2018-07-01 01:42:39 +08:00
<template>
<div class="md-scroll-view-refresh">
<md-activity-indicator-rolling
:process="!isRefreshing ? process : undefined"
:width="10"
:color="rollerColor"
2018-07-01 01:42:39 +08:00
></md-activity-indicator-rolling>
<p class="refresh-tip">{{ refreshTip }}</p>
</div>
</template>
<script> import {t} from '../_locale'
import Roller from '../activity-indicator/roller'
2018-07-01 01:42:39 +08:00
export default {
name: 'md-scroll-view-refresh',
components: {
[Roller.name]: Roller,
},
props: {
scrollTop: {
2018-07-01 01:42:39 +08:00
type: Number,
default: 0,
},
isRefreshing: {
type: Boolean,
default: false,
},
isRefreshActive: {
type: Boolean,
default: false,
},
refreshText: {
type: String,
default: t('md.scroll_view.refresh.pullDownRefresh'),
2018-07-01 01:42:39 +08:00
},
refreshActiveText: {
type: String,
default: t('md.scroll_view.refresh.freedRefresh'),
2018-07-01 01:42:39 +08:00
},
refreshingText: {
type: String,
default: t('md.scroll_view.refresh.refreshing'),
2018-07-01 01:42:39 +08:00
},
rollerColor: {
type: String,
default: '#2F86F6',
},
2018-07-01 01:42:39 +08:00
},
computed: {
process() {
2019-01-26 22:28:11 +08:00
/* istanbul ignore if */
if (!this.$el || !this.scrollTop) {
return +this.scrollTop
2018-07-01 01:42:39 +08:00
}
const refreshHeight = this.$el.clientHeight
if (Math.abs(this.scrollTop) < refreshHeight / 2) {
return 0
}
// first 1/3 is not included in progress
return (Math.abs(this.scrollTop) - refreshHeight / 2) / (refreshHeight / 2)
2018-07-01 01:42:39 +08:00
},
refreshTip() {
if (this.isRefreshing) {
return this.refreshingText
} else if (this.isRefreshActive) {
return this.refreshActiveText
} else {
return this.refreshText
}
},
},
}
</script>
<style lang="stylus">
.md-scroll-view-refresh
display flex
padding 50px 0
justify-content center
align-items center
overflow hidden
.md-activity-indicator-rolling
.md-activity-indicator-svg
width 32px !important
height 32px !important
transform rotateZ(-45deg)
2018-07-01 01:42:39 +08:00
.refresh-tip
margin-left 15px
font-size 24px
2018-07-01 01:42:39 +08:00
color #999
</style>