From 57224e8015ed17bc72a243eabffd0a4edff0850c Mon Sep 17 00:00:00 2001 From: streakingman Date: Thu, 22 Sep 2022 20:01:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=85=A5=E9=98=9F=E9=A1=BA=E5=BA=8F?= =?UTF-8?q?=E7=BB=B4=E6=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 10 ++++++---- src/utils.ts | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index bdf0675..58fa8c3 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -62,7 +62,7 @@ const makeScene: (level: number, icons: Icon[]) => Scene = (level, icons) => { isCover: false, status: 0, icon, - id: randomString(4), + id: randomString(6), x: column * 100 + offset, y: row * 100 + offset, }); @@ -201,11 +201,13 @@ const App: FC = () => { // 队列区排序 useEffect(() => { const cache: Record = {}; + // 加上索引,避免以id字典序来排 + const idx = 0; for (const symbol of queue) { - if (cache[symbol.icon.name]) { - cache[symbol.icon.name].push(symbol); + if (cache[idx + symbol.icon.name]) { + cache[idx + symbol.icon.name].push(symbol); } else { - cache[symbol.icon.name] = [symbol]; + cache[idx + symbol.icon.name] = [symbol]; } } const temp = []; diff --git a/src/utils.ts b/src/utils.ts index 6769b62..9923816 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,7 +1,7 @@ export const randomString: (len: number) => string = (len) => { const pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; let res = ''; - while (len >= 0) { + while (len > 0) { res += pool[Math.floor(pool.length * Math.random())]; len--; }