ปรับ โหลดประเภทคำสั่ง
This commit is contained in:
parent
6e321708c2
commit
0777b3a39f
2 changed files with 85 additions and 44 deletions
|
|
@ -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,
|
||||
};
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue