visual-table.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <!-- -->
  2. <template>
  3. <HcTable
  4. ref="tableRef"
  5. :column="tableColumn" :datas="tableData" :loading="tableLoaing"
  6. is-new :index-style="{ width: 60 }" is-check :check-style="{ width: 29 }"
  7. @selection-change="tableSelection"
  8. />
  9. </template>
  10. <script setup>
  11. import { getCurrentInstance, nextTick, onMounted, onUnmounted, ref, watch } from 'vue'
  12. const props = defineProps({
  13. tableData: {
  14. type: Array,
  15. default: () => ([]),
  16. },
  17. })
  18. //事件
  19. const emit = defineEmits(['getTableKeys'])
  20. const { proxy } = getCurrentInstance()
  21. const allData = ref(props.tableData)
  22. const needle = ref(10)//数据指针 默认19
  23. const tableData = ref([])
  24. const tableLoaing = ref(false)
  25. //多选
  26. const tableKeys = ref([])
  27. const tableSelection = (rows) => {
  28. tableKeys.value = rows
  29. emit('getTableKeys', rows)
  30. }
  31. //表头
  32. const tableRef = ref(null)
  33. const tableColumn = ref([
  34. { key:'fileNumber', name: '档号', width: 180 },
  35. { key:'name', name: '案卷题名' },
  36. { key:'pageN', name: '总页数', width: 120 },
  37. { key:'storageTimeValue', name: '保管期限', width: 120 },
  38. { key:'remark', name: '备注' },
  39. ])
  40. //监听
  41. watch(() => [
  42. props.tableData,
  43. ], ([Data]) => {
  44. allData.value = Data
  45. tableData.value = []
  46. //判断数据长度有没有9个,有就先添加9个,没有直接获取所有数据
  47. if (allData.value.length > 9) {
  48. for (let i = 0;i < needle.value ;i++) {
  49. tableData.value[i] = allData.value[i]
  50. }
  51. } else {
  52. tableData.value = allData.value
  53. }
  54. },
  55. { immediate: true, deep: true })
  56. onMounted(()=>{
  57. tableRef.value && tableRef.value.tableRef && tableRef.value.tableRef.$refs.bodyWrapper.addEventListener('mousewheel', scrollBehavior)
  58. })
  59. onUnmounted(() => {
  60. // 卸载
  61. tableRef.value && tableRef.value.tableRef && tableRef.value.tableRef.$refs.bodyWrapper.removeEventListener('mousewheel', scrollBehavior)
  62. })
  63. const queryData = async ()=>{
  64. console.log('查询数据')
  65. let ortab = tableData.value
  66. if (needle.value < allData.value.length) {
  67. let pusharr = allData.value.slice(needle.value, needle.value + 10)
  68. pusharr.forEach((ele)=>{
  69. ortab.push(ele)
  70. })
  71. needle.value = needle.value + 10
  72. return ortab
  73. }
  74. }
  75. const scrollBehavior = async (e)=>{
  76. // 滚动方向判定
  77. const scrollDirection = e.deltaY > 0 ? 'down' : 'up'
  78. if (scrollDirection === 'down') {
  79. // 获取提供实际滚动的容器
  80. const dom = tableRef.value.tableRef.$refs.bodyWrapper.getElementsByClassName('el-scrollbar__wrap')[0]
  81. const { clientHeight, scrollTop, scrollHeight } = dom
  82. // 父容器高度 + 子容器距离父容器顶端的高度 = 子容器可滚动的高度
  83. if (clientHeight + scrollTop === scrollHeight) {
  84. console.log('竖向滚动条已经滚动到底部')
  85. const res = await queryData()
  86. if (res) {
  87. tableData.value = res
  88. }
  89. }
  90. }
  91. }
  92. </script>
  93. <style lang='scss' scoped>
  94. </style>