code refactor

This commit is contained in:
MaysWind
2023-06-23 21:19:24 +08:00
parent 59b883ff7f
commit 8e6aece9ae
3 changed files with 40 additions and 20 deletions
+9 -12
View File
@@ -95,13 +95,13 @@
class="list-item-with-header-and-title list-item-no-item-after"
:key="currentLocale + '_firstDayOfWeek'"
:header="$t('First Day of Week')"
:title="getDayOfWeekName(user.firstDayOfWeek)"
:title="currentDayOfWeekName"
smart-select :smart-select-params="{ openIn: 'popup', popupPush: true, closeOnSelect: true, scrollToSelectedItem: true, searchbar: true, searchbarPlaceholder: $t('Date'), searchbarDisableText: $t('Cancel'), appendSearchbarNotFound: $t('No results'), pageTitle: $t('First Day of Week'), popupCloseLinkText: $t('Done') }"
>
<select v-model="user.firstDayOfWeek">
<option :value="weekDay.type"
:key="weekDay.type"
v-for="weekDay in allWeekDays">{{ $t(`datetime.${weekDay.name}.long`) }}</option>
v-for="weekDay in allWeekDays">{{ weekDay.displayName }}</option>
</select>
</f7-list-item>
</f7-list>
@@ -180,7 +180,6 @@ import { useSettingsStore } from '@/stores/setting.js';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.js';
import { useExchangeRatesStore } from '@/stores/exchangeRates.js';
import datetimeConstants from '@/consts/datetime.js';
import categoryConstants from '@/consts/category.js';
import { getNameByKeyValue, copyArrayTo } from '@/lib/common.js';
@@ -201,7 +200,7 @@ export default {
nickname: '',
language: self.$i18n.locale,
defaultCurrency: settingsStore.defaultSetting.currency,
firstDayOfWeek: datetimeConstants.allWeekDays[self.$t('default.firstDayOfWeek')] ? datetimeConstants.allWeekDays[self.$t('default.firstDayOfWeek')].type : 0
firstDayOfWeek: settingsStore.defaultSetting.firstDayOfWeek,
},
submitting: false,
presetCategories: {
@@ -224,7 +223,7 @@ export default {
return this.$locale.getAllCurrencies();
},
allWeekDays() {
return datetimeConstants.allWeekDays;
return this.$locale.getAllWeekDays();
},
currentLocale: {
get: function () {
@@ -232,7 +231,7 @@ export default {
},
set: function (value) {
const isCurrencyDefault = this.user.defaultCurrency === this.settingsStore.defaultSetting.currency;
const isFirstWeekDayDefault = this.user.firstDayOfWeek === (datetimeConstants.allWeekDays[this.$t('default.firstDayOfWeek')] ? datetimeConstants.allWeekDays[this.$t('default.firstDayOfWeek')].type : 0);
const isFirstWeekDayDefault = this.user.firstDayOfWeek === this.settingsStore.defaultSetting.firstDayOfWeek;
this.user.language = value;
@@ -244,7 +243,7 @@ export default {
}
if (isFirstWeekDayDefault) {
this.user.firstDayOfWeek = datetimeConstants.allWeekDays[this.$t('default.firstDayOfWeek')] ? datetimeConstants.allWeekDays[this.$t('default.firstDayOfWeek')].type : 0;
this.user.firstDayOfWeek = this.settingsStore.defaultSetting.firstDayOfWeek;
}
}
},
@@ -257,6 +256,9 @@ export default {
return languageInfo.displayName;
},
currentDayOfWeekName() {
return getNameByKeyValue(this.allWeekDays, this.user.firstDayOfWeek, 'type', 'displayName');
},
inputIsEmpty() {
return !!this.inputEmptyProblemMessage;
},
@@ -397,11 +399,6 @@ export default {
}
});
},
getDayOfWeekName(dayOfWeek) {
const weekName = getNameByKeyValue(datetimeConstants.allWeekDays, dayOfWeek, 'type', 'name');
const i18nWeekNameKey = `datetime.${weekName}.long`;
return this.$t(i18nWeekNameKey);
},
getCategoryTypeName(categoryType) {
switch (categoryType) {
case categoryConstants.allCategoryTypes.Income.toString():
+3 -6
View File
@@ -149,7 +149,7 @@
<select v-model="newProfile.firstDayOfWeek">
<option :value="weekDay.type"
:key="weekDay.type"
v-for="weekDay in allWeekDays">{{ $t(`datetime.${weekDay.name}.long`) }}</option>
v-for="weekDay in allWeekDays">{{ weekDay.displayName }}</option>
</select>
</f7-list-item>
@@ -226,7 +226,6 @@ import { useSettingsStore } from '@/stores/setting.js';
import { useUserStore } from '@/stores/user.js';
import { useAccountsStore } from '@/stores/account.js';
import datetimeConstants from '@/consts/datetime.js';
import { getNameByKeyValue } from '@/lib/common.js';
import { getCategorizedAccounts } from '@/lib/account.js';
@@ -311,7 +310,7 @@ export default {
return getCategorizedAccounts(this.allVisibleAccounts);
},
allWeekDays() {
return datetimeConstants.allWeekDays;
return this.$locale.getAllWeekDays();
},
allLongDateFormats() {
return this.$locale.getAllLongDateFormats();
@@ -359,9 +358,7 @@ export default {
return this.$t('Unknown');
},
currentDayOfWeekName() {
const weekName = getNameByKeyValue(datetimeConstants.allWeekDays, this.newProfile.firstDayOfWeek, 'type', 'name');
const i18nWeekNameKey = `datetime.${weekName}.long`;
return this.$t(i18nWeekNameKey);
return getNameByKeyValue(this.allWeekDays, this.newProfile.firstDayOfWeek, 'type', 'displayName');
},
inputIsNotChanged() {
return !!this.inputIsNotChangedProblemMessage;