photoResults.vue 6.9 KB

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