FileUploadDialog.vue
1.39 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
<template>
<el-dialog
title="上传文件"
:visible.sync="dialogVisible"
:before-close="beforeClose"
append-to-body
>
<el-upload
:http-request="handleImport"
accept=".zip"
:file-list="fileList"
:limit="1"
:on-exceed="onExceed"
>
<el-button size="small" type="primary">点击上传</el-button>
<div slot="tip" class="el-upload__tip">只能上传zip文件</div>
</el-upload>
</el-dialog>
</template>
<script>
import req from '@/request'
export default {
name: 'FileUploadDialog',
props: {},
data() {
return {
dialogVisible: false,
fileList: [],
importUrl: '',
}
},
methods: {
open(importUrl) {
this.dialogVisible = true
this.importUrl = importUrl
},
beforeClose() {
this.dialogVisible = false
this.fileList = []
},
handleImport(param) {
let formData = new FormData()
formData.append('file', param.file)
req.post(this.importUrl, formData).then((resp) => {
if (resp.data.state) {
this.$message({type: 'success', message: '导入成功'})
this.dialogVisible = false
this.fileList = []
this.$emit('refresh')
} else {
this.beforeClose()
}
})
},
onExceed() {
this.$message.warning('只能选择一个zip文件!')
},
},
}
</script>
<style scoped></style>