coys 2 tahun lalu
induk
melakukan
503446829e

+ 4 - 1
src/components/nfcPopup/alone.vue

@@ -29,6 +29,7 @@
 import { baseImg } from '@/views/menu/LZRegister/api'
 import { upload, uploadBase64 } from '@/api/public'
 import ImageCompressor from 'js-image-compressor'
+import {imgUrl} from "@/utils";
 import { Toast } from 'vant'
 export default {
   name: 'index',
@@ -72,14 +73,16 @@ export default {
       uploadBase64(params)
         .then(res => {
           /*上传成功*/
+          
           this.$toast.success('上传成功')
           this.visible=false
+          
           this.imageList.push({ name: res.data.name, url: imgUrl(res.data.url), imgPath: res.data.url })
           this.$emit('input', this.imageList)
         })
         .catch(err => {
           /*上传失败*/
-          
+          console.log(err);
           this.$toast.fail('上传失败')
           this.fileList.splice(this.fileList.length - 1, 1)
         })

+ 153 - 98
src/components/upload/index.vue

@@ -5,18 +5,20 @@
       ref="uploader"
       v-bind="$attrs"
       v-model="fileList"
-      :before-read="beforeRead"
-      :after-read="afterRead"
       :max-count="maxCount"
       :multiple="multiple"
+      @click-upload="useCamera(2)"
       @delete="deleteHandler"
       :max-size="maxSize * 1024 * 1024"
-      
     />
+    <!-- :after-read="afterRead" -->
+    <!-- :before-read="beforeRead" -->
   </div>
 </template>
 <script>
-import { upload } from '@/api/public'
+import { imgUrl } from '@/utils'
+import { uploadBase64 } from '@/api/public'
+
 import ImageCompressor from 'js-image-compressor'
 import config from '@/config/index'
 export default {
@@ -47,13 +49,15 @@ export default {
     }
   },
 
-  mounted() {},
+  mounted() {
+    window.openCameraCallBack = this.openCameraCallBack
+  },
   watch: {
     value: {
       handler(val) {
         this.imageList = this.fileList = val.map(v => {
           let imgUrl = process.env.NODE_ENV === 'development' ? '/dev' + v.path : window.origin + v.path
-          console.log(imgUrl)
+          
           return {
             name: v.name,
             url: imgUrl,
@@ -66,105 +70,156 @@ export default {
     }
   },
   methods: {
-    //上传前压缩
-    beforeRead(file) {
-      console.log(file, '图片压缩前')
-      //当前是多文件的时候
-      if (file.length > 1) {
-        let list = []
-        for (let index = 0; index < file.length; index++) {
-          const element = file[index]
-          list.push(
-            new Promise((resolve, reject) => {
-              new ImageCompressor({
-                file: element,
-                quality: 0.6,
-                success: result => {
-                  console.log(result, '图片压缩后')
-                  let imgFile = new File([result], result.name, {
-                    width: result.width,
-                    height: result.height,
-                    type: result.type
-                  })
-                  console.log(imgFile, '后')
-                  resolve(imgFile)
-                },
-                error: e => {
-                  this.$toast(e)
-                  reject(e)
-                }
-              })
-            })
-          )
-          return list
+    useCamera(actionType) {
+      window.openCameraCallBack = null
+      window.openCameraCallBack = this.openCameraCallBack
+      let parms = {}
+      if (actionType) {
+        parms.actionType = actionType
+      }
+      let system = this.isAndroidOrIos()
+      if (system === 1) {
+        //android
+        // 判断当前环境是是否存在 js桥 'sap'
+        const hasSap = window.hasOwnProperty('sap')
+        if (hasSap) {
+          // 判断是否存在方法 ?preview
+          const fun = sap.hasOwnProperty('openCamera')
+          if (fun) {
+            sap.openCamera(JSON.stringify(parms))
+          }
         }
-      } else {
-        return new Promise((resolve, reject) => {
-          new ImageCompressor({
-            file,
-            quality: 0.6,
-            success: result => {
-              console.log(result, '图片压缩后')
-              let imgFile = new File([result], result.name, {
-                width: result.width,
-                height: result.height,
-                type: result.type
-              })
-              console.log(imgFile, '后')
-              resolve(imgFile)
-            },
-            error: e => {
-              this.$toast(e)
-              reject(e)
-            }
-          })
-        })
       }
-    },
-    //上传到服务器
-    afterRead(fileObj) {
-      console.log(fileObj)
-      //多文件上传
-      if (this.multiple&&fileObj instanceof Array) {
-        for (let index = 0; index < fileObj.length; index++) {
-          const element = fileObj[index]
-          let formData = new FormData()
-          formData.append('file', element.file)
-          upload(formData, 'image')
-            .then(res => {
-              
-              /*上传成功*/
-              let imgUrl =
-                process.env.NODE_ENV === 'development' ? config.baseUrl + res.data.url : window.origin + res.data.url
-
-              this.imageList.push({ name: res.data.name, url: imgUrl, path: res.data.url })
-              this.$emit('input', this.imageList)
-            })
-            .catch(err => {
-              /*上传失败*/
 
-              this.$toast.fail('上传失败')
-            })
+      if (system === 2) {
+        //ios
+        // 判断 ios是否存在方法 preview
+        const preview = window.webkit.messageHandlers.hasOwnProperty('openCamera')
+        if (preview) {
+          window.webkit.messageHandlers.openCamera.postMessage(JSON.stringify(parms))
         }
-      } else {
-        let formData = new FormData()
-        formData.append('file', fileObj.file)
-        upload(formData, 'image')
-          .then(res => {
-            /*上传成功*/
-            let imgUrl =
-              process.env.NODE_ENV === 'development' ? config.baseUrl + res.data.url : window.origin + res.data.url
-
-            this.imageList.push({ name: res.data.name, url: imgUrl, path: res.data.url })
-            this.$emit('input', this.imageList)
-          })
-          .catch(err => {
-            /*上传失败*/
+      }
+    },
 
-            this.$toast.fail('上传失败')
-          })
+    openCameraCallBack(data) {
+      let img = JSON.parse(data)
+      this.content = data
+      let params = {
+        extension: img.extension,
+        content: img.content
       }
+      uploadBase64(params)
+        .then(res => {
+          /*上传成功*/
+          this.$toast.success('上传成功')
+          this.imageList.push({ name: res.data.name, url: imgUrl(res.data.url), path: res.data.url })
+          this.$emit('input', this.imageList)
+        })
+        .catch(err => {
+          /*上传失败*/
+          this.$toast.fail('上传失败')
+          this.fileList.splice(this.fileList.length - 1, 1)
+        })
     },
+    // //上传前压缩
+    // beforeRead(file) {
+    //   console.log(file, '图片压缩前')
+    //   //当前是多文件的时候
+    //   if (file.length > 1) {
+    //     let list = []
+    //     for (let index = 0; index < file.length; index++) {
+    //       const element = file[index]
+    //       list.push(
+    //         new Promise((resolve, reject) => {
+    //           new ImageCompressor({
+    //             file: element,
+    //             quality: 0.6,
+    //             success: result => {
+    //               console.log(result, '图片压缩后')
+    //               let imgFile = new File([result], result.name, {
+    //                 width: result.width,
+    //                 height: result.height,
+    //                 type: result.type
+    //               })
+    //               console.log(imgFile, '后')
+    //               resolve(imgFile)
+    //             },
+    //             error: e => {
+    //               this.$toast(e)
+    //               reject(e)
+    //             }
+    //           })
+    //         })
+    //       )
+    //       return list
+    //     }
+    //   } else {
+    //     return new Promise((resolve, reject) => {
+    //       new ImageCompressor({
+    //         file,
+    //         quality: 0.6,
+    //         success: result => {
+    //           console.log(result, '图片压缩后')
+    //           let imgFile = new File([result], result.name, {
+    //             width: result.width,
+    //             height: result.height,
+    //             type: result.type
+    //           })
+    //           console.log(imgFile, '后')
+    //           resolve(imgFile)
+    //         },
+    //         error: e => {
+    //           this.$toast(e)
+    //           reject(e)
+    //         }
+    //       })
+    //     })
+    //   }
+    // },
+    // //上传到服务器
+    // afterRead(fileObj) {
+    //   console.log(fileObj)
+    //   //多文件上传
+    //   if (this.multiple&&fileObj instanceof Array) {
+    //     for (let index = 0; index < fileObj.length; index++) {
+    //       const element = fileObj[index]
+    //       let formData = new FormData()
+    //       formData.append('file', element.file)
+    //       upload(formData, 'image')
+    //         .then(res => {
+
+    //           /*上传成功*/
+    //           let imgUrl =
+    //             process.env.NODE_ENV === 'development' ? config.baseUrl + res.data.url : window.origin + res.data.url
+
+    //           this.imageList.push({ name: res.data.name, url: imgUrl, path: res.data.url })
+    //           this.$emit('input', this.imageList)
+    //         })
+    //         .catch(err => {
+    //           /*上传失败*/
+
+    //           this.$toast.fail('上传失败')
+    //         })
+    //     }
+    //   } else {
+    //     let formData = new FormData()
+    //     formData.append('file', fileObj.file)
+    //     upload(formData, 'image')
+    //       .then(res => {
+    //         /*上传成功*/
+    //         let imgUrl =
+    //           process.env.NODE_ENV === 'development' ? config.baseUrl + res.data.url : window.origin + res.data.url
+
+    //         this.imageList.push({ name: res.data.name, url: imgUrl, path: res.data.url })
+    //         this.$emit('input', this.imageList)
+    //       })
+    //       .catch(err => {
+    //         /*上传失败*/
+
+    //         this.$toast.fail('上传失败')
+    //       })
+    //   }
+    // },
     //删除
     deleteHandler() {
       let imageList = JSON.parse(JSON.stringify(this.fileList))

+ 1 - 1
src/utils/request.js

@@ -7,7 +7,7 @@ import { baseApi } from '@/config'
 // create an axios instance
 const service = axios.create({
   baseURL: baseApi, // url = base api url + request url
-  // baseURL: '/dev', // url = base api url + request url
+  // baseURL: 'http://10.87.10.55:8080', // url = base api url + request url
   withCredentials: false, // send cookies when cross-domain requests
   timeout: 15000 // request timeout
 })

+ 6 - 21
src/views/home/works.vue

@@ -40,8 +40,7 @@
               class="mainTitle"
               :value="worksLink(2, item.taskType, i.recStatus ? i.recStatus : i.status)"
               :label="i.startTime + '-' + i.endTime"
-              
-              :value-class="i.status == 0  ? `title-blue` : `title-orange`"
+              :value-class="i.status == 0 ? `title-blue` : `title-orange`"
             >
               <template #title>
                 <span class="custom-title"
@@ -55,7 +54,7 @@
                   ></span
                 >
               </template>
-             
+
               <template #right-icon>
                 <van-icon name="arrow" class="rightIcon" @click="isFalgHandler(i, item.taskType, item.id)" />
               </template>
@@ -67,7 +66,7 @@
         </div>
       </div>
       <!-- 扫描弹框 -->
-      <scandialog ref="scandialog" @change="resultImg" @changeNFC="getNFC"></scandialog>
+      <scandialog ref="scandialog" @input="resultImg" @changeNFC="getNFC"></scandialog>
     </div>
   </div>
 </template>
@@ -217,7 +216,7 @@ export default {
         if (val == 0 && taskType == 2) {
           strName = '进行中'
         }
-        
+
         //监控调阅
         if (val == 3 && taskType == 1) {
           strName = '调阅中'
@@ -279,21 +278,7 @@ export default {
     //监控调阅待调阅弹框处理
     //文件上传
     resultImg(img) {
-      let obj = base64ToBlob(img.base)
-      let formData = new FormData()
-      obj.name = '调阅.jpg'
-      formData.append('file', base64ToBlob(img.base))
-      upload(formData, 'image')
-        .then(res => {
-          /*上传成功*/
-          let imgUrl = process.env.NODE_ENV === 'development' ? res.data.url : window.origin + res.data.url
-          this.photoHandler(imgUrl)
-
-          // this.$emit("imgUrl", res.data.url);
-        })
-        .catch(err => {
-          /*上传失败*/
-        })
+      this.photoHandler(img[0].url)
     },
     //上传NFC
     getNFC(nfc) {
@@ -426,7 +411,7 @@ a {
   color: inherit;
   margin-right: 10px;
 }
-.rightIcon{
+.rightIcon {
   color: #969799;
   line-height: 46px;
   font-size: 40px;

+ 1 - 1
src/views/menu/monitoringCall/index.vue

@@ -316,7 +316,7 @@ export default {
       })
     },
     //文件上传
-    input(img) {
+    resultImg(img) {
       
       this.photoHandler(img[0].url)
     },