use for-of statements to replace for and for-in

This commit is contained in:
MaysWind
2025-09-14 01:40:53 +08:00
parent 67bc81d3e2
commit 4700446ca0
38 changed files with 389 additions and 597 deletions
@@ -145,6 +145,7 @@ import { useRootStore } from '@/stores/index.ts';
import { useSettingsStore } from '@/stores/setting.ts';
import { useTokensStore } from '@/stores/token.ts';
import { itemAndIndex, reversedItemAndIndex } from '@/core/base.ts';
import { type TokenInfoResponse, SessionInfo } from '@/models/token.ts';
import { isEquals } from '@/lib/common.ts';
@@ -203,8 +204,7 @@ const sessions = computed<DesktopPageSessionInfo[]>(() => {
return sessions;
}
for (let i = 0; i < tokens.value.length; i++) {
const token = tokens.value[i];
for (const token of tokens.value) {
const sessionInfo = parseSessionInfo(token);
sessions.push(new DesktopPageSessionInfo(sessionInfo));
}
@@ -336,9 +336,9 @@ function revokeSession(session: SessionInfo): void {
}).then(() => {
loadingSession.value = false;
for (let i = 0; i < tokens.value.length; i++) {
if (tokens.value[i].tokenId === session.tokenId) {
tokens.value.splice(i, 1);
for (const [token, index] of itemAndIndex(tokens.value)) {
if (token.tokenId === session.tokenId) {
tokens.value.splice(index, 1);
}
}
}).catch(error => {
@@ -362,9 +362,9 @@ function revokeAllSessions(): void {
tokensStore.revokeAllTokens().then(() => {
loadingSession.value = false;
for (let i = tokens.value.length - 1; i >= 0; i--) {
if (!tokens.value[i].isCurrent) {
tokens.value.splice(i, 1);
for (const [token, index] of reversedItemAndIndex(tokens.value)) {
if (!token.isCurrent) {
tokens.value.splice(index, 1);
}
}