@drax/crud-vue 0.14.1 → 0.14.3
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 +3 -3
- package/src/components/Crud.vue +7 -24
- package/src/components/CrudForm.vue +38 -24
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.3",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "./src/index.ts",
|
|
9
9
|
"module": "./src/index.ts",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"@drax/common-front": "^0.14.0",
|
|
28
28
|
"@drax/crud-front": "^0.14.0",
|
|
29
29
|
"@drax/crud-share": "^0.14.0",
|
|
30
|
-
"@drax/media-vue": "^0.14.
|
|
30
|
+
"@drax/media-vue": "^0.14.2"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"pinia": "^2.2.2",
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"vue-tsc": "^2.1.10",
|
|
65
65
|
"vuetify": "^3.7.1"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "6638957752a86713df6545de62664b083393cc45"
|
|
68
68
|
}
|
package/src/components/Crud.vue
CHANGED
|
@@ -12,7 +12,7 @@ const {entity} = defineProps({
|
|
|
12
12
|
})
|
|
13
13
|
|
|
14
14
|
const {
|
|
15
|
-
onView, onCreate, onEdit, onDelete,
|
|
15
|
+
onView, onCreate, onEdit, onDelete, resetCrudStore,
|
|
16
16
|
operation, dialog, form, notify, error, message, doExport,
|
|
17
17
|
prepareFilters
|
|
18
18
|
} = useCrud(entity);
|
|
@@ -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
|
|
|
@@ -93,10 +74,12 @@ async function submit() {
|
|
|
93
74
|
v-model="form"
|
|
94
75
|
:entity="entity"
|
|
95
76
|
:error="error"
|
|
96
|
-
:operation="operation"
|
|
97
77
|
:readonly="operation === 'delete'"
|
|
98
|
-
@
|
|
99
|
-
@
|
|
78
|
+
@created="item => emit('created', item)"
|
|
79
|
+
@updated="item => emit('updated', item)"
|
|
80
|
+
@deleted="emit('deleted')"
|
|
81
|
+
@viewed="emit('viewed')"
|
|
82
|
+
@canceled="emit('canceled')"
|
|
100
83
|
>
|
|
101
84
|
|
|
102
85
|
<template v-for="ifield in entity.fields" :key="ifield.name" v-slot:[`field.${ifield.name}`]="{field}">
|
|
@@ -1,43 +1,41 @@
|
|
|
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
7
|
import {computed, defineEmits, defineModel, 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
|
-
|
|
17
16
|
const valueModel = defineModel({type: [Object]})
|
|
18
17
|
|
|
19
|
-
const {entity
|
|
18
|
+
const {entity} = defineProps({
|
|
20
19
|
entity: {type: Object as PropType<IEntityCrud>, required: true},
|
|
21
|
-
|
|
22
|
-
readonly: {type: Boolean, default: false},
|
|
23
|
-
error: {type: String, required: false},
|
|
20
|
+
readonly: {type: Boolean, default: false}
|
|
24
21
|
})
|
|
25
22
|
|
|
23
|
+
const {onSubmit, onCancel, operation, error} = useCrud(entity)
|
|
26
24
|
|
|
27
|
-
const emit = defineEmits(['
|
|
25
|
+
const emit = defineEmits(['created', 'updated', 'deleted', 'viewed', 'canceled'])
|
|
28
26
|
|
|
29
27
|
const store = useCrudStore()
|
|
30
28
|
|
|
31
29
|
const formRef = ref()
|
|
32
30
|
|
|
33
31
|
const fields = computed(() => {
|
|
34
|
-
if (operation === 'create') {
|
|
32
|
+
if (operation.value === 'create') {
|
|
35
33
|
return entity.createFields
|
|
36
|
-
} else if (operation === 'edit') {
|
|
34
|
+
} else if (operation.value === 'edit') {
|
|
37
35
|
return entity.updateFields
|
|
38
|
-
} else if (operation === 'delete') {
|
|
36
|
+
} else if (operation.value === 'delete') {
|
|
39
37
|
return entity.deleteFields
|
|
40
|
-
} else if (operation === 'view') {
|
|
38
|
+
} else if (operation.value === 'view') {
|
|
41
39
|
return entity.viewFields
|
|
42
40
|
}
|
|
43
41
|
return []
|
|
@@ -51,27 +49,41 @@ const aFields = computed(() => {
|
|
|
51
49
|
async function submit() {
|
|
52
50
|
store.resetErrors()
|
|
53
51
|
|
|
54
|
-
if (
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
if (['create', 'edit'].includes(operation.value)) {
|
|
53
|
+
const {valid, errors} = await formRef.value.validate()
|
|
54
|
+
if (!valid) {
|
|
55
|
+
console.log('Invalid form', errors)
|
|
56
|
+
return
|
|
57
|
+
}
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
let result = await onSubmit(valueModel.value)
|
|
61
|
+
|
|
62
|
+
switch (result.status) {
|
|
63
|
+
case "created":
|
|
64
|
+
emit("created", result.item)
|
|
65
|
+
break
|
|
66
|
+
case "updated":
|
|
67
|
+
emit("updated", result.item)
|
|
68
|
+
break
|
|
69
|
+
case "deleted":
|
|
70
|
+
emit("deleted")
|
|
71
|
+
break
|
|
72
|
+
case "viewed":
|
|
73
|
+
emit("viewed")
|
|
74
|
+
break
|
|
65
75
|
}
|
|
76
|
+
|
|
66
77
|
}
|
|
67
78
|
|
|
68
79
|
function cancel() {
|
|
69
|
-
|
|
80
|
+
onCancel()
|
|
81
|
+
emit('canceled')
|
|
70
82
|
}
|
|
71
83
|
|
|
72
84
|
const {
|
|
73
85
|
variant, submitColor, readonly
|
|
74
|
-
} = useFormUtils(operation)
|
|
86
|
+
} = useFormUtils(operation.value)
|
|
75
87
|
|
|
76
88
|
|
|
77
89
|
</script>
|
|
@@ -118,7 +130,9 @@ const {
|
|
|
118
130
|
|
|
119
131
|
<v-card-actions>
|
|
120
132
|
<v-spacer></v-spacer>
|
|
121
|
-
<v-btn variant="text" color="grey" @click="cancel">
|
|
133
|
+
<v-btn variant="text" color="grey" @click="cancel">
|
|
134
|
+
{{ operation == 'view' ? t('action.close') : t('action.cancel') }}
|
|
135
|
+
</v-btn>
|
|
122
136
|
<v-btn variant="flat" v-if="operation != 'view'" :color="submitColor" @click="submit" :loading="store.loading">
|
|
123
137
|
{{ operation ? t('action.' + operation) : t('action.sent') }}
|
|
124
138
|
</v-btn>
|