-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from hepengwei/feat_he
双色球菜单页新增查看个色球出现频次情况弹框
- Loading branch information
Showing
7 changed files
with
156 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
137 changes: 137 additions & 0 deletions
137
src/pages/welfareLottery/DualColouredBall/components/OccurrenceFrequencyModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import { Modal } from "antd"; | ||
import { useGlobalContext } from "@/hooks/useGlobalContext"; | ||
|
||
type OccurrenceFrequencyModalProps = { | ||
open: boolean; | ||
onCancel: () => void; | ||
}; | ||
|
||
const OccurrenceFrequencyModal = (props: OccurrenceFrequencyModalProps) => { | ||
const { dualColouredBallDataSource } = useGlobalContext(); | ||
const { open, onCancel } = props; | ||
const [top5Data, setTop5Data] = useState<string[][]>([]); | ||
|
||
const handleCancel = () => { | ||
onCancel(); | ||
}; | ||
|
||
const computeTop5Data = () => { | ||
const newTop5Data: string[][] = []; | ||
const numberOccurrenceNum: Record<string, number>[] = []; | ||
if (dualColouredBallDataSource && dualColouredBallDataSource.length > 0) { | ||
dualColouredBallDataSource.forEach((item: Record<string, any>) => { | ||
const { red, blue } = item; | ||
const numberList = `${red},${blue}`.split(","); | ||
numberList.forEach((number: string, index: number) => { | ||
if (numberOccurrenceNum[index]) { | ||
if (numberOccurrenceNum[index][number]) { | ||
numberOccurrenceNum[index][number] += 1; | ||
} else { | ||
numberOccurrenceNum[index][number] = 1; | ||
} | ||
} else { | ||
numberOccurrenceNum[index] = { [number]: 1 }; | ||
} | ||
}); | ||
}); | ||
numberOccurrenceNum.forEach((occurrenceNum: Record<string, number>) => { | ||
const top5Data: string[] = []; | ||
Object.keys(occurrenceNum).forEach((number: string) => { | ||
const num = occurrenceNum[number]; | ||
for (let i = 0; i < 5; i++) { | ||
if (top5Data[i]) { | ||
if (num > occurrenceNum[top5Data[i]]) { | ||
top5Data[i] = number; | ||
break; | ||
} | ||
} else { | ||
top5Data[i] = number; | ||
break; | ||
} | ||
} | ||
}); | ||
newTop5Data.push(top5Data); | ||
}); | ||
} | ||
setTop5Data(newTop5Data); | ||
}; | ||
|
||
useEffect(() => { | ||
computeTop5Data(); | ||
}, [dualColouredBallDataSource]); | ||
|
||
return ( | ||
<Modal | ||
title='各色球号码出现频次情况' | ||
width={600} | ||
open={open} | ||
onCancel={handleCancel} | ||
footer={null} | ||
> | ||
<div | ||
style={{ | ||
width: "100%", | ||
display: "flex", | ||
flexDirection: "column", | ||
alignItems: "center", | ||
}} | ||
> | ||
{top5Data.map((numberList: string[], index: number) => ( | ||
<div | ||
style={{ | ||
width: "100%", | ||
display: "flex", | ||
flexDirection: "column", | ||
marginBottom: "20px", | ||
}} | ||
> | ||
<div | ||
style={{ | ||
fontSize: "15px", | ||
}} | ||
> | ||
第{index + 1}个色球出现次数最多的前5个号码: | ||
</div> | ||
<div | ||
style={{ | ||
width: "100%", | ||
display: "flex", | ||
justifyContent: "center", | ||
alignItems: "center", | ||
height: 40, | ||
border: "2px dashed #cccccc", | ||
marginTop: "6px", | ||
}} | ||
> | ||
{numberList && numberList.length > 0 | ||
? numberList.map((number: string) => ( | ||
<div | ||
style={{ | ||
width: 28, | ||
height: 28, | ||
margin: "0 20px", | ||
display: "flex", | ||
justifyContent: "center", | ||
alignItems: "center", | ||
borderRadius: "50%", | ||
fontSize: "14px", | ||
fontWeight: "500", | ||
color: "#FFFFFF", | ||
backgroundColor: | ||
index === top5Data.length - 1 ? "#0A5EB0" : "#F72C5B", | ||
}} | ||
> | ||
{number} | ||
</div> | ||
)) | ||
: null} | ||
</div> | ||
</div> | ||
))} | ||
</div> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default OccurrenceFrequencyModal; |
1 change: 0 additions & 1 deletion
1
src/pages/welfareLottery/DualColouredBall/components/RandomOneModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.