index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <div class="dashboard-container">
  3. <PanelGroup
  4. :service-method-handler-count="dashboardData.serviceMethodHandlerCount || 0"
  5. :app-key-count="dashboardData.appKeyCount || 0"
  6. :place-count="dashboardData.placeCount || 0"
  7. :file-count="dashboardData.fileCount || 0"
  8. />
  9. <el-card>
  10. <div slot="header" class="clearfix">
  11. <span>API统计</span>
  12. <div style="float: right; font-size: 12px">
  13. <a type="text" href="javascript:;" @click="$router.push({ path: '/appKey/requestLogs' })">详情>></a>
  14. </div>
  15. </div>
  16. <el-row :gutter="16">
  17. <el-col :span="8">
  18. <div id="request-log-pie" style="width: 100%;height:300px;"/>
  19. </el-col>
  20. <el-col :span="16">
  21. <div id="request-log-line" style="width: 100%;height:300px;"/>
  22. </el-col>
  23. </el-row>
  24. </el-card>
  25. </div>
  26. </template>
  27. <script>
  28. import PanelGroup from './PanelGroup'
  29. import { dashboard } from '@/api/dashboard'
  30. import * as echarts from 'echarts'
  31. export default {
  32. name: 'Dashboard',
  33. components: { PanelGroup },
  34. data() {
  35. return {
  36. dashboardData: {}
  37. }
  38. },
  39. mounted() {
  40. const _this = this
  41. dashboard().then(v => {
  42. _this.dashboardData = v
  43. _this.buildRequestLogPie(this.dashboardData.requestLogPieData)
  44. _this.buildRequestLogLine(this.dashboardData.requestLogLineData)
  45. })
  46. },
  47. methods: {
  48. gotoPage(redirect) {
  49. console.log(redirect)
  50. this.$router.push({ path: redirect })
  51. // this.$router.(redirect)
  52. },
  53. buildRequestLogLine(requestLogPieData) {
  54. console.log(requestLogPieData)
  55. const xAxis = []
  56. requestLogPieData.forEach(o => {
  57. xAxis.push(o.d)
  58. })
  59. const chart = echarts.init(document.getElementById('request-log-line'))
  60. chart.setOption({
  61. tooltip: {
  62. trigger: 'item'
  63. },
  64. legend: {
  65. top: '0',
  66. right: '1%'
  67. },
  68. grid: {
  69. left: '5%',
  70. right: '1%',
  71. bottom: '6%',
  72. containLabel: true
  73. },
  74. xAxis: {
  75. type: 'category',
  76. data: xAxis
  77. },
  78. yAxis: {
  79. type: 'value'
  80. },
  81. series: [
  82. {
  83. name: '请求次数',
  84. type: 'line',
  85. data: requestLogPieData
  86. }
  87. ]
  88. })
  89. },
  90. buildRequestLogPie(requestLogPieData) {
  91. console.log(requestLogPieData)
  92. const chart = echarts.init(document.getElementById('request-log-pie'))
  93. chart.setOption({
  94. tooltip: {
  95. trigger: 'item'
  96. },
  97. legend: {
  98. top: '0',
  99. left: '0'
  100. },
  101. grid: {
  102. // left: '8%',
  103. // right: '10%',
  104. // bottom: '1%',
  105. // containLabel: true
  106. },
  107. series: [
  108. {
  109. name: '请求次数',
  110. type: 'pie',
  111. radius: ['40%', '60%'],
  112. avoidLabelOverlap: false,
  113. label: {
  114. show: false
  115. },
  116. labelLine: {
  117. show: false
  118. },
  119. data: requestLogPieData
  120. }
  121. ]
  122. })
  123. }
  124. }
  125. }
  126. </script>
  127. <style lang="scss" scoped>
  128. .dashboard {
  129. &-container {
  130. margin: 30px;
  131. }
  132. &-text {
  133. font-size: 30px;
  134. line-height: 46px;
  135. }
  136. }
  137. </style>