Explorar o código

fix upload /api/placeholder

Michael Wang %!s(int64=4) %!d(string=hai) anos
pai
achega
c8c3bb2c55
Modificáronse 3 ficheiros con 36 adicións e 10 borrados
  1. 2 2
      .env.development
  2. 7 7
      public/index.html
  3. 27 1
      src/features/system/OrgManagement/UploadFile.vue

+ 2 - 2
.env.development

@@ -1,5 +1,5 @@
 VUE_APP_SELF_DEFINE_DOMAIN=true
 VUE_APP_ENABLE_VUE_RENDER_LOGS=false
 VUE_APP_ROUTER_PATH=/admin/
-VUE_APP_MAIN_PROXY=https://192.168.10.36:9222/
-VUE_APP_MAIN_PROXY_FILE=https://192.168.10.36:9222/
+VUE_APP_MAIN_PROXY=https://admin.online-exam-test.cn
+VUE_APP_MAIN_PROXY_FILE=https://admin.online-exam-test.cn

+ 7 - 7
public/index.html

@@ -17,13 +17,13 @@
     <div id="app"></div>
     <script>
       var _hmt = _hmt || [];
-      (function () {
-        var hmId = "xxxxx";
-        var hm = document.createElement("script");
-        hm.src = "https://hm.baidu.com/hm.js?" + hmId;
-        var s = document.getElementsByTagName("script")[0];
-        s.parentNode.insertBefore(hm, s);
-      })();
+      // (function () {
+      //   var hmId = "xxxxx";
+      //   var hm = document.createElement("script");
+      //   hm.src = "https://hm.baidu.com/hm.js?" + hmId;
+      //   var s = document.getElementsByTagName("script")[0];
+      //   s.parentNode.insertBefore(hm, s);
+      // })();
     </script>
     <!-- built files will be auto injected -->
   </body>

+ 27 - 1
src/features/system/OrgManagement/UploadFile.vue

@@ -4,11 +4,13 @@
     class="upload-demo"
     action="/api/placeholder"
     accept=".jpg,.png"
+    :on-change="handleChange"
     :on-preview="handlePreview"
     :on-remove="handleRemove"
     :file-list="fileList"
     :before-upload="beforeUpload"
     list-type="picture"
+    :auto-upload="false"
   >
     <el-button size="small" type="primary">点击上传</el-button>
     <div slot="tip" class="el-upload__tip">
@@ -50,7 +52,31 @@ export default {
       this.$emit("change", url);
     },
     handlePreview(file) {
-      console.log(file);
+      console.log("preview", file);
+    },
+    async handleChange(file) {
+      console.log("change", file);
+      if (!file?.raw) return;
+      file = file.raw;
+      async function blobToArray(blob) {
+        return new Promise((resolve) => {
+          var reader = new FileReader();
+          reader.addEventListener("loadend", function () {
+            // reader.result contains the contents of blob as a typed array
+            resolve(reader.result);
+          });
+          reader.readAsArrayBuffer(blob);
+        });
+      }
+      const ab = await blobToArray(file);
+      const md5 = MD5(ab);
+
+      const res = await uploadFile({ file, md5 });
+      console.log(res);
+      const url = res.data.data.url;
+      this.fileList[0].url = url;
+      this.$emit("input", url);
+      this.$emit("change", url);
     },
     async beforeUpload(file) {
       console.log(file);