UploadFiles.vue
3.73 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<template>
<a-spin :tip="$t('common.uploading')" class="spin-upload" v-if="upLoading"></a-spin>
<template v-if="type === 'button'">
<a-upload v-model:fileList="fileList" :headers="headers" name="file" :multiple="multiple" :action="apiUrl+action" :showUploadList="showUploadList"
@change="handleChange" @download="download" :max-count="max" :beforeUpload="beforeUpload" @reject="handleReject" @remove="handleRemove" :accept="fileType">
<div v-if="showButton">
<a-button class="flex-center">
<upload-outlined/>
<span>{{ buttonName || $t('common.upload') }}</span>
</a-button>
</div>
</a-upload>
<div class="file-type" v-if="showSuffixesHint">
<div class="text-danger">{{ $t('common.file.type') }}:{{ suffixes }}</div>
</div>
<div class="file-type" v-if="showMaxHint">
<div class="text-danger">{{ $t('common.file.limit') }}:{{ max }}</div>
</div>
</template>
<template v-else-if="type === 'dragger'">
<a-upload-dragger class="dragger" v-model:fileList="fileList" :headers="headers" name="file" :max-count="max" :multiple="multiple" :action="apiUrl+action"
@change="handleChange" @download="download" :beforeUpload="beforeUpload" @reject="handleReject" @remove="handleRemove" :accept="fileType" @drop="handleDrop">
<p class="ant-upload-drag-icon">
<inbox-outlined></inbox-outlined>
</p>
<p class="ant-upload-text">{{ $t('common.upload_drag') }}</p>
<span class="ant-upload-hint">
<span class="file-type" v-if="showSuffixesHint">
<span class="text-danger">{{ $t('common.file.type') }}:{{ suffixes }}</span>
</span>
<span class="file-type" v-if="showMaxHint">
<span class="text-danger">{{ $t('common.file.limit') }}:{{ max }} </span>
</span>
</span>
</a-upload-dragger>
</template>
</template>
<script lang="ts">
import {InboxOutlined, UploadOutlined} from '@ant-design/icons-vue';
import {Component, Prop, Watch} from "vue-facing-decorator";
import {message} from "ant-design-vue";
import {UploadBase} from '../UploadBase';
/**
* 创建上传的用法
* <UploadFiles ref="uploadFiles"
:directory="'document-process'"
suffixes='doc,docx,pdf,xlsx,xls,jpg,png,jpeg' @change="fileChange"/>
编辑的上传用法
需加上:fileListProp="documentProcess?.filePath"属性
*/
@Component({
name: "MUploadFiles",
components: {UploadOutlined, InboxOutlined}
})
export default class UploadFiles extends UploadBase {
/**
* 类型
*/
@Prop({type: String, required: false, default: 'button'})
type: 'button' | 'dragger';
handleDrop(e: DragEvent): void {
console.log(e);
}
handleReject(fileList: any[]): void {
let fileName = "";
if (fileList && fileList.length > 0) {
fileName = fileList[0].name;
}
message.warning(this.$t('common.upload_file_type_error', {name: fileName, suffixes: this.suffixes}));
}
showMessage(msg: string, type: "success" | "warning" | "error" | "info"): void {
switch (type) {
case "success":
message.success(msg);
break;
case "warning":
message.warning(msg);
break;
case "error":
message.error(msg);
break;
case "info":
message.info(msg);
break;
}
}
}
</script>
<style scoped>
.dragger {
::v-deep(.ant-upload) {
height: auto !important
}
}
</style>