|
@@ -27,18 +27,18 @@
|
|
<Upload
|
|
<Upload
|
|
ref="upload"
|
|
ref="upload"
|
|
v-show="this.uploadList.length < 6"
|
|
v-show="this.uploadList.length < 6"
|
|
|
|
+ :accept="this.format.map(v => 'image/' + v).join()"
|
|
:data="headers"
|
|
:data="headers"
|
|
:show-upload-list="false"
|
|
:show-upload-list="false"
|
|
:default-file-list="defaultList2"
|
|
:default-file-list="defaultList2"
|
|
:on-success="handleSuccess"
|
|
:on-success="handleSuccess"
|
|
- :format="['jpg', 'jpeg', 'png']"
|
|
|
|
|
|
+ :format="format"
|
|
:max-size="5 * 1024"
|
|
:max-size="5 * 1024"
|
|
:on-format-error="handleFormatError"
|
|
:on-format-error="handleFormatError"
|
|
:on-exceeded-size="handleMaxSize"
|
|
:on-exceeded-size="handleMaxSize"
|
|
:before-upload="handleBeforeUpload"
|
|
:before-upload="handleBeforeUpload"
|
|
- multiple
|
|
|
|
- type="drag"
|
|
|
|
:action="this.uploadUrl"
|
|
:action="this.uploadUrl"
|
|
|
|
+ type="drag"
|
|
style="display: inline-block;width:100px;"
|
|
style="display: inline-block;width:100px;"
|
|
>
|
|
>
|
|
<div style="width: 100px;height:100px;line-height: 100px;">
|
|
<div style="width: 100px;height:100px;line-height: 100px;">
|
|
@@ -77,7 +77,8 @@ export default {
|
|
defaultList2: [...this.defaultList],
|
|
defaultList2: [...this.defaultList],
|
|
uploadList: [],
|
|
uploadList: [],
|
|
uploadUrl: "",
|
|
uploadUrl: "",
|
|
- headers: {}
|
|
|
|
|
|
+ headers: {},
|
|
|
|
+ format: ["jpg", "jpeg", "png"]
|
|
};
|
|
};
|
|
},
|
|
},
|
|
methods: {
|
|
methods: {
|
|
@@ -108,7 +109,73 @@ export default {
|
|
desc: file.name + `超过${MAX_UPLOAD_SIZE}M.`
|
|
desc: file.name + `超过${MAX_UPLOAD_SIZE}M.`
|
|
});
|
|
});
|
|
},
|
|
},
|
|
|
|
+ fileFormatCheck(file, resolve, reject) {
|
|
|
|
+ function getMimetype(signature) {
|
|
|
|
+ switch (signature) {
|
|
|
|
+ case "89504E47":
|
|
|
|
+ return "image/png";
|
|
|
|
+ case "47494638":
|
|
|
|
+ return "image/gif";
|
|
|
|
+ case "25504446":
|
|
|
|
+ return "application/pdf";
|
|
|
|
+ case "FFD8FFDB":
|
|
|
|
+ case "FFD8FFE0":
|
|
|
|
+ case "FFD8FFE1":
|
|
|
|
+ return "image/jpeg";
|
|
|
|
+ case "504B0304":
|
|
|
|
+ return "application/zip";
|
|
|
|
+ case "504B34":
|
|
|
|
+ return "application/zip";
|
|
|
|
+ default:
|
|
|
|
+ return "Unknown filetype";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const filereader = new FileReader();
|
|
|
|
+ let uploads = [];
|
|
|
|
+ filereader.onloadend = evt => {
|
|
|
|
+ if (evt.target.readyState === FileReader.DONE) {
|
|
|
|
+ const uint = new Uint8Array(evt.target.result);
|
|
|
|
+ let bytes = [];
|
|
|
|
+ uint.forEach(byte => {
|
|
|
|
+ bytes.push(byte.toString(16));
|
|
|
|
+ });
|
|
|
|
+ const hex = bytes.join("").toUpperCase();
|
|
|
|
+ uploads.push({
|
|
|
|
+ filename: file.name,
|
|
|
|
+ filetype: file.type ? file.type : "Unknown/Extension missing",
|
|
|
|
+ binaryFileType: getMimetype(hex),
|
|
|
|
+ hex: hex
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ if (
|
|
|
|
+ ["image/png", "image/gif", "image/jpeg"].includes(getMimetype(hex))
|
|
|
|
+ ) {
|
|
|
|
+ resolve();
|
|
|
|
+ } else {
|
|
|
|
+ console.log("binary file type check: not zip or pdf");
|
|
|
|
+ this.$Notice.warning({
|
|
|
|
+ title: "文件损坏",
|
|
|
|
+ desc: file.name + " 文件无法以 " + "png/jpg/jpeg" + " 格式读取。"
|
|
|
|
+ });
|
|
|
|
+ this.loadingStatus = false;
|
|
|
|
+ reject("作答文件损坏");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ const blob = file.slice(0, 4);
|
|
|
|
+ filereader.readAsArrayBuffer(blob);
|
|
|
|
+ },
|
|
async handleBeforeUpload(file) {
|
|
async handleBeforeUpload(file) {
|
|
|
|
+ const result = await new Promise((resolve, reject) =>
|
|
|
|
+ this.fileFormatCheck(file, resolve, reject)
|
|
|
|
+ );
|
|
|
|
+ if (result) {
|
|
|
|
+ // this.$Notice.warning({
|
|
|
|
+ // title: `最多上传${MAX_UPLOADS_NUM}张照片。`
|
|
|
|
+ // });
|
|
|
|
+ return Promise.resolve(false);
|
|
|
|
+ }
|
|
const MAX_UPLOADS_NUM = 6;
|
|
const MAX_UPLOADS_NUM = 6;
|
|
const check = this.uploadList.length < MAX_UPLOADS_NUM;
|
|
const check = this.uploadList.length < MAX_UPLOADS_NUM;
|
|
if (!check) {
|
|
if (!check) {
|