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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
| <script setup>
| import { ref } from "vue";
|
| defineOptions({
| name: "文件上传组件",
| });
|
| const props = defineProps({
| downloadTemplate: Function,
| showTips: Boolean,
| accept: {
| type: String,
| default: ".xls, .xlsx",
| },
| headers: Object,
| action: String,
| disabled: {
| type: Boolean,
| default: false,
| },
| });
| const emits = defineEmits(["success", "error"]);
|
| const uploadRef = ref();
| const fileList = ref([]);
|
| const uploadApi = () => {
| uploadRef.value.submit();
| };
|
| const handleFileSuccess = (response, file, fileList) => {
| upload.open = false;
| upload.isUploading = false;
| uploadRef.value.handleRemove(file);
| emits("success", response, file, fileList);
| };
|
| defineExpose({
| fileList,
| uploadApi,
| });
| </script>
|
| <template>
| <el-upload
| ref="uploadRef"
| v-model:file-list="fileList"
| drag
| multiple
| :action="action"
| :accept="accept"
| :headers="headers"
| :disabled="disabled"
| :auto-upload="false"
| :limit="1"
| :drag="true"
| :on-success="handleFileSuccess"
| >
| <div class="el-upload__text">
| <el-icon class="el-icon--upload"><upload-filled /></el-icon>
| <div class="el-upload__text">
| 将文件拖到此处,或
| <em>点击导入数据</em>
| </div>
| </div>
| <template #tip>
| <div class="el-upload__tip text-center">
| 只能上传xlsx/xls文件,且不超过10M
| <el-button
| type="primary"
| link
| class="reset-margin"
| @click="props.downloadTemplate()"
| >
| <span style="font-size: 12px; font-weight: normal">下载模板</span>
| </el-button>
| </div>
| </template>
| </el-upload>
| </template>
|
|