@drax/crud-vue 0.14.2 → 0.14.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/components/Crud.vue +8 -28
- package/src/components/CrudForm.vue +42 -29
- package/src/composables/UseCrud.ts +3 -3
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.14.
|
|
6
|
+
"version": "0.14.4",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "./src/index.ts",
|
|
9
9
|
"module": "./src/index.ts",
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"vue-tsc": "^2.1.10",
|
|
65
65
|
"vuetify": "^3.7.1"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "d16e928bedeaaedf04229ec2db917e67d0eb117c"
|
|
68
68
|
}
|
package/src/components/Crud.vue
CHANGED
|
@@ -12,8 +12,8 @@ const {entity} = defineProps({
|
|
|
12
12
|
})
|
|
13
13
|
|
|
14
14
|
const {
|
|
15
|
-
onView, onCreate, onEdit, onDelete,
|
|
16
|
-
operation, dialog,
|
|
15
|
+
onView, onCreate, onEdit, onDelete, resetCrudStore,
|
|
16
|
+
operation, dialog, notify, error, message, doExport,
|
|
17
17
|
prepareFilters
|
|
18
18
|
} = useCrud(entity);
|
|
19
19
|
|
|
@@ -22,27 +22,8 @@ onBeforeMount(() => {
|
|
|
22
22
|
prepareFilters()
|
|
23
23
|
})
|
|
24
24
|
|
|
25
|
-
const emit = defineEmits(['created', 'updated', 'deleted', 'viewed'])
|
|
25
|
+
const emit = defineEmits(['created', 'updated', 'deleted', 'viewed','canceled'])
|
|
26
26
|
|
|
27
|
-
async function submit() {
|
|
28
|
-
let result = await onSubmit(form.value)
|
|
29
|
-
switch (result.status) {
|
|
30
|
-
case "created":
|
|
31
|
-
emit("created", result.item)
|
|
32
|
-
break
|
|
33
|
-
case "updated":
|
|
34
|
-
emit("updated", result.item)
|
|
35
|
-
break
|
|
36
|
-
case "deleted":
|
|
37
|
-
emit("deleted")
|
|
38
|
-
break
|
|
39
|
-
case "viewed":
|
|
40
|
-
emit("deleted")
|
|
41
|
-
break
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
27
|
|
|
47
28
|
</script>
|
|
48
29
|
|
|
@@ -90,13 +71,12 @@ async function submit() {
|
|
|
90
71
|
|
|
91
72
|
<slot name="form">
|
|
92
73
|
<crud-form
|
|
93
|
-
v-model="form"
|
|
94
74
|
:entity="entity"
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
@
|
|
99
|
-
@
|
|
75
|
+
@created="item => emit('created', item)"
|
|
76
|
+
@updated="item => emit('updated', item)"
|
|
77
|
+
@deleted="emit('deleted')"
|
|
78
|
+
@viewed="emit('viewed')"
|
|
79
|
+
@canceled="emit('canceled')"
|
|
100
80
|
>
|
|
101
81
|
|
|
102
82
|
<template v-for="ifield in entity.fields" :key="ifield.name" v-slot:[`field.${ifield.name}`]="{field}">
|
|
@@ -1,43 +1,39 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import {useI18n} from "vue-i18n";
|
|
3
|
-
import type {IEntityCrud, IEntityCrudField
|
|
3
|
+
import type {IEntityCrud, IEntityCrudField} from "@drax/crud-share";
|
|
4
4
|
import {useFormUtils} from "../composables/UseFormUtils";
|
|
5
5
|
import {getItemId} from "../helpers/getItemId";
|
|
6
6
|
import CrudFormField from "./CrudFormField.vue";
|
|
7
|
-
import {computed, defineEmits,
|
|
7
|
+
import {computed, defineEmits, defineProps, ref} from "vue";
|
|
8
8
|
import type {PropType} from "vue";
|
|
9
9
|
import {useCrudStore} from "../stores/UseCrudStore";
|
|
10
|
+
import {useCrud} from "../composables/UseCrud";
|
|
10
11
|
import {useAuth} from '@drax/identity-vue'
|
|
11
12
|
|
|
12
13
|
const {hasPermission} = useAuth()
|
|
13
14
|
const {t, te} = useI18n()
|
|
14
15
|
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
const valueModel = defineModel({type: [Object]})
|
|
18
|
-
|
|
19
|
-
const {entity, operation} = defineProps({
|
|
17
|
+
const {entity} = defineProps({
|
|
20
18
|
entity: {type: Object as PropType<IEntityCrud>, required: true},
|
|
21
|
-
operation: {type: String as PropType<IEntityCrudOperation>, required: true},
|
|
22
|
-
readonly: {type: Boolean, default: false},
|
|
23
|
-
error: {type: String, required: false},
|
|
24
19
|
})
|
|
25
20
|
|
|
21
|
+
const {onSubmit, onCancel, operation, error, form} = useCrud(entity)
|
|
26
22
|
|
|
27
|
-
const emit = defineEmits(['
|
|
23
|
+
const emit = defineEmits(['created', 'updated', 'deleted', 'viewed', 'canceled'])
|
|
28
24
|
|
|
29
25
|
const store = useCrudStore()
|
|
30
26
|
|
|
31
27
|
const formRef = ref()
|
|
32
28
|
|
|
33
29
|
const fields = computed(() => {
|
|
34
|
-
if (operation === 'create') {
|
|
30
|
+
if (operation.value === 'create') {
|
|
35
31
|
return entity.createFields
|
|
36
|
-
} else if (operation === 'edit') {
|
|
32
|
+
} else if (operation.value === 'edit') {
|
|
37
33
|
return entity.updateFields
|
|
38
|
-
} else if (operation === 'delete') {
|
|
34
|
+
} else if (operation.value === 'delete') {
|
|
39
35
|
return entity.deleteFields
|
|
40
|
-
} else if (operation === 'view') {
|
|
36
|
+
} else if (operation.value === 'view') {
|
|
41
37
|
return entity.viewFields
|
|
42
38
|
}
|
|
43
39
|
return []
|
|
@@ -51,27 +47,41 @@ const aFields = computed(() => {
|
|
|
51
47
|
async function submit() {
|
|
52
48
|
store.resetErrors()
|
|
53
49
|
|
|
54
|
-
if (
|
|
55
|
-
|
|
56
|
-
|
|
50
|
+
if (['create', 'edit'].includes(operation.value)) {
|
|
51
|
+
const {valid, errors} = await formRef.value.validate()
|
|
52
|
+
if (!valid) {
|
|
53
|
+
console.log('Invalid form', errors)
|
|
54
|
+
return
|
|
55
|
+
}
|
|
57
56
|
}
|
|
58
57
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
58
|
+
let result = await onSubmit(form.value)
|
|
59
|
+
|
|
60
|
+
switch (result.status) {
|
|
61
|
+
case "created":
|
|
62
|
+
emit("created", result.item)
|
|
63
|
+
break
|
|
64
|
+
case "updated":
|
|
65
|
+
emit("updated", result.item)
|
|
66
|
+
break
|
|
67
|
+
case "deleted":
|
|
68
|
+
emit("deleted")
|
|
69
|
+
break
|
|
70
|
+
case "viewed":
|
|
71
|
+
emit("viewed")
|
|
72
|
+
break
|
|
65
73
|
}
|
|
74
|
+
|
|
66
75
|
}
|
|
67
76
|
|
|
68
77
|
function cancel() {
|
|
69
|
-
|
|
78
|
+
onCancel()
|
|
79
|
+
emit('canceled')
|
|
70
80
|
}
|
|
71
81
|
|
|
72
82
|
const {
|
|
73
83
|
variant, submitColor, readonly
|
|
74
|
-
} = useFormUtils(operation)
|
|
84
|
+
} = useFormUtils(operation.value)
|
|
75
85
|
|
|
76
86
|
|
|
77
87
|
</script>
|
|
@@ -80,13 +90,14 @@ const {
|
|
|
80
90
|
<v-form ref="formRef" @submit.prevent>
|
|
81
91
|
<v-card flat>
|
|
82
92
|
|
|
83
|
-
<v-card-subtitle v-if="getItemId(
|
|
93
|
+
<v-card-subtitle v-if="getItemId(form)">ID: {{ getItemId(form) }}</v-card-subtitle>
|
|
84
94
|
|
|
85
95
|
<v-card-text v-if="error">
|
|
86
96
|
<v-alert color="error">{{ te(error) ? t(error) : error }}</v-alert>
|
|
87
97
|
</v-card-text>
|
|
88
98
|
|
|
89
99
|
<v-card-text>
|
|
100
|
+
|
|
90
101
|
<v-row>
|
|
91
102
|
<v-col
|
|
92
103
|
v-for="field in aFields"
|
|
@@ -101,9 +112,9 @@ const {
|
|
|
101
112
|
<crud-form-field
|
|
102
113
|
:field="field"
|
|
103
114
|
:entity="entity"
|
|
104
|
-
v-model="
|
|
115
|
+
v-model="form[field.name]"
|
|
105
116
|
:clearable="false"
|
|
106
|
-
:readonly="
|
|
117
|
+
:readonly="['delete','view'].includes(operation) || field.readonly"
|
|
107
118
|
:variant="variant"
|
|
108
119
|
:prepend-inner-icon="field?.prependInnerIcon"
|
|
109
120
|
:prepend-icon="field?.prependIcon"
|
|
@@ -118,7 +129,9 @@ const {
|
|
|
118
129
|
|
|
119
130
|
<v-card-actions>
|
|
120
131
|
<v-spacer></v-spacer>
|
|
121
|
-
<v-btn variant="text" color="grey" @click="cancel">
|
|
132
|
+
<v-btn variant="text" color="grey" @click="cancel">
|
|
133
|
+
{{ operation == 'view' ? t('action.close') : t('action.cancel') }}
|
|
134
|
+
</v-btn>
|
|
122
135
|
<v-btn variant="flat" v-if="operation != 'view'" :color="submitColor" @click="submit" :loading="store.loading">
|
|
123
136
|
{{ operation ? t('action.' + operation) : t('action.sent') }}
|
|
124
137
|
</v-btn>
|
|
@@ -224,20 +224,20 @@ export function useCrud(entity: IEntityCrud) {
|
|
|
224
224
|
|
|
225
225
|
|
|
226
226
|
function onCreate() {
|
|
227
|
-
store.setOperation("create")
|
|
228
227
|
store.setForm(entity.form)
|
|
228
|
+
store.setOperation("create")
|
|
229
229
|
openDialog()
|
|
230
230
|
}
|
|
231
231
|
|
|
232
232
|
function onEdit(item: object) {
|
|
233
|
-
store.setOperation("edit")
|
|
234
233
|
store.setForm(cast({...item}))
|
|
234
|
+
store.setOperation("edit")
|
|
235
235
|
openDialog()
|
|
236
236
|
}
|
|
237
237
|
|
|
238
238
|
function onDelete(item: object) {
|
|
239
|
-
store.setOperation("delete")
|
|
240
239
|
store.setForm(cast({...item}))
|
|
240
|
+
store.setOperation("delete")
|
|
241
241
|
openDialog()
|
|
242
242
|
}
|
|
243
243
|
|