qa-prevention-xgf-vue/src/views/util/uploadFile/index.vue

82 lines
1.9 KiB
Vue
Raw Normal View History

2023-11-07 10:17:12 +08:00
<template>
<div>
<el-upload
ref="uploadFile"
:auto-upload="false"
:file-list="fileList"
:on-change="onChange"
:on-remove="onRemove"
:limit="limit"
:on-exceed="handleExceed"
:accept="accept"
action="#">
<el-button slot="trigger" size="small" type="primary">选取文件</el-button>
<div slot="tip" class="el-upload__tip">{{ info }}</div>
</el-upload>
</div>
</template>
<script>
export default {
name: 'UploadImg',
props: {
fileList: {
type: Array,
default() {
return []
}
},
limit: {
type: Number,
default: 1
},
fileSize: {
type: Number,
default: 500
},
accept: {
type: String,
default: ''
},
info: {
type: String,
2024-02-04 11:03:10 +08:00
default: '文件大小不超过500MB'
2023-11-07 10:17:12 +08:00
}
},
data() {
return {
dialogImageUrl: '',
dialogVisible: false,
disabled: false
}
},
methods: {
handleRemove(file) {
this.fileList.splice(this.fileList.findIndex(item => item.uid === file.uid), 1)
},
handlePictureCardPreview(file) {
this.dialogImageUrl = file.url
this.dialogVisible = true
},
onChange(file, fileList) {
this.file = file
this.file_name = file.name
const isLt2M = file.size / 1024 / 1024 < this.fileSize
if (!isLt2M) {
this.$message.error('上传视频大小不能超过 ' + this.fileSize + 'MB!')
this.$refs.uploadFile.clearFiles()
return false
}
this.$emit('update:fileList', fileList)
},
onRemove(file, fileList) {
this.$emit('update:fileList', fileList)
},
handleExceed(files, fileList) {
this.$message.warning(`当前限制选择 ${this.limit} 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`)
}
}
}
</script>
<style scoped>
</style>