瑶都万能墙
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
1.8 KiB

2 weeks ago
  1. <template>
  2. <view class="waterfall-container">
  3. <view class="waterfall-columns">
  4. <!-- 左列 -->
  5. <view class="waterfall-column">
  6. <waterfallItem
  7. v-for="(item, index) in leftColumnData"
  8. :key="'left_' + index"
  9. :item="item"
  10. @click="handleItemClick"
  11. @like="handleItemLike"
  12. />
  13. </view>
  14. <!-- 右列 -->
  15. <view class="waterfall-column">
  16. <waterfallItem
  17. v-for="(item, index) in rightColumnData"
  18. :key="'right_' + index"
  19. :item="item"
  20. @click="handleItemClick"
  21. @like="handleItemLike"
  22. />
  23. </view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. import waterfallItem from './waterfallItem.vue'
  29. export default {
  30. components: {
  31. waterfallItem
  32. },
  33. props: {
  34. list: {
  35. type: Array,
  36. default: () => []
  37. }
  38. },
  39. data() {
  40. return {
  41. leftColumnData: [],
  42. rightColumnData: []
  43. }
  44. },
  45. watch: {
  46. list: {
  47. handler(newList) {
  48. this.distributeItems(newList)
  49. },
  50. immediate: true
  51. }
  52. },
  53. methods: {
  54. // 将数据分配到左右两列
  55. distributeItems(items) {
  56. this.leftColumnData = []
  57. this.rightColumnData = []
  58. items.forEach((item, index) => {
  59. // 简单的奇偶分配,也可以根据内容高度智能分配
  60. if (index % 2 === 0) {
  61. this.leftColumnData.push(item)
  62. } else {
  63. this.rightColumnData.push(item)
  64. }
  65. })
  66. },
  67. // 处理点击事件
  68. handleItemClick(item) {
  69. this.$emit('item-click', item)
  70. },
  71. // 处理点赞事件
  72. handleItemLike(item) {
  73. this.$emit('item-like', item)
  74. }
  75. }
  76. }
  77. </script>
  78. <style scoped lang="scss">
  79. .waterfall-container {
  80. padding: 20rpx;
  81. .waterfall-columns {
  82. display: flex;
  83. gap: 20rpx;
  84. .waterfall-column {
  85. flex: 1;
  86. display: flex;
  87. flex-direction: column;
  88. }
  89. }
  90. }
  91. </style>