SysResourceService.js 5.5 KB
"use strict";
var sysResourceService = angular.module('SysResourceService',[]);

sysResourceService.service("SysResourceService", [
	'$rootScope',
	'BaseService',
	function ($rootScope,BaseService) {
		var _service = {
				users:[],
				logs:[],
				addSysResource:function(resource, callback){
					var url = resource.id != 0 ? BaseService.url.editSysResource_url : BaseService.url.addSysResource_url;
					BaseService.request({
						url:url,
						method:'post',
						mark:true,
						data:resource,
						fn:function(response) {
							BaseService.updateAlert(response.message,response.code);
							callback.call(this,response);
						}
					});
				},
				deleteSysResource:function(id, callback) {
					BaseService.request({
						url:BaseService.url.deleteSysResource_url+id,
						method:'get',
						mark:true,
						fn:function(response) {
							BaseService.updateAlert(response.message,response.code);
							callback.call(this,response);
						}
					});
				},
				getSysResource:function(id,callback){
					BaseService.request({
						url:BaseService.url.getSysResource_url+id,
						method:'get',
						mark:true,
						fn:function(response) {
							callback.call(this,response);
						}
					});
				},
				getTreeSysResource:function(callback){
					BaseService.request({
						url:BaseService.url.getTreeSysResource_url,
						method:'get',
						mark:true,
						fn:function(response) {
							callback.call(this,response);
						}
					});
				},
				getParentSysResource:function(id, callback){
					BaseService.request({
						url:BaseService.url.getParentSysResource_url+id,
						method:'get',
						mark:true,
						fn:function(response) {
							callback.call(this,response);
						}
					});
				},
				addSysRole:function(role) {
					var url = role.id ? BaseService.url.editSysRole_url+role.id : BaseService.url.addSysRole_url;
					BaseService.request({
						url:url,
						method:'post',
						mark:true,
						data:role,
						fn:function(response) {
							BaseService.updateAlert(response.message,response.code);
							if(response.code == 0) {
								window.history.go(-1);
							}
						}
					});
				},
				deleteSysRole:function(id, callback) {
					BaseService.request({
						url:BaseService.url.deleteSysRole_url+id,
						method:'get',
						mark:true,
						fn:function(response) {
							BaseService.updateAlert(response.message,response.code);
							callback.call(this,response);
						}
					});
				},
				getSysRole:function (id, callback) {
					BaseService.request({
						url:BaseService.url.getSysRole_url+id,
						method:'get',
						mark:true,
						fn:function(response) {
							callback.call(this,response);
						}
					});
				},
				allocationRoleResource:function(role) {
					BaseService.request({
						url:BaseService.url.allocationRoleResource_url,
						method:'post',
						mark:true,
						data:role,
						fn:function(response) {
							BaseService.updateAlert(response.message,response.code);
							if(response.code == 0) {
								window.history.go(-1);
							}
						}
					});
				},
				getRoleResource:function(id, callback) {
					BaseService.request({
						url:BaseService.url.getRoleResource_url+id,
						method:'get',
						mark:true,
						fn:function(response) {
							callback.call(this,response);
						}
					});
				},
				listSysRole:function(callback) {
					BaseService.request({
						url:BaseService.url.listSysRole_url,
						method:'get',
						mark:true,
						fn:function(response) {
							callback.call(this,response);
						}
					});
				},
				listUser:function(userQuery) {
					BaseService.request({
						url:BaseService.url.pagerSysUser_url,
						method:'post',
						mark:true,
                        data:userQuery,
						fn:function(response) {
							if(response.code == 0) {
								_service.users = response.data;
								$rootScope.$broadcast('user.list');
							}
						}
					});
				},
				addSysUser:function(user) {
					var url = user.id ? BaseService.url.editSysUser_url : BaseService.url.addSysUser_url;
					BaseService.request({
						url:url,
						method:'post',
						mark:true,
						data:user,
						fn:function(response) {
							BaseService.updateAlert(response.message,response.code);
							if(response.code == 0) {
								window.history.go(-1);
							}
						}
					});
				},
				getSysUser:function(id, callback) {
					BaseService.request({
						url:BaseService.url.getSysUser_url+id,
						method:'get',
						mark:true,
						fn:function(response) {
							callback.call(this,response);
						}
					});
				},
				lockedUser:function(user, callback) {
					BaseService.request({
						url:BaseService.url.lockedUser_url,
						method:'post',
						mark:true,
						data:user,
						fn:function(response) {
							BaseService.updateAlert(response.message,response.code);
							callback.call(this,response);
						}
					});
				},
				resetUserPassword:function(user) {
					BaseService.request({
						url:BaseService.url.resetUserPassword_url,
						method:'post',
						mark:true,
						data:user,
						fn:function(response) {
							BaseService.updateAlert(response.message,response.code);
							if(response.code == 0) {
								window.history.go(-1);
							}
						}
					});
				},
				listLog:function(pageNow, pageSize, logType) {
					BaseService.request({
						url:BaseService.url.pagerSysLog_url+"?pageNow="+pageNow+"&pageSize="+pageSize+"&logType="+logType,
						method:'get',
						mark:true,
						fn:function(response) {
							if(response.code == 0) {
								_service.logs = response.data;
								$rootScope.$broadcast('log.list');
							}
						}
					});
				},
		}
		return _service;
	}]);