|
@ -39,18 +39,32 @@ export default { |
|
|
data() { |
|
|
data() { |
|
|
return { |
|
|
return { |
|
|
tableData: [], // 正在展示的数据 |
|
|
tableData: [], // 正在展示的数据 |
|
|
time: null |
|
|
|
|
|
|
|
|
scrollTimer: null, |
|
|
|
|
|
showComplete: false, // 是否滚动显示完所有数据 |
|
|
|
|
|
getDataTimer: null |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
watch: { |
|
|
|
|
|
// 如果 `tableData` 发生改变,这个函数就会运行 |
|
|
|
|
|
tableData: function(newData, oldData) { |
|
|
|
|
|
this.tableRefScroll() |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
created() { |
|
|
created() { |
|
|
this.getSecuritydoor() |
|
|
this.getSecuritydoor() |
|
|
this.time = setInterval(() => { |
|
|
|
|
|
this.getSecuritydoor() |
|
|
|
|
|
|
|
|
this.getDataTimer = setInterval(() => { |
|
|
|
|
|
console.log('SecurityDoor', this.showComplete) |
|
|
|
|
|
if (this.showComplete) { |
|
|
|
|
|
this.getSecuritydoor() |
|
|
|
|
|
this.showComplete = false |
|
|
|
|
|
} |
|
|
}, 1000 * 30) |
|
|
}, 1000 * 30) |
|
|
}, |
|
|
}, |
|
|
destroyed() { |
|
|
destroyed() { |
|
|
clearInterval(this.time) |
|
|
|
|
|
this.time = null |
|
|
|
|
|
|
|
|
clearInterval(this.scrollTimer) |
|
|
|
|
|
this.scrollTimer = null |
|
|
|
|
|
clearInterval(this.getDataTimer) |
|
|
|
|
|
this.getDataTimer = null |
|
|
}, |
|
|
}, |
|
|
methods: { |
|
|
methods: { |
|
|
// 表格隔行变色 |
|
|
// 表格隔行变色 |
|
@ -61,6 +75,42 @@ export default { |
|
|
return '' |
|
|
return '' |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
|
|
|
// table滚动 |
|
|
|
|
|
tableRefScroll() { |
|
|
|
|
|
clearInterval(this.scrollTimer) // 清除定时器 |
|
|
|
|
|
const table = this.$refs.table // 获取DOM元素 |
|
|
|
|
|
this.wrapperHeight = table.$el.offsetHeight - 30 |
|
|
|
|
|
// 组件一页能完整展示的数据条数 |
|
|
|
|
|
this.displayNum = Math.floor(this.wrapperHeight / 40) |
|
|
|
|
|
if (this.tableData.length > this.displayNum) { |
|
|
|
|
|
const bodyWrapper = table.bodyWrapper // 获取表格中承载数据的div元素 |
|
|
|
|
|
this.addTableRefScroll(bodyWrapper) |
|
|
|
|
|
// 鼠标移入 |
|
|
|
|
|
bodyWrapper.onmouseover = () => { |
|
|
|
|
|
clearInterval(this.scrollTimer) |
|
|
|
|
|
} |
|
|
|
|
|
// 鼠标移出 |
|
|
|
|
|
bodyWrapper.onmouseout = () => { |
|
|
|
|
|
this.addTableRefScroll(bodyWrapper) |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
this.showComplete = true |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
addTableRefScroll(bodyWrapper) { |
|
|
|
|
|
// let scrollTop = bodyWrapper.scrollTop |
|
|
|
|
|
if (this.displayNum && this.displayNum > 0) { |
|
|
|
|
|
this.scrollTimer = setInterval(() => { |
|
|
|
|
|
// scrollTop = bodyWrapper.scrollTop |
|
|
|
|
|
if (bodyWrapper.scrollTop + this.wrapperHeight >= this.tableData.length * 40) { |
|
|
|
|
|
bodyWrapper.scrollTop = 0 |
|
|
|
|
|
this.showComplete = true |
|
|
|
|
|
} else { |
|
|
|
|
|
bodyWrapper.scrollTop += this.displayNum * 40 |
|
|
|
|
|
} |
|
|
|
|
|
}, 1000 * 3 * this.displayNum) |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
getSecuritydoor() { |
|
|
getSecuritydoor() { |
|
|
securitydoor().then((data) => { |
|
|
securitydoor().then((data) => { |
|
|
if (data && data.length > 0) { |
|
|
if (data && data.length > 0) { |
|
|