store
This commit is contained in:
@@ -1,9 +1,15 @@
|
||||
<script setup lang="ts">
|
||||
const data = ref(null)
|
||||
import {useSettingStore} from "@/stores/api/setting/setting"
|
||||
const {getTypeUser} = useSettingStore()
|
||||
|
||||
// import {useSettingStore} from "@/stores/api/setting/setting"
|
||||
// const {getTypeUser} = useSettingStore()
|
||||
import {useMySetting2Store} from "@/stores/api/setting/setting2"
|
||||
const store = useMySetting2Store()
|
||||
const onSubmit = async() => {
|
||||
// await store.getTypeUser()
|
||||
// console.log("ini tipe usernya",store.listTypeUser)
|
||||
// await store.getRoleMenuById('683d57b2bccc67d467a9e10f')
|
||||
// console.log("ini tipe usernya",store.roleMenuById)
|
||||
// await store.addTypeUser(data.value?.form$.data)
|
||||
// await getTypeUser(data.value?.form$.data)
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -88,7 +88,7 @@ watch([mdAndDown, () => props.items], ([mdVal, items]) => {
|
||||
<div>
|
||||
<LayoutFullVerticalHeaderRightMobileSidebar />
|
||||
<LayoutFullVerticalHeaderThemeToggler />
|
||||
<LayoutFullVerticalHeaderNavigations />
|
||||
<!-- <LayoutFullVerticalHeaderNavigations /> -->
|
||||
<LayoutFullVerticalHeaderProfileDD />
|
||||
</div>
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ onMounted(async() => {
|
||||
<!-- ini list -->
|
||||
<template>
|
||||
<div class="d-flex pt-6 align-center ml-3 mb-6">
|
||||
<!-- <v-btn class="mr-16" color="primary" variant="tonal" @click="state= !state; type='create'"><v-icon>mdi-plus</v-icon> Tipe User</v-btn> -->
|
||||
<v-btn class="mr-16" color="primary" variant="tonal" @click="state= !state; type='create'"><v-icon>mdi-plus</v-icon> Tipe User</v-btn>
|
||||
</div>
|
||||
<v-row no-gutters>
|
||||
<v-col cols="12" md="4">
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
import { defineStore } from 'pinia'
|
||||
const runtime = useRuntimeConfig().public;
|
||||
interface Setting {
|
||||
listTypeUser: [];
|
||||
listMenu: [];
|
||||
roleMenuById: [];
|
||||
message: string;
|
||||
}
|
||||
export const useMySetting2Store = defineStore('mySetting2Store', {
|
||||
// id: 'mySetting2Store',
|
||||
state: (): Setting => ({
|
||||
listTypeUser: [],
|
||||
listMenu: [],
|
||||
roleMenuById: [],
|
||||
message: ''
|
||||
}),
|
||||
actions: {
|
||||
async getMenu() {
|
||||
try {
|
||||
const response = await $fetch(`${runtime.APIBASE}/menu/getlist`, {
|
||||
method: "GET",
|
||||
headers: { "Content-Type": "application/json" }
|
||||
})
|
||||
this.listMenu = response as []
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
this.message = error.message
|
||||
// console.log(error.message)
|
||||
}
|
||||
}
|
||||
},
|
||||
async getRoleMenuById(body: Record<string, any>) {
|
||||
try {
|
||||
console.log(body)
|
||||
const response = await $fetch(`${runtime.APIBASE}/menu/role/type/${body}`, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
method: "GET",
|
||||
})
|
||||
this.roleMenuById = response as []
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
this.message = error.message
|
||||
// console.log(error.message)
|
||||
}
|
||||
}
|
||||
},
|
||||
async getTypeUser() {
|
||||
try {
|
||||
const response = await $fetch(`${runtime.APIBASE}/menu/type`, {
|
||||
method: "GET",
|
||||
headers: { "Content-Type": "application/json" }
|
||||
})
|
||||
this.listTypeUser = response as []
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
this.message = error.message
|
||||
// console.log(error.message)
|
||||
}
|
||||
}
|
||||
},
|
||||
async postRoleUserMenu(body: Record<string, any>) {
|
||||
try {
|
||||
const roleUserMenu = body.menus.map((item) => ({
|
||||
type_user_id: item.type_user_id,
|
||||
menu_id: item.menu_id,
|
||||
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("body post:", body.menus)
|
||||
const response = await $fetch(`${runtime.APIBASE}/menu/update/rolemenu?id=${body.menus[0].type_user_id}`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(roleUserMenu)
|
||||
})
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
this.message = error.message
|
||||
// console.log(error.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
// async addTypeUser(data: any) {
|
||||
// console.log(data)
|
||||
// try {
|
||||
// const response = await $fetch('https://',{
|
||||
// method: 'POST',
|
||||
// headers: {'Content-Type': 'application/json'},
|
||||
// body: JSON.stringify(data)
|
||||
// })
|
||||
// } catch (error) {
|
||||
// if(error instanceof Error){
|
||||
// this.message = error.message
|
||||
// // console.log(error.message)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user