save roleMenuUser belum fix
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
import {useSettingStore} from "@/stores/api/setting/setting";
|
import {useSettingStore} from "@/stores/api/setting/setting";
|
||||||
|
|
||||||
const {getTypeUser, getMenu, postRoleUserMenu} = useSettingStore();
|
const {getTypeUser, getMenu, postRoleUserMenu} = useSettingStore();
|
||||||
const {listMenu, listTypeUser, roleMenuById,} = storeToRefs(useSettingStore());
|
const {listMenu, listTypeUser,typeUser, roleMenuById,} = storeToRefs(useSettingStore());
|
||||||
|
|
||||||
const data = ref<any>([]);
|
const data = ref<any>([]);
|
||||||
const menuItem = ref<any>([]);
|
const menuItem = ref<any>([]);
|
||||||
@@ -16,13 +16,16 @@ const dataMenu = async () => {
|
|||||||
])
|
])
|
||||||
// filtering role akses menu terhadap tipe user
|
// filtering role akses menu terhadap tipe user
|
||||||
if (roleMenuById.value.data != null && roleMenuById.value.data != "") {
|
if (roleMenuById.value.data != null && roleMenuById.value.data != "") {
|
||||||
|
console.log('lidt menu',listMenu.value)
|
||||||
return roleMenuById.value.data.map((role_menu: any) => {
|
return roleMenuById.value.data.map((role_menu: any) => {
|
||||||
menuItem.value = listMenu.value.find(
|
menuItem.value = listMenu.value.find(
|
||||||
(menu: any) => menu._id == role_menu.menu_id
|
(menu: any) =>
|
||||||
|
menu._id == role_menu.menu_id
|
||||||
);
|
);
|
||||||
type_user.value = listTypeUser.value.find(
|
type_user.value = listTypeUser.value.find(
|
||||||
(type_user: any) => type_user._id == role_menu.type_user_id
|
(type_user: any) => type_user._id == role_menu.type_user_id
|
||||||
);
|
);
|
||||||
|
console.log('menu item', menuItem.value);
|
||||||
return {
|
return {
|
||||||
_id: role_menu._id,
|
_id: role_menu._id,
|
||||||
idTipeUser: type_user.value._id,
|
idTipeUser: type_user.value._id,
|
||||||
@@ -45,11 +48,13 @@ const checkMenu = () => {
|
|||||||
!roleMenuById.value.data ||
|
!roleMenuById.value.data ||
|
||||||
!roleMenuById.value.data.map((r: any) => r.menu_id).includes(i._id)
|
!roleMenuById.value.data.map((r: any) => r.menu_id).includes(i._id)
|
||||||
);
|
);
|
||||||
|
console.log(' menu arr ',arr);
|
||||||
|
console.log('list menu arr ',listMenu.value);
|
||||||
// Check if arr is not empty or roleMenuById.value.data is null
|
// Check if arr is not empty or roleMenuById.value.data is null
|
||||||
if (arr.length !== 0 || !roleMenuById.value.data) {
|
if (arr.length !== 0 || !roleMenuById.value.data) {
|
||||||
arr.forEach((i: any, index: number) => {
|
arr.forEach((i: any, index: number) => {
|
||||||
data.value.push({
|
data.value.push({
|
||||||
_id: `${index + 1}`,
|
_id: `${i._id}`,
|
||||||
idTipeUser: type_user.value._id,
|
idTipeUser: type_user.value._id,
|
||||||
menu: i.display,
|
menu: i.display,
|
||||||
accessAdd: 0,
|
accessAdd: 0,
|
||||||
@@ -61,59 +66,80 @@ const checkMenu = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const onChange = (newValue, oldValue, el$) => {
|
|
||||||
}
|
|
||||||
// const onSubmit = async () => {
|
// const onSubmit = async () => {
|
||||||
// const formData = dataDetail.value?.form$.data;
|
// // try {
|
||||||
// const result = data.value.map(menu => ({
|
// const formData = dataDetail.value?.form$.data
|
||||||
// id: menu._id,
|
// console.log('form ',formData)
|
||||||
// menuName: formData[`menu_${menu._id}`]?.name,
|
// console.log(' data value',data.value)
|
||||||
// // ... akses data lainnya ...
|
// // Struktur data untuk dikirim ke backend
|
||||||
// }));
|
// const payload = {
|
||||||
|
// menus: data.value.map(menu => ({
|
||||||
|
// type_user_id: formData.idTipeUser, // ID tipe user dari hidden field
|
||||||
|
// menu_id: menu._id,
|
||||||
|
// // menu_name: formData[`name_menu_${menu._id}`], // Nama menu dari static element
|
||||||
|
// access: [
|
||||||
|
// {type: 'add', value: formData[`accessAdd_${menu._id}`] || '0'},
|
||||||
|
// {type: 'update', value: formData[`accessUpdate_${menu._id}`] || '0'},
|
||||||
|
// {type: 'read', value: formData[`accessRead_${menu._id}`] || '0'},
|
||||||
|
// {type: 'delete', value: formData[`accessDelete_${menu._id}`] || '0'}
|
||||||
|
// ]
|
||||||
|
// }))
|
||||||
|
// }
|
||||||
//
|
//
|
||||||
// console.log("Data terstruktur:", result);
|
// // console.log('Data yang dikirim:', payload)
|
||||||
// };
|
// await postRoleUserMenu(payload)
|
||||||
|
// // Panggil action dari store untuk mengirim data ke backend
|
||||||
|
// // const response = await saveRoleMenu(payload)
|
||||||
|
//
|
||||||
|
// // Handle response dari backend
|
||||||
|
// // if (response.success) {
|
||||||
|
// // alert('Data berhasil disimpan!')
|
||||||
|
// // // Refresh data jika perlu
|
||||||
|
// // data.value = await dataMenu()
|
||||||
|
// // } else {
|
||||||
|
// // alert('Gagal menyimpan data: ' + response.message)
|
||||||
|
// // }
|
||||||
|
// // } catch (error) {
|
||||||
|
// // console.error('Error saat menyimpan data:', error)
|
||||||
|
// // alert('Terjadi kesalahan saat menyimpan data')
|
||||||
|
// // }
|
||||||
|
// }
|
||||||
const onSubmit = async () => {
|
const onSubmit = async () => {
|
||||||
// try {
|
const formData = dataDetail.value?.form$.data;
|
||||||
const formData = dataDetail.value?.form$.data
|
|
||||||
|
|
||||||
|
// Jika data.value kosong, kita akan mengambil data dari form
|
||||||
|
const menusToProcess = data.value!==undefined ? data.value : listMenu.value;
|
||||||
|
console.log(formData);
|
||||||
|
console.log(listTypeUser.value);
|
||||||
|
console.log(data.value);
|
||||||
|
console.log(menusToProcess);
|
||||||
// Struktur data untuk dikirim ke backend
|
// Struktur data untuk dikirim ke backend
|
||||||
const payload = {
|
const payload = {
|
||||||
type_user_id: formData.idTipeUser, // ID tipe user dari hidden field
|
menus: menusToProcess.map(menu => {
|
||||||
menus: data.value.map(menu => ({
|
const menuId = menu._id || menu.id; // Gunakan _id atau id tergantung struktur data
|
||||||
menu_id: menu._id,
|
return {
|
||||||
menu_name: formData[`name_menu_${menu._id}`], // Nama menu dari static element
|
type_user_id: formData.idTipeUser||typeUser.value, // ID tipe user dari hidden field
|
||||||
access: [
|
menu_id: menuId,
|
||||||
{type: 'add', value: formData[`accessAdd_${menu._id}`] || '0'},
|
access: [
|
||||||
{type: 'update', value: formData[`accessUpdate_${menu._id}`] || '0'},
|
{type: 'add', value: formData[`accessAdd_${menuId}`] || '0'},
|
||||||
{type: 'read', value: formData[`accessRead_${menu._id}`] || '0'},
|
{type: 'update', value: formData[`accessUpdate_${menuId}`] || '0'},
|
||||||
{type: 'delete', value: formData[`accessDelete_${menu._id}`] || '0'}
|
{type: 'read', value: formData[`accessRead_${menuId}`] || '0'},
|
||||||
]
|
{type: 'delete', value: formData[`accessDelete_${menuId}`] || '0'}
|
||||||
}))
|
]
|
||||||
}
|
};
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
// console.log('Data yang dikirim:', payload)
|
console.log('Payload yang dikirim:', payload);
|
||||||
await postRoleUserMenu(payload)
|
await postRoleUserMenu(payload);
|
||||||
// Panggil action dari store untuk mengirim data ke backend
|
};
|
||||||
// const response = await saveRoleMenu(payload)
|
|
||||||
|
|
||||||
// Handle response dari backend
|
|
||||||
// if (response.success) {
|
|
||||||
// alert('Data berhasil disimpan!')
|
|
||||||
// // Refresh data jika perlu
|
|
||||||
// data.value = await dataMenu()
|
|
||||||
// } else {
|
|
||||||
// alert('Gagal menyimpan data: ' + response.message)
|
|
||||||
// }
|
|
||||||
// } catch (error) {
|
|
||||||
// console.error('Error saat menyimpan data:', error)
|
|
||||||
// alert('Terjadi kesalahan saat menyimpan data')
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
data.value = await dataMenu();
|
data.value = await dataMenu();
|
||||||
checkMenu()
|
|
||||||
console.log('aaaaa', data.value);
|
console.log('aaaaa', data.value);
|
||||||
|
console.log('user select', typeUser.value);
|
||||||
|
console.log('listTypeUser', listTypeUser.value);
|
||||||
|
checkMenu()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@@ -142,6 +168,7 @@ const createCheckbox = (namePrefix: string, menu: any) => {
|
|||||||
// Helper function to create a menu row
|
// Helper function to create a menu row
|
||||||
let count = 0
|
let count = 0
|
||||||
const createMenuRow = (menu: any) => {
|
const createMenuRow = (menu: any) => {
|
||||||
|
console.log('create menu',menu);
|
||||||
count += 1; // Use the current counter value and then increment it
|
count += 1; // Use the current counter value and then increment it
|
||||||
const multiElement = {
|
const multiElement = {
|
||||||
nama_menu: {
|
nama_menu: {
|
||||||
@@ -160,15 +187,13 @@ const createMenuRow = (menu: any) => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
idTipeUser: {
|
idTipeUser: {
|
||||||
type: 'hidden',
|
type: 'text',
|
||||||
default: menu.idTipeUser,
|
default: menu.idTipeUser,
|
||||||
builder: {
|
builder: {
|
||||||
type: 'text',
|
type: 'text',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
console.log(multiElement)
|
|
||||||
|
|
||||||
const result = [
|
const result = [
|
||||||
[`${count}`, 1, 1],
|
[`${count}`, 1, 1],
|
||||||
[
|
[
|
||||||
@@ -195,31 +220,8 @@ const createMenuRow = (menu: any) => {
|
|||||||
[createCheckbox('accessRead', menu), 1, 1],
|
[createCheckbox('accessRead', menu), 1, 1],
|
||||||
[createCheckbox('accessDelete', menu), 1, 1]
|
[createCheckbox('accessDelete', menu), 1, 1]
|
||||||
]
|
]
|
||||||
// console.log(result)
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// const checkMenu = () => {
|
|
||||||
// // Filter the listMenu based on roleMenuById
|
|
||||||
// var arr = listMenu.value.filter((i: any) =>
|
|
||||||
// !roleMenuById.value.data ||
|
|
||||||
// !roleMenuById.value.data.map((r: any) => r.menu_id).includes(i._id)
|
|
||||||
// );
|
|
||||||
// // Check if arr is not empty or roleMenuById.value.data is null
|
|
||||||
// if (arr.length !== 0 || !roleMenuById.value.data) {
|
|
||||||
// arr.forEach((i: any, index: number) => {
|
|
||||||
// data.value.push({
|
|
||||||
// _id: `${index + 1}`,
|
|
||||||
// menu: i.display,
|
|
||||||
// accessAdd: 0,
|
|
||||||
// accessUpdate: 0,
|
|
||||||
// accessRead: 0,
|
|
||||||
// accessDelete: 0
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
@@ -65,8 +65,6 @@ export default defineEventHandler(async (event) => {
|
|||||||
// });
|
// });
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// console.log(authorizationUrl)
|
|
||||||
|
|
||||||
return { callbackURL: authorizationUrl }
|
return { callbackURL: authorizationUrl }
|
||||||
// return { callbackURL: authorizationUrl+`&response_type=${responseType}&scope=${scope}` }
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
export default defineEventHandler(async (event) => {
|
export default defineEventHandler(async (event) => {
|
||||||
const res = await $fetch(`http://10.10.150.131:8080/api/menu/type`, {
|
const body = await readBody(event)
|
||||||
method: "GET",
|
console.log(body)
|
||||||
headers: {"Content-Type": "application/json"}
|
const res = await $fetch(`http://10.10.150.131:8080/api/menu/role/insert`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {"Content-Type": "application/json"},
|
||||||
|
body:body
|
||||||
})
|
})
|
||||||
// console.log(res)
|
// console.log(res)
|
||||||
return res
|
return res
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
import { defineStore } from "pinia";
|
|
||||||
import axios from "axios";
|
|
||||||
export const useMenu = defineStore("menu", () => {
|
|
||||||
const listMenu = ref<any>([]);
|
|
||||||
const getMenu = async () => {
|
|
||||||
// await $fetch("http://10.10.150.131:8080/api/menu/getlist", {
|
|
||||||
await $fetch("/api/menu/listMenu", {
|
|
||||||
// mode: "no-cors",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
method:"GET",
|
|
||||||
})
|
|
||||||
.then((res) => {
|
|
||||||
listMenu.value = res
|
|
||||||
console.log(listMenu.value);
|
|
||||||
});
|
|
||||||
// return listMenu;
|
|
||||||
};
|
|
||||||
return { getMenu,listMenu };
|
|
||||||
});
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
import { defineStore } from "pinia";
|
|
||||||
import axios from "axios";
|
|
||||||
export const useRoleMode = defineStore("roleMode", () => {
|
|
||||||
const typeUser = ref<any>([]);
|
|
||||||
const roleMenuById = ref<any>([]);
|
|
||||||
const getRoleMenuById = async (body: Record<string, any>) => {
|
|
||||||
typeUser.value = body;
|
|
||||||
// console.log(typeUser.value);
|
|
||||||
// await $fetch("http://10.10.150.131:8080/api/menu/getlist", {
|
|
||||||
await $fetch(`/api/roleMenu/roleMenu`, {
|
|
||||||
// mode: "no-cors",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
method: "POST",
|
|
||||||
body: JSON.stringify(body),
|
|
||||||
}).then((res) => {
|
|
||||||
roleMenuById.value = res;
|
|
||||||
// console.log(roleMenuById.value);
|
|
||||||
});
|
|
||||||
// return roleMenuById;
|
|
||||||
};
|
|
||||||
return { getRoleMenuById, roleMenuById, typeUser };
|
|
||||||
});
|
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import {defineStore} from "pinia";
|
import {defineStore} from "pinia";
|
||||||
|
import type {RoleMenuUser} from "~/types/setting/RoleMenuUser";
|
||||||
|
|
||||||
export const useSettingStore = defineStore("SettingStore", () => {
|
export const useSettingStore = defineStore("SettingStore", () => {
|
||||||
const listMenu = ref<any>([]);
|
const listMenu = ref<any>([]);
|
||||||
@@ -43,7 +44,7 @@ export const useSettingStore = defineStore("SettingStore", () => {
|
|||||||
// Accept: 'application/json',
|
// Accept: 'application/json',
|
||||||
// 'Content-Type': 'application/json',
|
// 'Content-Type': 'application/json',
|
||||||
// },
|
// },
|
||||||
method:"GET",
|
method: "GET",
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
listTypeUser.value = res
|
listTypeUser.value = res
|
||||||
@@ -51,15 +52,36 @@ export const useSettingStore = defineStore("SettingStore", () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const postRoleUserMenu = async (body: Record<string, any>) => {
|
const postRoleUserMenu = async (body: Record<string, any>) => {
|
||||||
console.log('asdasdasd',body)
|
// console.log('asdasdasd', body)
|
||||||
await $fetch(`/api/setting/postRoleMenuUserMenu`, {
|
const roleUserMenu = body.menus.map((item) => ({
|
||||||
method:'POST',
|
type_user_id: item.type_user_id,
|
||||||
headers:{'Content-Type': 'application/json'},
|
menu_id: item.menu_id,
|
||||||
body:JSON.stringify(body)
|
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')})
|
.then((res) => {
|
||||||
.catch((err) => {console.log(err)})
|
console.log('success')
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return {getMenu,getRoleMenuById,getTypeUser,postRoleUserMenu, listMenu,roleMenuById, typeUser,listTypeUser};
|
return {getMenu, getRoleMenuById, getTypeUser, postRoleUserMenu,typeUserSelected, listMenu, roleMenuById, typeUser, listTypeUser,listTypeUserSelected};
|
||||||
})
|
})
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
import axios from 'axios'
|
|
||||||
import { defineStore } from 'pinia'
|
|
||||||
|
|
||||||
// export const useMySidebarStore = defineStore({
|
|
||||||
// id: 'mySidebarStore',
|
|
||||||
// state: () => ({ }),
|
|
||||||
// actions: {}
|
|
||||||
// })
|
|
||||||
|
|
||||||
export const useSidebarStore = defineStore('SidebarStore', () => {
|
|
||||||
const getSidebar = async () => {
|
|
||||||
console.log('aaaaa')
|
|
||||||
const res = await $fetch(`http://10.10.150.131:8080/api/login/6835632801e46cf9c5551876`, {
|
|
||||||
mode: 'no-cors',
|
|
||||||
headers: {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
Accept: 'application/json',
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.then((response) => {
|
|
||||||
console.log(response)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
getSidebar
|
|
||||||
}
|
|
||||||
})
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
import { defineStore } from "pinia";
|
|
||||||
import axios from "axios";
|
|
||||||
export const useTypeUser = defineStore("typeUser", () => {
|
|
||||||
const listTypeUser = ref<any>([]);
|
|
||||||
const getTypeUser = async () => {
|
|
||||||
// await $fetch("http://10.10.150.131:8080/api/menu/type", {
|
|
||||||
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
|
|
||||||
// console.log(listTypeUser.value);
|
|
||||||
});
|
|
||||||
// return listTypeUser;
|
|
||||||
};
|
|
||||||
return { getTypeUser,listTypeUser };
|
|
||||||
});
|
|
||||||
Reference in New Issue
Block a user