Prechádzať zdrojové kódy

简化代码,供以后重用

Michael Wang 4 rokov pred
rodič
commit
dadf92c69d

+ 3 - 75
src/features/system/OrgManagement/UploadFile.vue

@@ -4,17 +4,13 @@
     class="upload-demo"
     action="/api/placeholder"
     accept=".jpg,.png"
-    :on-preview="handlePreview"
-    :on-remove="handleRemove"
-    :file-list="fileList"
     list-type="picture"
+    :file-list="fileList"
     :http-request="uploadHttpRequest"
+    :on-remove="handleRemove"
     :on-success="handleSuccess"
     :on-error="handleError"
   >
-    <!-- :on-change="handleChange" -->
-    <!-- :before-upload="beforeUpload" -->
-    <!-- :auto-upload="false" -->
     <el-button size="small" type="primary">点击上传</el-button>
     <div slot="tip" class="el-upload__tip">
       只能上传jpg/png文件,且不超过500kb
@@ -27,7 +23,7 @@
 import { uploadFile } from "@/api/system-info";
 
 /**
- *       
+ * uploadHttpRequest(options)      
  * const options = {
         headers: this.headers,
         withCredentials: this.withCredentials,
@@ -48,21 +44,6 @@ import { uploadFile } from "@/api/system-info";
         }
       };
  */
-// async function uploadHttpRequest(options) {
-//   console.log(options);
-//   return uploadFile({
-//     file: options.file,
-//     onUploadProgress: options.onProgress,
-//   });
-// .then((res) => {
-//   options.onSuccess(res);
-//   return res;
-// })
-// .catch((reason) => {
-//   debugger;
-//   options.onError(reason);
-// });
-// }
 
 export default {
   props: { value: String },
@@ -99,69 +80,16 @@ export default {
       this.$emit("input", url);
       this.$emit("change", url);
     },
-    handlePreview(file) {
-      console.log("preview", file);
-    },
-    // async handleChange(file) {
-    //   console.log("change", file);
-    //   this.fileList = [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);
-    // },
     handleError() {
-      // console.log(file);
       const url = null;
       this.fileList = [];
       this.$emit("input", url);
       this.$emit("change", url);
     },
     handleSuccess(res) {
-      // console.log(res, file);
-      // this.fileList = [];
       this.$emit("input", res.data.data.url);
       this.$emit("change", res.data.data.url);
     },
-    // async beforeUpload(file) {
-    //   console.log(file);
-    //   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);
-    //   return Promise.reject("stop upload");
-    // },
   },
 };
 </script>