  /*
  功能：自动计算界面底部自适应高度
  作者：郭飞
  邮箱：guofei2922@boe.com.cn
  时间：2024年10月17日
  版本：v1.0 
 */

import { ref, onUnmounted } from 'vue'

export const bTableHeight = (fixHeight: number) => {
  const tableContainer = ref<any>(null)
  const tableHeight = ref(0)

  onUnmounted(() => {
    window.removeEventListener('resize', handleResize)
  })

  const updateTableHeight = () => {
    if (tableContainer.value) {
      const containerRect = tableContainer.value.getBoundingClientRect()
      const containerHeight = containerRect.height
      tableHeight.value = containerHeight - fixHeight
    }
  }

  const handleResize = () => {
    updateTableHeight()
  }

  return { tableContainer, tableHeight, handleResize, updateTableHeight }
}
