fix: change history function
This commit is contained in:
parent
eefddd1963
commit
a09fbeb29e
1 changed files with 9 additions and 19 deletions
|
|
@ -53,8 +53,6 @@ const columns: QTableColumn[] = [
|
||||||
];
|
];
|
||||||
|
|
||||||
const currentDate = ref();
|
const currentDate = ref();
|
||||||
const currentData = ref();
|
|
||||||
const currentIndex = ref(0);
|
|
||||||
const isHistoryData = ref(false);
|
const isHistoryData = ref(false);
|
||||||
const formatList = ref<NewEmployeeHistory[]>([]);
|
const formatList = ref<NewEmployeeHistory[]>([]);
|
||||||
|
|
||||||
|
|
@ -281,9 +279,9 @@ function mapName(field: string): { title: string; i18n: string } {
|
||||||
return { title: '-', i18n: '-' };
|
return { title: '-', i18n: '-' };
|
||||||
}
|
}
|
||||||
|
|
||||||
async function groupEmployeeHistory(
|
function groupEmployeeHistory(
|
||||||
historyList: EmployeeHistory[],
|
historyList: EmployeeHistory[],
|
||||||
): Promise<NewEmployeeHistory[]> {
|
): NewEmployeeHistory[] {
|
||||||
const grouped = historyList.reduce((acc, curr) => {
|
const grouped = historyList.reduce((acc, curr) => {
|
||||||
const updatedAt = new Date(curr.updatedAt);
|
const updatedAt = new Date(curr.updatedAt);
|
||||||
const dateKey = `${updatedAt.getFullYear()}-${updatedAt.getMonth() + 1}-${updatedAt.getDate()}`;
|
const dateKey = `${updatedAt.getFullYear()}-${updatedAt.getMonth() + 1}-${updatedAt.getDate()}`;
|
||||||
|
|
@ -346,22 +344,14 @@ async function groupEmployeeHistory(
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
const newList = await groupEmployeeHistory(historyList.value);
|
formatList.value = groupEmployeeHistory(historyList.value);
|
||||||
formatList.value = newList;
|
currentDate.value =
|
||||||
|
formatList.value.at(0)?.date || formatDate(new Date().toISOString());
|
||||||
currentDate.value = formatList.value[currentIndex.value].date;
|
|
||||||
currentData.value = formatList.value[currentIndex.value].data;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
watch(
|
const currentData = computed(() => {
|
||||||
() => currentDate.value,
|
return formatList.value.find((v) => v.date === currentDate.value)?.data || [];
|
||||||
(i) => {
|
});
|
||||||
const dateKey = formatDate(i);
|
|
||||||
isHistoryData.value = formatList.value.some(
|
|
||||||
(item) => item.date === dateKey,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
@ -412,7 +402,7 @@ watch(
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="isHistoryData && currentData?.length > 0">
|
<div v-if="currentData?.length > 0">
|
||||||
<q-table
|
<q-table
|
||||||
flat
|
flat
|
||||||
class="table-border"
|
class="table-border"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue