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"; export const useCommandMainStore = defineStore("commandMainStore", () => { const commandTypes = ref([]); 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; } function getCommandTypeById(id: string) { return commandTypes.value.find((item) => item.id === id); } return { commandTypes, getCommandTypes, getCommandTypeById, }; });