HtImportButton.vue
5.5 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
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<template>
<span>
<el-button icon="el-icon-back" @click="importDialogVisible = true">导入</el-button>
<el-dialog
:title="'导入'+name"
:visible.sync="importDialogVisible"
width="40%"
top="30vh"
:close-on-click-modal="false"
name="uploadDialog"
custom-class="upload-dialog"
v-if="importDialogVisible"
>
<div style="height: 150px; padding-left: 20px">
<eip-sys-type-selector
v-if="typeKey || catId"
placeholder="请选择分类"
:type-key="typeKey"
:cat-id="catId"
v-model="formTypeSelectorCatName"
:sys-type-id.sync="formTypeSelectorCatId"
:validate="{required: true}"
/>
<br />
<br />
<el-upload
style="display: inline-block"
:action="realUploadUrl"
:on-success="handleUploadResult"
:on-error="handleUploadResult"
:headers="uploadHeaders"
:on-exceed="onExceed"
accept=".zip"
:before-upload="beforeUpload"
:limit="1"
:auto-upload="false"
ref="upload"
>
<el-button size="small" icon="el-icon-upload">选择{{name}}</el-button>
</el-upload>
</div>
<span slot="footer" class="dialog-footer" style="text-align: right;">
<el-button @click="importDialogVisible = false">取 消</el-button>
<el-button
type="primary"
@click="uploadSubmit"
element-loading-text="导入中..."
v-loading.fullscreen.lock="fullscreenLoading"
>确 定</el-button
>
</span>
</el-dialog>
<el-dialog
title="温馨提示"
:visible="myDialogVisible"
:before-close="beforeClose2"
name="myDialogVisible"
width="30%"
custom-class="upload-dialog"
top="30vh"
>
<span>部分{{name}}已存在,请确认重复项的导入操作!</span>
<span slot="footer" class="dialog-footer" style="text-align: right;">
<el-button type="default" @click="beforeClose2">取消</el-button>
<el-button type="primary" @click="confirmSubmit('jump')"
>跳过重复项</el-button
>
<el-button type="primary" @click="confirmSubmit('cover')"
>覆盖更新</el-button
>
</span>
</el-dialog>
</span>
</template>
<script>
import req from '@/request.js'
import {mapState} from 'vuex'
const EipSysTypeSelector = () =>import('@/components/selector/EipSysTypeSelector.vue')
export default {
components: { EipSysTypeSelector },
name: 'ht-import-button',
props: {
typeKey: {
type: String,
default: '',
},
catId: {
type: String,
default: '',
},
requestMethod: {
type: String,
default: 'POST',
},
uploadUrl: {
type: String,
required: true,
},
confirmUrl: {
type: String,
required: true,
},
name: {
type: String,
required: true,
},
htTable: {
type: Object,
},
},
data() {
return {
importDialogVisible: false,
formTypeSelectorCatId:'',
formTypeSelectorCatName:'',
myDialogVisible: false,
fullscreenLoading: false
}
},
computed: {
...mapState({
uploadHeaders: function(mapState) {
return {Authorization: 'Bearer ' + mapState.login.currentUser.token}
},
realUploadUrl: function() {
if (this.typeKey || this.catId) {
return this.uploadUrl +this.formTypeSelectorCatId
}
return this.uploadUrl
}
})
},
mounted() {},
methods: {
handleSuccess(message) {
this.$message.success(message)
this.myDialogVisible = false
if (this.htTable) {
this.htTable.querys = []
this.htTable.load()
}
this.importDialogVisible = false
this.fullscreenLoading = false
},
confirmSubmit(arg) {
const this_ = this
let url =this.confirmUrl + this.uploadAddress +'&status=' + arg
if (this.typeKey || this.catId) {
url+= '&typeId=' +this.formTypeSelectorCatId
}
req.post(url).then(function(rep) {
rep = rep.data
if (rep && rep.state) {
this_.handleSuccess(rep.message)
} else {
this_.$message.error(rep.message || '保存失败')
}
})
},
handleUploadResult(data) {
if (data.state) {
if (data.message && data.message == 'confirmUpload') {
this.uploadAddress = data.value
this.myDialogVisible = true
return
} else {
this.handleSuccess(data.message)
}
} else {
this.fullscreenLoading = false
this.$message({type: 'error', message: data.message})
}
},
beforeUpload(file) {
if (!file.name.endsWith('.zip')) {
this.$message.warning('只能导入zip文件!')
return false
}
this.fullscreenLoading = true
},
onExceed(file) {
this.$message.warning('只能选择一个zip文件!')
},
uploadSubmit() {
if (
!this.$refs.upload.uploadFiles ||
this.$refs.upload.uploadFiles.length == 0
) {
this.$message.warning('请选择要导入的'+this.name+'!')
return false
}
this.$refs.upload.submit()
},
beforeClose2() {
this.myDialogVisible = false
this.fullscreenLoading = false
}
},
}
</script>