|
@@ -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);
|