photoResults.vue 7.5 KB

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