ExtJs页面元素权限控制

带有权限控制的安钮组件: Ext.define(matrix.sys.view.authority.XButton, { extend : Ext.button.Button, alternateClassName : [ Ext.authority.XButton ], alias : widget.xButton, requires : [ matrix.sys.store.AuthorityButtonStore ], stores : [ authorityButtonStore ], initComponent : function() { var disabled=false; //取得当前登陆用户拥有的页面元素权限 var store = Ext.data.StoreManager.lookup(authorityButtonStore); //判断是否可见 if(store && this.buttonAlias){ if(!store.getById(this.buttonAlias)){ disabled=true; } } Ext.apply(this, { cls : this.buttonAlias, hidden : this.hidden?this.hidden: disabled, border : 1 }); this.callParent(arguments); } }); 其中authorityButtonStore的访问路径 /matrix/sysSubButton/getByCurrentUser.do 将会读取当前登陆用户所拥有的全部页面元素权限,并绶存于authorityButtonStore当中。 用法: { xtype : xButton, text : Ext.Res.getText(add), buttonAlias:SysUserView.add, iconCls : btn-add, action : add } 这个只是button的案例,其实其它的页面元素也可以安照这个思路来扩展。

带有权限控制的安钮组件: Ext.define(matrix.sys.view.authority.XButton, { extend : Ext.button.Button, alternateClassName : [ Ext.authority.XButton ], alias : widget.xButton, requires : [ matrix.sys.store.AuthorityButtonStore ], stores : [ authorityButtonStore ], initComponent : function() { var disabled=false; //取得当前登陆用户拥有的页面元素权限 var store = Ext.data.StoreManager.lookup(authorityButtonStore); //判断是否可见 if(store && this.buttonAlias){ if(!store.getById(this.buttonAlias)){ disabled=true; } } Ext.apply(this, { cls : this.buttonAlias, hidden : this.hidden?this.hidden: disabled, border : 1 }); this.callParent(arguments); } }); 其中authorityButtonStore的访问路径 /matrix/sysSubButton/getByCurrentUser.do 将会读取当前登陆用户所拥有的全部页面元素权限,并绶存于authorityButtonStore当中。 用法: { xtype : xButton, text : Ext.Res.getText(add), buttonAlias:SysUserView.add, iconCls : btn-add, action : add } 这个只是button的案例,其实其它的页面元素也可以安照这个思路来扩展。
经验分享 程序员 微信小程序 职场和发展