dark35(); // 卡片内容宽度 $this->contentWidth(5, 7); // 标题 $this->title('Avg Sessions'); // 设置下拉选项 $this->dropdown([ '7' => 'Last 7 Days', '28' => 'Last 28 Days', '30' => 'Last Month', '365' => 'Last Year', ]); // 设置图表颜色 $this->chartColors([ $dark35, $dark35, $color->primary(), $dark35, $dark35, $dark35 ]); } /** * 处理请求 * * @param Request $request * * @return mixed|void */ public function handle(Request $request) { switch ($request->get('option')) { case '7': default: // 卡片内容 $this->withContent('2.7k', '+5.2%'); // 图表数据 $this->withChart([ [ 'name' => 'Sessions', 'data' => [75, 125, 225, 175, 125, 75, 25], ], ]); } } /** * 设置图表数据. * * @param array $data * * @return $this */ public function withChart(array $data) { return $this->chart([ 'series' => $data, ]); } /** * 设置卡片内容. * * @param string $title * @param string $value * @param string $style * * @return $this */ public function withContent($title, $value, $style = 'success') { // 根据选项显示 $label = strtolower( $this->dropdown[request()->option] ?? 'last 7 days' ); $minHeight = '183px'; return $this->content( <<