3a3ecabe
Imshann
init
|
1
2
3
4
5
6
|
import template from "./Form.html";
import style from "antd/lib/form/style/index.css";
class Form {
useModules = ["esNgAntd"];
|
dd962f77
Imshann
优化
|
7
8
|
template = template;
|
3a3ecabe
Imshann
init
|
9
10
11
12
13
|
props = {
name: String,
labelCol: Object,
wrapperCol: Object,
onFinish: Function,
|
dd962f77
Imshann
优化
|
14
15
16
17
|
form: Object,
};
state = {
|
a468667f
Imshann
优化
|
18
|
formItems: [],
|
3a3ecabe
Imshann
init
|
19
|
};
|
3a3ecabe
Imshann
init
|
20
21
22
|
constructor() {
esNgAntd.createStyle("ant-form", style);
|
2c0a9da3
Imshann
优化
|
23
|
|
3a3ecabe
Imshann
init
|
24
25
26
27
28
29
30
31
32
|
if (this.props.name) {
let inputs = $element[0].querySelectorAll("input");
for (let i = 0; i < inputs.length; i++) {
const element = inputs[i];
element.id = this.props.name + "_" + element.id;
}
}
}
|
dd962f77
Imshann
优化
|
33
34
|
resetFields() {
this.state.formItems.forEach(function (item) {
|
a468667f
Imshann
优化
|
35
36
37
38
39
40
|
if (typeof item.setValue === "function") {
item.setValue(item.defaultValue || null);
} else {
item.value = null;
}
});
|
dd962f77
Imshann
优化
|
41
42
|
}
|
061629e7
Imshann
add
|
43
44
45
46
|
submit() {
this.handleSubmit();
}
|
3a3ecabe
Imshann
init
|
47
48
|
handleSubmit() {
let values = {};
|
dd962f77
Imshann
优化
|
49
50
51
52
|
this.state.formItems.forEach(function (item) {
let name = item.esFormItem && item.esFormItem.name;
let value = item.value || item.state.value || null;
values[name] = value;
|
a468667f
Imshann
优化
|
53
|
});
|
3a3ecabe
Imshann
init
|
54
55
56
57
58
|
this.props.onFinish({
values: values,
});
}
}
|