Commit a5fb53e07215343d1a465c801fafd78eb5e0e01f

Authored by Imshann
1 parent 5b248282

优化

build/Compile/Compile.js deleted
@@ -1,15 +0,0 @@ @@ -1,15 +0,0 @@
1 -class Compile {  
2 - props = {  
3 - compile: Object,  
4 - };  
5 -  
6 - constructor(esTable) {  
7 - if (/<[\w\d-=() "]+?>/.test(this.props.compile)) {  
8 - $elements.append(  
9 - $compile(this.props.compile)(esTable.getContext().$parent)  
10 - );  
11 - } else {  
12 - $elements.text(this.props.compile);  
13 - }  
14 - }  
15 -}  
build/Slot/Slot.js
@@ -17,11 +17,13 @@ angular.module(&quot;esNgAntd&quot;).directive(&quot;antdSlot&quot;, function ($compile) { @@ -17,11 +17,13 @@ angular.module(&quot;esNgAntd&quot;).directive(&quot;antdSlot&quot;, function ($compile) {
17 content: (newValue) => { 17 content: (newValue) => {
18 if (newValue !== undefined) { 18 if (newValue !== undefined) {
19 if (/<[^>]+>/.test(newValue)) { 19 if (/<[^>]+>/.test(newValue)) {
20 - $element.replaceWith(  
21 - $compile(newValue)(  
22 - $scope.context ? $scope.context : $scope  
23 - )  
24 - ); 20 + $scope.parentElement
  21 + .empty()
  22 + .append(
  23 + $compile(newValue)(
  24 + $scope.context ? $scope.context : $scope
  25 + )
  26 + );
25 } else { 27 } else {
26 $element.text(newValue); 28 $element.text(newValue);
27 } 29 }
@@ -33,6 +35,8 @@ angular.module(&quot;esNgAntd&quot;).directive(&quot;antdSlot&quot;, function ($compile) { @@ -33,6 +35,8 @@ angular.module(&quot;esNgAntd&quot;).directive(&quot;antdSlot&quot;, function ($compile) {
33 $scope.$watch(key, $scope.watch[key], true); 35 $scope.$watch(key, $scope.watch[key], true);
34 } 36 }
35 }, 37 },
36 - link: function ($scope, $element, $attrs, $controllers, $transclude) {}, 38 + link: function ($scope, $element, $attrs, $controllers, $transclude) {
  39 + $scope.parentElement = $element.parent();
  40 + },
37 }; 41 };
38 }); 42 });
@@ -280,7 +280,7 @@ eval(&quot;__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _Mod @@ -280,7 +280,7 @@ eval(&quot;__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _Mod
280 /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { 280 /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
281 281
282 "use strict"; 282 "use strict";
283 -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _Pagination_html__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Pagination.html */ \"./build/Pagination/Pagination.html\");\n/* harmony import */ var antd_lib_pagination_style_index_css__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! antd/lib/pagination/style/index.css */ \"./node_modules/antd/lib/pagination/style/index.css\");\n\n\nangular.module(\"esNgAntd\").directive(\"antdPagination\", function (esNgAntd) {\n return {\n controllerAs: \"antdPagination\",\n restrict: \"E\",\n transclude: true,\n replace: true,\n scope: {\n defaultCurrent: \"@\",\n current: \"@\",\n total: \"@\",\n defaultPageSize: \"@\",\n pageSize: \"@\",\n onChange: \"&\",\n onShowSizeChange: \"&\",\n showQuickJumper: \"@\",\n showSizeChanger: \"@\",\n size: \"@\",\n showTotal: \"&\",\n },\n template: _Pagination_html__WEBPACK_IMPORTED_MODULE_0__[\"default\"],\n controller: function ($scope, $element, $attrs) {\n this.getContext = function () {\n return $scope;\n };\n\n $scope.state = {\n total: null,\n current: null,\n pageSize: null,\n pageNum: null,\n pageNumList: null,\n defaultPageSize: $scope.defaultPageSize || 10,\n };\n $scope.watch = {\n total: function (newVal, oldVal) {\n if (newVal && oldVal) {\n $scope.state.total = Number(newVal);\n $scope.state.pageNum = $scope.getPageNum();\n $scope.state.pageNumList = $scope.getPageNumList();\n }\n },\n };\n\n for (const key in $scope.watch) {\n $scope.$watch(key, $scope.watch[key], true);\n }\n\n $scope.handleShowTotal = function () {\n return $scope.showTotal({\n total: $scope.state.total,\n });\n };\n\n $scope.getItemLinkClassName = function (value) {\n if (typeof value === \"number\") {\n return (\n \"ant-pagination-item\" +\n ($scope.state.current === value\n ? \" ant-pagination-item-active\"\n : \"\")\n );\n } else {\n return \"ant-pagination-jump-next ant-pagination-jump-next-custom-icon\";\n }\n };\n\n $scope.getPageNumList = function () {\n let pageNumList = [$scope.state.current];\n let pageNum = $scope.getPageNum();\n\n if (pageNum <= 7 || $scope.state.current - 1 < 4) {\n for (let i = $scope.state.current - 1; i > 0; i--) {\n pageNumList.unshift(i);\n }\n } else {\n let len =\n $scope.state.current - 1 > 2\n ? 2\n : $scope.state.current - 1;\n\n for (let i = 1; i <= len; i++) {\n pageNumList.unshift($scope.state.current - i);\n }\n\n if ($scope.state.current - 2 > 2) {\n pageNumList.unshift(\"prev\");\n pageNumList.unshift(1);\n }\n }\n\n if (pageNum <= 7 || pageNum - $scope.state.current < 4) {\n for (let i = $scope.state.current + 1; i <= pageNum; i++) {\n pageNumList.push(i);\n }\n } else {\n let limit =\n 3 - $scope.state.current > 0\n ? 2 + (3 - $scope.state.current)\n : 2;\n let len =\n pageNum - $scope.state.current > limit\n ? limit\n : pageNum - $scope.state.current;\n\n for (let i = 1; i <= len; i++) {\n pageNumList.push($scope.state.current + i);\n }\n\n if (pageNum - $scope.state.current > 2) {\n pageNumList.push(\"next\");\n pageNumList.push(pageNum);\n }\n }\n\n return pageNumList;\n };\n\n $scope.getPageNum = function () {\n return (\n Math.ceil(\n $scope.state.total /\n ($scope.pageSize || $scope.defaultPageSize || 10)\n ) || 1\n );\n };\n\n $scope.getPopupContainer = function () {\n return $element[0].querySelector(\".ant-pagination-options\");\n };\n\n $scope.handleNext = function () {\n if ($scope.state.current === $scope.state.pageNum) {\n return false;\n }\n\n $scope.handleClick(++$scope.state.current);\n };\n\n $scope.handlePrev = function () {\n if ($scope.state.current === 1) {\n return false;\n }\n\n $scope.handleClick(--$scope.state.current);\n };\n\n $scope.handleClick = function (value) {\n if (value === $scope.state.current) {\n return;\n }\n\n if (value === \"next\") {\n value = $scope.state.current + 5;\n }\n\n if (value === \"prev\") {\n value = $scope.state.current - 5;\n }\n\n $scope.setCurrent($scope.getCurrent(value));\n };\n\n $scope.handleChange = function () {\n let current = $scope.state.current;\n\n if ($scope.state.current > $scope.state.pageNum) {\n current = $scope.state.pageNum;\n } else if ($scope.state.current < 1) {\n current = 1;\n }\n\n $scope.onChange({\n page: current,\n pageSize: parseInt($scope.state.pageSize),\n });\n };\n\n $scope.handleSelectChange = function (value) {\n $scope.state.current = 1;\n $scope.state.pageSize = parseInt(value);\n $scope.handleChange();\n };\n\n $scope.getCurrent = function (number) {\n if (number > $scope.state.pageNum) {\n return $scope.state.pageNum;\n }\n\n if (number < 1) {\n return 1;\n }\n\n return parseInt(number);\n };\n\n $scope.setCurrent = function (value) {\n if (!value) {\n return;\n }\n\n $scope.state.current = $scope.getCurrent(value);\n $scope.state.pageNumList = $scope.getPageNumList();\n $scope.handleChange();\n };\n\n $scope.handleBlur = function (event) {\n $scope.setCurrent(event.target.value);\n event.target.value = null;\n };\n\n $scope.onKeyPress = function (event) {\n if (event.keyCode === 13 || event.keyCode === 32) {\n $scope.setCurrent(event.target.value);\n event.target.value = null;\n }\n };\n },\n link: function ($scope, $element, $attrs, $controllers, $transclude) {\n esNgAntd.createStyle(\"ant-pagination\", antd_lib_pagination_style_index_css__WEBPACK_IMPORTED_MODULE_1__[\"default\"]);\n $scope.state.total = Number($scope.total || 0);\n $scope.state.current = Number(\n $scope.current || $scope.defaultCurrent || 1\n );\n $scope.state.pageSize =\n $scope.pageSize || $scope.defaultPageSize || 10;\n $scope.state.pageNum = $scope.getPageNum();\n $scope.state.pageNumList = $scope.getPageNumList();\n },\n };\n});\n\n\n//# sourceURL=webpack://ng-antd/./build/Pagination/Pagination.js?"); 283 +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _Pagination_html__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Pagination.html */ \"./build/Pagination/Pagination.html\");\n/* harmony import */ var antd_lib_pagination_style_index_css__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! antd/lib/pagination/style/index.css */ \"./node_modules/antd/lib/pagination/style/index.css\");\n\n\nangular.module(\"esNgAntd\").directive(\"antdPagination\", function (esNgAntd) {\n return {\n controllerAs: \"antdPagination\",\n restrict: \"E\",\n transclude: true,\n replace: true,\n scope: {\n defaultCurrent: \"@\",\n current: \"@\",\n total: \"@\",\n defaultPageSize: \"@\",\n pageSize: \"@\",\n onChange: \"&\",\n onShowSizeChange: \"&\",\n showQuickJumper: \"@\",\n showSizeChanger: \"@\",\n size: \"@\",\n showTotal: \"&\",\n },\n template: _Pagination_html__WEBPACK_IMPORTED_MODULE_0__[\"default\"],\n controller: function ($scope, $element, $attrs) {\n this.getContext = function () {\n return $scope;\n };\n\n $scope.state = {\n total: null,\n current: null,\n pageSize: null,\n pageNum: null,\n pageNumList: null,\n defaultPageSize: $scope.defaultPageSize || 10,\n };\n $scope.watch = {\n total: function (newVal) {\n if (newVal) {\n $scope.state.total = Number(newVal);\n $scope.reset();\n $scope.state.pageNum = $scope.getPageNum();\n $scope.state.pageNumList = $scope.getPageNumList();\n }\n },\n };\n\n for (const key in $scope.watch) {\n $scope.$watch(key, $scope.watch[key], true);\n }\n\n $scope.handleShowTotal = function () {\n return $scope.showTotal({\n total: $scope.state.total,\n });\n };\n\n $scope.getItemLinkClassName = function (value) {\n if (typeof value === \"number\") {\n return (\n \"ant-pagination-item\" +\n ($scope.state.current === value\n ? \" ant-pagination-item-active\"\n : \"\")\n );\n } else {\n return \"ant-pagination-jump-next ant-pagination-jump-next-custom-icon\";\n }\n };\n\n $scope.reset = function () {\n $scope.state.current = 1;\n };\n\n $scope.getPageNumList = function () {\n let pageNumList = [$scope.state.current];\n let pageNum = $scope.getPageNum();\n\n if (pageNum <= 7 || $scope.state.current - 1 < 4) {\n for (let i = $scope.state.current - 1; i > 0; i--) {\n pageNumList.unshift(i);\n }\n } else {\n let len =\n $scope.state.current - 1 > 2\n ? 2\n : $scope.state.current - 1;\n\n for (let i = 1; i <= len; i++) {\n pageNumList.unshift($scope.state.current - i);\n }\n\n if ($scope.state.current - 2 > 2) {\n pageNumList.unshift(\"prev\");\n pageNumList.unshift(1);\n }\n }\n\n if (pageNum <= 7 || pageNum - $scope.state.current < 4) {\n for (let i = $scope.state.current + 1; i <= pageNum; i++) {\n pageNumList.push(i);\n }\n } else {\n let limit =\n 3 - $scope.state.current > 0\n ? 2 + (3 - $scope.state.current)\n : 2;\n let len =\n pageNum - $scope.state.current > limit\n ? limit\n : pageNum - $scope.state.current;\n\n for (let i = 1; i <= len; i++) {\n pageNumList.push($scope.state.current + i);\n }\n\n if (pageNum - $scope.state.current > 2) {\n pageNumList.push(\"next\");\n pageNumList.push(pageNum);\n }\n }\n\n return pageNumList;\n };\n\n $scope.getPageNum = function () {\n return (\n Math.ceil(\n $scope.state.total /\n ($scope.state.pageSize ||\n $scope.defaultPageSize ||\n 10)\n ) || 1\n );\n };\n\n $scope.getPopupContainer = function () {\n return $element[0].querySelector(\".ant-pagination-options\");\n };\n\n $scope.handleNext = function () {\n if ($scope.state.current === $scope.state.pageNum) {\n return false;\n }\n\n $scope.handleClick($scope.state.current + 1);\n };\n\n $scope.handlePrev = function () {\n if ($scope.state.current === 1) {\n return false;\n }\n\n $scope.handleClick($scope.state.current - 1);\n };\n\n $scope.handleClick = function (value) {\n if (value === $scope.state.current) {\n return;\n }\n\n if (value === \"next\") {\n value = $scope.state.current + 5;\n }\n\n if (value === \"prev\") {\n value = $scope.state.current - 5;\n }\n\n $scope.setCurrent($scope.getCurrent(value));\n };\n\n $scope.handleChange = function () {\n let current = $scope.state.current;\n $scope.state.pageNum = $scope.getPageNum();\n $scope.state.pageNumList = $scope.getPageNumList();\n\n if ($scope.state.current > $scope.state.pageNum) {\n current = $scope.state.pageNum;\n } else if ($scope.state.current < 1) {\n current = 1;\n }\n\n $scope.onChange({\n page: current,\n pageSize: parseInt($scope.state.pageSize),\n });\n };\n\n $scope.handleSelectChange = function (value) {\n $scope.state.current = 1;\n $scope.state.pageSize = parseInt(value);\n $scope.handleChange();\n };\n\n $scope.getCurrent = function (number) {\n if (number > $scope.state.pageNum) {\n return $scope.state.pageNum;\n }\n\n if (number < 1) {\n return 1;\n }\n\n return parseInt(number);\n };\n\n $scope.setCurrent = function (value) {\n if (!value) {\n return;\n }\n\n $scope.state.current = $scope.getCurrent(value);\n $scope.state.pageNumList = $scope.getPageNumList();\n $scope.handleChange();\n };\n\n $scope.handleBlur = function (event) {\n $scope.setCurrent(event.target.value);\n event.target.value = null;\n };\n\n $scope.onKeyPress = function (event) {\n if (event.keyCode === 13 || event.keyCode === 32) {\n $scope.setCurrent(event.target.value);\n event.target.value = null;\n }\n };\n },\n link: function ($scope, $element, $attrs, $controllers, $transclude) {\n esNgAntd.createStyle(\"ant-pagination\", antd_lib_pagination_style_index_css__WEBPACK_IMPORTED_MODULE_1__[\"default\"]);\n $scope.state.total = Number($scope.total || 0);\n $scope.state.current = Number(\n $scope.current || $scope.defaultCurrent || 1\n );\n $scope.state.pageSize =\n $scope.pageSize || $scope.defaultPageSize || 10;\n $scope.state.pageNum = $scope.getPageNum();\n $scope.state.pageNumList = $scope.getPageNumList();\n },\n };\n});\n\n\n//# sourceURL=webpack://ng-antd/./build/Pagination/Pagination.js?");
284 284
285 /***/ }), 285 /***/ }),
286 286
@@ -367,7 +367,7 @@ eval(&quot;__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _Sel @@ -367,7 +367,7 @@ eval(&quot;__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _Sel
367 \****************************/ 367 \****************************/
368 /***/ (() => { 368 /***/ (() => {
369 369
370 -eval("angular.module(\"esNgAntd\").directive(\"antdSlot\", function ($compile) {\n return {\n controllerAs: \"antdSlot\",\n restrict: \"E\",\n transclude: true,\n replace: true,\n scope: {\n content: \"@\",\n context: \"=\",\n },\n controller: function ($scope, $element, $attrs) {\n this.getContext = function () {\n return $scope;\n };\n\n $scope.watch = {\n content: (newValue) => {\n if (newValue !== undefined) {\n if (/<[^>]+>/.test(newValue)) {\n $element.replaceWith(\n $compile(newValue)(\n $scope.context ? $scope.context : $scope\n )\n );\n } else {\n $element.text(newValue);\n }\n }\n },\n };\n\n for (const key in $scope.watch) {\n $scope.$watch(key, $scope.watch[key], true);\n }\n },\n link: function ($scope, $element, $attrs, $controllers, $transclude) {},\n };\n});\n\n\n//# sourceURL=webpack://ng-antd/./build/Slot/Slot.js?"); 370 +eval("angular.module(\"esNgAntd\").directive(\"antdSlot\", function ($compile) {\n return {\n controllerAs: \"antdSlot\",\n restrict: \"E\",\n transclude: true,\n replace: true,\n scope: {\n content: \"@\",\n context: \"=\",\n },\n controller: function ($scope, $element, $attrs) {\n this.getContext = function () {\n return $scope;\n };\n\n $scope.watch = {\n content: (newValue) => {\n if (newValue !== undefined) {\n if (/<[^>]+>/.test(newValue)) {\n $scope.parentElement.empty().append(\n $compile(newValue)(\n $scope.context ? $scope.context : $scope\n )\n );\n } else {\n $element.text(newValue);\n }\n }\n },\n };\n\n for (const key in $scope.watch) {\n $scope.$watch(key, $scope.watch[key], true);\n }\n },\n link: function ($scope, $element, $attrs, $controllers, $transclude) {\n $scope.parentElement = $element.parent();\n },\n };\n});\n\n\n//# sourceURL=webpack://ng-antd/./build/Slot/Slot.js?");
371 371
372 /***/ }), 372 /***/ }),
373 373
@@ -411,7 +411,7 @@ eval(&quot;__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _Tab @@ -411,7 +411,7 @@ eval(&quot;__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _Tab
411 /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { 411 /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
412 412
413 "use strict"; 413 "use strict";
414 -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _Table_html__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Table.html */ \"./build/Table/Table.html\");\n/* harmony import */ var antd_lib_table_style_index_css__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! antd/lib/table/style/index.css */ \"./node_modules/antd/lib/table/style/index.css\");\n\n\nangular.module(\"esNgAntd\").directive(\"antdTable\", function (esNgAntd) {\n return {\n controllerAs: \"antdTable\",\n restrict: \"E\",\n transclude: true,\n replace: true,\n scope: {\n columns: \"=\",\n dSource: \"=\",\n rowSelection: \"=\",\n rowKey: \"@\",\n loading: \"@\",\n onChange: \"&\",\n size: \"@\",\n },\n template: _Table_html__WEBPACK_IMPORTED_MODULE_0__[\"default\"],\n controller: function ($scope, $element, $attrs) {\n this.getContext = function () {\n return $scope;\n };\n\n $scope.state = {\n size: $scope.size || \"default\",\n dataSource: [],\n selectedrecordKeys: [],\n selectedrecords: [],\n isSelectAll: false,\n rowKey: $scope.rowKey || \"id\",\n sortDirections: [\"ascend\", \"descend\"],\n sorter: {\n field: null,\n order: null,\n },\n };\n $scope.watch = {\n dSource: (newValue) => {\n if (newValue !== undefined) {\n let dataSource = [];\n newValue.forEach((record, index) => {\n let row = {};\n\n if ($scope.rowSelection) {\n row.checked = false;\n row.disabled = false;\n }\n\n if (\n $scope.rowSelection &&\n typeof $scope.rowSelection.getCheckboxProps ===\n \"function\"\n ) {\n let extraAttr =\n $scope.rowSelection.getCheckboxProps(\n record\n );\n row = Object.assign(row, extraAttr);\n }\n\n $scope.columns.forEach((column) => {\n // 排序\n if (column.sortOrder) {\n $scope.state.sorter.field = column.key;\n $scope.state.sorter.order =\n column.sortOrder;\n }\n\n row[column.key] = column.render\n ? $scope.getRender(column, record, index)\n : record[column.key];\n }); // 主键\n\n if ($scope.rowKey !== undefined) {\n row[$scope.state.rowKey] =\n record[$scope.state.rowKey];\n } else {\n row[$scope.state.rowKey] = index + 1;\n }\n\n dataSource[index] = row;\n });\n $scope.state.dataSource = dataSource;\n }\n },\n \"rowSelection.selectedRowKeys\": (newVal) => {\n if (Array.isArray(newVal)) {\n $scope.state.dataSource.map(function (row, key) {\n row.checked = newVal.includes(key);\n }); // if (newVal.length > 0) {\n // this.state.dataSource.map(function (row, key) {\n // if (newVal.includes(key)) {\n // row.checked = true;\n // }\n // });\n // } else {\n // this.state.dataSource.map(function (row) {\n // row.checked = false;\n // });\n // }\n }\n },\n };\n\n for (const key in $scope.watch) {\n $scope.$watch(key, $scope.watch[key], true);\n }\n\n $scope.getParameterName = function (fn) {\n if (typeof fn !== \"object\" && typeof fn !== \"function\") return;\n const COMMENTS = /((\\/\\/.*$)|(\\/\\*[\\s\\S]*?\\*\\/))/gm;\n const DEFAULT_PARAMS = /=[^,)]+/gm;\n const FAT_ARROWS = /=>.*$/gm;\n let code = fn.prototype\n ? fn.prototype.constructor.toString()\n : fn.toString();\n code = code\n .replace(COMMENTS, \"\")\n .replace(FAT_ARROWS, \"\")\n .replace(DEFAULT_PARAMS, \"\");\n let result = code\n .slice(code.indexOf(\"(\") + 1, code.indexOf(\")\"))\n .match(/([^\\s,]+)/g);\n return result === null ? [] : result;\n };\n\n $scope.getRender = function (column, record, index) {\n let params = $scope.getParameterName(column.render);\n let render = column.render(record[column.key], record, index);\n\n if ($attrs.dSource) {\n if (params[0]) {\n render = render.replace(\n new RegExp(`(\\{\\{.*?)${params[0]}(.*?\\}\\})`, \"g\"),\n `$1${$attrs.dSource}[${index}].${column.key}$2`\n );\n }\n\n if (params[1]) {\n render = render.replace(\n new RegExp(`(\\{\\{.*?)${params[1]}(.*?\\}\\})`, \"g\"),\n `$1${$attrs.dSource}[${index}]$2`\n );\n }\n\n if (params[2]) {\n render = render.replace(\n new RegExp(`(\\{\\{.*?)${params[2]}(.*?\\}\\})`, \"g\"),\n `$1${index}$2`\n );\n }\n }\n\n return render;\n };\n\n $scope.handleSelectAll = function (event) {\n $scope.state.isSelectAll = event.target.checked;\n $scope.state.selectedrecordKeys = [];\n $scope.state.selectedrecords = [];\n $scope.state.dataSource.map((record, key) => {\n if (record.disabled === false) {\n record.checked = event.target.checked;\n }\n\n if (record.checked) {\n $scope.state.selectedrecordKeys.push(key);\n $scope.state.selectedrecords.push($scope.dSource[key]);\n }\n\n return record;\n });\n\n if (typeof $scope.rowSelection.onChange === \"function\") {\n $scope.rowSelection.onChange(\n $scope.state.selectedrecordKeys,\n $scope.state.selectedrecords\n );\n }\n };\n\n $scope.handleSelect = function (event, index) {\n let pos = $scope.state.selectedrecordKeys.findIndex(\n (value) => value === index\n );\n\n if (event.target.checked && pos === -1) {\n $scope.state.selectedrecordKeys.push(index);\n $scope.state.selectedrecords.push($scope.dSource[index]);\n } else {\n $scope.state.selectedrecordKeys.splice(pos, 1);\n $scope.state.selectedrecords.splice(pos, 1);\n }\n\n if ($scope.state.selectedrecordKeys.length === 0) {\n $scope.state.isSelectAll = false;\n }\n\n if (typeof $scope.rowSelection.onChange === \"function\") {\n $scope.rowSelection.onChange(\n $scope.state.selectedrecordKeys,\n $scope.state.selectedrecords\n );\n }\n };\n\n $scope.handleSorter = function (key) {\n $scope.state.sorter.field = key;\n\n if ($scope.state.sorter.order === null) {\n $scope.state.sorter.order = \"ascend\";\n } else if ($scope.state.sorter.order === \"ascend\") {\n $scope.state.sorter.order = \"descend\";\n } else if ($scope.state.sorter.order === \"descend\") {\n $scope.state.sorter.order = null;\n $scope.state.sorter.field = null;\n }\n\n $scope.onChange({\n sorter: $scope.state.sorter,\n });\n };\n },\n link: function ($scope, $element, $attrs, $controllers, $transclude) {\n esNgAntd.createStyle(\"ant-table\", antd_lib_table_style_index_css__WEBPACK_IMPORTED_MODULE_1__[\"default\"]);\n },\n };\n});\n\n\n//# sourceURL=webpack://ng-antd/./build/Table/Table.js?"); 414 +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _Table_html__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Table.html */ \"./build/Table/Table.html\");\n/* harmony import */ var antd_lib_table_style_index_css__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! antd/lib/table/style/index.css */ \"./node_modules/antd/lib/table/style/index.css\");\n\n\nangular.module(\"esNgAntd\").directive(\"antdTable\", function (esNgAntd) {\n return {\n controllerAs: \"antdTable\",\n restrict: \"E\",\n transclude: true,\n replace: true,\n scope: {\n columns: \"=\",\n dSource: \"=\",\n rowSelection: \"=\",\n rowKey: \"@\",\n loading: \"@\",\n onChange: \"&\",\n size: \"@\",\n },\n template: _Table_html__WEBPACK_IMPORTED_MODULE_0__[\"default\"],\n controller: function ($scope, $element, $attrs) {\n this.getContext = function () {\n return $scope;\n };\n\n $scope.state = {\n size: $scope.size || \"default\",\n dataSource: [],\n selectedrecordKeys: [],\n selectedrecords: [],\n isSelectAll: false,\n rowKey: $scope.rowKey || \"id\",\n sortDirections: [\"ascend\", \"descend\"],\n sorter: {\n field: null,\n order: null,\n },\n };\n $scope.watch = {\n dSource: (newValue) => {\n if (newValue !== undefined) {\n let dataSource = [];\n newValue.forEach((record, index) => {\n let row = {};\n\n if ($scope.rowSelection) {\n row.checked = false;\n row.disabled = false;\n }\n\n if (\n $scope.rowSelection &&\n typeof $scope.rowSelection.getCheckboxProps ===\n \"function\"\n ) {\n let extraAttr =\n $scope.rowSelection.getCheckboxProps(\n record\n );\n row = Object.assign(row, extraAttr);\n }\n\n $scope.columns.forEach((column) => {\n row[column.key] = column.render\n ? $scope.getRender(column, record, index)\n : record[column.key];\n }); // 主键\n\n if ($scope.rowKey !== undefined) {\n row[$scope.state.rowKey] =\n record[$scope.state.rowKey];\n } else {\n row[$scope.state.rowKey] = index + 1;\n }\n\n dataSource[index] = row;\n });\n $scope.state.dataSource = dataSource;\n }\n },\n \"rowSelection.selectedRowKeys\": (newVal) => {\n if (Array.isArray(newVal)) {\n $scope.state.selectedrecordKeys = newVal;\n $scope.state.dataSource.map(function (row, key) {\n row.checked = newVal.includes(key);\n });\n }\n },\n };\n\n for (const key in $scope.watch) {\n $scope.$watch(key, $scope.watch[key], true);\n }\n\n $scope.getParameterName = function (fn) {\n if (typeof fn !== \"object\" && typeof fn !== \"function\") return;\n const COMMENTS = /((\\/\\/.*$)|(\\/\\*[\\s\\S]*?\\*\\/))/gm;\n const DEFAULT_PARAMS = /=[^,)]+/gm;\n const FAT_ARROWS = /=>.*$/gm;\n let code = fn.prototype\n ? fn.prototype.constructor.toString()\n : fn.toString();\n code = code\n .replace(COMMENTS, \"\")\n .replace(FAT_ARROWS, \"\")\n .replace(DEFAULT_PARAMS, \"\");\n let result = code\n .slice(code.indexOf(\"(\") + 1, code.indexOf(\")\"))\n .match(/([^\\s,]+)/g);\n return result === null ? [] : result;\n };\n\n $scope.getRender = function (column, record, index) {\n let params = $scope.getParameterName(column.render);\n let render = column.render(record[column.key], record, index);\n\n if ($attrs.dSource) {\n if (params[0]) {\n render = render.replace(\n new RegExp(`(\\{\\{.*?)${params[0]}(.*?\\}\\})`, \"g\"),\n `$1${$attrs.dSource}[${index}].${column.key}$2`\n );\n }\n\n if (params[1]) {\n render = render.replace(\n new RegExp(`(\\{\\{.*?)${params[1]}(.*?\\}\\})`, \"g\"),\n `$1${$attrs.dSource}[${index}]$2`\n );\n }\n\n if (params[2]) {\n render = render.replace(\n new RegExp(`(\\{\\{.*?)${params[2]}(.*?\\}\\})`, \"g\"),\n `$1${index}$2`\n );\n }\n }\n\n return render;\n };\n\n $scope.handleSelectAll = function (event) {\n $scope.state.isSelectAll = event.target.checked;\n $scope.state.selectedrecordKeys = [];\n $scope.state.selectedrecords = [];\n $scope.state.dataSource.map((record, key) => {\n if (record.disabled === false) {\n record.checked = event.target.checked;\n }\n\n if (record.checked) {\n $scope.state.selectedrecordKeys.push(key);\n $scope.state.selectedrecords.push($scope.dSource[key]);\n }\n\n return record;\n });\n\n if (typeof $scope.rowSelection.onChange === \"function\") {\n $scope.rowSelection.onChange(\n $scope.state.selectedrecordKeys,\n $scope.state.selectedrecords\n );\n }\n };\n\n $scope.handleSelect = function (event, index) {\n let pos = $scope.state.selectedrecordKeys.findIndex(\n (value) => value === index\n );\n\n if (event.target.checked && pos === -1) {\n $scope.state.selectedrecordKeys.push(index);\n $scope.state.selectedrecords.push($scope.dSource[index]);\n } else {\n $scope.state.selectedrecordKeys.splice(pos, 1);\n $scope.state.selectedrecords.splice(pos, 1);\n }\n\n if ($scope.state.selectedrecordKeys.length === 0) {\n $scope.state.isSelectAll = false;\n }\n\n if (typeof $scope.rowSelection.onChange === \"function\") {\n $scope.rowSelection.onChange(\n $scope.state.selectedrecordKeys,\n $scope.state.selectedrecords\n );\n }\n };\n\n $scope.handleSorter = function (key) {\n $scope.state.sorter.field = key;\n\n if ($scope.state.sorter.order === null) {\n $scope.state.sorter.order = \"ascend\";\n } else if ($scope.state.sorter.order === \"ascend\") {\n $scope.state.sorter.order = \"descend\";\n } else if ($scope.state.sorter.order === \"descend\") {\n $scope.state.sorter.order = null;\n $scope.state.sorter.field = null;\n }\n\n $scope.onChange({\n sorter: $scope.state.sorter,\n });\n };\n },\n link: function ($scope, $element, $attrs, $controllers, $transclude) {\n esNgAntd.createStyle(\"ant-table\", antd_lib_table_style_index_css__WEBPACK_IMPORTED_MODULE_1__[\"default\"]); // 初始化默认排序\n\n $scope.columns.forEach((column) => {\n if (column.sortOrder) {\n $scope.state.sorter.field = column.key;\n $scope.state.sorter.order = column.sortOrder;\n }\n });\n },\n };\n});\n\n\n//# sourceURL=webpack://ng-antd/./build/Table/Table.js?");
415 415
416 /***/ }), 416 /***/ }),
417 417
example/table.html
@@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
9 <body> 9 <body>
10 <div ng-app="esNgAntd" ng-controller="mainCtrl"> 10 <div ng-app="esNgAntd" ng-controller="mainCtrl">
11 <div class="container" style="padding: 50px"> 11 <div class="container" style="padding: 50px">
12 - <es-table columns="columns" d-source="dataSource" row-selection="rowSelection" loading="{{loading}}" on-change="handleChange(sorter)" size="small"/> 12 + <antd-table columns="columns" d-source="dataSource" row-selection="rowSelection" loading="{{loading}}" on-change="handleChange(sorter)" size="small"/>
13 </div> 13 </div>
14 </div> 14 </div>
15 <script src="https://cdn.staticfile.org/angular.js/1.2.28/angular.min.js"></script> 15 <script src="https://cdn.staticfile.org/angular.js/1.2.28/angular.min.js"></script>
@@ -35,6 +35,9 @@ @@ -35,6 +35,9 @@
35 { 35 {
36 title: "状态", 36 title: "状态",
37 key: "status", 37 key: "status",
  38 + render: function(value) {
  39 + return `<span>${value}</span>`;
  40 + }
38 }, 41 },
39 { 42 {
40 title: "操作", 43 title: "操作",
@@ -78,6 +81,13 @@ @@ -78,6 +81,13 @@
78 $scope.dataSource.splice(key, 1); 81 $scope.dataSource.splice(key, 1);
79 console.log($scope.dataSource); 82 console.log($scope.dataSource);
80 }; 83 };
  84 +
  85 + $scope.constructor = (function(){
  86 + $timeout(function(){
  87 + $scope.dataSource[1].status = 1;
  88 + console.log($scope.dataSource)
  89 + }, 3000)
  90 + })();
81 }); 91 });
82 </script> 92 </script>
83 </body> 93 </body>
@@ -10,7 +10,7 @@ class Slot { @@ -10,7 +10,7 @@ class Slot {
10 content: (newValue) => { 10 content: (newValue) => {
11 if (newValue !== undefined) { 11 if (newValue !== undefined) {
12 if (/<[^>]+>/.test(newValue)) { 12 if (/<[^>]+>/.test(newValue)) {
13 - $element.replaceWith( 13 + this.parentElement.empty().append(
14 $compile(newValue)( 14 $compile(newValue)(
15 $scope.context ? $scope.context : $scope 15 $scope.context ? $scope.context : $scope
16 ) 16 )
@@ -23,6 +23,6 @@ class Slot { @@ -23,6 +23,6 @@ class Slot {
23 }; 23 };
24 24
25 constructor() { 25 constructor() {
26 - 26 + this.parentElement = $element.parent();
27 } 27 }
28 } 28 }
@@ -6,9 +6,9 @@ module.exports = { @@ -6,9 +6,9 @@ module.exports = {
6 entry: "./build/index.js", 6 entry: "./build/index.js",
7 output: { 7 output: {
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