hrms-mgt/src/modules/18_command/store/Main.ts

36 lines
916 B
TypeScript
Raw Normal View History

2024-09-24 11:19:41 +07:00
import { defineStore } from "pinia";
import { ref } from "vue";
import type { ListCommand } from "@/modules/18_command/interface/index/Main";
import http from "@/plugins/http";
import config from "@/app.config";
2024-09-24 11:19:41 +07:00
export const useCommandMainStore = defineStore("commandMainStore", () => {
const commandTypes = ref<ListCommand[]>([]);
2024-09-24 11:19:41 +07:00
async function getCommandTypes() {
if (commandTypes.value.length === 0) {
await http
.get(config.API.commandType)
.then(async (res) => {
const data = await res.data.result;
commandTypes.value = data;
})
.catch((err) => {
console.log("get commands: ", err);
});
}
return commandTypes.value;
2024-09-24 11:19:41 +07:00
}
function getCommandTypeById(id: string) {
return commandTypes.value.find((item) => item.id === id);
}
return {
commandTypes,
getCommandTypes,
getCommandTypeById,
};
});