index.vue
2.48 KB
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
<template >
<div class="NCC-common-layout">
<div class="NCC-preview-main">
<div class="NCC-common-page-header">
<p>{{config.fullName}}</p>
<div class="options">
<el-button type="primary" @click="dataFormSubmit()" :loading="btnLoading">
{{formConf.confirmButtonText||'确 定'}}</el-button>
<el-button type="warning" @click="resetForm()">重置</el-button>
</div>
</div>
<div class="dynamic-form-main" :style="{margin: '0 auto',width:formConf.fullScreenWidth}">
<parser :form-conf="formConf" @submit="sumbitForm" :key="key" ref="dynamicForm"
:setFormData="setFormData" :setShowOrHide="setShowOrHide" :setRequired="setRequired"
:setDisabled="setDisabled" :setFieldOptions="setFieldOptions" v-if="!loading" />
</div>
</div>
</div>
</template>
<script>
import { createModel } from '@/api/onlineDev/visualDev'
import Parser from '@/components/Generator/parser/Parser'
import ParserMixin from '@/components/Generator/parser/mixin'
export default {
components: { Parser },
mixins: [ParserMixin],
props: ['config', 'modelId', 'isPreview'],
data() {
return {
visible: false,
dataForm: {
data: ''
},
btnLoading: false,
loading: true,
}
},
created() {
this.init()
},
methods: {
init() {
this.formConf = JSON.parse(this.config.formData)
this.loading = true
this.$nextTick(() => {
this.visible = true
this.loading = false
this.key = +new Date()
})
},
sumbitForm(data, callback) {
if (!data) return
this.btnLoading = true
this.dataForm.data = JSON.stringify(data)
createModel(this.modelId, this.dataForm).then(res => {
this.$message({
message: res.msg,
type: 'success',
duration: 1500,
onClose: () => {
if (callback && typeof callback === "function") callback()
this.btnLoading = false
this.resetForm()
}
})
}).catch(() => { this.btnLoading = false })
},
dataFormSubmit() {
if (this.isPreview) return this.$message({ message: '功能预览不支持数据保存', type: 'warning' })
this.$refs.dynamicForm && this.$refs.dynamicForm.submitForm()
},
resetForm() {
this.formConf = JSON.parse(this.config.formData)
this.$nextTick(() => {
this.$refs.dynamicForm && this.$refs.dynamicForm.resetForm()
})
}
}
}
</script>