This commit is contained in:
@jyuhsin
2026-01-28 15:43:10 +08:00
parent f00393bdba
commit 62203cf452
13 changed files with 231 additions and 51 deletions
@@ -34,6 +34,7 @@
:accept="fileAccept"
:multiple="true"
list-type="picture-card"
:class="{ hide: hideUpload }"
>
<i class="el-icon-plus"></i>
<!-- <div class="el-upload__tip" v-if="fileList.length < upload_number">-->
@@ -212,10 +213,14 @@ module.exports = {
tips = tips + '不限格式;'
}
if (fileSize) {
tips = tips + `单个文件大小不能超过<span style="color: red">${fileSize / 1024 / 1024}</span>M`
tips = tips + `单个文件大小不能超过<span style="color: red">${(fileSize / 1024 / 1024).toFixed(2)}</span>M`
}
return tips
}
},
hideUpload() {
// 实时根据文件列表长度和限制数量计算
return this.fileList.length >= this.upload_number;
},
},
methods: {
buildFileObject(url, id) {
@@ -309,38 +314,35 @@ module.exports = {
beforeUpload(file) {
if (file.size > this.upload_size) {
this.$message.error("文件过大,请上传小于" + (this.upload_size / 1024 / 1024).toFixed(0) + "M的文件!")
this.$message.error("文件过大,请上传小于" + (this.upload_size / 1024 / 1024).toFixed(2) + "M的文件!")
return false
}
if (!this.fileAccept || typeof this.fileAccept !== "string") {
return true
}
return true
// 去除前后空格并转换为数组
const acceptTypes = this.fileAccept
.trim()
.split(",")
.map((type) => type.trim().toUpperCase())
// if (!this.fileAccept || typeof this.fileAccept !== "string") {
// return true
// }
//
// // 去除前后空格并转换为数组
// const acceptTypes = this.fileAccept
// .trim()
// .split(",")
// .map((type) => type.trim().toUpperCase())
//
// let fileType
// const dotIndex = file.name.lastIndexOf(".")
// if (dotIndex !== -1) {
// fileType = file.name.substring(dotIndex).toUpperCase()
// } else {
// this.$message.error("文件必须包含有效的扩展名!")
// return false
// }
//
// const valid = acceptTypes.includes(fileType)
// if (valid) {
// return true
// }
// this.$message.error(`文件只能是 ${this.fileAccept} 格式!`)
// return false
let fileType
const dotIndex = file.name.lastIndexOf(".")
if (dotIndex !== -1) {
fileType = file.name.substring(dotIndex).toUpperCase()
} else {
this.$message.error("文件必须包含有效的扩展名!")
return false
}
const valid = acceptTypes.includes(fileType)
if (valid) {
return true
}
this.$message.error(`文件只能是 ${this.fileAccept} 格式!`)
return false
},
// 预览图片
@@ -643,4 +645,7 @@ module.exports = {
height: var(--upload-height, 148px);
}
.hide .el-upload--picture-card {
display: none;
}
</style>