healthTendency.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <template>
  2. <div class="content-chart-row health-t">
  3. <div class="column-row-title">
  4. <span class="title-text">
  5. <img src="@/assets/images/title-icon.png" alt=""/>应用健康趋势
  6. </span>
  7. <div>
  8. <el-select v-model="dateType" size="small" style="width: 60px" @change="changeDate">
  9. <el-option v-for="item in monthDay" :label="item" :value="item" />
  10. </el-select>
  11. <el-date-picker v-model="dateValue" :type="pickerType" size="small" style="width: 120px;margin-left:10px;" @change="changeDate"/>
  12. </div>
  13. </div>
  14. <div class="column-content chart-content">
  15. <div ref="chartSort" style="height: 238px" />
  16. </div>
  17. </div>
  18. </template>
  19. <script setup lang="ts">
  20. import * as echarts from "echarts";
  21. import {parseTime} from "@/utils/ruoyi"
  22. import {hlMonthDay} from "@/api/index/hl"
  23. import {onMounted,onUnmounted} from "vue";
  24. const props = defineProps(["refreshTime"])
  25. const today = new Date();
  26. const yesterday = new Date(today);
  27. const interval = ref(null)
  28. yesterday.setDate(today.getDate());
  29. const monthDay = ["按年","按月","按日"]
  30. const dateType = ref("按日")
  31. const dateValue = ref(yesterday)
  32. const chartSort = ref(null)
  33. const pickerType = ref("data")
  34. onMounted(()=>{
  35. changeDate()
  36. interval.value = setInterval(() => {
  37. changeDate()
  38. }, props.refreshTime)
  39. })
  40. onUnmounted(() => {
  41. clearInterval(interval.value)
  42. })
  43. async function changeDate(){
  44. if(dateType.value=="按月"){
  45. const d=parseTime(dateValue.value,"{y}-{m}")
  46. const res = await hlMonthDay("month",d)
  47. pickerType.value = "month"
  48. initChart(res.data)
  49. }else if(dateType.value=="按日"){
  50. const d=parseTime(dateValue.value,"{y}-{m}-{d}")
  51. const res = await hlMonthDay("day",d)
  52. pickerType.value = "date"
  53. initChart(res.data)
  54. }else{
  55. const d=parseTime(dateValue.value,"{y}")
  56. pickerType.value = "year"
  57. const res = await hlMonthDay("year",d)
  58. initChart(res.data)
  59. }
  60. }
  61. function initChart(res) {
  62. const myChart = echarts.init(chartSort.value);
  63. const option = {
  64. tooltip: {
  65. trigger: 'axis'
  66. },
  67. legend: {
  68. data: res.map(p=>p.name),
  69. textStyle: {
  70. color: "#9FB9E7"
  71. }
  72. },
  73. grid: {
  74. left: '3%',
  75. right: '4%',
  76. bottom: '3%',
  77. top: '15%',
  78. containLabel: true
  79. },
  80. xAxis: {
  81. type: 'category',
  82. boundaryGap: false,
  83. data: res[0].time,
  84. axisLine: {
  85. show: true,
  86. lineStyle: {
  87. color: "#9FB9E7",
  88. width: 0,
  89. }
  90. },
  91. axisTick: {
  92. show: false,
  93. },
  94. },
  95. yAxis: {
  96. type: 'value',
  97. axisLine: {
  98. show: true,
  99. lineStyle: {
  100. color: "#9FB9E7",
  101. width: 0,
  102. }
  103. },
  104. splitLine: {
  105. lineStyle: {
  106. color: "#6B8AC080",
  107. type: 'dashed',
  108. }
  109. },
  110. },
  111. series:res.map(p=>{
  112. return {
  113. name: p.name,
  114. type: 'line',
  115. // stack: 'Total',
  116. smooth: true,
  117. symbolSize: 0,
  118. data: p.score
  119. }
  120. })
  121. };
  122. myChart.setOption(option)
  123. }
  124. </script>