123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- /*
- * @Description:
- * @Author: hy
- * @Date: 2019-08-12 17:59:33
- * @LastEditTime: 2019-08-16 14:47:58
- */
- Ext.define('uas.controller.Global', {
- extend: 'Ext.app.Controller',
- namespace: 'uas',
- stores: [
- 'Navigation'
- ],
- config: {
- control: {
- 'navigation-tree': {
- selectionchange: 'onTreeNavSelectionChange'
- }
- },
- refs: {
- viewport: 'viewport',
- navigationTree: 'navigation-tree',
- contentPanel: 'contentPanel',
- },
- routes : {
- ':target': {
- action: 'handleRoute',
- before: 'beforeHandleRoute'
- }
- }
- },
- beforeHandleRoute: function(target, action) {
- let me = this,
- store = Ext.StoreMgr.get('Navigation'),
- className = Ext.ClassManager.getNameByAlias('widget.' + target),
- ViewClass = Ext.ClassManager.get(className);
- if(!!ViewClass && store.getCount() > 0) {
- action.resume();
- }else {
- Ext.Msg.alert(
- '加载异常',
- '确定以返回首页',
- function() {
- // TODO 路由跳转并不会引起页面刷新,待解决
- me.redirectTo(me.getApplication().getDefaultToken());
- }
- );
- action.stop();
- }
- },
- handleRoute: function(target) {
- let me = this,
- contentPanel = me.getContentPanel(),
- navigationTree = me.getNavigationTree(),
- store = Ext.StoreMgr.get('Navigation'),
- node = store.findNode('target', target),
- title = node.get('text');
-
- this.getViewport().getViewModel().set('selectedNode', [node]);
- if (node.isRoot()) {
- navigationTree.ensureVisible(0, {
- focus: true
- });
- } else {
- if (node.parentNode && !node.parentNode.isExpanded()) {
- node.parentNode.expand();
- }
- navigationTree.ensureVisible(node, {
- focus: true,
- select: true
- });
- }
- Ext.suspendLayouts();
- contentPanel.removeAll(true);
- className = Ext.ClassManager.getNameByAlias('widget.' + target);
- ViewClass = Ext.ClassManager.get(className);
- cmp = new ViewClass();
- contentPanel.add(cmp);
- me.updateTitle(title);
- if (cmp.floating) {
- Ext.resumeLayouts(true);
- cmp.show();
- Ext.suspendLayouts();
- }
- Ext.resumeLayouts(true);
- },
- onTreeNavSelectionChange: function(tree, selected, eOpts) {
- if(selected.length>0){
- let target = selected[0].get('target');
- if(target) {
- this.redirectTo(target);
- }
- }
- },
- updateTitle: function(title) {
- let contentPanel = this.getContentPanel();
- if (contentPanel.setTitle) {
- contentPanel.setTitle(title);
- }
- document.title = document.title.split(' - ')[0] + ' - ' + title;
- }
- });
|