list-view.uvue 14.2 KB
Newer Older
1
<script>
2
  type ScrollEventTest = {
DCloud-WZF's avatar
DCloud-WZF 已提交
3 4 5 6
    type : string;
    target : UniElement | null;
    currentTarget : UniElement | null;
    direction ?: string
7
  }
雪洛's avatar
雪洛 已提交
8
  import { ItemType } from '@/components/enum-data/enum-data'
shutao-dc's avatar
shutao-dc 已提交
9 10 11 12 13 14
  export default {
    data() {
      return {
        refresher_triggered_boolean: false,
        refresher_enabled_boolean: false,
        scroll_with_animation_boolean: false,
15
        show_scrollbar_boolean: false,
16
        bounces_boolean: true,
shutao-dc's avatar
shutao-dc 已提交
17 18
        scroll_y_boolean: true,
        scroll_x_boolean: false,
19
        scroll_direction: "vertical",
shutao-dc's avatar
shutao-dc 已提交
20 21 22 23 24
        upper_threshold_input: 50,
        lower_threshold_input: 50,
        scroll_top_input: 0,
        scroll_left_input: 0,
        refresher_background_input: "#FFF",
shutao-dc's avatar
shutao-dc 已提交
25 26
        scrollData: [] as Array<string>,
        size_enum: [{ "value": 0, "name": "item---0" }, { "value": 3, "name": "item---3" }] as ItemType[],
shutao-dc's avatar
shutao-dc 已提交
27
        scrollIntoView: "",
shutao-dc's avatar
shutao-dc 已提交
28 29 30 31
        refresherrefresh: false,
        refresher_default_style_input: "black",
        text: ['继续下拉执行刷新', '释放立即刷新', '刷新中', ""],
        state: 3,
32 33
        reset: true,
        // 自动化测试
DCloud-WZF's avatar
DCloud-WZF 已提交
34 35 36 37 38
        isScrollTest: '',
        isScrolltolowerTest: '',
        isScrolltoupperTest: '',
        scrollDetailTest: null as UniScrollEventDetail | null,
        scrollEndDetailTest: null as UniScrollEventDetail | null,
shutao-dc's avatar
shutao-dc 已提交
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
      }
    },
    onLoad() {
      let lists : Array<string> = []
      for (let i = 0; i < 10; i++) {
        lists.push("item---" + i)
      }
      this.scrollData = lists
    },
    methods: {
      list_view_click() { console.log("组件被点击时触发") },
      list_view_touchstart() { console.log("手指触摸动作开始") },
      list_view_touchmove() { console.log("手指触摸后移动") },
      list_view_touchcancel() { console.log("手指触摸动作被打断,如来电提醒,弹窗") },
      list_view_touchend() { console.log("手指触摸动作结束") },
      list_view_tap() { console.log("手指触摸后马上离开") },
      list_view_longpress() { console.log("如果一个组件被绑定了 longpress 事件,那么当用户长按这个组件时,该事件将会被触发。") },
shutao-dc's avatar
shutao-dc 已提交
56 57
      list_view_refresherpulling(e : RefresherEvent) {
        console.log("下拉刷新控件被下拉")
H
hdx 已提交
58 59 60 61 62 63
        if (this.reset) {
          if (e.detail.dy > 45) {
            this.state = 1
          } else {
            this.state = 0
          }
shutao-dc's avatar
shutao-dc 已提交
64 65
        }
      },
shutao-dc's avatar
shutao-dc 已提交
66
      list_view_refresherrefresh() {
shutao-dc's avatar
shutao-dc 已提交
67
        console.log("下拉刷新被触发 ")
shutao-dc's avatar
shutao-dc 已提交
68
        this.refresherrefresh = true
shutao-dc's avatar
shutao-dc 已提交
69
        this.refresher_triggered_boolean = true
shutao-dc's avatar
shutao-dc 已提交
70 71
        this.state = 2
        this.reset = false;
72
        setTimeout(() => {
H
hdx 已提交
73
          this.refresher_triggered_boolean = false
shutao-dc's avatar
shutao-dc 已提交
74 75
        }, 1500)
      },
shutao-dc's avatar
shutao-dc 已提交
76 77
      list_view_refresherrestore() {
        this.refresherrefresh = false
shutao-dc's avatar
shutao-dc 已提交
78 79
        this.state = 3
        this.reset = true
shutao-dc's avatar
shutao-dc 已提交
80
        console.log("下拉刷新被复位")
shutao-dc's avatar
shutao-dc 已提交
81
      },
shutao-dc's avatar
shutao-dc 已提交
82
      list_view_refresherabort() { console.log("下拉刷新被中止") },
83 84 85
      list_view_scrolltoupper(e : UniScrollToUpperEvent) {
        console.log("滚动到顶部/左边,会触发 scrolltoupper 事件  direction=" + e.detail.direction)
        this.checkEventTest({
DCloud-WZF's avatar
DCloud-WZF 已提交
86 87 88 89 90
          type: e.type,
          target: e.target,
          currentTarget: e.currentTarget,
          direction: e.detail.direction,
        } as ScrollEventTest, 'scrolltoupper')
91 92 93 94
      },
      list_view_scrolltolower(e : UniScrollToLowerEvent) {
        console.log("滚动到底部/右边,会触发 scrolltolower 事件  direction=" + e.detail.direction)
        this.checkEventTest({
DCloud-WZF's avatar
DCloud-WZF 已提交
95 96 97 98 99
          type: e.type,
          target: e.target,
          currentTarget: e.currentTarget,
          direction: e.detail.direction,
        } as ScrollEventTest, 'scrolltolower')
100
      },
DCloud-WZF's avatar
DCloud-WZF 已提交
101
      list_view_scroll(e : UniScrollEvent) {
102 103 104
        console.log("滚动时触发,event.detail = {scrollLeft, scrollTop, scrollHeight, scrollWidth, deltaX, deltaY}")
        this.scrollDetailTest = e.detail
        this.checkEventTest({
DCloud-WZF's avatar
DCloud-WZF 已提交
105 106 107 108
          type: e.type,
          target: e.target,
          currentTarget: e.currentTarget
        } as ScrollEventTest, 'scroll')
109
      },
DCloud-WZF's avatar
DCloud-WZF 已提交
110 111
      list_view_scrollend(e : UniScrollEvent) {
        console.log("滚动结束时触发", e.detail)
112 113
        this.scrollEndDetailTest = e.detail
        this.checkEventTest({
DCloud-WZF's avatar
DCloud-WZF 已提交
114 115 116 117
          type: e.type,
          target: e.target,
          currentTarget: e.currentTarget
        } as ScrollEventTest, 'scrollend')
118
      },
shutao-dc's avatar
shutao-dc 已提交
119 120 121 122 123 124 125 126 127 128 129
      list_item_click() { console.log("list-item组件被点击时触发") },
      list_item_touchstart() { console.log("手指触摸list-item组件动作开始") },
      list_item_touchmove() { console.log("手指触摸list-item组件后移动") },
      list_item_touchcancel() { console.log("手指触摸list-item组件动作被打断,如来电提醒,弹窗") },
      list_item_touchend() { console.log("手指触摸list-item组件动作结束") },
      list_item_tap() { console.log("手指触摸list-item组件后马上离开") },
      list_item_longpress() { console.log("list-item组件被绑定了 longpress 事件,那么当用户长按这个组件时,该事件将会被触发。") },
      change_refresher_triggered_boolean(checked : boolean) { this.refresher_triggered_boolean = checked },
      change_refresher_enabled_boolean(checked : boolean) { this.refresher_enabled_boolean = checked },
      change_scroll_with_animation_boolean(checked : boolean) { this.scroll_with_animation_boolean = checked },
      change_show_scrollbar_boolean(checked : boolean) { this.show_scrollbar_boolean = checked },
130 131 132
      change_bounces_boolean(checked : boolean) { this.bounces_boolean = checked },
      change_scroll_y_boolean(checked : boolean) {
        this.scroll_y_boolean = checked
133
        this.change_scroll_direction()
134 135 136
      },
      change_scroll_x_boolean(checked : boolean) {
        this.scroll_x_boolean = checked
137
        this.change_scroll_direction()
138 139
      },
      change_scroll_direction() {
H
hdx 已提交
140
        if (this.scroll_y_boolean && this.scroll_x_boolean || this.scroll_y_boolean) {
141
          this.scroll_direction = "vertical"
H
hdx 已提交
142
        } else if (!this.scroll_y_boolean && !this.scroll_x_boolean) {
143
          this.scroll_direction = "none"
H
hdx 已提交
144
        } else if (!this.scroll_y_boolean && this.scroll_x_boolean) {
145
          this.scroll_direction = "horizontal"
146 147
        }
      },
shutao-dc's avatar
shutao-dc 已提交
148 149 150 151
      confirm_upper_threshold_input(value : number) { this.upper_threshold_input = value },
      confirm_lower_threshold_input(value : number) { this.lower_threshold_input = value },
      confirm_scroll_top_input(value : number) { this.scroll_top_input = value },
      confirm_scroll_left_input(value : number) { this.scroll_left_input = value },
shutao-dc's avatar
shutao-dc 已提交
152
      confirm_refresher_background_input(value : string) { this.refresher_background_input = value },
H
hdx 已提交
153
      item_change_size_enum(index : number) { this.scrollIntoView = "item---" + index },
154
      // 自动化测试专用(由于事件event参数对象中存在循环引用,在ios端JSON.stringify报错,自动化测试无法page.data获取)
DCloud-WZF's avatar
DCloud-WZF 已提交
155
      checkEventTest(e : ScrollEventTest, eventName : String) {
156 157
        const isPass = e.type === eventName && e.target instanceof UniElement && e.currentTarget instanceof UniElement;
        const result = isPass ? `${eventName}:Success` : `${eventName}:Fail`;
DCloud-WZF's avatar
DCloud-WZF 已提交
158
        switch (eventName) {
159 160 161 162
          case 'scroll':
            this.isScrollTest = result
            break;
          case 'scrolltolower':
DCloud-WZF's avatar
DCloud-WZF 已提交
163
            this.isScrolltolowerTest = result + `-${e.direction}`
164 165
            break;
          case 'scrolltoupper':
DCloud-WZF's avatar
DCloud-WZF 已提交
166
            this.isScrolltoupperTest = result + `-${e.direction}`
167 168 169 170 171
            break;
          default:
            break;
        }
      },
shutao-dc's avatar
shutao-dc 已提交
172
      //自动化测试例专用
H
hdx 已提交
173
      check_scroll_height() : Boolean {
DCloud-yyl's avatar
DCloud-yyl 已提交
174
        var listElement = this.$refs["listview"] as UniElement
H
hdx 已提交
175 176
        console.log("check_scroll_height--" + listElement.scrollHeight)
        if (listElement.scrollHeight > 2000) {
177 178 179
          return true
        }
        return false
shutao-dc's avatar
shutao-dc 已提交
180
      },
181
      //自动化测试例专用
H
hdx 已提交
182
      check_scroll_width() : Boolean {
DCloud-yyl's avatar
DCloud-yyl 已提交
183
        var listElement = this.$refs["listview"] as UniElement
H
hdx 已提交
184 185
        console.log("check_scroll_width" + listElement.scrollWidth)
        if (listElement.scrollWidth > 2000) {
shutao-dc's avatar
shutao-dc 已提交
186
          return true
187 188
        }
        return false
shutao-dc's avatar
shutao-dc 已提交
189 190
      },
      change_refresher_style_boolean(checked : boolean) {
H
hdx 已提交
191
        if (checked) {
shutao-dc's avatar
shutao-dc 已提交
192 193 194 195
          this.refresher_default_style_input = "none"
        } else {
          this.refresher_default_style_input = "black"
        }
shutao-dc's avatar
shutao-dc 已提交
196
      }
shutao-dc's avatar
shutao-dc 已提交
197 198
    }
  }
