Commit 83dc5277 authored by xinzhedeai's avatar xinzhedeai

孵化器上传图片格式限制

parent a1e63816
......@@ -92,12 +92,11 @@
class="upload-demo"
:action="`${baseAPI}api/file/upload?modelName=incubator`"
:on-preview="handlePreview"
:on-remove="handleRemove"
:before-remove="beforeRemove"
:before-upload="beforeUpload"
:on-success="handleSuccess"
:on-error="handleError"
:limit="1"
:on-exceed="handleExceed"
:on-change="handleChange"
accept="image/png, image/jpeg, image/jpg"
:file-list="fileList"
:show-file-list="false"
style="margin-bottom: 6px"
......@@ -179,6 +178,16 @@ export default {
// this.getData();
},
methods: {
handleChange(file) {
this.fileList = [file]; // 保留最新上传的文件,覆盖旧文件
},
beforeUpload(file) {
const isImage = file.type.startsWith('image/');
if (!isImage) {
this.$message.error('只能上传图片文件');
}
return isImage;
},
handleSuccess(response, file) {
// 处理上传成功
console.log("Upload success:", response, file);
......@@ -198,22 +207,10 @@ export default {
status: "上传失败",
});
},
handleRemove(file, fileList) {
console.log(file, fileList);
},
handlePreview(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) {
var VUE = 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