NumberS2.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace UCore\DcatAdmin\Metrics\Examples;
  3. use Dcat\Admin\Widgets\Metrics\RadialBar;
  4. use Illuminate\Support\Str;
  5. /**
  6. * 显示多个数值
  7. * 一行
  8. */
  9. class NumberS2 extends RadialBar
  10. {
  11. protected $contentWidth = [ 12, 0 ];
  12. protected $chartPullRight = true;
  13. protected $decimal_places = 2;
  14. /**
  15. * 初始化卡片内容
  16. */
  17. protected function init()
  18. {
  19. $this->id('metric-card-' . Str::random(8));
  20. $this->class('card');
  21. $this->height(130);
  22. $this->dropdown([
  23. '1' => '最近 1 天',
  24. '7' => '最近 7 天',
  25. '30' => '最近 30 天',
  26. '90' => '最近 90 天',
  27. ]);
  28. }
  29. /**
  30. * 处理请求,获取数值
  31. *
  32. * @param \Illuminate\Http\Request $request
  33. *
  34. * @return mixed|void
  35. */
  36. public function handle(\Illuminate\Http\Request $request)
  37. {
  38. switch ($request->get('option')) {
  39. case '1':
  40. default:
  41. // 演示数值
  42. $data = [
  43. 'sum' => 10,
  44. 'sum_price' => 1.1,
  45. 'sum_huansuan' => 100,
  46. 'sum2' => 102
  47. ];
  48. }
  49. // 卡片底部
  50. $this->withContent([
  51. '数额' => $data['sum'],
  52. '交易额' => $data['sum_price'],
  53. '交易额2' => $data['sum2'],
  54. '换算额' => $data['sum_huansuan']
  55. ]);
  56. }
  57. /**
  58. * 卡片内容.
  59. *
  60. * @param string $new
  61. * @param string $open
  62. * @param string $response
  63. *
  64. * @return $this
  65. */
  66. public function withContent($dataList)
  67. {
  68. $string = '';
  69. foreach ($dataList as $key => $value) {
  70. $value = number_format(floatval($value), $this->decimal_places);
  71. $string .= <<<HTML
  72. <div class="text-center">
  73. <p>$key</p>
  74. <span class="font-md-5">{$value}</span>
  75. </div>
  76. HTML;
  77. }
  78. return $this->content(
  79. <<<HTML
  80. <div class="d-flex justify-content-between p-1" style="padding-top: 15px !important;">
  81. $string
  82. </div>
  83. HTML
  84. );
  85. }
  86. }