UploadFileSingle.vue
1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<template>
<div class="UploadFile-container">
<el-upload :action="define.comUploadUrl+'/'+type" :headers="uploadHeaders"
:on-preview="handlePreview" :on-remove="handleRemove" :before-remove="beforeRemove"
:on-success="handleSuccess" :file-list="fileList" :accept="accept">
<el-button size="small" icon="el-icon-upload">选择文件</el-button>
</el-upload>
</div>
</template>
<script>
import { getDownloadUrl } from '@/api/common'
export default {
name: 'UploadFileSingle',
props: {
value: {
type: String,
default: ''
},
type: {
type: String,
default: 'workFlow'
},
accept: {
type: String,
default: '*'
}
},
data() {
return {
fileList: [],
uploadHeaders: { Authorization: this.$store.getters.token }
}
},
watch: {
value(val) { if (!val) this.fileList = [] }
},
methods: {
handlePreview(file) {
// 点击下载文件
// if (!file.fileId) return
// getDownloadUrl(this.type, file.fileId).then(res => {
// window.location.href = this.define.comUrl + res.data.url
// })
},
handleRemove(file, fileList) {
this.fileList = fileList
this.$emit('input', '')
},
handleSuccess(res, file, fileList) {
if (res.code == 200) {
this.fileList = fileList.slice(-1)
this.$emit('input', res.data.name)
} else {
this.fileList = fileList.filter(o => o.uid != file.uid)
this.$message({ message: res.msg, type: 'error', duration: 1500 })
}
},
beforeRemove(file, fileList) {
return this.$confirm(`确定移除 ${file.name}?`).catch(() => { });
}
}
}
</script>