photoImage.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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="item.addr"
  30. />
  31. <image
  32. class="photo-image__item-icon"
  33. src="https://s3.hnyfwlw.com/webstaticimg/bigdata_app/img/ai.png"
  34. />
  35. <image
  36. class="photo-image__item-icon-video"
  37. src="https://s3.hnyfwlw.com/webstaticimg/bigdata_app/img/video.png"
  38. />
  39. </view>
  40. <view class="photo-image__item-title">
  41. 相机1
  42. </view>
  43. <view class="photo-image__item-time">
  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. },
  78. data() {
  79. return {
  80. activeIndexList:[],
  81. activePest:[],
  82. activeTab: 0,
  83. tabs: ['全部', '稻飞虱', '水龟虫', '蝼蛄', '系统','全部', '稻飞虱', '水龟虫', '蝼蛄', '系统'],
  84. };
  85. },
  86. methods: {
  87. changeTab(index) {
  88. if(this.activeIndexList.includes(index)){
  89. this.activePest = this.activePest.filter(item => item !== this.pestList[index])
  90. this.activeIndexList = this.activeIndexList.filter(item => item !== index)
  91. }else{
  92. this.activeIndexList.push(index)
  93. this.activePest.push(this.pestList[index])
  94. }
  95. this.$emit('changeTab', this.activePest)
  96. },
  97. changeTabActive(index) {
  98. this.activeTab = index
  99. this.$emit('changeTab', this.activePest)
  100. },
  101. // 格式化时间
  102. formatDate(dateString) {
  103. const date = new Date(dateString*1000);
  104. const year = date.getFullYear();
  105. const month = String(date.getMonth() + 1).padStart(2, '0');
  106. const day = String(date.getDate()).padStart(2, '0');
  107. const hour = String(date.getHours()).padStart(2, '0');
  108. const minute = String(date.getMinutes()).padStart(2, '0');
  109. const second = String(date.getSeconds()).padStart(2, '0');
  110. return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
  111. },
  112. handleClick(item) {
  113. uni.navigateTo({
  114. url: '/pages/cbd/devicePhoto?device_id=' + item?.device_id + '&addtime=' + item?.addtime + '&img_id=' + item?.ids + '&id=' + this.deviceInfo.id + '&currentYear=' + this.currentYear
  115. })
  116. }
  117. },
  118. };
  119. </script>
  120. <style lang="scss" scoped>
  121. .photo-image {
  122. width: 100%;
  123. box-sizing: border-box;
  124. .photo-tabs{
  125. display: flex;
  126. align-items: center;
  127. justify-content: space-between;
  128. text-align: center;
  129. border-radius: 16rpx;
  130. background: #ffffff;
  131. padding: 20rpx;
  132. .photo-tab-item{
  133. flex:1;
  134. font-size: 28rpx;
  135. color: #999999;
  136. font-family: "Source Han Sans CN VF";
  137. font-weight: 400;
  138. }
  139. .photo-tab-item.active{
  140. border-radius: 4px;
  141. background: #0BBC58;
  142. color: #ffffff;
  143. line-height: 46rpx;
  144. display: flex;
  145. align-items: center;
  146. justify-content: center;
  147. }
  148. }
  149. &__header {
  150. margin-bottom: 32rpx;
  151. white-space: nowrap;
  152. &::-webkit-scrollbar {
  153. display: none;
  154. }
  155. }
  156. &__tabs {
  157. box-sizing: border-box;
  158. width: 100%;
  159. overflow-x: auto;
  160. overflow-y: hidden;
  161. white-space: nowrap;
  162. // 去掉滚动条
  163. -ms-overflow-style: none;
  164. scrollbar-width: none;
  165. }
  166. .photo-image__content{
  167. margin-top: 24rpx;
  168. .photo-image__grid{
  169. display: grid;
  170. grid-template-columns: repeat(2, 1fr);
  171. gap: 20rpx;
  172. }
  173. }
  174. &__tab {
  175. position: relative;
  176. display: inline-block;
  177. box-sizing: border-box;
  178. margin-right: 16rpx;
  179. background: #ffffff;
  180. color: #999999;
  181. font-family: "Source Han Sans CN VF";
  182. font-size: 28rpx;
  183. padding: 10rpx 32rpx;
  184. border-radius: 8rpx;
  185. &:last-child {
  186. margin-right: 0;
  187. }
  188. .tab-text {
  189. margin-right: 8rpx;
  190. }
  191. .tab-check {
  192. color: #4CAF50;
  193. font-weight: bold;
  194. }
  195. &.active {
  196. color: #0BBC58;
  197. }
  198. .tab-underline {
  199. position: absolute;
  200. bottom: 0;
  201. left: 0;
  202. right: 0;
  203. height: 4rpx;
  204. background: #4CAF50;
  205. border-radius: 2rpx;
  206. }
  207. }
  208. &__item {
  209. border-radius: 16rpx;
  210. padding: 20rpx;
  211. position: relative;
  212. width: 100%;
  213. box-sizing: border-box;
  214. display: inline-block;
  215. overflow: hidden;
  216. background: #ffffff;
  217. &-img-container {
  218. width: 100%;
  219. padding-bottom: 60%;
  220. position: relative;
  221. border-radius: 16rpx;
  222. overflow: hidden;
  223. background-color: #f5f5f5;
  224. }
  225. &-img {
  226. position: absolute;
  227. top: 0;
  228. left: 0;
  229. width: 100%;
  230. height: 100%;
  231. }
  232. &-icon {
  233. position: absolute;
  234. top: 8rpx;
  235. left: 8rpx;
  236. width: 40rpx;
  237. height: 40rpx;
  238. }
  239. &-icon-video {
  240. position: absolute;
  241. top: 8rpx;
  242. left: 52rpx;
  243. width: 40rpx;
  244. height: 40rpx;
  245. }
  246. &-title {
  247. font-size: 28rpx;
  248. color: #333333;
  249. font-family: "Source Han Sans CN VF";
  250. font-weight: 500;
  251. margin-top: 12rpx;
  252. }
  253. &-time {
  254. width: 100%;
  255. padding: 0;
  256. overflow: hidden;
  257. text-overflow: ellipsis;
  258. white-space: nowrap;
  259. margin-top: 12rpx;
  260. font-size: 22rpx;
  261. color: #666666;
  262. }
  263. }
  264. }
  265. </style>