<template>
<div class="upload">
<el-upload
class="upload-demo"
action
multiple
list-type="text"
:show-file-list="showFileList"
:on-preview="handlePreview"
:on-progress="onDocUpload"
:on-change="handleChange"
:on-remove="handleRemove"
:limit="limit"
:on-exceed="handleExceed"
:before-upload="beforeUpload"
:file-list="fileList"
:http-request="docUpload"
>
<el-button
v-if="title && !svgIcon"
size="mini"
type="primary"
:icon="icon"
>{{ title }}</el-button
>
<el-button
v-if="!title && !svgIcon"
size="mini"
type="primary"
:icon="icon"
></el-button>
<svg-icon v-if="svgIcon" class="svg" icon-class="import" />
<div slot="tip" v-if="tips" class="el-upload__tip">{{ tips }}</div>
<el-progress
:percentage="loadProgress"
:format="format"
v-show="showPorgess"
></el-progress>
</el-upload>
</div>
</template>
<script>
import axios from 'axios'
export default {
name: 'docUpload',
props: {
svgIcon: {
type: String,
default: '',
},
icon: {
type: String,
default: '',
},
title: {
type: String,
default: '',
},
tips: {
type: String,
default: '',
},
typeCheck: {
type: Function,
required: true,
default: null,
},
limit: {
type: Number,
default: 1,
},
showFileList: {
type: Boolean,
default: true,
},
},
data() {
return {
fileList: [],
imgurl: '',
fd: null,
file: '',
loadProgress: 0,
showPorgess: false,
}
},
methods: {
handleRemove(file, fileList) {
this.$emit('on-remove', file, fileList)
},
handleExceed(files, fileList) {
this.$message.warning(`每次只能上传 ${this.limit} 个文件`)
},
docUpload(raw) {
},
handlePreview(file, fileList) {
console.log(fileList)
},
beforeRemove(file, fileList) {
return this.$confirm(`Are you sure to delete ${file.name}?`)
},
beforeUpload(file) {
let bool = this.typeCheck(file)
return bool
},
onDocUpload(event) {
this.showPorgess = true
this.loadProgress = Math.floor(event.percent)
},
handleChange() {
this.showPorgess = false
},
format(percentage) {
return `${percentage}%`
},
clearFile() {
this.fileList = []
},
},
}
</script>
<style lang="scss" scoped>
.upload {
display: inline-block;
}
.svg {
font-size: 16px;
}
</style>