flexSecurity 简单权限控制

最终效果:



首先把 flex_security.swc 放进你项目的lib文件中。

 

如图:


 

 

四种权限控制方式:

 

 

1. styleName

 

 

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark" 
			   xmlns:mx="library://ns.adobe.com/flex/mx" 
			   width="100%" height="100%"
			   viewSourceURL="http://code.google.com/p/flex-security/source/browse/trunk/flex_security_demo/src/helloworld_by_styleName.mxml"
			   creationComplete="creationComplete()">
	<s:layout>
		<s:VerticalLayout horizontalAlign="center"/>
	</s:layout>
	<fx:Script>
		<![CDATA[
			import cn.org.rapid_framework.flex_security.SecurityControler;
			
			import mx.collections.ArrayCollection;
			import mx.events.FlexEvent;

			[Bindable]
			private var permissionList : Array = ['cc','sq','lb','ta_input'];
			
			protected function creationComplete():void
			{
				//启动权限控制
				SecurityControler.start(null,'visible');
			}

		]]>
	</fx:Script>
	
	<s:HGroup>
		<mx:HBox>
			<mx:ComboBox id="permInput" dataProvider="{permissionList}"/>
			<mx:Button click="SecurityControler.addPerm(permInput.selectedLabel)" label="添加权限" />
			<mx:Button click="SecurityControler.removePerm(permInput.selectedLabel)" label="移除权限" />
			<mx:Button click="SecurityControler.addAllPerms(new ArrayCollection(permissionList))" label="添加所有权限" />
			<mx:Button click="SecurityControler.removeAllPerms()" label="移除所有权限" />	
		</mx:HBox>
	</s:HGroup>
	
	<s:HGroup>
		<!-- 通过styleName增加需要权限保护的组件,没有权限将不能进行相关操作 -->
		<mx:HBox>
			<!-- id要和声明的对应,enabled表示显现出来,由于受到权限的控制,不可启用-->
			<mx:Button label="曹操" id="cc" styleName="security(null,enabled)" />
			<!-- 没有声明id,那么在security内要写上 -->
			<mx:Button label="孙权" styleName="security(sq)"/>
			<!-- 注意这个remove属性,这里声明了remove,那么下面的组件就不受security的控制而会显现出来了 -->
			<mx:Button label="刘备" styleName="security(lb,remove)"/>
			<!-- 这个算是容易点的写法吧 -->
			<mx:TextArea id="ta_input" styleName="security"/>
		</mx:HBox>
	</s:HGroup>
</s:Application>

 

 

参考:helloworld_by_styleName

 

 

2. manual

 

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark" 
			   xmlns:mx="library://ns.adobe.com/flex/mx" 
			   width="100%" height="100%"
			   viewSourceURL="http://code.google.com/p/flex-security/source/browse/trunk/flex_security_demo/src/helloworld_by_manual.mxml"
			   creationComplete="creationComplete()">
	<s:layout>
		<s:VerticalLayout horizontalAlign="center"/>
	</s:layout>
	<fx:Script>
		<![CDATA[
			import cn.org.rapid_framework.flex_security.SecurityControler;
			
			import mx.collections.ArrayCollection;
			import mx.events.FlexEvent;
			
			[Bindable]
			private var permissionList : Array = ['cc','sq','lb','ta_input'];
			
			protected function creationComplete():void
			{
				//启动权限控制
				SecurityControler.start(null,'visible');
				
				//增加需要权限保护的UI资源
				SecurityControler.addSecurityAction(cc);
				SecurityControler.addSecurityAction(sq);
				SecurityControler.addSecurityAction(lb); 
			}
			
		]]>
	</fx:Script>
	
	<s:HGroup>
		<mx:HBox>
			<mx:ComboBox id="permInput" dataProvider="{permissionList}"/>
			<mx:Button click="SecurityControler.addPerm(permInput.selectedLabel)" label="添加权限" />
			<mx:Button click="SecurityControler.removePerm(permInput.selectedLabel)" label="移除权限" />
			<mx:Button click="SecurityControler.addAllPerms(new ArrayCollection(permissionList))" label="添加所有权限" />
			<mx:Button click="SecurityControler.removeAllPerms()" label="移除所有权限" />	
		</mx:HBox>
	</s:HGroup>
	
	<s:HGroup>
		<!-- 被权限控制的按钮,没有权限将看不见下面的相关按钮 -->
		<mx:HBox>
			<!-- 看见没有,主要还是id和permissionList声明的对应 -->
			<mx:Button label="曹操" id="cc"/>
			<mx:Button label="孙权" id="sq"/>
			<mx:Button label="刘备" id="lb"/>
			<mx:TextArea id="ta_input"/>
		</mx:HBox>
	</s:HGroup>
</s:Application>
 

参考:helloworld_by_manual

 

 

