From 2c9bb12da90d0c580656283186848c77c72753e0 Mon Sep 17 00:00:00 2001 From: MaysWind Date: Thu, 3 Apr 2025 23:50:14 +0800 Subject: [PATCH] code refactor --- src/lib/account.ts | 20 ------------------- src/models/account.ts | 20 +++++++++++++++++++ .../base/accounts/AccountEditPageBase.ts | 3 +-- .../accounts/list/dialogs/EditDialog.vue | 3 +-- 4 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/lib/account.ts b/src/lib/account.ts index 6cf5e38c..1d374f57 100644 --- a/src/lib/account.ts +++ b/src/lib/account.ts @@ -338,23 +338,3 @@ export function isAccountOrSubAccountsHasButNotAllChecked(account: Account, filt return checkedCount > 0 && checkedCount < account.subAccounts.length; } - -export function setAccountSuitableIcon(account: Account, oldCategory: number, newCategory: number): void { - const allCategories = AccountCategory.values(); - - for (let i = 0; i < allCategories.length; i++) { - if (allCategories[i].type === oldCategory) { - if (account.icon !== allCategories[i].defaultAccountIconId) { - return; - } else { - break; - } - } - } - - for (let i = 0; i < allCategories.length; i++) { - if (allCategories[i].type === newCategory) { - account.icon = allCategories[i].defaultAccountIconId; - } - } -} diff --git a/src/models/account.ts b/src/models/account.ts index 7c639be1..ec7d07d2 100644 --- a/src/models/account.ts +++ b/src/models/account.ts @@ -133,6 +133,26 @@ export class Account implements AccountInfoResponse { this.visible = other.visible; } + public setSuitableIcon(oldCategory: number, newCategory: number): void { + const allCategories = AccountCategory.values(); + + for (let i = 0; i < allCategories.length; i++) { + if (allCategories[i].type === oldCategory) { + if (this.icon !== allCategories[i].defaultAccountIconId) { + return; + } else { + break; + } + } + } + + for (let i = 0; i < allCategories.length; i++) { + if (allCategories[i].type === newCategory) { + this.icon = allCategories[i].defaultAccountIconId; + } + } + } + public toCreateRequest(clientSessionId: string, subAccounts?: Account[], parentAccount?: Account): AccountCreateRequest { let subAccountCreateRequests: AccountCreateRequest[] | undefined = undefined; diff --git a/src/views/base/accounts/AccountEditPageBase.ts b/src/views/base/accounts/AccountEditPageBase.ts index 6f616555..32109f70 100644 --- a/src/views/base/accounts/AccountEditPageBase.ts +++ b/src/views/base/accounts/AccountEditPageBase.ts @@ -10,7 +10,6 @@ import type { LocalizedAccountCategory } from '@/core/account.ts'; import { Account } from '@/models/account.ts'; import { getCurrentUnixTime } from '@/lib/datetime.ts'; -import { setAccountSuitableIcon } from '@/lib/account.ts'; export interface DayAndDisplayName { readonly day: number; @@ -153,7 +152,7 @@ export function useAccountEditPageBaseBase() { } watch(() => account.value.category, (newValue, oldValue) => { - setAccountSuitableIcon(account.value, oldValue, newValue); + account.value.setSuitableIcon(oldValue, newValue); }); return { diff --git a/src/views/desktop/accounts/list/dialogs/EditDialog.vue b/src/views/desktop/accounts/list/dialogs/EditDialog.vue index e03fa162..5e285aa4 100644 --- a/src/views/desktop/accounts/list/dialogs/EditDialog.vue +++ b/src/views/desktop/accounts/list/dialogs/EditDialog.vue @@ -204,7 +204,6 @@ import { Account } from '@/models/account.ts'; import { isNumber } from '@/lib/common.ts'; import { getCurrentUnixTime } from '@/lib/datetime.ts'; import { generateRandomUUID } from '@/lib/misc.ts'; -import { setAccountSuitableIcon } from '@/lib/account.ts'; import { mdiDotsVertical, @@ -314,7 +313,7 @@ function open(options?: { id?: string, currentAccount?: Account, category?: numb } else { if (options && isNumber(options.category)) { account.value.category = options.category; - setAccountSuitableIcon(account.value, 1, options.category); + account.value.setSuitableIcon(1, options.category); } editAccountId.value = null;