downImage.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <view class="down-image">
  3. <view class="down-image__content" v-if="images.length">
  4. <view class="down-image__grid">
  5. <view class="down-image__item" v-for="(item, index) in images" :key="item.id || index" @click="handleClick(index)">
  6. <view class="down-image__item-img-container">
  7. <image
  8. class="down-image__item-img"
  9. :src="item.img"
  10. mode="aspectFill"
  11. lazy-load
  12. />
  13. </view>
  14. <view class="down-image__item-title">
  15. {{ formatDate(item.uptime) }}
  16. </view>
  17. </view>
  18. </view>
  19. </view>
  20. <view v-else>
  21. <u-empty text="暂无图片"></u-empty>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. export default {
  27. props:{
  28. images:{
  29. type: Array,
  30. default: () => []
  31. },
  32. deviceInfo:{
  33. type: Object,
  34. default: () => ({})
  35. },
  36. },
  37. methods: {
  38. // 点击跳转查看图片页,与监测图像(前后左右)一致
  39. handleClick(index) {
  40. const item = this.images[index] || {};
  41. // 只带当前点击的这张图片,URL放不下长链接,走storage
  42. const imgs = [{
  43. addr: item.img,
  44. mark: this.parseMark(item.mark),
  45. addtime: item.uptime,
  46. }];
  47. uni.setStorageSync('shuhai_group_imgs', JSON.stringify(imgs));
  48. uni.navigateTo({
  49. url: '/pages/shuHai1/devicePhoto?addtime=' + (item.uptime || 0) + '&id=' + (this.deviceInfo.id || '') + '&group_id=' + (item.id || '') + '&photo_type=' + encodeURIComponent('下')
  50. })
  51. },
  52. // mark可能是JSON字符串
  53. parseMark(mark) {
  54. if (Array.isArray(mark)) {
  55. return mark;
  56. }
  57. try {
  58. const arr = JSON.parse(mark || '[]');
  59. return Array.isArray(arr) ? arr : [];
  60. } catch (error) {
  61. return [];
  62. }
  63. },
  64. // 格式化时间
  65. formatDate(dateString) {
  66. if(!dateString){
  67. return '';
  68. }
  69. const date = new Date(dateString*1000);
  70. const year = date.getFullYear();
  71. const month = String(date.getMonth() + 1).padStart(2, '0');
  72. const day = String(date.getDate()).padStart(2, '0');
  73. const hour = String(date.getHours()).padStart(2, '0');
  74. const minute = String(date.getMinutes()).padStart(2, '0');
  75. const second = String(date.getSeconds()).padStart(2, '0');
  76. return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
  77. },
  78. },
  79. };
  80. </script>
  81. <style lang="scss" scoped>
  82. .down-image {
  83. width: 100%;
  84. box-sizing: border-box;
  85. .down-image__content{
  86. margin-top: 24rpx;
  87. .down-image__grid{
  88. display: grid;
  89. grid-template-columns: repeat(2, 1fr);
  90. gap: 20rpx;
  91. }
  92. }
  93. &__item {
  94. border-radius: 16rpx;
  95. padding: 20rpx;
  96. position: relative;
  97. width: 100%;
  98. box-sizing: border-box;
  99. display: inline-block;
  100. overflow: hidden;
  101. background: #ffffff;
  102. &-img-container {
  103. width: 100%;
  104. padding-bottom: 60%;
  105. position: relative;
  106. border-radius: 16rpx;
  107. overflow: hidden;
  108. background-color: #f5f5f5;
  109. }
  110. &-img {
  111. position: absolute;
  112. top: 0;
  113. left: 0;
  114. width: 100%;
  115. height: 100%;
  116. }
  117. &-title {
  118. font-size: 28rpx;
  119. color: #333333;
  120. font-family: "Source Han Sans CN VF";
  121. font-weight: 500;
  122. margin-top: 12rpx;
  123. }
  124. }
  125. }
  126. </style>