目录

refresh-header(1090+)

概述

refresh2下拉刷新顶部容器。

使用限制

限制条件

说明

适用终端

手机、平板、智慧屏、车机

适用区域

全球

子组件

支持。

属性

除了支持 通用属性 以外,还支持如下属性。

名称

类型

默认值

是否必填

描述

dragRate

number

0.5

否

拖动率,取值等于header移动距离除以手势移动距离。

triggerRatio

number

0.7

否

移动率,用于计算触发刷新时的header移动距离。header移动距离等于该属性取值乘以header高度。triggerRatio优先级低于triggerSize。

triggerSize

number

0

否

触发刷新时的移动距离,取值大于0时生效,优先级高于triggerRatio。

单位:px

maxdragratio

number

1

否

header可移动的最大距离比率,该取值乘以header高度等于最大移动距离。

maxdragsize

number

0

否

header可移动最大距离,取值大于0时有效,优先级高于maxdragratio。单位:px

refreshdisplayratio

number

0.7

否

刷新时header的展示高度比率,该取值乘以header高度等于展示高度。默认值为0.7。

refreshdisplaysize

number

0

否

刷新时header的展示高度,取值大于0时有效,优先级高于refreshdisplayratio。

单位:px

spinnerstyle

string

translation

否

header的展示风格,支持如下三种类型:

  • translation:header移动时,内容跟随移动
  • front:header展示在内容上方,内容不跟随移动
  • behind:header展示在内容下方,内容不跟随移动

autorefresh

boolean

false

否

滑向顶部时,是否自动加载。

translationwithcontent

boolean

false

否

默认取值为false,表示刷新时展示header。

样式

支持 通用样式 。

事件

除了支持 通用事件 以外,还支持如下事件。

名称

参数

描述

move

{scrollY:number,percent:number,isDrag:boolean,refreshing:boolean}

header移动参数回调。

scrollY:header相对初始位置的移动距离。当下拉header时,该值为正。

percent:header移动距离/触发刷新的距离。当percent大于或等于1f(宽度为1的浮点数)时,触发刷新。

isDrag:是否可通过手势拖拽。

refreshing:当前是否处理刷新状态。(刷新状态下也可移动)

示例代码

<import name="movie-item" src="../Common/SR399/movie-item.ux"></import>
<template>
  <div class="root">
    <refresh2 id="refresh" style="background-color:{{backgroundColor}};progress-color:{{progressColor}};" offset="132px" animationduration="300" class="container" reboundable="true" type="auto" @refresh="refresh" @pulluprefresh="pullUpRefresh" @pulldownrefresh="pullDownRefresh" gesture="true" enablepulldown="true" enablepullup="true">
      <refresh-header class="header" spinnerstyle="behind" translationwithcontent="false" @move="headerMove" autorefresh="true">
        <progress class="circular" type="circular" style="color: #fff" />
      </refresh-header>
      <!-- content -->
      <div class="content-list">
        <list class="list" id="movie-list" @scrollbottom="loadMoreData">
          <list-item type="listItem" for="{{dataList}}" tid="$item.id">
            <movie-item item="{{$item}}"></movie-item>
          </list-item>
        </list>
      </div>
    </refresh2>
  </div>
</template>
<style>
  .root {
    align-items: center;
  }
  .list {
    padding-left: 16px;
    padding-right: 16px;
  }
  .content-list {
    background-color: #D0D0D0;
    flex-direction: column;
    align-items: center;
  }
  .container {
    height: 100%;
    width: 100%;
  }
  .header {
    height: 175%;
    width: 100%;
    background-color: #800000;
    justify-content: center;
    align-items: center;
  }
  .content {
    width: 100%;
    height: 100%;
    background-color: #ffffff;
  }
  .txt {
    width: 100%;
    height: 100px;
  }
  .circular {
    width: 100%;
    height: 75px;
  }
  .footer {
    height: 100px;
    width: 100%;
    background-color: #008000;
    justify-content: center;
    align-items: center;
  }
  .loading {
    color: #ffffff;
  }
</style>
<script>
import api from '../Common/SR399/service.js'
  const LOAD_MORE_INITIAL_INDEX = 1;
  const LOAD_MORE_INCREASE_THRESHOLD = 1;
  module.exports = {
    backgroundColor: "#ffffff",
    progressColor: "#ffffff",
    data: {
      dataList: [],
      currentTotalPages: Number.MAX_SAFE_INTEGER,
      currentPage: LOAD_MORE_INITIAL_INDEX,
    },
    computed: {
      loadMoreEnabled: {
        get() {
          return this.currentPage < this.currentTotalPages
        }
      },
    },
    onReady(options) {
      this.getData(LOAD_MORE_INITIAL_INDEX)
    },
    // Service calls
    loadMoreData: function () {
      if (this.loadMoreEnabled) {
        this.getData(this.currentPage + LOAD_MORE_INCREASE_THRESHOLD)
      }
    },
    clearData: function () {
      this.dataList = []
    },
    getData: function (page) {
      this.currentPage = page
      var app = this
      api.callGet({ page: page }, function (data) {
        if (page > LOAD_MORE_INCREASE_THRESHOLD) {
          data.results.forEach(movie => {
            app.dataList.push(movie)
          });
        } else {
          app.dataList = data.results
        }
        app.currentTotalPages = data.total_pages
      })
    },
    pullDownRefresh: function () {
      console.log("pullDownRefresh");
      console.log("pulldownrefreshing:" + this.$element('refresh').pulldownrefreshing)
      console.log("pulluprefreshing:" + this.$element('refresh').pulluprefreshing)
      this.$element('refresh').startPullDownRefresh()
      setTimeout(() => {
        this.clearData()
        this.getData(LOAD_MORE_INITIAL_INDEX)
        this.finishPullDownRefresh()
      }, 1500);
    },
    pullUpRefresh: function () {
      console.log("pullUpRefresh");
      console.log("pulldownrefreshing:" + this.$element('refresh').pulldownrefreshing)
      console.log("pulluprefreshing:" + this.$element('refresh').pulluprefreshing)
      this.$element('refresh').startPullUpRefresh();
      setTimeout(() => {
        this.finishPullUpRefresh()
      }, 1500);
    },
    refresh: function (e) {
      console.log("refresh:" + e.refreshing);
    },
    headerMove: function (params) {
      console.log("headermove - scrollY:" + params.scrollY + " percent:" + params.percent + " isDrag:" + params.isDrag + " refreshing:" + params.refreshing);
    },
    footerMove: function (params) {
      console.log("footermove - scrollY:" + params.scrollY + " percent:" + params.percent + " isDrag:" + params.isDrag + " refreshing:" + params.refreshing)
    },
    finishPullDownRefresh: function () {
      console.log("finishPullDownRefresh")
      this.$element('refresh').stopPullDownRefresh()
    },
    finishPullUpRefresh: function () {
      console.log("finishPullUpRefresh")
      this.$element('refresh').stopPullUpRefresh()
    },
  }
</script>

版本更新说明

版本

发布日期

描述

1090

2022-05-19

第一次正式发布。