|
@@ -0,0 +1,309 @@
|
|
1
|
+<template>
|
|
2
|
+ <div class="mainPage">
|
|
3
|
+ <img
|
|
4
|
+ src="../assets/images/icon1.jpg"
|
|
5
|
+ class="centerLabel cover bg"
|
|
6
|
+ :class="{'grey': bgGrey}"
|
|
7
|
+ style="z-index: 1;"
|
|
8
|
+ @load="imgLoad"
|
|
9
|
+ alt
|
|
10
|
+ >
|
|
11
|
+ <img
|
|
12
|
+ src="../assets/images/icon2.png"
|
|
13
|
+ width="100%"
|
|
14
|
+ class="bg"
|
|
15
|
+ :class="{'grey': bgGrey}"
|
|
16
|
+ style="z-index: 3;top:0;left:0"
|
|
17
|
+ @load="imgLoad"
|
|
18
|
+ alt
|
|
19
|
+ >
|
|
20
|
+ <div class="userList centerLabel">
|
|
21
|
+ <ul class="flex-h">
|
|
22
|
+ <li
|
|
23
|
+ v-for="(item, index) in users"
|
|
24
|
+ v-show="!item.delete"
|
|
25
|
+ class="flex-item"
|
|
26
|
+ :key="index"
|
|
27
|
+ :class="{'active': item.active, 'activeLi': item.active, 'hide': !item.show}"
|
|
28
|
+ >
|
|
29
|
+ <span>{{item.UserName}}</span>
|
|
30
|
+ </li>
|
|
31
|
+ </ul>
|
|
32
|
+ </div>
|
|
33
|
+ <div class="drawUserList centerLabel">
|
|
34
|
+ <ul class="flex-h">
|
|
35
|
+ <li
|
|
36
|
+ v-for="(item, index) in drawUsersArr"
|
|
37
|
+ class="flex-item targetLi"
|
|
38
|
+ :key="index"
|
|
39
|
+ :class="{'active': item.active}"
|
|
40
|
+ >
|
|
41
|
+ <span>{{item.UserName}}</span>
|
|
42
|
+ </li>
|
|
43
|
+ </ul>
|
|
44
|
+ </div>
|
|
45
|
+ <div class="drawEndList">
|
|
46
|
+ <a
|
|
47
|
+ v-for="(item, index) in drawUsersArr"
|
|
48
|
+ :key="index"
|
|
49
|
+ :style="{width: item.width + 'px', left: item.startX + 'px', top: item.startY + 'px'}"
|
|
50
|
+ >
|
|
51
|
+ <span>{{item.UserName}}</span>
|
|
52
|
+ </a>
|
|
53
|
+ </div>
|
|
54
|
+ </div>
|
|
55
|
+</template>
|
|
56
|
+
|
|
57
|
+<script>
|
|
58
|
+/* eslint-disable */
|
|
59
|
+import '../assets/reset.css'
|
|
60
|
+export default {
|
|
61
|
+ name: 'draw',
|
|
62
|
+ data () {
|
|
63
|
+ return {
|
|
64
|
+ bgGrey: false,
|
|
65
|
+ time: 300,
|
|
66
|
+ drawCount: 10,
|
|
67
|
+ imgTotal: 2,
|
|
68
|
+ curImgNum: 0,
|
|
69
|
+ status: false,
|
|
70
|
+ sureStatus: true,
|
|
71
|
+ arrTimer: null,
|
|
72
|
+ users: [],
|
|
73
|
+ initUsers: [],
|
|
74
|
+ drawUsersArr: [],
|
|
75
|
+ randomArr: [],
|
|
76
|
+ windowWidth: window.innerWidth,
|
|
77
|
+ windowHeight: window.innerHeight,
|
|
78
|
+ drawWidth: Math.floor(window.innerWidth * .7)
|
|
79
|
+ }
|
|
80
|
+ },
|
|
81
|
+ created () {
|
|
82
|
+ for (var n = 0; n < 500; n++) {
|
|
83
|
+ this.initUsers.push({
|
|
84
|
+ UserId: n + 1,
|
|
85
|
+ UserName: '姓名' + n,
|
|
86
|
+ active: false,
|
|
87
|
+ show: true,
|
|
88
|
+ delete: false
|
|
89
|
+ })
|
|
90
|
+ }
|
|
91
|
+ },
|
|
92
|
+ mounted () {
|
|
93
|
+ this.$nextTick(() => {
|
|
94
|
+ })
|
|
95
|
+ },
|
|
96
|
+ methods: {
|
|
97
|
+ imgLoad () {
|
|
98
|
+ this.curImgNum += 1 // 图片加载完 + 1
|
|
99
|
+ if (this.curImgNum >= this.imgTotal) { // 图片加载完毕之后执行抽奖初始化逻辑
|
|
100
|
+ this.initDraw()
|
|
101
|
+ }
|
|
102
|
+ },
|
|
103
|
+ initDraw () { // 初始化抽奖
|
|
104
|
+ // this.arrTimer = window.setInterval(() => { // 间隔时间进行抽奖随机变换效果
|
|
105
|
+ // this.users = [] // 每次变换之前置空当前显示列表
|
|
106
|
+ // this.calcRandomArr(90, this.initUsers, this.users, 'UserId', this.drawCount) // 从所有名单中随机获取若干个数据(获取数据个数,所有名单对象,当前显示名单列表对象,判重关键字,抽取中奖数量)
|
|
107
|
+ // }, this.time)
|
|
108
|
+ document.getElementsByTagName('html')[0].onkeydown = (e) => { // 页面添加键盘点击事件监听
|
|
109
|
+ e = e || event
|
|
110
|
+ if (e.ctrlKey && e.keyCode == 13) { // 启停抽奖组合键:Ctrl + Enter
|
|
111
|
+ this.sureStatus = true
|
|
112
|
+ if (!this.status) { // 重新抽奖
|
|
113
|
+ this.bgGrey = true
|
|
114
|
+ this.status = !this.status
|
|
115
|
+ this.users = []
|
|
116
|
+ this.drawUsersArr = [] // 置空中奖数据
|
|
117
|
+ this.calcRandomArr(90, this.initUsers, this.users, 'UserId', this.drawCount)
|
|
118
|
+ this.arrTimer = window.setInterval(() => {
|
|
119
|
+ this.users = []
|
|
120
|
+ this.calcRandomArr(90, this.initUsers, this.users, 'UserId', this.drawCount)
|
|
121
|
+ }, this.time)
|
|
122
|
+ } else { // 抽奖变换动画暂定
|
|
123
|
+ this.status = !this.status
|
|
124
|
+ clearInterval(this.arrTimer)
|
|
125
|
+ this.arrTimer = null
|
|
126
|
+ this.users.map((item) => { // 记录中奖数据,以便读取过渡动画结束位置坐标
|
|
127
|
+ if (item.active) {
|
|
128
|
+ this.drawUsersArr.push({ ...item, width: 0, startX: '', startY: '' })
|
|
129
|
+ }
|
|
130
|
+ })
|
|
131
|
+ this.$nextTick(() => {
|
|
132
|
+ this.drawUsersArr.map((item, index) => { // 记录中奖名单结束位置坐标
|
|
133
|
+ item.endX = document.getElementsByClassName('targetLi')[index].getBoundingClientRect().x
|
|
134
|
+ item.endY = document.getElementsByClassName('targetLi')[index].getBoundingClientRect().y
|
|
135
|
+ })
|
|
136
|
+ for (var n = 0; n < this.drawCount; n++) { // 记录中奖名单开始位置坐标
|
|
137
|
+ this.drawUsersArr[n].startX = document.getElementsByClassName('activeLi')[n].getBoundingClientRect().x
|
|
138
|
+ this.drawUsersArr[n].startY = document.getElementsByClassName('activeLi')[n].getBoundingClientRect().y
|
|
139
|
+ this.drawUsersArr[n].width = document.getElementsByClassName('activeLi')[n].getBoundingClientRect().width
|
|
140
|
+ }
|
|
141
|
+ })
|
|
142
|
+ }
|
|
143
|
+ } else if (e.ctrlKey && e.keyCode == 32) { // 确认抽奖结果组合键:Ctrl + Space
|
|
144
|
+ if (!this.status) {
|
|
145
|
+ if (this.sureStatus) { // 之前已执行过Ctrl + Enter的前提下,才能执行确认动作
|
|
146
|
+ this.sureStatus = !this.sureStatus
|
|
147
|
+ this.users.map((item) => { // 隐藏未抽中数据
|
|
148
|
+ item.show = false
|
|
149
|
+ })
|
|
150
|
+ this.drawUsersArr.map((item) => {
|
|
151
|
+ item.startX = item.endX
|
|
152
|
+ item.startY = item.endY
|
|
153
|
+ })
|
|
154
|
+ }
|
|
155
|
+ }
|
|
156
|
+ }
|
|
157
|
+ }
|
|
158
|
+ },
|
|
159
|
+ calcRandomArr (num, pArr, aArr, key, activeNum) {
|
|
160
|
+ if (pArr.length > num) {
|
|
161
|
+ var randomNum = Math.floor(Math.random() * pArr.length), bool = false
|
|
162
|
+ aArr.map((item) => {
|
|
163
|
+ if (item[key] === pArr[randomNum]) {
|
|
164
|
+ bool = true
|
|
165
|
+ }
|
|
166
|
+ })
|
|
167
|
+ if (!bool) aArr.push({ ...pArr[randomNum], active: false })
|
|
168
|
+ if (aArr.length === num) {
|
|
169
|
+ return this.returnSubArr(aArr, activeNum, 'active', 0)
|
|
170
|
+ } else {
|
|
171
|
+ this.calcRandomArr(num, pArr, aArr, key, activeNum)
|
|
172
|
+ }
|
|
173
|
+ } else {
|
|
174
|
+ return { ...pArr[randomNum], active: true }
|
|
175
|
+ }
|
|
176
|
+ },
|
|
177
|
+ returnSubArr (arr, subNum, key, count) {
|
|
178
|
+ var randomNum = Math.floor(Math.random() * arr.length)
|
|
179
|
+ if (!arr[randomNum][key]) {
|
|
180
|
+ arr[randomNum][key] = true
|
|
181
|
+ count += 1
|
|
182
|
+ }
|
|
183
|
+ if (count < subNum) {
|
|
184
|
+ this.returnSubArr(arr, subNum, key, count)
|
|
185
|
+ } else {
|
|
186
|
+ return arr
|
|
187
|
+ }
|
|
188
|
+ }
|
|
189
|
+ }
|
|
190
|
+}
|
|
191
|
+</script>
|
|
192
|
+
|
|
193
|
+<style>
|
|
194
|
+.mainPage {
|
|
195
|
+ overflow: hidden;
|
|
196
|
+ background: #000;
|
|
197
|
+}
|
|
198
|
+.bg{
|
|
199
|
+ -webkit-filter: brightness(100%);
|
|
200
|
+ filter: brightness(100%);
|
|
201
|
+ transition: filter .3s linear;
|
|
202
|
+ -webkit-transition: filter .3s linear;
|
|
203
|
+ display: block;
|
|
204
|
+ position: absolute;
|
|
205
|
+}
|
|
206
|
+.bg.grey{
|
|
207
|
+ -webkit-filter: brightness(20%);
|
|
208
|
+ filter: brightness(20%);
|
|
209
|
+}
|
|
210
|
+.drawEndList {
|
|
211
|
+ width: 100%;
|
|
212
|
+ height: 100%;
|
|
213
|
+ position: relative;
|
|
214
|
+ overflow: hidden;
|
|
215
|
+ z-index: 200;
|
|
216
|
+}
|
|
217
|
+.drawEndList > a {
|
|
218
|
+ display: inline-block;
|
|
219
|
+ box-sizing: border-box;
|
|
220
|
+ border-radius: 60px;
|
|
221
|
+ border: 2px solid #e7963b;
|
|
222
|
+ position: absolute;
|
|
223
|
+ box-shadow: 0 0 0.2rem 0.15rem rgba(231, 150, 59, 0.2);
|
|
224
|
+ transition: none 0.5s ease-out 1s;
|
|
225
|
+ -webkit-transition: none 0.5s ease-out 1s;
|
|
226
|
+ transition-property: left, top;
|
|
227
|
+ -webkit-transition-property: left, top;
|
|
228
|
+}
|
|
229
|
+.drawEndList > a > span {
|
|
230
|
+ width: 100%;
|
|
231
|
+ display: block;
|
|
232
|
+ line-height: 60px;
|
|
233
|
+ border-radius: 60px;
|
|
234
|
+ color: #fff;
|
|
235
|
+ text-align: center;
|
|
236
|
+ font-size: 27px;
|
|
237
|
+ white-space: nowrap;
|
|
238
|
+ overflow: hidden;
|
|
239
|
+ text-overflow: ellipsis;
|
|
240
|
+ box-shadow: 0 0 0.2rem 0.15rem rgba(231, 150, 59, 0.2) inset;
|
|
241
|
+}
|
|
242
|
+.userList,
|
|
243
|
+.drawUserList {
|
|
244
|
+ width: 44%;
|
|
245
|
+ min-width: 1500px;
|
|
246
|
+ overflow: visible;
|
|
247
|
+ z-index: 100;
|
|
248
|
+}
|
|
249
|
+.drawUserList {
|
|
250
|
+ width: 22%;
|
|
251
|
+ min-width: 750px;
|
|
252
|
+ opacity: 0;
|
|
253
|
+}
|
|
254
|
+.userList > ul,
|
|
255
|
+.drawUserList > ul {
|
|
256
|
+ width: 100%;
|
|
257
|
+ position: relative;
|
|
258
|
+ overflow: visible;
|
|
259
|
+ flex-wrap: wrap;
|
|
260
|
+ -webkit-flex-wrap: wrap;
|
|
261
|
+ transition: all 0.2s linear;
|
|
262
|
+ -webkit-transition: all 0.2s linear;
|
|
263
|
+ justify-content: center;
|
|
264
|
+}
|
|
265
|
+.userList > ul > li,
|
|
266
|
+.drawUserList > ul > li {
|
|
267
|
+ min-width: 10%;
|
|
268
|
+ max-width: 10%;
|
|
269
|
+ margin: 10px 0.5%;
|
|
270
|
+ box-sizing: border-box;
|
|
271
|
+ border: 2px solid #79321c;
|
|
272
|
+ border-radius: 60px;
|
|
273
|
+ overflow: hidden;
|
|
274
|
+ opacity: 1;
|
|
275
|
+ transition: all 0.2s linear;
|
|
276
|
+ -webkit-transition: all 0.2s linear;
|
|
277
|
+}
|
|
278
|
+.drawUserList > ul > li {
|
|
279
|
+ min-width: 20%;
|
|
280
|
+ max-width: 20%;
|
|
281
|
+ margin: 10px 1%;
|
|
282
|
+}
|
|
283
|
+.userList > ul > li.hide {
|
|
284
|
+ opacity: 0;
|
|
285
|
+}
|
|
286
|
+.userList > ul > li > span,
|
|
287
|
+.drawUserList > ul > li > span {
|
|
288
|
+ width: 100%;
|
|
289
|
+ display: block;
|
|
290
|
+ line-height: 60px;
|
|
291
|
+ border-radius: 60px;
|
|
292
|
+ color: #777;
|
|
293
|
+ text-align: center;
|
|
294
|
+ font-size: 27px;
|
|
295
|
+ white-space: nowrap;
|
|
296
|
+ overflow: hidden;
|
|
297
|
+ text-overflow: ellipsis;
|
|
298
|
+}
|
|
299
|
+.userList > ul > li.active {
|
|
300
|
+ border-color: #e7963b;
|
|
301
|
+ box-shadow: 0 0 0.2rem 0.15rem rgba(231, 150, 59, 0.2);
|
|
302
|
+}
|
|
303
|
+.userList > ul > li.active > span {
|
|
304
|
+ border-color: #e7963b;
|
|
305
|
+ box-shadow: 0 0 0.2rem 0.15rem rgba(231, 150, 59, 0.2) inset;
|
|
306
|
+ color: #fff;
|
|
307
|
+}
|
|
308
|
+</style>
|
|
309
|
+
|