173 lines
3.8 KiB
Markdown
Executable File
173 lines
3.8 KiB
Markdown
Executable File
# Dcat-Admin
|
|
|
|
Fork From [jqhph/dcat-admin](https://github.com/jqhph/dcat-admin)
|
|
|
|
## 安装
|
|
|
|
- `composer` 镜像(可选): `composer config repo.packagist composer https://mirrors.aliyun.com/composer/`
|
|
- `composer config repositories.peidikeji/dcat-admin git https://gitea.peidikeji.cn/pdkj/dcat-admin.git`
|
|
- `composer require peidikeji/dcat-admin`
|
|
- 修改 `config/app.php`
|
|
|
|
```php
|
|
return [
|
|
'timezone' => env('TIMEZONE', 'Asia/Chongqing'),
|
|
'locale' => 'zh_CN',
|
|
'faker_locale' => 'zh_CN',
|
|
];
|
|
```
|
|
|
|
- 修改 `app\Providers\AppServiceProvider.php`
|
|
|
|
```php
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
public function boot()
|
|
{
|
|
Schema::defaultStringLength(191);
|
|
JsonResource::withoutWrapping();
|
|
}
|
|
```
|
|
|
|
- 修改`.env` 中的数据库配置
|
|
|
|
```
|
|
APP_URL=网站域名(如: https://laravel.com)
|
|
|
|
LOG_DEPRECATIONS_CHANNEL=null(删除本项)
|
|
|
|
DB_CONNECTION=mysql
|
|
DB_HOST=127.0.0.1
|
|
DB_PORT=3306
|
|
DB_DATABASE=laravel
|
|
DB_USERNAME=root
|
|
DB_PASSWORD=
|
|
```
|
|
|
|
- `php artisan admin:publish`
|
|
- `php artisan admin:install`
|
|
- 进入管理后台 `{host}/admin`, admin, admin
|
|
|
|
## 改动
|
|
|
|
- 文件: `dcat-admin/src/Form/Footer.php`, 将 `reset` 按钮默认设置为 `false`
|
|
|
|
```php
|
|
protected $buttons = ['reset' => false, 'submit' => true, 'back' => true];
|
|
|
|
public function disableBack(bool $disable = true)
|
|
{
|
|
$this->buttons['back'] = !$disable;
|
|
}
|
|
```
|
|
|
|
- 添加 Form 表单的 `back` 按钮, 文件: `dcat-admin/resources/views/form/footer.blade.php`
|
|
|
|
```php
|
|
@if(! empty($buttons['back']))
|
|
<div class="btn-group pull-left">
|
|
<a href="javascript:window.history.back()" class="btn btn-white"><i class="feather icon-arrow-left"></i> {{ trans('admin.back') }}</a>
|
|
</div>
|
|
@endif
|
|
```
|
|
|
|
- 文件: `dcat-admin/src/Show/Tools.php`, 添加 `back` 按钮, `list` 默认设置为 `false`, 修改按钮的渲染方式(去掉外层的 `btn-group` 标签, 添加类名 `mr-1`)
|
|
|
|
```php
|
|
protected $tools = ['back', 'list', 'edit', 'delete'];
|
|
|
|
protected $showBack = true;
|
|
|
|
public function disableBack(bool $disable = true)
|
|
{
|
|
$this->showBack = !$disable;
|
|
return $this;
|
|
}
|
|
|
|
protected function renderBack()
|
|
{
|
|
if (! $this->showBack) {
|
|
return;
|
|
}
|
|
|
|
$back = trans('admin.back');
|
|
|
|
return <<<HTML
|
|
<a href="javascript:window.history.back()" class="btn btn-sm btn-primary mr-1">
|
|
<i class="feather icon-arrow-left"></i><span class="d-none d-sm-inline"> {$back}</span>
|
|
</a>
|
|
HTML;
|
|
}
|
|
```
|
|
|
|
## 配置
|
|
|
|
- config/app.php
|
|
|
|
```php
|
|
return [
|
|
'timezone' => env('TIMEZONE', 'Asia/Chongqing'),
|
|
'locale' => 'zh_CN',
|
|
];
|
|
```
|
|
|
|
- config/auth.php
|
|
|
|
```php
|
|
return [
|
|
'api' => [
|
|
'driver' => 'sanctum',
|
|
'provider' => 'users',
|
|
],
|
|
'providers' => [
|
|
'users' => [
|
|
'driver' => 'eloquent',
|
|
'model' => Peidikeji\User\Models\User::class,
|
|
],
|
|
],
|
|
];
|
|
```
|
|
|
|
- app\Exceptions\Handler.php
|
|
|
|
```php
|
|
public function register()
|
|
{
|
|
$this->renderable(function (\Symfony\Component\HttpKernel\Exception\NotFoundHttpException $e, Request $request) {
|
|
if ($request->ajax()) {
|
|
return response()->json(['code' => 404, 'message' => $e->getMessage(), 'data' => null], 200);
|
|
}
|
|
});
|
|
$this->renderable(function (\Illuminate\Validation\ValidationException $e, Request $request) {
|
|
if ($request->ajax()) {
|
|
$errors = $e->validator->errors();
|
|
return response()->json(['code' => 422, 'message' => $errors->first(), 'data' => $errors], 200);
|
|
}
|
|
});
|
|
}
|
|
```
|
|
|
|
- app\Http\Controllers\Controller.php
|
|
|
|
```php
|
|
use Dcat\Admin\Traits\JsonResponse;
|
|
|
|
use Illuminate\Routing\Controller as BaseController;
|
|
class Controller extends BaseController
|
|
{
|
|
use JsonResponse;
|
|
}
|
|
```
|
|
|
|
- app\Providers\RouteServiceProvider.php
|
|
|
|
```php
|
|
protected function configureRateLimiting()
|
|
{
|
|
RateLimiter::for('sms', function (Request $request) {
|
|
return Limit::perMinute(1)->by($request->input('phone'));
|
|
});
|
|
}
|
|
```
|