From ee8e8c097fe8fdcbe369b49ff04cd6df42ea114d Mon Sep 17 00:00:00 2001 From: Imshann <851188611@qq.com> Date: Thu, 17 Feb 2022 10:54:10 +0800 Subject: [PATCH] 优化CheckableTag组件 --- build/CheckableTag/CheckableTag.html | 2 +- build/CheckableTag/CheckableTag.js | 51 +++++++++++++++++++++++---------------------------- dist/ng-antd.js | 4 ++-- example/checkable-tag.html | 2 +- src/CheckableTag/CheckableTag.html | 2 +- src/CheckableTag/CheckableTag.js | 24 +++++++++++++----------- 6 files changed, 41 insertions(+), 44 deletions(-) diff --git a/build/CheckableTag/CheckableTag.html b/build/CheckableTag/CheckableTag.html index 7721a57..c4014a1 100644 --- a/build/CheckableTag/CheckableTag.html +++ b/build/CheckableTag/CheckableTag.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/build/CheckableTag/CheckableTag.js b/build/CheckableTag/CheckableTag.js index 37214a3..510bd35 100644 --- a/build/CheckableTag/CheckableTag.js +++ b/build/CheckableTag/CheckableTag.js @@ -1,29 +1,24 @@ -import template from "./CheckableTag.html"; import style from "antd/lib/tag/style/index.css"; -angular.module("esNgAntd").directive("antdCheckableTag", function (esNgAntd) { - return { - controllerAs: "antdCheckableTag", - restrict: "E", - transclude: true, - replace: true, - scope: { - checked: "@", - onChange: "&", - }, - template: template, - controller: function ($scope, $element, $attrs) { - this.getContext = function () { - return $scope; - }; - - $scope.handleClick = function () { - $scope.onChange({ - checked: !($scope.checked === "true"), - }); - }; - }, - link: function ($scope, $element, $attrs, $controllers, $transclude) { - esNgAntd.createStyle("ant-tag", style); - }, - }; -}); +import template from "./CheckableTag.html"; +angular.module("esNgAntd").directive("antdCheckableTag", ["esNgAntd", function (esNgAntd) { + return { + template: template, + restrict: "E", + replace: true, + transclude: true, + scope: { + checked: "=", + onChange: "&" + }, + controller: function ($scope) { + $scope.handleClick = function () { + $scope.onChange({ + checked: !($scope.checked === true) + }); + }; + }, + link: function ($scope) { + esNgAntd.createStyle("ant-tag", style); + } + }; +}]); \ No newline at end of file diff --git a/dist/ng-antd.js b/dist/ng-antd.js index ff6d86e..5fbbbba 100644 --- a/dist/ng-antd.js +++ b/dist/ng-antd.js @@ -71,7 +71,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var antd /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _CheckableTag_html__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./CheckableTag.html */ \"./build/CheckableTag/CheckableTag.html\");\n/* harmony import */ var antd_lib_tag_style_index_css__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! antd/lib/tag/style/index.css */ \"./node_modules/antd/lib/tag/style/index.css\");\n\n\nangular.module(\"esNgAntd\").directive(\"antdCheckableTag\", function (esNgAntd) {\n return {\n controllerAs: \"antdCheckableTag\",\n restrict: \"E\",\n transclude: true,\n replace: true,\n scope: {\n checked: \"@\",\n onChange: \"&\",\n },\n template: _CheckableTag_html__WEBPACK_IMPORTED_MODULE_0__[\"default\"],\n controller: function ($scope, $element, $attrs) {\n this.getContext = function () {\n return $scope;\n };\n\n $scope.handleClick = function () {\n $scope.onChange({\n checked: !($scope.checked === \"true\"),\n });\n };\n },\n link: function ($scope, $element, $attrs, $controllers, $transclude) {\n esNgAntd.createStyle(\"ant-tag\", antd_lib_tag_style_index_css__WEBPACK_IMPORTED_MODULE_1__[\"default\"]);\n },\n };\n});\n\n\n//# sourceURL=webpack://ng-antd/./build/CheckableTag/CheckableTag.js?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var antd_lib_tag_style_index_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! antd/lib/tag/style/index.css */ \"./node_modules/antd/lib/tag/style/index.css\");\n/* harmony import */ var _CheckableTag_html__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./CheckableTag.html */ \"./build/CheckableTag/CheckableTag.html\");\n\n\nangular.module(\"esNgAntd\").directive(\"antdCheckableTag\", [\"esNgAntd\", function (esNgAntd) {\n return {\n template: _CheckableTag_html__WEBPACK_IMPORTED_MODULE_1__[\"default\"],\n restrict: \"E\",\n replace: true,\n transclude: true,\n scope: {\n checked: \"=\",\n onChange: \"&\"\n },\n controller: function ($scope) {\n $scope.handleClick = function () {\n $scope.onChange({\n checked: !($scope.checked === true)\n });\n };\n },\n link: function ($scope) {\n esNgAntd.createStyle(\"ant-tag\", antd_lib_tag_style_index_css__WEBPACK_IMPORTED_MODULE_0__[\"default\"]);\n }\n };\n}]);\n\n//# sourceURL=webpack://ng-antd/./build/CheckableTag/CheckableTag.js?"); /***/ }), @@ -9485,7 +9485,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n// Module\nvar code = \"\";\n// Exports\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (code);\n\n//# sourceURL=webpack://ng-antd/./build/CheckableTag/CheckableTag.html?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n// Module\nvar code = \"\";\n// Exports\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (code);\n\n//# sourceURL=webpack://ng-antd/./build/CheckableTag/CheckableTag.html?"); /***/ }), diff --git a/example/checkable-tag.html b/example/checkable-tag.html index 7ae08c1..9f6f3cf 100644 --- a/example/checkable-tag.html +++ b/example/checkable-tag.html @@ -9,7 +9,7 @@
- {{tag.label}} + {{tag.label}}
diff --git a/src/CheckableTag/CheckableTag.html b/src/CheckableTag/CheckableTag.html index 16a5273..f036536 100644 --- a/src/CheckableTag/CheckableTag.html +++ b/src/CheckableTag/CheckableTag.html @@ -1 +1 @@ -{children} \ No newline at end of file +{children} \ No newline at end of file diff --git a/src/CheckableTag/CheckableTag.js b/src/CheckableTag/CheckableTag.js index 6cc3e57..e02818a 100644 --- a/src/CheckableTag/CheckableTag.js +++ b/src/CheckableTag/CheckableTag.js @@ -2,23 +2,25 @@ import template from "./CheckableTag.html"; import style from "antd/lib/tag/style/index.css"; class CheckableTag { - + useModules = ["esNgAntd"]; - template = template; - - props = { - checked: Boolean, - onChange: Function, + constructor() { + esNgAntd.createStyle("ant-tag", style); } handleClick() { this.props.onChange({ - checked: !(this.props.checked==="true") - }) + checked: !(this.props.checked === true), + }); } - constructor() { - esNgAntd.createStyle("ant-tag", style); + render() { + return template; } -} \ No newline at end of file +} + +CheckableTag.propTypes = { + checked: PropTypes.boolean, + onChange: PropTypes.function, +}; -- libgit2 0.21.2