|
@@ -1,9 +1,9 @@
|
|
|
<template>
|
|
|
<div class="upload">
|
|
|
- <el-upload v-if="isBtn()" :action="action" :headers="headers" :multiple="multiple" :data="data"
|
|
|
- :name="name" :show-file-list="showFileList" :drag="drag" :accept="accept" :listType="listType"
|
|
|
- :autoUpload="autoUpload" :disabled="disabled" :before-upload="beforeUpload" :on-progress="onProgress"
|
|
|
- :on-success="onSuccess" :on-error="onError">
|
|
|
+ <el-upload v-if="isBtn()" :action="action" :headers="headers" :multiple="multiple" :data="data" :name="name"
|
|
|
+ :show-file-list="showFileList" :drag="drag" :accept="accept" :listType="listType" :autoUpload="autoUpload"
|
|
|
+ :disabled="disabled" :before-upload="beforeUpload" :on-progress="onProgress" :on-success="onSuccess"
|
|
|
+ :on-error="onError">
|
|
|
<el-button v-if="listType !== 'picture-card'" :type="type" ref="upload">
|
|
|
<slot v-if="percentage <= 0 && !form.file">点击上传</slot>
|
|
|
<span v-if="percentage > 0 && !form.file">{{ title }}</span>
|
|
@@ -61,6 +61,11 @@ export default {
|
|
|
},
|
|
|
// 最大允许上传个数
|
|
|
limit: Number,
|
|
|
+ // 文件类型
|
|
|
+ accept: {
|
|
|
+ type: String,
|
|
|
+ default: ''
|
|
|
+ },
|
|
|
// 图片尺寸
|
|
|
width: Number,
|
|
|
height: Number,
|
|
@@ -73,7 +78,8 @@ export default {
|
|
|
obj: {
|
|
|
'text': `${baseUrl}/system/file/file/upload`,
|
|
|
'picture-card': `${baseUrl}/system/file/picture/upload`,
|
|
|
- 'audio': `${baseUrl}/system/file/mp3/upload`
|
|
|
+ 'audio': `${baseUrl}/system/file/mp3/upload`,
|
|
|
+ 'zip': `${baseUrl}/system/file/file/uploadFolderZip`
|
|
|
},
|
|
|
// 上传地址
|
|
|
action: '#',
|
|
@@ -85,8 +91,6 @@ export default {
|
|
|
data: {},
|
|
|
// 文件名
|
|
|
name: 'multipartFile',
|
|
|
- // 文件类型
|
|
|
- accept: '',
|
|
|
// 进度条
|
|
|
percentage: 0,
|
|
|
title: '',
|
|
@@ -100,16 +104,17 @@ export default {
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
- watch:{
|
|
|
+ watch: {
|
|
|
url(val) {
|
|
|
this.form.file = val
|
|
|
+ },
|
|
|
+ listType(val) {
|
|
|
+ this.action = this.obj[val]
|
|
|
}
|
|
|
},
|
|
|
created() {
|
|
|
// 根据上传类型 变更 上传地址
|
|
|
this.action = this.obj[this.listType]
|
|
|
- // 根据上传类型 变更 文件类型
|
|
|
- this.accept = this.listType === 'picture-card' ? '.jpg, .jpeg, .png, .bmp, .icon, .gif' : ''
|
|
|
// 回显图片
|
|
|
this.form.file = this.url
|
|
|
},
|
|
@@ -184,7 +189,7 @@ export default {
|
|
|
|
|
|
// 上传按钮
|
|
|
isBtn() {
|
|
|
- return ['text', 'audio'].includes(this.listType) || (this.listType === 'picture-card' && this.percentage == 0 && !this.form.file)
|
|
|
+ return ['text', 'audio', 'zip'].includes(this.listType) || (this.listType === 'picture-card' && this.percentage == 0 && !this.form.file)
|
|
|
},
|
|
|
// 显示进度条
|
|
|
isPercentage() {
|