index.vue
13.1 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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
<template>
<div>
<div class="d2-mr personal-wrap">
<el-popover ref="popover1"
placement="top-start"
width="400"
@show="redPotShow = false"
popper-class="popper"
v-model="visible"
trigger="hover">
<p class="title">导出和导出任务</p>
<p class="tips"> 导出和导出任务加载完成后将自动进行下载,加载过程中不要离开系统,否则将导致任务自动清空</p>
<!-- <div v-for="(item,index) in dowloadList"
:key="index"
class="downloadSty">
<span class="one-line-ellipsis downName">{{item.name}}</span>
<span class="downLabel"> {{item.labelText}}</span>
</div> -->
<div v-for="(item,index) in updateList"
:key="index+'a'"
class="updateListClass">
<div v-if="item.progress!= 100">
<p>{{item.name}}</p>
<el-progress :percentage="item.progress?item.progress:2"></el-progress>
</div>
<div v-else>
<p>{{item.name||''}}</p>
<p>成功{{item.succNum}}条<span v-if="item.failNum">,失败{{item.failNum}}条</span></p>
</div>
</div>
<!-- @click="test" -->
<span slot="reference">
<i class="el-icon-bell tipsIcon "
:class="{'redPot':redPotShow }"></i>
</span>
</el-popover>
<span v-if="show"
class="btn-text">{{info && info.detail ? (info.detail.userType == 2 ? `${info.detail.userName}` : '管理员') : '未登录'}}</span>
<span class="btn-text out-txt"
@click="clear">退出</span>
</div>
</div>
</template>
<script>
// mapMutations
import { mapActions, mapState, mapMutations } from 'vuex'
// import PersonalPanel from '../personal-panel'
import { getImportResult } from '@api/order'
import { exportExcel } from '@api/sys.base'
import { downLoadFile } from '@/common/util'
var dowloadTimer = 0
var uploadTimer = 0
export default {
components: {
// PersonalPanel
},
data() {
return {
show: true,
accountPanelVisible: false,
userVisible: false,
visiblepop: true,
visible: false,
accountInfo: {
accountList: []
},
info: {},
timeStep: [0, 1, 3, 5, 8, 15],
// timeStep: [0, 1],
dowloadTimerNum: 0,
// dowloadTimer: 0,
uploadTimerNum: 0,
redPotShow: false
}
},
computed: {
...mapState({
'dowloadList': (state) => state.d2admin.user.dowloadList,
'updateList': (state) => state.d2admin.user.updateList
})
},
watch: {
dowloadList: {
handler(val, oldVal) {
console.log('watch', val)
const searchList = val.filter(item => !item.ifSuccess)
if (searchList.length) {
// console.log('searchList.length', searchList.length)
const oldList = oldVal || []
// console.log(!oldList || val.length > oldList.length)
if (!oldList || val.length > oldList.length) {
this.redPotShow = true
const that = this
setTimeout(() => {
that.visible = true
}, 2000)
clearInterval(dowloadTimer)
this.dowloadTimerNum = 0
// this.getUploadlistInfo(searchList)
this.getDownloadslistInfo(searchList)
}
}
},
deep: true,
immediate: true
},
updateList: {
handler(val, oldVal) {
// console.log('watch', val)
// console.log('oldVal', oldVal)
// 假如相等可以认为是轮询结果,跳过
// 只有新老长度有变化才可以认为是新增的
const searchList = val.filter(item => !item.ifSuccess)
if (searchList.length) {
// console.log('searchList.length', searchList.length)
const oldList = oldVal || []
// console.log(!oldList || val.length > oldList.length)
if (!oldList || val.length > oldList.length) {
this.redPotShow = true
const that = this
setTimeout(() => {
that.visible = true
}, 2000)
clearInterval(uploadTimer)
this.uploadTimerNum = 0
this.getUploadlistInfo(searchList)
}
}
},
deep: true,
immediate: true
}
// 调用其他接口,导致表格刷新-标识
// '$store.state.d2admin.refreshtable.value'(val) {
// (val === 'fresh') && this.refreshEmit()
// }
},
mounted() {
this.show = false
this.$event.$on('e-password-dialog', res => (this.passVisible = res))
this.getInfo()
// const list = [
// {
// name: '下载测试登记卡洞口兰格拉斯蛋糕卡嘎嘎就固特威outwe和',
// ifSuccess: false,
// uuid: '282d9222-1076-4b49-a4f6-fdf265d85c40',
// labelText: '导出中'
// status: 'loading',
// type: 'downloads',
// }
// ]
// this.actionSetDownloadList({ list, type: 'dowloadList' })
},
methods: {
...mapActions('d2admin/user', ['load', 'loadAcocunt', 'actionSetDownloadList']),
...mapActions('d2admin/account', ['logout']),
...mapMutations('d2admin/user', ['setUpdateRefesh']),
getUploadlistInfo(list) {
// if (this.dowloadTimer) {
const that = this
const num = this.timeStep[this.uploadTimerNum] ?? 15
// console.log(num)
// console.log('num', num)
// console.log(dowloadTimer)
uploadTimer = setTimeout(() => {
that.getUpload(list)
}, num * 1000)
// }
this.dowloadTimerNum++
},
getDownloadslistInfo(list) {
// if (this.dowloadTimer) {
const that = this
const num = this.timeStep[this.dowloadTimerNum] ?? 15
// console.log(num)
// console.log('num', num)
// console.log(dowloadTimer)
uploadTimer = setTimeout(() => {
that.getDownloads(list)
}, num * 1000)
// }
this.dowloadTimerNum++
},
getUpload(list) {
// 模拟接口调用
const uuids = list.map((item) => {
return item.uuid
})
// console.log(uuids)
// return
getImportResult({ uuids }).then((result) => {
let flag = false
// 根据情况处理数据
const list = this.updateList.map((item) => {
result.map((ele) => {
if (ele.uuid == item.uuid) {
item = Object.assign(item, ele)
item.ifSuccess = ele.progress == 100
if (item.ifSuccess) {
flag = true
if (ele.failNum) {
this.notice.warningTips('部分导入失败,请修改后重新导入')
downLoadFile(ele.url)
} else {
this.notice.okTips('导入成功')
}
}
}
})
return item
})
// 判断是否需要刷新列表
console.log('flag', flag)
flag && this.setUpdateRefesh(true)
this.actionSetDownloadList({ list, type: 'updateList' })
// console.log(list)
const needSearchList = this.filterNoSucces(list)
console.log(needSearchList)
// return
if (needSearchList.length) {
this.uploadTimerNum++
this.getUploadlistInfo(needSearchList)
}
}).catch((err) => {
console.log(err)
})
},
getDownloads(list) {
const fileUuidList = list.map((item) => {
return item.uuid
})
console.log(fileUuidList)
// return
exportExcel({ fileUuidList }).then((result) => {
console.log(result)
// return
// const flag = false
const status = {
0: '导出中',
1: '导出成功',
2: '导出失败'
}
// 根据情况处理数据
console.log(this.dowloadList)
const list = this.dowloadList.map((item) => {
result.map((ele) => {
if (ele.fileUuid == item.uuid) {
item = Object.assign(item, ele)
item.ifSuccess = ele.status != 0
if (ele.status == 1) {
// console.log(ele.fileUrl)
downLoadFile(ele.fileUrl)
this.notice.okTips(status[ele.status])
} else if (ele.status == 2) {
this.notice.warningTips(status[ele.status])
}
item.labelText = status[ele.status]
}
})
return item
})
// 判断是否需要刷新列表
// console.log('flag', flag)
// flag && this.setUpdateRefesh(true)
console.log('list', list)
this.actionSetDownloadList({ list, type: 'dowloadList' })
const needSearchList = this.filterNoSucces(list)
console.log(needSearchList)
// return
if (needSearchList.length) {
this.dowloadTimerNum++
this.getDownloadslistInfo(needSearchList)
}
}).catch((err) => {
console.log(err)
})
},
filterNoSucces(list) {
// console.log(list)
return list.filter((item) => {
return !item.ifSuccess
})
},
// test() {
// console.log('click')
// // const list = [
// // // {
// // // name: 'xxx店订单补录2022-02-04test',
// // // ifSuccess: false,
// // // id: 1,
// // // status: 'loading',
// // // type: 'upload',
// // // labelText: '导入成功110条, 导入失败1条'
// // // }
// // ]
// const list = [{
// uuid: '5b2a53b5-6aeb-49ba-9691-8c32903327e8',
// name: 'test2',
// ifSuccess: false,
// labelText: ''
// }]
// this.actionSetDownloadList({ list, type: 'updateList' })
// },
handleChangeAccount() {
this.accountPanelVisible = !this.accountPanelVisible
},
handleAccountClose() {
this.userVisible = !this.userVisible
this.accountPanelVisible = false
},
/**
* @description 登出
*/
clear() {
this.$confirm('确认退出?', '退出', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(async () => {
const reload = async () => {
localStorage.clear()
await this.logout()
window.location.reload()
}
if (this.$router.currentRoute.name === 'index') {
reload()
} else {
this.$router.push({ name: 'index' })
var _t = setInterval(() => {
if (this.$router.currentRoute.name === 'index') {
clearInterval(_t)
reload()
}
}, 0)
}
})
},
async logOut() {
this.$confirm('确认退出?', '退出', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(async () => {
this.$router.push('/login')
await this.logout()
await this.$StoreReset.call(this.$store) // 重置 store
})
},
async getInfo() {
this.info = await this.load()
this.accountInfo = await this.loadAcocunt()
this.$nextTick(() => {
this.show = true
})
}
},
beforeDestroy() {
clearInterval(dowloadTimer)
clearInterval(uploadTimer)
}
}
</script>
<style lang="scss">
.personal-wrap {
transform: translateY(-3px);
}
.personal-wrap .arrow-icon {
cursor: pointer;
}
.el-icon-arrow-down {
transition: all 0.2s ease-in-out;
}
.personal-wrap .arrow-icon.drOpen {
transform: rotate(-180deg);
}
.tipsIcon {
font-size: 12px;
position: relative;
}
.redPot::after {
content: '';
width: 6px;
height: 6px;
border-radius: 3px;
background-color: red;
position: absolute;
top: -2px;
right: -2px;
}
.popper {
padding: 20px 18px 16px;
z-index: 200;
.title {
font-weight: 600;
font-size: 16px;
margin-bottom: 16px;
margin-top: 0;
color: #333;
}
.downloadSty {
display: flex;
align-items: center;
justify-content: space-between;
}
.downName {
width: 70%;
overflow: hidden;
}
.tips {
word-break: break-all;
font-size: 14px;
color: #333;
}
.updateListClass {
margin-bottom: 15px;
p {
margin: 5px 0;
}
}
}
.accout-panel {
left: -160px;
top: 0;
}
.accout-panel .panel-item {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
max-width: 10em;
line-height: 36px;
padding: 0 20px;
margin: 0;
font-size: 14px;
color: #606266;
user-select: none;
cursor: pointer;
}
.accout-panel .i {
margin-right: 5px;
}
.accout-panel .hidden {
display: none;
}
.accout-panel .el-button--text {
color: #606266;
}
</style>