提交 a7b477df authored 作者: 王鹏飞's avatar 王鹏飞

上传文件显示文件名称

上级 38ed5814
...@@ -10,23 +10,18 @@ ...@@ -10,23 +10,18 @@
</template> </template>
</el-upload> </el-upload>
<div class="file-list" v-if="fileList.length"> <div class="file-list" v-if="fileList.length">
<div class="file-list-item" v-for="(fileUrl, index) in fileList" :key="index"> <div class="file-list-item" v-for="(item, index) in fileList" :key="index">
<a :href="fileUrl" target="_blank"> <a :href="item.url" :download="item.name" target="_blank">
<i class="el-icon-document"></i> <i class="el-icon-document"></i>
{{ fileUrl | fileName }} {{ item.name }}
</a> </a>
<div> <div>
<a <a href="javascript:;" @click="handleRemove(index)" style="margin-right: 10px" v-if="!disabled">
href="javascript:;"
@click="handleRemove(index)"
style="margin-right:10px;"
v-if="!disabled"
>
<el-tooltip effect="dark" content="删除"> <el-tooltip effect="dark" content="删除">
<i class="el-icon-delete"></i> <i class="el-icon-delete"></i>
</el-tooltip> </el-tooltip>
</a> </a>
<a :href="fileUrl" :download="fileUrl | fileName" target="_blank"> <a :href="item.url" :download="item.name" target="_blank">
<el-tooltip effect="dark" content="下载"> <el-tooltip effect="dark" content="下载">
<i class="el-icon-download"></i> <i class="el-icon-download"></i>
</el-tooltip> </el-tooltip>
...@@ -55,36 +50,39 @@ export default { ...@@ -55,36 +50,39 @@ export default {
value: { value: {
immediate: true, immediate: true,
handler(value) { handler(value) {
if (value) { if (!value) {
if (Array.isArray(value)) { return
this.fileList = value.map(item => { }
return item.url || item let fileList = []
}) if (Array.isArray(value)) {
} else { fileList = value.map(item => {
this.fileList = [value] return { name: item.name || item, url: item.url || item }
} })
} else {
fileList.push({ name: '附件下载', url: value })
} }
this.fileList = fileList
} }
} }
}, },
filters: {
fileName(value) {
return value ? value.split('/').pop() : ''
}
},
methods: { methods: {
httpRequest(xhr) { httpRequest(xhr) {
api.uploadFile({ file: xhr.file }).then(response => { api
if (response.success) { .uploadFile({ file: xhr.file })
if (Array.isArray(this.value)) { .then(response => {
this.fileList.push(response.url) if (response.success) {
this.$emit('input', this.fileList) if (Array.isArray(this.value)) {
} else { this.fileList.push({ name: xhr.file.name, url: response.url })
this.fileList = [response.url] this.$emit('input', this.fileList)
this.$emit('input', response.url) } else {
this.fileList = [response.url]
this.$emit('input', response.url)
}
} }
} })
}) .catch(error => {
this.$message.error(error.message)
})
}, },
handleRemove(index) { handleRemove(index) {
this.fileList.splice(index, 1) this.fileList.splice(index, 1)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论