Skip to content

Commit

Permalink
fix(list): 组件事件不被触发 jd-opensource#1607
Browse files Browse the repository at this point in the history
  • Loading branch information
szg2008 committed Sep 29, 2022
1 parent 01faac5 commit 64088fc
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/packages/__VUE/list/doc.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ body {
|--------------|----------------------------------|--------|------------------|
| height | The height of the list item | Number | `50` |
| 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

Expand Down
2 changes: 1 addition & 1 deletion src/packages/__VUE/list/doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ body {
|--------------|----------------------------------|--------|------------------|
| height | 列表项的高度 | Number | `50` |
| list-data | 列表数据 | any[] | `[]` |
| container-height `v3.1.19` | 容器高度 | Number | `可视区高度` |
| container-height `v3.1.19` | 容器高度(最大值不能超过可视区) | Number | `可视区高度` |

### Slot

Expand Down
1 change: 0 additions & 1 deletion src/packages/__VUE/list/index.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.nut-list {
width: 100%;
height: 100%;
overflow: scroll;
position: relative;
-webkit-overflow-scrolling: touch;
Expand Down
12 changes: 9 additions & 3 deletions src/packages/__VUE/list/index.taro.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<scroll-view
:class="classes"
:scroll-y="true"
:style="{ height: containerHeight + 'px' }"
:style="{ height: `${getContainerHeight}px` }"
scroll-top="0"
@scroll="handleScrollEvent"
ref="list"
Expand All @@ -20,6 +20,7 @@ import { reactive, toRefs, computed, ref, Ref, watch } from 'vue';
import { createComponent } from '@/packages/utils/create';
import Taro from '@tarojs/taro';
const { componentName, create } = createComponent('list');
const clientHeight = Taro.getSystemInfoSync().windowHeight;
export default create({
props: {
height: {
Expand All @@ -34,7 +35,7 @@ export default create({
},
containerHeight: {
type: [Number],
default: Taro.getSystemInfoSync().windowHeight || 667
default: clientHeight || 667
}
},
emits: ['scroll', 'scroll-bottom'],
Expand All @@ -47,8 +48,12 @@ export default create({
list: props.listData.slice()
});
const getContainerHeight = computed(() => {
return Math.min(props.containerHeight, clientHeight);
});
const visibleCount = computed(() => {
return Math.ceil(props.containerHeight / props.height);
return Math.ceil(getContainerHeight.value / props.height);
});
const end = computed(() => {
Expand Down Expand Up @@ -98,6 +103,7 @@ export default create({
listHeight,
visibleData,
classes,
getContainerHeight,
handleScrollEvent
};
}
Expand Down
14 changes: 10 additions & 4 deletions src/packages/__VUE/list/index.vue
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<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-container" :style="{ transform: getTransform }">
<div class="nut-list-item" :style="{ height: height + 'px' }" v-for="(item, index) in visibleData" :key="item">
<slot :item="item" :index="index"></slot>
</div>
</div>
</view>
</div>
</template>
<script lang="ts">
import { reactive, toRefs, computed, ref, Ref, watch } from 'vue';
import { createComponent } from '@/packages/utils/create';
const { componentName, create } = createComponent('list');
const clientHeight = document.documentElement.clientHeight || document.body.clientHeight;
export default create({
props: {
height: {
Expand All @@ -26,7 +27,7 @@ export default create({
},
containerHeight: {
type: [Number],
default: document.documentElement.clientHeight || document.body.clientHeight || 667
default: clientHeight || 667
}
},
emits: ['scroll', 'scroll-bottom'],
Expand All @@ -39,8 +40,12 @@ export default create({
list: props.listData.slice()
});
const getContainerHeight = computed(() => {
return Math.min(props.containerHeight, clientHeight);
});
const visibleCount = computed(() => {
return Math.ceil(props.containerHeight / props.height);
return Math.ceil(getContainerHeight.value / props.height);
});
const end = computed(() => {
Expand Down Expand Up @@ -90,6 +95,7 @@ export default create({
listHeight,
visibleData,
classes,
getContainerHeight,
handleScrollEvent
};
}
Expand Down
3 changes: 0 additions & 3 deletions src/sites/mobile-taro/vue/src/exhibition/pages/list/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ export default defineComponent({
</script>
<style lang="scss">
.list-demo {
.nut-cell {
height: 100%;
}
.list-item {
display: flex;
align-items: center;
Expand Down

0 comments on commit 64088fc

Please sign in to comment.