文档管理中心
API参考快应用组件refresh-header(1090+)

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:当前是否处理刷新状态。(刷新状态下也可移动)

示例代码

收起
自动换行
深色代码主题
复制
  1. <import name="movie-item" src="../Common/SR399/movie-item.ux"></import>
  2. <template>
  3. <div class="root">
  4. <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">
  5. <refresh-header class="header" spinnerstyle="behind" translationwithcontent="false" @move="headerMove" autorefresh="true">
  6. <progress class="circular" type="circular" style="color: #fff" />
  7. </refresh-header>
  8. <!-- content -->
  9. <div class="content-list">
  10. <list class="list" id="movie-list" @scrollbottom="loadMoreData">
  11. <list-item type="listItem" for="{{dataList}}" tid="$item.id">
  12. <movie-item item="{{$item}}"></movie-item>
  13. </list-item>
  14. </list>
  15. </div>
  16. </refresh2>
  17. </div>
  18. </template>
  19. <style>
  20. .root {
  21. align-items: center;
  22. }
  23. .list {
  24. padding-left: 16px;
  25. padding-right: 16px;
  26. }
  27. .content-list {
  28. background-color: #D0D0D0;
  29. flex-direction: column;
  30. align-items: center;
  31. }
  32. .container {
  33. height: 100%;
  34. width: 100%;
  35. }
  36. .header {
  37. height: 175%;
  38. width: 100%;
  39. background-color: #800000;
  40. justify-content: center;
  41. align-items: center;
  42. }
  43. .content {
  44. width: 100%;
  45. height: 100%;
  46. background-color: #ffffff;
  47. }
  48. .txt {
  49. width: 100%;
  50. height: 100px;
  51. }
  52. .circular {
  53. width: 100%;
  54. height: 75px;
  55. }
  56. .footer {
  57. height: 100px;
  58. width: 100%;
  59. background-color: #008000;
  60. justify-content: center;
  61. align-items: center;
  62. }
  63. .loading {
  64. color: #ffffff;
  65. }
  66. </style>
  67. <script>
  68. import api from '../Common/SR399/service.js'
  69. const LOAD_MORE_INITIAL_INDEX = 1;
  70. const LOAD_MORE_INCREASE_THRESHOLD = 1;
  71. module.exports = {
  72. backgroundColor: "#ffffff",
  73. progressColor: "#ffffff",
  74. data: {
  75. dataList: [],
  76. currentTotalPages: Number.MAX_SAFE_INTEGER,
  77. currentPage: LOAD_MORE_INITIAL_INDEX,
  78. },
  79. computed: {
  80. loadMoreEnabled: {
  81. get() {
  82. return this.currentPage < this.currentTotalPages
  83. }
  84. },
  85. },
  86. onReady(options) {
  87. this.getData(LOAD_MORE_INITIAL_INDEX)
  88. },
  89. // Service calls
  90. loadMoreData: function () {
  91. if (this.loadMoreEnabled) {
  92. this.getData(this.currentPage + LOAD_MORE_INCREASE_THRESHOLD)
  93. }
  94. },
  95. clearData: function () {
  96. this.dataList = []
  97. },
  98. getData: function (page) {
  99. this.currentPage = page
  100. var app = this
  101. api.callGet({ page: page }, function (data) {
  102. if (page > LOAD_MORE_INCREASE_THRESHOLD) {
  103. data.results.forEach(movie => {
  104. app.dataList.push(movie)
  105. });
  106. } else {
  107. app.dataList = data.results
  108. }
  109. app.currentTotalPages = data.total_pages
  110. })
  111. },
  112. pullDownRefresh: function () {
  113. console.log("pullDownRefresh");
  114. console.log("pulldownrefreshing:" + this.$element('refresh').pulldownrefreshing)
  115. console.log("pulluprefreshing:" + this.$element('refresh').pulluprefreshing)
  116. this.$element('refresh').startPullDownRefresh()
  117. setTimeout(() => {
  118. this.clearData()
  119. this.getData(LOAD_MORE_INITIAL_INDEX)
  120. this.finishPullDownRefresh()
  121. }, 1500);
  122. },
  123. pullUpRefresh: function () {
  124. console.log("pullUpRefresh");
  125. console.log("pulldownrefreshing:" + this.$element('refresh').pulldownrefreshing)
  126. console.log("pulluprefreshing:" + this.$element('refresh').pulluprefreshing)
  127. this.$element('refresh').startPullUpRefresh();
  128. setTimeout(() => {
  129. this.finishPullUpRefresh()
  130. }, 1500);
  131. },
  132. refresh: function (e) {
  133. console.log("refresh:" + e.refreshing);
  134. },
  135. headerMove: function (params) {
  136. console.log("headermove - scrollY:" + params.scrollY + " percent:" + params.percent + " isDrag:" + params.isDrag + " refreshing:" + params.refreshing);
  137. },
  138. footerMove: function (params) {
  139. console.log("footermove - scrollY:" + params.scrollY + " percent:" + params.percent + " isDrag:" + params.isDrag + " refreshing:" + params.refreshing)
  140. },
  141. finishPullDownRefresh: function () {
  142. console.log("finishPullDownRefresh")
  143. this.$element('refresh').stopPullDownRefresh()
  144. },
  145. finishPullUpRefresh: function () {
  146. console.log("finishPullUpRefresh")
  147. this.$element('refresh').stopPullUpRefresh()
  148. },
  149. }
  150. </script>

版本更新说明

展开

版本

发布日期

描述

1090

2022-05-19

第一次正式发布。

在 API参考 中进行搜索
请输入您想要搜索的关键词