3a3ecabe
Imshann
init
|
1
|
import style from "antd/lib/checkbox/style/index.css";
|
b9305a60
Imshann
优化checkbox组件
|
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
import template from "./Checkbox.html";
angular.module("esNgAntd").directive("antdCheckbox", ["esNgAntd", function (esNgAntd) {
return {
template: template,
restrict: "E",
replace: true,
transclude: true,
scope: {
defaultChecked: "=",
checked: "@",
disabled: "@",
onChange: "&"
},
require: ["^?antdForm", "^?antdFormItem"],
controller: function ($scope, $element) {
$scope.watch = {
checked: function (newVal) {
if (newVal !== undefined) {
$scope.state.checked = ["true", "checked", true].includes(newVal) ? true : false;
}
|
3a3ecabe
Imshann
init
|
22
|
},
|
b9305a60
Imshann
优化checkbox组件
|
23
24
25
26
27
28
29
30
31
32
33
|
disabled: function (newVal) {
if (newVal !== undefined) {
$scope.state.disabled = ["true", "disabled", true].includes(newVal) ? true : false;
}
}
};
$scope.state = {
checked: $scope.checked || $scope.defaultChecked || false,
disabled: false,
type: "checkbox"
};
|
3a3ecabe
Imshann
init
|
34
|
|
b9305a60
Imshann
优化checkbox组件
|
35
36
37
38
|
$scope.handleClick = function ($event) {
if ($scope.state.disabled) {
return;
}
|
3a3ecabe
Imshann
init
|
39
|
|
b9305a60
Imshann
优化checkbox组件
|
40
41
42
43
44
|
$scope.state.checked = !$scope.state.checked;
$scope.onChange({
event: $event
});
};
|
3a3ecabe
Imshann
init
|
45
|
|
b9305a60
Imshann
优化checkbox组件
|
46
47
48
49
50
51
52
53
54
55
56
57
|
$scope.setValue = function (value) {
if (value) {
$scope.state.checked = value;
} else {
$scope.state.checked = false;
}
};
},
link: function ($scope, $element, $attrs, $controllers) {
for (const key in $scope.watch) {
$scope.$watch(key, $scope.watch[key], true);
}
|
fe17acf4
Imshann
优化组件
|
58
|
|
b9305a60
Imshann
优化checkbox组件
|
59
60
|
let [antdForm, antdFormItem] = $controllers;
esNgAntd.createStyle("ant-checkbox", style); // 上下文
|
fe17acf4
Imshann
优化组件
|
61
|
|
b9305a60
Imshann
优化checkbox组件
|
62
63
64
65
|
if (antdForm) {
$scope.antdForm = antdForm.getContext();
$scope.antdForm.state.formItems.push($scope);
}
|
fe17acf4
Imshann
优化组件
|
66
|
|
b9305a60
Imshann
优化checkbox组件
|
67
68
69
70
71
72
|
if (antdFormItem) {
$scope.antdFormItem = antdFormItem.getContext();
}
}
};
}]);
|