Browse Source

fix(list): 组件事件不被触发 #1607

suzigang 3 years ago
parent
commit
64088fcfa7

+ 1 - 1
src/packages/__VUE/list/doc.en-US.md

@@ -98,7 +98,7 @@ body {
 |--------------|----------------------------------|--------|------------------|
 |--------------|----------------------------------|--------|------------------|
 | height         | The height of the list item               | Number | `50`                |
 | height         | The height of the list item               | Number | `50`                |
 | list-data         | List data               | any[] | `[]`                |
 | list-data         | List data               | any[] | `[]`                |
-| container-height `v3.1.19`        | Container height              | Number | `Visual area height`                |
+| container-height `v3.1.19`        | Container height(The maximum value cannot exceed the viewable area)              | Number | `Visual area height`                |
 
 
 ### Slot
 ### Slot
 
 

+ 1 - 1
src/packages/__VUE/list/doc.md

@@ -98,7 +98,7 @@ body {
 |--------------|----------------------------------|--------|------------------|
 |--------------|----------------------------------|--------|------------------|
 | height         | 列表项的高度               | Number | `50`                |
 | height         | 列表项的高度               | Number | `50`                |
 | list-data         | 列表数据               | any[] | `[]`                |
 | list-data         | 列表数据               | any[] | `[]`                |
-| container-height `v3.1.19`        | 容器高度              | Number | `可视区高度`                |
+| container-height `v3.1.19`        | 容器高度(最大值不能超过可视区)              | Number | `可视区高度`                |
 
 
 ### Slot
 ### Slot
 
 

+ 0 - 1
src/packages/__VUE/list/index.scss

@@ -1,6 +1,5 @@
 .nut-list {
 .nut-list {
   width: 100%;
   width: 100%;
-  height: 100%;
   overflow: scroll;
   overflow: scroll;
   position: relative;
   position: relative;
   -webkit-overflow-scrolling: touch;
   -webkit-overflow-scrolling: touch;

+ 9 - 3
src/packages/__VUE/list/index.taro.vue

@@ -2,7 +2,7 @@
   <scroll-view
   <scroll-view
     :class="classes"
     :class="classes"
     :scroll-y="true"
     :scroll-y="true"
-    :style="{ height: containerHeight + 'px' }"
+    :style="{ height: `${getContainerHeight}px` }"
     scroll-top="0"
     scroll-top="0"
     @scroll="handleScrollEvent"
     @scroll="handleScrollEvent"
     ref="list"
     ref="list"
@@ -20,6 +20,7 @@ import { reactive, toRefs, computed, ref, Ref, watch } from 'vue';
 import { createComponent } from '@/packages/utils/create';
 import { createComponent } from '@/packages/utils/create';
 import Taro from '@tarojs/taro';
 import Taro from '@tarojs/taro';
 const { componentName, create } = createComponent('list');
 const { componentName, create } = createComponent('list');
+const clientHeight = Taro.getSystemInfoSync().windowHeight;
 export default create({
 export default create({
   props: {
   props: {
     height: {
     height: {
@@ -34,7 +35,7 @@ export default create({
     },
     },
     containerHeight: {
     containerHeight: {
       type: [Number],
       type: [Number],
-      default: Taro.getSystemInfoSync().windowHeight || 667
+      default: clientHeight || 667
     }
     }
   },
   },
   emits: ['scroll', 'scroll-bottom'],
   emits: ['scroll', 'scroll-bottom'],
@@ -47,8 +48,12 @@ export default create({
       list: props.listData.slice()
       list: props.listData.slice()
     });
     });
 
 
+    const getContainerHeight = computed(() => {
+      return Math.min(props.containerHeight, clientHeight);
+    });
+
     const visibleCount = computed(() => {
     const visibleCount = computed(() => {
-      return Math.ceil(props.containerHeight / props.height);
+      return Math.ceil(getContainerHeight.value / props.height);
     });
     });
 
 
     const end = computed(() => {
     const end = computed(() => {
@@ -98,6 +103,7 @@ export default create({
       listHeight,
       listHeight,
       visibleData,
       visibleData,
       classes,
       classes,
+      getContainerHeight,
       handleScrollEvent
       handleScrollEvent
     };
     };
   }
   }

+ 10 - 4
src/packages/__VUE/list/index.vue

@@ -1,17 +1,18 @@
 <template>
 <template>
-  <view :class="classes" @scroll.passive="handleScrollEvent" ref="list">
+  <div :class="classes" :style="{ height: `${getContainerHeight}px` }" @scroll.passive="handleScrollEvent" ref="list">
     <div class="nut-list-phantom" :style="{ height: listHeight + 'px' }"></div>
     <div class="nut-list-phantom" :style="{ height: listHeight + 'px' }"></div>
     <div class="nut-list-container" :style="{ transform: getTransform }">
     <div class="nut-list-container" :style="{ transform: getTransform }">
       <div class="nut-list-item" :style="{ height: height + 'px' }" v-for="(item, index) in visibleData" :key="item">
       <div class="nut-list-item" :style="{ height: height + 'px' }" v-for="(item, index) in visibleData" :key="item">
         <slot :item="item" :index="index"></slot>
         <slot :item="item" :index="index"></slot>
       </div>
       </div>
     </div>
     </div>
-  </view>
+  </div>
 </template>
 </template>
 <script lang="ts">
 <script lang="ts">
 import { reactive, toRefs, computed, ref, Ref, watch } from 'vue';
 import { reactive, toRefs, computed, ref, Ref, watch } from 'vue';
 import { createComponent } from '@/packages/utils/create';
 import { createComponent } from '@/packages/utils/create';
 const { componentName, create } = createComponent('list');
 const { componentName, create } = createComponent('list');
+const clientHeight = document.documentElement.clientHeight || document.body.clientHeight;
 export default create({
 export default create({
   props: {
   props: {
     height: {
     height: {
@@ -26,7 +27,7 @@ export default create({
     },
     },
     containerHeight: {
     containerHeight: {
       type: [Number],
       type: [Number],
-      default: document.documentElement.clientHeight || document.body.clientHeight || 667
+      default: clientHeight || 667
     }
     }
   },
   },
   emits: ['scroll', 'scroll-bottom'],
   emits: ['scroll', 'scroll-bottom'],
@@ -39,8 +40,12 @@ export default create({
       list: props.listData.slice()
       list: props.listData.slice()
     });
     });
 
 
+    const getContainerHeight = computed(() => {
+      return Math.min(props.containerHeight, clientHeight);
+    });
+
     const visibleCount = computed(() => {
     const visibleCount = computed(() => {
-      return Math.ceil(props.containerHeight / props.height);
+      return Math.ceil(getContainerHeight.value / props.height);
     });
     });
 
 
     const end = computed(() => {
     const end = computed(() => {
@@ -90,6 +95,7 @@ export default create({
       listHeight,
       listHeight,
       visibleData,
       visibleData,
       classes,
       classes,
+      getContainerHeight,
       handleScrollEvent
       handleScrollEvent
     };
     };
   }
   }

+ 0 - 3
src/sites/mobile-taro/vue/src/exhibition/pages/list/index.vue

@@ -37,9 +37,6 @@ export default defineComponent({
 </script>
 </script>
 <style lang="scss">
 <style lang="scss">
 .list-demo {
 .list-demo {
-  .nut-cell {
-    height: 100%;
-  }
   .list-item {
   .list-item {
     display: flex;
     display: flex;
     align-items: center;
     align-items: center;