2018-07-01 01:42:39 +08:00
|
|
|
<template>
|
|
|
|
<div class="md-scroll-view-refresh">
|
|
|
|
<md-activity-indicator-rolling
|
|
|
|
:process="!isRefreshing ? process : undefined"
|
2018-09-29 15:31:34 +08:00
|
|
|
:width="10"
|
2018-07-01 01:42:39 +08:00
|
|
|
></md-activity-indicator-rolling>
|
|
|
|
<p class="refresh-tip">{{ refreshTip }}</p>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
import Roller from '../activity-indicator/roller'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'md-scroll-view-refresh',
|
|
|
|
|
|
|
|
components: {
|
|
|
|
[Roller.name]: Roller,
|
|
|
|
},
|
|
|
|
|
|
|
|
props: {
|
2018-07-12 17:44:42 +08:00
|
|
|
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: '下拉刷新',
|
|
|
|
},
|
|
|
|
refreshActiveText: {
|
|
|
|
type: String,
|
2018-07-04 20:15:39 +08:00
|
|
|
default: '释放刷新',
|
2018-07-01 01:42:39 +08:00
|
|
|
},
|
|
|
|
refreshingText: {
|
|
|
|
type: String,
|
|
|
|
default: '刷新中...',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
process() {
|
2018-07-12 17:44:42 +08:00
|
|
|
if (!this.$el || !this.scrollTop) {
|
|
|
|
return +this.scrollTop
|
2018-07-01 01:42:39 +08:00
|
|
|
}
|
2018-07-04 20:15:39 +08:00
|
|
|
|
|
|
|
const refreshHeight = this.$el.clientHeight
|
|
|
|
|
2018-07-12 17:44:42 +08:00
|
|
|
if (Math.abs(this.scrollTop) < refreshHeight / 2) {
|
2018-07-04 20:15:39 +08:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
// first 1/3 is not included in progress
|
2018-07-12 17:44:42 +08:00
|
|
|
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
|
2018-07-04 20:15:39 +08:00
|
|
|
transform rotateZ(-45deg)
|
2018-07-01 01:42:39 +08:00
|
|
|
.refresh-tip
|
|
|
|
margin-left 15px
|
2018-07-04 20:15:39 +08:00
|
|
|
font-size 24px
|
2018-07-01 01:42:39 +08:00
|
|
|
color #999
|
|
|
|
</style>
|