链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
3.2 KiB

  1. <?php
  2. namespace App\Admin\Metrics\Examples\Order;
  3. use App\Admin\Common\Common;
  4. use Dcat\Admin\Widgets\Metrics\Card;
  5. use Illuminate\Contracts\Support\Renderable;
  6. use Illuminate\Http\Request;
  7. class OrderReportCard extends Card
  8. {
  9. /**
  10. * 卡片底部内容.
  11. *
  12. * @var string|Renderable|\Closure
  13. */
  14. protected $footer;
  15. // 保存自定义参数
  16. protected $data = [];
  17. // 构造方法参数必须设置默认值
  18. public function __construct(array $data = [])
  19. {
  20. $this->data = [];
  21. parent::__construct();
  22. }
  23. protected function init()
  24. {
  25. parent::init();
  26. // 设置标题
  27. $this->title('现存用户总数(人)');
  28. // 设置下拉菜单
  29. $today = date('Y-m-d');
  30. $monthBefore = date("Y-m-d",strtotime("-1 weeks",strtotime($today)));
  31. $timeData = Common::periodDateArr($monthBefore,$today);
  32. $this->dropdown($timeData);
  33. }
  34. /**
  35. * 处理请求.
  36. *
  37. * @param Request $request
  38. *
  39. * @return void
  40. */
  41. public function handle(Request $request)
  42. {
  43. // 获取外部传递的自定义参数
  44. $key1 = $request->get('key1');
  45. switch ($request->get('option')) {
  46. case '365':
  47. $this->content(mt_rand(600, 1500));
  48. $this->down(mt_rand(1, 30));
  49. break;
  50. case '30':
  51. $this->content(mt_rand(170, 250));
  52. $this->up(mt_rand(12, 50));
  53. break;
  54. case '28':
  55. $this->content(mt_rand(155, 200));
  56. $this->up(mt_rand(5, 50));
  57. break;
  58. case '7':
  59. default:
  60. $this->content(143);
  61. $this->up(15);
  62. }
  63. }
  64. // 传递自定义参数到 handle 方法
  65. public function parameters() : array
  66. {
  67. return $this->data;
  68. }
  69. /**
  70. * @param int $percent
  71. *
  72. * @return $this
  73. */
  74. public function up($percent)
  75. {
  76. return $this->footer(
  77. "<i class=\"feather icon-trending-up text-success\"></i> {$percent}% Increase"
  78. );
  79. }
  80. /**
  81. * @param int $percent
  82. *
  83. * @return $this
  84. */
  85. public function down($percent)
  86. {
  87. return $this->footer(
  88. "<i class=\"feather icon-trending-down text-danger\"></i> {$percent}% Decrease"
  89. );
  90. }
  91. /**
  92. * 设置卡片底部内容
  93. *
  94. * @param string|Renderable|\Closure $footer
  95. *
  96. * @return $this
  97. */
  98. public function footer($footer)
  99. {
  100. $this->footer = $footer;
  101. return $this;
  102. }
  103. /**
  104. * 渲染卡片内容.
  105. *
  106. * @return string
  107. */
  108. public function renderContent()
  109. {
  110. $content = parent::renderContent();
  111. return <<<HTML
  112. <div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px">
  113. <h2 class="ml-1 font-large-1">{$content}</h2>
  114. </div>
  115. <div class="ml-1 mt-1 font-weight-bold text-80">
  116. {$this->renderFooter()}
  117. </div>
  118. HTML;
  119. }
  120. /**
  121. * @return string
  122. */
  123. public function renderFooter()
  124. {
  125. return $this->toString($this->footer);
  126. }
  127. }