OneDay.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <el-card shadow="none" style="padding: 10px 14px;">
  3. <div class="trend-container">
  4. <div class="card-title">
  5. 日启动次数分布<el-tooltip class="box-item" effect="light" placement="right-start">
  6. <template #content>
  7. <div style="width: 300px;">
  8. 您可以查看用户在任意1天内日启动次数的分布情况,同时可以对日启动次数的数据进行版本、渠道、分群的交叉筛选。<br />
  9. <span style="color: rgba(22, 122, 240, 1);">日启动次数:</span>(用户)一天内启动应用的次数
  10. </div>
  11. </template>
  12. <span style=" vertical-align: middle; margin: 0 0 0 8px;">
  13. <Svg name="export"></Svg>
  14. </span>
  15. </el-tooltip>
  16. </div>
  17. <FormEcharts v-if="type === 'date'" @dateChange="handleDateChange" :averageValue="averageValue" :type="type" :form="form" />
  18. <div class="chart-container">
  19. <BarChart :data="usageTimeData" :is-multi-series="true" :series-names="seriesNames" title="多系列对比柱状图"
  20. style="height: 300px;" />
  21. </div>
  22. <el-divider style="margin: 30px 0; background: rgba(230, 230, 230, 1);" />
  23. <ExportToCSV :data="formatData" :columns="columns" :fileName="'日启动次数分布'" />
  24. </div>
  25. </el-card>
  26. </template>
  27. <script setup lang="ts">
  28. import { ref, computed } from 'vue'
  29. import BarChart from '/@/views/count/components/BarChart.vue';
  30. import ExportToCSV from '/@/views/count/components/ExportToCSV.vue';
  31. import FormEcharts from '../components/FormEcharts.vue';
  32. import Svg from '/@/components/Svg.vue';
  33. const props = defineProps({
  34. type: {
  35. type: String,
  36. default: 'date'
  37. },
  38. form: {
  39. type: Object,
  40. default: () => ({})
  41. }
  42. })
  43. const averageValue = ref({
  44. time: '平均每日启动次数',
  45. value: '1.23'
  46. })
  47. // 多系列数据对比
  48. const usageTimeData = ref([
  49. {
  50. name: '1-2',
  51. values: []
  52. },
  53. {
  54. name: '3-5',
  55. values: []
  56. },
  57. {
  58. name: '6-10',
  59. values: []
  60. },
  61. {
  62. name: '11-20',
  63. values: []
  64. }
  65. ])
  66. const seriesNames = ref<string[]>([]);
  67. const handleDateChange = (val: string[]) => {
  68. // 强制触发响应式更新
  69. seriesNames.value = [...val];
  70. // 创建新的数据对象以确保响应式更新
  71. const newData = usageTimeData.value.map((item: any) => ({
  72. ...item,
  73. values: val.map((date: string) => {
  74. const value = Math.floor(Math.random() * 100);
  75. return {
  76. value: value,
  77. percentage: `${value}%`
  78. }
  79. })
  80. }));
  81. console.log(newData);
  82. usageTimeData.value = newData;
  83. }
  84. // 定义表格列配置
  85. const columns = [
  86. { prop: 'time', label: '启动次数' },
  87. { prop: 'count', label: '用户数' },
  88. { prop: 'percentage', label: '用户数比例' }
  89. ];
  90. const formatData = computed(() => {
  91. console.log(`formatData: `);
  92. console.log(usageTimeData.value);
  93. return usageTimeData.value.map((item: any) => {
  94. return {
  95. time: item.name,
  96. count: item.values[0]?.value || 0,
  97. percentage: `${item.values[0]?.value || 0}%`
  98. }
  99. })
  100. })
  101. </script>
  102. <style scoped lang="scss">
  103. @import '/@/views/count/styles/common.scss';
  104. svg {
  105. vertical-align: middle;
  106. margin: 0 0 0 12px;
  107. }
  108. .chart-container {
  109. margin: 0 auto;
  110. max-width: 1360px;
  111. }
  112. </style>