appAccessCtrl.js 4.21 KB
(function(angular) {
	function appAccessCtrl($scope, DTOptionsBuilder, DTColumnBuilder, dopService,$uibModal, $filter, $state, $rootScope,SweetAlertX) {		
		$scope.dtColumns = [
		    DTColumnBuilder.newColumn('appId').withOption('width',80).withTitle('应用ID'),
		    DTColumnBuilder.newColumn('appName').withOption('width',60).withTitle('应用名称'),
		    DTColumnBuilder.newColumn('appPrincipal').withOption('width',80).withTitle('应用主体'),
		    DTColumnBuilder.newColumn('appKey').withOption('width',180).withTitle('应用Key').renderWith(function(e, dt, node, config){
		    	if($rootScope.loginUser.isSuper){
		    		return node.appKey;
		    	}else{
		    		return $scope.replacepos(node.appKey, 8, 23, '****************')
		    	}
		    }),
		    DTColumnBuilder.newColumn('appSecret').withOption('width',180).withTitle('应用秘钥').renderWith(function(e, dt, node, config){
		    	if($rootScope.loginUser.isSuper){
		    		return node.appSecret;
		    	}else{
		    		return $scope.replacepos(node.appSecret, 16, 31, '****************')
		    	}
		    }),
		    DTColumnBuilder.newColumn('appStatus').withOption('width',60).withTitle('应用状态').renderWith(function(e, dt, node, config){
            	if(node.appStatus == 1){
            		return '启用';
            	}else if(node.appStatus == 2){
            		return '停用';
            	}else if(node.appStatus == 3){
            		return '异常';
            	}
            	return "";
            }),
            DTColumnBuilder.newColumn('updatedDate').withOption('width',120).withTitle('更新时间').renderWith(function(e, dt, node, config){
            	return $filter('date')(new Date(node.updatedDate), 'yyyy-MM-dd HH:mm:ss');
            })
        ];
		if($rootScope.loginUser.isSuper){
			$scope.dtColumns.push(DTColumnBuilder.newColumn(null).withTitle(function(){
            	return '操作';
            }).withOption('width', 120).withClass('text-center').renderWith(function(data, type, full, oSettings) {
            	var str = '<div class="form-inline">'
            		+'<div class="form-group"><a class="btn btn-link" ng-click="appService('+ data.id +')">已授权服务</a></div>'
	                +'<div class="form-group"><a class="btn btn-link" ng-click="createOrUpdate('+ data.id +')">修改</a></div>';
	            str += '</div>';
                return str;
            }))
		}
		$scope.dtOptions = DTOptionsBuilder.newOptions()
		.withOption('id','id')
		.withFixedColumns({
              rightColumns: 1
         });

		$scope.dtInstance = {
			serverData : dopService.searchAppAccess
		};

		$scope.getParams =function(){
			var condition = {};
			if($scope.appName){
				condition.appName = $scope.appName;
			}
			if($scope.appId){
				condition.appId = $scope.appId;
			}
			return {'condition':condition};
		}


		//查询
		$scope.submitForm = function(){
			$scope.dtInstance.query($scope.getParams());
		}
		
		$scope.createOrUpdate = function (id) {
	        $uibModal.open({
	            templateUrl: 'biz/dop/view/appAccessDialog.html',
	            controller: 'appAccessDialogCtrl',
	            size: 'lg',
	            resolve: {
	                params: function () {
	                    return {'id':id}
	                }
	            }
	        }).result.then(function (data) {
	        	$scope.dtInstance.query($scope.getParams());
	        },function(){
	        	$scope.dtInstance.query($scope.getParams());
	        })
	    };
	    
	    // 授权服务
	    $scope.appService = function (id) {
	    	$uibModal.open({
	            templateUrl: 'biz/dop/view/appServiceDialog.html',
	            controller: 'appServiceDialogCtrl',
	            size: 'lg',
	            resolve: {
	                params: function () {
	                    return {'id':id}
	                }
	            }
	        }).result.then(function (data) {
	        	$scope.dtInstance.query($scope.getParams());
	        },function(){
	        	$scope.dtInstance.query($scope.getParams());
	        })
	    }
	    
	    $scope.replacepos = function (text, start, stop, replacetext){
	      	 var mystr = text.substring(0,start-1) + replacetext + text.substring(stop);
	      	 return mystr;
	    }
	    
	}

	angular.module('dop').controller('appAccessCtrl', appAccessCtrl)
})(angular);