Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
lottery
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fushaowu
lottery
Commits
033cee84
Commit
033cee84
authored
Jan 06, 2021
by
rendong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update lottery.js
parent
abe07e6a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
20 deletions
+21
-20
lottery.js
src/lottery.js
+21
-20
No files found.
src/lottery.js
View file @
033cee84
...
@@ -2,19 +2,17 @@
...
@@ -2,19 +2,17 @@
*
*
* @param {*} status true: 把中奖名单删除
* @param {*} status true: 把中奖名单删除
*/
*/
function
getLotteryList
(
status
=
false
)
{
function
randomNPerson
(
num
,
candidateMap
)
{
let
notWinPersonList
=
[...
personInfo
Map
.
values
()];
let
candidateList
=
[...
candidate
Map
.
values
()];
if
(
vue
.
num
>
notWinPerson
List
.
length
)
{
if
(
num
>
candidate
List
.
length
)
{
vue
.
num
=
notWinPerson
List
.
length
;
num
=
candidate
List
.
length
;
}
}
// 该批次名单
// 该批次名单
let
currentWinPersonMap
=
new
Map
();
let
currentWinPersonMap
=
new
Map
();
while
(
currentWinPersonMap
.
size
<
vue
.
num
)
{
while
(
currentWinPersonMap
.
size
<
num
)
{
let
random
=
Math
.
floor
(
Math
.
random
()
*
notWinPersonList
.
length
);
let
random
=
Math
.
floor
(
Math
.
random
()
*
candidateList
.
length
);
currentWinPersonMap
.
set
(
notWinPersonList
[
random
][
'name'
],
notWinPersonList
[
random
]);
currentWinPersonMap
.
set
(
candidateList
[
random
][
'name'
],
candidateList
[
random
]);
if
(
status
)
{
candidateList
.
splice
(
random
,
1
);
// 删除中奖人员名单
notWinPersonList
.
splice
(
random
,
1
);
// 删除中奖人员名单
}
}
}
return
[...
currentWinPersonMap
.
values
()];
return
[...
currentWinPersonMap
.
values
()];
}
}
...
@@ -22,7 +20,7 @@ function getLotteryList(status = false) {
...
@@ -22,7 +20,7 @@ function getLotteryList(status = false) {
/**
/**
* 获取所有未中过奖名单
* 获取所有未中过奖名单
*/
*/
function
get
NotWinPersonList
()
{
function
get
CandidateMap
()
{
let
winPerson
=
localStorage
.
getItem
(
'yit'
);
let
winPerson
=
localStorage
.
getItem
(
'yit'
);
if
(
winPerson
)
{
if
(
winPerson
)
{
winPerson
=
JSON
.
parse
(
winPerson
);
winPerson
=
JSON
.
parse
(
winPerson
);
...
@@ -38,18 +36,21 @@ function getNotWinPersonList() {
...
@@ -38,18 +36,21 @@ function getNotWinPersonList() {
/**
/**
* 抽奖开始
* 抽奖开始
*/
*/
function
start
()
{
function
start
(
num
)
{
getNotWinPersonList
();
var
candidateMap
=
getCandidateMap
();
if
(
personInfo
Map
.
size
===
0
)
{
if
(
candidate
Map
.
size
===
0
)
{
let
status
=
window
.
confirm
(
'没有未中奖人员, 去往抽奖结果页面'
);
let
status
=
window
.
confirm
(
'没有未中奖人员, 去往抽奖结果页面'
);
status
&&
window
.
open
(
'./list.html'
);
if
(
status
)
{
window
.
open
(
'./list.html'
);
}
else
{
vue
.
activePersonList
=
[];
vue
.
activePersonList
=
[];
vue
.
step
=
1
;
vue
.
step
=
1
;
vue
.
statusText
=
'抽奖完成'
;
vue
.
statusText
=
'抽奖完成'
;
}
return
;
return
;
}
}
vue
.
interval
=
setInterval
(()
=>
{
vue
.
interval
=
setInterval
(()
=>
{
vue
.
activePersonList
=
getLotteryList
(
);
vue
.
activePersonList
=
randomNPerson
(
num
,
candidateMap
);
},
100
);
},
100
);
}
}
...
@@ -107,7 +108,7 @@ let vue = new Vue({
...
@@ -107,7 +108,7 @@ let vue = new Vue({
watch
:
{
watch
:
{
step
(
newValue
)
{
step
(
newValue
)
{
if
(
newValue
===
2
)
{
if
(
newValue
===
2
)
{
start
();
start
(
this
.
num
);
}
}
},
},
},
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment