手册版本 V3.0
组件名称
graceReload : /graceUI/组件目录/graceReload
最近一次更新于 2020.12.02 请更新框架文件及图标文件;
使用场景
下拉刷新在日常开发中是极其常见的场景,但 uni-app 或小程序提供的刷新方案有着位置固定、样式不可修改、不能配合自定义导航使用等诸多缺点。
GraceUI 下拉刷新组件通过与滚动区域的组合,模拟实现了下拉刷新,解决了上面提到的多个不足。
实现原理
1. 监听滚动区域的滚动数据及手指滑动数据
2. 根据滚动位置、手指滑动数据判断是否进行刷新
3. 刷新组件激活 reload 事件
4. 在页面上执行 reload 事件
5. 刷新完成后关闭刷新动画
组件属性
// 刷新过程中的提示文本
refreshText : ['继续下拉刷新','松开手指开始刷新','数据刷新中','数据已刷新'];,
// 刷新过程中组件的背景颜色
refreshBgColor : ['#FFFFFF','#FFFFFF','#FFFFFF','#63D2BC']
// 刷新过程中组件的文本颜色 [ 准备刷新, 刷新中, 刷新完成 ]
refreshColor : ['rgba(69, 90, 100, 0.6)','rgba(69, 90, 100, 0.6)','#63D2BC','#FFFFFF']
// 组件文本尺寸
refreshFontSize : 26rpx
组件函数
endload : 关闭刷新动画;
演示代码
UNI 普通版本
NVUE 版本
微信小程序独立版本
<template>
<gracePage :customHeader="false">
<view slot="gBody" class="grace-flex-v1" id="gBody">
<view class="grace-margin-top grace-body">
<text class="grace-title">刷新演示</text>
</view>
<scroll-view class="grace-relative" scroll-y="true" :style="{height:scrollHeight+'px'}"
@touchstart="touchstart" @touchmove="touchmove" @touchend="touchend" @scroll="scroll">
<graceReload @reload="reload" width="700rpx" marginLeft="25rpx" ref="graceReload"></graceReload>
<view class="grace-text-center" style="background:#F8F8F8; height:2000px; margin:0 25rpx;">
<text class="grace-text" style="line-height:100px;">滚动区域,请根据需求放置您的布局。</text>
</view>
</scroll-view>
</view>
</gracePage>
</template>
<script>
import gracePage from "../../graceUI/components/gracePage.vue";
import graceReload from '../../graceUI/components/graceReload.vue';
export default {
data() {
return {
scrollTop : 0,
scrollHeight : 600
}
},
onReady:function(){
setTimeout(()=>{
uni.createSelectorQuery().select('#gBody').fields(
{size: true}, (res) => {
// 60 是滚动区域上方内容的高
this.scrollHeight = res.height - 60;
}
).exec();
},1000);
},
methods:{
scroll:function(e){
console.log(e);
this.scrollTop = e.detail.scrollTop;
},
touchstart : function (e){
var touchObj = {scrollTop :this.scrollTop, moveY : e.changedTouches[0].pageY};
this.$refs.graceReload.touchstart(touchObj);
},
touchmove : function (e) {
var touchObj = {scrollTop :this.scrollTop, moveY : e.changedTouches[0].pageY};
this.$refs.graceReload.touchmove(touchObj);
},
touchend : function (e) {
var touchObj = {scrollTop :this.scrollTop, moveY : e.changedTouches[0].pageY};
this.$refs.graceReload.touchend(touchObj);
},
// 下拉刷新函数 ( 请根据项目需要自行编写代码 )
reload:function(){
console.log('刷新函数执行......');
// 刷新完毕后关闭刷新
setTimeout(()=>{
this.$refs.graceReload.endReload();
}, 2000);
}
},
components:{gracePage, graceReload}
}
</script>
<style>
</style>
<template>
<gracePage :customHeader="false" :flexVal="1">
<view slot="gBody" class="grace-flex-v1" ref="gBody">
<view class="grace-margin-top grace-body">
<text class="grace-title">刷新演示</text>
</view>
<scroll-view scroll-y="true" :style="{height:scrollHeight+'px'}"
@touchstart="touchstart" @touchmove="touchmove" @touchend="touchend" @scroll="scroll">
<graceReload @reload="reload" ref="graceReload" width="700rpx" marginLeft="25rpx"></graceReload>
<view style="background-color:#F8F8F8; height:2000px; width:700rpx; margin-left:25rpx;">
<text class="grace-text grace-text-center" style="line-height:100px;">滚动区域,请根据需求放置您的布局。</text>
</view>
</scroll-view>
</view>
</gracePage>
</template>
<script>
import gracePage from "../../graceUI/weexComponents/gracePage.nvue";
import graceReload from '../../graceUI/weexComponents/graceReload.nvue';
const dom = weex.requireModule('dom');
export default {
data() {
return {
scrollTop : 0,
scrollHeight : 600
}
},
onReady:function(){
setTimeout(()=>{
// 获取顶部内容高度
var el = this.$refs.gBody;
dom.getComponentRect(el, (res) => {
this.scrollHeight = res.size.height - 60;
});
},1000);
},
methods:{
scroll:function(e){
this.scrollTop = e.detail.scrollTop;
},
touchstart : function (e){
var touchObj = {scrollTop :this.scrollTop, moveY : e.changedTouches[0].pageY};
this.$refs.graceReload.touchstart(touchObj);
},
touchmove : function (e) {
var touchObj = {scrollTop :this.scrollTop, moveY : e.changedTouches[0].pageY};
this.$refs.graceReload.touchmove(touchObj);
},
touchend : function (e) {
var touchObj = {scrollTop :this.scrollTop, moveY : e.changedTouches[0].pageY};
this.$refs.graceReload.touchend(touchObj);
},
// 下拉刷新函数 ( 请根据项目需要自行编写代码 )
reload:function(){
console.log('刷新函数执行......');
// 刷新完毕后关闭刷新
setTimeout(()=>{
this.$refs.graceReload.endReload();
}, 2000);
}
},
components:{gracePage, graceReload}
}
</script>
<style>
</style>
.wxml
<gracePage customHeader="{{false}}">
<view slot="gBody" class="grace-flex-v1" id="gBody">
<view class="grace-margin-top grace-body">
<text class="grace-title">刷新演示</text>
</view>
<scroll-view scroll-y="true" style="height:{{mainHeight+'px'}};" bindtouchstart="touchstart"
bindtouchmove="touchmove" bindtouchend="touchend" bindscroll="scroll">
<view class="grace-text-center" style="background-color:#F8F8F8; height:2000px; width:700rpx; margin-left:25rpx;">
<graceReload bind:reload="reload" id="graceReload" width="700rpx"></graceReload>
<text class="grace-text" style="line-height:100px;">滚动区域,请根据需求放置您的布局。</text>
</view>
</scroll-view>
</view>
</gracePage>.js
Page({
data:{
mainHeight: 600,
// 滚动区域的滚动值
scrollTop:0
},
onReady: function () {
setTimeout(() => {
wx.createSelectorQuery().select('#gBody').fields(
{ size: true }, (res) => {
this.setData({ mainHeight: res.height - 60});
}
).exec();
}, 1000);
},
scroll: function (e) {
this.data.scrollTop = e.detail.scrollTop;
this.setData({ scrollTop: this.data.scrollTop });
},
touchstart: function (e) {
var touchObj = { scrollTop: this.data.scrollTop, moveY: e.changedTouches[0].pageY };
this.selectComponent("#graceReload").touchstart(touchObj);
},
touchmove: function (e) {
var touchObj = { scrollTop: this.data.scrollTop, moveY: e.changedTouches[0].pageY };
this.selectComponent("#graceReload").touchmove(touchObj);
},
touchend: function (e) {
var touchObj = { scrollTop: this.data.scrollTop, moveY: e.changedTouches[0].pageY };
this.selectComponent("#graceReload").touchend(touchObj);
},
// 下拉刷新函数 ( 请根据项目需要自行编写代码 )
reload: function () {
console.log('刷新函数执行......');
// 刷新完毕后关闭刷新
setTimeout(() => {
this.selectComponent("#graceReload").endReload();
}, 2000);
}
}).json
{
"usingComponents": {
"gracePage" : "../../graceUI/components/gracePage",
"graceReload": "../../graceUI/components/graceReload"
}
}