|
@@ -0,0 +1,80 @@
|
|
|
+<template>
|
|
|
+ <el-select v-model="props.modelValue" placeholder="Select" ref="select" @visible-change="visible"
|
|
|
+ :teleported="false">
|
|
|
+ <el-option
|
|
|
+ v-for="item in listData"
|
|
|
+ :key="item.value"
|
|
|
+ :label="item.label"
|
|
|
+ :value="item.value"
|
|
|
+ >
|
|
|
+ <span>{{ item.label }}</span>
|
|
|
+ <span>{{ item.value }}</span>
|
|
|
+ </el-option>
|
|
|
+ </el-select>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup name='TestElSelectV2'>
|
|
|
+const props = defineProps({
|
|
|
+ modelValue: {
|
|
|
+ type: String,
|
|
|
+ default: ''
|
|
|
+ },
|
|
|
+ data: {
|
|
|
+ type: Array,
|
|
|
+ }
|
|
|
+})
|
|
|
+
|
|
|
+let select = $ref(null)
|
|
|
+
|
|
|
+const itemHeight = 34
|
|
|
+let start = $ref(0)
|
|
|
+const containerHeight = 274
|
|
|
+const itemCount = Math.ceil(containerHeight / itemHeight)
|
|
|
+let translateY = $ref(0)
|
|
|
+
|
|
|
+const listData = computed(() => {
|
|
|
+ return props.data.slice(start, start + itemCount + 1)
|
|
|
+})
|
|
|
+
|
|
|
+watch(
|
|
|
+ () => props.data,
|
|
|
+ () => {
|
|
|
+
|
|
|
+ },
|
|
|
+ {immediate: true, deep: true}
|
|
|
+)
|
|
|
+
|
|
|
+onMounted(() => {
|
|
|
+ nextTick(() => {
|
|
|
+ let dropdownList = select.$el.querySelectorAll('.el-select-dropdown .el-select-dropdown__wrap')[0]
|
|
|
+ let ul = dropdownList.querySelectorAll('ul')[0]
|
|
|
+ ul.style.height = props.data.length * 37 + 'px'
|
|
|
+
|
|
|
+ // ul
|
|
|
+ // dropdownList.addEventListener('scroll', e => {
|
|
|
+ // const {scrollTop} = e.target
|
|
|
+ // start = Math.floor(scrollTop / itemHeight)
|
|
|
+ // console.log(start)
|
|
|
+ // })
|
|
|
+
|
|
|
+ })
|
|
|
+})
|
|
|
+
|
|
|
+
|
|
|
+const visible = (val) => {
|
|
|
+ // console.log(option)
|
|
|
+ let dropdownList = select.$el.querySelectorAll('.el-select-dropdown .el-select-dropdown__wrap')[0]
|
|
|
+ let ul = dropdownList.querySelectorAll('ul')[0]
|
|
|
+ dropdownList.addEventListener('scroll', e => {
|
|
|
+ const {scrollTop} = e.target
|
|
|
+ ul.style.transform = `translateY(${scrollTop}px)`
|
|
|
+ start = Math.floor(scrollTop / itemHeight)
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+</script>
|
|
|
+
|
|
|
+<style scoped>
|
|
|
+
|
|
|
+</style>
|