|
@@ -187,7 +187,6 @@
|
187
|
187
|
import '../assets/reset.css'
|
188
|
188
|
import getApi from '../apis.js'
|
189
|
189
|
import request from '../utils/request.js'
|
190
|
|
-import { newWebsocket } from '../utils/websocket.js'
|
191
|
190
|
export default {
|
192
|
191
|
name: 'draw',
|
193
|
192
|
data () {
|
|
@@ -217,23 +216,30 @@ export default {
|
217
|
216
|
randomArr: [],
|
218
|
217
|
windowWidth: window.innerWidth,
|
219
|
218
|
windowHeight: window.innerHeight,
|
220
|
|
- drawWidth: Math.floor(window.innerWidth * .7)
|
|
219
|
+ drawWidth: Math.floor(window.innerWidth * .7),
|
|
220
|
+ getDrawStatus: true
|
221
|
221
|
}
|
222
|
222
|
},
|
223
|
223
|
created () {
|
224
|
|
- this.initWebSocket()
|
225
|
224
|
this.getUserList()
|
226
|
225
|
this.getPrizeList()
|
227
|
226
|
},
|
228
|
227
|
mounted () {
|
229
|
228
|
this.$nextTick(() => {
|
230
|
229
|
this.canvasInit()
|
|
230
|
+ this.drawStatus()
|
|
231
|
+ // var timer = null
|
|
232
|
+ // timer = window.setInterval(() => {
|
|
233
|
+ // if (this.getDrawStatus) {
|
|
234
|
+ // this.drawStatus()
|
|
235
|
+ // } else {
|
|
236
|
+ // window.clearInterval(timer)
|
|
237
|
+ // timer = null
|
|
238
|
+ // }
|
|
239
|
+ // }, 60000)
|
231
|
240
|
})
|
232
|
241
|
},
|
233
|
242
|
methods: {
|
234
|
|
- initWebSocket () {
|
235
|
|
- newWebsocket('ws://192.168.0.11:8080/api/ws?id=web', this.webSocketCallback)
|
236
|
|
- },
|
237
|
243
|
webSocketCallback (e) {
|
238
|
244
|
console.log(e)
|
239
|
245
|
},
|
|
@@ -343,6 +349,26 @@ export default {
|
343
|
349
|
this.initUsers = res.users.map(x => ({ ...x, active: false, show: true, delete: false, orgName: x.UserOrg }))
|
344
|
350
|
})
|
345
|
351
|
},
|
|
352
|
+ drawStatus () {
|
|
353
|
+ if (this.getDrawStatus) {
|
|
354
|
+ this.getDrawStatus = false
|
|
355
|
+ const api = getApi('drawStatus')
|
|
356
|
+ request(api).then((res) => {
|
|
357
|
+ res = JSON.parse(res)
|
|
358
|
+ this.getDrawStatus = true
|
|
359
|
+ // this.initDraw(res)
|
|
360
|
+ if (res.type === 'start') {
|
|
361
|
+ this.startDrawStep()
|
|
362
|
+ this.drawStatus()
|
|
363
|
+ } else if (res.type === 'stop') {
|
|
364
|
+ this.stopDrawStep()
|
|
365
|
+ }
|
|
366
|
+ }).catch(() => {
|
|
367
|
+ this.getDrawStatus = true
|
|
368
|
+ this.drawStatus()
|
|
369
|
+ })
|
|
370
|
+ }
|
|
371
|
+ },
|
346
|
372
|
getPrizeList () { // 获取奖品数据
|
347
|
373
|
const api = getApi('prize.list')
|
348
|
374
|
request(api).then((res) => {
|
|
@@ -355,93 +381,99 @@ export default {
|
355
|
381
|
this.initDraw()
|
356
|
382
|
}
|
357
|
383
|
},
|
358
|
|
- initDraw () { // 初始化抽奖
|
|
384
|
+ initDraw (res) { // 初始化抽奖
|
359
|
385
|
document.getElementsByTagName('html')[0].onkeydown = (e) => { // 页面添加键盘点击事件监听
|
360
|
386
|
e = e || event
|
361
|
387
|
if (e.ctrlKey && e.keyCode == 13) { // 启停抽奖组合键:Ctrl + Enter
|
362
|
388
|
this.sureStatus = true
|
363
|
389
|
if (!this.status) { // 重新抽奖
|
364
|
|
- const api = getApi('draw')
|
365
|
|
- request(api).then((res) => {
|
366
|
|
- this.currentPrize = {
|
367
|
|
- img: this.prizeList.filter((item) => { if (item.PrizeName === res.winner[0].PrizeName) return item.Picture })[0].Picture,
|
368
|
|
- name: res.winner[0].PrizeName || '未知奖品',
|
369
|
|
- num: res.winner.length || 0,
|
370
|
|
- type: this.prizeList.filter((item) => { if (item.PrizeName === res.winner[0].PrizeName) return item.PrizeType })[0].PrizeType
|
371
|
|
- }
|
372
|
|
- this.winner = res.winner || []
|
373
|
|
- this.drawCount = res.winner.length || 0
|
374
|
|
- this.bgGrey = true
|
375
|
|
- this.projectStart = false
|
376
|
|
- this.status = !this.status
|
377
|
|
- this.users = []
|
378
|
|
- this.drawUsersArr = [] // 置空中奖数据
|
379
|
|
- this.calcRandomArr(this.initUsers.length > 90 ? 90 : this.initUsers.length, this.initUsers, this.users, 'UserId', this.drawCount)
|
380
|
|
- this.arrTimer = window.setInterval(() => {
|
381
|
|
- this.users = []
|
382
|
|
- this.calcRandomArr(this.initUsers.length > 90 ? 90 : this.initUsers.length, this.initUsers, this.users, 'UserId', this.drawCount)
|
383
|
|
- }, this.time)
|
384
|
|
- })
|
|
390
|
+ this.startDrawStep()
|
385
|
391
|
} else { // 抽奖变换动画暂定
|
386
|
|
- this.status = !this.status
|
387
|
|
- clearInterval(this.arrTimer)
|
388
|
|
- this.arrTimer = null
|
389
|
|
- var num = 0
|
390
|
|
- this.users.map((item) => { // 记录中奖数据,以便读取过渡动画结束位置坐标
|
391
|
|
- if (item.active) {
|
392
|
|
- item.UserName = this.winner[num].UserName
|
393
|
|
- item.orgName = this.winner[num].UserOrg
|
394
|
|
- item.isReset = true
|
395
|
|
- num += 1
|
396
|
|
- this.drawUsersArr.push({ ...item, width: 0, startX: '', startY: '', listX: '', listY: '' })
|
397
|
|
- }
|
398
|
|
- })
|
399
|
|
- this.$nextTick(() => {
|
400
|
|
- this.drawUsersArr.map((item, index) => { // 记录中奖名单结束位置坐标
|
401
|
|
- item.endX = document.getElementsByClassName('targetLi')[index].getBoundingClientRect().x
|
402
|
|
- item.endY = document.getElementsByClassName('targetLi')[index].getBoundingClientRect().y
|
403
|
|
- })
|
404
|
|
- window.setTimeout(() => {
|
405
|
|
- this.drawUsersArr.map((item, index) => { // 记录中奖名单结束位置坐标
|
406
|
|
- item.listX = document.getElementsByClassName('endListLi')[index].getBoundingClientRect().x
|
407
|
|
- item.listY = document.getElementsByClassName('endListLi')[index].getBoundingClientRect().y
|
408
|
|
- })
|
409
|
|
- }, 50)
|
410
|
|
- for (var n = 0; n < this.drawCount; n++) { // 记录中奖名单开始位置坐标
|
411
|
|
- this.drawUsersArr[n].startX = document.getElementsByClassName('activeLi')[n].getBoundingClientRect().x
|
412
|
|
- this.drawUsersArr[n].startY = document.getElementsByClassName('activeLi')[n].getBoundingClientRect().y
|
413
|
|
- this.drawUsersArr[n].width = document.getElementsByClassName('activeLi')[n].getBoundingClientRect().width
|
414
|
|
- }
|
415
|
|
- this.drawUsersArr.map((item, index) => {
|
416
|
|
- item.UserId = this.winner[index].UserId,
|
417
|
|
- item.UserName = this.winner[index].UserName,
|
418
|
|
- item.orgName = this.winner[index].UserOrg
|
419
|
|
- })
|
420
|
|
- window.setTimeout(() => {
|
421
|
|
- this.users.map((item) => { // 隐藏未抽中数据
|
422
|
|
- item.show = false
|
423
|
|
- })
|
424
|
|
- this.drawUsersArr.map((item) => {
|
425
|
|
- item.startX = item.endX
|
426
|
|
- item.startY = item.endY
|
427
|
|
- })
|
428
|
|
- window.setTimeout(() => {
|
429
|
|
- this.animationOff = true
|
430
|
|
- }, 1000)
|
431
|
|
- window.setTimeout(() => {
|
432
|
|
- this.bgGrey = false
|
433
|
|
- this.hidePrize = false
|
434
|
|
- this.drawUsersArr.map((item) => {
|
435
|
|
- item.startX = item.listX
|
436
|
|
- item.startY = item.listY
|
437
|
|
- })
|
438
|
|
- }, 2500)
|
439
|
|
- }, 1000)
|
440
|
|
- })
|
|
392
|
+ this.stopDrawStep()
|
441
|
393
|
}
|
442
|
394
|
}
|
443
|
395
|
}
|
444
|
396
|
},
|
|
397
|
+ startDrawStep () {
|
|
398
|
+ const api = getApi('draw')
|
|
399
|
+ request(api).then((res) => {
|
|
400
|
+ this.currentPrize = {
|
|
401
|
+ img: this.prizeList.filter((item) => { if (item.PrizeName === res.winner[0].PrizeName) return item.Picture })[0].Picture,
|
|
402
|
+ name: res.winner[0].PrizeName || '未知奖品',
|
|
403
|
+ num: res.winner.length || 0,
|
|
404
|
+ type: this.prizeList.filter((item) => { if (item.PrizeName === res.winner[0].PrizeName) return item.PrizeType })[0].PrizeType
|
|
405
|
+ }
|
|
406
|
+ this.winner = res.winner || []
|
|
407
|
+ this.drawCount = res.winner.length || 0
|
|
408
|
+ this.bgGrey = true
|
|
409
|
+ this.projectStart = false
|
|
410
|
+ this.status = !this.status
|
|
411
|
+ this.users = []
|
|
412
|
+ this.drawUsersArr = [] // 置空中奖数据
|
|
413
|
+ this.calcRandomArr(this.initUsers.length > 90 ? 90 : this.initUsers.length, this.initUsers, this.users, 'UserId', this.drawCount)
|
|
414
|
+ this.arrTimer = window.setInterval(() => {
|
|
415
|
+ this.users = []
|
|
416
|
+ this.calcRandomArr(this.initUsers.length > 90 ? 90 : this.initUsers.length, this.initUsers, this.users, 'UserId', this.drawCount)
|
|
417
|
+ }, this.time)
|
|
418
|
+ })
|
|
419
|
+ },
|
|
420
|
+ stopDrawStep () {
|
|
421
|
+ this.status = !this.status
|
|
422
|
+ clearInterval(this.arrTimer)
|
|
423
|
+ this.arrTimer = null
|
|
424
|
+ var num = 0
|
|
425
|
+ this.users.map((item) => { // 记录中奖数据,以便读取过渡动画结束位置坐标
|
|
426
|
+ if (item.active) {
|
|
427
|
+ item.UserName = this.winner[num].UserName
|
|
428
|
+ item.orgName = this.winner[num].UserOrg
|
|
429
|
+ item.isReset = true
|
|
430
|
+ num += 1
|
|
431
|
+ this.drawUsersArr.push({ ...item, width: 0, startX: '', startY: '', listX: '', listY: '' })
|
|
432
|
+ }
|
|
433
|
+ })
|
|
434
|
+ this.$nextTick(() => {
|
|
435
|
+ this.drawUsersArr.map((item, index) => { // 记录中奖名单结束位置坐标
|
|
436
|
+ item.endX = document.getElementsByClassName('targetLi')[index].getBoundingClientRect().x
|
|
437
|
+ item.endY = document.getElementsByClassName('targetLi')[index].getBoundingClientRect().y
|
|
438
|
+ })
|
|
439
|
+ window.setTimeout(() => {
|
|
440
|
+ this.drawUsersArr.map((item, index) => { // 记录中奖名单结束位置坐标
|
|
441
|
+ item.listX = document.getElementsByClassName('endListLi')[index].getBoundingClientRect().x
|
|
442
|
+ item.listY = document.getElementsByClassName('endListLi')[index].getBoundingClientRect().y
|
|
443
|
+ })
|
|
444
|
+ }, 50)
|
|
445
|
+ for (var n = 0; n < this.drawCount; n++) { // 记录中奖名单开始位置坐标
|
|
446
|
+ this.drawUsersArr[n].startX = document.getElementsByClassName('activeLi')[n].getBoundingClientRect().x
|
|
447
|
+ this.drawUsersArr[n].startY = document.getElementsByClassName('activeLi')[n].getBoundingClientRect().y
|
|
448
|
+ this.drawUsersArr[n].width = document.getElementsByClassName('activeLi')[n].getBoundingClientRect().width
|
|
449
|
+ }
|
|
450
|
+ this.drawUsersArr.map((item, index) => {
|
|
451
|
+ item.UserId = this.winner[index].UserId,
|
|
452
|
+ item.UserName = this.winner[index].UserName,
|
|
453
|
+ item.orgName = this.winner[index].UserOrg
|
|
454
|
+ })
|
|
455
|
+ window.setTimeout(() => {
|
|
456
|
+ this.users.map((item) => { // 隐藏未抽中数据
|
|
457
|
+ item.show = false
|
|
458
|
+ })
|
|
459
|
+ this.drawUsersArr.map((item) => {
|
|
460
|
+ item.startX = item.endX
|
|
461
|
+ item.startY = item.endY
|
|
462
|
+ })
|
|
463
|
+ window.setTimeout(() => {
|
|
464
|
+ this.animationOff = true
|
|
465
|
+ }, 1000)
|
|
466
|
+ window.setTimeout(() => {
|
|
467
|
+ this.bgGrey = false
|
|
468
|
+ this.hidePrize = false
|
|
469
|
+ this.drawUsersArr.map((item) => {
|
|
470
|
+ item.startX = item.listX
|
|
471
|
+ item.startY = item.listY
|
|
472
|
+ })
|
|
473
|
+ }, 2500)
|
|
474
|
+ }, 1000)
|
|
475
|
+ })
|
|
476
|
+ },
|
445
|
477
|
calcRandomArr (num, pArr, aArr, key, activeNum) {
|
446
|
478
|
var randomNum = Math.floor(Math.random() * pArr.length), bool = false
|
447
|
479
|
if (pArr.length > num) {
|