refactor: datetime function

This commit is contained in:
Methapon2001 2024-12-25 13:26:05 +07:00
parent 23e05efd24
commit 9bedf5f2fe

View file

@ -1,4 +1,5 @@
<script lang="ts" setup> <script lang="ts" setup>
import { ref } from 'vue';
import { QTableProps, QTableSlots } from 'quasar'; import { QTableProps, QTableSlots } from 'quasar';
import QuotationCard from 'src/components/05_quotation/QuotationCard.vue'; import QuotationCard from 'src/components/05_quotation/QuotationCard.vue';
@ -6,11 +7,12 @@ import BadgeComponent from 'src/components/BadgeComponent.vue';
import KebabAction from 'src/components/shared/KebabAction.vue'; import KebabAction from 'src/components/shared/KebabAction.vue';
import useOptionStore from 'src/stores/options'; import useOptionStore from 'src/stores/options';
import { dateFormatJS, dateFormat } from 'src/utils/datetime';
import { TaskOrder, TaskOrderStatus } from 'src/stores/task-order/types';
import { column } from './constants'; import { column } from './constants';
import { ref } from 'vue'; import { dateFormatJS } from 'src/utils/datetime';
import { TaskOrder, TaskOrderStatus } from 'src/stores/task-order/types';
import { Lang } from 'src/utils/ui';
const optionStore = useOptionStore();
const selectedTask = defineModel<TaskOrder[]>('selectedTask', { default: [] }); const selectedTask = defineModel<TaskOrder[]>('selectedTask', { default: [] });
const props = withDefaults( const props = withDefaults(
defineProps<{ defineProps<{
@ -78,14 +80,13 @@ function getCreatedByName(
locale?: string; locale?: string;
}, },
) { ) {
const createdBy = record.createdBy; const _user = record.createdBy;
switch (opts?.locale) {
return ( case Lang.English:
{ return `${optionStore.mapOption(_user?.namePrefix) || ''} ${_user?.firstNameEN} ${_user?.lastNameEN}`;
['eng']: `${useOptionStore().mapOption(createdBy?.namePrefix) || ''} ${createdBy?.firstNameEN} ${createdBy?.lastNameEN}`, default:
['tha']: `${useOptionStore().mapOption(createdBy?.namePrefix) || ''} ${createdBy?.firstName} ${createdBy?.lastName}`, return `${optionStore.mapOption(_user?.namePrefix) || ''} ${_user?.firstName} ${_user?.lastName}`;
}[opts?.locale || 'eng'] || '-' }
);
} }
function openList(index: number, data: TaskOrder) { function openList(index: number, data: TaskOrder) {
@ -171,10 +172,15 @@ const emit = defineEmits<{
dateFormatJS({ dateFormatJS({
date: props.row.createdAt, date: props.row.createdAt,
dayStyle: '2-digit', dayStyle: '2-digit',
monthStyle: '2-digit', monthStyle: 'short',
}) || '-' }) || '-'
}} }}
{{ dateFormat(props.row.createdAt, false, true) }} {{
dateFormatJS({
date: props.row.createdAt,
timeOnly: true,
})
}}
</q-td> </q-td>
<q-td v-if="visibleColumns.includes('createdBy')" class="text-left"> <q-td v-if="visibleColumns.includes('createdBy')" class="text-left">
{{ getCreatedByName(props.row, $i18n) }} {{ getCreatedByName(props.row, $i18n) }}
@ -272,8 +278,11 @@ const emit = defineEmits<{
value: `${dateFormatJS({ value: `${dateFormatJS({
date: props.row.createdAt, date: props.row.createdAt,
dayStyle: '2-digit', dayStyle: '2-digit',
monthStyle: '2-digit', monthStyle: 'short',
})} ${dateFormat(props.row.createdAt, false, true)}`, })} ${dateFormatJS({
date: props.row.createdAt,
timeOnly: true,
})}`,
}, },
{ {
label: $t('taskOrder.madeBy'), label: $t('taskOrder.madeBy'),