199 200 201
</script>

<template>
shutao-dc's avatar
shutao-dc 已提交
202
  <view class="main">
H
hdx 已提交
203 204 205
    <list-view :direction="scroll_direction" :rebound="bounces_boolean" :upper-threshold="upper_threshold_input"
      :lower-threshold="lower_threshold_input" :scroll-top="scroll_top_input" :scroll-left="scroll_left_input"
      :show-scrollbar="show_scrollbar_boolean" :scroll-into-view="scrollIntoView"
shutao-dc's avatar
shutao-dc 已提交
206 207
      :scroll-with-animation="scroll_with_animation_boolean" :refresher-enabled="refresher_enabled_boolean"
      :refresher-background="refresher_background_input" :refresher-triggered="refresher_triggered_boolean"
H
hdx 已提交
208 209 210 211 212 213
      :refresher-default-style="refresher_default_style_input" @click="list_view_click"
      @touchstart="list_view_touchstart" @touchmove="list_view_touchmove" @touchcancel="list_view_touchcancel"
      @touchend="list_view_touchend" @tap="list_view_tap" @longpress="list_view_longpress"
      @refresherpulling="list_view_refresherpulling" @refresherrefresh="list_view_refresherrefresh"
      @refresherrestore="list_view_refresherrestore" @refresherabort="list_view_refresherabort"
      @scrolltoupper="list_view_scrolltoupper" ref="listview" @scrolltolower="list_view_scrolltolower"
