code refactor

This commit is contained in:
MaysWind
2023-07-16 22:55:02 +08:00
parent 41034de676
commit ed4040f2ec
5 changed files with 25 additions and 8 deletions
+8 -3
View File
@@ -277,6 +277,10 @@ function getDefaultFirstDayOfWeek(translateFn) {
return translateFn('default.firstDayOfWeek');
}
function getCurrencyName(currencyCode, translateFn) {
return translateFn(`currency.${currencyCode}`);
}
function getAllLongMonthNames(translateFn) {
return [
translateFn('datetime.January.long'),
@@ -516,7 +520,7 @@ function getAllCurrencies(translateFn) {
allCurrencies.push({
code: currencyCode,
displayName: translateFn(`currency.${currencyCode}`)
displayName: getCurrencyName(currencyCode, translateFn)
});
}
@@ -639,7 +643,7 @@ function getAllDisplayExchangeRates(exchangeRatesData, translateFn) {
availableExchangeRates.push({
currencyCode: exchangeRate.currency,
currencyDisplayName: translateFn(`currency.${exchangeRate.currency}`),
currencyDisplayName: getCurrencyName(exchangeRate.currency, translateFn),
rate: exchangeRate.rate
});
}
@@ -707,7 +711,7 @@ function getDisplayCurrency(value, currencyCode, options, translateFn) {
} else if (currencyCode && currencyDisplayMode === currency.allCurrencyDisplayModes.Code) {
return `${value} ${currencyCode}`;
} else if (currencyCode && currencyDisplayMode === currency.allCurrencyDisplayModes.Name) {
const currencyName = translateFn(`currency.${currencyCode}`);
const currencyName = getCurrencyName(currencyCode, translateFn);
return `${value} ${currencyName}`;
} else {
return value;
@@ -898,6 +902,7 @@ export function i18nFunctions(i18nGlobal) {
getCurrentLanguageInfo: () => getCurrentLanguageInfo(i18nGlobal),
getDefaultCurrency: () => getDefaultCurrency(i18nGlobal.t),
getDefaultFirstDayOfWeek: () => getDefaultFirstDayOfWeek(i18nGlobal.t),
getCurrencyName: (currencyCode) => getCurrencyName(currencyCode, i18nGlobal.t),
getAllLongMonthNames: () => getAllLongMonthNames(i18nGlobal.t),
getAllShortMonthNames: () => getAllShortMonthNames(i18nGlobal.t),
getAllLongWeekdayNames: () => getAllLongWeekdayNames(i18nGlobal.t),
+4 -1
View File
@@ -16,7 +16,7 @@
>
<template #title>
<div class="no-padding no-margin">
<span>{{ $t(`currency.${baseCurrency}`) }}&nbsp;</span>
<span>{{ getCurrencyName(baseCurrency) }}&nbsp;</span>
<small class="smaller">{{ baseCurrency }}</small>
</div>
</template>
@@ -207,6 +207,9 @@ export default {
}
});
},
getCurrencyName(currencyCode) {
return this.$locale.getCurrencyName(currencyCode);
},
getConvertedAmount(toExchangeRate) {
const fromExchangeRate = this.exchangeRatesStore.latestExchangeRateMap[this.baseCurrency];
return getConvertedAmount(this.baseAmount / 100, fromExchangeRate, toExchangeRate);
+4 -1
View File
@@ -80,7 +80,7 @@
>
<template #title>
<f7-block class="no-padding no-margin">
<span>{{ $t(`currency.${user.defaultCurrency}`) }}&nbsp;</span>
<span>{{ getCurrencyName(user.defaultCurrency) }}&nbsp;</span>
<small class="smaller">{{ user.defaultCurrency }}</small>
</f7-block>
</template>
@@ -399,6 +399,9 @@ export default {
}
});
},
getCurrencyName(currencyCode) {
return this.$locale.getCurrencyName(currencyCode);
},
getCategoryTypeName(categoryType) {
switch (categoryType) {
case categoryConstants.allCategoryTypes.Income.toString():
+5 -2
View File
@@ -164,7 +164,7 @@
>
<template #title>
<div class="no-padding no-margin">
<span>{{ $t(`currency.${account.currency}`) }}&nbsp;</span>
<span>{{ getCurrencyName(account.currency) }}&nbsp;</span>
<small class="smaller">{{ account.currency }}</small>
</div>
</template>
@@ -357,7 +357,7 @@
>
<template #title>
<div class="no-padding no-margin">
<span>{{ $t(`currency.${subAccount.currency}`) }}&nbsp;</span>
<span>{{ getCurrencyName(subAccount.currency) }}&nbsp;</span>
<small class="smaller">{{ subAccount.currency }}</small>
</div>
</template>
@@ -712,6 +712,9 @@ export default {
}
});
},
getCurrencyName(currencyCode) {
return this.$locale.getCurrencyName(currencyCode);
},
getAccountTypeName(accountType) {
const typeName = getNameByKeyValue(this.allAccountTypesArray, accountType, 'id', 'name');
return this.$t(typeName);
+4 -1
View File
@@ -129,7 +129,7 @@
>
<template #title>
<f7-block class="no-padding no-margin">
<span>{{ $t(`currency.${newProfile.defaultCurrency}`) }}&nbsp;</span>
<span>{{ getCurrencyName(newProfile.defaultCurrency) }}&nbsp;</span>
<small class="smaller">{{ newProfile.defaultCurrency }}</small>
</f7-block>
</template>
@@ -456,6 +456,9 @@ export default {
getNameByKeyValue(src, value, keyField, nameField, defaultName) {
return getNameByKeyValue(src, value, keyField, nameField, defaultName);
},
getCurrencyName(currencyCode) {
return this.$locale.getCurrencyName(currencyCode);
},
setCurrentUserProfile(profile) {
this.oldProfile.email = profile.email;
this.oldProfile.nickname = profile.nickname;