ปรับ โหลดประเภทคำสั่ง

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2024-09-30 16:18:46 +07:00
parent 6e321708c2
commit 0777b3a39f
2 changed files with 85 additions and 44 deletions

View file

@ -1,7 +1,18 @@
import { defineStore } from "pinia";
import { ref } from "vue";
import { useQuasar } from "quasar";
import type { DataListCommand } from "@/modules/18_command/interface/response/Main";
import { useCounterMixin } from "@/stores/mixin";
import http from "@/plugins/http";
import config from "@/app.config";
import type {
DataListCommand,
DataCommandType,
} from "@/modules/18_command/interface/response/Main";
const $q = useQuasar();
const { showLoader, hideLoader, messageError } = useCounterMixin();
export const useCommandListStore = defineStore("commandListStore", () => {
const tabsMain = ref<string>("DRAFT");
@ -9,10 +20,42 @@ export const useCommandListStore = defineStore("commandListStore", () => {
const total = ref<number>(0);
const maxPage = ref<number>(0);
const listCommand = ref<DataCommandType[]>([]); //รายการข้อมูลปรเภทคำสั่ง
/**
* API
* 'listCommand' Call API
* @returns
*/
async function fetchCommandType() {
//เช็คค่าของ listCommand
if (listCommand.value.length === 0) {
showLoader();
try {
const res = await http.get(config.API.commandType);
const data = res.data.result;
listCommand.value = data.map((e: DataCommandType) => ({
id: e.id,
name: e.subtitle ? `${e.name} (${e.subtitle})` : e.name,
}));
return listCommand.value;
} catch (err) {
messageError($q, err);
} finally {
hideLoader();
}
} else {
return listCommand.value;
}
}
return {
tabsMain,
rows,
total,
maxPage,
fetchCommandType,
};
});