214
      @scroll="list_view_scroll" @scrollend="list_view_scrollend" style="width:100%;" id="listview">
H
hdx 已提交
215 216 217
      <list-item v-for="key in scrollData" :key="key" :id="key" @click="list_item_click"
        @touchstart="list_item_touchstart" @touchmove="list_item_touchmove" @touchcancel="list_item_touchcancel"
        @touchend="list_item_touchend" @tap="list_item_tap" @longpress="list_item_longpress" class="list-item">
shutao-dc's avatar
shutao-dc 已提交
218 219
        <text>{{key}}</text>
      </list-item>
220
      <!-- #ifdef APP -->
shutao-dc's avatar
shutao-dc 已提交
221 222 223
      <list-item slot="refresher" class="refresh-box">
        <text class="tip-text">{{text[state]}}</text>
      </list-item>
224
      <!-- #endif -->
shutao-dc's avatar
shutao-dc 已提交
225 226
    </list-view>
  </view>
227

雪洛's avatar
雪洛 已提交
228
  <scroll-view style="flex:1" direction="vertical">
A
Anne_LXM 已提交
229
    <view class="content">
230
      <!-- #ifdef APP -->
shutao-dc's avatar
shutao-dc 已提交
231 232
      <boolean-data :defaultValue="false" title="设置当前下拉刷新状态,true 表示下拉刷新已经被触发,false 表示下拉刷新未被触发"
        @change="change_refresher_triggered_boolean"></boolean-data>
