|
@@ -29,31 +29,36 @@ const Rank = () => {
|
|
|
const [currentUser, setCurrentUser] = useState<number>(0);
|
|
|
const topThree = ["探花", "榜眼", "状元"];
|
|
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
|
- const { noRank } = useLocation().state as { noRank: boolean } || { noRank: false };
|
|
|
+ const { noRank, phone } = useLocation().state as { noRank: boolean; phone?: number } || { noRank: false };
|
|
|
|
|
|
useEffect(() => {
|
|
|
getRankList().then((res) => {
|
|
|
setRankList(sortDESC(res.data.data));
|
|
|
- // 暂时用最大id作为当前用户
|
|
|
// 找到最大id
|
|
|
const maxId = Math.max(...res.data.data.map((item: RankItem) => item.id));
|
|
|
if (noRank) {
|
|
|
setCurrentUser(res.data.data[res.data.data.length - 1].id);
|
|
|
} else {
|
|
|
+ const rankMe = res.data.data.find((item: RankItem) => item.phone === phone?.toString())
|
|
|
+ // 是否在榜
|
|
|
+ if (rankMe) {
|
|
|
+ setCurrentUser(rankMe.id);
|
|
|
+ return
|
|
|
+ }
|
|
|
setCurrentUser(maxId);
|
|
|
}
|
|
|
});
|
|
|
// 一开始就滚到当前用户
|
|
|
|
|
|
setTimeout(() => {
|
|
|
- const container = document.querySelector(".rank-item-active");
|
|
|
+ const container = document.querySelector(".rank-focus-item");
|
|
|
if (container) {
|
|
|
container.scrollIntoView({ behavior: "smooth", inline: "end", block: "nearest" });
|
|
|
}
|
|
|
}, 200);
|
|
|
|
|
|
containerRef.current = document.querySelector(".container")!;
|
|
|
- }, [noRank]);
|
|
|
+ }, [noRank, phone]);
|
|
|
|
|
|
// 滚轮让x轴滚动
|
|
|
const handleWheel = (event: React.WheelEvent<HTMLDivElement>) => {
|
|
@@ -68,7 +73,7 @@ const Rank = () => {
|
|
|
if (activeRank < rankList.length) {
|
|
|
setCurrentUser(rankList.find((item) => item.rank === activeRank + 1)!.id);
|
|
|
if (containerRef.current) {
|
|
|
- const target = containerRef.current.querySelector(".rank-item-active");
|
|
|
+ const target = containerRef.current.querySelector(".rank-focus-item");
|
|
|
if (target) {
|
|
|
target.scrollIntoView({ behavior: "smooth", inline: "end", block: "nearest" });
|
|
|
}
|
|
@@ -80,7 +85,7 @@ const Rank = () => {
|
|
|
if (activeRank > 1) {
|
|
|
setCurrentUser(rankList.find((item) => item.rank === activeRank - 1)!.id);
|
|
|
if (containerRef.current) {
|
|
|
- const target = containerRef.current.querySelector(".rank-item-active");
|
|
|
+ const target = containerRef.current.querySelector(".rank-focus-item");
|
|
|
if (target) {
|
|
|
target.scrollIntoView({ behavior: "smooth", inline: "start", block: "nearest" });
|
|
|
}
|
|
@@ -96,7 +101,7 @@ const Rank = () => {
|
|
|
<div className="container" onWheel={handleWheel}>
|
|
|
<div className="container-item">
|
|
|
{rankList.map((item, index) => (
|
|
|
- <div className={`rank-item ${item.id === currentUser ? "rank-item-active" : ""}`} key={index} >
|
|
|
+ <div className={`rank-item ${item.id === currentUser ? `rank-focus-item ${item.phone === phone?.toString() ? 'rank-item-active' : ''}` : ""}`} key={index} >
|
|
|
<div className="rank-title">{index >= rankList.length - 3 ? topThree[index - (rankList.length - 3)] : `第${item.rank}名`} </div>
|
|
|
<div className="nickname">{item.name}</div>
|
|
|
<div className="score">获得{item.score}分</div>
|