photoImage.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <template>
  2. <view class="photo-image">
  3. <view
  4. class="photo-image__tabs"
  5. v-if="disableShow"
  6. >
  7. <view
  8. class="photo-image__tab"
  9. v-for="(pest, index) in pestList"
  10. :key="index"
  11. :class="{ active: activeIndexList.includes(index) }"
  12. @click="changeTab(index)"
  13. >
  14. <text class="tab-text">{{ pest.pest_name }}({{ pest.pest_num }})</text>
  15. </view>
  16. </view>
  17. <view class="photo-image__content" v-if="images.length">
  18. <view class="photo-image__grid">
  19. <view class="photo-image__item" v-for="(item, index) in images" :key="index" @click="handleClick(item)">
  20. <view class="photo-image__item-img-container">
  21. <image
  22. class="photo-image__item-img"
  23. :src="getSrc(item)"
  24. />
  25. <!-- <view class="photo-image__item-icon-container">
  26. <image
  27. v-if="hasMark(item)"
  28. class="photo-image__item-icon"
  29. src="https://s3.hnyfwlw.com/webstaticimg/bigdata_app/img/ai.png"
  30. />
  31. <image
  32. v-if="item.has_photo == 1"
  33. class="photo-image__item-icon-video"
  34. src="https://s3.hnyfwlw.com/webstaticimg/bigdata_app/img/video.png"
  35. />
  36. <image
  37. v-if="item.has_video == 1"
  38. class="photo-image__item-icon-img"
  39. src="https://s3.hnyfwlw.com/webstaticimg/bigdata_app/img/img.png"
  40. />
  41. </view> -->
  42. </view>
  43. <view class="photo-image__item-title">
  44. {{ formatDate(item.addtime) }}
  45. </view>
  46. </view>
  47. </view>
  48. </view>
  49. <view v-else>
  50. <u-empty text="暂无图片"></u-empty>
  51. </view>
  52. </view>
  53. </template>
  54. <script>
  55. export default {
  56. props:{
  57. disableShow:{
  58. type: Boolean,
  59. default: true
  60. },
  61. pestList:{
  62. type: Array,
  63. default: () => []
  64. },
  65. images:{
  66. type: Array,
  67. default: () => []
  68. },
  69. deviceInfo:{
  70. type: Object,
  71. default: () => ({})
  72. },
  73. currentYear:{
  74. type: String | Number,
  75. default: ''
  76. },
  77. ding_one_device_id:{
  78. type: String,
  79. default: ''
  80. },
  81. ding_three_device_id:{
  82. type: String,
  83. default: ''
  84. },
  85. ding_two_device_id:{
  86. type: String,
  87. default: ''
  88. },
  89. },
  90. data() {
  91. return {
  92. activeIndexList:[],
  93. activePest:[],
  94. activeTab: 0,
  95. tabs: ['全部', '稻飞虱', '水龟虫', '蝼蛄', '系统','全部', '稻飞虱', '水龟虫', '蝼蛄', '系统'],
  96. };
  97. },
  98. methods: {
  99. // 取第一张有地址的图片作为封面
  100. getSrc(item){
  101. const first = (item.imgs || []).find(img => img && img.addr);
  102. return first?.addr;
  103. },
  104. // 是否有识别标记
  105. hasMark(item){
  106. return (item.imgs || []).some(img => img && img.mark && img.mark.length);
  107. },
  108. changeTab(index) {
  109. if(this.activeIndexList.includes(index)){
  110. this.activePest = this.activePest.filter(item => item !== this.pestList[index])
  111. this.activeIndexList = this.activeIndexList.filter(item => item !== index)
  112. }else{
  113. this.activeIndexList.push(index)
  114. this.activePest.push(this.pestList[index])
  115. }
  116. this.$emit('changeTab', this.activePest)
  117. },
  118. changeTabActive(index, event_id) {
  119. this.activeTab = index
  120. this.$emit('changeTab', event_id)
  121. },
  122. // 格式化时间
  123. formatDate(dateString) {
  124. const date = new Date(dateString*1000);
  125. const year = date.getFullYear();
  126. const month = String(date.getMonth() + 1).padStart(2, '0');
  127. const day = String(date.getDate()).padStart(2, '0');
  128. const hour = String(date.getHours()).padStart(2, '0');
  129. const minute = String(date.getMinutes()).padStart(2, '0');
  130. const second = String(date.getSeconds()).padStart(2, '0');
  131. return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
  132. },
  133. handleClick(item) {
  134. // 把该分组的所有图片带过去,URL放不下长链接,走storage
  135. uni.setStorageSync('shuhai_group_imgs', JSON.stringify(item?.imgs || []));
  136. uni.navigateTo({
  137. url: '/pages/shuHai1/devicePhoto?addtime=' + item?.addtime + '&id=' + this.deviceInfo.id + '&group_id=' + item?.group_id
  138. })
  139. }
  140. },
  141. };
  142. </script>
  143. <style lang="scss" scoped>
  144. .photo-image {
  145. width: 100%;
  146. box-sizing: border-box;
  147. &__header {
  148. margin-bottom: 32rpx;
  149. white-space: nowrap;
  150. &::-webkit-scrollbar {
  151. display: none;
  152. }
  153. }
  154. &__tabs {
  155. box-sizing: border-box;
  156. width: 100%;
  157. overflow-x: auto;
  158. overflow-y: hidden;
  159. white-space: nowrap;
  160. // 去掉滚动条
  161. -ms-overflow-style: none;
  162. scrollbar-width: none;
  163. }
  164. .photo-image__content{
  165. margin-top: 24rpx;
  166. .photo-image__grid{
  167. display: grid;
  168. grid-template-columns: repeat(2, 1fr);
  169. gap: 20rpx;
  170. }
  171. }
  172. &__tab {
  173. position: relative;
  174. display: inline-block;
  175. box-sizing: border-box;
  176. margin-right: 16rpx;
  177. background: #ffffff;
  178. color: #999999;
  179. font-family: "Source Han Sans CN VF";
  180. font-size: 28rpx;
  181. padding: 10rpx 32rpx;
  182. border-radius: 8rpx;
  183. &:last-child {
  184. margin-right: 0;
  185. }
  186. .tab-text {
  187. margin-right: 8rpx;
  188. }
  189. .tab-check {
  190. color: #4CAF50;
  191. font-weight: bold;
  192. }
  193. &.active {
  194. color: #0BBC58;
  195. }
  196. .tab-underline {
  197. position: absolute;
  198. bottom: 0;
  199. left: 0;
  200. right: 0;
  201. height: 4rpx;
  202. background: #4CAF50;
  203. border-radius: 2rpx;
  204. }
  205. }
  206. &__item {
  207. border-radius: 16rpx;
  208. padding: 20rpx;
  209. position: relative;
  210. width: 100%;
  211. box-sizing: border-box;
  212. display: inline-block;
  213. overflow: hidden;
  214. background: #ffffff;
  215. &-img-container {
  216. width: 100%;
  217. padding-bottom: 60%;
  218. position: relative;
  219. border-radius: 16rpx;
  220. overflow: hidden;
  221. background-color: #f5f5f5;
  222. }
  223. .photo-image__item-icon-container{
  224. position: absolute;
  225. display: flex;
  226. gap: 4rpx;
  227. top: 8rpx;
  228. left: 8rpx;
  229. width: 100%;
  230. height: 100%;
  231. }
  232. &-img {
  233. position: absolute;
  234. top: 0;
  235. left: 0;
  236. width: 100%;
  237. height: 100%;
  238. }
  239. &-icon {
  240. width: 40rpx;
  241. height: 40rpx;
  242. }
  243. &-icon-video {
  244. width: 40rpx;
  245. height: 40rpx;
  246. }
  247. &-icon-img {
  248. width: 40rpx;
  249. height: 40rpx;
  250. }
  251. &-title {
  252. font-size: 28rpx;
  253. color: #333333;
  254. font-family: "Source Han Sans CN VF";
  255. font-weight: 500;
  256. margin-top: 12rpx;
  257. }
  258. }
  259. }
  260. </style>