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
106
107
108
109
110
111
112
113
114
115
<template>
<div>
<dee-form
ref="searchForm"
:form="form"
:form-data="showFormData"
:rules="configData.rules"
:form-buttons="formButtons"
form-btn-position="center"
:label-width="labelWidth"
@on-submit="searchFun"
@on-reset="resetFun"
/>
</div>
</template>
<script>
import { getLayouts } from '@/api/config'
export default {
name: 'DeeFormCmp',
props: {
typeName: {
type: String,
default: ''
},
typeKey: {
type: String,
default: 'search'
},
labelWidth: {
type: String,
default: '100px'
},
basicData: {
type: Object,
default: () => {
return {}
}
}
},
data() {
return {
configData: {},
form: {},
formButtons: [{
'text': '查询',
'type': 'submit',
'component': {
'type': 'primary',
'size': 'small'
}
},
{
'text': '重置',
'type': 'reset',
'component': {
'size': 'small'
}
}]
}
},
computed: {
showFormData() {
return this.getFormData(this.configData)
}
},
watch: {
typeName: {
immediate: true,
handler: function(val) {
this.getlayout()
}
},
typeKey: {
immediate: true,
handler: function(val) {
this.getlayout()
}
}
},
created() {
this.getlayout()
},
methods: {
async getlayout() {
if (!this.typeName || !this.typeKey) {
return
}
await getLayouts(this.typeName, this.typeKey).then((res) => {
if (res.items) {
const x = res.items.slice(-1)
if (x[0] && x[0].configDetails) {
const configData = JSON.parse(x[0].configDetails)
this.configData = configData
}
}
})
},
getFormData(configData) {
if (!configData || !configData.formData) {
return []
}
return configData.formData
},
searchFun() {
this.$emit('searchFun', this.form)
},
resetFun() {
this.$refs['searchForm'].reset()
}
}
}
</script>
<style lang="scss">
</style>