discern.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. // 识别虫害
  58. if (type == 'insect') {
  59. result = await handleInsectDiscern(file)
  60. }
  61. // 识别病害
  62. if (type == 'plant') {
  63. result = await handlePlantDiscern(file)
  64. }
  65. },
  66. uploadImageSync() {
  67. return new Promise((resolve, reject) => {
  68. uni.chooseImage({
  69. count: 1, // 默认9
  70. sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
  71. sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
  72. success(res) {
  73. resolve(res.tempFiles[0]);
  74. },
  75. fail(e) {
  76. resolve(null);
  77. }
  78. })
  79. })
  80. }
  81. }
  82. }
  83. </script>
  84. <style lang="scss">
  85. .media-item {
  86. position: relative;
  87. display: flex;
  88. padding-top: 24rpx;
  89. padding-bottom: 24rpx;
  90. background-color: #fff;
  91. border-bottom: 1rpx solid #F5F5F5;
  92. &:first-child {
  93. padding-top: 0;
  94. }
  95. &:last-child {
  96. padding-bottom: 0;
  97. border: none;
  98. }
  99. }
  100. .media-hd {
  101. overflow: hidden;
  102. width: 336rpx;
  103. height: 255rpx;
  104. margin-right: 32rpx;
  105. border-radius: 6rpx;
  106. }
  107. .media-bd {
  108. display: flex;
  109. flex: 1;
  110. flex-direction: column;
  111. align-items: flex-start;
  112. .title {
  113. margin-bottom: 5rpx;
  114. font-size: 32rpx;
  115. color: #333333;
  116. line-height: 45rpx;
  117. }
  118. .text {
  119. display: -webkit-box;
  120. -webkit-line-clamp: 4;
  121. -webkit-box-orient: vertical;
  122. overflow: hidden;
  123. text-overflow: ellipsis;
  124. font-size: 24rpx;
  125. color: #999999;
  126. line-height: 34rpx;
  127. }
  128. .btn {
  129. height: 60rpx;
  130. margin-top: 16rpx;
  131. margin-right: 0;
  132. font-size: 24rpx;
  133. }
  134. }
  135. .btn-box {
  136. padding: 180rpx 24rpx 100rpx;
  137. overflow: hidden;
  138. }
  139. </style>