From 5b2482824b04d0c16ee814eab901d5131f23c781 Mon Sep 17 00:00:00 2001 From: Imshann <851188611@qq.com> Date: Wed, 23 Feb 2022 10:30:30 +0800 Subject: [PATCH] 优化 --- build/Checkbox/Checkbox.js | 1 - build/Pagination/Pagination.js | 13 +++++++++---- build/Table/Table.js | 16 ++++++++-------- src/Pagination/Pagination.js | 13 +++++++++---- src/Table/Table.js | 12 +++++++----- webpack.config.js | 4 ++-- 6 files changed, 35 insertions(+), 24 deletions(-) diff --git a/build/Checkbox/Checkbox.js b/build/Checkbox/Checkbox.js index 9fa20d2..6535027 100644 --- a/build/Checkbox/Checkbox.js +++ b/build/Checkbox/Checkbox.js @@ -46,7 +46,6 @@ angular.module("esNgAntd").directive("antdCheckbox", function (esNgAntd) { $scope.handleClick = function ($event) { $scope.state.checked = !$scope.state.checked; - $event.target.checked = $scope.state.checked; $scope.onChange({ event: $event, }); diff --git a/build/Pagination/Pagination.js b/build/Pagination/Pagination.js index d3682dc..6f2554d 100644 --- a/build/Pagination/Pagination.js +++ b/build/Pagination/Pagination.js @@ -34,9 +34,10 @@ angular.module("esNgAntd").directive("antdPagination", function (esNgAntd) { defaultPageSize: $scope.defaultPageSize || 10, }; $scope.watch = { - total: function (newVal, oldVal) { - if (newVal && oldVal) { + total: function (newVal) { + if (newVal) { $scope.state.total = Number(newVal); + $scope.reset(); $scope.state.pageNum = $scope.getPageNum(); $scope.state.pageNumList = $scope.getPageNumList(); } @@ -66,6 +67,10 @@ angular.module("esNgAntd").directive("antdPagination", function (esNgAntd) { } }; + $scope.reset = function () { + $scope.state.current = 1; + }; + $scope.getPageNumList = function () { let pageNumList = [$scope.state.current]; let pageNum = $scope.getPageNum(); @@ -137,7 +142,7 @@ angular.module("esNgAntd").directive("antdPagination", function (esNgAntd) { return false; } - $scope.handleClick(++$scope.state.current); + $scope.handleClick($scope.state.current + 1); }; $scope.handlePrev = function () { @@ -145,7 +150,7 @@ angular.module("esNgAntd").directive("antdPagination", function (esNgAntd) { return false; } - $scope.handleClick(--$scope.state.current); + $scope.handleClick($scope.state.current - 1); }; $scope.handleClick = function (value) { diff --git a/build/Table/Table.js b/build/Table/Table.js index d00f392..20b1386 100644 --- a/build/Table/Table.js +++ b/build/Table/Table.js @@ -59,13 +59,6 @@ angular.module("esNgAntd").directive("antdTable", function (esNgAntd) { } $scope.columns.forEach((column) => { - // 排序 - if (column.sortOrder) { - $scope.state.sorter.field = column.key; - $scope.state.sorter.order = - column.sortOrder; - } - row[column.key] = column.render ? $scope.getRender(column, record, index) : record[column.key]; @@ -213,7 +206,14 @@ angular.module("esNgAntd").directive("antdTable", function (esNgAntd) { }; }, link: function ($scope, $element, $attrs, $controllers, $transclude) { - esNgAntd.createStyle("ant-table", style); + esNgAntd.createStyle("ant-table", style); // 初始化默认排序 + + $scope.columns.forEach((column) => { + if (column.sortOrder) { + $scope.state.sorter.field = column.key; + $scope.state.sorter.order = column.sortOrder; + } + }); }, }; }); diff --git a/src/Pagination/Pagination.js b/src/Pagination/Pagination.js index f2f8a1c..4ab454c 100644 --- a/src/Pagination/Pagination.js +++ b/src/Pagination/Pagination.js @@ -30,9 +30,10 @@ class Pagination { }; watch = { - total: function (newVal, oldVal) { - if (newVal && oldVal) { + total: function (newVal) { + if (newVal) { this.state.total = Number(newVal); + this.reset(); this.state.pageNum = this.getPageNum(); this.state.pageNumList = this.getPageNumList(); } @@ -70,6 +71,10 @@ class Pagination { } } + reset() { + this.state.current = 1; + } + getPageNumList() { let pageNumList = [this.state.current]; let pageNum = this.getPageNum(); @@ -127,14 +132,14 @@ class Pagination { if (this.state.current === this.state.pageNum) { return false; } - this.handleClick(++this.state.current); + this.handleClick(this.state.current+1); } handlePrev() { if (this.state.current === 1) { return false; } - this.handleClick(--this.state.current); + this.handleClick(this.state.current-1); } handleClick(value) { diff --git a/src/Table/Table.js b/src/Table/Table.js index d7d4c26..e9fbe04 100644 --- a/src/Table/Table.js +++ b/src/Table/Table.js @@ -50,11 +50,6 @@ class Table { row = Object.assign(row, extraAttr); } this.props.columns.forEach((column) => { - // 排序 - if (column.sortOrder) { - this.state.sorter.field = column.key; - this.state.sorter.order = column.sortOrder; - } row[column.key] = column.render ? this.getRender(column, record, index) : record[column.key]; @@ -82,6 +77,13 @@ class Table { constructor() { esNgAntd.createStyle("ant-table", style); + // 初始化默认排序 + this.props.columns.forEach((column) => { + if (column.sortOrder) { + this.state.sorter.field = column.key; + this.state.sorter.order = column.sortOrder; + } + }); } getParameterName(fn) { diff --git a/webpack.config.js b/webpack.config.js index 700bc4e..8aeae93 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -6,11 +6,11 @@ module.exports = { entry: "./build/index.js", output: { // bpms - // path: "/Users/shann/Project/essa/bpms/bpms-webapp/src/main/webapp/lib/ng-antd", + path: "/Users/shann/Project/essa/bpms/bpms-webapp/src/main/webapp/lib/ng-antd", // boss // path: "/Users/shann/Project/essa/boss/trunk/vendor-lib/ng-antd", // mvo - path: "/Users/shann/Project/essa/mvo/mvo-webapp/public/browser-vendor/ng-antd", + // path: "/Users/shann/Project/essa/mvo/mvo-webapp/public/browser-vendor/ng-antd", // local // path: path.resolve(__dirname, "dist"), filename: "ng-antd.js", -- libgit2 0.21.2