discern.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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/img/insect.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/img/plant.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" v-if="token">
  32. <button class="btn" @click="openExpert">专家指导</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. token: ''
  45. };
  46. },
  47. async onLoad(options) {
  48. await this.$onLaunched;
  49. this.token = options.token;
  50. },
  51. methods: {
  52. openExpert(e) {
  53. uni.navigateTo({
  54. url: `expert?token=${this.token}`
  55. })
  56. },
  57. /**
  58. * 开始识别
  59. * @param {String} type 识别类型 insect:虫害,plant:病害
  60. */
  61. async startDiscern(type) {
  62. let file = await this.uploadImageSync();
  63. if (!file) {
  64. return;
  65. }
  66. let result; // 识别结果
  67. this.$api.loading('识别中...');
  68. // 识别虫害
  69. if (type == 'insect') {
  70. result = await handleInsectDiscern(file)
  71. }
  72. // 识别病害
  73. if (type == 'plant') {
  74. result = await handlePlantDiscern(file)
  75. }
  76. this.$api.hide();
  77. if (!result) {
  78. return;
  79. }
  80. this.openDiscernResult(result);
  81. },
  82. // 打开识别结果
  83. openDiscernResult(item) {
  84. uni.navigateTo({
  85. url: `discern-result?params=${JSON.stringify(item)}`
  86. })
  87. },
  88. uploadImageSync() {
  89. return new Promise((resolve, reject) => {
  90. uni.chooseImage({
  91. count: 1, // 默认9
  92. sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
  93. sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
  94. success(res) {
  95. resolve(res.tempFiles[0]);
  96. },
  97. fail(e) {
  98. resolve(null);
  99. }
  100. })
  101. })
  102. }
  103. }
  104. }
  105. </script>
  106. <style lang="scss">
  107. .media-item {
  108. position: relative;
  109. display: flex;
  110. padding-top: 24rpx;
  111. padding-bottom: 24rpx;
  112. background-color: #fff;
  113. border-bottom: 1rpx solid #F5F5F5;
  114. &:first-child {
  115. padding-top: 0;
  116. }
  117. &:last-child {
  118. padding-bottom: 0;
  119. border: none;
  120. }
  121. }
  122. .media-hd {
  123. overflow: hidden;
  124. width: 336rpx;
  125. height: 255rpx;
  126. margin-right: 32rpx;
  127. border-radius: 6rpx;
  128. }
  129. .media-bd {
  130. display: flex;
  131. flex: 1;
  132. flex-direction: column;
  133. align-items: flex-start;
  134. .title {
  135. margin-bottom: 5rpx;
  136. font-size: 32rpx;
  137. color: #333333;
  138. line-height: 45rpx;
  139. }
  140. .text {
  141. display: -webkit-box;
  142. -webkit-line-clamp: 4;
  143. -webkit-box-orient: vertical;
  144. overflow: hidden;
  145. text-overflow: ellipsis;
  146. font-size: 24rpx;
  147. color: #999999;
  148. line-height: 34rpx;
  149. }
  150. .btn {
  151. height: 60rpx;
  152. margin-top: 16rpx;
  153. margin-right: 0;
  154. font-size: 24rpx;
  155. }
  156. }
  157. .btn-box {
  158. padding: 180rpx 24rpx 100rpx;
  159. overflow: hidden;
  160. }
  161. </style>