photoResults.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. <template>
  2. <view style="background-color: #f7f7f7;padding-top: 88rpx;height: calc(100vh - 88rpx);">
  3. <uni-nav-bar @clickLeft="clickLeft" left-icon="back" title="识别结果" backgroundColor="#F7F7F7"></uni-nav-bar>
  4. <u-calendar v-model="calendarShow" mode="range" @change="change" @maxDate="maxDate"></u-calendar>
  5. <view class="img-result">
  6. <view class="tile-item">
  7. <view @click="calendarShow = true" class="calendar">{{start_time}} <span style="margin: 0 40rpx;"> -</span> {{end_time}}</view>
  8. </view>
  9. <view class="images_box">
  10. <view class="canvas-bg">
  11. <img v-if="photos.length>0" :src="photos[active].addr+'?x-oss-process=image/resize,w_130/quality,q_90'" alt="" @click="examine()"/>
  12. </view>
  13. <view class="image-flex" >
  14. <view v-for="(item,index) in photos" :key="index">
  15. <image class="my-img" :class="active==index?'active':''" :src="item.addr" @click="imgClick(item,index)" mode=""></image>
  16. </view>
  17. </view>
  18. </view>
  19. <view class="information">
  20. <view class="btn">
  21. <p class="title">当前图片识别结果</p>
  22. <u-button size="mini" :loading='respetLoading' class="btn_box" throttle-time="500" @click="resetPest" :customStyle="customStyle">重新识别</u-button>
  23. </view>
  24. <view class="notip" v-if="isObject(pestResult)">
  25. 暂无识别结果
  26. </view>
  27. <view v-else class="information_data" v-for="(value,key) in pestResult">
  28. <p> <span>{{key}}</span> <span>{{value}}头</span> </p>
  29. </view>
  30. </view>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. import jsencrypt from '@/components/jsencrypt/jsencrypt.vue';
  36. import insect_dict from "../../../../static/data/cbd_pest_library.js"
  37. export default {
  38. data() {
  39. return {
  40. maxDate:'2050-12-31',
  41. device_type:'',
  42. device_id:'',
  43. d_id:'',
  44. calendarShow:false,
  45. start_time:'',
  46. end_time:'',
  47. photos:[],
  48. active:0,
  49. respetLoading:false
  50. }
  51. },
  52. computed:{
  53. customStyle(){
  54. return {
  55. background: '#018B3F',
  56. fontSize:'12px',
  57. border:'none',
  58. color:'#fff'
  59. }
  60. },
  61. pestResult(){
  62. if(this.photos==0){
  63. return {}
  64. }
  65. let obj = {}
  66. let item = this.photos[this.active]
  67. console.log('选中',item)
  68. if(item.is_mark==0){
  69. // 机器识别
  70. let aiLabel = []
  71. if (item.label) {
  72. aiLabel = JSON.parse(item.label.replace(/'/g, '"'))
  73. aiLabel.forEach(label => {
  74. const text = Object.keys(label)[0]
  75. if (obj[insect_dict[text]]) {
  76. obj[insect_dict[text]]++
  77. } else {
  78. obj[insect_dict[text]] = 1
  79. }
  80. })
  81. }
  82. }else{
  83. item.mark.forEach(item => {
  84. if (obj[item.text]) {
  85. obj[item.text]++
  86. } else {
  87. obj[item.text] = 1
  88. }
  89. })
  90. }
  91. return obj
  92. },
  93. previewImages(){
  94. let list = []
  95. if(this.photos.length>0){
  96. this.photos.forEach(photo=>{
  97. list.push(photo.addr)
  98. })
  99. return list
  100. }else{
  101. return []
  102. }
  103. }
  104. },
  105. methods: {
  106. clickLeft() {
  107. uni.navigateBack()
  108. },
  109. isObject(obj){
  110. return Object.keys(obj).length==0
  111. },
  112. change(e){
  113. this.start_time = e.startDate
  114. this.end_time = e.endDate
  115. this.page = 1
  116. this.photos = []
  117. this.getImgData()
  118. },
  119. async getImgData(){
  120. const res = await this.$myRequest({
  121. url: '/api/api_gateway?method=new_gateway.photo_info.photo_list',
  122. data: {
  123. id: this.d_id,
  124. device_type_id:this.device_type,
  125. page: 1,
  126. page_number: 99999,
  127. start: +new Date(this.start_time+' 00:00:00') / 1000,
  128. end: +new Date(this.end_time+' 23:59:59') / 1000
  129. }
  130. })
  131. this.photos = this.photos.concat(res.data)
  132. console.log(this.photos,'---')
  133. // this.photos = res.data
  134. },
  135. async resetPest(){
  136. this.respetLoading = true
  137. const res = await this.$myRequest({
  138. url: '/api/api_gateway?method=new_gateway.photo_info.identify_again',
  139. data: {
  140. id: this.photos[this.active].id,
  141. device_type_id:this.device_type
  142. }
  143. })
  144. this.respetLoading = false
  145. if(res.code==2000){
  146. uni.showToast({
  147. title: '操作成功',
  148. duration: 2000
  149. })
  150. }else{
  151. uni.showToast({
  152. title: res.msg,
  153. duration: 2000
  154. })
  155. }
  156. },
  157. examine() {
  158. uni.previewImage({
  159. urls: this.previewImages
  160. });
  161. },
  162. imgClick(item,index){
  163. this.active = index
  164. }
  165. },
  166. onLoad(option) {
  167. console.log('结果页面:',option)
  168. this.device_id = option.device_id
  169. this.d_id = option.d_id
  170. this.device_type = option.device_type
  171. let endTime = +new Date(option.time)/1000 + 60 * 60 * 24
  172. let startTime = +new Date(option.time)/1000
  173. this.end_time = this.formatTime(endTime*1000,'yyyy-MM-dd')
  174. this.start_time = this.formatTime(startTime*1000,'yyyy-MM-dd')
  175. this.getImgData()
  176. }
  177. }
  178. </script>
  179. <style lang="scss" scoped>
  180. /deep/.u-calendar__action {
  181. display: flex;
  182. justify-content: space-around;
  183. .u-calendar__action__text {
  184. line-height: 25px;
  185. }
  186. }
  187. page{
  188. background: #F7F7F7;
  189. }
  190. .img-result{
  191. padding: 0rpx 48rpx;
  192. background-color: #F7F7F7;
  193. // height: calc(100vh - 120rpx);
  194. }
  195. .tile-item{
  196. margin-top: 32rpx;
  197. // padding: 0rpx 32rpx;
  198. box-sizing: border-box;
  199. height: 92rpx;
  200. line-height: 92rpx;
  201. display: flex;
  202. justify-content: space-between;
  203. background: #F7F7F7;
  204. .calendar{
  205. width: 100%;
  206. background-color: #fff;
  207. border-radius: 24rpx;
  208. padding: 0 18rpx;
  209. color: #5C5C5C;
  210. text-align: center;
  211. }
  212. .camera{
  213. }
  214. }
  215. .images_box {
  216. width: 100%;
  217. height: 742rpx;
  218. padding: 32rpx;
  219. margin: 32rpx 0;
  220. box-sizing: border-box;
  221. background: #fff;
  222. border-radius: 24rpx;
  223. .canvas-bg{
  224. height: 558rpx;
  225. position: relative;
  226. margin-bottom: 16rpx;
  227. img{
  228. width: 100%;
  229. height: 100%;
  230. }
  231. }
  232. .image-flex {
  233. width: 100%;
  234. overflow-x: scroll;
  235. display: flex;
  236. flex-wrap: nowrap;
  237. gap: 20rpx;
  238. padding: 10rpx 0;
  239. box-sizing: border-box;
  240. .my-img {
  241. width: 96rpx;
  242. height: 96rpx;
  243. border-radius: 4rpx;
  244. opacity: 0.5;
  245. }
  246. .active{
  247. border: 4px solid #ccc;
  248. animation: borderAnimation 1s;
  249. position: relative;
  250. top: -4px;
  251. opacity: 1;
  252. }
  253. }
  254. }
  255. .information {
  256. padding-bottom: 2rpx;
  257. .btn{
  258. overflow: hidden;
  259. }
  260. .title {
  261. float: left;
  262. color: #999999;
  263. }
  264. .notip{
  265. text-align: center;
  266. color: #999999;
  267. margin-top: 100rpx;
  268. }
  269. .btn_box{
  270. float: right;
  271. // border-radius: 8rpx;
  272. // background: #018B3F;
  273. // padding: 2rpx 10rpx;
  274. // color: #fff;
  275. // font-size: 24rpx;
  276. }
  277. .information_data {
  278. margin: 32rpx 0;
  279. display: flex;
  280. background-color: #fff;
  281. // padding: 20rpx 10rpx;
  282. height: 104rpx;
  283. line-height: 104rpx;
  284. border-radius: 24rpx;
  285. padding: 0 32rpx;
  286. p {
  287. // margin-right: 20rpx;
  288. font-size: 24rpx;
  289. color: #666666;
  290. }
  291. }
  292. }
  293. @keyframes borderAnimation {
  294. 0% {
  295. opacity: 0.5;
  296. }
  297. 100% {
  298. opacity: 1;
  299. }
  300. }
  301. </style>