mali-applet-ui 0.0.100 → 0.1.0
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.
|
@@ -26,7 +26,6 @@ export default {
|
|
|
26
26
|
name: 'MlForm',
|
|
27
27
|
props: {
|
|
28
28
|
value: Object,
|
|
29
|
-
data: Object,
|
|
30
29
|
items: Array,
|
|
31
30
|
rules: Object,
|
|
32
31
|
align: String,
|
|
@@ -49,14 +48,58 @@ export default {
|
|
|
49
48
|
},
|
|
50
49
|
methods: {
|
|
51
50
|
validate () {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
let errMaps = null
|
|
52
|
+
for (let i = 0; i < this.itemList.length; i++) {
|
|
53
|
+
const item = this.itemList[i]
|
|
54
|
+
const errRule = this.validRule(item)
|
|
55
|
+
if (errRule) {
|
|
56
|
+
if (!errMaps) {
|
|
57
|
+
errMaps = {}
|
|
58
|
+
}
|
|
59
|
+
errMaps[item.field] = errRule
|
|
60
|
+
item.errRule = { field: item.field, message: errRule.message }
|
|
61
|
+
} else {
|
|
62
|
+
item.errRule = null
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return errMaps ? Promise.resolve(errMaps) : Promise.resolve()
|
|
55
66
|
},
|
|
56
|
-
validateField (
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
67
|
+
validateField (field) {
|
|
68
|
+
let errMaps = null
|
|
69
|
+
if (field) {
|
|
70
|
+
const item = this.itemList.find(item => item.field === field)
|
|
71
|
+
if (item) {
|
|
72
|
+
const errRule = this.validRule(item)
|
|
73
|
+
if (errRule) {
|
|
74
|
+
errMaps = { [field]: errRule }
|
|
75
|
+
item.errRule = { field, message: errRule.message }
|
|
76
|
+
} else {
|
|
77
|
+
item.errRule = null
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return errMaps ? Promise.resolve(errMaps) : Promise.resolve()
|
|
82
|
+
},
|
|
83
|
+
validRule (item) {
|
|
84
|
+
const rules = item && this.rules ? this.rules[item.field] : null
|
|
85
|
+
const itemValue = item && this.value ? this.value[item.field] : null
|
|
86
|
+
let errRule = null
|
|
87
|
+
if (rules) {
|
|
88
|
+
for (let i = 0; i < rules.length; i++) {
|
|
89
|
+
const rule = rules[i]
|
|
90
|
+
if (rule.required) {
|
|
91
|
+
if (!itemValue) {
|
|
92
|
+
errRule = rule
|
|
93
|
+
break
|
|
94
|
+
}
|
|
95
|
+
if (rule.type === 'array' && !itemValue.length) {
|
|
96
|
+
errRule = rule
|
|
97
|
+
break
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return errRule
|
|
60
103
|
},
|
|
61
104
|
updateModel ({ field, value }) {
|
|
62
105
|
this.$emit('input', { ...this.value, [field]: value })
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<view class="ml-form-item" :class="[className
|
|
2
|
+
<view class="ml-form-item" :class="[className || '', itemTitleAlign ? `title-align-${itemTitleAlign}` : '', itemAlign ? `align-${itemAlign}` : '', {'is-border': isFormBorder, 'is-vertical': itemVertical, 'is-required': isRequired, 'is-error': itemErrRule}]">
|
|
3
3
|
<view class="ml-form-item-header" :style="titleStyle">
|
|
4
4
|
<view v-if="isRequired" class="ml-form-item-header-asterisk">*</view>
|
|
5
5
|
<view class="ml-form-item-header-title">
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
<text v-else class="ml-form-item-default-content">{{ itemValue }}</text>
|
|
20
20
|
</slot>
|
|
21
21
|
</view>
|
|
22
|
+
<view class="ml-form-item-content-error">{{ itemErrRule.message }}</view>
|
|
22
23
|
</view>
|
|
23
24
|
</view>
|
|
24
25
|
</template>
|
|
@@ -47,18 +48,31 @@ export default {
|
|
|
47
48
|
default: null
|
|
48
49
|
}
|
|
49
50
|
},
|
|
51
|
+
provide() {
|
|
52
|
+
return {
|
|
53
|
+
mlFormItem: this
|
|
54
|
+
}
|
|
55
|
+
},
|
|
50
56
|
data () {
|
|
51
57
|
return {
|
|
52
58
|
mId: XEUtils.uniqueId('mlFItem')
|
|
53
59
|
}
|
|
54
60
|
},
|
|
61
|
+
watch: {
|
|
62
|
+
itemValue () {
|
|
63
|
+
if (this.form) {
|
|
64
|
+
this.form.validateField(this.field)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
},
|
|
55
68
|
mounted () {
|
|
56
69
|
this.$nextTick(() => {
|
|
57
70
|
if (this.form) {
|
|
58
71
|
this.form.itemList.push({
|
|
59
72
|
mId: this.mId,
|
|
60
73
|
title: this.title,
|
|
61
|
-
field: this.field
|
|
74
|
+
field: this.field,
|
|
75
|
+
errRule: null
|
|
62
76
|
})
|
|
63
77
|
}
|
|
64
78
|
})
|
|
@@ -84,6 +98,13 @@ export default {
|
|
|
84
98
|
}
|
|
85
99
|
return false
|
|
86
100
|
},
|
|
101
|
+
itemErrRule () {
|
|
102
|
+
if (this.form) {
|
|
103
|
+
const item = this.form.itemList.find(item => item.mId === this.mId)
|
|
104
|
+
return item ? item.errRule : null
|
|
105
|
+
}
|
|
106
|
+
return null
|
|
107
|
+
},
|
|
87
108
|
itemValue () {
|
|
88
109
|
const value = this.formData[this.field]
|
|
89
110
|
return XEUtils.eqNull(value) ? '' : value
|
|
@@ -147,6 +168,12 @@ export default {
|
|
|
147
168
|
border: 0;
|
|
148
169
|
}
|
|
149
170
|
}
|
|
171
|
+
&.is-error {
|
|
172
|
+
.ml-form-item-content-error {
|
|
173
|
+
opacity: 1;
|
|
174
|
+
transform: scaleY(1);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
150
177
|
.ml-form-item-header {
|
|
151
178
|
min-height: 70rpx;
|
|
152
179
|
color: rgba(0, 0, 0, 0.65);
|
|
@@ -204,8 +231,10 @@ export default {
|
|
|
204
231
|
}
|
|
205
232
|
}
|
|
206
233
|
.ml-form-item-content {
|
|
234
|
+
position: relative;
|
|
207
235
|
display: flex;
|
|
208
236
|
align-items: center;
|
|
237
|
+
flex-direction: column;
|
|
209
238
|
flex-grow: 1;
|
|
210
239
|
}
|
|
211
240
|
.ml-form-item-content-warpper {
|
|
@@ -213,4 +242,17 @@ export default {
|
|
|
213
242
|
width: 100%;
|
|
214
243
|
padding: 10rpx 0;
|
|
215
244
|
}
|
|
245
|
+
.ml-form-item-content-error {
|
|
246
|
+
position: absolute;
|
|
247
|
+
left: 0;
|
|
248
|
+
bottom: -20rpx;
|
|
249
|
+
width: 100%;
|
|
250
|
+
color: $uni-color-error;
|
|
251
|
+
font-size: 24rpx;
|
|
252
|
+
text-align: left;
|
|
253
|
+
opacity: 0;
|
|
254
|
+
transform-origin: center top;
|
|
255
|
+
transform: scaleY(0);
|
|
256
|
+
transition: all 0.3s;
|
|
257
|
+
}
|
|
216
258
|
</style>
|