photoImage.vue 7.4 KB

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