forked from N3-components/N3-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
n3Form.vue
95 lines (81 loc) · 1.71 KB
/
n3Form.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
<template>
<form :class="classObj" @submit.prevent="noop">
<slot></slot>
</form>
</template>
<script>
export default {
props: {
type: {
type: String,
default: 'horizontal'
},
validate: {
type: Boolean,
default: false
},
result: {
type: Object,
twoWay: true
},
prefixCls: {
type: String,
default: 'n3'
}
},
methods: {
noop () {
}
},
watch: {
validate (val) {
this.$broadcast('n3@openValidate', val)
if (val) {
this.result = this._result
} else {
this.result = {results: {}, isvaild: true}
}
}
},
ready () {
if (!this.validate) {
this.result = {results: {}, isvaild: true}
}
this.$broadcast('n3@openValidate', this.validate)
},
computed: {
classObj () {
let {prefixCls, type} = this
let klass = {}
klass[prefixCls + '-form-horizontal'] = type === 'horizontal'
klass[prefixCls + '-form-inline'] = type === 'inline'
klass['clearfix'] = true
return klass
}
},
events: {
'n3@validateChange' (val) {
let name = val.name
let validateResult = Object.assign({}, this._result)
if (!validateResult.results)validateResult.results = {}
validateResult.results[name] = val.result
validateResult.isvalid = true
for (let i in validateResult.results) {
if (!validateResult.results[i]['isvalid']) {
validateResult.isvalid = false
break
}
}
this._result = validateResult
if (this.validate) {
this.result = this._result
}
}
},
data () {
return {
_result: {results: {}, isvaild: true}
}
}
}
</script>