albumCarousel7d.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <template v-for="(images,index) in imagesList" :key="index">
  3. <album-carousel-item :farmId="farmId" :images="images"></album-carousel-item>
  4. <div style="height: 5px"></div>
  5. </template>
  6. </template>
  7. <script setup>
  8. import { ref, computed, onMounted, onUnmounted } from "vue";
  9. import AlbumDrawBoxItem from "./albumCarouselItem";
  10. import "./cacheImg.js"
  11. import AlbumCarouselItem from "./albumCarouselItem";
  12. import {dateFormat} from "@/utils/date_util.js"
  13. import eventBus from "@/api/eventBus";
  14. const props =defineProps({
  15. // sampleId:{
  16. // type: [Number, String],
  17. // required: false
  18. // },
  19. farmId:{
  20. type: [Number, String],
  21. required: true
  22. },
  23. farmWork:{
  24. type: Object,
  25. required: false
  26. }
  27. })
  28. const imagesList = ref([]);
  29. let params = {farmId: props.farmId}
  30. onMounted(() => {
  31. if(props.farmWork?.executeDate){
  32. let execcuteDate = new Date(props.farmWork.executeDate)
  33. let beforeExecuteDate = new Date(props.farmWork.beforeExecuteDate)
  34. const pastDate = new Date(beforeExecuteDate);
  35. const futureDate = new Date(execcuteDate);
  36. params.startDate = dateFormat(pastDate, "YY-mm-dd");
  37. params.endDate = dateFormat(futureDate, "YY-mm-dd");
  38. params.limit = 20
  39. }
  40. getImageList(params)
  41. });
  42. const updateData = () =>{
  43. params.farmId = props.farmId
  44. getImageList(params)
  45. }
  46. onUnmounted(()=>{
  47. eventBus.off("chart:updateOption",updateData)
  48. })
  49. const getImageList = (params) =>{
  50. VE_API.image.list(params).then(res => {
  51. if(res.code === 0){
  52. let result = splitByWeek(res.data, params.startDate, params.endDate);
  53. if(result && result.length > 0){
  54. result = result.reverse()
  55. }
  56. for(let i=0;result != null && i<result.length;i++){
  57. if (result[i] && result[i].length > 0){
  58. imagesList.value.push(result[i])
  59. }
  60. }
  61. }
  62. })
  63. }
  64. eventBus.on("chart:updateOption",updateData)
  65. function splitByWeek(items, startDate, endDate) {
  66. // 将开始时间和结束时间转换为时间戳
  67. const start = new Date(startDate).getTime();
  68. const end = new Date(endDate).getTime();
  69. // 创建一个用于存储按周分组的结果
  70. const weeklyGroups = [];
  71. // 遍历每一项
  72. items.forEach(item => {
  73. const uploadDate = new Date(item.uploadDate).getTime();
  74. // 确保上传日期在开始日期和结束日期之间
  75. if (uploadDate >= start && uploadDate <= end) {
  76. // 计算上传日期属于第几周
  77. const weekIndex = Math.floor((uploadDate - start) / (7 * 24 * 60 * 60 * 1000));
  78. // 如果该周的数组不存在,则创建一个
  79. if (!weeklyGroups[weekIndex]) {
  80. weeklyGroups[weekIndex] = [];
  81. }
  82. // 将当前项添加到对应的周数组中
  83. weeklyGroups[weekIndex].push(item);
  84. }
  85. });
  86. return weeklyGroups;
  87. }
  88. </script>
  89. <style lang="scss" scoped>
  90. @import "src/styles/index";
  91. </style>