shutao-dc's avatar
shutao-dc 已提交
233
      <boolean-data :defaultValue="false" title="开启下拉刷新" @change="change_refresher_enabled_boolean"></boolean-data>
shutao-dc's avatar
shutao-dc 已提交
234
      <boolean-data :defaultValue="false" title="开启自定义样式" @change="change_refresher_style_boolean"></boolean-data>
235
      <!-- #endif -->
shutao-dc's avatar
shutao-dc 已提交
236 237
      <boolean-data :defaultValue="false" title="是否在设置滚动条位置时使用滚动动画,设置false没有滚动动画"
        @change="change_scroll_with_animation_boolean"></boolean-data>
238
      <boolean-data :defaultValue="false" title="控制是否出现滚动条" @change="change_show_scrollbar_boolean"></boolean-data>
239
      <!-- #ifdef APP -->
240
      <boolean-data :defaultValue="true" title="控制是否回弹效果" @change="change_bounces_boolean"></boolean-data>
241
      <!-- #endif -->
shutao-dc's avatar
shutao-dc 已提交
242
      <boolean-data :defaultValue="true" title="允许纵向滚动" @change="change_scroll_y_boolean"></boolean-data>
243
      <!-- #ifdef APP -->
shutao-dc's avatar
shutao-dc 已提交
244
      <boolean-data :defaultValue="false" title="允许横向滚动" @change="change_scroll_x_boolean"></boolean-data>
