Added Role composable

This commit is contained in:
Joan Sanchez 2022-03-04 15:33:47 +01:00
parent fade50dd2a
commit ec05b368e9
3 changed files with 31 additions and 10 deletions

View File

@ -0,0 +1,17 @@
import store from '@/store';
export function Role() {
function hasAny(roles: string[]): boolean {
const roleStore: string[] = store.state.roles;
for (const role of roles) {
if (roleStore.indexOf(role) !== -1) return true;
}
return false;
}
return {
hasAny,
};
}

View File

@ -7,6 +7,16 @@ interface UserProfile {
token: string;
}
interface Role {
id: number;
name: string;
}
interface UserRole {
id: number;
role: Role;
}
export default createStore({
state: {
user: {},
@ -23,7 +33,8 @@ export default createStore({
state.user = user;
},
setRoles(state, roles) {
setRoles(state, data) {
const roles = data.map((userRole: UserRole) => userRole.role.name);
state.roles = roles;
},
},

View File

@ -1,9 +1,6 @@
<template>
<q-page class="q-pa-md">
<q-card class="q-pa-md">
Dashboard page..
{{ $filters.toLowerCase('HELLO WORLD') }}
</q-card>
<q-card class="q-pa-md"> Dashboard page.. </q-card>
</q-page>
</template>
@ -11,11 +8,7 @@
import { Options, Vue } from 'vue-class-component';
@Options({})
export default class Dashboard extends Vue {
get whatever(): string {
return this.$filters.toLowerCase('HELLO WORLD');
}
}
export default class Dashboard extends Vue {}
</script>
<style lang="scss" scoped></style>