|
|
@@ -2,14 +2,20 @@
|
|
|
* Created by yujia on 2017/3/24.
|
|
|
* 原厂认证
|
|
|
*/
|
|
|
-define(['app/app'], function(app) {
|
|
|
+define(['app/app'], function (app) {
|
|
|
"use strict";
|
|
|
- app.register.controller('vendorAccountManagementCtrl', ['$scope', '$rootScope', 'Enterprise', 'User', 'toaster', '$modal','BaseService','ngTableParams','$http', 'AuthenticationService','$stateParams', function($scope, $rootScope, Enterprise, User, toaster, $modal, BaseService, ngTableParams, $http, AuthenticationService,$stateParams) {
|
|
|
+ app.register.controller('vendorAccountManagementCtrl', ['$scope', '$rootScope', 'Enterprise', 'User', 'toaster', '$modal', 'BaseService', 'ngTableParams', '$http', 'AuthenticationService', '$stateParams','AccountResource','AccountRole', function ($scope, $rootScope, Enterprise, User, toaster, $modal, BaseService, ngTableParams, $http, AuthenticationService, $stateParams, AccountResource, AccountRole) {
|
|
|
$rootScope.active = 'vendor_account_management';
|
|
|
- document.title = '账户管理-优软商城';
|
|
|
- $scope.tab = 'base';
|
|
|
+ document.title = '账户管理-优软商城';
|
|
|
+ $scope.tab = 'base';
|
|
|
+ $scope.addingUser = false;
|
|
|
+ $scope.setAddingUser = function (status) {
|
|
|
+ $scope.addingUser = status;
|
|
|
+ $scope.adding = false;
|
|
|
+ };
|
|
|
$scope.userInfo = $rootScope.userInfo;
|
|
|
$scope.updateState = false;
|
|
|
+ $scope.filterRole = 'all';
|
|
|
$scope.searchParams = {
|
|
|
keyword: ''
|
|
|
};
|
|
|
@@ -151,183 +157,260 @@ define(['app/app'], function(app) {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- $scope.tableParams = new ngTableParams({
|
|
|
- page: 1, // show first page
|
|
|
- count: 10 // count per page
|
|
|
- }, {
|
|
|
- total: 0,
|
|
|
- getData: function ($defer, params) {
|
|
|
- var param = BaseService.parseParams(params.url());
|
|
|
- param.enuu = $scope.userInfo.enterprise.uu;
|
|
|
- if (!$scope.searchMthod) {
|
|
|
- Enterprise.getAllUsersByEnuu(param, function (page) {
|
|
|
- if (page) {
|
|
|
- params.total(page.totalElements);
|
|
|
- $defer.resolve(page.content);
|
|
|
- $scope.users = page.content;
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- else {
|
|
|
- param.keyword = $scope.keyword;
|
|
|
- Enterprise.findUsersByKeyword(param, function (page) {
|
|
|
- if (page) {
|
|
|
- params.total(page.totalElements);
|
|
|
- $defer.resolve(page.content);
|
|
|
- $scope.users = page.content;
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
+ $scope.pageParam = {};
|
|
|
+ $scope.tableParams = new ngTableParams({
|
|
|
+ page : 1, // show first page
|
|
|
+ count : 10 // count per page
|
|
|
+ }, {
|
|
|
+ total : 0,
|
|
|
+ getData : function($defer, params) {
|
|
|
+ var param = BaseService.parseParams(params.url());
|
|
|
+ param.enuu = $scope.userInfo.enterprise.uu;
|
|
|
+ if(!$scope.searchMthod) {
|
|
|
+ Enterprise.getAllUsersByEnuu(param, function (page) {
|
|
|
+ if (page) {
|
|
|
+ $scope.pageParam.start = (page.number-1)*page.size+1;
|
|
|
+ $scope.pageParam.end = $scope.pageParam.start + page.numberOfElements - 1;
|
|
|
+ $scope.pageParam.all = page.totalElements;
|
|
|
+ params.total(page.totalElements);
|
|
|
+ $defer.resolve(page.content);
|
|
|
+ $scope.users = page.content;
|
|
|
+ $scope.reloadUserCheck(false);
|
|
|
+ }
|
|
|
+ },function (error) {
|
|
|
+ toaster.pop('error', '获取企业人员信息失败',error.data);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ param.keyword = $scope.keyword;
|
|
|
+ if (filterRolejs !== 1){
|
|
|
+ param.roleId = filterRolejs;
|
|
|
+ }
|
|
|
+ Enterprise.findUsersByKeyword(param,function (page) {
|
|
|
+ if (page) {
|
|
|
+ $scope.pageParam.start = (page.number-1)*page.size+1;
|
|
|
+ $scope.pageParam.end = $scope.pageParam.start + page.numberOfElements - 1;
|
|
|
+ $scope.pageParam.all = page.totalElements;
|
|
|
+ params.total(page.totalElements);
|
|
|
+ $defer.resolve(page.content);
|
|
|
+ $scope.users = page.content;
|
|
|
+ $scope.reloadUserCheck(false);
|
|
|
+ }
|
|
|
+ },function (error) {
|
|
|
+ toaster.pop('error', '获取企业人员信息失败',error.data);
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
- });
|
|
|
+ });
|
|
|
|
|
|
- $scope.onSearch = function (keyword) {
|
|
|
- if (keyword != null && keyword != '') {
|
|
|
- $scope.searchMthod = true;
|
|
|
- $scope.keyword = keyword;
|
|
|
+ var filterRolejs = 1;
|
|
|
+ $scope.onSearch = function (keyword,filterRole) {
|
|
|
+ filterRolejs = 1;
|
|
|
+ if ((keyword != null && keyword != '') || filterRole !== 'all') {
|
|
|
+ if (filterRole === 'all'){
|
|
|
+ filterRolejs = 1;
|
|
|
+ }else {
|
|
|
+ filterRolejs = filterRole;
|
|
|
+ }
|
|
|
+ $scope.searchMthod = true;
|
|
|
+ $scope.keyword = keyword;
|
|
|
} else {
|
|
|
- $scope.searchMthod = false;
|
|
|
+ $scope.searchMthod = false;
|
|
|
}
|
|
|
$scope.tableParams.page(1);
|
|
|
$scope.tableParams.reload();
|
|
|
- };
|
|
|
+ };
|
|
|
+ $scope.onKeyUpSearch = function (keyword, filterRole, event) {
|
|
|
+ if (event && event.keyCode == 13) {
|
|
|
+ $scope.onSearch(keyword, filterRole);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- $scope.newUser = {};
|
|
|
+ $scope.newUser = {};
|
|
|
|
|
|
- //弹出添加用户模态框
|
|
|
- $scope.addExistUser = function () {
|
|
|
+ //弹出添加用户模态框
|
|
|
+ $scope.addExistUser = function () {
|
|
|
+ $scope.adding = false;
|
|
|
+ $scope.setAddingUser(false);
|
|
|
+ $scope.newUser = {};
|
|
|
var modalInstance = $modal.open({
|
|
|
- animation: true,
|
|
|
- templateUrl: $rootScope.rootPath
|
|
|
- + '/static/view/vendor/forstore/addExistUser.html',
|
|
|
- controller: 'AddExistUserCtrl'
|
|
|
+ animation: true,
|
|
|
+ templateUrl: $rootScope.rootPath + '/static/view/vendor/forstore/addExistUser.html',
|
|
|
+ controller: 'AddExistUserCtrl'
|
|
|
});
|
|
|
|
|
|
modalInstance.result.then(function () {
|
|
|
- $scope.userTelSuccess = false;
|
|
|
- $scope.userTelError = false;
|
|
|
- $scope.tableParams.page(1);
|
|
|
- $scope.tableParams.reload();
|
|
|
+ $scope.userTelSuccess = false;
|
|
|
+ $scope.userTelError = false;
|
|
|
+ $scope.tableParams.page(1);
|
|
|
+ $scope.tableParams.reload();
|
|
|
}, function () {
|
|
|
|
|
|
});
|
|
|
|
|
|
- };
|
|
|
- /**
|
|
|
- * 添加未注册用户
|
|
|
- */
|
|
|
- $scope.addUser = function () {
|
|
|
+ };
|
|
|
+ /**
|
|
|
+ * 添加未注册用户
|
|
|
+ */
|
|
|
+ $scope.addUser = function () {
|
|
|
+ if (!$scope.userEmailSuccess || !$scope.userTelSuccess) {
|
|
|
+ toaster.pop('error', '请输入正确的信息后提交');
|
|
|
+ return;
|
|
|
+ }
|
|
|
$scope.adding = true;
|
|
|
$scope.loading = true;
|
|
|
Enterprise.saveUser({}, $scope.newUser, function () {
|
|
|
- $scope.loading = false;
|
|
|
- toaster.pop('success', '提示', '增加用户成功:' + $scope.newUser.userName);
|
|
|
- $scope.newUser = {userSex: 'M'};
|
|
|
- $scope.tableParams.page(1);
|
|
|
- $scope.tableParams.reload();
|
|
|
- $scope.adding = false;
|
|
|
- $scope.newUserForm.newUserTel.$setValidity('available', false);
|
|
|
- $scope.newUserForm.newUserEmail.$setValidity('available', false);
|
|
|
- $scope.userTelSuccess = false;
|
|
|
- $scope.userTelError = false;
|
|
|
- $scope.userEmailSuccess = false;
|
|
|
- $scope.userEmailError = false;
|
|
|
+ $scope.loading = false;
|
|
|
+ toaster.pop('success', '提示', '增加用户成功:' + $scope.newUser.userName);
|
|
|
+ $scope.setAddingUser(false);
|
|
|
+ $scope.newUser = {userSex: 'M'};
|
|
|
+ $scope.tableParams.page(1);
|
|
|
+ $scope.tableParams.reload();
|
|
|
+ $scope.adding = false;
|
|
|
+ // $scope.newUserForm.newUserTel.$setValidity('available', false);
|
|
|
+ // $scope.newUserForm.newUserEmail.$setValidity('available', false);
|
|
|
+ $scope.userTelSuccess = false;
|
|
|
+ $scope.userTelError = false;
|
|
|
+ $scope.userEmailSuccess = false;
|
|
|
+ $scope.userEmailError = false;
|
|
|
}, function (response) {
|
|
|
- $scope.loading = false;
|
|
|
- toaster.pop('error', '错误', response.data);
|
|
|
+ $scope.loading = false;
|
|
|
+ toaster.pop('error', '错误', response.data);
|
|
|
});
|
|
|
- };
|
|
|
-
|
|
|
- /**
|
|
|
- * 删除用户
|
|
|
- */
|
|
|
- $scope.removeUser = function (user) {
|
|
|
+ };
|
|
|
|
|
|
- if (confirm('确定删除用户(' + user.userName + ')吗?')) {
|
|
|
- Enterprise.removeUser({uu: user.userUU}, function () {
|
|
|
+ $scope.adding = false;
|
|
|
+ $scope.setAdding = function (status) {
|
|
|
+ $scope.adding = status;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 删除用户
|
|
|
+ */
|
|
|
+ $scope.removeUser = function (user) {
|
|
|
+
|
|
|
+ // if (confirm('确定删除用户(' + user.userName + ')吗?')) {
|
|
|
+ // }
|
|
|
+ Enterprise.removeUser({uu: user.userUU}, function () {
|
|
|
toaster.pop('success', '提示', '用户删除成功。');
|
|
|
$scope.tableParams.page(1);
|
|
|
$scope.tableParams.reload();
|
|
|
- }, function (response) {
|
|
|
+ $scope.showDelUserFlag = false;
|
|
|
+ }, function (response) {
|
|
|
toaster.pop('error', '删除失败', response.data);
|
|
|
- });
|
|
|
+ });
|
|
|
+ };
|
|
|
+ //用户删除确认框
|
|
|
+ $scope.showDelUserFlag = false;
|
|
|
+
|
|
|
+ $scope.setShowDelUserFlag = function (flag, user) {
|
|
|
+ $scope.showDelUserFlag = flag;
|
|
|
+ if (flag) {
|
|
|
+ $scope.delUser = user;
|
|
|
}
|
|
|
- };
|
|
|
- /**
|
|
|
- * 验证手机号是否可用
|
|
|
- */
|
|
|
- $scope.telValid = function (tel) {
|
|
|
- if (tel) {
|
|
|
- $http.get('basic/user/telEnable', {
|
|
|
- params: {
|
|
|
- tel: tel
|
|
|
- }
|
|
|
- }).success(function (data) {
|
|
|
- data = eval(data);
|
|
|
- if (data == true) {
|
|
|
- $scope.newUserForm.newUserTel.$setValidity('available', true);
|
|
|
- $scope.userTelSuccess = true;
|
|
|
- $scope.userTelError = false;
|
|
|
- } else {
|
|
|
- $scope.newUserForm.newUserTel.$setValidity('available',
|
|
|
- false);
|
|
|
- $scope.userTelError = true;
|
|
|
- $scope.userTelSuccess = false;
|
|
|
- if (tel.length == 11) {
|
|
|
- toaster.pop('error', '错误', '手机号 ' + tel + ' 已被注册');
|
|
|
- }
|
|
|
+ }
|
|
|
+ /***
|
|
|
+ * 全选
|
|
|
+ * */
|
|
|
+ $scope.isCheckAll = false;
|
|
|
+ $scope.doCheckAll = function () {
|
|
|
+ $scope.isCheckAll = !$scope.isCheckAll;
|
|
|
+ if ($scope.isCheckAll) {
|
|
|
+ $scope.reloadUserCheck(true);
|
|
|
+ } else {
|
|
|
+ $scope.reloadUserCheck(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $scope.checkUser = function (user) {
|
|
|
+ user.checked = !user.checked;
|
|
|
+ var allcheck = true
|
|
|
+ angular.forEach($scope.users, function (item) {
|
|
|
+ if (!item.checked) {
|
|
|
+ allcheck = false;
|
|
|
}
|
|
|
- }).error(function () {
|
|
|
- $scope.userTelSuccess = false;
|
|
|
- $scope.userTelError = true;
|
|
|
- });
|
|
|
+ });
|
|
|
+ $scope.isCheckAll = allcheck;
|
|
|
+ }
|
|
|
+
|
|
|
+ $scope.reloadUserCheck = function (flag) {
|
|
|
+ angular.forEach($scope.users, function (item) {
|
|
|
+ item.checked = flag;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 验证手机号是否可用
|
|
|
+ */
|
|
|
+ $scope.telValid = function (tel) {
|
|
|
+ if (tel) {
|
|
|
+ $http.get('basic/user/telEnable', {
|
|
|
+ params: {
|
|
|
+ tel: tel
|
|
|
+ }
|
|
|
+ }).success(function (data) {
|
|
|
+ data = eval(data);
|
|
|
+ if (data == true) {
|
|
|
+ // $scope.newUserForm.newUserTel.$setValidity('available', true);
|
|
|
+ $scope.userTelSuccess = true;
|
|
|
+ $scope.userTelError = false;
|
|
|
+ } else {
|
|
|
+ // $scope.newUserForm.newUserTel.$setValidity('available', false);
|
|
|
+ $scope.userTelError = true;
|
|
|
+ $scope.userTelSuccess = false;
|
|
|
+ if (tel.length == 11)
|
|
|
+ toaster.pop('error', '错误', '手机号 ' + tel + ' 已被注册');
|
|
|
+ }
|
|
|
+ }).error(function () {
|
|
|
+ $scope.userTelSuccess = false;
|
|
|
+ $scope.userTelError = true;
|
|
|
+ });
|
|
|
} else {
|
|
|
- $scope.userTelSuccess = false;
|
|
|
- $scope.userTelError = false;
|
|
|
+ $scope.userTelSuccess = false;
|
|
|
+ $scope.userTelError = false;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- /**
|
|
|
- * 验证邮箱是否可用
|
|
|
- */
|
|
|
- $scope.emailValid = function (email) {
|
|
|
+ /**
|
|
|
+ * 验证邮箱是否可用
|
|
|
+ */
|
|
|
+ $scope.emailValid = function (email) {
|
|
|
if (email) {
|
|
|
- $http.get('basic/user/emailEnable', {
|
|
|
- params: {
|
|
|
- email: email
|
|
|
- }
|
|
|
- }).success(function (data) {
|
|
|
- data = eval(data);
|
|
|
- if (data == true) {
|
|
|
- $scope.newUserForm.newUserEmail.$setValidity('available',
|
|
|
- true);
|
|
|
- $scope.userEmailSuccess = true;
|
|
|
- $scope.userEmailError = false;
|
|
|
- } else {
|
|
|
- $scope.newUserForm.newUserEmail.$setValidity('available',
|
|
|
- false);
|
|
|
- $scope.userEmailError = true;
|
|
|
- $scope.userEmailSuccess = false;
|
|
|
- }
|
|
|
- }).error(function () {
|
|
|
- $scope.userEmailError = true;
|
|
|
- $scope.userEmailSuccess = false;
|
|
|
- });
|
|
|
+ $http.get('basic/user/emailEnable', {
|
|
|
+ params: {
|
|
|
+ email: email
|
|
|
+ }
|
|
|
+ }).success(function (data) {
|
|
|
+ data = eval(data);
|
|
|
+ if (data == true) {
|
|
|
+ // $scope.newUserForm.newUserEmail.$setValidity('available',
|
|
|
+ // true);
|
|
|
+ $scope.userEmailSuccess = true;
|
|
|
+ $scope.userEmailError = false;
|
|
|
+ } else {
|
|
|
+ // $scope.newUserForm.newUserEmail.$setValidity('available',
|
|
|
+ // false);
|
|
|
+ $scope.userEmailError = true;
|
|
|
+ $scope.userEmailSuccess = false;
|
|
|
+ toaster.pop('error', '错误', '邮箱 ' + email + ' 已被注册');
|
|
|
+ }
|
|
|
+ }).error(function () {
|
|
|
+ $scope.userEmailError = true;
|
|
|
+ $scope.userEmailSuccess = false;
|
|
|
+ });
|
|
|
} else {
|
|
|
- $scope.userEmailError = false;
|
|
|
- $scope.userEmailSuccess = false;
|
|
|
+ $scope.userEmailError = false;
|
|
|
+ $scope.userEmailSuccess = false;
|
|
|
}
|
|
|
- };
|
|
|
+ };
|
|
|
|
|
|
- /**
|
|
|
- * 变更到更新状态
|
|
|
- */
|
|
|
- $scope.changeToUpdate = function (isUpdate) {
|
|
|
+ /**
|
|
|
+ * 变更到更新状态
|
|
|
+ */
|
|
|
+ $scope.changeToUpdate = function (isUpdate) {
|
|
|
$scope.updateState = isUpdate;
|
|
|
if ($scope.updateState == false) {
|
|
|
- $scope.enterpriseInfo = angular.copy($scope.enterpriseInfoBackup);
|
|
|
+ $scope.enterpriseInfo = angular.copy($scope.enterpriseInfoBackup);
|
|
|
}
|
|
|
- };
|
|
|
+ };
|
|
|
|
|
|
/**
|
|
|
* 验证企业信息
|
|
|
@@ -337,20 +420,20 @@ define(['app/app'], function(app) {
|
|
|
|
|
|
var flag = true;
|
|
|
angular.forEach(props, function (prop) {
|
|
|
- if ($scope.enterpriseInfo.hasOwnProperty(prop)) {
|
|
|
- if (!$scope.enterpriseInfo[prop] || $scope.enterpriseInfo[prop]
|
|
|
- === '') {
|
|
|
- console.log(prop + '不能为空');
|
|
|
- // TODO 记录验证信息
|
|
|
- flag = false;
|
|
|
+ if ($scope.enterpriseInfo.hasOwnProperty(prop)) {
|
|
|
+ if (!$scope.enterpriseInfo[prop] || $scope.enterpriseInfo[prop]
|
|
|
+ === '') {
|
|
|
+ console.log(prop + '不能为空');
|
|
|
+ // TODO 记录验证信息
|
|
|
+ flag = false;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ console.log(prop + '不能为空');
|
|
|
+ flag = false;
|
|
|
}
|
|
|
- } else {
|
|
|
- console.log(prop + '不能为空');
|
|
|
- flag = false;
|
|
|
- }
|
|
|
});
|
|
|
return flag;
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
// 获取行业信息
|
|
|
$http.get('static/data/profession.json').success(function (data) {
|
|
|
@@ -437,24 +520,24 @@ define(['app/app'], function(app) {
|
|
|
// 先检查信息是否为空
|
|
|
if (angular.equals($scope.enterpriseInfo,
|
|
|
$scope.enterpriseInfoBackup)) {
|
|
|
- toaster.pop('error', '未做任何修改');
|
|
|
- $scope.updateState = false;
|
|
|
- return;
|
|
|
+ toaster.pop('error', '未做任何修改');
|
|
|
+ $scope.updateState = false;
|
|
|
+ return;
|
|
|
}
|
|
|
var enterpriseInfoFlag = validateEnterpriseInfo();
|
|
|
if (!enterpriseInfoFlag) {
|
|
|
- toaster.pop('error', '请补充完信息后再次提交');
|
|
|
- return;
|
|
|
+ toaster.pop('error', '请补充完信息后再次提交');
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
Enterprise.updateEnterpriseInfo(
|
|
|
{enuu: $scope.userInfo.enterprise.uu}, $scope.enterpriseInfo,
|
|
|
function () {
|
|
|
- $scope.loading = false;
|
|
|
- toaster.pop('success', '提示', '企业信息修改成功');
|
|
|
- $scope.enterpriseInfoBackup = angular.copy(
|
|
|
- $scope.enterpriseInfo);
|
|
|
- $scope.updateState = false;
|
|
|
+ $scope.loading = false;
|
|
|
+ toaster.pop('success', '提示', '企业信息修改成功');
|
|
|
+ $scope.enterpriseInfoBackup = angular.copy(
|
|
|
+ $scope.enterpriseInfo);
|
|
|
+ $scope.updateState = false;
|
|
|
|
|
|
}, function (response) {
|
|
|
$scope.loading = false;
|
|
|
@@ -471,8 +554,22 @@ define(['app/app'], function(app) {
|
|
|
// 切换tab
|
|
|
$scope.checkTab = function (t) {
|
|
|
$scope.tab = t;
|
|
|
+ if (t === 'role' && $scope.rolesExcept) {
|
|
|
+ toaster.pop('error', '获取企业角色信息失败',$scope.rolesExcept);
|
|
|
+ }
|
|
|
+ // if (t === 'auth') {
|
|
|
+ // $scope.keyword = '';
|
|
|
+ // $scope.onSearch($scope.keyword,'all');
|
|
|
+ // }
|
|
|
};
|
|
|
|
|
|
+ /* 查询接口权限 */
|
|
|
+ // AccountRole.findAuthority({resUrl: encodeURIComponent('/account/role'), method: 'GET'}, function (data) {
|
|
|
+ //
|
|
|
+ // }, function (error) {
|
|
|
+ //
|
|
|
+ // })
|
|
|
+
|
|
|
$scope.updatePassword = function () {
|
|
|
AuthenticationService.redirectPassword();
|
|
|
};
|
|
|
@@ -524,81 +621,163 @@ define(['app/app'], function(app) {
|
|
|
$scope.updateUserEmail();
|
|
|
break;
|
|
|
}
|
|
|
- }
|
|
|
- }]);
|
|
|
-
|
|
|
- /*
|
|
|
- * 绑定用户到企业
|
|
|
- */
|
|
|
- app.register.controller('AddExistUserCtrl',
|
|
|
- ['$scope', '$modalInstance', 'Enterprise', 'AuthenticationService',
|
|
|
- '$timeout', 'toaster',
|
|
|
- function ($scope, $modalInstance, Enterprise, AuthenticationService,
|
|
|
- $timeout, toaster) {
|
|
|
- $scope.searching = false;
|
|
|
- //根据输入的内容查找用户
|
|
|
- $scope.searchUser = function (keyWord) {
|
|
|
- $scope.searching = true;
|
|
|
- $scope.searchSuccess = false;
|
|
|
- $scope.searchFailed = false;
|
|
|
- $scope.illegalError = false;
|
|
|
- $scope.reBindError = false;
|
|
|
- $scope.okDisabled = false;
|
|
|
- Enterprise.searchUser({keyWord: keyWord}, function (data) {
|
|
|
- $scope.searchSuccess = true;
|
|
|
- $scope.searchFailed = false;
|
|
|
- $scope.user = data; //查询到的用户
|
|
|
- }, function (response) {
|
|
|
- $scope.searchSuccess = false;
|
|
|
- $scope.searchFailed = true;
|
|
|
+ }
|
|
|
+ //角色控制
|
|
|
+ $scope.roles = {};
|
|
|
+ AccountResource.query({}, function (data) {
|
|
|
+ if (data && data.length > 0) {
|
|
|
+ data[0].$open = true;
|
|
|
+ }
|
|
|
+ $scope.resources = data;
|
|
|
+ });
|
|
|
+ var getData = function () {
|
|
|
+ AccountRole.findAll({}, function (data) {
|
|
|
+ var defaults = [], custom = [];
|
|
|
+ angular.forEach(data, function (d) {
|
|
|
+ if (d.isdefault == 1)
|
|
|
+ defaults.push(d);
|
|
|
+ else
|
|
|
+ custom.push(d);
|
|
|
+ });
|
|
|
+ $scope.roles = {defaults: defaults, custom: custom};
|
|
|
+ },function (error) {
|
|
|
+ $scope.rolesExcept = error.data;
|
|
|
});
|
|
|
- };
|
|
|
+ AccountRole.getByExistRoleAndEnuu({}, function (data) {
|
|
|
+ var defaults = [], custom = [];
|
|
|
+ angular.forEach(data, function (d) {
|
|
|
+ if (d.isdefault == 1)
|
|
|
+ defaults.push(d);
|
|
|
+ else
|
|
|
+ custom.push(d);
|
|
|
+ });
|
|
|
+ $scope.existRoles = {defaults: defaults, custom: custom};
|
|
|
+ });
|
|
|
+ };
|
|
|
+ getData();
|
|
|
+ $scope.editRole = function (role) {
|
|
|
+ var modalInstance = $modal.open({
|
|
|
+ animation: true,
|
|
|
+ templateUrl: $rootScope.rootPath + '/static/view/vendor/modal/role_detail.html',
|
|
|
+ controller: 'RoleEditCtrl',
|
|
|
+ resolve: {
|
|
|
+ role: function () {
|
|
|
+ return role;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ modalInstance.result.then(function (added) {
|
|
|
+ added && getData();
|
|
|
+ });
|
|
|
+ };
|
|
|
|
|
|
- //确认绑定
|
|
|
- $scope.ok = function (keyWord) {
|
|
|
- AuthenticationService.getAuthentication().success(function (data) {
|
|
|
- $scope.currentUser = data; //当前登录的用户(管理员)
|
|
|
- //不可自己绑定自己
|
|
|
- if ($scope.currentUser.userUU == $scope.user.userUU) {
|
|
|
- $scope.illegalError = true;
|
|
|
- $scope.okDisabled = true;
|
|
|
- return false;
|
|
|
- }
|
|
|
+ $scope.editUserRole = function (user) {
|
|
|
+ var modalInstance = $modal.open({
|
|
|
+ animation: true,
|
|
|
+ templateUrl: $rootScope.rootPath + '/static/view/vendor/modal/edit_user_role.html',
|
|
|
+ controller: 'UserRoleEditCtrl',
|
|
|
+ resolve: {
|
|
|
+ user: function () {
|
|
|
+ return user;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ };
|
|
|
|
|
|
- //用户未绑定到任何企业时
|
|
|
- if (!$scope.user.enterprises) {
|
|
|
- //正常绑定
|
|
|
- Enterprise.bindUserToMyEnterprise({userUU: $scope.user.userUU},
|
|
|
- function (data) {
|
|
|
- $scope.okDisabled = true;
|
|
|
- toaster.pop("success", "提示", "用户绑定成功");
|
|
|
- $modalInstance.close(true);
|
|
|
+ $scope.inSelect = false;
|
|
|
+ $scope.setInSelect = function (status) {
|
|
|
+ $scope.inSelect = status;
|
|
|
+ }
|
|
|
+ $(document).on("click", function () {
|
|
|
+ $scope.$apply(function () {
|
|
|
+ if (!$scope.inSelect) {
|
|
|
+ $scope.setAdding(false);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }]);
|
|
|
+
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 绑定用户到企业
|
|
|
+ */
|
|
|
+ app.register.controller('AddExistUserCtrl',
|
|
|
+ ['$scope', '$modalInstance', 'Enterprise', 'AuthenticationService',
|
|
|
+ '$timeout', 'toaster',
|
|
|
+ function ($scope, $modalInstance, Enterprise, AuthenticationService,
|
|
|
+ $timeout, toaster) {
|
|
|
+ $scope.searching = false;
|
|
|
+ //根据输入的内容查找用户
|
|
|
+ $scope.searchUser = function (keyWord) {
|
|
|
+ $scope.searching = true;
|
|
|
+ $scope.searchSuccess = false;
|
|
|
+ $scope.searchFailed = false;
|
|
|
+ $scope.illegalError = false;
|
|
|
+ $scope.reBindError = false;
|
|
|
+ $scope.okDisabled = false;
|
|
|
+ Enterprise.searchUser({keyWord: keyWord}, function (data) {
|
|
|
+ $scope.searchSuccess = true;
|
|
|
+ $scope.searchFailed = false;
|
|
|
+ $scope.user = data; //查询到的用户
|
|
|
}, function (response) {
|
|
|
+ $scope.searchSuccess = false;
|
|
|
+ $scope.searchFailed = true;
|
|
|
});
|
|
|
- return true;
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
- //用户已绑定到某些企业时
|
|
|
- for (var i = 0; i < $scope.currentUser.enterprises.length; i++) {
|
|
|
- if ($scope.currentUser.enterprises[i].current) {
|
|
|
- for (var j = 0; j < $scope.user.enterprises.length; j++) {
|
|
|
- //该用户已绑定到当前企业,不可重复绑定
|
|
|
- if ($scope.currentUser.enterprises[i].uu
|
|
|
- == $scope.user.enterprises[j].uu) {
|
|
|
- $scope.reBindError = true;
|
|
|
- $scope.okDisabled = true;
|
|
|
- return false;
|
|
|
+ $scope.onKeyDown = function (e, key) {
|
|
|
+ var keycode = window.event ? e.keyCode : e.which;
|
|
|
+ if (keycode == 13) {
|
|
|
+ $scope.searchUser(key);
|
|
|
}
|
|
|
- }
|
|
|
- //该用户未绑定到当前企业,可以进行绑定
|
|
|
- Enterprise.bindUserToMyEnterprise(
|
|
|
- {userUU: $scope.user.userUU}, function (data) {
|
|
|
- $scope.okDisabled = true;
|
|
|
- toaster.pop("success", "提示", "用户绑定成功");
|
|
|
- $modalInstance.close(true);
|
|
|
- }, function (response) {
|
|
|
- console.log("绑定失败!");
|
|
|
- });
|
|
|
+ }
|
|
|
+
|
|
|
+ //确认绑定
|
|
|
+ $scope.ok = function (keyWord) {
|
|
|
+ AuthenticationService.getAuthentication().success(function (data) {
|
|
|
+ $scope.currentUser = data; //当前登录的用户(管理员)
|
|
|
+ //不可自己绑定自己
|
|
|
+ if ($scope.currentUser.userUU == $scope.user.userUU) {
|
|
|
+ $scope.illegalError = true;
|
|
|
+ $scope.okDisabled = true;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ //用户未绑定到任何企业时
|
|
|
+ if (!$scope.user.enterprises) {
|
|
|
+ //正常绑定
|
|
|
+ Enterprise.bindUserToMyEnterprise({userUU: $scope.user.userUU},
|
|
|
+ function (data) {
|
|
|
+ $scope.okDisabled = true;
|
|
|
+ toaster.pop("success", "提示", "用户绑定成功");
|
|
|
+ $modalInstance.close(true);
|
|
|
+ }, function (response) {
|
|
|
+ toaster.pop('error', response.data);
|
|
|
+ });
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ //用户已绑定到某些企业时
|
|
|
+ for (var i = 0; i < $scope.currentUser.enterprises.length; i++) {
|
|
|
+ if ($scope.currentUser.enterprises[i].current) {
|
|
|
+ for (var j = 0; j < $scope.user.enterprises.length; j++) {
|
|
|
+ //该用户已绑定到当前企业,不可重复绑定
|
|
|
+ if ($scope.currentUser.enterprises[i].uu
|
|
|
+ == $scope.user.enterprises[j].uu) {
|
|
|
+ $scope.reBindError = true;
|
|
|
+ $scope.okDisabled = true;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //该用户未绑定到当前企业,可以进行绑定
|
|
|
+ Enterprise.bindUserToMyEnterprise(
|
|
|
+ {userUU: $scope.user.userUU}, function (data) {
|
|
|
+ $scope.okDisabled = true;
|
|
|
+ toaster.pop("success", "提示", "用户绑定成功");
|
|
|
+ $modalInstance.close(true);
|
|
|
+ }, function (response) {
|
|
|
+ toaster.pop('error', response.data);
|
|
|
+ });
|
|
|
|
|
|
}
|
|
|
}
|
|
|
@@ -1638,16 +1817,481 @@ define(['app/app'], function(app) {
|
|
|
$scope.checkFailed = false;
|
|
|
window.location.href = "vendor#/account/management/sec";
|
|
|
|
|
|
- window.location.reload();
|
|
|
- $modalInstance.close();
|
|
|
- }, function(response){
|
|
|
- toaster.pop('error', '错误', response.data);
|
|
|
- $modalInstance.close();
|
|
|
+ window.location.reload();
|
|
|
+ $modalInstance.close();
|
|
|
+ }, function (response) {
|
|
|
+ toaster.pop('error', '错误', response.data);
|
|
|
+ $modalInstance.close();
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ $scope.cancel = function () {
|
|
|
+ $modalInstance.close();
|
|
|
+ };
|
|
|
+ }]);
|
|
|
+//角色管理-编辑角色controller
|
|
|
+ app.register.controller('RoleEditCtrl', ['$scope', '$modalInstance', '$timeout', 'AccountResource', 'AccountRole', 'toaster', 'role', 'BaseService', function ($scope, $modalInstance, $timeout, AccountResource, AccountRole, toaster, role, BaseService) {
|
|
|
+ BaseService.scrollBackToTop();
|
|
|
+ $scope.role = angular.copy(role || {});
|
|
|
+ $scope.master = angular.copy($scope.role);
|
|
|
+ var isNew = role == null;
|
|
|
+ $scope.cancel = function () {
|
|
|
+ $modalInstance.close(false);
|
|
|
+ };
|
|
|
+
|
|
|
+ var getCheckRoleResource = function (data, rs) {
|
|
|
+ if (data.items.length > 0) {
|
|
|
+ var c = 0;
|
|
|
+ angular.forEach(data.items, function (item) {
|
|
|
+ if (rs.indexOf(item.id) > -1) {
|
|
|
+ item.$checked = true;
|
|
|
+ c += 1;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ data.$checked = c > 0 && c == data.items.length;
|
|
|
+ data.$halfChecked = c > 0 && c < data.items.length;
|
|
|
+ } else {
|
|
|
+ angular.forEach(data.children, function (item) {
|
|
|
+ getCheckRoleResource(item, rs);
|
|
|
+ var activeCount = 0;
|
|
|
+ angular.forEach(data.children, function (item) {
|
|
|
+ if (!item.$checked) {
|
|
|
+ activeCount ++;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ data.$checked = activeCount > 0 && activeCount == data.children.length;
|
|
|
+
|
|
|
+ data.$halfChecked = activeCount > 0 && activeCount < data.children.length;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ AccountResource.query({}, function (data) {
|
|
|
+ if (data && data.length > 0) {
|
|
|
+ var rs = [];// 已分配的资源的id
|
|
|
+ if (role && role.resourceItems) {
|
|
|
+ angular.forEach(role.resourceItems, function (item) {
|
|
|
+ rs.push(item.id);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ angular.forEach(data, function (data2) {
|
|
|
+ getCheckRoleResource(data2, rs);
|
|
|
+ })
|
|
|
+ $scope.resourceItems = data[0].items;
|
|
|
+ data[0].$active = true;
|
|
|
+ }
|
|
|
+ $scope.resources = data;
|
|
|
+ // if ($scope.role) {
|
|
|
+ // angular.forEach($scope.role.resourceItems,function (item) {
|
|
|
+ // angular.forEach($scope.resources, function (roleItem) {
|
|
|
+ // if (item.id == roleItem.id) {
|
|
|
+ // roleItem.$active = true;
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ // })
|
|
|
+ // }
|
|
|
+ $timeout(function () {
|
|
|
+ angular.forEach($scope.resources, function (resource) {
|
|
|
+ var c = 0;
|
|
|
+ angular.forEach(resource.items, function (item) {
|
|
|
+ item.$checked && (c += 1);
|
|
|
+ });
|
|
|
+ angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
|
|
|
+ });
|
|
|
+ }, 100);
|
|
|
+ getChecked();
|
|
|
+ });
|
|
|
+
|
|
|
+ $scope.onItemClick = function (resource) {
|
|
|
+ if (resource.items.length > 0) {
|
|
|
+ $scope.resourceItems = resource.items;
|
|
|
+ $scope.activeResource = resource
|
|
|
+ } else {
|
|
|
+ $scope.resourceItems = [];
|
|
|
+ if (!resource.activeLevel) {
|
|
|
+ resource.activeLevel = true;
|
|
|
+ } else {
|
|
|
+ resource.activeLevel = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ setNoActive($scope.resources);
|
|
|
+ resource.$active = true;
|
|
|
+ };
|
|
|
+ var setNoActive = function (obj) {
|
|
|
+ angular.forEach(obj, function (r) {
|
|
|
+ r.$active = false;
|
|
|
+ if (r.children) {
|
|
|
+ setNoActive(r.children);
|
|
|
+ }
|
|
|
});
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
- $scope.cancel = function () {
|
|
|
+ var getChecked = function () {
|
|
|
+ var items = [];
|
|
|
+ angular.forEach($scope.resources, function (resource) {
|
|
|
+ pushCheckedResource(resource, items);
|
|
|
+ });
|
|
|
+ if ($scope.role) {
|
|
|
+ $scope.role.resourceItems = items;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ var pushCheckedResource = function (resource, items) {
|
|
|
+ if (resource.items.length > 0) {
|
|
|
+ var activeCount = 0;
|
|
|
+ angular.forEach(resource.items, function (item) {
|
|
|
+ // item.$checked && items.push(item);
|
|
|
+ if (item.$checked) {
|
|
|
+ items.push(item);
|
|
|
+ activeCount ++;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ resource.$checked = activeCount > 0 && activeCount == resource.items.length;
|
|
|
+ resource.$halfChecked = activeCount > 0 && activeCount < resource.items.length;
|
|
|
+
|
|
|
+ } else {
|
|
|
+ var halfCount = 0;
|
|
|
+ var fullCount = 0;
|
|
|
+ angular.forEach(resource.children, function (item) {
|
|
|
+ if (item.$checked) {
|
|
|
+ fullCount ++;
|
|
|
+ } else if (item.$halfChecked) {
|
|
|
+ halfCount ++;
|
|
|
+ }
|
|
|
+ pushCheckedResource(item, items);
|
|
|
+ })
|
|
|
+ resource.$halfChecked = halfCount > 0 || (fullCount > 0 && fullCount < resource.children.length);
|
|
|
+ resource.$checked = fullCount > 0 && fullCount == resource.children.length;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $scope.onResourceChange = function (resource) {
|
|
|
+ levelResourceChecked(resource);
|
|
|
+ getChecked();
|
|
|
+ };
|
|
|
+ var levelResourceChecked = function (resource) {
|
|
|
+ if (resource.items.length > 0) {
|
|
|
+ angular.forEach(resource.items, function (item) {
|
|
|
+ item.$checked = resource.$checked;
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ angular.forEach(resource.children, function (item) {
|
|
|
+ item.$checked = resource.$checked;
|
|
|
+ levelResourceChecked(item);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ $scope.onItemChange = function () {
|
|
|
+ var activeCount = 0;
|
|
|
+ var resourceItems = $scope.resourceItems;
|
|
|
+ // console.log(resourceItems);
|
|
|
+ angular.forEach(resourceItems, function (item) {
|
|
|
+ if (item.$checked) {
|
|
|
+ activeCount++;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ // console.log(activeCount);
|
|
|
+ // console.log( $scope.activeResource)
|
|
|
+ $scope.activeResource.$checked = activeCount == resourceItems.length;
|
|
|
+
|
|
|
+ $scope.activeResource.$halfChecked = activeCount > 0 && activeCount < resourceItems.length;
|
|
|
+
|
|
|
+ angular.forEach($scope.resources, function (resource) {
|
|
|
+ if (resource.$active) {
|
|
|
+ var c = 0;
|
|
|
+ angular.forEach(resource.items, function (item) {
|
|
|
+ item.$checked && (c += 1);
|
|
|
+ });
|
|
|
+ resource.$checked = (c == resource.items.length);
|
|
|
+ resource.$halfChecked = c > 0 && c < resource.items.length;
|
|
|
+ angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ getChecked();
|
|
|
+ };
|
|
|
+ $scope.isChanged = function (formData) {
|
|
|
+ if (!$scope.master)
|
|
|
+ return true;
|
|
|
+ return !angular.equals(formData, $scope.master);
|
|
|
+ };
|
|
|
+ $scope.save = function () {
|
|
|
+ $scope.master = angular.copy($scope.role);
|
|
|
+ if (!$scope.master.color || $scope.master.color == '') {
|
|
|
+ $scope.master.color = parseInt(Math.random() * 5) + 1 + '';
|
|
|
+ }
|
|
|
+ AccountRole.save($scope.master, function () {
|
|
|
+ toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 资料' + (isNew ? '添加' : '修改') + '成功');
|
|
|
+ $modalInstance.close(true);
|
|
|
+ }, function (response) {
|
|
|
+ toaster.pop('error', '错误', response.data);
|
|
|
+ });
|
|
|
+ };
|
|
|
+ $scope.del = function () {
|
|
|
+ if (confirm('确定删除角色(' + $scope.role.desc + ')吗?')) {
|
|
|
+ AccountRole.remove({id: role.id}, function () {
|
|
|
+ toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 删除成功');
|
|
|
+ $modalInstance.close(true);
|
|
|
+ }, function (response) {
|
|
|
+ toaster.pop('error', '错误', response.data);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }]);
|
|
|
+
|
|
|
+ app.register.controller('UserRoleEditCtrl', ['$scope', '$modalInstance', '$timeout', 'AccountResource', 'toaster', 'user', 'BaseService', 'AccountRole', 'User', function ($scope, $modalInstance, $timeout, AccountResource, toaster, user, BaseService, AccountRole, User) {
|
|
|
+
|
|
|
+ $scope.pages = [];
|
|
|
+
|
|
|
+ $scope.params = {
|
|
|
+ page: 1,
|
|
|
+ count: 6,
|
|
|
+ totalPage: 1,
|
|
|
+ currentPage: 1
|
|
|
+ };
|
|
|
+
|
|
|
+ var loadCurrentRoles = function () {
|
|
|
+ var start = ($scope.params.page - 1) * $scope.params.count;
|
|
|
+ var end = $scope.params.page * $scope.params.count;
|
|
|
+ $scope.currentRoles = $scope.rolesData.slice(start, end);
|
|
|
+ };
|
|
|
+
|
|
|
+ var init = function () {
|
|
|
+ $scope.user = angular.copy(user);
|
|
|
+ AccountRole.query({}, function (data) {
|
|
|
+ $scope.rolesData = data;
|
|
|
+ loadCurrentRoles();
|
|
|
+ $scope.params.totalPage = Math.ceil($scope.rolesData.length / 6);
|
|
|
+ $scope.acculatePages(1, $scope.params.totalPage);
|
|
|
+ angular.forEach($scope.rolesData, function (item) {
|
|
|
+ item.checked = false;
|
|
|
+ angular.forEach($scope.user.roles, function (userItem) {
|
|
|
+ if (item.id === userItem.id) {
|
|
|
+ item.checked = true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ init();
|
|
|
+
|
|
|
+ $scope.checked = [];
|
|
|
+ //勾选角色
|
|
|
+ $scope.checkRole = function (role) {
|
|
|
+ role.checked = !role.checked;
|
|
|
+ }
|
|
|
+
|
|
|
+ //关闭模态框
|
|
|
+ $scope.cancelModal = function () {
|
|
|
$modalInstance.close();
|
|
|
- };
|
|
|
- }]);
|
|
|
+ }
|
|
|
+ $scope.close = function (save) {
|
|
|
+ if (save) {
|
|
|
+ if (user.userUU) {
|
|
|
+ angular.forEach($scope.rolesData, function (item) {
|
|
|
+ if (item.checked) {
|
|
|
+ $scope.checked.push(item);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ $scope.user.roles = $scope.checked;
|
|
|
+ User.update({}, $scope.user, function () {
|
|
|
+ toaster.pop('success', '提示', '保存成功');
|
|
|
+ user.roles = $scope.checked
|
|
|
+ $modalInstance.close(true);
|
|
|
+ }, function (response) {
|
|
|
+ toaster.pop('error', '保存失败', response.data);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ $modalInstance.close(true, $scope.checked);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $modalInstance.close(false);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ // //初始化分页数据
|
|
|
+ // var initPages = function () {
|
|
|
+ // $scope.totalPages = Math.ceil = ($scope.rolesData.length/6);
|
|
|
+ // }
|
|
|
+ //初始化页数信息
|
|
|
+ $scope.initPages = function (totalElementPages) {
|
|
|
+ var pageNum = [];
|
|
|
+ if (totalElementPages == 1) {
|
|
|
+ return;
|
|
|
+ } else if (totalElementPages < 10) {
|
|
|
+ for (var i = 0; i < totalElementPages + 2; i++) {
|
|
|
+ pageNum.push(i);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ pageNum = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
|
|
+ }
|
|
|
+ angular.forEach(pageNum, function (number) {
|
|
|
+ var page = {active: true, type: 'page', number: number};
|
|
|
+ if (number == 0) {
|
|
|
+ page.type = 'prev';
|
|
|
+ } else if (number == 1) {
|
|
|
+ page.type = 'first';
|
|
|
+ } else if (number == pageNum.length - 2) {
|
|
|
+ page.type = 'last';
|
|
|
+ page.number = totalElementPages;
|
|
|
+ } else if (number == pageNum.length - 1) {
|
|
|
+ page.type = 'next';
|
|
|
+ }
|
|
|
+ $scope.pages.push(page);
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ //当前页在后端计算方式
|
|
|
+ $scope.endSegment = function (currentPage, totalElementPages) {
|
|
|
+ if (totalElementPages > 8) {
|
|
|
+ angular.forEach($scope.pages, function (page) {
|
|
|
+ switch (page.number) {
|
|
|
+ case 2:
|
|
|
+ page.active = false;
|
|
|
+ page.type = 'more';
|
|
|
+ break;
|
|
|
+ case 10:
|
|
|
+ if (currentPage == totalElementPages) {
|
|
|
+ page.active = false;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 0:
|
|
|
+ case 1:
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ if (page.number != totalElementPages) {
|
|
|
+ page.number = totalElementPages - 9 + page.number;
|
|
|
+ }
|
|
|
+ page.current = (currentPage == page.number);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ //当前页在中间计算方式
|
|
|
+ $scope.middleSegment = function (currentPage) {
|
|
|
+ angular.forEach($scope.pages, function (page) {
|
|
|
+ switch (page.number) {
|
|
|
+ case 2:
|
|
|
+ case 8:
|
|
|
+ page.type = 'more';
|
|
|
+ page.active = false;
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ page.number = currentPage - 2;
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ page.number = currentPage - 1;
|
|
|
+ break;
|
|
|
+ case 5:
|
|
|
+ page.number = currentPage;
|
|
|
+ page.current = true;
|
|
|
+ break;
|
|
|
+ case 6:
|
|
|
+ page.number = currentPage + 1;
|
|
|
+ break;
|
|
|
+ case 7:
|
|
|
+ page.number = currentPage + 2;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ //当前页在前段的计算方式
|
|
|
+ $scope.frontSegment = function (currentPage, totalElementPages) {
|
|
|
+ if (totalElementPages > 8) {
|
|
|
+ angular.forEach($scope.pages, function (page) {
|
|
|
+ switch (page.number) {
|
|
|
+ case 8:
|
|
|
+ page.type = 'more';
|
|
|
+ page.active = false;
|
|
|
+ break;
|
|
|
+ case 0:
|
|
|
+ if (currentPage == 1) {
|
|
|
+ page.active = false;
|
|
|
+ }
|
|
|
+ default : {
|
|
|
+ page.current = (currentPage == page.number);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ //输入框监听Enter事件
|
|
|
+ $scope.listenEnter = function () {
|
|
|
+ if (event.keyCode == 13) {
|
|
|
+ $scope.setPage("page", $scope.params.currentPage);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ $scope.setPage = function (type, number) {
|
|
|
+ if (type != 'prev' && type != 'page' && type != 'next' && type != 'last' && type != 'first') {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ ;
|
|
|
+ var page = -1;
|
|
|
+ switch (type) {
|
|
|
+ case "page":
|
|
|
+ if (number < 1) {
|
|
|
+ page = 1;
|
|
|
+ } else if (number > $scope.params.totalPage) {
|
|
|
+ page = $scope.params.totalPage;
|
|
|
+ } else {
|
|
|
+ page = number;
|
|
|
+ }
|
|
|
+ ;
|
|
|
+ break;
|
|
|
+ case "prev":
|
|
|
+ if ($scope.params.page <= 1) {
|
|
|
+ page = 1;
|
|
|
+ } else {
|
|
|
+ page = $scope.params.page - 1;
|
|
|
+ }
|
|
|
+ ;
|
|
|
+ break;
|
|
|
+ case "next":
|
|
|
+ if ($scope.params.page >= $scope.params.totalPage) {
|
|
|
+ page = $scope.params.totalPage;
|
|
|
+ } else {
|
|
|
+ page = $scope.params.page + 1;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case "first":
|
|
|
+ page = 1;
|
|
|
+ break;
|
|
|
+ case "last":
|
|
|
+ page = $scope.params.totalPage;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (page == $scope.params.page || page < 1 || page > $scope.params.totalPage) {
|
|
|
+ $scope.params.currentPage = $scope.params.page;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ $scope.params.page = page;
|
|
|
+ $scope.params.currentPage = page;
|
|
|
+ loadData();
|
|
|
+ };
|
|
|
+
|
|
|
+ //计算页数的方式。
|
|
|
+ $scope.acculatePages = function (currentPage, totalElementPages) {
|
|
|
+ $scope.pages = [];
|
|
|
+ if (totalElementPages < 1) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //初始化页面数据
|
|
|
+ $scope.initPages(totalElementPages);
|
|
|
+ if (currentPage < 6) {//当期页小于6
|
|
|
+ $scope.frontSegment(currentPage, totalElementPages);
|
|
|
+ } else if (currentPage > totalElementPages - 5) { //当期页在后面
|
|
|
+ $scope.endSegment(currentPage, totalElementPages);
|
|
|
+ } else { //当期页在中间
|
|
|
+ $scope.middleSegment(currentPage);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ var loadData = function () {
|
|
|
+ loadCurrentRoles();
|
|
|
+ $scope.acculatePages($scope.params.page, $scope.params.totalPage);
|
|
|
+ };
|
|
|
+ }]);
|
|
|
});
|