Files
onboard/resources/js/Stores/report.js
2026-01-04 23:15:06 +09:00

45 lines
1.2 KiB
JavaScript

import {defineStore} from "pinia";
import {useTimestamp} from "@vueuse/core";
import {computed, ref} from "vue";
export const useReportStore = defineStore('reportStore', () => {
const timestampNow = useTimestamp()
const _timestampCurrent = ref(null)
const timestampCurrent = computed({
get: () => {
if (_timestampCurrent.value === null)
return timestampNow.value
return _timestampCurrent.value
},
set: (value) => {
_timestampCurrent.value = value
}
})
const timestampCurrentRange = ref([timestampNow.value, timestampNow.value])
const dataOnReport = ref(null)
const getDataOnReportDate = async () => {
await axios.get(`/api/metric-forms/1/report-by-date?sent_at=${timestampCurrentRange.value}`)
.then(res => {
dataOnReport.value = res.data
})
.catch(err => {
// Отчета на выбранную дату не найдено
if (err.code === 404) {}
})
}
return {
timestampNow,
timestampCurrent,
timestampCurrentRange,
dataOnReport,
getDataOnReportDate
}
})