Commit 033b7802fc2bc46eb747a1b4fde2532fd4bf7d7b
1 parent
caa6e645
升级spin组件
Showing
6 changed files
with
67 additions
and
47 deletions
Show diff stats
build/Spin/Spin.html
1 | <div> | 1 | <div> |
2 | <div ng-if="state.hasChildren" class="ant-spin-nested-loading"> | 2 | <div ng-if="state.hasChildren" class="ant-spin-nested-loading"> |
3 | - <div ng-if="spinning==='true'"> | 3 | + <div ng-if="spinning===true"> |
4 | <div ng-class="state.className"> | 4 | <div ng-class="state.className"> |
5 | <span class="ant-spin-dot ant-spin-dot-spin"> | 5 | <span class="ant-spin-dot ant-spin-dot-spin"> |
6 | <i class="ant-spin-dot-item"></i> | 6 | <i class="ant-spin-dot-item"></i> |
@@ -10,7 +10,7 @@ | @@ -10,7 +10,7 @@ | ||
10 | </span> | 10 | </span> |
11 | </div> | 11 | </div> |
12 | </div> | 12 | </div> |
13 | - <div ng-class="'ant-spin-container'+(spinning==='true'?' ant-spin-blur':'')" ng-transclude></div> | 13 | + <div ng-class="'ant-spin-container'+(spinning===true?' ant-spin-blur':'')" ng-transclude></div> |
14 | </div> | 14 | </div> |
15 | <div ng-if="!state.hasChildren" ng-class="state.className"> | 15 | <div ng-if="!state.hasChildren" ng-class="state.className"> |
16 | <span class="ant-spin-dot ant-spin-dot-spin"> | 16 | <span class="ant-spin-dot ant-spin-dot-spin"> |
build/Spin/Spin.js
1 | import template from "./Spin.html"; | 1 | import template from "./Spin.html"; |
2 | angular.module("esNgAntd").directive("antdSpin", function () { | 2 | angular.module("esNgAntd").directive("antdSpin", function () { |
3 | - return { | ||
4 | - controllerAs: "antdSpin", | ||
5 | - restrict: "E", | ||
6 | - transclude: true, | ||
7 | - replace: true, | ||
8 | - scope: { | ||
9 | - size: "@", | ||
10 | - spinning: "@", | ||
11 | - }, | ||
12 | - template: template, | ||
13 | - controller: function ($scope, $element, $attrs) { | ||
14 | - this.getContext = function () { | ||
15 | - return $scope; | ||
16 | - }; | 3 | + return { |
4 | + template: template, | ||
5 | + restrict: "E", | ||
6 | + replace: true, | ||
7 | + transclude: true, | ||
8 | + scope: { | ||
9 | + size: "@", | ||
10 | + spinning: "=" | ||
11 | + }, | ||
12 | + controller: function ($scope, $element, $attrs) { | ||
13 | + $scope.state = { | ||
14 | + className: [], | ||
15 | + hasChildren: false | ||
16 | + }; | ||
17 | + }, | ||
18 | + link: function ($scope, $element, $attrs, $controllers, $transclude) { | ||
19 | + [$element, $attrs, $controllers, $transclude].forEach(function (value, key) { | ||
20 | + if ([undefined, null, ""].includes(value)) { | ||
21 | + throw new Error(`${["$element", "$attrs", "$controllers", "$transclude"][key]} parameter of constructor method is required.`); | ||
22 | + } | ||
23 | + }); | ||
24 | + $scope.state.className = ["ant-spin", "ant-spin-spinning"]; | ||
17 | 25 | ||
18 | - $scope.state = { | ||
19 | - className: [], | ||
20 | - hasChildren: false, | ||
21 | - }; | ||
22 | - }, | ||
23 | - link: function ($scope, $element, $attrs, $controllers, $transclude) { | ||
24 | - $scope.state.className = ["ant-spin", "ant-spin-spinning"]; | ||
25 | - $scope.state.hasChildren = JSON.stringify($transclude()) !== "{}"; | 26 | + if ($transclude()) { |
27 | + let len = $transclude().lenght; | ||
26 | 28 | ||
27 | - if ($scope.size === "small") { | ||
28 | - $scope.state.className.splice(1, 0, "ant-spin-sm"); | ||
29 | - } | 29 | + if (len > 0) { |
30 | + $scope.state.hasChildren = true; | ||
31 | + } | ||
32 | + } | ||
30 | 33 | ||
31 | - if ($scope.size === "large") { | ||
32 | - $scope.state.className.splice(1, 0, "ant-spin-lg"); | ||
33 | - } | ||
34 | - }, | ||
35 | - }; | ||
36 | -}); | 34 | + if ($scope.size === "small") { |
35 | + $scope.state.className.splice(1, 0, "ant-spin-sm"); | ||
36 | + } | ||
37 | + | ||
38 | + if ($scope.size === "large") { | ||
39 | + $scope.state.className.splice(1, 0, "ant-spin-lg"); | ||
40 | + } | ||
41 | + } | ||
42 | + }; | ||
43 | +}); | ||
37 | \ No newline at end of file | 44 | \ No newline at end of file |
src/Spin/Spin.html
1 | <div> | 1 | <div> |
2 | {state.hasChildren && <div className="ant-spin-nested-loading"> | 2 | {state.hasChildren && <div className="ant-spin-nested-loading"> |
3 | - {spinning === 'true' && <div> | 3 | + {spinning === true && <div> |
4 | <div className={state.className}> | 4 | <div className={state.className}> |
5 | <span className="ant-spin-dot ant-spin-dot-spin"> | 5 | <span className="ant-spin-dot ant-spin-dot-spin"> |
6 | <i className="ant-spin-dot-item"></i> | 6 | <i className="ant-spin-dot-item"></i> |
@@ -10,7 +10,7 @@ | @@ -10,7 +10,7 @@ | ||
10 | </span> | 10 | </span> |
11 | </div> | 11 | </div> |
12 | </div>} | 12 | </div>} |
13 | - <div className={"ant-spin-container"+(spinning==="true"?" ant-spin-blur":"")}>{children}</div> | 13 | + <div className={"ant-spin-container"+(spinning===true?" ant-spin-blur":"")}>{children}</div> |
14 | </div>} | 14 | </div>} |
15 | {!state.hasChildren && <div className={state.className}> | 15 | {!state.hasChildren && <div className={state.className}> |
16 | <span className="ant-spin-dot ant-spin-dot-spin"> | 16 | <span className="ant-spin-dot ant-spin-dot-spin"> |
src/Spin/Spin.js
1 | import template from "./Spin.html"; | 1 | import template from "./Spin.html"; |
2 | 2 | ||
3 | class Spin { | 3 | class Spin { |
4 | - props = { | ||
5 | - size: String, | ||
6 | - spinning: Boolean | ||
7 | - }; | ||
8 | 4 | ||
9 | state = { | 5 | state = { |
10 | className: [], | 6 | className: [], |
11 | hasChildren: false, | 7 | hasChildren: false, |
12 | }; | 8 | }; |
13 | 9 | ||
14 | - template = template; | ||
15 | - | ||
16 | - constructor() { | 10 | + constructor($element, $attrs, $controllers, $transclude) { |
17 | this.state.className = ["ant-spin", "ant-spin-spinning"]; | 11 | this.state.className = ["ant-spin", "ant-spin-spinning"]; |
18 | - this.state.hasChildren = JSON.stringify($transclude()) !== "{}"; | 12 | + |
13 | + if ($transclude()) { | ||
14 | + let len = $transclude().lenght; | ||
15 | + if (len > 0) { | ||
16 | + this.state.hasChildren = true; | ||
17 | + } | ||
18 | + } | ||
19 | 19 | ||
20 | if (this.size === "small") { | 20 | if (this.size === "small") { |
21 | this.state.className.splice(1, 0, "ant-spin-sm"); | 21 | this.state.className.splice(1, 0, "ant-spin-sm"); |
@@ -25,4 +25,13 @@ class Spin { | @@ -25,4 +25,13 @@ class Spin { | ||
25 | this.state.className.splice(1, 0, "ant-spin-lg"); | 25 | this.state.className.splice(1, 0, "ant-spin-lg"); |
26 | } | 26 | } |
27 | } | 27 | } |
28 | + | ||
29 | + render() { | ||
30 | + return template; | ||
31 | + } | ||
32 | +} | ||
33 | + | ||
34 | +Spin.propTypes = { | ||
35 | + size: PropTypes.string, | ||
36 | + spinning: PropTypes.boolean, | ||
28 | } | 37 | } |
temp.txt
1 | image | 1 | image |
2 | - [mvo] | ||
3 | - preview=["']\{\{(.*?)\}\}["'] => preview="$1" | ||
4 | \ No newline at end of file | 2 | \ No newline at end of file |
3 | + [mvo|boss] | ||
4 | + preview=["']?\{\{(.*?)\}\}["']? => preview="$1" | ||
5 | + | ||
6 | +spin | ||
7 | + [boss] | ||
8 | + spinning=["']?\{\{(.*?)\}\}["']? => spinning="$1" | ||
5 | \ No newline at end of file | 9 | \ No newline at end of file |
webpack.config.js
@@ -8,9 +8,9 @@ module.exports = { | @@ -8,9 +8,9 @@ module.exports = { | ||
8 | // bpms | 8 | // bpms |
9 | // path: "/Users/shann/Project/essa/bpms/bpms-webapp/src/main/webapp/lib/ng-antd", | 9 | // path: "/Users/shann/Project/essa/bpms/bpms-webapp/src/main/webapp/lib/ng-antd", |
10 | // boss | 10 | // boss |
11 | - // path: "/Users/shann/Project/essa/boss/trunk/vendor-lib/ng-antd", | 11 | + path: "/Users/shann/Project/essa/boss/trunk/vendor-lib/ng-antd", |
12 | // mvo | 12 | // mvo |
13 | - path: "/Users/shann/Project/essa/mvo/mvo-webapp/public/browser-vendor/ng-antd", | 13 | + // path: "/Users/shann/Project/essa/mvo/mvo-webapp/public/browser-vendor/ng-antd", |
14 | // local | 14 | // local |
15 | // path: path.resolve(__dirname, "dist"), | 15 | // path: path.resolve(__dirname, "dist"), |
16 | filename: "ng-antd.js", | 16 | filename: "ng-antd.js", |