3a3ecabe
Imshann
init
|
1
2
3
4
5
6
|
import style from "antd/lib/input/style/index.css";
class Input {
useModules = ["$compile", "esNgAntd"];
|
d88eaac5
Imshann
优化
|
7
|
require = ["^?antdFormItem", "^?antdForm"];
|
3a3ecabe
Imshann
init
|
8
9
10
11
12
|
state = {
inputEventTarget: null,
}
|
d88eaac5
Imshann
优化
|
13
14
15
|
constructor($element, $attrs, $controllers) {
let [antdForm, antdFormItem] = $controllers;
|
3a3ecabe
Imshann
init
|
16
|
esNgAntd.createStyle("ant-input", style);
|
1b6f912f
Imshann
优化
|
17
|
|
e154891a
Imshann
优化Input组件
|
18
19
20
|
if (antdFormItem) {
this.antdFormItem = antdFormItem.getContext();
}
|
1b6f912f
Imshann
优化
|
21
|
// 上下文
|
81f8a467
Imshann
调整组件前缀
|
22
23
24
|
if (antdForm) {
this.antdForm = antdForm.getContext();
this.antdForm.state.formItems.push($scope);
|
1b6f912f
Imshann
优化
|
25
|
}
|
3a3ecabe
Imshann
init
|
26
|
this.props.style = $attrs.style;
|
3a3ecabe
Imshann
init
|
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
$element.replaceWith($compile(this.getTemplate())($scope));
}
handleClick(event) {
this.state.inputEventTarget = event;
}
handleChange() {
this.props.onChange({
event: this.state.inputEventTarget
});
}
getTemplate() {
let maxLengthAttribute = "";
let styleAttribute = "";
let idAttribute = "";
if (this.props.maxLength) {
maxLengthAttribute = `maxlength="${this.props.maxLength}"`;
}
if (this.props.style) {
styleAttribute = `style="${this.props.style}"`
}
|
81f8a467
Imshann
调整组件前缀
|
50
51
|
if (this.antdFormItem && this.antdFormItem.name) {
idAttribute = `id="${this.antdFormItem.name}"`;
|
3a3ecabe
Imshann
init
|
52
53
|
}
let templates = [
|
d88eaac5
Imshann
优化
|
54
|
`<input type="text" class="ant-input" placeholder={{placeholder}} ng-change="handleChange()" ng-model="value" ng-focus="handleClick($event)" ng-disabled="disabled===true" ${styleAttribute} ${maxLengthAttribute} ${idAttribute}/>`,
|
3a3ecabe
Imshann
init
|
55
56
57
|
`<span class="ant-input-group-wrapper" ng-if="addonBefore||addonAfter">
<span class="ant-input-wrapper ant-input-group" style="">
<span class="ant-input-group-addon" ng-if="addonBefore">{{addonBefore}}</span>
|
d88eaac5
Imshann
优化
|
58
|
<input type="text" class="ant-input" ng-change="handleChange()" ng-model="value" ng-focus="handleClick($event)" ng-disabled="disabled===true" style="${this.props.style}" ${styleAttribute} ${maxLengthAttribute} ${idAttribute}/>
|
3a3ecabe
Imshann
init
|
59
60
61
62
63
64
65
66
67
68
69
|
<span class="ant-input-group-addon" ng-if="addonAfter">{{addonAfter}}</span>
</span>
</span>`,
];
if (this.props.addonBefore || this.props.addonAfter) {
return templates[1]
} else {
return templates[0];
}
}
}
|
d88eaac5
Imshann
优化
|
70
71
72
73
74
75
76
77
78
79
|
Input.propTypes = {
value: PropTypes.string,
placeholder: PropTypes.string,
addonBefore: PropTypes.string,
addonAfter: PropTypes.string,
disabled: PropTypes.boolean,
onChange: PropTypes.function,
maxLength: PropTypes.number,
};
|