Commit 658f7f96 by zhangxw

下拉触发方法修改

1 parent 7b1da277
...@@ -226,17 +226,24 @@ export default { ...@@ -226,17 +226,24 @@ export default {
directives: { directives: {
"el-select-loadmore": { "el-select-loadmore": {
bind(el, binding) { bind(el, binding) {
let isTriggered = false
const debounceTime = 300 // 防抖时间
const waitForDropdown = () => { const waitForDropdown = () => {
const SELECTWRAP_DOM = el.querySelector('.el-select-dropdown .el-select-dropdown__wrap') const SELECTWRAP_DOM = el.querySelector('.el-select-dropdown .el-select-dropdown__wrap');
if (SELECTWRAP_DOM) { if (SELECTWRAP_DOM) {
SELECTWRAP_DOM.addEventListener('scroll', function() { SELECTWRAP_DOM.addEventListener('scroll', function() {
const condition = this.scrollHeight - this.scrollTop <= this.clientHeight + 1 const condition = this.scrollHeight - this.scrollTop <= this.clientHeight + 1
if (condition) { if (condition && !isTriggered) {
isTriggered = true
binding.value() binding.value()
// 延迟重置触发状态
setTimeout(() => {
isTriggered = false
}, debounceTime)
} }
}); })
} else { } else {
// 如果没有找到下拉框DOM,延迟重试(针对对话框情况) // 如果没有找到下拉框DOM,延迟重试
setTimeout(waitForDropdown, 50) setTimeout(waitForDropdown, 50)
} }
} }
...@@ -261,6 +268,7 @@ export default { ...@@ -261,6 +268,7 @@ export default {
}) })
}, },
interestsLoadmore() { interestsLoadmore() {
console.log('22222222')
setTimeout(() => { setTimeout(() => {
this.pageNum = this.pageNum + 1 this.pageNum = this.pageNum + 1
if (this.allPages < this.pageNum) { if (this.allPages < this.pageNum) {
......
...@@ -495,18 +495,23 @@ export default { ...@@ -495,18 +495,23 @@ export default {
directives: { directives: {
"el-select-loadmore": { "el-select-loadmore": {
bind(el, binding) { bind(el, binding) {
let triggered = false
const threshold = 50
const debounceTime = 300 // 防抖时间
const waitForDropdown = () => { const waitForDropdown = () => {
const SELECTWRAP_DOM = el.querySelector('.el-select-dropdown .el-select-dropdown__wrap') const SELECTWRAP_DOM = el.querySelector('.el-select-dropdown .el-select-dropdown__wrap')
if (SELECTWRAP_DOM) { if (SELECTWRAP_DOM) {
SELECTWRAP_DOM.addEventListener('scroll', function() { SELECTWRAP_DOM.addEventListener('scroll', function() {
const condition = this.scrollHeight - this.scrollTop <= this.clientHeight + 1 const scrollBottom = this.scrollHeight - this.scrollTop - this.clientHeight
if (condition) { if (scrollBottom <= threshold && !triggered) {
binding.value() triggered = true
binding.value() // 执行加载更多
// 无论是否是异步操作,都延迟重置
setTimeout(() => {
triggered = false
}, debounceTime)
} }
}); })
} else {
// 如果没有找到下拉框DOM,延迟重试(针对对话框情况)
setTimeout(waitForDropdown, 50)
} }
} }
waitForDropdown() waitForDropdown()
...@@ -514,17 +519,24 @@ export default { ...@@ -514,17 +519,24 @@ export default {
}, },
"el-select-loadmore-dialog": { "el-select-loadmore-dialog": {
bind(el, binding) { bind(el, binding) {
let isTriggered = false
const debounceTime = 300 // 防抖时间
const waitForDropdown = () => { const waitForDropdown = () => {
const SELECTWRAP_DOM = el.querySelector('.el-select-dropdown .el-select-dropdown__wrap') const SELECTWRAP_DOM = el.querySelector('.el-select-dropdown .el-select-dropdown__wrap');
if (SELECTWRAP_DOM) { if (SELECTWRAP_DOM) {
SELECTWRAP_DOM.addEventListener('scroll', function() { SELECTWRAP_DOM.addEventListener('scroll', function() {
const condition = this.scrollHeight - this.scrollTop <= this.clientHeight + 1 const condition = this.scrollHeight - this.scrollTop <= this.clientHeight + 1
if (condition) { if (condition && !isTriggered) {
isTriggered = true
binding.value() binding.value()
// 延迟重置触发状态
setTimeout(() => {
isTriggered = false
}, debounceTime)
} }
}); })
} else { } else {
// 如果没有找到下拉框DOM,延迟重试(针对对话框情况) // 如果没有找到下拉框DOM,延迟重试
setTimeout(waitForDropdown, 50) setTimeout(waitForDropdown, 50)
} }
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!