|
|
|
@ -2,7 +2,7 @@ |
|
|
|
<el-upload |
|
|
|
<el-upload |
|
|
|
ref="upload" |
|
|
|
ref="upload" |
|
|
|
:before-upload="beforeUpload" |
|
|
|
:before-upload="beforeUpload" |
|
|
|
:class="{disabled:hideUploader}" |
|
|
|
:class="{disabled: hideUploader}" |
|
|
|
:file-list="data" |
|
|
|
:file-list="data" |
|
|
|
:http-request="httpRequest" |
|
|
|
:http-request="httpRequest" |
|
|
|
:limit="limit" |
|
|
|
:limit="limit" |
|
|
|
@ -14,30 +14,48 @@ |
|
|
|
list-type="picture-card" |
|
|
|
list-type="picture-card" |
|
|
|
> |
|
|
|
> |
|
|
|
<i class="el-icon-plus" slot="default"/> |
|
|
|
<i class="el-icon-plus" slot="default"/> |
|
|
|
|
|
|
|
|
|
|
|
<template v-slot:file="{file}"> |
|
|
|
<template v-slot:file="{file}"> |
|
|
|
<el-tooltip :content="file.name" effect="dark" placement="bottom"> |
|
|
|
<span |
|
|
|
<span class="el-upload-list__item-actions"> |
|
|
|
class="el-upload-list__item-actions" |
|
|
|
<span v-if="showPreview(file)" class="el-upload-list__item-preview" @click="preview(file)"> |
|
|
|
@mouseenter="e => handleBlockMouseEnter(e,file)" |
|
|
|
<i class="el-icon-zoom-in"/> |
|
|
|
@mouseleave="handleBlockMouseLeave" |
|
|
|
</span> |
|
|
|
> |
|
|
|
<span v-if="showDownload(file)" class="el-upload-list__item-delete" @click="download(file)"> |
|
|
|
<span |
|
|
|
<i class="el-icon-download"/> |
|
|
|
v-if="showPreview(file)" |
|
|
|
</span> |
|
|
|
class="el-upload-list__item-preview" |
|
|
|
<span v-if="!disabled" class="el-upload-list__item-delete" @click="remove(file)"> |
|
|
|
@click="() => preview(file)" |
|
|
|
<i class="el-icon-delete"/> |
|
|
|
> |
|
|
|
</span> |
|
|
|
<i class="el-icon-zoom-in"/> |
|
|
|
</span> |
|
|
|
</span> |
|
|
|
</el-tooltip> |
|
|
|
<span |
|
|
|
<img :src="file.url" class="el-upload-list__item-thumbnail"> |
|
|
|
v-if="showDownload(file)" |
|
|
|
|
|
|
|
class="el-upload-list__item-delete" |
|
|
|
|
|
|
|
@click="() => download(file)" |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
<i class="el-icon-download"/> |
|
|
|
|
|
|
|
</span> |
|
|
|
|
|
|
|
<span |
|
|
|
|
|
|
|
v-if="!disabled" |
|
|
|
|
|
|
|
class="el-upload-list__item-delete" |
|
|
|
|
|
|
|
@click="() => remove(file)" |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
<i class="el-icon-delete"/> |
|
|
|
|
|
|
|
</span> |
|
|
|
|
|
|
|
</span> |
|
|
|
|
|
|
|
<img v-if="file.status === 'success'" :src="file.url" class="el-upload-list__item-thumbnail"> |
|
|
|
<label class="el-upload-list__item-status-label"> |
|
|
|
<label class="el-upload-list__item-status-label"> |
|
|
|
<i class="el-icon-upload-success el-icon-check"/> |
|
|
|
<i class="el-icon-upload-success el-icon-check"/> |
|
|
|
</label> |
|
|
|
</label> |
|
|
|
<div v-if="file.status==='uploading'" class="progress-mask"> |
|
|
|
<div v-if="file.status === 'uploading'" class="progress-mask"> |
|
|
|
<el-progress :percentage="file.percentage" type="circle"/> |
|
|
|
<el-progress :percentage="file.percentage" type="circle"/> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</template> |
|
|
|
</template> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<el-tooltip ref="tooltip" :content="tooltipContent" popper-class="upload-tooltip"/> |
|
|
|
</el-upload> |
|
|
|
</el-upload> |
|
|
|
</template> |
|
|
|
</template> |
|
|
|
|
|
|
|
|
|
|
|
<script> |
|
|
|
<script> |
|
|
|
/* |
|
|
|
/* |
|
|
|
* 直传七牛云 |
|
|
|
* 直传七牛云 |
|
|
|
@ -47,13 +65,14 @@ |
|
|
|
import axios from 'axios' |
|
|
|
import axios from 'axios' |
|
|
|
import {attachmentPrefix} from '@/config' |
|
|
|
import {attachmentPrefix} from '@/config' |
|
|
|
import {elError} from "@/utils/message" |
|
|
|
import {elError} from "@/utils/message" |
|
|
|
import {isEmpty} from '@/utils' |
|
|
|
import {debounce, isEmpty} from '@/utils' |
|
|
|
import {isImage} from "@/utils/validate" |
|
|
|
import {isImage} from "@/utils/validate" |
|
|
|
import {deleteUpload, download, upload, autoCompleteUrl} from "@/utils/file" |
|
|
|
import {deleteUpload, download, upload, autoCompleteUrl} from "@/utils/file" |
|
|
|
import {numberFormatter} from "@/filter" |
|
|
|
import {numberFormatter} from "@/filter" |
|
|
|
|
|
|
|
|
|
|
|
export default { |
|
|
|
export default { |
|
|
|
name: 'UploadFile', |
|
|
|
name: 'UploadFile', |
|
|
|
|
|
|
|
|
|
|
|
props: { |
|
|
|
props: { |
|
|
|
disabled: {type: Boolean, default: false}, |
|
|
|
disabled: {type: Boolean, default: false}, |
|
|
|
multiple: {type: Boolean, default: true}, |
|
|
|
multiple: {type: Boolean, default: true}, |
|
|
|
@ -61,11 +80,14 @@ |
|
|
|
limit: {type: Number, default: 10}, |
|
|
|
limit: {type: Number, default: 10}, |
|
|
|
maxSize: {type: Number | String, default: '10MB'} |
|
|
|
maxSize: {type: Number | String, default: '10MB'} |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
data() { |
|
|
|
data() { |
|
|
|
return { |
|
|
|
return { |
|
|
|
data: this.fileList |
|
|
|
data: this.fileList, |
|
|
|
|
|
|
|
tooltipContent: null |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
computed: { |
|
|
|
computed: { |
|
|
|
count() { |
|
|
|
count() { |
|
|
|
return this.data.length |
|
|
|
return this.data.length |
|
|
|
@ -74,10 +96,10 @@ |
|
|
|
return this.disabled || this.count >= this.limit |
|
|
|
return this.disabled || this.count >= this.limit |
|
|
|
}, |
|
|
|
}, |
|
|
|
previewUrlList() { |
|
|
|
previewUrlList() { |
|
|
|
if (!this.data) return [] |
|
|
|
return this.data ? this.data.map(i => i.url) : [] |
|
|
|
return this.data.map(i => i.url) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
watch: { |
|
|
|
watch: { |
|
|
|
fileList: { |
|
|
|
fileList: { |
|
|
|
immediate: true, |
|
|
|
immediate: true, |
|
|
|
@ -90,6 +112,7 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
methods: { |
|
|
|
methods: { |
|
|
|
showPreview(file) { |
|
|
|
showPreview(file) { |
|
|
|
return file.name && isImage(file.name) |
|
|
|
return file.name && isImage(file.name) |
|
|
|
@ -108,6 +131,24 @@ |
|
|
|
return parseInt(num) * (map[unit] || 1) |
|
|
|
return parseInt(num) * (map[unit] || 1) |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//模仿el-table的tooltip |
|
|
|
|
|
|
|
handleBlockMouseEnter(event, file) { |
|
|
|
|
|
|
|
const tooltip = this.$refs.tooltip |
|
|
|
|
|
|
|
this.tooltipContent = file.name |
|
|
|
|
|
|
|
tooltip.referenceElm = event.target |
|
|
|
|
|
|
|
tooltip.$refs.popper && (tooltip.$refs.popper.style.display = 'none') |
|
|
|
|
|
|
|
tooltip.doDestroy() |
|
|
|
|
|
|
|
tooltip.setExpectedState(true) |
|
|
|
|
|
|
|
this.activateTooltip(tooltip) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
handleBlockMouseLeave() { |
|
|
|
|
|
|
|
const tooltip = this.$refs.tooltip |
|
|
|
|
|
|
|
if (tooltip) { |
|
|
|
|
|
|
|
tooltip.setExpectedState(false) |
|
|
|
|
|
|
|
tooltip.handleClosePopper() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
//附件移除时,仅当非本次上传时触发remove事件 |
|
|
|
//附件移除时,仅当非本次上传时触发remove事件 |
|
|
|
remove(file) { |
|
|
|
remove(file) { |
|
|
|
//区分是否为本次新上传,以及是否上传成功 |
|
|
|
//区分是否为本次新上传,以及是否上传成功 |
|
|
|
@ -151,7 +192,7 @@ |
|
|
|
this.remove(file) |
|
|
|
this.remove(file) |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
//上传前获取七牛的上传凭证,并指定key |
|
|
|
//上传前过滤文件 |
|
|
|
beforeUpload(file) { |
|
|
|
beforeUpload(file) { |
|
|
|
if (!file.type.includes('image')) { |
|
|
|
if (!file.type.includes('image')) { |
|
|
|
elError('暂时只支持图片上传') |
|
|
|
elError('暂时只支持图片上传') |
|
|
|
@ -176,12 +217,18 @@ |
|
|
|
}, |
|
|
|
}, |
|
|
|
cancelToken: source.token |
|
|
|
cancelToken: source.token |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
//由于ele原有的上传方法是原生ajax,所以取消上传时会调用一次abort方法 |
|
|
|
promise.abort = source.cancel |
|
|
|
promise.abort = source.cancel |
|
|
|
return promise |
|
|
|
return promise |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
created() { |
|
|
|
|
|
|
|
this.activateTooltip = debounce(tooltip => tooltip.handleShowPopper(), 100) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
</script> |
|
|
|
</script> |
|
|
|
|
|
|
|
|
|
|
|
<style lang="scss"> |
|
|
|
<style lang="scss"> |
|
|
|
.disabled .el-upload--picture-card { |
|
|
|
.disabled .el-upload--picture-card { |
|
|
|
display: none; |
|
|
|
display: none; |
|
|
|
@ -215,4 +262,8 @@ |
|
|
|
.el-upload-list__item-thumbnail { |
|
|
|
.el-upload-list__item-thumbnail { |
|
|
|
object-fit: cover; |
|
|
|
object-fit: cover; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.upload-tooltip { |
|
|
|
|
|
|
|
max-width: 146px; |
|
|
|
|
|
|
|
} |
|
|
|
</style> |
|
|
|
</style> |
|
|
|
|