modal-import.vue
2.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
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
104
105
106
107
108
109
110
111
<template>
<Modal v-model="model" class-name="vertical-center-modal">
<p slot="header">
{{ title }}
</p>
<Form label-position="left" :label-width="80">
<Form-item label="上传文件:">
<upload-xlsx
ref="upload"
:data="importParams"
:action="action"
:on-success="uploadSuccess"
:on-error="uploadError"
:on-change="uploadChange"
>
<Button type="ghost" icon="ios-cloud-upload-outline">上传文件</Button>
</upload-xlsx>
<span>{{ name }}</span>
</Form-item>
<slot name="remark"> </slot>
</Form>
<slot name="report"></slot>
<div slot="footer" style="text-align: center">
<Button type="primary" size="large" :disabled="disableSave" :loading="modelLoading" @click="upload">保存</Button>
<Button type="primary" size="large" @click="close">取消</Button>
</div>
</Modal>
</template>
<script>
import _ from 'lodash';
export default {
name: 'ModalImport',
props: {
value: {
type: Boolean,
default: false,
},
action: {
type: String,
default: '/import',
},
title: {
type: String,
default: '导入',
},
transParams: {
type: Object,
default: () => {
return {};
},
},
},
data() {
return {
model: this.value,
modelLoading: false,
disableSave: true,
fileName: '',
};
},
computed: {
name() {
return this.fileName || '未选择任何文件';
},
importParams() {
const ps = {};
_.map(this.transParams, (v, k) => {
if (typeof v === 'object') {
ps[k] = JSON.stringify(v);
} else {
ps[k] = v;
}
});
return ps;
},
},
methods: {
uploadSuccess(result) {
this.$emit('import', result);
},
uploadError(err) {
this.$emit('upload-error', err);
},
uploadChange(files) {
if (files.length > 0) {
//导入取消无name
this.fileName = files[0].name;
this.disableSave = false;
}
},
upload() {
this.modelLoading = true;
this.$refs.upload.upload();
},
close() {
this.model = false;
this.disableSave = true;
this.fileName = '';
this.$refs.upload.clear();
this.modelLoading = false;
},
show() {
this.model = true;
},
},
};
</script>