增加 应用程序
This commit is contained in:
parent
f214664317
commit
80c0059d3a
124
app/Http/Controllers/Admin/ApplicationController.php
Normal file
124
app/Http/Controllers/Admin/ApplicationController.php
Normal file
@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Application;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class ApplicationController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
|
||||
$applications = Application::paginate(100);
|
||||
|
||||
return view('admin.applications.index', compact('applications'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
|
||||
return view('admin.applications.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return View
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
|
||||
$this->validate($request, [
|
||||
'name' => 'required',
|
||||
'description' => 'required',
|
||||
'api_token' => 'required|unique:applications,api_token',
|
||||
]);
|
||||
|
||||
$application = Application::create($request->all());
|
||||
|
||||
return view('admin.applications.edit', compact('application'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\Application $application
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function show(Application $application)
|
||||
{
|
||||
//
|
||||
|
||||
return redirect()->route('admin.applications.edit', $application);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\Application $application
|
||||
* @return View
|
||||
*/
|
||||
public function edit(Application $application)
|
||||
{
|
||||
//
|
||||
|
||||
return view('admin.applications.edit', compact('application'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\Application $application
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(Request $request, Application $application)
|
||||
{
|
||||
//
|
||||
|
||||
$this->validate($request, [
|
||||
'name' => 'required',
|
||||
'description' => 'required',
|
||||
'api_token' => 'required|unique:applications,api_token,' . $application->id,
|
||||
]);
|
||||
|
||||
$application->update($request->all());
|
||||
|
||||
return back()->with('success', '应用程序已更新。');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\Application $application
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(Application $application)
|
||||
{
|
||||
//
|
||||
|
||||
$application->delete();
|
||||
|
||||
return redirect()->route('admin.applications.index')->with('success', '应用程序已删除。');
|
||||
}
|
||||
}
|
11
app/Http/Controllers/Application/AuthController.php
Normal file
11
app/Http/Controllers/Application/AuthController.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Application;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AuthController extends Controller
|
||||
{
|
||||
//
|
||||
}
|
17
app/Models/Application.php
Normal file
17
app/Models/Application.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
|
||||
class Application extends Authenticatable
|
||||
{
|
||||
use Cachable;
|
||||
|
||||
public $fillable = [
|
||||
'name',
|
||||
'description',
|
||||
'api_token',
|
||||
];
|
||||
}
|
@ -39,6 +39,11 @@ public function boot()
|
||||
->as('modules.')
|
||||
->group(base_path('routes/modules.php'));
|
||||
|
||||
Route::middleware(['module', 'auth:application'])
|
||||
->prefix('applications')
|
||||
->as('applications.')
|
||||
->group(base_path('routes/applications.php'));
|
||||
|
||||
Route::middleware(['web'])
|
||||
->prefix('admin')
|
||||
->as('admin.')
|
||||
|
@ -51,6 +51,11 @@
|
||||
'provider' => 'modules',
|
||||
],
|
||||
|
||||
'application' => [
|
||||
'driver' => 'token',
|
||||
'provider' => 'applications',
|
||||
],
|
||||
|
||||
'api' => [
|
||||
'driver' => 'api'
|
||||
],
|
||||
@ -88,6 +93,11 @@
|
||||
'driver' => 'eloquent',
|
||||
'model' => App\Models\Module::class,
|
||||
],
|
||||
|
||||
'applications' => [
|
||||
'driver' => 'eloquent',
|
||||
'model' => App\Models\Application::class,
|
||||
],
|
||||
],
|
||||
|
||||
/*
|
||||
|
@ -0,0 +1,37 @@
|
||||
<?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::create('applications', function (Blueprint $table) {
|
||||
$table->id();
|
||||
|
||||
$table->string('name')->index();
|
||||
|
||||
$table->string('description')->nullable();
|
||||
|
||||
$table->string('api_token')->index()->unique();
|
||||
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('applications');
|
||||
}
|
||||
};
|
53
resources/views/admin/applications/create.blade.php
Normal file
53
resources/views/admin/applications/create.blade.php
Normal file
@ -0,0 +1,53 @@
|
||||
@extends('layouts.admin')
|
||||
|
||||
@section('title', '新建应用')
|
||||
|
||||
@section('content')
|
||||
<h3>新建应用</h3>
|
||||
|
||||
<form method="POST" action="{{ route('admin.applications.store')}}">
|
||||
@csrf
|
||||
|
||||
<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="description">描述</label>
|
||||
<input type="text" class="form-control" id="description" name="description">
|
||||
</div>
|
||||
|
||||
<div class="form-group mt-1">
|
||||
<label for="api_token">密钥</label>
|
||||
<input type="text" class="form-control" id="api_token" name="api_token" required autocomplete="off">
|
||||
<span class="form-text text-muted">密钥应该保密,并且还应该是唯一的。</span>
|
||||
|
||||
</div>
|
||||
|
||||
{{-- 随机密钥生成 --}}
|
||||
<div class="form-group mt-1">
|
||||
<button type="button" class="btn btn-primary" id="generate-api-token" onclick="fillApiToken()">生成密钥
|
||||
</button>
|
||||
</div>
|
||||
|
||||
|
||||
<button type="submit" class="btn btn-primary mt-3">提交</button>
|
||||
</form>
|
||||
|
||||
|
||||
<script>
|
||||
function randomString(length) {
|
||||
let chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
let result = '';
|
||||
for (let i = length; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)];
|
||||
return result;
|
||||
}
|
||||
|
||||
function fillApiToken() {
|
||||
|
||||
document.getElementById('api_token').value = randomString(32);
|
||||
}
|
||||
</script>
|
||||
|
||||
@endsection
|
64
resources/views/admin/applications/edit.blade.php
Normal file
64
resources/views/admin/applications/edit.blade.php
Normal file
@ -0,0 +1,64 @@
|
||||
@extends('layouts.admin')
|
||||
|
||||
@section('title', '应用程序: ' . $application->name)
|
||||
|
||||
@section('content')
|
||||
<h3>{{ $application->name }}</h3>
|
||||
{{-- <a class="mt-3" href="{{ route('admin.applications.show', $application) }}">查看</a>--}}
|
||||
|
||||
<form method="POST" action="{{ route('admin.applications.update', $application)}}">
|
||||
@csrf
|
||||
@method('PATCH')
|
||||
|
||||
<div class="form-group">
|
||||
<label for="name">名称</label>
|
||||
<input type="text" class="form-control" id="name" name="name" value="{{ $application->name }}">
|
||||
</div>
|
||||
|
||||
<div class="form-group mt-1">
|
||||
<label for="description">描述</label>
|
||||
<input type="text" class="form-control" id="description" name="description"
|
||||
value="{{ $application->description }}">
|
||||
</div>
|
||||
|
||||
<div class="form-group mt-1">
|
||||
<label for="api_token">密钥</label>
|
||||
<input type="text" class="form-control" id="api_token" name="api_token"
|
||||
value="{{ $application->api_token }}" required autocomplete="off">
|
||||
<span class="form-text text-muted">密钥应该保密,并且还应该是唯一的。</span>
|
||||
|
||||
</div>
|
||||
|
||||
{{-- 随机密钥生成 --}}
|
||||
<div class="form-group mt-1">
|
||||
<button type="button" class="btn btn-primary" id="generate-api-token" onclick="fillApiToken()">生成密钥
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary mt-3">提交</button>
|
||||
</form>
|
||||
|
||||
|
||||
<hr/>
|
||||
<form method="POST" action="{{ route('admin.applications.destroy', $application)}}"
|
||||
onsubmit="return confirm('删除后,业务将无法正常进行。')">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button type="submit" class="btn btn-danger">删除</button>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
function randomString(length) {
|
||||
let chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
let result = '';
|
||||
for (let i = length; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)];
|
||||
return result;
|
||||
}
|
||||
|
||||
function fillApiToken() {
|
||||
|
||||
document.getElementById('api_token').value = randomString(32);
|
||||
}
|
||||
</script>
|
||||
|
||||
@endsection
|
44
resources/views/admin/applications/index.blade.php
Normal file
44
resources/views/admin/applications/index.blade.php
Normal file
@ -0,0 +1,44 @@
|
||||
@extends('layouts.admin')
|
||||
|
||||
@section('title', '应用程序')
|
||||
|
||||
@section('content')
|
||||
<h3>应用程序</h3>
|
||||
<a href="{{ route('admin.applications.create') }}">新建应用</a>
|
||||
<div class="overflow-auto">
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
<th>ID</th>
|
||||
<th>名称</th>
|
||||
<th>描述</th>
|
||||
<th>操作</th>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
@foreach ($applications as $application)
|
||||
<tr>
|
||||
<td>
|
||||
<a href="{{ route('admin.applications.show', $application) }}">
|
||||
{{ $application->id }}
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
{{ $application->name }}
|
||||
</td>
|
||||
<td>
|
||||
{{ $application->description }}
|
||||
</td>
|
||||
<td>
|
||||
<a href="{{ route('admin.applications.edit', $application) }}"
|
||||
class="btn btn-primary btn-sm">编辑</a>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{{-- 分页 --}}
|
||||
{{ $applications->links() }}
|
||||
|
||||
@endsection
|
@ -1,6 +1,6 @@
|
||||
@extends('layouts.admin')
|
||||
|
||||
@section('title', '模块:' . $module->name)
|
||||
@section('title', '模块: ' . $module->name)
|
||||
|
||||
@section('content')
|
||||
<h3>{{ $module->name }}</h3>
|
||||
|
@ -38,8 +38,4 @@
|
||||
{{-- 分页 --}}
|
||||
{{ $modules->links() }}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@endsection
|
||||
|
@ -1,6 +1,6 @@
|
||||
@extends('layouts.admin')
|
||||
|
||||
@section('title', '模块:' . $module->name)
|
||||
@section('title', '模块: ' . $module->name)
|
||||
|
||||
@section('content')
|
||||
<h3>{{ $module->name }}</h3>
|
||||
|
@ -55,6 +55,9 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{ route('admin.user-groups.index') }}">用户组</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{ route('admin.applications.index') }}">应用程序</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{ route('admin.commands') }}">命令速查表</a>
|
||||
</li>
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
use App\Http\Controllers\Admin\AdminController;
|
||||
use App\Http\Controllers\Admin\ApplicationController;
|
||||
use App\Http\Controllers\Admin\AuthController;
|
||||
use App\Http\Controllers\Admin\HomeController;
|
||||
use App\Http\Controllers\Admin\HostController;
|
||||
@ -24,6 +25,7 @@
|
||||
Route::resource('admins', AdminController::class)->except('show');
|
||||
Route::resource('users', UserController::class)->only(['index', 'show', 'edit', 'update']);
|
||||
Route::resource('modules', ModuleController::class);
|
||||
Route::resource('applications', ApplicationController::class);
|
||||
Route::resource('hosts', HostController::class)->only(['index', 'edit', 'update', 'destroy']);
|
||||
Route::resource('work-orders', WorkOrderController::class)->only(['index', 'show', 'edit', 'update', 'destroy']);
|
||||
|
||||
|
3
routes/applications.php
Normal file
3
routes/applications.php
Normal file
@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
// Route::post('')
|
Loading…
Reference in New Issue
Block a user