通常管理系统都是采用extjs 的border布局,即左边菜单中心工作区,顶部是log还有个人信息,状态等,由于之前对Extjs不太熟悉,各个组件写的比较散乱,层次结构很糟乱,这样会导致程序维护麻烦,代码重复比较多,非常影响浏览速度,找了很多资料,《Extjs in Action》给了我很大的启发,目前已经将自己构建的系统框架雏形已经完成,基本实现我的需求,代码如下,方便来日参考,无奈是使用的3版本,4中已经有Ext.define 这样的句子了,顺带说一句尽量用4版本
-
Ext.BLANK_IMAGE_URL = 'images/s.gif';
-
Ext.QuickTips.init();
-
Ext.lib.Ajax.defaultPostHeader += ";charset=utf-8";
-
-
/**
-
* @class Kingnet.Yunwei.App
-
* 运维管理系统前端APP
-
*
-
* @constructor
-
* @singleton
-
**/
-
//名称空间
-
Ext.ns("Kingnet", "Kingnet.Yunwei");
-
-
//Kingnet.Yunwei.App = function(){
-
Kingnet.Yunwei.App= function(){
-
var viewport,loginWindow,cookieUtil = Ext.util.Cookies;
-
//treepanel 默认属性
-
var deFaults = {
-
loader:new Ext.tree.TreeLoader({
-
dataUrl:'/test/getTree.php',
-
listeners:{
-
'beforeload':function(loader,node,cb){
-
loader.dataUrl = '/test/getTree.php?&id='+ node.id;
-
}
-
-
}
-
}),
-
listeners:{
-
'click':function(node,event){
-
if(node && node.isLeaf()){
-
LazyLoad.js(Ext.util.Format.capitalize(node.attributes.id)+'.js',function(){
-
var ct,tp,p,np;
-
ct = node.getOwnerTree().ownerCt.ownerCt;
-
tp = ct.getComponent('main');//取得主工作区
-
p = tp.getComponent(node.id);
-
if(p){
-
tp.setActiveTab(p)
-
}
-
else{
-
tp.add(new Test.Office.FinancialPanel({
-
title:node.attributes.text,
-
closable : true,
-
itemId:node.attributes.id
-
})).show();
-
-
}
-
})
-
-
}
-
}
-
}
-
};
-
-
return {
-
init:function(){
-
-
if(!cookieUtil.get('loginCookie')){
-
if (! loginWindow){
-
loginWindow = this.buildLoginWindow();
-
//console.log('not login!');
-
}
-
loginWindow.show();
-
}
-
else{
-
//console.log(Ext.get(this.header.contentEl));
-
console.log('logined!!!');
-
this.buildViewport();
-
username = cookieUtil.get('loginCookie');
-
console.log(cookieUtil.get('loginCookie'));
-
//this.test();
-
}
-
-
},
-
-
buildLoginWindow:function(){
-
return new Kingnet.Yunwei.UserLoginWindow({
-
title :'登入运维管理系统',
-
scope : this,
-
handler : this.onLogin
-
})
-
},
-
-
//顶部
-
buildHeader : function(){
-
return {
-
xtype:'panel',
-
region : 'north',
-
border:false,
-
height:60,
-
bbar:new Ext.Toolbar({
-
defaults:{height:60},
-
items:[
-
'->',{
-
xtype:'label',
-
text:'当前用户',
-
},
-
'-',{
-
xtype:'label',
-
html:''+cookieUtil.get('loginCookie')+'',
-
},
-
'-',{
-
xtype:'button',
-
text:'修改密码',
-
scope:this,
-
handler:function(){}
-
},
-
'-',{
-
xtype:'button',
-
text:'退出系统',
-
scope:this,
-
handler:this.onLogOut
-
}]
-
})
-
}
-
},
-
-
-
//底部
-
footer:new Ext.Panel({
-
region : 'south',
-
height:35,
-
html : '
'
-
+ '
'
-
+ 'Power By: Anthony
'
-
+ ''
-
+ '
',
-
-
}),
-
-
//左侧菜单
-
menupanel:new Ext.Panel({
-
title: '系统菜单',
-
width : 200,
-
split : true,
-
region : 'west',
-
collapseMode :'mini',
-
layout: 'accordion',
-
defaults:deFaults,
-
layoutConfig : {
-
animate : true,
-
},
-
items:[
-
{
-
xtype:'treepanel',
-
containerScroll:true,
-
itemId:'sheetManage',
-
title:'报表管理',
-
animate:true,
-
containerScroll:true,
-
root:new Ext.tree.AsyncTreeNode({
-
expanded:true,
-
text:'报表管理',
-
id:'2',
-
draggable:false,
-
}),
-
},{
-
xtype:'treepanel',
-
containerScroll:true,
-
animate:true,
-
title:'应用管理',
-
containerScroll:true,
-
root:new Ext.tree.AsyncTreeNode({
-
expanded:true,
-
text:'应用管理',
-
id:'1',
-
draggable:false
-
}),
-
},{
-
xtype:'treepanel',
-
containerScroll:true,
-
animate:true,
-
containerScroll:true,
-
title:'资产管理',
-
root:new Ext.tree.AsyncTreeNode({
-
expanded:true,
-
text:'资产管理',
-
id:'0',
-
draggable:false
-
}),
-
},{
-
xtype:'treepanel',
-
containerScroll:true,
-
animate:true,
-
title:'权限管理',
-
containerScroll:true,
-
root:new Ext.tree.AsyncTreeNode({
-
expanded:true,
-
text:'权限管理',
-
id:'3',
-
draggable:false
-
}),
-
}],
-
-
}),
-
-
//中心区域
-
mainpanel:new Ext.TabPanel({
-
region:'center',
-
activeTab : 0,
-
itemId:'main',
-
//id:'main',
-
enableTabScroll : true,
-
items : [{
-
title : '首页',
-
html : '
welcom
'
-
}]
-
-
}),
-
-
buildViewport:function(){
-
viewport = new Ext.Viewport({
-
layout:'border',
-
renderTo:'viewport',
-
items:[this.buildHeader(),this.menupanel,this.mainpanel,this.footer],
-
});
-
Ext.getBody().unmask();
-
-
},
-
-
onLogin: function() {
-
var form = loginWindow.get(0);
-
if (form.getForm().isValid()) {
-
loginWindow.el.mask('Please wait...', 'x-mask-loading');
-
form.getForm().submit({
-
success : this.onLoginSuccess,
-
failure : this.onLoginFailure,
-
scope : this
-
});
-
}
-
},
-
-
onLoginSuccess : function() {
-
loginWindow.el.unmask();
-
var cookie = cookieUtil.get('loginCookie');
-
if (cookie) {
-
this.buildViewport();
-
loginWindow.destroy();
-
loginWindow = null;
-
}
-
else {
-
this.onLoginFailure();
-
}
-
},
-
-
onLoginFailure : function() {
-
loginWindow.el.unmask();
-
Ext.MessageBox.alert('Warning', "登入失败,请检查密码是否正确!");
-
},
-
-
-
onLogOut : function() {
-
Ext.MessageBox.confirm(
-
'Please confirm',
-
'Are you sure you want to log out?',
-
function(btn) {
-
if (btn === 'yes') {
-
Ext.getBody().mask('Logging out...', 'x-mask-loading');
-
Ext.Ajax.request({
-
url : 'userlogout.php',
-
params : { user : cookieUtil.get('loginCookie') },
-
scope : this,
-
success:function(){
-
Ext.getBody().unmask();
-
window.location.href='' //your URL
-
},
-
failure:function(){
-
alert('somthing was wrong!!!');
-
}
-
});
-
-
}
-
},
-
this
-
);
-
}
-
}
-
}();
-
-
Ext.onReady(Kingnet.Yunwei.App.init,Kingnet.Yunwei.App);
主要实现方式:
1.采用异步树节点加载,可以根据登入用户角色加载配置
2.动态加载js文件,按需加载,当用户点击treenode 会加载相应的js文件
loginwindow:
-
Ext.ns("Kingnet.Yunwei");
-
-
Kingnet.Yunwei.UserLoginWindow = Ext.extend(Ext.Window, {
-
initComponent : function() {
-
// Force defaults
-
Ext.apply(this, {
-
width : 250,
-
height : 125,
-
border :false,
-
modal : true,
-
draggable : false,
-
renderTo : 'logindiv',
-
layout : 'fit',
-
closable :true,
-
center : true,
-
closable : false,
-
resizable : false,
-
border : false,
-
items : this.buildForm(),
-
buttons : [
-
{
-
text : 'Login',
-
handler : this.handler || Ext.emptyFn,
-
scope : this.scope || this
-
}
-
]
-
});
-
-
Kingnet.Yunwei.UserLoginWindow.superclass.initComponent.call(this,arguments);
-
},
-
//private builds the form.
-
buildForm : function() {
-
-
var formItemDefaults = {
-
allowBlank : false,
-
anchor : '-5',
-
listeners : {
-
scope : this,
-
specialkey : function(field, e) {
-
if (e.getKey() === e.ENTER && this.handler) {
-
this.handler.call(this.scope);
-
}
-
}
-
}
-
};
-
-
return {
-
xtype : 'form',
-
defaultType : 'textfield',
-
labelWidth : 70,
-
frame : true,
-
url : 'login.php',
-
labelAlign : 'right',
-
defaults : formItemDefaults,
-
items : [
-
{
-
fieldLabel : '用户名 ',
-
name : 'user'
-
},
-
{
-
inputType : 'password',
-
fieldLabel : '密码 ',
-
name : 'password'
-
}
-
]
-
};
-
}
-
-
});
app.html:
-
<html>
-
<head>
-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-
<link rel="stylesheet" type="text/css" href="extjs3/resources/css/ext-all.css" />
-
<link rel="stylesheet" type="text/css" href="extjs3/examples/ux/css/RowEditor.css" />
-
<script type="text/javascript" src="extjs3/adapter/ext/ext-base.js"></script>
-
<script type="text/javascript" src="extjs3/ext-all-debug.js"></script>
-
<script type="text/javascript" src="./UserLoginWindow.js"></script>
-
<script type="text/javascript" src="./lazyload.js"></script>
-
<script type="text/javascript" src="./WorkSpace.js"></script>
-
<title>资产管理系统</title>
-
</head>
-
<style>
-
#logindiv {
-
/*background: blue;*/
-
width:100%;
-
height:100%;
-
}
-
</style>
-
<body>
-
<div id='logindiv' ></div>
-
<div id = 'viewport'></div>
-
</body>
-
</html
阅读(7761) | 评论(3) | 转发(0) |