salix-front/src/stores/useWeekdayStore.js

45 lines
1.2 KiB
JavaScript
Raw Normal View History

2024-03-21 16:15:11 +00:00
import { reactive } from 'vue';
2024-03-14 12:48:04 +00:00
import { useI18n } from 'vue-i18n';
import { defineStore } from 'pinia';
export const useWeekdayStore = defineStore('weekdayStore', () => {
const weekdays = [
{ code: 'sun', name: 'Sunday' },
{ code: 'mon', name: 'Monday' },
{ code: 'tue', name: 'Tuesday' },
{ code: 'wed', name: 'Wednesday' },
{ code: 'thu', name: 'Thursday' },
{ code: 'fri', name: 'Friday' },
{ code: 'sat', name: 'Saturday' },
];
2024-03-21 16:15:11 +00:00
const { t } = useI18n();
2024-03-14 12:48:04 +00:00
const weekdaysMap = reactive({});
const initStore = () => {
getWeekdaysMap();
};
const getWeekdaysMap = () => {
if (Object.keys(weekdaysMap).length > 0) return weekdaysMap;
weekdays.forEach((day, i) => {
const obj = {
...day,
index: i,
char: day.name.substr(0, 1),
abr: day.name.substr(0, 3),
locale: t(`weekdays.${day.code}`),
localeChar: t(`weekdays.${day.code}`).substr(0, 1),
localeAbr: t(`weekdays.${day.code}`).substr(0, 3),
};
weekdaysMap[day.code] = obj;
});
};
return {
initStore,
weekdaysMap,
};
});