Commit 83dc5277 authored by xinzhedeai's avatar xinzhedeai

孵化器上传图片格式限制

parent a1e63816
...@@ -92,12 +92,11 @@ ...@@ -92,12 +92,11 @@
class="upload-demo" class="upload-demo"
:action="`${baseAPI}api/file/upload?modelName=incubator`" :action="`${baseAPI}api/file/upload?modelName=incubator`"
:on-preview="handlePreview" :on-preview="handlePreview"
:on-remove="handleRemove" :before-upload="beforeUpload"
:before-remove="beforeRemove"
:on-success="handleSuccess" :on-success="handleSuccess"
:on-error="handleError" :on-error="handleError"
:limit="1" :on-change="handleChange"
:on-exceed="handleExceed" accept="image/png, image/jpeg, image/jpg"
:file-list="fileList" :file-list="fileList"
:show-file-list="false" :show-file-list="false"
style="margin-bottom: 6px" style="margin-bottom: 6px"
...@@ -179,6 +178,16 @@ export default { ...@@ -179,6 +178,16 @@ export default {
// this.getData(); // this.getData();
}, },
methods: { methods: {
handleChange(file) {
this.fileList = [file]; // 保留最新上传的文件,覆盖旧文件
},
beforeUpload(file) {
const isImage = file.type.startsWith('image/');
if (!isImage) {
this.$message.error('只能上传图片文件');
}
return isImage;
},
handleSuccess(response, file) { handleSuccess(response, file) {
// 处理上传成功 // 处理上传成功
console.log("Upload success:", response, file); console.log("Upload success:", response, file);
...@@ -198,22 +207,10 @@ export default { ...@@ -198,22 +207,10 @@ export default {
status: "上传失败", status: "上传失败",
}); });
}, },
handleRemove(file, fileList) {
console.log(file, fileList);
},
handlePreview(file) { handlePreview(file) {
console.log(file); console.log(file);
}, },
handleExceed(files, fileList) {
this.$message.warning(
`当前限制选择 3 个文件,本次选择了 ${files.length} 个文件,共选择了 ${
files.length + fileList.length
} 个文件`
);
},
beforeRemove(file, fileList) {
return this.$confirm(`确定移除 ${file.name}?`);
},
amapOptions(cmap) { amapOptions(cmap) {
var VUE = this; var VUE = this;
var self = this, var self = this,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment