本文地址:http://blog.csdn.net/sushengmiyan/article/details/38815923javascript
实例代码下载地址: http://download.csdn.net/detail/sushengmiyan/7817549java
本文做者:sushengmiyanweb
------------------------------------------------------------------------------------------------------------------------------------ajax
临时完毕效果图例如如下:json
1.登陆界面session
输入随意username与password(临时没有设置登陆验证等,后期加入)。点击用户登陆进入主页面app
在左下角,显示了你刚才输入的username,实现了数据的传输。eclipse
代码模块展演示样例如如下:ide
app.js函数
/* * This file is generated and updated by Sencha Cmd. You can edit this file as * needed for your application, but these edits will have to be merged by * Sencha Cmd when upgrading. */ Ext.application({ name: 'oaSystem', extend: 'oaSystem.Application', //autoCreateViewport: 'oaSystem.view.main.Main', //------------------------------------------------------------------------- // Most customizations should be made to oaSystem.Application. If you need to // customize this file, doing so below this section reduces the likelihood // of merge conflicts when upgrading to new versions of Sencha Cmd. //------------------------------------------------------------------------- });application.js
/** * The main application class. An instance of this class is created by app.js when it calls * Ext.application(). This is the ideal place to handle application launch and initialization * details. */ Ext.define('oaSystem.Application', { extend: 'Ext.app.Application', name: 'oaSystem', uses:['oaSystem.SimData', 'Ext.ux.ajax.*'], views: [ // TODO: add views here ], controllers: [ 'Root' // TODO: add controllers here ], stores: [ // TODO: add stores here ], launch: function () { // TODO - Launch the application //server傀儡,模拟真实世界中server交换 //oaSystem.SimData.init(); //console.log('launch begin'); //this.callParent() Ext.ux.ajax.SimManager.init().register({ '/authenticate': { type: 'json', data: function(ctx){ return Ext.apply({}, true); } } }); } });
Ext.define( 'oaSystem.view.login.Login', { requires:['oaSystem.view.login.LoginController'], extend: 'Ext.window.Window', controller: 'login', closable: false, resizable : false, modal: true, //draggable: false, autoShow: true, title: '用户登陆---OA办公系统', glyph: 'xf007@FontAwesome', items:[{ xtype:'form',//父窗口 reference: 'form', bodyPadding: 20, items:[{ xtype: 'textfield', name: 'username', labelWidth: 50, fieldLabel: 'username', allowBlank: false, emptyText: 'username或邮箱地址' },{ xtype: 'textfield', name: 'password', labelWidth: 50, inputType: 'password', fieldLabel: '密 码', allowBlank: false, emptyText: '请输入您的密码' }] }], buttons: [{ name: 'registbutton', text: '用户注冊', glyph: 'xf118@FontAwesome' },{ name: 'loginbutton', text: '用户登陆', glyph: 'xf110@FontAwesome', region: 'center', listeners:{ click: 'onLoginbtnClick'//单击事件 调用LoginConroller.js中的onLoginbtnClick函数 } }] } );logincontroller.js
Ext.define( 'oaSystem.view.login.LoginController', { extend: 'Ext.app.ViewController', alias: 'controller.login', //用户登陆button事件处理 onLoginbtnClick: function(){ var form = this.lookupReference('form'); if (form.isValid()) { this.login({ data: form.getValues(), scope: this, success: 'onLoginSuccess', failure: 'onLoginFailure' })} }, onLoginFailure: function() { // Do something Ext.getBody().unmask(); }, onLoginSuccess: function(logname, logpass) { console.log('登陆成功,用户名: ' + logname); console.log('登陆成功,密 码: ' + logpass); this.fireViewEvent('login', logname); //var org = this.lookupReference('organization').getSelectedRecord(); // this.fireViewEvent('login', this.getView(), user, org, this.loginManager); }, login: function(options) { Ext.Ajax.request({ url: '/authenticate', method: 'GET', params: options.data, scope: this, callback: this.onLoginReturn, original: options }); }, /** applyModel: function(model) { return model && Ext.data.schema.Schema.lookupEntity(model); }, */ onLoginReturn: function(options, success, response) { options = options.original; //var session = this.getSession(), // resultSet; if (success) { console.log('log in success'); /** resultSet = this.getModel().getProxy().getReader().read(response, { recordCreator: session ? session.recordCreator : null }); if (resultSet.getSuccess()) { Ext.callback(options.success, options.scope, [resultSet.getRecords()[0]]); /*/ console.log(response); Ext.callback(options.success, options.scope, [options.data.username, options.data.password]); return; //} } //Ext.callback(options.failure, options.scope, [response, resultSet]); } } );
Ext.define( 'oaSystem.view.main.Main', { extend: 'Ext.container.Viewport', uses:['oaSystem.view.main.region.Top', 'oaSystem.view.main.region.Bottom'], layout: { type: 'border' }, viewModel: { type: 'main' }, items: [{ xtype: 'maintop', region: 'north' }, { xtype: 'mainbottom', region: 'south', bind: '你好,{currentUser}' }, { xtype: 'panel' }], initComponent: function(){ //设置图标文件。设置后可以使用glyph属性 Ext.setGlyphFontFamily('FontAwesome'); this.callParent(); } } );root.js
/** * The main application controller. This is a good place to handle things like routes. * 这是主程序的控制器。这里适合作类似路由转发这种事情 */ Ext.define('oaSystem.controller.Root', { extend: 'Ext.app.Controller', uses: ['oaSystem.view.login.Login','oaSystem.view.main.Main'], /** * 初始化事件 */ onLaunch: function () { var session = this.session = new Ext.data.Session(); if (Ext.isIE8) { Ext.Msg.alert('亲。本样例不支持IE8哟'); return; }; this.login = new oaSystem.view.login.Login({ session: session, listeners: { scope: this, login: 'onLogin' }}); }, /** * logincontroller 的 "login" 事件回调. * @param user * @param loginManager */ onLogin: function (username, loginController) { this.login.destroy(); this.user = username; console.log('username: ' + username); this.showUI(); }, showUI: function(){ console.log('show ui started'); //显示主界面 this.viewport = new oaSystem.view.main.Main( { //用户信息传入视图 viewModel: { data: { currentUser: this.user } } } ); } });
1.第一步:使用sencha cmd 建立项目 名称需要注意 输入为oaSystem
我使用的命令例如如下:sencha -sdk E:\openSrc\ext-5.0.0 generate app oaSystem E:\workspaces\myeclipse2014\csdn
假设不太清楚sencha cmd的命令參数,建议先阅读 http://blog.csdn.net/sushengmiyan/article/details/38313537
2.第二步:使用sencha app build 命令构建应用程序,使用sencha web start 測试是否成功。
建议先阅读:http://blog.csdn.net/sushengmiyan/article/details/38331347
3.将刚才新建文件夹下的app文件夹全部删除。将下载的压缩文件解压缩。直接解压缩到项目文件夹就能够,又一次build执行。