Home.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. Ext.define('saas.view.home.Home', {
  2. extend: 'Ext.container.Container',
  3. xtype: 'home',
  4. id: 'home',
  5. requires: [
  6. 'Ext.layout.container.Border',
  7. 'Ext.ux.layout.ResponsiveColumn'
  8. ],
  9. controller: 'home',
  10. viewModel: {
  11. type: 'home'
  12. },
  13. cls: 'x-home-panel',
  14. padding: '0 16 0 0',
  15. layout: 'responsivecolumn',
  16. scrollable: true,
  17. REFRESH_INTERVALS: 5 * 60 * 1000, // 刷新间隔
  18. defaults: {
  19. shadow: true,
  20. cls: 'x-home-box',
  21. userCls: 'big-100 small-100',
  22. },
  23. items: [{
  24. style: {
  25. marginRight: '0',
  26. },
  27. xtype: 'infocard'
  28. }, {
  29. xtype: 'panel',
  30. style: {
  31. background: '#f4f4f4',
  32. },
  33. latyout: 'responsivecolumn',
  34. defaults: {
  35. margin: '0 16 0 0',
  36. userCls: 'x-home-chart big-33 small-50',
  37. },
  38. items: []
  39. }, {
  40. xtype: 'panel',
  41. latyout: 'responsivecolumn',
  42. style: {
  43. background: '#f4f4f4',
  44. },
  45. defaults: {
  46. margin: '0 16 0 0',
  47. userCls: 'x-home-chart big-33 small-50',
  48. },
  49. items: []
  50. }],
  51. initComponent: function() {
  52. this.lastTime = Ext.Date.now();
  53. this.callParent(arguments);
  54. },
  55. listeners: {
  56. onTabActivate: function(p) {
  57. p.refreshId = window.setInterval((p.refreshStores.bind(p)()).bind(p), p.REFRESH_INTERVALS);
  58. },
  59. onTabDeactivate: function(p) {
  60. p.lastTime = 0;
  61. window.clearInterval(p.refreshId);
  62. }
  63. },
  64. refreshStores: function() {
  65. var me = this,
  66. lastTime = me.lastTime || 0,
  67. now = Ext.Date.now(),
  68. viewModel = me.getViewModel(),
  69. stores = viewModel.storeInfo;
  70. if(now - lastTime > me.REFRESH_INTERVALS) {
  71. for(var key in stores) {
  72. var store = stores[key];
  73. store.load();
  74. }
  75. me.lastTime = Ext.Date.now();
  76. }
  77. return me.refreshStores;
  78. }
  79. });