Chinaunix首页 | 论坛 | 博客
  • 博客访问: 347789
  • 博文数量: 26
  • 博客积分: 495
  • 博客等级: 下士
  • 技术积分: 562
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-26 13:50
文章分类

全部博文(26)

文章存档

2015年(9)

2014年(6)

2013年(7)

2012年(2)

2011年(2)

分类: JavaScript

2013-09-11 10:16:35

管理系统都会有自己的logo界面,在Extjs 中,通常有三种方式可以实现页面logo + 工具栏
1.使用纯html方式实现,在定义的north panel中html配置项目,例如如下例子:

点击(此处)折叠或打开

  1. var head = new Ext.Panel({
  2.         region : 'north',
  3.         border : false,
  4.         bodyStyle: 'background:#385975',
  5.         height : 100,
  6.         html:'
    '
  7.              +'
    当前用户: '
  8.              +user_name+'|修改密码 | 退出
',
  •         })
  • 我之前的logo是这样做,发现工具栏的handler函数太难定义了,scope的问题很多,如果使用全局变量的话,又显得很凌乱,不推荐这种方法

    2.使用html 加 toolbar 的组合,例如:

    点击(此处)折叠或打开

    1. var head = new Ext.Panel({
    2.         region : 'north',
    3.         border : false,
    4.         bodyStyle: 'background:#385975',
    5.         height : 100,
    6.         html:'
      ',
    7.         tbar:['->',
    8.             {
    9.                 xtype:'label',
    10.                 text:'当前用户:'
    11.                 height:30,
    12.             },
    13.             '-',{
    14.                 xtype:'label',
    15.                 text:user_name,
    16.                 height:30
    17.             },
    18.             '-',{
    19.                 text:'退出系统',
    20.                 handler:this.onLogout,
    21.             }
    22.         }]
    23.     })
    本例没有亲测,但是网上很多朋友都是这么做的,思路就是这个样子,这样做也是能实现的,但是如果你是追求完美的人,就继续往下

    3.覆盖extjs自带css,通过API 可以看到Ext.Toolbar一个配置项 "ctCls" 其解释为:
    An optional extra CSS class that will be added to this component's container. This can be useful for adding customized styles to the container or any of its children using standard CSS rules.
    意思就是我们可以自定义自己的css 影响toolbar container 或者 toolbar items的样式,背景图我们需要在包含toolbar的容器内设置,toolbar 的组件需要在toolbar容器内设置,看下面的例子

    点击(此处)折叠或打开

    1. //顶部
    2.         buildHeader : function(){
    3.             return {
    4.                 xtype:'panel',
    5.                 region : 'north',
    6.                 border:false,
    7.                 height:60,
    8.                 bbar:new Ext.Toolbar({
    9.                     defaults:{height:60},
    10.                     ctCls: 'mainToolbar', //自定义css
    11.                     items:[
    12.                     '->',{    //button align to right
    13.                         xtype:'label',
    14.                         text:'当前用户:',
    15.                         height:20,
    16.                         style: 'font-weight:bold;font-size:16px',
    17.                     },{
    18.                         xtype:'tbspacer', //2个label之间的间隔
    19.                         height:60     // 这里高度设置非常重要
    20.                     },{
    21.                         xtype:'label',
    22.                         height:20,
    23.                         html:''+cookieUtil.get('loginCookie')+'',
    24.                     },{
    25.                         xtype:'tbseparator', 
    26.                         height:20
    27.                     },{
    28.                         xtype:'button',
    29.                         height:20,
    30.                         text:'修改密码',
    31.                         scope:this,
    32.                         handler:function(){}
    33.                     },{
    34.                         xtype:'tbseparator',
    35.                         height:20
    36.                     },{
    37.                         xtype:'button',
    38.                         height:20,
    39.                         text:'退出系统',
    40.                         scope:this,
    41.                         handler:this.onLogOut
    42.                     }]
    43.                 })
    44.             }
    45.         },
    mainToolbar css:

    点击(此处)折叠或打开

    1. .mainToolbar .x-toolbar{
    2.                                 border-color:#444444;
    3.                                 background:#375975 url(../images/logo.gif) no-repeat top left;
    4.                         }
    5.                         .mainToolbar .x-toolbar .x-toolbar-cell{
    6.                                 vertical-align: bottom;   // 设置button的垂直对齐方式,默认是middle,按照习惯应该在bottom
    7.                         }
    8.                 
    9.                         .mainToolbar .x-btn-noicon .x-btn-small .x-btn-text{
    10.                                  background-color: #A4D3EE;// 设置button背景色,如果不设置,默认会是toolbar的背景色,如果是深色背景色,会看不清button上面的text
    11.                         }
    12.                         .mainToolbar .x-toolbar .xtb-spacer {
    13.                                 width: 5px;  // 上文说的label间隔距离默认是2px,
    14.                         }

    这种方式我觉得无论在美观,还是在可行性上面都是最好的,值得推荐~ 最后附一张本例结果图,






    阅读(6210) | 评论(0) | 转发(0) |
    给主人留下些什么吧!~~