fe-drone-ci/src/directive/el-table/adaptive.js

33 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

export default{
/**
* 仅当 el-table :data属性为动态加载不包括computed才会触发此事件且 已为 el-table 设置 height 的初始值(任何值) 此指令才起作用
* @param {*} el
* @param {*} binding
* binding.value 格式为 {
* table: $refs.table, // 表格对象
* topHeight: 10 // 表格顶边 距离顶部高度,默认值为 10
* footerHeight: 10 // 表格底部 距离底部高度,默认值为 10
* }
* @param {*} vnode
* @param {*} oldVnode
*/
update(el, binding, vnode, oldVnode) {
let topHeight = binding.value.topHeight ? binding.value.topHeight : 10
let footerHeight = binding.value.footerHeight ? binding.value.footerHeight : 10
let table = binding.value.table
let tableHeight = window.innerHeight - el.offsetTop - footerHeight - topHeight;
table.layout.setHeight(tableHeight)
table.doLayout()
// 监听窗口大小变化
window.addEventListener("resize", () => {
tableHeight = window.innerHeight - el.offsetTop - footerHeight - topHeight
table.layout.setHeight(tableHeight)
table.doLayout()
})
}
}