photoImage.vue 7.8 KB

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