| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- <template>
- <!-- 病虫害识别技术 -->
- <view>
- <view class="page-panel">
- <!-- 识别列表 -->
- <view class="media-item">
- <view class="media-hd">
- <image src="@/static/img/insect.png" mode="aspectFill"></image>
- </view>
- <view class="media-bd">
- <view class="title">虫害识别技术</view>
- <view class=" flex-1 text">
- 模型和算法训练对虫害种类进行识别
- </view>
- <button class="btn" @click="startDiscern('insect')">我要识别</button>
- </view>
- </view>
- <view class="media-item">
- <view class="media-hd">
- <image src="@/static/img/plant.png" mode="aspectFill"></image>
- </view>
- <view class="media-bd">
- <view class="title">病害识别技术</view>
- <view class=" flex-1 text">
- 通过模型和算法训练对病害进行识别
- </view>
- <button class="btn" @click="startDiscern('plant')">我要识别</button>
- </view>
- </view>
- </view>
- <view class="btn-box" v-if="token">
- <button class="btn" @click="openExpert">专家指导</button>
- </view>
- </view>
- </template>
- <script>
- import {
- handlePlantDiscern,
- handleInsectDiscern
- } from '@/api/pest.js'
- export default {
- data() {
- return {
- token: ''
- };
- },
- async onLoad(options) {
- await this.$onLaunched;
- this.token = options.token;
- },
- methods: {
- openExpert(e) {
- uni.navigateTo({
- url: `expert?token=${this.token}`
- })
- },
- /**
- * 开始识别
- * @param {String} type 识别类型 insect:虫害,plant:病害
- */
- async startDiscern(type) {
- let file = await this.uploadImageSync();
- if (!file) {
- return;
- }
- let result; // 识别结果
- this.$api.loading('识别中...');
- // 识别虫害
- if (type == 'insect') {
- result = await handleInsectDiscern(file)
- }
- // 识别病害
- if (type == 'plant') {
- result = await handlePlantDiscern(file)
- }
- this.$api.hide();
- if (!result) {
- return;
- }
- this.openDiscernResult(result);
- },
- // 打开识别结果
- openDiscernResult(item) {
- uni.navigateTo({
- url: `discern-result?params=${JSON.stringify(item)}`
- })
- },
- uploadImageSync() {
- return new Promise((resolve, reject) => {
- uni.chooseImage({
- count: 1, // 默认9
- sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
- sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
- success(res) {
- resolve(res.tempFiles[0]);
- },
- fail(e) {
- resolve(null);
- }
- })
- })
- }
- }
- }
- </script>
- <style lang="scss">
- .media-item {
- position: relative;
- display: flex;
- padding-top: 24rpx;
- padding-bottom: 24rpx;
- background-color: #fff;
- border-bottom: 1rpx solid #F5F5F5;
- &:first-child {
- padding-top: 0;
- }
- &:last-child {
- padding-bottom: 0;
- border: none;
- }
- }
- .media-hd {
- overflow: hidden;
- width: 336rpx;
- height: 255rpx;
- margin-right: 32rpx;
- border-radius: 6rpx;
- }
- .media-bd {
- display: flex;
- flex: 1;
- flex-direction: column;
- align-items: flex-start;
- .title {
- margin-bottom: 5rpx;
- font-size: 32rpx;
- color: #333333;
- line-height: 45rpx;
- }
- .text {
- display: -webkit-box;
- -webkit-line-clamp: 4;
- -webkit-box-orient: vertical;
- overflow: hidden;
- text-overflow: ellipsis;
- font-size: 24rpx;
- color: #999999;
- line-height: 34rpx;
- }
- .btn {
- height: 60rpx;
- margin-top: 16rpx;
- margin-right: 0;
- font-size: 24rpx;
- }
- }
- .btn-box {
- padding: 180rpx 24rpx 100rpx;
- overflow: hidden;
- }
- </style>
|