Browse Source

h5拍照的base64转换后上传

xuqiaoying 2 years ago
parent
commit
a0ca4aa68c
3 changed files with 25 additions and 7 deletions
  1. 4 2
      App.vue
  2. 1 1
      manifest.json
  3. 20 4
      pages3/polyv/detail.vue

+ 4 - 2
App.vue

@@ -1,6 +1,8 @@
 <script>
 import plv from "./pages3/static/polyv-sdk/index";
+// #ifdef H5
 import vconsole from 'vconsole';
+// #endif
 export default {
   onLaunch: function (option) {
     let inviteCode = option.inviteCode;
@@ -17,14 +19,14 @@ export default {
   methods: {},
   onShow: function (option) {
     this.$store.commit('setScene', option.scene || 0)
-    //#ifdef H5
+    // #ifdef H5
     if (process.env.NODE_ENV === 'development') {
       console.log('开发环境')
       const consoleObj = new vconsole()
     } else {
       console.log('生产环境')
     }
-    //#endif
+    // #endif
   },
   onHide: function () {
     uni.$emit("playPause");

+ 1 - 1
manifest.json

@@ -1,6 +1,6 @@
 {
     "name" : "Applet",
-    "appid" : "",
+    "appid" : "__UNI__F4122BF",
     "description" : "",
     "versionName" : "1.0.0",
     "versionCode" : "100",

+ 20 - 4
pages3/polyv/detail.vue

@@ -2602,10 +2602,24 @@ export default {
             self.$method.showToast("上传路径报错" + JSON.stringify(res.data));
             return;
           }
+          let filePath = ''
+          // #ifdef MP-WEIXIN
+          filePath = options
+          // #endif
+          // #ifdef H5
+          let bytes = window.atob(options.split(",")[1]);
+          let ab = new ArrayBuffer(bytes.length);
+          let ia = new Uint8Array(ab);
+          for (let i = 0; i < bytes.length; i++) {
+            ia[i] = bytes.charCodeAt(i);
+          }
+          filePath = new Blob([ab], { type: "image/jpeg" });
+          // #endif
+          console.log('filePath:', filePath);
           uni.uploadFile({
             url: ossToken.host,
             name: "file",
-            filePath: options,
+            filePath: filePath,
             fileType: "image",
             header: {
               AuthorizationToken: "WX " + uni.getStorageSync("token"),
@@ -2646,6 +2660,7 @@ export default {
       });
     },
     imageInfos() {
+      console.log('avatarUrl:', this.avatarUrl);
       var self = this;
       return new Promise(async (resolve, reject) => {
         // #ifdef MP-WEIXIN
@@ -2967,7 +2982,7 @@ export default {
             //   gradeId: this.gradeId,
             // })
             
-            this.CompareFace(base64)
+            this.CompareFace(base64, resolve)
           },
           fail(err) {
             // this.$u.toast('人脸识别错误!')
@@ -2976,11 +2991,11 @@ export default {
         });
         // #endif
         // #ifdef H5
-        this.CompareFace(this.faceUrl)
+        this.CompareFace(this.faceUrl, resolve)
         // #endif
       });
     },
-    CompareFace(url) {
+    CompareFace(url, resolve) {
       let timer = setTimeout(() => {
         uni.showToast({
           icon: "none",
@@ -3106,6 +3121,7 @@ export default {
         quality: "high",
         success: (res) => {
           this.avatarUrl = res.tempImagePath;
+          console.log('开始拍照this.avatarUrl:', this.avatarUrl);
           this.isTaking = false;
         },
         fail: (err) => {