whiteListModal.vue
10.9 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
<template>
<a-modal
:title="title"
:width="800"
:centered="true"
:visible="visible"
:confirmLoading="confirmLoading"
@ok="handleSubmit"
@cancel="handleCancel"
cancelText="关闭"
style="top:20px;"
:maskClosable="false"
>
<a-spin :spinning="confirmLoading">
<a-form :form="form">
<!-- <a-form-item label="业务渠道编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
<a-select
placeholder="请选择业务渠道编号"
@change="handleChange"
v-decorator="[ 'businessChannelNo', validatorRules.businessChannelNo]"
>
<a-select-option
v-for="(item, index) in productList"
:key="index"
:value="item.productNo"
>{{item.productName}}</a-select-option>
</a-select>
</a-form-item> -->
<template v-if="type=='add'">
<a-form-item label="业务渠道名称" :labelCol="labelCol" :wrapperCol="wrapperCol" hasFeedback>
<a-select
placeholder="请选择业务渠道名称"
:labelInValue="true"
@change="value => handleChange(value)"
v-decorator="[ 'businessChannelName', validatorRules.businessChannelNo]"
>
<a-select-option
v-for="(item, index) in productList"
:key="index"
:value="item.businessChannelNo"
>{{item.businessChannelName}}</a-select-option>
</a-select>
</a-form-item>
<a-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
<a-textarea rows="4" placeholder="最多输入300字" v-decorator="['remark']" />
</a-form-item>
</template>
<template v-else>
<a-form-item
label="上传白名单文件"
:labelCol="labelCol"
:wrapperCol="wrapperCol"
>
<div class="pos">
<input id="file" type="file" accept=".xls,.xlsx" ref="uploadFile" @change="handleFile" name="file" />
<span style="position:absolute;left:120px;">{{uploadUrl}}</span>
<span class="abso">上传白名单文件</span>
</div>
<!-- <a-upload
accept=".xls,.xlsx"
name="file"
:action="url.upload"
@change="upLoadChange"
>
<a-button>
<a-icon type="upload" />上传文件
</a-button>
</a-upload> -->
<a @click="downList('白名单模板')">白名单模板下载</a><br>
<a v-show="failShow" @click="downListFail('校验失败的白名单记录')" style="color:red;">校验失败的白名单记录下载</a>
</a-form-item>
</template>
</a-form>
</a-spin>
</a-modal>
</template>
<script>
import { postAction, downFile,saveWhiteListConfiguration,updateWhiteListConfiguration } from '@/api/configApi'
import { getUploadFileList,getFilePaths } from '@/utils/commonUploadFile.js'
import { axios } from '@/utils/requestLocal'
import Vue from 'vue'
import { ACCESS_TOKEN } from "@/store/mutation-types"
export default {
name: 'PasswordModal',
data() {
return {
visible: false,
confirmLoading: false,
confirmDirty: false,
title: '上传白名单文件',
type:'add',
fileList:[],
productList: [],
validatorRules: {
businessChannelNo: {
rules: [
{
required: true,
message: '选择业务渠道编号'
}
]
},
upload: {
rules: [
{
required: true,
message: '请上传文件'
},
]
},
},
model: {
businessChannelNo:'',
businessChannelName:''
},
labelCol: {
xs: { span: 24 },
sm: { span: 5 }
},
wrapperCol: {
xs: { span: 24 },
sm: { span: 16 }
},
form: this.$form.createForm(this),
url: {
upload: window._CONFIG['uploadUrl'],
},
uploadData:{},
failShow:false,
uploadUrl:'',
}
},
created() {
this.initPrudect()
},
methods: {
handleChange(value) {
console.log(value)
this.model.businessChannelNo = value.key
this.model.businessChannelName = value.lable
},
// 下载白名单模板
downList(fileName){
downFile('/config/admin/whiteListExcelTemp').then(data => {
console.log(data)
if (!data) {
this.$message.warning("文件下载失败")
return
}
if (typeof window.navigator.msSaveBlob !== 'undefined') {
window.navigator.msSaveBlob(new Blob([data]), fileName+'.xlsx')
}else{
let url = window.URL.createObjectURL(new Blob([data]))
let link = document.createElement('a')
link.style.display = 'none'
link.href = url
link.setAttribute('download', fileName+'.xlsx')
document.body.appendChild(link)
link.click()
document.body.removeChild(link); //下载完成移除元素
window.URL.revokeObjectURL(url); //释放掉blob对象
}
})
},
// 下载校验失败的白名单记录
downListFail(fileName){
downFile(`/config/admin/exportWhiteListFails?id=${this.uploadData.id}`).then(data => {
console.log(data)
if (!data) {
this.$message.warning("文件下载失败")
return
}
if (typeof window.navigator.msSaveBlob !== 'undefined') {
window.navigator.msSaveBlob(new Blob([data]), fileName+'.xlsx')
}else{
let url = window.URL.createObjectURL(new Blob([data]))
let link = document.createElement('a')
link.style.display = 'none'
link.href = url
link.setAttribute('download', fileName+'.xlsx')
document.body.appendChild(link)
link.click()
document.body.removeChild(link); //下载完成移除元素
window.URL.revokeObjectURL(url); //释放掉blob对象
}
})
},
initPrudect() {
let _params = {
pageNo: 1,
pageSize: 10000,
params: {}
}
postAction('/config/admin/getBusinessChannelSelect', _params).then(r => {
this.productList = r.data
})
},
edit(records) {
this.form.resetFields()
this.visible = true
this.title = '上传白名单文件',
this.type = 'edit'
this.model=records
this.$nextTick(() => {
// this.form.setFieldsValue(records)
})
},
add(records) {
this.form.resetFields()
this.visible = true
this.title = '新增白名单配置',
this.type = 'add'
this.model={
businessChannelNo:'',
businessChannelName:'',
remark:''
},
this.$nextTick(() => {
this.form.setFieldsValue()
})
},
onChange() {},
close() {
this.uploadUrl = ''
this.$emit('close')
this.visible = false
this.disableSubmit = false
this.selectedRole = []
},
// 上传
handleFile(e){
this.confirmLoading = true
this.fileList = this.$refs.uploadFile.files[0];
console.log(!this.fileList)
if(this.$refs.uploadFile.files.length<=0){ //如果取消上传,则改文件的长度为0
this.confirmLoading = false
return;
}else{
//如果有文件上传,这在这里面进行
const formData = new FormData();
formData.append('businessChannelNo', this.model.businessChannelNo);
formData.append('businessChannelName', this.model.businessChannelName);
formData.append('whiteListFile', this.fileList);
postAction(`/config/admin/importWhiteListDetails`, formData).then((res) => {
if(res.status.statusCode == 0){
console.log(res)
this.uploadData = res.result
this.uploadUrl = res.result.fileName
this.uploadData.failNums>0?this.failShow = true : this.failShow = false;
this.$message.success(res.status.statusReason)
this.$emit('ok')
}else{
this.$message.warning(res.status.statusReason)
}
}).finally(() => {
this.confirmLoading = false
})
}
},
getObjectURL(file) {
var url = null;
if (window.createObjcectURL != undefined) {
url = window.createOjcectURL(file);
} else if (window.URL != undefined) {
url = window.URL.createObjectURL(file);
} else if (window.webkitURL != undefined) {
url = window.webkitURL.createObjectURL(file);
}
return url;
},
handleSubmit() {
// 触发表单验证
this.form.validateFields((err, values) => {
if (!err) {
this.confirmLoading = true
let formData = Object.assign(this.model, values)
if(this.type =='add'){
formData.businessChannelName = this.model.businessChannelName.label
saveWhiteListConfiguration(formData)
.then(res => {
if (res.status.statusCode == 0) {
this.$message.success(res.status.statusReason)
this.$emit('ok')
} else {
this.$message.warning(res.status.statusReason)
}
})
.finally(() => {
this.confirmLoading = false
this.close()
})
}else{
this.confirmLoading = false
this.close()
// const formData = new FormData();
// formData.append('businessChannelNo', this.model.businessChannelNo);
// formData.append('businessChannelName', this.model.businessChannelName);
// formData.append('whiteListFile', this.fileList);
// postAction(`/config/admin/importWhiteListDetails`, formData).then((res) => {
// if(res.status.statusCode == 0){
// this.uploadData = res.result
// this.uploadData.failNums>0?this.failShow = true : this.failShow = false;
// this.$message.success(res.status.statusReason)
// this.visible=false
// this.$emit('ok')
// }else{
// this.$message.warning(res.status.statusReason)
// }
// }).finally(() => {
// this.confirmLoading = false
// this.close()
// })
}
}
})
},
handleCancel() {
this.close()
}
}
}
</script>
<style scoped>
.pos{
height: 40px;
position: relative;
cursor: pointer;
}
.pos>input{
cursor: pointer;
width:100px;
}
#file{
opacity: 0;
position: absolute;
z-index: 2;
}
.abso{
cursor: pointer;
color:#1890FF;
font-size: 14px;
position: absolute;
left: 0;
top:0;
z-index: 1;
}
</style>