code refactor

This commit is contained in:
MaysWind
2023-07-16 23:05:11 +08:00
parent ed4040f2ec
commit 25f83a98e3
6 changed files with 30 additions and 8 deletions
@@ -28,10 +28,10 @@
:preset-ranges="presetRanges" :preset-ranges="presetRanges"
v-model="dateRange"> v-model="dateRange">
<template #month="{ text }"> <template #month="{ text }">
{{ $t(`datetime.${text}.short`) }} {{ getMonthShortName(text) }}
</template> </template>
<template #month-overlay-value="{ text }"> <template #month-overlay-value="{ text }">
{{ $t(`datetime.${text}.short`) }} {{ getMonthShortName(text) }}
</template> </template>
</vue-date-picker> </vue-date-picker>
</v-card-text> </v-card-text>
@@ -188,6 +188,9 @@ export default {
}, },
cancel() { cancel() {
this.$emit('update:show', false); this.$emit('update:show', false);
},
getMonthShortName(month) {
return this.$locale.getMonthShortName(month);
} }
} }
} }
@@ -29,10 +29,10 @@
:preset-ranges="presetRanges" :preset-ranges="presetRanges"
v-model="dateRange"> v-model="dateRange">
<template #month="{ text }"> <template #month="{ text }">
{{ $t(`datetime.${text}.short`) }} {{ getMonthShortName(text) }}
</template> </template>
<template #month-overlay-value="{ text }"> <template #month-overlay-value="{ text }">
{{ $t(`datetime.${text}.short`) }} {{ getMonthShortName(text) }}
</template> </template>
</vue-date-picker> </vue-date-picker>
<f7-button large fill <f7-button large fill
@@ -189,6 +189,9 @@ export default {
}, },
cancel() { cancel() {
this.$emit('update:show', false); this.$emit('update:show', false);
},
getMonthShortName(month) {
return this.$locale.getMonthShortName(month);
} }
} }
} }
@@ -24,10 +24,10 @@
:is24="is24Hour" :is24="is24Hour"
v-model="dateTime"> v-model="dateTime">
<template #month="{ text }"> <template #month="{ text }">
{{ $t(`datetime.${text}.short`) }} {{ getMonthShortName(text) }}
</template> </template>
<template #month-overlay-value="{ text }"> <template #month-overlay-value="{ text }">
{{ $t(`datetime.${text}.short`) }} {{ getMonthShortName(text) }}
</template> </template>
</vue-date-picker> </vue-date-picker>
</f7-page-content> </f7-page-content>
@@ -115,6 +115,9 @@ export default {
this.$emit('update:modelValue', unixTime); this.$emit('update:modelValue', unixTime);
this.$emit('update:show', false); this.$emit('update:show', false);
},
getMonthShortName(month) {
return this.$locale.getMonthShortName(month);
} }
} }
} }
+10
View File
@@ -371,6 +371,14 @@ function getAllShortTimeFormats(translateFn) {
return getDateTimeFormats(translateFn, datetime.allShortTimeFormat, datetime.allShortTimeFormatArray, 'format.shortTime', defaultShortTimeFormatTypeName, datetime.defaultShortTimeFormat); return getDateTimeFormats(translateFn, datetime.allShortTimeFormat, datetime.allShortTimeFormatArray, 'format.shortTime', defaultShortTimeFormatTypeName, datetime.defaultShortTimeFormat);
} }
function getMonthShortName(month, translateFn) {
return translateFn(`datetime.${month}.short`);
}
function getWeekdayShortName(weekDay, translateFn) {
return translateFn(`datetime.${weekDay}.short`);
}
function getI18nLongDateFormat(translateFn, formatTypeValue) { function getI18nLongDateFormat(translateFn, formatTypeValue) {
const defaultLongDateFormatTypeName = translateFn('default.longDateFormat'); const defaultLongDateFormatTypeName = translateFn('default.longDateFormat');
return getDateTimeFormat(translateFn, datetime.allLongDateFormat, datetime.allLongDateFormatArray, 'format.longDate', defaultLongDateFormatTypeName, datetime.defaultLongDateFormat, formatTypeValue); return getDateTimeFormat(translateFn, datetime.allLongDateFormat, datetime.allLongDateFormatArray, 'format.longDate', defaultLongDateFormatTypeName, datetime.defaultLongDateFormat, formatTypeValue);
@@ -912,6 +920,8 @@ export function i18nFunctions(i18nGlobal) {
getAllShortDateFormats: () => getAllShortDateFormats(i18nGlobal.t), getAllShortDateFormats: () => getAllShortDateFormats(i18nGlobal.t),
getAllLongTimeFormats: () => getAllLongTimeFormats(i18nGlobal.t), getAllLongTimeFormats: () => getAllLongTimeFormats(i18nGlobal.t),
getAllShortTimeFormats: () => getAllShortTimeFormats(i18nGlobal.t), getAllShortTimeFormats: () => getAllShortTimeFormats(i18nGlobal.t),
getMonthShortName: (month) => getMonthShortName(month, i18nGlobal.t),
getWeekdayShortName: (weekDay) => getWeekdayShortName(weekDay, i18nGlobal.t),
formatUnixTimeToLongDateTime: (userStore, unixTime, utcOffset, currentUtcOffset) => formatUnixTime(unixTime, getI18nLongDateFormat(i18nGlobal.t, userStore.currentUserLongDateFormat) + ' ' + getI18nLongTimeFormat(i18nGlobal.t, userStore.currentUserLongTimeFormat), utcOffset, currentUtcOffset), formatUnixTimeToLongDateTime: (userStore, unixTime, utcOffset, currentUtcOffset) => formatUnixTime(unixTime, getI18nLongDateFormat(i18nGlobal.t, userStore.currentUserLongDateFormat) + ' ' + getI18nLongTimeFormat(i18nGlobal.t, userStore.currentUserLongTimeFormat), utcOffset, currentUtcOffset),
formatUnixTimeToShortDateTime: (userStore, unixTime, utcOffset, currentUtcOffset) => formatUnixTime(unixTime, getI18nShortDateFormat(i18nGlobal.t, userStore.currentUserShortDateFormat) + ' ' + getI18nShortTimeFormat(i18nGlobal.t, userStore.currentUserShortTimeFormat), utcOffset, currentUtcOffset), formatUnixTimeToShortDateTime: (userStore, unixTime, utcOffset, currentUtcOffset) => formatUnixTime(unixTime, getI18nShortDateFormat(i18nGlobal.t, userStore.currentUserShortDateFormat) + ' ' + getI18nShortTimeFormat(i18nGlobal.t, userStore.currentUserShortTimeFormat), utcOffset, currentUtcOffset),
formatUnixTimeToLongDate: (userStore, unixTime, utcOffset, currentUtcOffset) => formatUnixTime(unixTime, getI18nLongDateFormat(i18nGlobal.t, userStore.currentUserLongDateFormat), utcOffset, currentUtcOffset), formatUnixTimeToLongDate: (userStore, unixTime, utcOffset, currentUtcOffset) => formatUnixTime(unixTime, getI18nLongDateFormat(i18nGlobal.t, userStore.currentUserLongDateFormat), utcOffset, currentUtcOffset),
@@ -143,7 +143,7 @@ export default {
return getDay(this.currentTime); return getDay(this.currentTime);
}, },
currentDayOfWeek() { currentDayOfWeek() {
return this.$t(`datetime.${getDayOfWeekName(this.currentTime)}.short`); return this.$locale.getWeekdayShortName(getDayOfWeekName(this.currentTime));
}, },
currentShortTime() { currentShortTime() {
return this.$locale.formatUnixTimeToShortTime(this.userStore, this.currentTime); return this.$locale.formatUnixTimeToShortTime(this.userStore, this.currentTime);
+4 -1
View File
@@ -159,7 +159,7 @@
{{ transaction.day }} {{ transaction.day }}
</span> </span>
<span class="transaction-day-of-week full-line flex-direction-column"> <span class="transaction-day-of-week full-line flex-direction-column">
{{ $t(`datetime.${transaction.dayOfWeek}.short`) }} {{ getWeekdayShortName(transaction) }}
</span> </span>
</div> </div>
</template> </template>
@@ -857,6 +857,9 @@ export default {
enableThousandsSeparator: this.settingsStore.appSettings.thousandsSeparator enableThousandsSeparator: this.settingsStore.appSettings.thousandsSeparator
}); });
}, },
getWeekdayShortName(transaction) {
return this.$locale.getWeekdayShortName(transaction.dayOfWeek);
},
getTransactionTypeName(type, defaultName) { getTransactionTypeName(type, defaultName) {
switch (type){ switch (type){
case this.allTransactionTypes.ModifyBalance: case this.allTransactionTypes.ModifyBalance: