Global.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * @Description:
  3. * @Author: hy
  4. * @Date: 2019-08-12 17:59:33
  5. * @LastEditTime: 2019-08-15 09:24:55
  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. node = store.findNode('target', target),
  35. path = node.get('path');
  36. ViewClass = Ext.ClassManager.get(path);
  37. if(!!ViewClass) {
  38. //resume action
  39. action.resume();
  40. }else {
  41. new Ext.Promise(function (resolve, reject) {
  42. Ext.require(path,function(){
  43. resolve();
  44. });
  45. }).then(function(){
  46. if(!!Ext.ClassManager.get(path)) {
  47. action.resume();
  48. }else{
  49. Ext.Msg.alert(
  50. '创建组件失败',
  51. '确定以返回首页',
  52. function() {
  53. // TODO 路由跳转并不会引起页面刷新,待解决
  54. me.redirectTo(me.getApplication().getDefaultToken());
  55. }
  56. );
  57. //stop action
  58. action.stop();
  59. }
  60. })
  61. }
  62. },
  63. handleRoute: function(target) {
  64. let me = this,
  65. store = Ext.StoreMgr.get('Navigation'),
  66. node = store.findNode('target', target),
  67. title = node.get('text'),
  68. path = node.get('path'),
  69. contentPanel = me.getContentPanel();
  70. this.getViewport().getViewModel().set('selectedNode', node);
  71. Ext.suspendLayouts();
  72. contentPanel.removeAll(true);
  73. ViewClass = Ext.ClassManager.get(path);
  74. cmp = new ViewClass();
  75. contentPanel.add(cmp);
  76. me.updateTitle(title);
  77. if (cmp.floating) {
  78. Ext.resumeLayouts(true);
  79. cmp.show();
  80. Ext.suspendLayouts();
  81. }
  82. Ext.resumeLayouts(true);
  83. },
  84. onTreeNavSelectionChange: function(treelist, record, eOpts) {
  85. let target = record.get('target');
  86. if(target) {
  87. this.redirectTo(target);
  88. }
  89. },
  90. updateTitle: function(title) {
  91. let contentPanel = this.getContentPanel();
  92. if (contentPanel.setTitle) {
  93. contentPanel.setTitle(title);
  94. }
  95. document.title = document.title.split(' - ')[0] + ' - ' + title;
  96. }
  97. });