-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathMetaComponentCreate.vue
105 lines (101 loc) · 2.45 KB
/
MetaComponentCreate.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<template>
<div>
<Editors
v-if="record"
ref="editors"
:fields="fields"
:editable-fields="editableFields"
:record="record"
mode="create"
v-bind="$attrs"
/>
<div>
<el-button
v-bind="cancelBtnConfig"
@click="doCancel"
>
{{ cancelBtnConfig.text }}
</el-button>
<el-button
v-bind="confirmBtnConfig"
@click="handleConfirmClick"
>
{{ confirmBtnConfig.text }}
</el-button>
</div>
</div>
</template>
<script>
import Editors from './Editors/Editors';
import {
logError,
} from '@/widget/utility';
import _createMixin from './CollectionOperators/_createMixin';
export default {
name: 'MetaComponentCreate',
components: {
Editors,
},
mixins: [
_createMixin,
],
props: {
handleCancel: {
type: Function,
default () {
this.$router.back();
},
},
handleCreateSuccess: {
type: Function,
default () {
this.$router.back();
},
},
cancelBtnConfig: {
type: Object,
default () {
return {
text: '取消',
};
},
},
confirmBtnConfig: {
type: Object,
default () {
return {
type: 'primary',
text: '确认',
};
},
},
},
created () {
this.getCreateFields().then((editableFields) => {
this.editableFields = editableFields;
this.resetRecord();
});
},
methods: {
doCancel () {
this.handleCancel();
},
handleConfirmClick () {
this.$refs.editors.validate()
.then(this.handleConfirm)
.catch(logError);
},
handleConfirm (data) {
if (this.isCreating) {
return;
}
this.isCreating = true;
this.doCreateRequest(this.transformData(data)).then(() => {
this.handleCreateSuccess();
}).catch(logError).finally(() => {
this.isCreating = false;
});
},
},
};
</script>