import {defineStore} from "pinia"; import type {RoleMenuUser} from "~/types/setting/RoleMenuUser"; export const useSettingStore = defineStore("SettingStore", () => { const listMenu = ref([]); const getMenu = async () => { await $fetch("/api/menu/listMenu", { // mode: "no-cors", headers: { "Content-Type": "application/json", }, method: "GET", }) .then((res) => { listMenu.value = res console.log(listMenu.value); }); }; const typeUser = ref([]); const roleMenuById = ref([]); const getRoleMenuById = async (body: Record) => { typeUser.value = body; await $fetch(`/api/roleMenu/roleMenu`, { // mode: "no-cors", headers: { "Content-Type": "application/json", }, method: "POST", body: JSON.stringify(body), }).then((res) => { roleMenuById.value = res; }); }; const listTypeUser = ref([]); const getTypeUser = async () => { await $fetch("/api/typeUser/listTypeUser", { // mode: 'no-cors', // headers: { // 'Access-Control-Allow-Origin': '*', // Accept: 'application/json', // 'Content-Type': 'application/json', // }, method: "GET", }) .then((res) => { listTypeUser.value = res }); }; const postRoleUserMenu = async (body: Record) => { // console.log('asdasdasd', body) const roleUserMenu = body.menus.map((item) => ({ type_user_id: item.type_user_id, menu_id: item.menu_id, access: [ // item.access { add: parseInt(item.access[0].value), update: parseInt(item.access[1].value), read: parseInt(item.access[2].value), delete: parseInt(item.access[3].value), } ] })) { } console.log('role', roleUserMenu); await $fetch(`/api/setting/postRoleMenuUser`, { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify(roleUserMenu) }) .then((res) => { console.log('success') }) .catch((err) => { console.log(err) }) } return {getMenu, getRoleMenuById, getTypeUser, postRoleUserMenu, listMenu, roleMenuById, typeUser, listTypeUser}; })