discern.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <!-- 病虫害识别技术 -->
  3. <view>
  4. <view class="page-panel">
  5. <!-- 识别列表 -->
  6. <view class="media-item">
  7. <view class="media-hd">
  8. <image src="@/static/demo/demo1.png" mode="aspectFill"></image>
  9. </view>
  10. <view class="media-bd">
  11. <view class="title">虫害识别技术</view>
  12. <view class=" flex-1 text">
  13. 介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字
  14. </view>
  15. <button class="btn" @click="startDiscern('insect')">我要识别</button>
  16. </view>
  17. </view>
  18. <view class="media-item">
  19. <view class="media-hd">
  20. <image src="@/static/demo/demo1.png" mode="aspectFill"></image>
  21. </view>
  22. <view class="media-bd">
  23. <view class="title">病害识别技术</view>
  24. <view class=" flex-1 text">
  25. 介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字
  26. </view>
  27. <button class="btn" @click="startDiscern('plant')">我要识别</button>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="btn-box">
  32. <button class="btn">专家指导</button>
  33. </view>
  34. </view>
  35. </template>
  36. <script>
  37. import {
  38. handlePlantDiscern,
  39. handleInsectDiscern
  40. } from '@/api/pest.js'
  41. export default {
  42. data() {
  43. return {
  44. };
  45. },
  46. methods: {
  47. /**
  48. * 开始识别
  49. * @param {String} type 识别类型 insect:虫害,plant:病害
  50. */
  51. async startDiscern(type) {
  52. let file = await this.uploadImageSync();
  53. if (!file) {
  54. return;
  55. }
  56. let result; // 识别结果
  57. this.$api.loading('识别中...');
  58. // 识别虫害
  59. if (type == 'insect') {
  60. result = await handleInsectDiscern(file)
  61. }
  62. // 识别病害
  63. if (type == 'plant') {
  64. result = await handlePlantDiscern(file)
  65. }
  66. this.$api.hide();
  67. if (!result) {
  68. return;
  69. }
  70. this.openDiscernResult(result);
  71. },
  72. // 打开识别结果
  73. openDiscernResult(item){
  74. uni.navigateTo({
  75. url:`discern-result?params=${JSON.stringify(item)}`
  76. })
  77. },
  78. uploadImageSync() {
  79. return new Promise((resolve, reject) => {
  80. uni.chooseImage({
  81. count: 1, // 默认9
  82. sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
  83. sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
  84. success(res) {
  85. resolve(res.tempFiles[0]);
  86. },
  87. fail(e) {
  88. resolve(null);
  89. }
  90. })
  91. })
  92. }
  93. }
  94. }
  95. </script>
  96. <style lang="scss">
  97. .media-item {
  98. position: relative;
  99. display: flex;
  100. padding-top: 24rpx;
  101. padding-bottom: 24rpx;
  102. background-color: #fff;
  103. border-bottom: 1rpx solid #F5F5F5;
  104. &:first-child {
  105. padding-top: 0;
  106. }
  107. &:last-child {
  108. padding-bottom: 0;
  109. border: none;
  110. }
  111. }
  112. .media-hd {
  113. overflow: hidden;
  114. width: 336rpx;
  115. height: 255rpx;
  116. margin-right: 32rpx;
  117. border-radius: 6rpx;
  118. }
  119. .media-bd {
  120. display: flex;
  121. flex: 1;
  122. flex-direction: column;
  123. align-items: flex-start;
  124. .title {
  125. margin-bottom: 5rpx;
  126. font-size: 32rpx;
  127. color: #333333;
  128. line-height: 45rpx;
  129. }
  130. .text {
  131. display: -webkit-box;
  132. -webkit-line-clamp: 4;
  133. -webkit-box-orient: vertical;
  134. overflow: hidden;
  135. text-overflow: ellipsis;
  136. font-size: 24rpx;
  137. color: #999999;
  138. line-height: 34rpx;
  139. }
  140. .btn {
  141. height: 60rpx;
  142. margin-top: 16rpx;
  143. margin-right: 0;
  144. font-size: 24rpx;
  145. }
  146. }
  147. .btn-box {
  148. padding: 180rpx 24rpx 100rpx;
  149. overflow: hidden;
  150. }
  151. </style>