HomeController.php 9.7 KB

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