Home.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. xtype: 'month-sale',
  40. padding: '0 0 0 14',
  41. }, {
  42. xtype: 'profit-detail',
  43. padding: '0 0 0 14',
  44. }, {
  45. xtype: 'key-data',
  46. margin: 0
  47. }]
  48. }, {
  49. xtype: 'panel',
  50. latyout: 'responsivecolumn',
  51. style: {
  52. background: '#f4f4f4',
  53. },
  54. defaults: {
  55. margin: '0 16 0 0',
  56. userCls: 'x-home-chart big-33 small-50',
  57. },
  58. items: [{
  59. xtype: 'sale-trend',
  60. padding: '0 0 0 14',
  61. }, {
  62. xtype: 'month-io',
  63. padding: '0 0 0 14',
  64. }, {
  65. xtype: 'stock-amount',
  66. margin: 0,
  67. padding: '0 0 0 14',
  68. }]
  69. }],
  70. initComponent: function() {
  71. var me = this;
  72. this.lastTime = Ext.Date.now();
  73. //判断当前是否未完成新手导航
  74. saas.util.BaseUtil.request({
  75. url: '/api/commons/init/check'
  76. }).then(function(res) {
  77. if(!res.data.begin){
  78. saas.util.BaseUtil.openTab('sys-guide-formpanel', '新手导航', 'sys-guide-formpanel')
  79. }
  80. if(!res.data.currency){
  81. me.getController().setDefaultCurrency();
  82. }
  83. }).catch(function(e) {
  84. saas.util.BaseUtil.showErrorToast(e.message);
  85. })
  86. this.callParent(arguments);
  87. },
  88. listeners: {
  89. onTabActivate: function(p) {
  90. p.refreshId = window.setInterval((p.refreshStores.bind(p)()).bind(p), p.REFRESH_INTERVALS);
  91. },
  92. onTabDeactivate: function(p) {
  93. p.lastTime = 0;
  94. window.clearInterval(p.refreshId);
  95. }
  96. },
  97. refreshStores: function() {
  98. var me = this,
  99. lastTime = me.lastTime || 0,
  100. now = Ext.Date.now(),
  101. viewModel = me.getViewModel(),
  102. stores = viewModel.storeInfo;
  103. if(now - lastTime > me.REFRESH_INTERVALS) {
  104. for(var key in stores) {
  105. var store = stores[key];
  106. store.load();
  107. }
  108. me.lastTime = Ext.Date.now();
  109. }
  110. return me.refreshStores;
  111. }
  112. });