code refactor

This commit is contained in:
MaysWind
2025-03-09 00:39:54 +08:00
parent 34247be52c
commit 09574f1c75
9 changed files with 95 additions and 71 deletions
@@ -1,6 +1,5 @@
import { ref, computed } from 'vue';
import { type LanguageOption } from '@/locales/index.ts';
import { useI18n } from '@/locales/helpers.ts';
import { useSettingsStore } from '@/stores/setting.ts';
@@ -23,7 +22,6 @@ export function useUserProfilePageBase() {
tt,
getDefaultCurrency,
getDefaultFirstDayOfWeek,
getAllLanguageOptions,
getAllCurrencies,
getAllWeekDays,
getAllLongDateFormats,
@@ -55,7 +53,6 @@ export function useUserProfilePageBase() {
const resending = ref<boolean>(false);
const saving = ref<boolean>(false);
const allLanguages = computed<LanguageOption[]>(() => getAllLanguageOptions(true));
const allCurrencies = computed<LocalizedCurrencyInfo[]>(() => getAllCurrencies());
const allAccounts = computed<Account[]>(() => accountsStore.allPlainAccounts);
const allVisibleAccounts = computed<Account[]>(() => accountsStore.allVisiblePlainAccounts);
@@ -189,7 +186,6 @@ export function useUserProfilePageBase() {
resending,
saving,
// computed states
allLanguages,
allCurrencies,
allAccounts,
allVisibleAccounts,
+5 -27
View File
@@ -90,30 +90,10 @@
<v-row>
<v-col cols="12" md="12">
<v-select
item-title="nativeDisplayName"
item-value="languageTag"
:disabled="submitting || navigateToHomePage"
:label="languageTitle"
:placeholder="languageTitle"
:items="allLanguages"
v-model="currentLocale"
>
<template #item="{ props, item }">
<v-list-item :value="item.value" v-bind="props">
<template #title>
<v-list-item-title>
<div class="d-flex align-center">
<span>{{ item.title }}</span>
<v-spacer />
<v-icon :icon="mdiCheck" v-if="currentLocale == item.raw.languageTag" />
<span class="text-field-append-text" v-if="currentLocale !== item.raw.languageTag">{{ item.raw.displayName }}</span>
</div>
</v-list-item-title>
</template>
</v-list-item>
</template>
</v-select>
<language-select :disabled="submitting || navigateToHomePage"
:label="languageTitle"
:placeholder="languageTitle"
:use-model-value="true" v-model="currentLocale" />
</v-col>
</v-row>
@@ -243,7 +223,6 @@ import { ref, computed, useTemplateRef } from 'vue';
import { useRouter } from 'vue-router';
import { useTheme } from 'vuetify';
import type { LanguageOption } from '@/locales/index.ts';
import { useI18n } from '@/locales/helpers.ts';
import { useSignupPageBase } from '@/views/base/SignupPageBase.ts';
@@ -269,7 +248,7 @@ type SnackBarType = InstanceType<typeof SnackBar>;
const router = useRouter();
const theme = useTheme();
const { tt, getAllLanguageOptions, getAllCurrencies, getAllWeekDays, getAllTransactionDefaultCategories } = useI18n();
const { tt, getAllCurrencies, getAllWeekDays, getAllTransactionDefaultCategories } = useI18n();
const {
user,
@@ -291,7 +270,6 @@ const usePresetCategories = ref<boolean>(false);
const finalResultMessage = ref<string | null>(null);
const navigateToHomePage = ref<boolean>(false);
const allLanguages = computed<LanguageOption[]>(() => getAllLanguageOptions(false));
const allCurrencies = computed<LocalizedCurrencyInfo[]>(() => getAllCurrencies());
const allWeekDays = computed<TypeAndDisplayName[]>(() => getAllWeekDays());
const allPresetCategories = computed<PartialRecord<CategoryType, LocalizedPresetCategory[]>>(() => getAllTransactionDefaultCategories(0, currentLocale.value));
@@ -116,31 +116,11 @@
<v-card-text>
<v-row>
<v-col cols="12" md="6">
<v-select
item-title="nativeDisplayName"
item-value="languageTag"
persistent-placeholder
:disabled="loading || saving"
:label="languageTitle"
:placeholder="languageTitle"
:items="allLanguages"
v-model="newProfile.language"
>
<template #item="{ props, item }">
<v-list-item :value="item.value" v-bind="props">
<template #title>
<v-list-item-title>
<div class="d-flex align-center">
<span>{{ item.title }}</span>
<v-spacer />
<v-icon :icon="mdiCheck" v-if="newProfile.language == item.raw.languageTag" />
<span class="text-field-append-text" v-if="newProfile.language !== item.raw.languageTag">{{ item.raw.displayName }}</span>
</div>
</v-list-item-title>
</template>
</v-list-item>
</template>
</v-select>
<language-select :disabled="loading || saving"
:label="languageTitle"
:placeholder="languageTitle"
:include-system-default="true"
:use-model-value="true" v-model="newProfile.language" />
</v-col>
<v-col cols="12" md="6">
@@ -366,8 +346,7 @@ import { isUserVerifyEmailEnabled } from '@/lib/server_settings.ts';
import {
mdiAccount,
mdiAccountEditOutline,
mdiCheck
mdiAccountEditOutline
} from '@mdi/js';
type ConfirmDialogType = InstanceType<typeof ConfirmDialog>;
@@ -382,7 +361,6 @@ const {
loading,
resending,
saving,
allLanguages,
allCurrencies,
allVisibleAccounts,
allVisibleCategorizedAccounts,
+4 -2
View File
@@ -344,6 +344,7 @@
import { ref, computed } from 'vue';
import type { Router } from 'framework7/types';
import type { LanguageOption } from '@/locales/index.ts';
import { useI18n } from '@/locales/helpers.ts';
import { useI18nUIComponents, showLoading, hideLoading } from '@/lib/ui/mobile.ts';
import { useUserProfilePageBase } from '@/views/base/users/UserProfilePageBase.ts';
@@ -362,7 +363,7 @@ const props = defineProps<{
f7router: Router.Router;
}>();
const { tt, getCurrencyName } = useI18n();
const { tt, getAllLanguageOptions, getCurrencyName } = useI18n();
const { showAlert, showToast, routeBackOnError } = useI18nUIComponents();
const {
@@ -371,7 +372,6 @@ const {
loading,
resending,
saving,
allLanguages,
allCurrencies,
allAccounts,
allVisibleAccounts,
@@ -413,6 +413,8 @@ const showAccountSheet = ref<boolean>(false);
const showDefaultCurrencyPopup = ref<boolean>(false);
const showMoreActionSheet = ref<boolean>(false);
const allLanguages = computed<LanguageOption[]>(() => getAllLanguageOptions(true));
const currentLanguageName = computed<string>(() => {
for (let i = 0; i < allLanguages.value.length; i++) {
if (allLanguages.value[i].languageTag === newProfile.value.language) {