改进 收益显示

This commit is contained in:
iVampireSP.com 2022-11-20 11:51:19 +08:00
parent 8e14b89ffa
commit e500341d68
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
6 changed files with 91 additions and 29 deletions

View File

@ -0,0 +1,18 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\Module;
use Illuminate\Http\Request;
class HomeController extends Controller
{
//
public function index() {
$modules = Module::paginate(10);
return view('admin.index', compact('modules'));
}
}

View File

@ -0,0 +1,33 @@
<?php
namespace App\View\Components;
use App\Models\Module;
use Illuminate\View\Component;
class ModuleEarning extends Component
{
private Module $module;
/**
* Create a new component instance.
*
* @return void
*/
public function __construct(Module $module)
{
//
$this->module = $module;
}
/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\Contracts\View\View|\Closure|string
*/
public function render()
{
$years = $this->module->calculate();
return view('components.module-earning', compact('years'));
}
}

View File

@ -3,7 +3,18 @@
@section('title', '首页')
@section('content')
<h2>今年的收益</h2>
欢迎来到后台管理系统
@foreach($modules as $module)
@php($years = $module->calculate())
<h3 class="mb-3">{{ $module->name }}</h3>
<div class="mt-3">
<x-module-earning :module="$module"/>
</div>
@endforeach
{{ $modules->links() }}
@endsection

View File

@ -5,31 +5,8 @@
@section('content')
<h3>{{ $module->name }}</h3>
<a class="mt-3" href="{{ route('admin.modules.edit', $module) }}">编辑</a>
<h4>收益</h4>
<h4 class="mt-2">收益</h4>
<div>
<table class="table table-hover">
<thead>
<th> / </th>
@for ($i = 1; $i < 13; $i++)
<th>{{ $i }} </th>
@endfor
</thead>
<tbody>
@foreach ($years as $year => $months)
<tr>
<td>{{ $year }}</td>
@for ($i = 1; $i < 13; $i++)
<td @if ($months[$i]['should_balance'] ?? 0 > 0) class="text-danger" @endif>{{ $months[$i]['should_balance'] ?? 0 }}
</td>
@endfor
</tr>
@endforeach
</tbody>
</table>
<x-module-earning :module="$module" />
</div>
@endsection

View File

@ -0,0 +1,24 @@
<table class="table table-hover">
<thead>
<th> / </th>
@for ($i = 1; $i < 13; $i++)
<th>{{ $i }} </th>
@endfor
</thead>
<tbody>
@foreach ($years as $year => $months)
<tr>
<td>{{ $year }}</td>
@for ($i = 1; $i < 13; $i++)
<td @if (($months[$i]['should_balance'] ?? 0) > 0) class="text-danger" @endif>{{ $months[$i]['should_balance'] ?? 0 }}
</td>
@endfor
</tr>
@endforeach
</tbody>
</table>

View File

@ -1,6 +1,7 @@
<?php
use App\Http\Controllers\Admin\AuthController;
use App\Http\Controllers\Admin\HomeController;
use App\Http\Controllers\Admin\HostController;
use App\Http\Controllers\Admin\ModuleController;
use App\Http\Controllers\Admin\UserController;
@ -13,9 +14,7 @@
});
Route::post('/logout', [AuthController::class, 'logout'])->name('logout');
Route::view('/', 'admin.index')->name('index')->middleware('auth:admin');
Route::get('/', [HomeController::class, 'index'])->name('index')->middleware('auth:admin');
Route::group([
'middleware' => 'auth:admin',