add function formatted date/time to API in mixin
This commit is contained in:
parent
197b621436
commit
126fbdbed1
2 changed files with 20 additions and 7 deletions
|
|
@ -1,7 +1,6 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, reactive, watch, onMounted } from "vue";
|
import { ref, reactive, watch, onMounted } from "vue";
|
||||||
import { useQuasar } from "quasar";
|
import { useQuasar } from "quasar";
|
||||||
import { format, utcToZonedTime } from "date-fns-tz";
|
|
||||||
|
|
||||||
import http from "@/plugins/http";
|
import http from "@/plugins/http";
|
||||||
import config from "@/app.config";
|
import config from "@/app.config";
|
||||||
|
|
@ -25,6 +24,7 @@ const {
|
||||||
showLoader,
|
showLoader,
|
||||||
hideLoader,
|
hideLoader,
|
||||||
success,
|
success,
|
||||||
|
convertDateToAPI,
|
||||||
} = mixin;
|
} = mixin;
|
||||||
|
|
||||||
const emit = defineEmits(["update:change-page"]);
|
const emit = defineEmits(["update:change-page"]);
|
||||||
|
|
@ -113,12 +113,7 @@ function onSubmit() {
|
||||||
|
|
||||||
/** Function เปลี่ยนรอบเวลา*/
|
/** Function เปลี่ยนรอบเวลา*/
|
||||||
async function changeRound() {
|
async function changeRound() {
|
||||||
const formattedDateForAPI = await (formData.effectiveDate
|
const formattedDateForAPI = await convertDateToAPI(formData.effectiveDate);
|
||||||
? format(
|
|
||||||
utcToZonedTime(formData.effectiveDate, "Asia/Bangkok"),
|
|
||||||
"yyyy-MM-dd"
|
|
||||||
)
|
|
||||||
: null);
|
|
||||||
|
|
||||||
showLoader();
|
showLoader();
|
||||||
await http
|
await http
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import moment from "moment";
|
||||||
import CustomComponent from "@/components/CustomDialog.vue";
|
import CustomComponent from "@/components/CustomDialog.vue";
|
||||||
import { Loading, QSpinnerCube } from "quasar";
|
import { Loading, QSpinnerCube } from "quasar";
|
||||||
import { logout } from "@/plugins/auth";
|
import { logout } from "@/plugins/auth";
|
||||||
|
import { format, utcToZonedTime } from "date-fns-tz";
|
||||||
|
|
||||||
moment.locale("th");
|
moment.locale("th");
|
||||||
|
|
||||||
|
|
@ -1177,6 +1178,20 @@ export const useCounterMixin = defineStore("mixin", () => {
|
||||||
// return `${y} ปี ${m} เดือน ${d} วัน`;
|
// return `${y} ปี ${m} เดือน ${d} วัน`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// กรณีมีเฉพาะ date
|
||||||
|
function convertDateToAPI(date: Date | null) {
|
||||||
|
return date
|
||||||
|
? format(utcToZonedTime(date, "Asia/Bangkok"), "yyyy-MM-dd")
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// กรณี datetime
|
||||||
|
function convertDatetimeToAPI(date: Date | null) {
|
||||||
|
return date
|
||||||
|
? format(utcToZonedTime(date, "Asia/Bangkok"), "yyyy-MM-dd HH:mm:ss")
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
calAge,
|
calAge,
|
||||||
date2Thai,
|
date2Thai,
|
||||||
|
|
@ -1225,5 +1240,8 @@ export const useCounterMixin = defineStore("mixin", () => {
|
||||||
onSearchDataTable,
|
onSearchDataTable,
|
||||||
formatDatePosition,
|
formatDatePosition,
|
||||||
formatDatePositionReport,
|
formatDatePositionReport,
|
||||||
|
|
||||||
|
convertDateToAPI,
|
||||||
|
convertDatetimeToAPI,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue