data = []; parent::__construct(); } protected function init() { parent::init(); // 设置标题 $this->title('现存用户总数(人)'); // 设置下拉菜单 $today = date('Y-m-d'); $monthBefore = date("Y-m-d",strtotime("-1 weeks",strtotime($today))); $timeData = Common::periodDateArr($monthBefore,$today); $this->dropdown($timeData); } /** * 处理请求. * * @param Request $request * * @return void */ public function handle(Request $request) { // 获取外部传递的自定义参数 $key1 = $request->get('key1'); switch ($request->get('option')) { case '365': $this->content(mt_rand(600, 1500)); $this->down(mt_rand(1, 30)); break; case '30': $this->content(mt_rand(170, 250)); $this->up(mt_rand(12, 50)); break; case '28': $this->content(mt_rand(155, 200)); $this->up(mt_rand(5, 50)); break; case '7': default: $this->content(143); $this->up(15); } } // 传递自定义参数到 handle 方法 public function parameters() : array { return $this->data; } /** * @param int $percent * * @return $this */ public function up($percent) { return $this->footer( " {$percent}% Increase" ); } /** * @param int $percent * * @return $this */ public function down($percent) { return $this->footer( " {$percent}% Decrease" ); } /** * 设置卡片底部内容 * * @param string|Renderable|\Closure $footer * * @return $this */ public function footer($footer) { $this->footer = $footer; return $this; } /** * 渲染卡片内容. * * @return string */ public function renderContent() { $content = parent::renderContent(); return <<