demo20230512/Browser_Local/js/Directive/Page.js

38 lines
1.3 KiB
JavaScript
Raw Normal View History

2023-05-12 10:20:28 +08:00
var arr = window.location.href.split("/");
if (arr[3].indexOf('app') == 0)
baseUrl = '';
else
baseUrl = '/' + arr[3];
angular.module('View.Directive')
.directive('page', function () {
return {
restrict: 'E',
templateUrl: baseUrl+'/Partials/templates-page',
scope: {
passedTotalPage: '=',
passedCurrentPage: '='
},
link: function ($scope) {
$scope.changePage = function (currentPage) {
if (currentPage < 1 || currentPage > $scope.passedTotalPage) return;
$scope.passedCurrentPage = currentPage;
};
$scope.test = function (value) {
return (value + $scope.passedCurrentPage) > 0
&& (value + $scope.passedCurrentPage) <= $scope.passedTotalPage
}
$scope.$watch('passedTotalPage', function () {
if (!$scope.passedCurrentPage) {
$scope.passedCurrentPage = 1;
}
if ($scope.passedCurrentPage > $scope.passedTotalPage) {
$scope.passedCurrentPage = $scope.passedTotalPage;
}
});
}
}
});