photoResults.vue 7.8 KB

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