Ver Fonte

瓦斯巡检图片识别-更新

lxh há 2 semanas atrás
pai
commit
03ce83bf2d
2 ficheiros alterados com 24 adições e 77 exclusões
  1. 4 2
      manifest.json
  2. 20 75
      pages/gasreport/components/gasImgIdentify.vue

+ 4 - 2
manifest.json

@@ -26,7 +26,8 @@
         /* 5+App特有相关 */
         "modules" : {
             "Push" : {},
-            "VideoPlayer" : {}
+            "VideoPlayer" : {},
+            "Camera" : {}
         },
         /* 模块配置 */
         "distribute" : {
@@ -58,7 +59,8 @@
                     "<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>",
                     "<uses-permission android:name=\"android.permission.NFC\"/>",
                     "<uses-sdk android:minSdkVersion=\"10\"/>",
-                    "<uses-feature android:name=\"android.hardware.nfc\" android:required=\"true\" />"
+                    "<uses-feature android:name=\"android.hardware.nfc\" android:required=\"true\" />",
+                    "<uses-permission android:name=\"android.permission.READ_EXTERNAL_STORAGE\"/>"
                 ]
             },
             "ios" : {

+ 20 - 75
pages/gasreport/components/gasImgIdentify.vue

@@ -12,7 +12,7 @@
                         @close="showCalendarTb = false"></u-datetime-picker>
                 </view> -->
                 <u-button type="primary" icon="camera-fill" size="small" @click="chooseImage"
-                    style="margin: 2px 0px;">从相册选取</u-button>
+                    style="margin: 2px 0px;">图片选取</u-button>
                 <!-- 图片预览 -->
                 <view class="imgView">
                     <image v-if="imageSrc" style="width:150px" :src="imageSrc" mode="widthFix"></image>
@@ -297,89 +297,33 @@ export default {
         //获取图片识别数据
         getGasIdentify() {
             let that = this
-            // let formData = new FormData();
-            // formData.append('img', that.imageSrcList[0]);
-            // formData.append('user', that.username);
-            // console.log(that.imageSrcList,formData,'111')
-            // new Promise((resolve, reject) => {
-            //     api
-            //         .gasIdentify({img: that.imageSrcList[0],user:that.username})
-            //         .then((response) => {
-            //             if (response.data.code == 200) {
-            //                 let data = response.data.result
-            //                 console.log(data, '图片识别数据--------')
-            //             } else {
-            //                 reject(response);
-            //             }
-            //         })
-            //         .catch((error) => {
-            //             console.log("catch===>response", response);
-            //             reject(error);
-            //         });
-            // });
             let apiUrl = configService.apiUrl;
-            uni.request({
+            console.log(that.imageSrcList[0])
+            uni.uploadFile({
                 url: `${apiUrl}/gasIdentify`,
-                data: {
-                    img: that.imageSrcList[0].name,
-                    user:that.username
+                filePath: that.imageSrcList[0].path,
+                name: 'img',
+                formData: {
+                    'user': that.username,
                 },
-                method: 'POST', // 参数类型
-                header: {
-                    "Content-Type": "application/x-www-form-urlencoded"
-                }, // 请求头
                 success: (res) => {
-                    console.log(res, 'hhhhhhhhhhhhh')
+                    console.log(res,'识别成功!');
+                    if(res){
+                        that.indexList=res.data.dara
+                    }
+
                 },
-                complete: () => { },
-                fail: (res) => { }
-            })
-
-
-            // this.indexList = [
-            //     {
-            //         "日期": "2025年3月5日",
-            //         "班次": "早班",
-            //         "检查地点": "22106综采工作面设备列车",
-            //         "检查时间": "0:04",
-            //         "CH4%": "0.00",
-            //         "CO2%": "0.04",
-            //         "O2%": "20.9",
-            //         "CO(ppm)": "1",
-            //         "温度(℃)": "17",
-            //         "检查人": "xxx"
-            //     },
-            //     {
-            //         "日期": "2025年3月5日",
-            //         "班次": "早班",
-            //         "检查地点": "22106综采工作面设备列车",
-            //         "检查时间": "8:13",
-            //         "CH4%": "0.00",
-            //         "CO2%": "0.04",
-            //         "O2%": "20.9",
-            //         "CO(ppm)": "1",
-            //         "温度(℃)": "17",
-            //         "检查人": "xxx"
-            //     },
-            //     {
-            //         "日期": "2025年3月5日",
-            //         "班次": "早班",
-            //         "检查地点": "22106综采工作面设备列车",
-            //         "检查时间": "16:15",
-            //         "CH4%": "0.00",
-            //         "CO2%": "0.04",
-            //         "O2%": "20.9",
-            //         "CO(ppm)": "1",
-            //         "温度(℃)": "17",
-            //         "检查人": "xxx"
-            //     }
-
-
-            // ]
+                fail:(errpr)=>{
+                    console.log(error.data,'识别失败!');
+                }
+            });
         },
         // 选择图片的方法
         chooseImage() {
             uni.chooseImage({
+                count: 1, // 默认9,设置图片的最大选择数
+                sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
+                sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
                 success: (res) => {
                     console.log(res, 'res===')
                     // 获取选中的图片路径,这里我们只取第一张图进行预览
@@ -401,6 +345,7 @@ export default {
         delSb() {
             this.indexList = []
             this.indexParam = {}
+            this.imageSrc=''
         },
         //班次下拉选项切换
         changeBc(e) {