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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
(function(){
angular.module("app.manage")
.controller("authCtrl",["$rootScope","$scope","HttpService","ToolService","UtilService","$state",authCtrl])
.controller("authDetailCtrl",["$rootScope","$scope","HttpService","ToolService","UtilService","$q","$state","$stateParams",authDetailCtrl]);
function authCtrl($rootScope,$scope,HttpService,ToolService,UtilService,$state){
$scope.demoUSuper = UtilService.getUser().email == 'demoadmin@reyun.com';
$scope.deviceList = [
{id:1,name:"已启用"},
{id:2,name:"已停用"}
];
$scope.deviceInit = $scope.deviceList[0].id;
$scope.$on("deviceId",function(e,msg){
$scope.seeFlag = msg.info.id;
if( $scope.seeFlag == 1){
$scope.findName = 'enable';
}else{
$scope.findName = 'disable';
}
$scope.query();
});
if(!$rootScope.accountFlag){
$rootScope.accountFlag = "account";
}
$scope.query = function(flag){
if(flag){
$rootScope.accountFlag = flag;
$rootScope.thirdtab = '子账号管理';
}
if(angular.isUndefined($scope.findName)){return false;}
$scope.authList = [];
var authPM = HttpService.getInfo("mng/auth"+$scope.getSuburl()+"/list/"+$scope.findName);
ToolService.showLoading();
authPM.then(function(data){
ToolService.hideLoading();
$scope.authList = data;
});
}
$scope.query();
$scope.$on('flipinfo',function(e,msg){
$scope.flipPage = msg;
});
$scope.wantOn = false;
$scope.doOpen = function(info){
$scope.curOnId = info.id;
if(info.isSpecialAccount=="1"){
$scope.wantOn = true;
ToolService.showAlp();
}
else{
$scope.onUser($scope.curOnId);
}
}
$scope.onUser = function(id){
if($scope.wantOn){
$scope.closeOn();
}
ToolService.showLoading();
var userPM = HttpService.putInfo("mng/auth"+$scope.getSuburl()+"/"+id+"/enable");
userPM.then(function(data){
ToolService.hideLoading();
ToolService.showTips("启用成功");
$rootScope.operSubmitData("启用");
$scope.query();
});
}
$scope.closeOn = function(){
$scope.wantOn = false;
ToolService.hideAlp();
}
$scope.offUser = function(id){
var userPM = HttpService.putInfo("mng/auth"+$scope.getSuburl()+"/"+id+"/disable");
ToolService.showLoading();
userPM.then(function(data){
ToolService.hideLoading();
ToolService.showTips("停用成功");
$rootScope.operSubmitData("停用");
$scope.query();
});
}
$scope.deleteAuth = function(d){
$scope.delInfo = d;
$scope.wantDelete = true;
ToolService.showAlp();
}
$scope.doDelete = function(){
$scope.closeWin();
ToolService.showLoading();
var deletePM = HttpService.deleteInfo("mng/auth/"+$scope.delInfo.id+"/delete");
deletePM.then(function(data){
ToolService.hideLoading();
if(data){
ToolService.showTips("删除成功");
$scope.query();
}
else{
ToolService.showTips("该账号已激活,不支持删除,您可以在右侧操作区对账号进行停用。");
}
});
}
$scope.sendEmailAgain = function(send){
var sendPM = HttpService.postInfo("mng/auth/mail/"+send.id+"/resend");
ToolService.showLoading();
sendPM.then(function(data){
ToolService.hideLoading();
send.send = 1;
ToolService.showTips("发送成功");
});
}
$scope.closeWin = function(flag){
$scope.wantDelete = false;
ToolService.hideAlp();
}
$scope.gopage = function(info){
if(angular.isDefined(info)){
if(!info.valid){return false;}
$state.go("collect.authDetail",{aid:info.id});
}else{
$state.go("collect.authDetail");
}
}
$scope.getSuburl = function(){
var suburl = "";
if($rootScope.accountFlag == 'channel'){
suburl = "/channel";
}
return suburl;
}
$scope.isdetail = false;
$scope.showDetails = function(info){
$scope.detailInfo = info;
ToolService.showAlp();
$scope.isdetail = true;
angular.element(document).on("click",function(){
$scope.$apply(function(){
$scope.hideDetails();
});
});
}
$scope.hideDetails = function(){
ToolService.hideAlp();
$scope.isdetail = false;
}
}
var copyArray = function(arr){
return $.extend(true, [], arr);
}
function authDetailCtrl($rootScope,$scope,HttpService,ToolService,UtilService,$q,$state,$stateParams){
var infoId = $scope.id = $stateParams.aid;
$scope.$watch("applistInfo",function(data){
if(angular.isDefined(data)){
$scope.authapplist = copyArray(data);
if($scope.isAppManage && !UtilService.isNullStr(infoId)){
var hasAuthAppsPM = HttpService.getInfo("app/find/"+infoId+"/AuthApp");
hasAuthAppsPM.then(function(data){
$scope.init(data);
});
}
else{
$scope.init();
}
}
});
$scope.init = function(otherpowers){
if(!UtilService.isNullStr(infoId)){
ToolService.showLoading();
var accountPM = HttpService.getInfo("mng/auth/"+infoId+"/find");
accountPM.then(function(data){
ToolService.hideLoading();
$scope.accountInfo = data;
$scope.email = $scope.oldEmail = data.email;
$scope.name = data.name;
$scope.remark = data.remark;
$scope.parentRole = data.parentRole;
if(UtilService.isNullStr(data.name)){
$scope.nameNofix = false;
}else{
$scope.nameNofix = true;
}
$scope.roleCategory = data.roleCategory;
if($scope.roleCategory == 2){
$scope.authapplist = copyArray($scope.appAlllistInfo);
}
else{
$scope.authapplist = copyArray($scope.applistInfo);
}
if($scope.isAppManage){
var appids = [];
$scope.authapplist.filter(function(item){
appids.push(item.id);
});
otherpowers.filter(function(item){
if(appids.indexOf(item.id)==-1){
item.nopower = true;//当前子应用没有该app权限
$scope.authapplist.push(item);
}
});
}
var authStr = data.authList;
authStr.filter(function(power){
for(var i=0;i<$scope.authapplist.length;i++){
var appinfo = $scope.authapplist[i];
if(appinfo.id == power.app){
$scope.authapplist[i].ischeck = true;
break;
}
}
});
$scope.steps = 1;
if($scope.roleCategory == 1){
$scope.steps = 0;
$scope.maxstep = 0;
}
else if($scope.roleCategory == 2){//子应用管理员
$scope.maxstep = 1;
}
});
}
}
$scope.steps = 0;
$scope.maxstep = 0;
$scope.changeRole = function(flag){
switch(flag){
case 1: //管理员
$scope.steps = 0;
$scope.maxstep = 0;
break;
case 2: //子应用管理员
$scope.steps = 1;
$scope.maxstep = 1;
break;
default:
break;
}
if(flag == 2){ //子应用管理员可以赋予未调式的产品
$scope.authapplist = copyArray($scope.appAlllistInfo);
}
else{
$scope.authapplist = copyArray($scope.applistInfo);
}
$scope.roleCategory = flag;
}
$scope.getTips = function(app){
if(app.nopower){
return "该应用权限由管理员添加,您无此应用权限";
}
else{
return "";
}
}
//全选操作
$scope.doCheck = function(k){
var bol = $scope.isAllCheck = !$scope.isAllCheck;
if(k == 'app'){ //选择应用时的全选
$scope.authapplist.filter(function(item){
if(!item.nopower){
item.ischeck = bol;
}
});
}
}
$scope.isAllCheck = false;
//第一步选择app
$scope.selectApp = function(app){
app.ischeck = true;
var checkbol = true;
for(var i=0;i<$scope.authapplist.length;i++){
var item = $scope.authapplist[i];
if(!item.nopower && !item.ischeck){
checkbol = false;
break;
}
}
$scope.isAllCheck = checkbol;
}
$scope.removeApp = function(app){
if(app.nopower){return false;}
app.ischeck = false;
$scope.isAllCheck = false;
}
$scope.nameNofix = false;
$scope.save = function(){
var par = {
"email":$scope.email,
"name":$scope.name,
"roleCategory":$scope.roleCategory,
"remark":$scope.remark
};
var verPar = {
email:{
key:"email",
val:par.email,
nullTxt:"请填写邮箱"
},
name:{
key:"numLetter",
val:par.name,
nullTxt:"请填写姓名",
max:20,
txt:"请输入20位以内的中英文或数字"
}
};
if(!UtilService.isNullStr(par.remark)){
verPar.remark = {
key:'nameLen',
val:par.remark,
max:200,
txt:'最多可输入100字'
}
}
$scope.tip = formJudge(verPar);
if($scope.tip.succ != true) {
ToolService.showTips($scope.formTipMsg);
return false;
}
else if(!$scope.roleCategory){
ToolService.showTips("请选择角色");
return false;
}
if($scope.roleCategory ==2 ){
var appAuth = [];
$scope.authapplist.filter(function(item){
if(item.ischeck){
appAuth.push({app:item.id});
}
});
if(appAuth.length == 0){
ToolService.showTips("请选择应用");
return false;
}
par.authList = appAuth;
}
var savePM = null,txtTips = "已为该账号发送激活邮件,请在72小时内联系相关人员激活并设置密码";
if(infoId!=null){
par.id = infoId;
savePM = HttpService.putInfo("mng/auth"+$scope.getSuburl()+"/"+infoId+"/update",par);
txtTips = "修改成功";
}
else{
savePM = HttpService.postInfo("mng/auth"+$scope.getSuburl()+"/create",par);
}
ToolService.showLoading();
savePM.then(function(data){
if(data.code == -6001){
ToolService.hideLoading();
ToolService.showTips("该邮箱已创建");
}
else if(data.code == -300){
ToolService.hideLoading();
ToolService.showTips("最多可添加3个管理员");
}
else{
ToolService.hideLoading();
ToolService.showTips(txtTips);
$scope.cancel();
if(!infoId){
$rootScope.operSubmitData("新建");
}
}
},function(data){
if(data.code == -6001){
ToolService.hideLoading();
ToolService.showTips("该邮箱已创建");
}else if(data.code == -300){
ToolService.hideLoading();
ToolService.showTips("最多可添加3个管理员");
}
});
}
$scope.getSuburl = function(){
var suburl = "";
if($scope.accountFlag == 'channel'){
suburl = "/channel";
}
return suburl;
}
$scope.cancel = function(){
$state.go("collect.auth");
}
}
})();