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

View File

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