SingletonLoginUser

package cn.com.jgt.view
{
import flash.errors.IllegalOperationError;

/**
* actionscript类的构造方法不能是private,只能借助于包外类实现单例模式
*/
public class SingletonLoginUser
{
/**声明一个当前类的私有实例*/
private static var loginUser:LoginUser=null;

public function Singleton():void
{
throw new IllegalOperationError("Can't new SingletonFactory(),Please call getInstance()!");
}

/**构造方法需要传入一个包外类SingleClass的实例*/
public static function getInstance():LoginUser{
if(SingletonLoginUser.loginUser==null){
SingletonLoginUser.loginUser=new LoginUser();
}
return SingletonLoginUser.loginUser;
}
}
}

/**
* 在package声明之外的源代码只在本源文件中可见。
* 保存用户登录信息,包括用户名,区域,权限,部门等。
* 保存系统配置文件信息以及行政区域数据等。
*/
import flash.utils.describeType;

import mx.collections.ArrayCollection;

import cn.com.jgt.common.CommonUtils;
import cn.com.jgt.widgets.BusinessManage.PingTaiPeiZhi.EncapsulationInfos.UserInfo;

class LoginUser {
//登录用户信息
public var userInfo:UserInfo=new UserInfo();
//功能集合
public var functionCollection:ArrayCollection=new ArrayCollection();
//部门名称
public var branchName:String=new String();
//部门id
public var branchId:String=new String();
//行政区域 到村、到组
public var regionTreeRefGroup:String =new String();
public var regionTreeRefVillage:String =new String();
//保存配置文件信息
public var ServerConfig:XML = new XML();
public var LayerConfig:XML = new XML();
//用户部门权属
public var quanshu:String="";

/** 设置登录用户信息 */
public function setUserInfo(user:UserInfo):void{
this.userInfo=user;
}

/** 获取登录用户信息 */
public function getUserInfo():UserInfo{
return this.userInfo;
}

/**
* 遍历页面控件,验证各类控件是否具备操作权限。
* 验证包括按钮(Button),标签(Label),图片(Image),表格框列(GridColumn)控件的权限
*/
public function checkQuanxian(object:Object):void{

var instanceInfo:XML = describeType(object);
//输出xml
//trace(instanceInfo);

//获取所有的Button控件并验证权限(根据Button的name属性值验证权限)
var prop_btn:XMLList =instanceInfo.accessor.(@type=="spark.components::Button")
// 遍历Button信息
for each(var propertyInfo:XML in prop_btn) {
/*
* propertyInfo.@name //获取Button的id
* object[propertyName] //根据Button的id获取Button对象
* object[propertyName].name //根据Button的id获取Button对象的name属性值
* Button未定义name属性值时,name属性值为系统默认,如Button12321;定义了name属性时,获取name属性值
*/
var propertyName:String = propertyInfo.@name; // 获取Button的id
if(null!=object[propertyName]){ //获取的Button对象不为空时
if((object[propertyName].name).substring(0,6)!="Button"){ //如果Button指定了name属性,验证其权限
if((object[propertyName].name).substring(0,5)=="MENU_"){ //验证是否满足权限名称格式规范
if(checkYorN(object[propertyName].name)){ //校验权限,具备权限显示
object[propertyName].visible=true;
object[propertyName].includeInLayout=true;
}else{ //不具备权限影藏
object[propertyName].visible=false;
object[propertyName].includeInLayout=false;
}
}
}
}
}

//获取所有的label控件并验证权限(根据Label的name属性值验证权限,Label必须指定id属性)
var prop_label:XMLList = instanceInfo.accessor.(@type=="spark.components::Label");
// 遍历label信息
for each(var propertyInfo1:XML in prop_label) {
var propertyName1:String = propertyInfo1.@name; // 获取label的id
if(null!=object[propertyName1]){ //获取的label对象不为空时
if((object[propertyName1].name).substring(0,5)!="Label"){ //如果Label指定了name属性,验证其权限
if((object[propertyName1].name).substring(0,5)=="MENU_"){ //验证是否满足权限名称格式规范
if(checkYorN(object[propertyName1].name)){ //校验权限,具备权限显示
object[propertyName1].visible=true;
object[propertyName1].includeInLayout=true;
}else{ //不具备权限影藏
object[propertyName1].visible=false;
object[propertyName1].includeInLayout=false;
}
}
}
}
}

//获取所有的Image控件并验证权限(根据Image的id属性值验证权限)
var prop_image:XMLList =instanceInfo.accessor.(@type=="spark.components::Image");
// 遍历Image信息
for each(var propertyInfo2:XML in prop_image) {
var propertyName2:String = propertyInfo2.@name; // 获取Image的id
if(null!=object[propertyName2]){ //获取的Image对象不为空时
if((object[propertyName2].id).substring(0,5)!="Image"){ //如果Image指定了id属性,验证其权限
if((object[propertyName2].id).substring(0,5)=="MENU_"){ //验证是否满足权限名称格式规范
if(checkYorN(object[propertyName2].id)){ //校验权限,具备权限显示
object[propertyName2].visible=true;
object[propertyName2].includeInLayout=true;
}else{ //不具备权限影藏
object[propertyName2].visible=false;
object[propertyName2].includeInLayout=false;
}
}
}
}
}

//获取所有的GridColumn控件并验证权限(根据GridColumn的id属性值验证权限)
var prop_gridColumn:XMLList = instanceInfo.accessor.(@type=="spark.components.gridClasses::GridColumn");
// 遍历GridColumn信息
for each(var propertyInfo3:XML in prop_gridColumn) {
var propertyName3:String = propertyInfo3.@name; // 获取GridColumn的id
if(null!=object[propertyName3]){ //获取的GridColumn对象不为空时
if(propertyName3.substring(0,4)!="Grid"){ //如果GridColumn指定了id属性,验证其权限
if(propertyName3.substring(0,5)=="MENU_"){ //验证是否满足权限名称格式规范
if(checkYorN(propertyName3)){ //校验权限,具备权限显示
object[propertyName3].visible=true;
}else{ //不具备权限影藏
object[propertyName3].visible=false;
}
}
}
}
}

//获取所有的HGroup控件并验证权限(根据HGroup的name属性值验证权限,HGroup必须指定id属性)
var prop_HGroup:XMLList =instanceInfo.accessor.(@type=="spark.components::HGroup");
//遍历HGroup信息
for each(var propertyInfo4:XML in prop_HGroup) {
var propertyName4:String = propertyInfo4.@name; // 获取HGroup的name
if(null!=object[propertyName4]){ //获取的HGroup对象不为空时
if((object[propertyName4].name).substring(0,6)!="HGroup"){ //如果HGroup指定了name属性,验证其权限
if((object[propertyName4].name).substring(0,5)=="MENU_"){ //验证是否满足权限名称格式规范
if(checkYorN(object[propertyName4].name)){ //校验权限,具备权限显示
object[propertyName4].visible=true;
object[propertyName4].includeInLayout=true;
}else{ //不具备权限影藏
object[propertyName4].visible=false;
object[propertyName4].includeInLayout=false;
}
}
}
}
}

//获取所有的DropDownList控件并验证权限(根据DropDownList的name属性值验证权限,DropDownList必须指定id属性)
var prop_DropDownList:XMLList =instanceInfo.accessor.(@type=="spark.components::DropDownList");
//遍历DropDownList信息
for each(var propertyInfo5:XML in prop_DropDownList) {
var propertyName5:String = propertyInfo5.@name; // 获取DropDownList的name
if(null!=object[propertyName5]){ //获取的DropDownList对象不为空时
if((object[propertyName5].name).substring(0,12)!="DropDownList"){ //如果DropDownList指定了name属性,验证其权限
if((object[propertyName5].name).substring(0,5)=="MENU_"){ //验证是否满足权限名称格式规范
if(checkYorN(object[propertyName5].name)){ //校验权限,具备权限显示
object[propertyName5].visible=true;
object[propertyName5].includeInLayout=true;
}else{ //不具备权限影藏
object[propertyName5].visible=false;
object[propertyName5].includeInLayout=false;
}
}
}
}
}

}

/** 根据属性name来判断是否有相应的权限 */
public function checkYorN(name:String):Boolean{
for(var j:int=0;j<functionCollection.length;j++){
if(name==functionCollection.getItemAt(j).funcId){
return true;
}
}
return false;
}

/**
* 根据用户所具有的权属(ownership)过滤对应的各个业务的业务类别
* @param typeArrColl 需要过滤的数据集合
* @param matchProprety 匹配集合的属性
*/
public function filterCmbItemAuthorityByQs(typeArrColl:ArrayCollection):ArrayCollection
{
var ownerShip:String = CommonUtils.covertOwnership(userInfo.ownershop); //获取登录用户所拥有的权属并转换为名称
var result:Array = ownerShip.split(','); //转换为数组
for(var i:int=0;i<typeArrColl.length;i++){ //遍历需要过滤的数据集合
var b:Boolean=false;
if(CommonUtils.isEmptyStr(typeArrColl[i].qs)){ //过滤查询所有的项
continue;
}
for(var j:int=0;j<result.length;j++){ //遍历匹配
if(typeArrColl[i].qs == result[j]){
b = true;
break;
}else{
b = false;
}
}
if(!b){ //过滤数据
typeArrColl.removeItemAt(i);
i--;
}
}
return typeArrColl;
}

}

posted @ 2017-02-24 11:04  小拽A  阅读(202)  评论(0编辑  收藏  举报