index.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <div class="p-4">
  3. <a-card :bordered="false" style="height: 100%">
  4. <a-tabs v-model:activeKey="activeKey" animated @change="tabChange">
  5. <a-tab-pane key="bar" tab="柱状图">
  6. <a-row>
  7. <a-col :span="10">
  8. <a-radio-group v-model:value="barType" @change="statisticst">
  9. <a-radio-button value="year">按年统计</a-radio-button>
  10. <a-radio-button value="month">按月统计</a-radio-button>
  11. <a-radio-button value="category">按类别统计</a-radio-button>
  12. <a-radio-button value="cabinet">按柜号统计</a-radio-button>
  13. </a-radio-group>
  14. </a-col>
  15. </a-row>
  16. <Bar :chartData="dataSource" height="50vh"></Bar>
  17. </a-tab-pane>
  18. <a-tab-pane key="pie" tab="饼状图" force-render>
  19. <a-row :gutter="24">
  20. <a-col :span="10">
  21. <a-radio-group v-model:value="pieType" @change="statisticst">
  22. <a-radio-button value="year">按年统计</a-radio-button>
  23. <a-radio-button value="month">按月统计</a-radio-button>
  24. <a-radio-button value="category">按类别统计</a-radio-button>
  25. <a-radio-button value="cabinet">按柜号统计</a-radio-button>
  26. </a-radio-group>
  27. </a-col>
  28. <Pie :chartData="dataSource" height="40vh"></Pie>
  29. </a-row>
  30. </a-tab-pane>
  31. </a-tabs>
  32. </a-card>
  33. </div>
  34. </template>
  35. <script lang="ts" setup>
  36. import { defHttp } from '/@/utils/http/axios';
  37. import { ref, unref, reactive } from 'vue';
  38. import Bar from '/@/components/chart/Bar.vue';
  39. import Pie from '/@/components/chart/Pie.vue';
  40. const activeKey = ref('bar');
  41. const barType = ref('year');
  42. const pieType = ref('year');
  43. const dataSource = ref([]);
  44. const url = reactive({
  45. getYearCountInfo: '/mock/api/report/getYearCountInfo',
  46. getMonthCountInfo: '/mock/api/report/getMonthCountInfo',
  47. getCntrNoCountInfo: '/mock/api/report/getCntrNoCountInfo',
  48. getCabinetCountInfo: '/mock/api/report/getCabinetCountInfo',
  49. });
  50. async function loadDate(url, type, params) {
  51. const res = await defHttp.get({ url, params }, { isTransformResponse: false, errorMessageMode: 'none' });
  52. if (res.success) {
  53. dataSource.value = [];
  54. switch (type) {
  55. case 'year':
  56. getYearCountSource(res.result);
  57. break;
  58. case 'month':
  59. getMonthCountSource(res.result);
  60. break;
  61. case 'category':
  62. getCategoryCountSource(res.result);
  63. break;
  64. case 'cabinet':
  65. getCabinetCountSource(res.result);
  66. break;
  67. default:
  68. break;
  69. }
  70. }
  71. }
  72. function getYearCountSource(data) {
  73. for (let i = 0; i < data.length; i++) {
  74. dataSource.value.push({
  75. name: `${data[i].year}年`,
  76. value: data[i].yearcount,
  77. });
  78. }
  79. }
  80. function getMonthCountSource(data) {
  81. for (let i = 0; i < data.length; i++) {
  82. dataSource.value.push({
  83. name: `${data[i].month}`,
  84. value: data[i].monthcount,
  85. });
  86. }
  87. }
  88. function getCategoryCountSource(data) {
  89. for (let i = 0; i < data.length; i++) {
  90. dataSource.value.push({
  91. name: `${data[i].classifyname}`,
  92. value: data[i].cntrnocount,
  93. });
  94. }
  95. }
  96. function getCabinetCountSource(data) {
  97. for (let i = 0; i < data.length; i++) {
  98. dataSource.value.push({
  99. name: `${data[i].cabinetname}`,
  100. value: data[i].cabinetcocunt,
  101. });
  102. }
  103. }
  104. // 选择统计类别
  105. function statisticst(e) {
  106. if (unref(activeKey) === 'pie') {
  107. loadDate(getUrl(unref(pieType)), unref(pieType), {});
  108. } else {
  109. loadDate(getUrl(unref(barType)), unref(barType), {});
  110. }
  111. }
  112. function getUrl(type) {
  113. if (type === 'year') {
  114. return url.getYearCountInfo;
  115. }
  116. if (type === 'month') {
  117. return url.getMonthCountInfo;
  118. }
  119. if (type === 'category') {
  120. return url.getCntrNoCountInfo;
  121. }
  122. if (type === 'cabinet') {
  123. return url.getCabinetCountInfo;
  124. }
  125. }
  126. //tab切换
  127. function tabChange(key) {
  128. console.log('切换的key:', key);
  129. }
  130. loadDate(url.getYearCountInfo, 'year', {});
  131. </script>