Index.vue 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <script setup>
  2. import { ref } from 'vue'
  3. import { Head } from '@inertiajs/inertia-vue3'
  4. import AppLayout from '@/layouts/AppLayout.vue'
  5. defineProps({
  6. cardStatistics: Object,
  7. chartStatistics: Object,
  8. })
  9. const chartData = (chartData) => {
  10. const colors = ['#42A5F5', '#FFA726']
  11. const data = {
  12. datasets: [],
  13. }
  14. let id = 0
  15. for (const key in chartData) {
  16. data.datasets.push({
  17. label: key,
  18. backgroundColor: colors[id],
  19. data: chartData[key],
  20. })
  21. id++
  22. }
  23. return data
  24. }
  25. const chartOptions = ref({
  26. responsive: true,
  27. maintainAspectRatio: false,
  28. datasetFill: false,
  29. scales: {
  30. y: {
  31. ticks: {
  32. beginAtZero: true,
  33. callback: function (label) {
  34. if (Math.floor(label) === label) {
  35. return label
  36. }
  37. },
  38. },
  39. },
  40. },
  41. })
  42. </script>
  43. <template>
  44. <AppLayout>
  45. <Head title="Dashboard" />
  46. <div class="grid">
  47. <div v-for="cardStatistic in cardStatistics" class="col-12 md:col-3">
  48. <Card class="h-full">
  49. <template #content>
  50. <div class="flex justify-content-between mb-3">
  51. <div>
  52. <span class="block text-500 font-medium mb-3">{{ cardStatistic.title }}</span>
  53. <div v-if="cardStatistic.value" class="text-900 font-medium text-xl">{{ cardStatistic.value }}</div>
  54. </div>
  55. <div
  56. class="flex align-items-center justify-content-center bg-orange-100 border-round"
  57. style="width: 2.5rem; height: 2.5rem"
  58. >
  59. <i class="text-orange-500 text-xl" :class="cardStatistic.icon"></i>
  60. </div>
  61. </div>
  62. <span class="text-green-500 font-medium">{{ cardStatistic.amount }} </span>
  63. <span class="text-500"> {{ ' ' + cardStatistic.amountLabel }}</span>
  64. </template>
  65. </Card>
  66. </div>
  67. <div v-for="chartStatistic in chartStatistics" class="col-12 md:col-6">
  68. <Card>
  69. <template #title>{{ chartStatistic.title }}</template>
  70. <template #content>
  71. <Chart type="bar" :data="chartData(chartStatistic.data)" :options="chartOptions" />
  72. </template>
  73. </Card>
  74. </div>
  75. </div>
  76. </AppLayout>
  77. </template>