Global.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * @Description:
  3. * @Author: hy
  4. * @Date: 2019-08-12 17:59:33
  5. * @LastEditTime: 2019-08-16 14:47:58
  6. */
  7. Ext.define('uas.controller.Global', {
  8. extend: 'Ext.app.Controller',
  9. namespace: 'uas',
  10. stores: [
  11. 'Navigation'
  12. ],
  13. config: {
  14. control: {
  15. 'navigation-tree': {
  16. selectionchange: 'onTreeNavSelectionChange'
  17. }
  18. },
  19. refs: {
  20. viewport: 'viewport',
  21. navigationTree: 'navigation-tree',
  22. contentPanel: 'contentPanel',
  23. },
  24. routes : {
  25. ':target': {
  26. action: 'handleRoute',
  27. before: 'beforeHandleRoute'
  28. }
  29. }
  30. },
  31. beforeHandleRoute: function(target, action) {
  32. let me = this,
  33. store = Ext.StoreMgr.get('Navigation'),
  34. className = Ext.ClassManager.getNameByAlias('widget.' + target),
  35. ViewClass = Ext.ClassManager.get(className);
  36. if(!!ViewClass && store.getCount() > 0) {
  37. action.resume();
  38. }else {
  39. Ext.Msg.alert(
  40. '加载异常',
  41. '确定以返回首页',
  42. function() {
  43. // TODO 路由跳转并不会引起页面刷新,待解决
  44. me.redirectTo(me.getApplication().getDefaultToken());
  45. }
  46. );
  47. action.stop();
  48. }
  49. },
  50. handleRoute: function(target) {
  51. let me = this,
  52. contentPanel = me.getContentPanel(),
  53. navigationTree = me.getNavigationTree(),
  54. store = Ext.StoreMgr.get('Navigation'),
  55. node = store.findNode('target', target),
  56. title = node.get('text');
  57. this.getViewport().getViewModel().set('selectedNode', [node]);
  58. if (node.isRoot()) {
  59. navigationTree.ensureVisible(0, {
  60. focus: true
  61. });
  62. } else {
  63. if (node.parentNode && !node.parentNode.isExpanded()) {
  64. node.parentNode.expand();
  65. }
  66. navigationTree.ensureVisible(node, {
  67. focus: true,
  68. select: true
  69. });
  70. }
  71. Ext.suspendLayouts();
  72. contentPanel.removeAll(true);
  73. className = Ext.ClassManager.getNameByAlias('widget.' + target);
  74. ViewClass = Ext.ClassManager.get(className);
  75. cmp = new ViewClass();
  76. contentPanel.add(cmp);
  77. me.updateTitle(title);
  78. if (cmp.floating) {
  79. Ext.resumeLayouts(true);
  80. cmp.show();
  81. Ext.suspendLayouts();
  82. }
  83. Ext.resumeLayouts(true);
  84. },
  85. onTreeNavSelectionChange: function(tree, selected, eOpts) {
  86. if(selected.length>0){
  87. let target = selected[0].get('target');
  88. if(target) {
  89. this.redirectTo(target);
  90. }
  91. }
  92. },
  93. updateTitle: function(title) {
  94. let contentPanel = this.getContentPanel();
  95. if (contentPanel.setTitle) {
  96. contentPanel.setTitle(title);
  97. }
  98. document.title = document.title.split(' - ')[0] + ' - ' + title;
  99. }
  100. });