123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- namespace App\Admin\Metrics\Examples;
- use App\Models\Game;
- use Dcat\Admin\Widgets\Metrics\Line;
- use Illuminate\Http\Request;
- class Games extends Line
- {
- /**
- * 初始化卡片内容
- */
- protected function init()
- {
- parent::init();
- $this->title(trans('admin-home.Recent_events'));
- $this->height(400);
- //$this->chartHeight(300);
- //$this->chartLabels('Completed Tickets');
- // $this->dropdown([
- // '7' => 'Last 7 Days',
- // '28' => 'Last 28 Days',
- // '30' => 'Last Month',
- // '365' => 'Last Year',
- // ]);
- }
- /**
- * 处理请求
- *
- * @param Request $request
- *
- * @return mixed|void
- */
- public function handle(Request $request)
- {
- $games = Game::query()->orderByDesc('id')->limit(5)->select(['id','name','begin_time'])->get()->toArray();
- $this->withContent($games);
- }
- /**
- * 设置图表数据.
- *
- * @param int $data
- *
- * @return $this
- */
- public function withChart(int $data)
- {
- return $this->chart([
- 'series' => [$data],
- ]);
- }
- /**
- * 卡片内容
- *
- * @param string $content
- *
- * @return $this
- */
- public function withContent($content)
- {
- $str = '';
- foreach ($content as $k=>$v){
- $str.= '<h4 class="font-lg-12 mt-2 mb-3">'.$v['name'].' '.'<span style="float: right;font-size: 16px">'.trans('admin-home.Start_time').':'.$v['begin_time'].'</span></h4>';
- }
- return $this->content(
- <<<HTML
- <div class="justify-content-between align-items-center p-1">
- {$str}
- </div>
- HTML
- );
- }
- /**
- * 卡片底部内容.
- *
- * @param string $new
- * @param string $open
- * @param string $response
- *
- * @return $this
- */
- public function withFooter($new, $open, $response)
- {
- return $this->footer(
- <<<HTML
- <div class="d-flex justify-content-between p-1" style="padding-top: 0!important;">
- <div class="text-center">
- <p>New Tickets</p>
- <span class="font-lg-1">{$new}</span>
- </div>
- <div class="text-center">
- <p>Open Tickets</p>
- <span class="font-lg-1">{$open}</span>
- </div>
- <div class="text-center">
- <p>Response Time</p>
- <span class="font-lg-1">{$response}</span>
- </div>
- </div>
- HTML
- );
- }
- }
|