3. interface

 

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark" 
			   xmlns:mx="library://ns.adobe.com/flex/mx" 
			   width="100%" height="100%"
			   viewSourceURL="http://code.google.com/p/flex-security/source/browse/trunk/flex_security_demo/src/helloworld_by_interface.mxml"
			   implements="cn.org.rapid_framework.flex_security.ISecurityMetadata"
			   creationComplete="creationComplete()">
	<s:layout>
		<s:VerticalLayout horizontalAlign="center"/>
	</s:layout>
	<fx:Script>
		<![CDATA[
			import cn.org.rapid_framework.flex_security.SecurityAction;
			import cn.org.rapid_framework.flex_security.SecurityControler;
			//注意添加上面的实现---implements="cn.org.rapid_framework.flex_security.ISecurityMetadata"
			import cn.org.rapid_framework.flex_security.ISecurityMetadata;
			
			import mx.collections.ArrayCollection;
			import mx.events.FlexEvent;
			
			[Bindable]
			private var permissionList : Array = ['cc','sq','lb','ta_input'];
			
			protected function creationComplete():void
			{
				//启动权限控制
				SecurityControler.start(null,'visible');
			}
			
			//这里返回需要权限保护的UI资源
			public function getSecurityActions() : Array {
				return [
					new SecurityAction(cc),
					new SecurityAction(sq),
					new SecurityAction(lb)
				];
			}
			
		]]>
	</fx:Script>
	
	<s:HGroup>
		<mx:HBox>
			<mx:ComboBox id="permInput" dataProvider="{permissionList}"/>
			<mx:Button click="SecurityControler.addPerm(permInput.selectedLabel)" label="添加权限" />
			<mx:Button click="SecurityControler.removePerm(permInput.selectedLabel)" label="移除权限" />
			<mx:Button click="SecurityControler.addAllPerms(new ArrayCollection(permissionList))" label="添加所有权限" />
			<mx:Button click="SecurityControler.removeAllPerms()" label="移除所有权限" />	
		</mx:HBox>
	</s:HGroup>
	
	<s:HGroup>
		<!-- 被权限控制的按钮,没有权限将看不见下面的相关按钮 -->
		<mx:HBox>
			<!-- 看见没有,主要还是id和permissionList声明的对应 -->
			<mx:Button label="曹操" id="cc"/>
			<mx:Button label="孙权" id="sq"/>
			<mx:Button label="刘备" id="lb"/>
			<mx:TextArea id="ta_input"/>
		</mx:HBox>
	</s:HGroup>
</s:Application>
 

参考:helloworld_by_interface

 

 

4. annotation

 

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark" 
			   xmlns:mx="library://ns.adobe.com/flex/mx" 
			   width="100%" height="100%"
			   viewSourceURL="http://code.google.com/p/flex-security/source/browse/trunk/flex_security_demo/src/helloworld_by_annotation.mxml"
			   creationComplete="creationComplete()">
	<s:layout>
		<s:VerticalLayout horizontalAlign="center"/>
	</s:layout>
	
	<!-- 通过元数据[Protected(id='compId',permission='perm',controlBy='enabled')]确定那个UI组件需要权限保护 -->
	<fx:Metadata>
		[Protected(id="cc")]
		[Protected(id="sq")]
		[Protected(id="lb")]
	</fx:Metadata>
	
	<fx:Script>
		<![CDATA[
			import cn.org.rapid_framework.flex_security.SecurityControler;
			
			import mx.collections.ArrayCollection;
			import mx.events.FlexEvent;
			
			[Bindable]
			private var permissionList : Array = ['cc','sq','lb','ta_input'];
			
			protected function creationComplete():void
			{
				//启动权限控制
				SecurityControler.start(null,'visible');
			}
			
		]]>
	</fx:Script>
	
	<s:HGroup>
		<mx:HBox>
			<mx:ComboBox id="permInput" dataProvider="{permissionList}"/>
			<mx:Button click="SecurityControler.addPerm(permInput.selectedLabel)" label="添加权限" />
			<mx:Button click="SecurityControler.removePerm(permInput.selectedLabel)" label="移除权限" />
			<mx:Button click="SecurityControler.addAllPerms(new ArrayCollection(permissionList))" label="添加所有权限" />
			<mx:Button click="SecurityControler.removeAllPerms()" label="移除所有权限" />	
		</mx:HBox>
	</s:HGroup>
	
	<s:HGroup>
		<mx:HBox>
			<mx:Button label="曹操" id="cc"/>
			<mx:Button label="孙权" id="sq"/>
			<mx:Button label="刘备" id="lb"/>
			<mx:TextArea id="ta_input"/>
		</mx:HBox>
	</s:HGroup>
</s:Application>

 

参考:helloworld_by_annotation

 

 

按实际情况抉择使用

 

在当今计算机视觉领域,深度学习模型在图像分割任务中发挥着关键作用,其中 UNet 是一种在医学影像分析、遥感图像处理等领域广泛应用的经典架构。然而,面对复杂结构和多尺度特征的图像,UNet 的性能存在局限性。因此,Nested UNet(也称 UNet++)应运而生,它通过改进 UNet 的结构,增强了特征融合能力,提升了复杂图像的分割效果。 UNet 是 Ronneberger 等人在 2015 年提出的一种卷积神经网络,主要用于生物医学图像分割。它采用对称的编码器 - 解码器结构,编码器负责提取图像特征,解码器则将特征映射回原始空间,生成像素级预测结果。其跳跃连接设计能够有效传递低层次的细节信息,从而提高分割精度。 尽管 UNet 在许多场景中表现出色,但在处理复杂结构和多尺度特征的图像时,性能会有所下降。Nested UNet 通过引入更深层次的特征融合来解决这一问题。它在不同尺度上建立了密集的连接路径,增强了特征的传递与融合。这种“嵌套”结构不仅保持了较高分辨率,还增加了特征学习的深度,使模型能够更好地捕获不同层次的特征,从而显著提升了复杂结构的分割效果。 模型结构:在 PyTorch 中,可以使用 nn.Module 构建 Nested UNet 的网络结构。编码器部分包含多个卷积层和池化层,并通过跳跃连接传递信息;解码器部分则包含上采样层和卷积层,并与编码器的跳跃连接融合。每个阶段的连接路径需要精心设计,以确保不同尺度信息的有效融合。 编码器 - 解码器连接:Nested UNet 的核心在于多层次的连接。通过在解码器中引入“skip connection blocks”,将编码器的输出与解码器的输入相结合,形成一个密集的连接网络,从而实现特征的深度融合。 训练与优化:训练 Nested UNet 时,需要选择合适的损失函数和优化器。对于图像分割任务,常用的损失
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值