Index.vue 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <script setup>
  2. import { Head } from '@inertiajs/inertia-vue3'
  3. import { orderBy } from 'lodash'
  4. import AppCardStatistic from '@/components/AppCardStatistic.vue'
  5. import AppLayout from '@/layouts/AppLayout.vue'
  6. defineProps({
  7. cardStatistics: Object,
  8. barStatistics: Object,
  9. barHorizontalStatistics: Object,
  10. })
  11. const colors = [
  12. '#349dcf',
  13. '#00b2da',
  14. '#00c7dd',
  15. '#1fdbdb',
  16. '#57eed3',
  17. '#88ffc9',
  18. '#96ed9a',
  19. '#a8d96c',
  20. '#bbc242',
  21. '#cda91d',
  22. ]
  23. const barChart = (chartData) => {
  24. const colors = ['#349dcf', '#a8d96c']
  25. const data = {
  26. datasets: [],
  27. }
  28. let id = 0
  29. for (const key in chartData) {
  30. data.datasets.push({
  31. label: key,
  32. backgroundColor: colors[id],
  33. data: chartData[key],
  34. })
  35. id++
  36. }
  37. return data
  38. }
  39. const barChartOption = {
  40. maintainAspectRatio: false,
  41. datasetFill: false,
  42. }
  43. const barHorizontalChart = (chartData) => {
  44. // const data = {
  45. // datasets: [],
  46. // }
  47. // let id = 0
  48. // for (const key in chartData) {
  49. // data.datasets.push({
  50. // label: key,
  51. // backgroundColor: colors[id],
  52. // data: chartData[key],
  53. // })
  54. // id++
  55. // }
  56. // return data
  57. const labels = []
  58. const data = []
  59. for (const chartData of chartData) {
  60. labels.push([chartData.phone, chartData.name])
  61. data.push(chartData.amount)
  62. }
  63. return {
  64. labels: labels,
  65. datasets: [
  66. {
  67. data: data,
  68. backgroundColor: colors,
  69. },
  70. ],
  71. }
  72. }
  73. const barHorizontalChartOption = {
  74. maintainAspectRatio: false,
  75. datasetFill: false,
  76. indexAxis: 'y',
  77. plugins: {
  78. legend: {
  79. display: false,
  80. },
  81. },
  82. }
  83. const pieChart = (chartData) => {
  84. const labels = []
  85. const data = []
  86. for (const key in chartData) {
  87. labels.push(key)
  88. data.push(chartData[key])
  89. }
  90. return {
  91. labels: labels,
  92. datasets: [
  93. {
  94. data: data,
  95. backgroundColor: colors,
  96. },
  97. ],
  98. }
  99. }
  100. const pieChartOption = {
  101. maintainAspectRatio: false,
  102. datasetFill: false,
  103. }
  104. </script>
  105. <template>
  106. <AppLayout>
  107. <Head title="Dashboard" />
  108. <div class="grid">
  109. <div class="col-12 flex flex-wrap justify-content-between card-statistic">
  110. <div v-for="cardStatistic in cardStatistics" class="flex-grow-1">
  111. <AppCardStatistic :data="cardStatistic" />
  112. </div>
  113. </div>
  114. <div v-for="barStatistic in barStatistics" class="col-12 md:col-6">
  115. <Card>
  116. <template #title>
  117. <div class="flex flex-column">
  118. <span>{{ barStatistic.title }}</span>
  119. <span v-if="barStatistic.description" class="text-base font-normal">{{ barStatistic.description }}</span>
  120. </div>
  121. </template>
  122. <template #content>
  123. <Chart
  124. type="bar"
  125. :width="600"
  126. :height="300"
  127. :data="barChart(barStatistic.data)"
  128. :options="barChartOption"
  129. />
  130. </template>
  131. </Card>
  132. </div>
  133. <div v-for="barHorizontalStatistic in barHorizontalStatistics" class="col-12 md:col-6">
  134. <Card>
  135. <template #title>
  136. <div class="flex flex-column">
  137. <span>{{ barHorizontalStatistic.title }}</span>
  138. <span v-if="barHorizontalStatistic.description" class="text-base font-normal">{{
  139. barHorizontalStatistic.description
  140. }}</span>
  141. </div>
  142. </template>
  143. <template #content>
  144. <Chart
  145. type="bar"
  146. :width="600"
  147. :height="300"
  148. :data="barHorizontalChart(barHorizontalStatistic.data)"
  149. :options="barHorizontalChartOption"
  150. />
  151. </template>
  152. </Card>
  153. </div>
  154. <!-- <div v-for="pieStatistic in pieStatistics" class="col-12 md:col-6">
  155. <Card>
  156. <template #title>
  157. <div class="flex flex-column">
  158. <span>{{ pieStatistic.title }}</span>
  159. <span v-if="pieStatistic.description" class="text-base font-normal">{{ pieStatistic.description }}</span>
  160. </div>
  161. </template>
  162. <template #content>
  163. <Chart
  164. type="pie"
  165. :width="600"
  166. :height="300"
  167. :data="pieChart(pieStatistic.data)"
  168. :options="pieChartOption"
  169. />
  170. </template>
  171. </Card>
  172. </div> -->
  173. </div>
  174. </AppLayout>
  175. </template>
  176. <style scoped>
  177. .card-statistic {
  178. gap: 1rem;
  179. }
  180. </style>