歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> 用ExtJS 4.0打造自己的Web桌面

用ExtJS 4.0打造自己的Web桌面

日期:2017/3/1 9:41:13   编辑:Linux編程

本教程基於ExtJS 4.0版本,從靜態桌面圖標換行講起,到實現自己的動態WEB桌面,可以像webQQ那樣添加應用, 打開應用。本教程不包括詳細js代碼和服務器代碼,但基本思路及主要代碼給出。

ExtJS中運用HTML5 Canvas簡單例子 http://www.linuxidc.com/Linux/2012-04/59389.htm

1. 桌面圖標自動換行

1.1. 增加一個換行的方法

這是參考網上換行例子。建議加在desktop.js中,因為是屬於desktop的行為。

initShortcut : function() {

var btnHeight = 80;

var btnWidth = 80;

var btnPadding = 8;

var col = null;

var row = null;

var bottom;

var bodyHeight = Ext.getBody().getHeight();

function initColRow() {

col = {

index : 1,

x : btnPadding

};

row = {

index : 1,

y : btnPadding + 27

};

}



this.setXY = function(item) {

bottom = row.y + btnHeight;

if (bottom > bodyHeight && bottom > (btnHeight + btnPadding)) {

col = {

index : col.index++,

x : col.x + btnWidth + btnPadding

};

row = {

index : 1,

y : btnPadding + 27

};

}

Ext.fly(item).setXY([col.x, row.y]);

row.y = row.y + btnHeight + btnPadding + 4;

}





1.2. 在適當的地方調用

第一個地方是初始化時。

如Apps.js中的init:

init: function() {

this.callParent();

this.desktop.initShortcut();

}



第二個地方是resize時。如在desktop.js中的dataView中注冊一事件:

createDataView: function () {

var a = this;

return {

xtype: "dataview",

overItemCls: "x-view-over",

trackOver: true,

itemSelector: a.shortcutItemSelector,

store: a.shortcuts,

tpl: new Ext.XTemplate(a.shortcutTpl),

listeners:{

resize:this.initShortcut //這裡調用

}

}

}



第三個地方是刪除圖標或者增加圖標時。

如刪除:

desktop.shortcutsView.getStore().remove(desktop.handerObj);

desktop.initShortcut();

// handerObj是桌面圖標對象,在點擊圖標事件時可以獲得



還有其它……



1.3. 測試

在App.js中的getDesktopConfig中,通過復制增加圖標,這樣才能看到效果:

getDesktopConfig: function () {

var me = this, ret = me.callParent();



return Ext.apply(ret, {

//cls: 'ux-desktop-black',



contextMenuItems: [

{ text: 'Change Settings', handler: me.onSettings, scope: me }

],



shortcuts: Ext.create('Ext.data.Store', {

model: 'Ext.ux.desktop.ShortcutModel',

data: [

{ name: 'Grid Window', iconCls: 'grid-shortcut', module: 'grid-win' },

{ name: 'Accordion Window', iconCls: 'accordion-shortcut', module: 'acc-win' },

{ name: 'Notepad', iconCls: 'notepad-shortcut', module: 'notepad' },

{ name: 'Notepad', iconCls: 'notepad-shortcut', module: 'notepad' },

{ name: 'Notepad', iconCls: 'notepad-shortcut', module: 'notepad' },

{ name: 'Notepad', iconCls: 'notepad-shortcut', module: 'notepad' },

{ name: 'Notepad', iconCls: 'notepad-shortcut', module: 'notepad' },

{ name: 'Notepad', iconCls: 'notepad-shortcut', module: 'notepad' },

{ name: 'Notepad', iconCls: 'notepad-shortcut', module: 'notepad' },

{ name: 'System Status', iconCls: 'cpu-shortcut', module: 'systemstatus'}

]

}),



wallpaper: 'wallpapers/Blue-Sencha.jpg',

wallpaperStretch: false

});

},

更多詳情見請繼續閱讀下一頁的精彩內容: http://www.linuxidc.com/Linux/2014-08/105208p2.htm

Copyright © Linux教程網 All Rights Reserved