1
1
<script setup lang="ts">
2
2
import { VForm } from ' vuetify/components/VForm'
3
3
import { usePermissionStore } from ' ~/stores/admin/permission'
4
- import { type Role , useRoleStore } from ' ~/stores/admin/role'
5
4
6
5
interface Props {
7
6
isDialogVisible: boolean
@@ -15,10 +14,9 @@ interface Emit {
15
14
const props = defineProps <Props >()
16
15
const emit = defineEmits <Emit >()
17
16
18
- const roleStore = useRoleStore ()
19
- const { roleList } = storeToRefs (roleStore )
20
17
const permissionStore = usePermissionStore ()
21
18
const { permissionList } = storeToRefs (permissionStore )
19
+ const { fetchPermissions } = permissionStore
22
20
23
21
const refPermissionForm = ref <VForm >()
24
22
const isFormValid = ref (false )
@@ -29,20 +27,32 @@ const localRoleData = ref<Partial<Role>>({
29
27
name: ' ' ,
30
28
})
31
29
32
- // const checkedCount = computed(() => {
33
- // let counter = 0
34
-
35
- // permissions.value.forEach((permission) => {
36
- // Object.entries(permission).forEach(([key, value]) => {
37
- // if (key !== 'name' && value)
38
- // counter++
39
- // })
40
- // })
41
-
42
- // return counter
43
- // })
44
-
45
- // const isIndeterminate = computed(() => checkedCount.value > 0 && checkedCount.value < (permissions.value.length * 3))
30
+ const permissions = [
31
+ {
32
+ action: ' Read' ,
33
+ subject: ' All' ,
34
+ value: {
35
+ action: ' read' ,
36
+ subject: ' all' ,
37
+ },
38
+ },
39
+ {
40
+ action: ' Read' ,
41
+ subject: ' Category' ,
42
+ value: {
43
+ action: ' read' ,
44
+ subject: ' category' ,
45
+ },
46
+ },
47
+ {
48
+ action: ' Create' ,
49
+ subject: ' All' ,
50
+ value: {
51
+ action: ' create' ,
52
+ subject: ' all' ,
53
+ },
54
+ },
55
+ ]
46
56
47
57
// // select all
48
58
// watch(isSelectAll, (val) => {
@@ -116,11 +126,15 @@ watch(() => props.roleData, (newRoleData) => {
116
126
localRoleData .value = { ... newRoleData }
117
127
}
118
128
}, { immediate: true })
129
+
130
+ onMounted (() => {
131
+ fetchPermissions ()
132
+ })
119
133
</script >
120
134
121
135
<template >
122
136
<VDialog
123
- :width =" $vuetify.display.smAndDown ? 'auto ' : 900"
137
+ :width =" $vuetify.display.smAndDown ? '100% ' : 900"
124
138
:model-value =" props.isDialogVisible"
125
139
@update:model-value =" onReset"
126
140
>
@@ -146,69 +160,59 @@ watch(() => props.roleData, (newRoleData) => {
146
160
<VTextField
147
161
v-model =" localRoleData.name"
148
162
:rules =" [requiredValidator]"
163
+ class =" mb-6"
149
164
label =" Role Name"
150
165
placeholder =" Enter Role Name"
151
166
/>
152
167
153
- <h5 class =" text-h5 my-6" >
154
- Role Permissions
155
- </h5 >
156
-
157
- <!-- 👉 Role Permissions -->
158
-
159
- <VTable class =" permission-table text-no-wrap" >
160
- <!-- 👉 Admin -->
161
- <!-- <tr>
162
- <td class="text-h6">
163
- Admin
164
- </td>
165
- <td colspan="3">
166
- <div class="d-flex justify-end">
167
- <VCheckbox
168
- v-model="isSelectAll"
169
- v-model:indeterminate="isIndeterminate"
170
- label="Select All"
168
+ <!-- 👉 Role filter -->
169
+ <VRow >
170
+ <VCol cols =" 12" md =" 4" class =" d-flex align-center" >
171
+ <h5 class =" text-h5" >
172
+ Role Permissions
173
+ </h5 >
174
+ </VCol >
175
+
176
+ <VCol cols =" 12" md =" 8" >
177
+ <div class =" d-flex align-center gap-3 flex-wrap" >
178
+ <p >
179
+ Select:
180
+ </p >
181
+
182
+ <VBtn
183
+ color =" secondary"
184
+ variant =" text"
185
+ text =" All"
186
+ />
187
+
188
+ <VBtn
189
+ color =" secondary"
190
+ variant =" text"
191
+ text =" None"
192
+ />
193
+
194
+ <div class =" flex-grow-1" >
195
+ <VTextField
196
+ v-model =" search"
197
+ placeholder =" Search"
198
+ density =" compact"
199
+ prepend-inner-icon =" ri-search-line"
171
200
/>
172
201
</div >
173
- </td>
174
- </tr> -->
202
+ </div >
203
+ </VCol >
204
+ </VRow >
175
205
176
- <!-- 👉 Other permission loop -->
177
- <!-- <template
178
- v-for="permission in permissionList"
179
- :key="permission.id"
180
- >
181
- <tr>
182
- <td class="text-h6">
183
- {{ permission.action }}
184
- </td>
185
- <td style="inline-size: 5.75rem;">
186
- <div class="d-flex justify-end">
187
- <VCheckbox
188
- v-model="permission.read"
189
- label="Read"
190
- />
191
- </div>
192
- </td>
193
- <td style="inline-size: 5.75rem;">
194
- <div class="d-flex justify-end">
195
- <VCheckbox
196
- v-model="permission.write"
197
- label="Write"
198
- />
199
- </div>
200
- </td>
201
- <td style="inline-size: 5.75rem;">
202
- <div class="d-flex justify-end">
203
- <VCheckbox
204
- v-model="permission.create"
205
- label="Create"
206
- />
207
- </div>
208
- </td>
209
- </tr>
210
- </template> -->
211
- </VTable >
206
+ <!-- 👉 Role Permissions -->
207
+ <div class =" mt-6 d-flex flex-wrap gap-3" >
208
+ <div v-for =" permission in permissionList" :key =" permission.id" class =" d-flex align-center gap-2 flex-wrap border px-3 py-2" >
209
+ <VLabel >
210
+ <VCheckboxBtn />
211
+
212
+ {{ permission.action }}:{{ permission.subject }}
213
+ </VLabel >
214
+ </div >
215
+ </div >
212
216
213
217
<!-- 👉 Actions button -->
214
218
<div class =" d-flex align-center justify-center gap-3 mt-6" >
@@ -230,23 +234,5 @@ watch(() => props.roleData, (newRoleData) => {
230
234
</VDialog >
231
235
</template >
232
236
233
- <style lang="scss">
234
- .permission-table {
235
- td {
236
- border-block-end : 1px solid rgba (var (--v-border-color ), var (--v-border-opacity ));
237
- padding-block : 0.625rem ;
238
-
239
- .v-checkbox {
240
- min-inline-size : 4.75rem ;
241
- }
242
-
243
- & :not (:first-child ) {
244
- padding-inline : 0.75rem ;
245
- }
246
-
247
- .v-label {
248
- white-space : nowrap ;
249
- }
250
- }
251
- }
237
+ <style lang="scss" scoped>
252
238
</style >
0 commit comments