Home.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. Ext.define('saas.view.home.Home', {
  2. extend: 'Ext.container.Container',
  3. xtype: 'home',
  4. id: 'home',
  5. requires: [
  6. 'Ext.slider.Single',
  7. 'Ext.form.field.Display',
  8. 'Ext.layout.container.Border',
  9. 'Ext.ux.layout.ResponsiveColumn'
  10. ],
  11. controller: 'home',
  12. viewModel: {
  13. type: 'home'
  14. },
  15. cls: 'x-home-panel',
  16. layout: 'responsivecolumn',
  17. scrollable: true,
  18. REFRESH_INTERVALS: 5 * 60 * 1000, // 刷新间隔
  19. defaults: {
  20. shadow: true,
  21. cls: 'x-home-box',
  22. userCls: 'big-100 small-100',
  23. },
  24. items: [{
  25. style: {
  26. marginRight: '0',
  27. },
  28. xtype: 'infocard'
  29. }, {
  30. xtype: 'panel',
  31. style: {
  32. marginRight: '0',
  33. },
  34. // title: '2018年11月经营分析',
  35. latyout: 'responsivecolumn',
  36. defaults: {
  37. margin: '0 0 0 14',
  38. userCls: 'big-33 small-50',
  39. },
  40. items: [{
  41. xtype: 'month-sale',
  42. }, {
  43. xtype: 'month-purchase',
  44. }, {
  45. xtype: 'key-data',
  46. }]
  47. }, {
  48. xtype: 'panel',
  49. // title: '2018年11月经营分析',
  50. latyout: 'responsivecolumn',
  51. style: {
  52. marginRight: '0',
  53. marginBottom: '0'
  54. },
  55. defaults: {
  56. margin: '0 0 0 14',
  57. userCls: 'big-33 small-50',
  58. },
  59. items: [{
  60. xtype: 'month-io',
  61. }, {
  62. xtype: 'sale-trend',
  63. }, {
  64. // xtype: 'purchase-trend'
  65. // }, {
  66. xtype: 'stock-amount'
  67. }]
  68. }],
  69. initComponent: function() {
  70. this.lastTime = Ext.Date.now();
  71. this.callParent(arguments);
  72. },
  73. listeners: {
  74. onTabActivate: function(p) {
  75. p.refreshId = window.setInterval((p.refreshStores.bind(p)()).bind(p), p.REFRESH_INTERVALS);
  76. },
  77. onTabDeactivate: function(p) {
  78. p.lastTime = 0;
  79. window.clearInterval(p.refreshId);
  80. }
  81. },
  82. refreshStores: function() {
  83. var me = this,
  84. lastTime = me.lastTime || 0,
  85. now = Ext.Date.now(),
  86. viewModel = me.getViewModel(),
  87. stores = viewModel.storeInfo;
  88. if(now - lastTime > me.REFRESH_INTERVALS) {
  89. for(var key in stores) {
  90. var store = stores[key];
  91. store.load();
  92. }
  93. me.lastTime = Ext.Date.now();
  94. }
  95. return me.refreshStores;
  96. }
  97. });