photoImage.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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="item.addr"
  24. mode="aspectFill"
  25. />
  26. </view>
  27. <view class="photo-image__item-time">
  28. {{ formatItemTime(item) }}
  29. </view>
  30. </view>
  31. </view>
  32. </view>
  33. <view v-else>
  34. <u-empty text="暂无图片"></u-empty>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. export default {
  40. props:{
  41. disableShow:{
  42. type: Boolean,
  43. default: true
  44. },
  45. pestList:{
  46. type: Array,
  47. default: () => []
  48. },
  49. images:{
  50. type: Array,
  51. default: () => []
  52. },
  53. deviceInfo:{
  54. type: Object,
  55. default: () => ({})
  56. },
  57. currentYear:{
  58. type: String | Number,
  59. default: ''
  60. },
  61. // 孢子仪2.1(device_code=1):点击图片带整组图片跳 bzy2/devicePhoto
  62. sporeTwo:{
  63. type: Boolean,
  64. default: false
  65. },
  66. // 当前选中的文件夹id
  67. folderId:{
  68. type: [String, Number],
  69. default: ''
  70. },
  71. },
  72. data() {
  73. return {
  74. activeIndexList:[],
  75. activePest:[],
  76. activeTab: 0,
  77. tabs: ['全部', '稻飞虱', '水龟虫', '蝼蛄', '系统','全部', '稻飞虱', '水龟虫', '蝼蛄', '系统'],
  78. };
  79. },
  80. methods: {
  81. changeTab(index) {
  82. if(this.activeIndexList.includes(index)){
  83. this.activePest = this.activePest.filter(item => item !== this.pestList[index])
  84. this.activeIndexList = this.activeIndexList.filter(item => item !== index)
  85. }else{
  86. this.activeIndexList.push(index)
  87. this.activePest.push(this.pestList[index])
  88. }
  89. this.$emit('changeTab', this.activePest)
  90. },
  91. // 格式化时间
  92. formatDate(dateString) {
  93. const date = new Date(dateString*1000);
  94. const year = date.getFullYear();
  95. const month = String(date.getMonth() + 1).padStart(2, '0');
  96. const day = String(date.getDate()).padStart(2, '0');
  97. const hour = String(date.getHours()).padStart(2, '0');
  98. const minute = String(date.getMinutes()).padStart(2, '0');
  99. const second = String(date.getSeconds()).padStart(2, '0');
  100. return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
  101. },
  102. // 优先取文件名里的拍摄时间(20260905110150z0x0_sharp_1.jpg),孢子仪2.1所有图的addtime都是文件夹时间
  103. formatItemTime(item) {
  104. const match = String(item.addr || '').match(/(\d{14})/);
  105. if (match) {
  106. const s = match[1];
  107. return `${s.slice(0, 4)}-${s.slice(4, 6)}-${s.slice(6, 8)} ${s.slice(8, 10)}:${s.slice(10, 12)}:${s.slice(12, 14)}`;
  108. }
  109. return this.formatDate(item.addtime);
  110. },
  111. handleClick(item) {
  112. if (this.sporeTwo) {
  113. // 孢子仪2.1:整组图片放 storage 带过去,详情页本地渲染
  114. uni.setStorageSync('bzy_two_folder_imgs', JSON.stringify(this.images || []));
  115. uni.navigateTo({
  116. url: '/pages/bzy2/devicePhoto?spore_two=1&img_id=' + item?.id + '&addtime=' + item?.addtime + '&fold_id=' + this.folderId + '&id=' + this.deviceInfo.id
  117. });
  118. return;
  119. }
  120. uni.navigateTo({
  121. url: '/pages/bzy/devicePhoto?device_id=' + item?.device_id + '&addtime=' + item?.addtime + '&img_id=' + item?.id + '&id=' + this.deviceInfo.id + '&currentYear=' + this.currentYear
  122. })
  123. }
  124. },
  125. };
  126. </script>
  127. <style lang="scss" scoped>
  128. .photo-image {
  129. width: 100%;
  130. box-sizing: border-box;
  131. &__header {
  132. margin-bottom: 32rpx;
  133. white-space: nowrap;
  134. &::-webkit-scrollbar {
  135. display: none;
  136. }
  137. }
  138. &__tabs {
  139. box-sizing: border-box;
  140. width: 100%;
  141. overflow-x: auto;
  142. overflow-y: hidden;
  143. white-space: nowrap;
  144. // 去掉滚动条
  145. -ms-overflow-style: none;
  146. scrollbar-width: none;
  147. }
  148. .photo-image__content{
  149. padding: 30rpx;
  150. background: #ffffff;
  151. border-radius: 16rpx;
  152. .photo-image__grid{
  153. display: grid;
  154. grid-template-columns: repeat(3, 1fr);
  155. gap: 20rpx;
  156. }
  157. }
  158. &__tab {
  159. position: relative;
  160. display: inline-block;
  161. box-sizing: border-box;
  162. margin-right: 16rpx;
  163. background: #ffffff;
  164. color: #999999;
  165. font-family: "Source Han Sans CN VF";
  166. font-size: 28rpx;
  167. padding: 10rpx 32rpx;
  168. border-radius: 8rpx;
  169. &:last-child {
  170. margin-right: 0;
  171. }
  172. .tab-text {
  173. margin-right: 8rpx;
  174. }
  175. .tab-check {
  176. color: #4CAF50;
  177. font-weight: bold;
  178. }
  179. &.active {
  180. color: #0bbc58;
  181. }
  182. .tab-underline {
  183. position: absolute;
  184. bottom: 0;
  185. left: 0;
  186. right: 0;
  187. height: 4rpx;
  188. background: #4CAF50;
  189. border-radius: 2rpx;
  190. }
  191. }
  192. &__item {
  193. position: relative;
  194. width: 100%;
  195. padding: 0rpx;
  196. box-sizing: border-box;
  197. display: inline-block;
  198. overflow: hidden;
  199. border:2rpx solid #e4e7ed;
  200. border-radius: 16rpx;
  201. &-img-container {
  202. width: 100%;
  203. padding-bottom: 100%;
  204. position: relative;
  205. border-radius: 16rpx;
  206. overflow: hidden;
  207. background-color: #f5f5f5;
  208. }
  209. &-img {
  210. position: absolute;
  211. top: 0;
  212. left: 0;
  213. width: 100%;
  214. height: 100%;
  215. }
  216. &-time {
  217. position: absolute;
  218. bottom: 0rpx;
  219. width: 100%;
  220. text-align: center;
  221. padding: 0;
  222. overflow: hidden;
  223. text-overflow: ellipsis;
  224. white-space: nowrap;
  225. margin-top: 12rpx;
  226. font-size: 22rpx;
  227. color: #fff;
  228. text-align: center;
  229. background-color: rgba(0, 0, 0, 0.5);
  230. }
  231. }
  232. }
  233. </style>