visual-table.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <!-- -->
  2. <template>
  3. <!-- <el-table
  4. ref="myTable"
  5. v-loading="loading"
  6. :data="tableData"
  7. height="250"
  8. border
  9. element-loading-background="rgba(0, 0, 0, 0.8)"
  10. class="table-left color-table"
  11. >
  12. <el-table-column label="序号" type="index" align="center" width="56" />
  13. <el-table-column
  14. prop="fileNumber"
  15. label="档号"
  16. align="center"
  17. />
  18. <el-table-column
  19. prop="name"
  20. label="案卷题名"
  21. align="center"
  22. />
  23. <el-table-column
  24. prop="pageN"
  25. label="总页数"
  26. align="center"
  27. />
  28. <el-table-column
  29. prop="storageTimeValue"
  30. label="保管期限"
  31. align="center"
  32. />
  33. <el-table-column
  34. prop="remark"
  35. label="备注"
  36. align="center"
  37. />
  38. </el-table> -->
  39. <HcTable
  40. ref="tableRef"
  41. heights="250px" :column="tableColumn" :datas="tableData" :loading="tableLoaing"
  42. is-new :index-style="{ width: 60 }" is-check :check-style="{ width: 29 }"
  43. />
  44. </template>
  45. <script setup>
  46. import { getCurrentInstance, nextTick, onMounted, ref, watch } from 'vue'
  47. const props = defineProps({
  48. tableData: {
  49. type: Array,
  50. default: () => ([]),
  51. },
  52. })
  53. const { proxy } = getCurrentInstance()
  54. const allData = ref(props.tableData)
  55. const needle = ref(10)//数据指针 默认19
  56. const tableData = ref([])
  57. const tableLoaing = ref(false)
  58. //表头
  59. const tableRef = ref(null)
  60. const tableColumn = ref([
  61. { key:'fileNumber', name: '档号', width: 180 },
  62. { key:'name', name: '案卷题名' },
  63. { key:'pageN', name: '总页数', width: 120 },
  64. { key:'storageTimeValue', name: '保管期限', width: 120 },
  65. { key:'remark', name: '备注' },
  66. ])
  67. //监听
  68. watch(() => [
  69. props.tableData,
  70. ], ([Data]) => {
  71. allData.value = Data
  72. tableData.value = []
  73. //判断数据长度有没有9个,有就先添加9个,没有直接获取所有数据
  74. if (allData.value.length > 5) {
  75. for (let i = 0;i < needle.value + 1;i++) {
  76. tableData.value[i] = allData.value[i]
  77. }
  78. } else {
  79. tableData.value = allData.value
  80. }
  81. },
  82. { immediate: true, deep: true })
  83. onMounted(()=>{
  84. setTimeout(() => {
  85. lazyLoading()
  86. }, 1500)
  87. })
  88. const queryData = ()=>{
  89. // 一条一条加载记录,直至遍历到最后一条
  90. while (needle.value < allData.value.length ) {
  91. tableLoaing.value = true
  92. tableData.value[needle.value] = allData.value[needle.value]
  93. tableLoaing.value = false
  94. proxy.$forceUpdate()
  95. needle.value++
  96. }
  97. }
  98. const lazyLoading = ()=>{
  99. const wrapRef = tableRef.value.tableRef.$refs.scrollBarRef.wrapRef
  100. if ('onscrollend' in window) {
  101. console.log(5555555)
  102. wrapRef.addEventListener('scrollend', queryData)
  103. }
  104. }
  105. </script>
  106. <style lang='scss' scoped>
  107. </style>