From 4b2d6f95ac5bd6d9281dcd35ce976672277d585d Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Mon, 20 Mar 2023 17:38:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AE=BE=E5=A4=87=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Controllers/DeviceController.php | 72 +++++++++++++++++++ app/Admin/routes.php | 4 +- app/Models/Device.php | 38 ++++++++++ app/Services/Admin/DeviceService.php | 15 ++++ ...2023_03_20_162006_create_devices_table.php | 41 +++++++++++ 5 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 app/Admin/Controllers/DeviceController.php create mode 100644 app/Models/Device.php create mode 100644 app/Services/Admin/DeviceService.php create mode 100644 database/migrations/2023_03_20_162006_create_devices_table.php diff --git a/app/Admin/Controllers/DeviceController.php b/app/Admin/Controllers/DeviceController.php new file mode 100644 index 0000000..32d7221 --- /dev/null +++ b/app/Admin/Controllers/DeviceController.php @@ -0,0 +1,72 @@ +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('更新时间') + ]); + } +} diff --git a/app/Admin/routes.php b/app/Admin/routes.php index a5e7597..f0de428 100644 --- a/app/Admin/routes.php +++ b/app/Admin/routes.php @@ -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); }); diff --git a/app/Models/Device.php b/app/Models/Device.php new file mode 100644 index 0000000..aa5f9fe --- /dev/null +++ b/app/Models/Device.php @@ -0,0 +1,38 @@ +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 => '气象设备', + ]; + } +} diff --git a/app/Services/Admin/DeviceService.php b/app/Services/Admin/DeviceService.php new file mode 100644 index 0000000..35d1753 --- /dev/null +++ b/app/Services/Admin/DeviceService.php @@ -0,0 +1,15 @@ +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'); + } +};