This repository was archived by the owner on Apr 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathEleImport.vue
181 lines (175 loc) · 3.75 KB
/
EleImport.vue
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<template>
<div>
<el-dialog
:title="title"
:visible="visible"
:width="dialogWidth"
@close="handlClose"
append-to-body
v-if="visible"
>
<ele-steps
:active="currentStep"
:steps="['下载模板', '上传文件', '确认数据', '完成']"
:stepsAttrs="{
'align-center': true
}"
/>
<!-- 下载模板 -->
<ele-import-download
:filepath="filepath"
v-if="currentStep === 1"
/>
<!-- 上传Excel -->
<ele-import-upload
:fields="fields"
:tips="tips"
@upload="handleUpload"
v-if="currentStep === 2"
/>
<!-- 数据展示 -->
<ele-import-data
:append="append"
:fields="fields"
:formatter="formatter"
:request-fn="requestFn"
:rules="rules"
:table-data="tableData"
@pre="handleStep3Pre"
v-if="currentStep === 3"
/>
<!-- 导入结束 -->
<ele-import-finish
@finish="handleFinish"
v-if="currentStep === 4"
/>
</el-dialog>
</div>
</template>
<script>
import EleSteps from 'vue-ele-steps'
import EleImportDownload from './components/EleImportDownload'
import EleImportUpload from './components/EleImportUpload'
import EleImportData from './components/EleImportData'
import EleImportFinish from './components/EleImportFinish'
export default {
name: 'EleImport',
props: {
// 文件路径
filepath: {
type: String,
required: true
},
// 请求方法
requestFn: {
type: Function,
required: true
},
// 导入字段
fields: {
type: Object,
required: true
},
// 是否显示弹窗
visible: {
type: Boolean,
required: true
},
// 标题
title: {
type: String,
default: '批量导入'
},
// 增加附加数据
append: Object,
// 提示信息,数组
tips: Array,
// 验证规则
rules: Object,
// 格式化数据
formatter: {
type: Object,
validator (formatter) {
for (const key in formatter) {
if (!(formatter[key] instanceof Object)) {
// eslint-disable-next-line
console.error(`${key}的值必须为 对象 或 函数`)
return false
}
}
return true
}
},
// 弹窗宽度
dialogWidth: {
type: String,
default: '80%'
}
},
components: {
EleSteps,
EleImportData,
EleImportUpload,
EleImportFinish,
EleImportDownload
},
provide () {
return {
goPre: this.preStep,
goNext: this.nextStep
}
},
data () {
return {
tableData: [],
columns: [],
currentStep: 1
}
},
methods: {
// 上传
handleUpload (columns, tableData) {
this.columns = columns
this.tableData = tableData
},
// 初始化数据
initData () {
this.tableData = []
this.columns = []
this.currentStep = 1
},
// 关闭
handlClose () {
this.initData()
this.$emit('close')
this.$emit('update:visible', false)
},
// 结束
handleFinish () {
this.handlClose()
this.$emit('finish')
},
// 下一步
nextStep () {
this.currentStep++
},
// 上一步
preStep () {
this.currentStep--
},
// 第3步 -> 第2步
handleStep3Pre () {
this.tableData = []
this.columns = []
this.preStep()
}
},
mounted () {}
}
</script>
<style>
.ele-import-action {
margin-top: 20px;
text-align: center;
}
</style>