添加设备样式处理
parent
9489c3ea3a
commit
4b2d6f95ac
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use Slowlyo\OwlAdmin\Renderers\Page;
|
||||
use Slowlyo\OwlAdmin\Renderers\Form;
|
||||
use Slowlyo\OwlAdmin\Renderers\TableColumn;
|
||||
use Slowlyo\OwlAdmin\Renderers\TextControl;
|
||||
use Slowlyo\OwlAdmin\Controllers\AdminController;
|
||||
use App\Services\Admin\DeviceService;
|
||||
use App\Models\Device;
|
||||
|
||||
class DeviceController extends AdminController
|
||||
{
|
||||
protected string $serviceName = DeviceService::class;
|
||||
|
||||
protected string $pageTitle = '设备管理';
|
||||
|
||||
public function list(): Page
|
||||
{
|
||||
$crud = $this->baseCRUD()
|
||||
->filterTogglable(false)
|
||||
->headerToolbar([
|
||||
$this->createButton(true, 'lg'),
|
||||
...$this->baseHeaderToolBar(),
|
||||
])
|
||||
->columns([
|
||||
TableColumn::make()->name('id')->label('ID')->sortable(true),
|
||||
TableColumn::make()->name('name')->label('名称'),
|
||||
TableColumn::make()->name('sn')->label('编号'),
|
||||
TableColumn::make()->name('created_at')->label('创建时间')->type('datetime')->sortable(true),
|
||||
TableColumn::make()->name('updated_at')->label('更新时间')->type('datetime')->sortable(true),
|
||||
$this->rowActions(true),
|
||||
]);
|
||||
|
||||
return $this->baseList($crud);
|
||||
}
|
||||
|
||||
public function form(): Form
|
||||
{
|
||||
return $this->baseForm()->body([
|
||||
TextControl::make()->name('name')->label('名称')->required(true),
|
||||
TextControl::make()->name('sn')->label('编号'),
|
||||
\amisMake()->SelectControl()->name('powered_by')->label('厂家')->options(),
|
||||
TextControl::make()->name('model_sn')->label('型号'),
|
||||
\amisMake()->RadiosControl()->name('type')->label('类型')->options(Device::typeMap())->required(true),
|
||||
//监控设备-额外参数
|
||||
\amisMake()->TextControl()->name('extends.ip')->hiddenOn('data.type != '.Device::TYPE_MONITOR)->label('设备IP'),
|
||||
\amisMake()->TextControl()->name('extends.username')->hiddenOn('data.type != '.Device::TYPE_MONITOR)->label('设备用户名'),
|
||||
\amisMake()->TextControl()->name('extends.password')->hiddenOn('data.type != '.Device::TYPE_MONITOR)->label('设备密码'),
|
||||
\amisMake()->GroupControl()->body([
|
||||
\amisMake()->TextControl()->name('extends.live_port')->hiddenOn('data.type != '.Device::TYPE_MONITOR)->label('实时端口'),
|
||||
\amisMake()->TextControl()->name('extends.live_channel')->hiddenOn('data.type != '.Device::TYPE_MONITOR)->label('实时通道'),
|
||||
]),
|
||||
\amisMake()->GroupControl()->body([
|
||||
\amisMake()->TextControl()->name('extends.back_port')->hiddenOn('data.type != '.Device::TYPE_MONITOR)->label('回放端口'),
|
||||
\amisMake()->TextControl()->name('extends.back_channel')->hiddenOn('data.type != '.Device::TYPE_MONITOR)->label('回放通道'),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function detail(): Form
|
||||
{
|
||||
return $this->baseDetail()->body([
|
||||
TextControl::make()->static(true)->name('id')->label('ID'),
|
||||
TextControl::make()->static(true)->name('name')->label('名称'),
|
||||
TextControl::make()->static(true)->name('sn')->label('编号'),
|
||||
TextControl::make()->static(true)->name('created_at')->label('创建时间'),
|
||||
TextControl::make()->static(true)->name('updated_at')->label('更新时间')
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -28,8 +28,10 @@ Route::group([
|
|||
$router->resource('banners', \App\Admin\Controllers\BannerController::class);
|
||||
//友情链接
|
||||
$router->resource('friend-links', \App\Admin\Controllers\FriendLinkController::class);
|
||||
|
||||
//字典表
|
||||
$router->resource('keywords', \App\Admin\Controllers\KeywordController::class);
|
||||
//设备管理
|
||||
$router->resource('devices', \App\Admin\Controllers\DeviceController::class);
|
||||
|
||||
$router->resource('system/settings', \App\Admin\Controllers\SettingController::class);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use EloquentFilter\Filterable;
|
||||
|
||||
class Device extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use Filterable;
|
||||
|
||||
public const TYPE_MONITOR = 1; //监控设备
|
||||
public const TYPE_SOIL = 2; //土壤设备
|
||||
public const TYPE_WATER_QUALITY = 3; //水质设备
|
||||
public const TYPE_METEOROLOGICAL = 4; //气象设备
|
||||
|
||||
|
||||
protected $fillable = [
|
||||
'name', 'sn', 'powered_by', 'type', 'model_sn', 'state', 'extends',
|
||||
'is_enable', 'sort', 'is_recommend'
|
||||
];
|
||||
|
||||
protected function serializeDate(\DateTimeInterface $date){
|
||||
return $date->format('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
public static function typeMap()
|
||||
{
|
||||
return [
|
||||
self::TYPE_MONITOR => '监控设备',
|
||||
self::TYPE_SOIL => '土壤设备',
|
||||
self::TYPE_WATER_QUALITY => '水质设备',
|
||||
self::TYPE_METEOROLOGICAL => '气象设备',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services\Admin;
|
||||
|
||||
use App\Models\Device;
|
||||
use Slowlyo\OwlAdmin\Services\AdminService;
|
||||
|
||||
/**
|
||||
* @method Device getModel()
|
||||
* @method Device|\Illuminate\Database\Query\Builder query()
|
||||
*/
|
||||
class DeviceService extends AdminService
|
||||
{
|
||||
protected string $modelName = Device::class;
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
<?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('devices', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name')->comment('设备名称');
|
||||
$table->string('sn')->comment('设备唯一编码');
|
||||
$table->string('powered_by')->nullable()->comment('厂家');
|
||||
$table->string('model_sn')->nullable()->comment('型号');
|
||||
$table->unsignedTinyInteger('type')->comment('类型: 1 监控设备, 2 土壤设备, 3 水质设备, 4 气象设备');
|
||||
$table->unsignedTinyInteger('state')->default(2)->comment('状态: 0 禁用, 1 在线, 2 离线, 3 故障');
|
||||
$table->text('extends')->nullable()->comment('扩展信息');
|
||||
$table->unsignedTinyInteger('is_recommend')->default(0)->comment('推荐开关');
|
||||
$table->unsignedTinyInteger('is_enable')->default(1)->comment('显示开关');
|
||||
$table->unsignedInteger('sort')->default(0)->comment('排序');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('devices');
|
||||
}
|
||||
};
|
||||
Loading…
Reference in New Issue