增加 模块状态

This commit is contained in:
iVampireSP.com 2022-11-23 03:07:18 +00:00
parent d2084a4726
commit 83613ac5d6
5 changed files with 161 additions and 102 deletions

View File

@ -61,21 +61,14 @@ public function store(Request $request): RedirectResponse
$module->name = $request->name;
$module->api_token = $api_token;
$module->url = $request->url;
$module->status = $request->status;
$module->save();
return redirect()->route('admin.modules.index')->with('success', '模块创建成功, 请重置以获得 API Token。');
}
private function rules(): array
{
return [
'id' => 'required|string|max:255',
'name' => 'required|string|max:255',
'url' => 'required|url',
];
}
/**
* Display the specified resource.
*
@ -128,6 +121,7 @@ public function update(Request $request, Module $module): RedirectResponse
$module->id = $request->id;
$module->name = $request->name;
$module->url = $request->url;
$module->status = $request->status;
$module->save();
@ -156,4 +150,15 @@ public function destroy(Module $module): RedirectResponse
return redirect()->route('admin.modules.index')->with('success', '模块已删除。');
}
private function rules(): array
{
return [
'id' => 'required|string|max:255',
'name' => 'required|string|max:255',
'url' => 'required|url',
'status' => 'required|string|in:up,down,maintenance',
];
}
}

View File

@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('modules', function (Blueprint $table) {
//
$table->enum('status', ['up', 'down', 'maintenance'])->index()->default('down');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('modules', function (Blueprint $table) {
//
$table->dropColumn('status');
});
}
};

View File

@ -3,27 +3,37 @@
@section('title', '新建模块')
@section('content')
<h3>新建模块</h3>
<h3>新建模块</h3>
<form method="POST" action="{{ route('admin.modules.store')}}">
@csrf
<form method="POST" action="{{ route('admin.modules.store')}}">
@csrf
<div class="form-group">
<label for="name">ID</label>
<input type="text" class="form-control" id="id" name="id">
</div>
<div class="form-group">
<label for="name">ID</label>
<input type="text" class="form-control" id="id" name="id">
</div>
<div class="form-group">
<label for="name">名称</label>
<input type="text" class="form-control" id="name" name="name">
</div>
<div class="form-group">
<label for="name">名称</label>
<input type="text" class="form-control" id="name" name="name">
</div>
<div class="form-group mt-1">
<label for="name">对端地址</label>
<input type="text" class="form-control" id="url" name="url">
</div>
<div class="form-group mt-1">
<label for="name">对端地址</label>
<input type="text" class="form-control" id="url" name="url">
</div>
<button type="submit" class="btn btn-primary mt-3">提交</button>
</form>
<!-- 选择状态 -->
<div class="form-group mt-1">
<label for="status">状态</label>
<select class="form-control" id="status" name="status">
<option value="up">正常</option>
<option value="down">异常</option>
<option value="maintenance">维护模式</option>
</select>
</div>
@endsection
<button type="submit" class="btn btn-primary mt-3">提交</button>
</form>
@endsection

View File

@ -3,45 +3,53 @@
@section('title', '模块:' . $module->name)
@section('content')
<h3>{{ $module->name }}</h3>
<a class="mt-3" href="{{ route('admin.modules.show', $module) }}">查看</a>
<h3>{{ $module->name }}</h3>
<a class="mt-3" href="{{ route('admin.modules.show', $module) }}">查看</a>
<form method="POST" action="{{ route('admin.modules.update', $module)}}">
@csrf
@method('PATCH')
<form method="POST" action="{{ route('admin.modules.update', $module)}}">
@csrf
@method('PATCH')
<div class="form-group">
<label for="name">ID (修改后,路由也会改变)</label>
<input type="text" class="form-control" id="id" name="id" value="{{ $module->id }}">
</div>
<div class="form-group">
<label for="name">ID (修改后,路由也会改变)</label>
<input type="text" class="form-control" id="id" name="id" value="{{ $module->id }}">
</div>
<div class="form-group">
<label for="name">名称</label>
<input type="text" class="form-control" id="name" name="name" value="{{ $module->name }}">
</div>
<div class="form-group">
<label for="name">名称</label>
<input type="text" class="form-control" id="name" name="name" value="{{ $module->name }}">
</div>
<div class="form-group mt-1">
<label for="name">对端地址</label>
<input type="text" class="form-control" id="url" name="url" value="{{ $module->url }}">
</div>
<div class="form-group mt-1">
<label for="name">对端地址</label>
<input type="text" class="form-control" id="url" name="url" value="{{ $module->url }}">
</div>
<div class="form-check mt-1">
<input class="form-check-input" type="checkbox" value="1" id="reset_api_token" name="reset_api_token">
<label class="form-check-label" for="reset_api_token">
重置 Api Token(重置后,需要到对应的模块中更新,否则会导致模块无法正常工作)
</label>
</div>
<div class="form-group mt-1">
<label for="status">状态</label>
<select class="form-control" id="status" name="status">
<option value="up" @if ($module->status === 'up') selected @endif>正常</option>
<option value="down" @if ($module->status === 'down') selected @endif>异常</option>
<option value="maintenance" @if ($module->status === 'maintenance') selected @endif>维护模式</option>
</select>
</div>
<button type="submit" class="btn btn-primary mt-3">提交</button>
</form>
<div class="form-check mt-1">
<input class="form-check-input" type="checkbox" value="1" id="reset_api_token" name="reset_api_token">
<label class="form-check-label" for="reset_api_token">
重置 Api Token(重置后,需要到对应的模块中更新,否则会导致模块无法正常工作)
</label>
</div>
<button type="submit" class="btn btn-primary mt-3">提交</button>
</form>
<hr/>
<form method="POST" action="{{ route('admin.modules.destroy', $module)}}"
onsubmit="return confirm('删除后,业务将无法正常进行。')">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">删除</button>
</form>
<hr />
<form method="POST" action="{{ route('admin.modules.destroy', $module)}}" onsubmit="return confirm('删除后,业务将无法正常进行。')">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">删除</button>
</form>
@endsection

View File

@ -3,17 +3,18 @@
@section('title', '模块:' . $module->name)
@section('content')
<h3>{{ $module->name }}</h3>
<a class="mt-3" href="{{ route('admin.modules.edit', $module) }}">编辑</a>
<h4 class="mt-2">收益</h4>
<div>
<x-module-earning :module="$module"/>
</div>
<h3>{{ $module->name }}</h3>
<p>状态: {{ $module->status }}</p>
<a class="mt-3" href="{{ route('admin.modules.edit', $module) }}">编辑</a>
<h4 class="mt-2">收益</h4>
<div>
<x-module-earning :module="$module" />
</div>
<h4 class="mt-2">主机</h4>
<div class="overflow-auto">
<table class="table table-hover">
<thead>
<h4 class="mt-2">主机</h4>
<div class="overflow-auto">
<table class="table table-hover">
<thead>
<th>ID</th>
<th>名称</th>
<th>用户</th>
@ -21,41 +22,41 @@
<th>创建时间</th>
<th>更新时间</th>
<th>操作</th>
</thead>
</thead>
<tbody>
<tbody>
@foreach ($hosts as $host)
<tr>
<td>
<a href="{{ route('admin.hosts.edit', $host) }}">
{{ $host->id }}
</a>
</td>
<td>
{{ $host->name }}
</td>
<td>
<a href="{{ route('admin.users.edit', $host->user_id) }}"> {{ $host->user->name }}</a>
</td>
<td>
{{ $host->price }}
</td>
<td>
{{ $host->created_at }}
</td>
<td>
{{ $host->updated_at }}
</td>
<td>
<a href="{{ route('admin.hosts.edit', $host) }}" class="btn btn-primary btn-sm">编辑</a>
</td>
</tr>
<tr>
<td>
<a href="{{ route('admin.hosts.edit', $host) }}">
{{ $host->id }}
</a>
</td>
<td>
{{ $host->name }}
</td>
<td>
<a href="{{ route('admin.users.edit', $host->user_id) }}"> {{ $host->user->name }}</a>
</td>
<td>
{{ $host->price }}
</td>
<td>
{{ $host->created_at }}
</td>
<td>
{{ $host->updated_at }}
</td>
<td>
<a href="{{ route('admin.hosts.edit', $host) }}" class="btn btn-primary btn-sm">编辑</a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</tbody>
</table>
</div>
{{-- 分页 --}}
{{ $hosts->links() }}
@endsection
{{-- 分页 --}}
{{ $hosts->links() }}
@endsection