245
      <!-- #endif -->
shutao-dc's avatar
shutao-dc 已提交
246 247 248 249 250
      <input-data defaultValue="50" title="距顶部/左边多远时(单位px),触发 scrolltoupper 事件" type="number"
        @confirm="confirm_upper_threshold_input"></input-data>
      <input-data defaultValue="50" title="距底部/右边多远时(单位px),触发 scrolltolower 事件" type="number"
        @confirm="confirm_lower_threshold_input"></input-data>
      <input-data defaultValue="0" title="设置竖向滚动条位置" type="number" @confirm="confirm_scroll_top_input"></input-data>
251
      <!-- #ifdef APP -->
shutao-dc's avatar
shutao-dc 已提交
252
      <input-data defaultValue="0" title="设置横向滚动条位置" type="number" @confirm="confirm_scroll_left_input"></input-data>
shutao-dc's avatar
shutao-dc 已提交
253
      <input-data defaultValue="#FFF" title="设置下拉刷新区域背景颜色" type="text"
shutao-dc's avatar
shutao-dc 已提交
254
        @confirm="confirm_refresher_background_input"></input-data>
shutao-dc's avatar
shutao-dc 已提交
255
      <enum-data :items="size_enum" title="通过id位置跳转" @change="item_change_size_enum"></enum-data>
256
      <navigator url="/pages/component/list-view/list-view-refresh">
shutao-dc's avatar
shutao-dc 已提交
257 258 259 260
        <button type="primary" class="button">
          list-view 下拉刷新
        </button>
      </navigator>
261
      <!-- #endif -->
262
      <navigator url="/pages/component/list-view/list-view-multiplex">
A
Anne_LXM 已提交
263
        <button type="primary" class="button">
264 265 266
          list-view 对list-item复用测试
        </button>
      </navigator>
267
      <navigator url="/pages/component/list-view/list-view-multiplex-input">
268 269 270 271
        <button type="primary" class="button">
          list-view 复用测试(item中嵌入input)
        </button>
      </navigator>
272
      <navigator url="/pages/component/list-view/list-view-multiplex-video">
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
273 274 275 276
        <button type="primary" class="button">
          list-view 复用测试(item中嵌入video)
        </button>
      </navigator>
277
      <navigator url="/pages/component/list-view/list-view-children-in-slot">
278 279 280 281
        <button type="primary" class="button">
          list-view 测试插槽中子组件增删
        </button>
      </navigator>
shutao-dc's avatar
shutao-dc 已提交
282 283
    </view>
  </scroll-view>
284 285 286
</template>

<style>
shutao-dc's avatar
shutao-dc 已提交
287
  .main {
288
    max-height: 250px;
H
hdx 已提交
289
    padding: 5px 0;
shutao-dc's avatar
shutao-dc 已提交
290 291 292 293
    border-bottom: 1px solid rgba(0, 0, 0, .06);
    flex-direction: row;
    justify-content: center;
  }
294

shutao-dc's avatar
shutao-dc 已提交
295
  .main .list-item {
296
    width: 100%;
297
    height: 250px;
shutao-dc's avatar
shutao-dc 已提交
298 299 300 301 302
    border: 1px solid #666;
    background-color: #66ccff;
    align-items: center;
    justify-content: center;
  }
303

shutao-dc's avatar
shutao-dc 已提交
304
  .tip-text {
H
hdx 已提交
305 306
    color: #888;
    font-size: 12px;
shutao-dc's avatar
shutao-dc 已提交
307
  }
308

shutao-dc's avatar
shutao-dc 已提交
309 310 311 312 313 314 315
  .refresh-box {
    justify-content: center;
    align-items: center;
    flex-direction: row;
    height: 45px;
    width: 100%;
  }
316

317
  .button {
H
hdx 已提交
318
    margin-top: 15px;
319
  }
320
</style>