generated from liutk/owl-admin-base
调整后台首页
parent
1788620e8f
commit
3c19d5e4e5
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Slowlyo\OwlAdmin\Renderers\Card;
|
||||
use Slowlyo\OwlAdmin\Renderers\Flex;
|
||||
|
|
@ -14,19 +15,20 @@ use Slowlyo\OwlAdmin\Renderers\Custom;
|
|||
use Slowlyo\OwlAdmin\Renderers\Wrapper;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Slowlyo\OwlAdmin\Controllers\AdminController;
|
||||
use App\Models\User;
|
||||
|
||||
class HomeController extends AdminController
|
||||
{
|
||||
public function index(): JsonResponse|JsonResource
|
||||
{
|
||||
$page = $this->basePage()->css($this->css())->body([
|
||||
Grid::make()->columns([
|
||||
$this->frameworkInfo()->md(5),
|
||||
Flex::make()->items([
|
||||
$this->pieChart(),
|
||||
$this->cube(),
|
||||
]),
|
||||
]),
|
||||
// Grid::make()->columns([
|
||||
// $this->frameworkInfo()->md(5),
|
||||
// Flex::make()->items([
|
||||
// $this->pieChart(),
|
||||
// $this->cube(),
|
||||
// ]),
|
||||
// ]),
|
||||
Grid::make()->columns([
|
||||
$this->lineChart()->md(8),
|
||||
Flex::make()->className('h-full')->items([
|
||||
|
|
@ -171,28 +173,43 @@ JS
|
|||
|
||||
public function lineChart(): Card
|
||||
{
|
||||
$randArr = function () {
|
||||
$_arr = [];
|
||||
for ($i = 0; $i < 7; $i++) {
|
||||
$_arr[] = random_int(10, 200);
|
||||
$days = [];
|
||||
for($i=0; $i<7; $i++){
|
||||
$days[] = now()->subDays($i)->format('Y-m-d');
|
||||
}
|
||||
return '[' . implode(',', $_arr) . ']';
|
||||
};
|
||||
$createUser = User::selectRaw('DATE(`created_at`) as day, count(id) as num')
|
||||
->whereBetween('created_at', [now()->subDays(6)->startOfDay(), now()])
|
||||
->groupBy('day')
|
||||
->get()->pluck('num', 'day')->toArray();
|
||||
|
||||
$random1 = $randArr();
|
||||
$random2 = $randArr();
|
||||
$bindUser = User::selectRaw('DATE(`bind_phone_at`) as day, count(id) as num')
|
||||
->whereBetween('bind_phone_at', [now()->subDays(6)->startOfDay(), now()])
|
||||
->groupBy('day')
|
||||
->get()->pluck('num', 'day')->toArray();
|
||||
|
||||
foreach($days as $day){
|
||||
if(!isset($createUser[$day])){
|
||||
$createUser[$day] = 0;
|
||||
}
|
||||
if(!isset($bindUser[$day])){
|
||||
$bindUser[$day] = 0;
|
||||
}
|
||||
}
|
||||
asort($createUser);asort($bindUser);
|
||||
$createUser = '['.implode(',', $createUser).']';
|
||||
$bindUser = '['.implode(',', $bindUser).']';
|
||||
|
||||
$chart = Chart::make()->height(380)->className('h-96')->config("{
|
||||
backgroundColor:'',
|
||||
title:{ text: '会员增长情况', },
|
||||
tooltip: { trigger: 'axis' },
|
||||
xAxis: { type: 'category', boundaryGap: false, data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] },
|
||||
xAxis: { type: 'category', boundaryGap: false, data: ['".implode("','", $days)."']},
|
||||
yAxis: { type: 'value' },
|
||||
grid:{ left: '7%', right:'3%', top: 60, bottom: 30, },
|
||||
legend: { data: ['访问量','注册量'] },
|
||||
series: [
|
||||
{ name: '访问量', data: {$random1}, type: 'line', areaStyle: {}, smooth: true, symbol: 'none', },
|
||||
{ name:'注册量', data: {$random2}, type: 'line', areaStyle: {}, smooth: true, symbol: 'none', },
|
||||
{ name: '访问量', data: {$createUser}, type: 'line', areaStyle: {}, smooth: true, symbol: 'none', },
|
||||
{ name:'注册量', data: {$bindUser}, type: 'line', areaStyle: {}, smooth: true, symbol: 'none', },
|
||||
]}");
|
||||
|
||||
return Card::make()->className('clear-card-mb')->body($chart);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
return [
|
||||
// 应用名称
|
||||
'name' => 'Owl Admin',
|
||||
'name' => '竞猜小程序',
|
||||
|
||||
// 应用 logo
|
||||
'logo' => '/admin-assets/logo.png',
|
||||
|
|
@ -86,7 +86,7 @@ return [
|
|||
|
||||
'layout' => [
|
||||
// 浏览器标题, 功能名称使用 %title% 代替
|
||||
'title' => '%title% | OwlAdmin',
|
||||
'title' => '%title% | 竞猜小程序',
|
||||
'header' => [
|
||||
// 是否显示 [刷新] 按钮
|
||||
'refresh' => true,
|
||||
|
|
|
|||
Loading…
Reference in New Issue