haiwei-ui 1.3.6 → 1.3.7
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.
- package/package.json +1 -1
- package/packages/components/form/index.vue +130 -123
package/package.json
CHANGED
|
@@ -1,138 +1,145 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<el-form class="nm-form" ref="form" :model="model" :rules="rules" :label-width="labelWidth"
|
|
2
|
+
<el-form class="nm-form" ref="form" :model="model" :rules="rules" :label-width="labelWidth"
|
|
3
|
+
:label-position="labelPosition" :size="fontSize" :inline="inline" :disabled="disabled" v-loading="showLoading"
|
|
4
|
+
:element-loading-text="loadingText" :element-loading-background="loadingBackground"
|
|
5
|
+
:element-loading-spinner="loadingSpinner" @validate="onValidate">
|
|
3
6
|
<slot />
|
|
4
7
|
</el-form>
|
|
5
8
|
</template>
|
|
6
9
|
<script>
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
import loading from '../../mixins/components/loading'
|
|
11
|
+
export default {
|
|
12
|
+
name: 'Form',
|
|
13
|
+
mixins: [loading],
|
|
14
|
+
data() {
|
|
15
|
+
return {
|
|
16
|
+
loading_: false
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
props: {
|
|
20
|
+
/** 表单对象 */
|
|
21
|
+
model: {
|
|
22
|
+
type: Object,
|
|
23
|
+
required: true
|
|
15
24
|
},
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
/** 行内表单模式 */
|
|
27
|
-
inline: Boolean,
|
|
28
|
-
/** 是否显示成功提示消息 */
|
|
29
|
-
successMsg: {
|
|
30
|
-
type: Boolean,
|
|
31
|
-
default: true
|
|
32
|
-
},
|
|
33
|
-
/** 成功提示消息文本 */
|
|
34
|
-
successMsgText: {
|
|
35
|
-
type: String,
|
|
36
|
-
default: '保存成功'
|
|
37
|
-
},
|
|
38
|
-
/** 标签的宽度 */
|
|
39
|
-
labelWidth: {
|
|
40
|
-
type: String,
|
|
41
|
-
default: '100px'
|
|
42
|
-
},
|
|
43
|
-
/** 表单域标签的位置,如果值为 left 或者 right 时,则需要设置 label-width */
|
|
44
|
-
labelPosition: {
|
|
45
|
-
type: String,
|
|
46
|
-
default: 'right'
|
|
47
|
-
},
|
|
48
|
-
// 自定义验证
|
|
49
|
-
customValidate: Function,
|
|
50
|
-
/** 禁用表单 */
|
|
51
|
-
disabled: Boolean,
|
|
52
|
-
/** 显示加载动画 */
|
|
53
|
-
loading: Boolean,
|
|
54
|
-
/** 不显示加载动画 */
|
|
55
|
-
noLoading: Boolean,
|
|
56
|
-
/** 自定义重置操作 */
|
|
57
|
-
customResetFunction: Function
|
|
25
|
+
/** 验证规则 */
|
|
26
|
+
rules: Object,
|
|
27
|
+
/** 提交请求 */
|
|
28
|
+
action: Function,
|
|
29
|
+
/** 行内表单模式 */
|
|
30
|
+
inline: Boolean,
|
|
31
|
+
/** 是否显示成功提示消息 */
|
|
32
|
+
successMsg: {
|
|
33
|
+
type: Boolean,
|
|
34
|
+
default: true
|
|
58
35
|
},
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
36
|
+
/** 成功提示消息文本 */
|
|
37
|
+
successMsgText: {
|
|
38
|
+
type: String,
|
|
39
|
+
default: '保存成功'
|
|
63
40
|
},
|
|
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
|
-
this.$emit('reset')
|
|
105
|
-
},
|
|
106
|
-
/** 重置子组件 */
|
|
107
|
-
resetChildren(vnode) {
|
|
108
|
-
if (vnode.$children && vnode.$children.length > 0) {
|
|
109
|
-
vnode.$children.forEach(item => {
|
|
110
|
-
if (item && item.reset && typeof item.reset === 'function') {
|
|
111
|
-
item.reset()
|
|
41
|
+
/** 标签的宽度 */
|
|
42
|
+
labelWidth: {
|
|
43
|
+
type: String,
|
|
44
|
+
default: '100px'
|
|
45
|
+
},
|
|
46
|
+
/** 表单域标签的位置,如果值为 left 或者 right 时,则需要设置 label-width */
|
|
47
|
+
labelPosition: {
|
|
48
|
+
type: String,
|
|
49
|
+
default: 'right'
|
|
50
|
+
},
|
|
51
|
+
// 自定义验证
|
|
52
|
+
customValidate: Function,
|
|
53
|
+
/** 禁用表单 */
|
|
54
|
+
disabled: Boolean,
|
|
55
|
+
/** 显示加载动画 */
|
|
56
|
+
loading: Boolean,
|
|
57
|
+
/** 不显示加载动画 */
|
|
58
|
+
noLoading: Boolean,
|
|
59
|
+
/** 自定义重置操作 */
|
|
60
|
+
customResetFunction: Function
|
|
61
|
+
},
|
|
62
|
+
computed: {
|
|
63
|
+
showLoading() {
|
|
64
|
+
return !this.noLoading && (this.loading_ || this.loading)
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
methods: {
|
|
68
|
+
/** 提交 */
|
|
69
|
+
submit() {
|
|
70
|
+
this.validate(() => {
|
|
71
|
+
this.openLoading()
|
|
72
|
+
console.log('this.model======>', this.model);
|
|
73
|
+
// 使用深拷贝确保获取最新数据
|
|
74
|
+
const formData = JSON.parse(JSON.stringify(this.model))
|
|
75
|
+
console.log('this.model======>formData', formData);
|
|
76
|
+
this.action(this.model)
|
|
77
|
+
.then(data => {
|
|
78
|
+
if (this.successMsg === true) {
|
|
79
|
+
this._success(this.successMsgText)
|
|
112
80
|
}
|
|
113
|
-
this
|
|
81
|
+
this.$emit('success', data)
|
|
114
82
|
})
|
|
83
|
+
.catch(() => {
|
|
84
|
+
this.$emit('error')
|
|
85
|
+
})
|
|
86
|
+
.finally(() => {
|
|
87
|
+
this.closeLoading()
|
|
88
|
+
})
|
|
89
|
+
})
|
|
90
|
+
},
|
|
91
|
+
/** 表单验证 */
|
|
92
|
+
validate(callback) {
|
|
93
|
+
this.$refs.form.validate(async valid => {
|
|
94
|
+
// 自定义验证
|
|
95
|
+
if (valid && (!this.customValidate || this.customValidate() === true)) {
|
|
96
|
+
callback()
|
|
97
|
+
} else {
|
|
98
|
+
// 验证失败
|
|
99
|
+
this.$emit('validate-error')
|
|
115
100
|
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
101
|
+
})
|
|
102
|
+
},
|
|
103
|
+
/** 重置 */
|
|
104
|
+
reset() {
|
|
105
|
+
if (this.customResetFunction) {
|
|
106
|
+
this.customResetFunction()
|
|
107
|
+
} else {
|
|
108
|
+
this.$refs.form.resetFields()
|
|
109
|
+
this.resetChildren(this.$refs.form)
|
|
110
|
+
}
|
|
111
|
+
this.$emit('reset')
|
|
112
|
+
},
|
|
113
|
+
/** 重置子组件 */
|
|
114
|
+
resetChildren(vnode) {
|
|
115
|
+
if (vnode.$children && vnode.$children.length > 0) {
|
|
116
|
+
vnode.$children.forEach(item => {
|
|
117
|
+
if (item && item.reset && typeof item.reset === 'function') {
|
|
118
|
+
item.reset()
|
|
119
|
+
}
|
|
120
|
+
this.resetChildren(item)
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
/** 清除验证结果 */
|
|
125
|
+
clearValidate(props) {
|
|
126
|
+
this.$refs.form.clearValidate(props)
|
|
127
|
+
},
|
|
128
|
+
/** 打开加载中 */
|
|
129
|
+
openLoading() {
|
|
130
|
+
if (!this.noLoading) {
|
|
131
|
+
this.loading_ = true
|
|
135
132
|
}
|
|
133
|
+
},
|
|
134
|
+
/** 关闭加载中 */
|
|
135
|
+
closeLoading() {
|
|
136
|
+
if (!this.noLoading) {
|
|
137
|
+
this.loading_ = false
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
onValidate(prop, valid, msg) {
|
|
141
|
+
this.$emit('validate', prop, valid, msg)
|
|
136
142
|
}
|
|
137
143
|
}
|
|
144
|
+
}
|
|
138
145
|
</script>
|