userRole.js
7.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/**
* Created by cjl on 2018/4/23.
*/
(function () {
"user strict";
var userRoleController = function($scope,$modal,$http,$interval,dialogService,railwayService){
$scope.$emit('navShow', 7);
$scope.settingShow = 7;
$scope.vm = {
account: '',
totalCount : 0,
pageNumber : 1,
pageSize : 10,
userId : ''
};
$scope.getList = function(){
railwayService.findUserRoleList($scope.vm).success(function(data){
if (data.errors == null || data.errors.length > 0) {
dialogService.tip(data.errors);
}else{
$scope.userRoleList = data.result;
$scope.vm.totalCount = data.totalCount;
}
})
};
$scope.getList();
$scope.doSearch = function(){
$scope.vm.pageNumber = 1;
$scope.getList();
};
};
var assignRoleController = function($scope,$modal,$http,$location,$interval,dialogService,railwayService,toolsService){
$scope.$emit('navShow', 7);
$scope.settingShow = 7;
$scope.vm = {
id: toolsService.parameter("id", $location.absUrl()),
account: '',
name: '',
permissionId: ''
};
// 当前用户权限信息
$scope.permission = {
id: '',
name: ''
};
// 所有权限的信息数据
$scope.allPermission = {};
// 所有权限信息下拉列表数据
$scope.allPermissionList = [];
// 获取所有权限信息
$scope.fndAllPermissionList = function(){
var request = {};
railwayService.getAllPermissionList(request).success(function(data){
if (data.errors == null || data.errors.length > 0) {
dialogService.tip(data.errors);
}else{
$scope.allPermission = data.result;
for (var i = 0; i < $scope.allPermission.length; i++) {
$scope.allPermissionList.push({
"id": $scope.allPermission[i].id,
"name": $scope.allPermission[i].name
});
}
}
})
};
// 获取所有权限信息
$scope.fndAllPermissionList();
// 获取当前用户的信息及权限
$scope.getUserAndPermission = function(){
railwayService.findUserAndPermission($scope.vm).success(function(data){
if (data.errors == null || data.errors.length > 0) {
dialogService.tip(data.errors);
}else{
$scope.vm.account = data.user.account;
$scope.vm.name = data.user.name;
if (data.user.permissionId != null ) {
$scope.permission.id = data.user.permissionId;
$scope.vm.permissionId = data.user.permissionId;
$scope.permission.name = data.user.roleName;
}
}
})
};
// 获取当前用户的信息及权限
$scope.getUserAndPermission();
$scope.getPermission = function () {
$scope.vm.permissionId = $scope.permission.id;
};
// 保存
$scope.doSave = function () {
// $scope.vm.roleId = $scope.permission.id;
railwayService.updateUserAndPermission($scope.vm).success(function(data){
if (data.errors == null || data.errors.length > 0) {
dialogService.tip(data.errors);
}else{
dialogService.tip([{message: "更新成功"}],"/admin/userRole/index.htm",1000);
$modalInstance.close();
}
})
};
};
var permissionImportController = function($scope, $http, $modal, railwayService, dialogService){
$scope.$emit('navShow', 7);
$scope.settingShow = 7;
$scope.errorOpen = function (errors, url) {
$scope.result = {};
$scope.result.errors = errors;
$scope.result.url = url;
var modalInstance = $modal.open({
templateUrl: "errors.html",
controller: ErrorController,
resolve: {
items: function () {
return $scope.result;
}
}
});
modalInstance.result.then(function () {
}, function () {
});
};
$scope.doImport = function () {
var file = document.getElementById("upImportFileId").files[0];
if (!file) {
dialogService.tip([{"message": "请上传文件!"}]);
return;
}
railwayService.importUserRecommendPermission(file).success(function (data) {
if (!data.url){
if (data.errors === null || data.errors.length > 0) {
dialogService.tip([{message: data.errors[0].message}]);
// $scope.errorOpen(errors, data.url);
} else {
dialogService.tip([{message: "导入成功!"}],"/admin/userRole/index.htm",1000);
$modalInstance.close();
}
} else {
if (data.errors === null || data.errors.length > 0) {
if (data.errors.length > 10) {
data.errors = data.errors.slice(0, 9);
}
$scope.errorOpen(data.errors, data.url);
}
}
});
};
$scope.downloadTemplate = function () {
railwayService.permissionOutputTemplate().success(function (data) {
if (data.errors == null || data.errors.length > 0) {
$scope.errorOpen(data.errors, data.url);
} else {
window.open(data.url, "_self");
}
});
};
};
var ErrorController = ["$scope", "$modalInstance", "items",
function ($scope, $modalInstance, items) {
$scope.errors = items.errors;
$scope.download = function () {
$scope.url = items.url;
window.open($scope.url, "_self");
$modalInstance.dismiss('cancel');
/*window.location = "/admin/userRole/import.htm";*/
};
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
/*window.location = "/admin/userRole/import.htm";*/
};
}];
angular.module("xn.page", ["xn.directive.form"])
.controller("UserRoleController",["$scope","$modal","$http","$interval","dialogService","RailwayService",userRoleController])
.controller("AssignRoleController",["$scope","$modal","$http","$location","$interval","dialogService","RailwayService","toolsService",assignRoleController])
.controller("PermissionImportController",["$scope", "$http", "$modal", "RailwayService", "dialogService",permissionImportController])
})();