VciListLargeData.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <template>
  2. <div class="VciListLargeData">
  3. <vci-scroll
  4. ref="scroll"
  5. @scroll="scroll"
  6. >
  7. <i
  8. :style="{ height: `${fillTopHeight}px` }"
  9. class="lld-pre"
  10. ></i>
  11. <div
  12. ref="list"
  13. class="lld-list"
  14. >
  15. <div
  16. v-for="(v, i) in validList"
  17. :key="i"
  18. class="vl-item"
  19. >
  20. <slot v-bind="{ item: v, index: i }"></slot>
  21. </div>
  22. </div>
  23. <i
  24. :style="{ height: `${fillBottomHeight}px` }"
  25. class="lld-suf"
  26. ></i>
  27. </vci-scroll>
  28. </div>
  29. </template>
  30. <script>
  31. // power by visual-ceiling, at 2022/11/2 15:51
  32. import VciScroll from "@vci/vci/vue/v2/components/other/VciScroll.vue";
  33. export default {
  34. name: "VciListLargeData",
  35. components: { VciScroll },
  36. props: {
  37. list: {
  38. type: Array,
  39. default: () => []
  40. },
  41. validRows: {
  42. type: Number,
  43. default: 32
  44. }
  45. },
  46. data() {
  47. return {
  48. top: 0,
  49. topAmount: 0,
  50. validMaxAmount: 0,
  51. fillTopHeight: 0,
  52. fillBottomHeight: 0,
  53. validList: [],
  54. row: {
  55. height: 20
  56. }
  57. };
  58. },
  59. watch: {
  60. list: {
  61. immediate: true,
  62. handler: "analysis"
  63. }
  64. },
  65. methods: {
  66. analysis() {
  67. this.validList = this.list.filter((v, i) => i >= 0 && i < this.validRows);
  68. this.$nextTick(() => {
  69. // const { elViewHeight, elContentHeight } = this.$refs.scroll.getStructure();
  70. this.scroll({ top: 0 });
  71. });
  72. },
  73. scroll(e) {
  74. this.top = e.top;
  75. this.topAmount = Math.floor(this.top / this.row.height);
  76. this.validMaxAmount = this.topAmount + this.validRows;
  77. this.validList = this.list.filter((v, i) => i >= this.topAmount && i < this.validMaxAmount);
  78. this.fillTopHeight = this.topAmount * this.row.height;
  79. this.fillBottomHeight = this.list.filter((v, i) => i > this.validMaxAmount).length * this.row.height;
  80. this.$nextTick(() => this.$refs.scroll.scrollTo(this.top));
  81. }
  82. }
  83. };
  84. </script>
  85. <style lang="scss" scoped>
  86. .VciListLargeData {
  87. width: 100%;
  88. height: 100%;
  89. .lld-pre, .lld-suf {
  90. display: block;
  91. width: 100%;
  92. }
  93. }
  94. </style>