index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <div class="dashboard-editor-container">
  3. <panel-group @handleSetLineChartData="handleSetLineChartData" />
  4. <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
  5. <line-chart :chart-data="lineChartData" />
  6. </el-row>
  7. <el-row :gutter="32">
  8. <el-col :xs="24" :sm="24" :lg="8">
  9. <div class="chart-wrapper">
  10. <raddar-chart />
  11. </div>
  12. </el-col>
  13. <el-col :xs="24" :sm="24" :lg="8">
  14. <div class="chart-wrapper">
  15. <pie-chart />
  16. </div>
  17. </el-col>
  18. <el-col :xs="24" :sm="24" :lg="8">
  19. <div class="chart-wrapper">
  20. <bar-chart />
  21. </div>
  22. </el-col>
  23. </el-row>
  24. </div>
  25. </template>
  26. <script>
  27. import PanelGroup from './dashboard/PanelGroup'
  28. import LineChart from './dashboard/LineChart'
  29. import RaddarChart from './dashboard/RaddarChart'
  30. import PieChart from './dashboard/PieChart'
  31. import BarChart from './dashboard/BarChart'
  32. import { getToken, getExpiresIn, setExpiresIn } from '@/utils/auth'
  33. const lineChartData = {
  34. newVisitis: {
  35. expectedData: [100, 120, 161, 134, 105, 160, 165],
  36. actualData: [120, 82, 91, 154, 162, 140, 145]
  37. },
  38. messages: {
  39. expectedData: [200, 192, 120, 144, 160, 130, 140],
  40. actualData: [180, 160, 151, 106, 145, 150, 130]
  41. },
  42. purchases: {
  43. expectedData: [80, 100, 121, 104, 105, 90, 100],
  44. actualData: [120, 90, 100, 138, 142, 130, 130]
  45. },
  46. shoppings: {
  47. expectedData: [130, 140, 141, 142, 145, 150, 160],
  48. actualData: [120, 82, 91, 154, 162, 140, 130]
  49. }
  50. }
  51. export default {
  52. name: 'Index',
  53. components: {
  54. PanelGroup,
  55. LineChart,
  56. RaddarChart,
  57. PieChart,
  58. BarChart
  59. },
  60. data() {
  61. return {
  62. //刷新token锁
  63. refreshLock: false,
  64. //刷新token的时间
  65. refreshTime: '',
  66. lineChartData: lineChartData.newVisitis
  67. }
  68. },
  69. created() {
  70. this.refreshToken()
  71. },
  72. methods: {
  73. handleSetLineChartData(type) {
  74. this.lineChartData = lineChartData[type]
  75. },
  76. // 实时检测刷新token
  77. refreshToken() {
  78. this.refreshTime = setInterval(() => {
  79. if (null === getToken()) {
  80. return;
  81. }
  82. const expires_in = getExpiresIn();
  83. if (expires_in <= 1000 && !this.refreshLock) {
  84. this.refreshLock = true
  85. this.$store
  86. .dispatch('RefreshToken')
  87. .catch(() => {
  88. clearInterval(this.refreshTime)
  89. });
  90. this.refreshLock = false
  91. }
  92. this.$store.commit("SET_EXPIRES_IN", expires_in - 10);
  93. setExpiresIn(expires_in - 10);
  94. }, 10000);
  95. }
  96. }
  97. }
  98. </script>
  99. <style lang="scss" scoped>
  100. .dashboard-editor-container {
  101. padding: 32px;
  102. background-color: rgb(240, 242, 245);
  103. position: relative;
  104. .chart-wrapper {
  105. background: #fff;
  106. padding: 16px 16px 0;
  107. margin-bottom: 32px;
  108. }
  109. }
  110. @media (max-width:1024px) {
  111. .chart-wrapper {
  112. padding: 8px;
  113. }
  114. }
  115. </style>