HomeController.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use Slowlyo\OwlAdmin\Admin;
  4. use Illuminate\Http\JsonResponse;
  5. use Illuminate\Http\Resources\Json\JsonResource;
  6. use Slowlyo\OwlAdmin\Controllers\AdminController;
  7. class HomeController extends AdminController
  8. {
  9. public function index(): JsonResponse|JsonResource
  10. {
  11. $page = $this->basePage()->css($this->css())->body([
  12. amis()->Grid()->className('mb-1')->columns([
  13. $this->frameworkInfo()->set('md', 5),
  14. amis()->Flex()->items([
  15. $this->pieChart(),
  16. $this->cube(),
  17. ]),
  18. ]),
  19. amis()->Grid()->columns([
  20. $this->lineChart()->set('md', 8),
  21. amis()->Flex()->className('h-full')->items([
  22. $this->clock()
  23. ])->direction('column'),
  24. ]),
  25. ]);
  26. return $this->response()->success($page);
  27. }
  28. public function clock()
  29. {
  30. /** @noinspection all */
  31. return amis()->Card()->className('h-full bg-blingbling mb-4')->header(['title' => 'Clock'])->body([
  32. amis()->Custom()
  33. ->name('clock')
  34. ->html('<div id="clock" class="text-4xl"></div><div id="clock-date" class="mt-5"></div>')
  35. ->onMount(
  36. <<<JS
  37. const clock = document.getElementById('clock');
  38. const tick = () => {
  39. clock.innerHTML = (new Date()).toLocaleTimeString();
  40. requestAnimationFrame(tick);
  41. };
  42. tick();
  43. const clockDate = document.getElementById('clock-date');
  44. clockDate.innerHTML = (new Date()).toLocaleDateString();
  45. JS
  46. ),
  47. ]);
  48. }
  49. public function frameworkInfo()
  50. {
  51. $link = function ($label, $link) {
  52. return amis()->Action()
  53. ->level('link')
  54. ->className('text-lg font-semibold')
  55. ->label($label)
  56. ->set('blank', true)
  57. ->actionType('url')
  58. ->link($link);
  59. };
  60. return amis()->Card()->className('h-96')->body(
  61. amis()->Wrapper()->className('h-full')->body([
  62. amis()->Flex()
  63. ->className('h-full')
  64. ->direction('column')
  65. ->justify('center')
  66. ->alignItems('center')
  67. ->items([
  68. amis()->Image()->src(url(Admin::config('admin.logo'))),
  69. amis()->Wrapper()->className('text-3xl mt-9 font-bold')->body(Admin::config('admin.name')),
  70. amis()->Flex()->className('w-full mt-5')->justify('center')->items([
  71. $link('Official website', 'https://owladmin.com'),
  72. ]),
  73. ]),
  74. ])
  75. );
  76. }
  77. public function pieChart()
  78. {
  79. return amis()->Card()->className('h-96')->body(
  80. amis()->Chart()->height(350)->config([
  81. 'backgroundColor' => '',
  82. 'tooltip' => ['trigger' => 'item'],
  83. 'legend' => ['bottom' => 0, 'left' => 'center'],
  84. 'series' => [
  85. [
  86. 'name' => 'Access From',
  87. 'type' => 'pie',
  88. 'radius' => ['40%', '70%'],
  89. 'avoidLabelOverlap' => false,
  90. 'itemStyle' => ['borderRadius' => 10, 'borderColor' => '#fff', 'borderWidth' => 2],
  91. 'label' => ['show' => false, 'position' => 'center'],
  92. 'emphasis' => [
  93. 'label' => [
  94. 'show' => true,
  95. 'fontSize' => '40',
  96. 'fontWeight' => 'bold',
  97. ],
  98. ],
  99. 'labelLine' => ['show' => false],
  100. 'data' => [
  101. ['value' => 1048, 'name' => 'Search Engine'],
  102. ['value' => 735, 'name' => 'Direct'],
  103. ['value' => 580, 'name' => 'Email'],
  104. ['value' => 484, 'name' => 'Union Ads'],
  105. ['value' => 300, 'name' => 'Video Ads'],
  106. ],
  107. ],
  108. ],
  109. ])
  110. );
  111. }
  112. public function lineChart()
  113. {
  114. $randArr = function () {
  115. $_arr = [];
  116. for ($i = 0; $i < 7; $i++) {
  117. $_arr[] = rand(50, 200);
  118. }
  119. return $_arr;
  120. };
  121. $random1 = $randArr();
  122. $random2 = $randArr();
  123. $chart = amis()->Chart()->height(380)->className('h-96')->config([
  124. 'backgroundColor' => '',
  125. 'title' => ['text' => 'Users Behavior'],
  126. 'tooltip' => ['trigger' => 'axis'],
  127. 'xAxis' => [
  128. 'type' => 'category',
  129. 'boundaryGap' => false,
  130. 'data' => ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
  131. ],
  132. 'yAxis' => ['type' => 'value'],
  133. 'grid' => ['left' => '7%', 'right' => '3%', 'top' => 60, 'bottom' => 30,],
  134. 'legend' => ['data' => ['Visits', 'Bounce Rate']],
  135. 'series' => [
  136. [
  137. 'name' => 'Visits',
  138. 'data' => $random1,
  139. 'type' => 'line',
  140. 'areaStyle' => [],
  141. 'smooth' => true,
  142. 'symbol' => 'none',
  143. ],
  144. [
  145. 'name' => 'Bounce Rate',
  146. 'data' => $random2,
  147. 'type' => 'line',
  148. 'areaStyle' => [],
  149. 'smooth' => true,
  150. 'symbol' => 'none',
  151. ],
  152. ],
  153. ]);
  154. return amis()->Card()->className('clear-card-mb')->body($chart);
  155. }
  156. public function cube()
  157. {
  158. return amis()->Card()->className('h-96 ml-4 w-8/12')->body(
  159. amis()->Html()->html(
  160. <<<HTML
  161. <style>
  162. .cube-box{ height: 300px; display: flex; align-items: center; justify-content: center; }
  163. .cube { width: 100px; height: 100px; position: relative; transform-style: preserve-3d; animation: rotate 10s linear infinite; }
  164. .cube:after {
  165. content: '';
  166. width: 100%;
  167. height: 100%;
  168. box-shadow: 0 0 50px rgba(0, 0, 0, 0.2);
  169. position: absolute;
  170. transform-origin: bottom;
  171. transform-style: preserve-3d;
  172. transform: rotateX(90deg) translateY(50px) translateZ(-50px);
  173. background-color: rgba(0, 0, 0, 0.1);
  174. }
  175. .cube div {
  176. background-color: rgba(64, 158, 255, 0.7);
  177. position: absolute;
  178. width: 100%;
  179. height: 100%;
  180. border: 1px solid rgb(27, 99, 170);
  181. box-shadow: 0 0 60px rgba(64, 158, 255, 0.7);
  182. }
  183. .cube div:nth-child(1) { transform: translateZ(-50px); animation: shade 10s -5s linear infinite; }
  184. .cube div:nth-child(2) { transform: translateZ(50px) rotateY(180deg); animation: shade 10s linear infinite; }
  185. .cube div:nth-child(3) { transform-origin: right; transform: translateZ(50px) rotateY(270deg); animation: shade 10s -2.5s linear infinite; }
  186. .cube div:nth-child(4) { transform-origin: left; transform: translateZ(50px) rotateY(90deg); animation: shade 10s -7.5s linear infinite; }
  187. .cube div:nth-child(5) { transform-origin: bottom; transform: translateZ(50px) rotateX(90deg); background-color: rgba(0, 0, 0, 0.7); }
  188. .cube div:nth-child(6) { transform-origin: top; transform: translateZ(50px) rotateX(270deg); }
  189. @keyframes rotate {
  190. 0% { transform: rotateX(-15deg) rotateY(0deg); }
  191. 100% { transform: rotateX(-15deg) rotateY(360deg); }
  192. }
  193. @keyframes shade { 50% { background-color: rgba(0, 0, 0, 0.7); } }
  194. </style>
  195. <div class="cube-box">
  196. <div class="cube">
  197. <div></div>
  198. <div></div>
  199. <div></div>
  200. <div></div>
  201. <div></div>
  202. <div></div>
  203. </div>
  204. </div>
  205. HTML
  206. )
  207. );
  208. }
  209. private function css(): array
  210. {
  211. /** @noinspection all */
  212. return [
  213. '.clear-card-mb' => [
  214. 'margin-bottom' => '0 !important',
  215. ],
  216. '.cxd-Image' => [
  217. 'border' => '0',
  218. ],
  219. '.bg-blingbling' => [
  220. 'color' => '#fff',
  221. 'background' => 'linear-gradient(to bottom right, #2C3E50, #FD746C, #FF8235, #ffff1c, #92FE9D, #00C9FF, #a044ff, #e73827)',
  222. 'background-repeat' => 'no-repeat',
  223. 'background-size' => '1000% 1000%',
  224. 'animation' => 'gradient 60s ease infinite',
  225. ],
  226. '@keyframes gradient' => [
  227. '0%{background-position:0% 0%} 50%{background-position:100% 100%} 100%{background-position:0% 0%}',
  228. ],
  229. '.bg-blingbling .cxd-Card-title' => [
  230. 'color' => '#fff',
  231. ],
  232. ];
  233. }
  234. }