wenbobowen il y a 4 ans
Parent
commit
b60de23912
1 fichiers modifiés avec 25 ajouts et 36 suppressions
  1. 25 36
      src/components/input/normalArea.vue

+ 25 - 36
src/components/input/normalArea.vue

@@ -146,36 +146,25 @@ export default {
       return newStr
     },
     uploadImg(imgData) {
-      // var fd = new FormData();
-      // fd.append('file', this.base64Url2Blob(imgData));
-      // fd.append('innerPublic',true);
-      // const config = {
-      //   headers: {
-      //     // 'Content-Type': 'multipart/form-data'
-      //     'Content-Type': 'application/x-www-form-urlencoded',
-      //     'referer': 'https://xingyun.xiaojukeji.com'
-      //   },
-      //   // withCredentials: false
-      // } // 添加请求头
-      var HTTP = axios.create({
-        baseURL: '/apis', //这是基础url
-        headers: {'Content-Type': 'application/x-www-form-urlencoded'},
-        transformRequest: [function (data) {
+      const HTTP = axios.create({
+        baseURL: '/apis', // 这是基础url
+        headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
+        transformRequest: [(data) => {
           // Do whatever you want to transform the data
           let ret = ''
-          for (let it in data) {
+          for (const it in data) {
             ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
           }
           return ret
         }]
       })
-      HTTP.post('//star.xiaojukeji.com/upload/img.node',{
+      HTTP.post('//star.xiaojukeji.com/upload/img.node', {
         'imgData': imgData,
         'innerPublic': true
+      }).then((res) => {
+        // console.log(res.url)
+        return res.url
       })
-      .then(function(response){
-          console.log(response.data);
-      });
       // return new Promise((resolve, reject) => {
       //   axios.post(
       //     '//star.xiaojukeji.com/upload/img.node',
@@ -194,22 +183,22 @@ export default {
       //   })
       // })
     },
-    base64Url2Blob (url) {
-      // 将base64url通过 , 分割为含有两个元素的数组
-      const temp = url.split(',')
-        // 将图片的base64编码数据解码
-      const bytes = window.atob(temp[1])
-      // 匹配图片的 mime
-      const mime = temp[0].match(/:(.*?);/)[1]
-        // 创建一个类型化数组,该数组的长度与解码后的图片数据长度相同
-      let ia = new Uint8Array(bytes.length)
-        // 变量图片数据的每一位,并将每一位的 Unicode 编码存入类型化数组
-      for (let i = 0; i < bytes.length; i++) {
-        ia[i] = bytes.charCodeAt(i)
-      }
-        // 通过类型化数组创建一个 Blob 对象
-      return new Blob([ia], {type: mime})
-    },
+    // base64Url2Blob (url) {
+    //   // 将base64url通过 , 分割为含有两个元素的数组
+    //   const temp = url.split(',')
+    //     // 将图片的base64编码数据解码
+    //   const bytes = window.atob(temp[1])
+    //   // 匹配图片的 mime
+    //   const mime = temp[0].match(/:(.*?);/)[1]
+    //     // 创建一个类型化数组,该数组的长度与解码后的图片数据长度相同
+    //   let ia = new Uint8Array(bytes.length)
+    //     // 变量图片数据的每一位,并将每一位的 Unicode 编码存入类型化数组
+    //   for (let i = 0; i < bytes.length; i++) {
+    //     ia[i] = bytes.charCodeAt(i)
+    //   }
+    //     // 通过类型化数组创建一个 Blob 对象
+    //   return new Blob([ia], { type: mime })
+    // },
     changeText(e) { // 富文本内容改变
       this.inputValue = e
       this.$emit('update:value', this.inputValue)