Compare commits
3 Commits
7281a51b22
...
ce8ee04df9
| Author | SHA1 | Date |
|---|---|---|
|
|
ce8ee04df9 | |
|
|
d1a48b3f45 | |
|
|
f5e1a5698e |
|
|
@ -33,24 +33,19 @@ class DeviceController extends AdminController
|
|||
TextControl::make()->name('name')->label('名称')->size('md'),
|
||||
amisMake()->SelectControl()->name('factory')->label('厂家')->options(Keyword::getByParentKey('device-factory')->pluck('name', 'id')->toArray())->size('md'),
|
||||
amisMake()->SelectControl()->name('type')->label('类型')->options(Device::typeMap())->size('md'),
|
||||
Components::make()->keywordsTagControl('group_tags', '分组', 'device-group')->size('md'),
|
||||
Button::make()->label(__('admin.reset'))->actionType('clear-and-submit'),
|
||||
amis('submit')->label(__('admin.search'))->level('primary'),
|
||||
]))
|
||||
->quickSaveItemApi(admin_url('quick-edit/devices/$id'))
|
||||
->columns([
|
||||
TableColumn::make()->name('id')->label('ID')->sortable(true),
|
||||
TableColumn::make()->name('name')->label('名称'),
|
||||
TableColumn::make()->name('factory.name')->label('厂家'),
|
||||
TableColumn::make()->name('sn')->label('编号'),
|
||||
TableColumn::make()->name('type')->type('mapping')->map(Device::typeMap())->label('类型'),
|
||||
TableColumn::make()->name('is_enable')->type('switch')->label('显示')->quickEdit(Components::make()->enableControl('is_enable', '', 'inline')->saveImmediately(true)),
|
||||
TableColumn::make()->name('is_recommend')->type('switch')->label('推荐')->quickEdit(Components::make()->enableControl('is_recommend', '', 'inline')->saveImmediately(true)),
|
||||
TableColumn::make()->name('sort')->label(__('admin.order'))->align('center')->quickEdit(Components::make()->sortControl('sort', __('admin.order'))->saveImmediately(true)),
|
||||
TableColumn::make()->name('created_at')->label('创建时间')->type('datetime')->sortable(true),
|
||||
TableColumn::make()->name('created_at')->label('创建时间')->type('datetime')->sortable(true),
|
||||
TableColumn::make()->name('updated_at')->label('更新时间')->type('datetime')->sortable(true),
|
||||
$this->rowActions(true, 'lg'),
|
||||
]);
|
||||
])->debug(true);
|
||||
|
||||
return $this->baseList($crud);
|
||||
}
|
||||
|
|
@ -59,7 +54,7 @@ class DeviceController extends AdminController
|
|||
{
|
||||
return $this->baseForm()->body([
|
||||
TextControl::make()->name('name')->label('名称')->required(true),
|
||||
TextControl::make()->name('sn')->label('编号')->required(true),
|
||||
TextControl::make()->name('sn')->label('设备编号')->required(true),
|
||||
\amisMake()->SelectControl()->name('powered_by')->label('厂家')->options(Keyword::getByParentKey('device-factory')->pluck('name', 'id')->toArray())->required(true),
|
||||
TextControl::make()->name('model_sn')->label('型号'),
|
||||
\amisMake()->RadiosControl()->name('type')->label('类型')->options(Device::typeMap())->required(true),
|
||||
|
|
@ -68,11 +63,6 @@ class DeviceController extends AdminController
|
|||
TextControl::make()->name('extends.rtsp_url')->hiddenOn('data.type != '.Device::TYPE_MONITOR)->label(__('device.rtsp_url')),
|
||||
// rtsp://admin:lcdx12345@172.16.40.2:554/Streaming/tracks/5201
|
||||
TextControl::make()->name('extends.rtsp_history')->hiddenOn('data.type != '.Device::TYPE_MONITOR)->label(__('device.rtsp_history')),
|
||||
|
||||
Components::make()->keywordsTagControl('group_tags', '分组', 'device-group'),
|
||||
Components::make()->sortControl('sort', __('admin.order')),
|
||||
TextControl::make()->name('is_enable')->type('switch')->default(1)->label('显示'),
|
||||
TextControl::make()->name('is_recommend')->type('switch')->default(0)->label('推荐'),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,206 @@
|
|||
<?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\MonitorModeService;
|
||||
use App\Admin\Components;
|
||||
use App\Models\MonitorMode;
|
||||
use App\Models\Device;
|
||||
|
||||
/**
|
||||
* @property MonitorModeService $service
|
||||
*/
|
||||
class MonitorModeController extends AdminController
|
||||
{
|
||||
protected string $serviceName = MonitorModeService::class;
|
||||
|
||||
public function list(): Page
|
||||
{
|
||||
$crud = $this->baseCRUD()
|
||||
->filterTogglable(false)
|
||||
->headerToolbar([
|
||||
$this->createButton(true, 'lg'),
|
||||
...$this->baseHeaderToolBar(),
|
||||
])
|
||||
->filter($this->baseFilter()->actions([])->body([
|
||||
TextControl::make()->name('name')->label('名称')->size('md'),
|
||||
amisMake()->SelectControl()->name('type')->label('类型')->options(MonitorMode::typeMap())->size('md'),
|
||||
Components::make()->keywordsTagControl('group_tags', '分组', 'device-group')->size('md'),
|
||||
amis('button')->label(__('admin.reset'))->actionType('clear-and-submit'),
|
||||
amis('submit')->label(__('admin.search'))->level('primary'),
|
||||
]))
|
||||
->columns([
|
||||
TableColumn::make()->name('id')->label('ID')->sortable(true),
|
||||
TableColumn::make()->name('name')->label('名称'),
|
||||
TableColumn::make()->name('type')->type('mapping')->map(MonitorMode::typeMap())->label('类型'),
|
||||
TableColumn::make()->name('created_at')->label(__('admin.created_at'))->type('datetime')->sortable(true),
|
||||
amisMake()->Operation()->label(__('admin.actions'))->buttons([
|
||||
$this->setAboutDevice(),
|
||||
$this->rowDeleteButton()
|
||||
]),
|
||||
]);
|
||||
|
||||
return $this->baseList($crud);
|
||||
}
|
||||
|
||||
public function form(): Form
|
||||
{
|
||||
return $this->baseForm()->body([
|
||||
TextControl::make()->name('name')->label('名称'),
|
||||
\amisMake()->RadiosControl()->name('type')->label('类型')->options(MonitorMode::typeMap())->required(true),
|
||||
Components::make()->keywordsTagControl('group_tags', '分组', 'device-group'),
|
||||
Components::make()->sortControl('sort', __('admin.order')),
|
||||
TextControl::make()->name('is_enable')->type('switch')->default(1)->label('显示'),
|
||||
TextControl::make()->name('is_recommend')->type('switch')->default(0)->label('推荐'),
|
||||
]);
|
||||
}
|
||||
|
||||
private function setAboutDevice(){
|
||||
return amisMake()->DrawerAction()->label('设置监测设备')->icon('fa-solid fa-gear')->level('link')->drawer(
|
||||
amisMake()->Drawer()->title('设置监测设备')->resizable(true)->closeOnOutside(true)->closeOnEsc(true)->body([
|
||||
amisMake()
|
||||
->Form()
|
||||
->api(admin_url(''))//--todo
|
||||
->initApi($this->getEditGetDataPath())
|
||||
->mode('normal')
|
||||
->data(['id' => '${id}'])
|
||||
->body([
|
||||
amisMake()->RadiosControl()->name('type')->label('类型')->options(MonitorMode::typeMap())->disabled(true),
|
||||
amisMake()->PickerControl('monitor_devices', '监控设备')->visibleOn('data.type == '.MonitorMode::TYPE_MONITOR)
|
||||
->valueField('id')
|
||||
->labelField('name')
|
||||
->multiple(true)
|
||||
->size('lg')
|
||||
->source([
|
||||
'method' => 'get',
|
||||
'url' => admin_url('devices?_action=getData&type='.Device::TYPE_MONITOR),
|
||||
'data' => [
|
||||
'name'=>'${device_name}',
|
||||
]
|
||||
])
|
||||
->pickerSchema(
|
||||
[
|
||||
'mode' => 'table',
|
||||
'name' => 'monitor_list',
|
||||
'headerToolbar' => amisMake()->form()
|
||||
->wrapWithPanel(false)
|
||||
->className('text-right')
|
||||
->target('monitor_list')
|
||||
->mode('inline')
|
||||
->body([
|
||||
amisMake()->TextControl('device_name', '名称')->addOn(
|
||||
amis('submit')->label(__('admin.search'))->level('primary')
|
||||
)
|
||||
]),
|
||||
'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),
|
||||
]
|
||||
]
|
||||
),
|
||||
amisMake()->ArrayControl('soil_devices', '土壤监测')->visibleOn('data.type == '.MonitorMode::TYPE_SOIL)
|
||||
->items(
|
||||
amisMake()->ComboControl()->items([
|
||||
\amisMake()->CheckboxesControl('device_fields', '监测字段')->checkAll(true)->options(MonitorMode::fieldMap(MonitorMode::TYPE_SOIL)),
|
||||
\amisMake()->SelectControl('device_id', '监测设备'),
|
||||
]),
|
||||
),
|
||||
amisMake()->ArrayControl('water_devices', '水质监测')->visibleOn('data.type == '.MonitorMode::TYPE_WATER_QUALITY)
|
||||
->items(
|
||||
amisMake()->ComboControl()->items([
|
||||
\amisMake()->CheckboxesControl('device_fields', '监测字段')->checkAll(true)->options(MonitorMode::fieldMap(MonitorMode::TYPE_WATER_QUALITY)),
|
||||
\amisMake()->SelectControl('device_id', '监测设备'),
|
||||
]),
|
||||
),
|
||||
amisMake()->ArrayControl('meteorological_devices', '气象监测')->visibleOn('data.type == '.MonitorMode::TYPE_METEOROLOGICAL)
|
||||
->items(
|
||||
amisMake()->ComboControl()->items([
|
||||
\amisMake()->CheckboxesControl('device_fields', '监测字段')->checkAll(true)->options(MonitorMode::fieldMap(MonitorMode::TYPE_METEOROLOGICAL)),
|
||||
\amisMake()->SelectControl('device_id', '监测设备'),
|
||||
]),
|
||||
),
|
||||
amisMake()->PickerControl('air_devices', '通风设备')->visibleOn('data.type == '.MonitorMode::TYPE_AIR)
|
||||
->valueField('id')
|
||||
->labelField('name')
|
||||
->multiple(true)
|
||||
->size('lg')
|
||||
->source([
|
||||
'method' => 'get',
|
||||
'url' => admin_url('devices?_action=getData&type='.Device::TYPE_AIR),
|
||||
'data' => [
|
||||
'name'=>'${device_name}',
|
||||
]
|
||||
])
|
||||
->pickerSchema(
|
||||
[
|
||||
'mode' => 'table',
|
||||
'name' => 'monitor_list',
|
||||
'headerToolbar' => amisMake()->form()
|
||||
->wrapWithPanel(false)
|
||||
->className('text-right')
|
||||
->target('monitor_list')
|
||||
->mode('inline')
|
||||
->body([
|
||||
amisMake()->TextControl('device_name', '名称')->addOn(
|
||||
amis('submit')->label(__('admin.search'))->level('primary')
|
||||
)
|
||||
]),
|
||||
'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),
|
||||
]
|
||||
]
|
||||
),
|
||||
amisMake()->PickerControl('atomizing_devices', '喷雾设备')->visibleOn('data.type == '.MonitorMode::TYPE_ATOMIZING)
|
||||
->valueField('id')
|
||||
->labelField('name')
|
||||
->multiple(true)
|
||||
->size('lg')
|
||||
->source([
|
||||
'method' => 'get',
|
||||
'url' => admin_url('devices?_action=getData&type='.Device::TYPE_ATOMIZING),
|
||||
'data' => [
|
||||
'name'=>'${device_name}',
|
||||
]
|
||||
])
|
||||
->pickerSchema(
|
||||
[
|
||||
'mode' => 'table',
|
||||
'name' => 'monitor_list',
|
||||
'headerToolbar' => amisMake()->form()
|
||||
->wrapWithPanel(false)
|
||||
->className('text-right')
|
||||
->target('monitor_list')
|
||||
->mode('inline')
|
||||
->body([
|
||||
amisMake()->TextControl('device_name', '名称')->addOn(
|
||||
amis('submit')->label(__('admin.search'))->level('primary')
|
||||
)
|
||||
]),
|
||||
'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),
|
||||
]
|
||||
]
|
||||
),
|
||||
])
|
||||
])->footer([
|
||||
amisMake()->Button()->label('保存')->type('submit')->level('primary'),
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -5,16 +5,12 @@ 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\RegionService;
|
||||
use Slowlyo\OwlAdmin\Renderers\Button;
|
||||
use Slowlyo\OwlAdmin\Renderers\Image;
|
||||
use App\Admin\Components;
|
||||
use App\Models\Device;
|
||||
use App\Models\Region;
|
||||
use Slowlyo\OwlAdmin\Renderers\Html;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\MonitorMode;
|
||||
|
||||
class RegionController extends AdminController
|
||||
{
|
||||
|
|
@ -46,7 +42,6 @@ class RegionController extends AdminController
|
|||
TableColumn::make()->name('category.name')->label('分类')->className('text-primary'),
|
||||
TableColumn::make()->name('director')->label('负责人'),
|
||||
TableColumn::make()->name('area')->label('面积m²'),
|
||||
TableColumn::make()->name('devices_count')->label('设备数量'),
|
||||
TableColumn::make()->name('is_enable')->type('switch')->label('显示')->quickEdit(Components::make()->enableControl('is_enable', '', 'inline')->saveImmediately(true)),
|
||||
TableColumn::make()->name('created_at')->label('创建时间')->type('datetime')->sortable(true),
|
||||
// TableColumn::make()->name('updated_at')->label('更新时间')->type('datetime')->sortable(true),
|
||||
|
|
@ -55,7 +50,6 @@ class RegionController extends AdminController
|
|||
$this->rowEditButton(true, 'lg'),
|
||||
$this->rowDeleteButton()
|
||||
]),
|
||||
|
||||
]);
|
||||
|
||||
return $this->baseList($crud);
|
||||
|
|
@ -63,12 +57,12 @@ class RegionController extends AdminController
|
|||
|
||||
public function form(): Form
|
||||
{
|
||||
$deviceType = [];
|
||||
$devices = Device::get()->groupBy('type');
|
||||
foreach(Device::typeMap() as $key => $item) {;
|
||||
$deviceType[] = [
|
||||
$monitorModeType = [];
|
||||
$monitorModes = MonitorMode::get()->groupBy('type');
|
||||
foreach(MonitorMode::typeMap() as $key => $item) {;
|
||||
$monitorModeType[] = [
|
||||
'label' => $item,
|
||||
'children' => $devices->get($key)?->pluck('name', 'id')->toArray(),
|
||||
'children' => $monitorModes->get($key)?->pluck('name', 'id')->toArray(),
|
||||
];
|
||||
}
|
||||
return $this->baseForm()->body([
|
||||
|
|
@ -80,25 +74,10 @@ class RegionController extends AdminController
|
|||
Components::make()->decimalControl('area', '面积m²'),
|
||||
Components::make()->sortControl(),
|
||||
\amisMake()->SwitchControl()->name('is_enable')->value(1)->label('显示'),
|
||||
\amisMake()->TransferControl()->name('devices')->label('关联设备')
|
||||
\amisMake()->TransferControl()->name('monitorModes')->label('关联监测')
|
||||
->selectMode('chained')->searchable(true)
|
||||
->joinValues(false)->extractValue(true)
|
||||
->options($deviceType),
|
||||
]);
|
||||
}
|
||||
|
||||
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('category.name')->label('分类'),
|
||||
TextControl::make()->static(true)->name('director')->label('负责人'),
|
||||
TextControl::make()->name('cover')->label('封面')->static(true)->staticSchema(Image::make()),
|
||||
TextControl::make()->static(true)->name('area')->label('面积m²'),
|
||||
TextControl::make()->name('description')->label('内容介绍')->static(true)->staticSchema(Html::make()),
|
||||
TextControl::make()->static(true)->name('created_at')->label('创建时间'),
|
||||
TextControl::make()->static(true)->name('updated_at')->label('更新时间')
|
||||
->options($monitorModeType),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,11 +44,15 @@ Route::group([
|
|||
$router->resource('keywords', \App\Admin\Controllers\KeywordController::class);
|
||||
//设备管理
|
||||
$router->resource('devices', \App\Admin\Controllers\DeviceController::class);
|
||||
$router->post('quick-edit/devices/{device}',[\App\Admin\Controllers\DeviceController::class, 'update']);
|
||||
|
||||
//设备预警
|
||||
$router->get('warning-setting', '\App\Admin\Controllers\WarningSettingController@settingIndex');
|
||||
$router->get('warning-notice', '\App\Admin\Controllers\WarningNoticeController@index');
|
||||
|
||||
//监测点位
|
||||
$router->resource('monitor-modes', \App\Admin\Controllers\MonitorModeController::class);
|
||||
$router->post('quick-edit/monitor-modes/{monitor_mode}',[\App\Admin\Controllers\MonitorModeController::class, 'update']);
|
||||
|
||||
//区域分类
|
||||
$router->resource('region-categories', \App\Admin\Controllers\RegionCategoryController::class);
|
||||
$router->post('quick-edit/region-categories/{region_category}', '\App\Admin\Controllers\RegionCategoryController@update');
|
||||
|
|
|
|||
|
|
@ -28,9 +28,7 @@ class Device extends Model
|
|||
];
|
||||
|
||||
protected $fillable = [
|
||||
'name', 'sn', 'powered_by', 'type', 'model_sn', 'state', 'extends',
|
||||
'is_enable', 'sort', 'is_recommend',
|
||||
'group_tags'
|
||||
'name', 'sn', 'powered_by', 'type', 'model_sn', 'state', 'extends'
|
||||
];
|
||||
|
||||
public function scopePoweredBy(Builder $query, string $factory): void
|
||||
|
|
@ -48,7 +46,7 @@ class Device extends Model
|
|||
return [
|
||||
self::TYPE_MONITOR => '监控设备',
|
||||
self::TYPE_SOIL => '土壤设备',
|
||||
self::TYPE_WATER_QUALITY => '水质设备',
|
||||
// self::TYPE_WATER_QUALITY => '水质设备',
|
||||
self::TYPE_METEOROLOGICAL => '气象设备',
|
||||
self::TYPE_AIR => '通风设备',
|
||||
self::TYPE_ATOMIZING => '喷雾设备'
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ namespace App\Models;
|
|||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class RegionDevice extends Model
|
||||
class MonitorDevice extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use EloquentFilter\Filterable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MonitorMode extends Model
|
||||
{
|
||||
use Filterable;
|
||||
|
||||
protected $fillable = [
|
||||
'name', 'type',
|
||||
'is_enable', 'sort', 'is_recommend',
|
||||
'group_tags'
|
||||
];
|
||||
|
||||
public const TYPE_MONITOR = 1; //视频监控
|
||||
public const TYPE_SOIL = 2; //土壤监测
|
||||
public const TYPE_WATER_QUALITY = 3; //水质监测
|
||||
public const TYPE_METEOROLOGICAL = 4; //气象监测
|
||||
public const TYPE_AIR = 5; //通风控制
|
||||
public const TYPE_ATOMIZING = 6; //喷雾控制
|
||||
|
||||
public static function typeMap()
|
||||
{
|
||||
return [
|
||||
self::TYPE_MONITOR => '视频监控',
|
||||
self::TYPE_SOIL => '土壤监测',
|
||||
// self::TYPE_WATER_QUALITY => '水质监测',
|
||||
self::TYPE_METEOROLOGICAL => '气象监测',
|
||||
self::TYPE_AIR => '通风控制',
|
||||
self::TYPE_ATOMIZING => '喷雾控制'
|
||||
];
|
||||
}
|
||||
|
||||
public static function fieldMap($type)
|
||||
{
|
||||
$arr = [];
|
||||
switch ($type) {
|
||||
case self::TYPE_SOIL:
|
||||
$arr = [
|
||||
'conductivity'=>'导电率',
|
||||
'humidity'=>'湿度',
|
||||
'temperature'=>'温度',
|
||||
'n'=>'氮',
|
||||
'p'=>'磷',
|
||||
'k'=>'钾'
|
||||
];
|
||||
break;
|
||||
case self::TYPE_WATER_QUALITY:
|
||||
$arr = [
|
||||
];
|
||||
break;
|
||||
case self::TYPE_METEOROLOGICAL:
|
||||
$arr = [
|
||||
'box_temperature' => '温度',
|
||||
'box_humidity' => '湿度',
|
||||
'box_illumination' => '光照强度',
|
||||
'moment_rainfall' => '降雨量',
|
||||
'wind_speed' => '风速',
|
||||
'wind_direction' => '风向',
|
||||
'box_noise' => '噪音',
|
||||
'pm10' => 'PM10',
|
||||
'pm25' => 'PM25',
|
||||
'box_co2' => 'CO2'
|
||||
];
|
||||
break;
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
|
||||
protected function serializeDate(\DateTimeInterface $date){
|
||||
return $date->format('Y-m-d H:i:s');
|
||||
}
|
||||
}
|
||||
|
|
@ -12,7 +12,6 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|||
*/
|
||||
class Region extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use Filterable;
|
||||
|
||||
protected $fillable = [
|
||||
|
|
@ -44,10 +43,8 @@ class Region extends Model
|
|||
return $this->belongsTo(RegionCategory::class, 'category_id');
|
||||
}
|
||||
|
||||
// 关联设备
|
||||
public function devices()
|
||||
{
|
||||
return $this->belongsToMany(Device::class, RegionDevice::class, 'region_id', 'device_id')->withTimestamps();
|
||||
public function monitorModes(){
|
||||
return $this->belongsToMany(MonitorMode::class, RegionMonitor::class, 'region_id', 'monitor_id')->withTimestamps();
|
||||
}
|
||||
|
||||
// 种植记录
|
||||
|
|
@ -78,11 +75,11 @@ class Region extends Model
|
|||
'sort' => 0,
|
||||
],
|
||||
];
|
||||
if($region?->devices){
|
||||
foreach($region->devices as $device){
|
||||
switch($device->type)
|
||||
if($region?->monitorModes){
|
||||
foreach($region->monitorModes as $monitorMode){
|
||||
switch($monitorMode->type)
|
||||
{
|
||||
case Device::TYPE_MONITOR:
|
||||
case MonitorMode::TYPE_MONITOR:
|
||||
$tabs[] = [//有监控设备才有
|
||||
'title' => '监控视频',
|
||||
'value' => 'monitor',
|
||||
|
|
@ -91,34 +88,34 @@ class Region extends Model
|
|||
'sort' => 1,
|
||||
];
|
||||
break;
|
||||
case Device::TYPE_SOIL:
|
||||
case MonitorMode::TYPE_SOIL:
|
||||
$tabs[] = [//有土壤设备才有
|
||||
'title' => '土壤数据',
|
||||
'value' => 'turang',
|
||||
'value' => 'soil',
|
||||
'tab'=>\amisMake()->Service()->schemaApi(admin_url('custom-region-soil?id='.$region->id)),
|
||||
'unmountOnExit' => true,//每次切换tab都要销毁
|
||||
'sort' => 2,
|
||||
];
|
||||
break;
|
||||
case Device::TYPE_WATER_QUALITY:
|
||||
case MonitorMode::TYPE_WATER_QUALITY:
|
||||
$tabs[] = [//有水质设备才有
|
||||
'title' => '水质数据',
|
||||
'value' => 'shuizi',
|
||||
'value' => 'quality',
|
||||
'tab'=>\amisMake()->Service()->schemaApi(admin_url('custom-region-water?id='.$region->id)),
|
||||
'unmountOnExit' => true,//每次切换tab都要销毁
|
||||
'sort' => 3,
|
||||
];
|
||||
break;
|
||||
case Device::TYPE_METEOROLOGICAL:
|
||||
case MonitorMode::TYPE_METEOROLOGICAL:
|
||||
$tabs[] = [//有气象设备才有
|
||||
'title' => '气象数据',
|
||||
'value' => 'qixiang',
|
||||
'value' => 'meteorological',
|
||||
'tab'=>\amisMake()->Service()->schemaApi(admin_url('custom-region-meteorological?id='.$region->id)),
|
||||
'unmountOnExit' => true,//每次切换tab都要销毁
|
||||
'sort' => 4,
|
||||
];
|
||||
break;
|
||||
case Device::TYPE_AIR:
|
||||
case MonitorMode::TYPE_AIR:
|
||||
$tabs[] = [//有通风设备才有
|
||||
'title' => '通风设备',
|
||||
'value' => 'air',
|
||||
|
|
@ -127,11 +124,11 @@ class Region extends Model
|
|||
'sort' => 5,
|
||||
];
|
||||
break;
|
||||
case Device::TYPE_ATOMIZING:
|
||||
case MonitorMode::TYPE_ATOMIZING:
|
||||
$tabs[] = [//有喷雾设备才有
|
||||
'title' => '喷雾设备',
|
||||
'value' => 'wasserstrahl',
|
||||
'tab'=>\amisMake()->Service()->schemaApi(admin_url('custom-region-wasserstrahl?id='.$region->id)),
|
||||
'value' => 'atomizing',
|
||||
'tab'=>\amisMake()->Service()->schemaApi(admin_url('custom-region-atomizing?id='.$region->id)),
|
||||
'unmountOnExit' => true,//每次切换tab都要销毁
|
||||
'sort' => 6,
|
||||
];
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class RegionMonitor extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services\Admin;
|
||||
|
||||
use App\Models\MonitorMode;
|
||||
|
||||
/**
|
||||
* @method MonitorMode getModel()
|
||||
* @method MonitorMode|\Illuminate\Database\Query\Builder query()
|
||||
*/
|
||||
class MonitorModeService extends BaseService
|
||||
{
|
||||
protected string $modelName = MonitorMode::class;
|
||||
}
|
||||
|
|
@ -25,7 +25,7 @@ class RegionService extends BaseService
|
|||
public function getEditData($id): Model|\Illuminate\Database\Eloquent\Collection|Builder|array|null
|
||||
{
|
||||
$region = parent::getEditData($id);
|
||||
$region->devices = $region->devices()->selectRaw('devices.id as value, devices.name as label')->get()->toArray();
|
||||
$region->monitorModes = $region->monitorModes()->selectRaw('monitor_modes.id as value, monitor_modes.name as label')->get()->toArray();
|
||||
return $region;
|
||||
}
|
||||
|
||||
|
|
@ -45,8 +45,8 @@ class RegionService extends BaseService
|
|||
DB::beginTransaction();
|
||||
if($model->save()){
|
||||
//处理关联设备
|
||||
$devices = Arr::get($data, 'devices');
|
||||
$model->devices()->sync($devices ?? []);
|
||||
$monitorModes = Arr::get($data, 'monitorModes');
|
||||
$model->monitorModes()->sync($monitorModes ?? []);
|
||||
}
|
||||
DB::commit();
|
||||
return true;
|
||||
|
|
@ -73,8 +73,8 @@ class RegionService extends BaseService
|
|||
DB::beginTransaction();
|
||||
if($model->save()){
|
||||
//处理关联设备
|
||||
$devices = Arr::get($data, 'devices');
|
||||
$model->devices()->sync($devices ?? []);
|
||||
$monitorModes = Arr::get($data, 'monitorModes');
|
||||
$model->monitorModes()->sync($monitorModes ?? []);
|
||||
}
|
||||
DB::commit();
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -17,15 +17,11 @@ return new class extends Migration
|
|||
$table->id();
|
||||
$table->string('name')->comment('设备名称');
|
||||
$table->string('sn')->comment('设备唯一编码');
|
||||
$table->string('powered_by')->nullable()->comment('厂家');
|
||||
$table->unsignedBigInteger('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->string('group_tags')->nullable()->comment('分组标签');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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('monitor_modes', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name')->comment('名称');
|
||||
$table->unsignedTinyInteger('type')->comment('类型: 1 视频监控, 2 土壤监测, 3 水质监测, 4 气象监测, 5 通风控制');
|
||||
$table->unsignedTinyInteger('is_recommend')->default(0)->comment('推荐开关');
|
||||
$table->unsignedTinyInteger('is_enable')->default(1)->comment('显示开关');
|
||||
$table->unsignedInteger('sort')->default(0)->comment('排序');
|
||||
$table->string('group_tags')->nullable()->comment('分组标签');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('monitor_modes');
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
<?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('monitor_devices', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('monitor_id');
|
||||
$table->unsignedBigInteger('device_id');
|
||||
$table->text('fields')->nullable()->comment('监测字段');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('monitor_devices');
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
<?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('region_monitors', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('region_id');
|
||||
$table->unsignedBigInteger('monitor_id');
|
||||
$table->text('config')->nullable()->comment('配置信息');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('region_monitors');
|
||||
}
|
||||
};
|
||||
|
|
@ -48,22 +48,26 @@ class AdminMenuSeeder extends Seeder
|
|||
['title' => '稻田列表', 'icon' => 'icon-park:more-app', 'url' => '/custom-region/daotian', 'order'=>2],
|
||||
]
|
||||
],
|
||||
|
||||
['title' => '设备管理', 'icon' => 'icon-park:devices', 'url' => '/devices', 'order'=>6],
|
||||
['title' => '设备数据', 'icon' => 'icon-park:data-switching', 'url' => '', 'order'=>7,
|
||||
['title' => '监测管理', 'icon' => 'icon-park:monitor-one', 'url' => '', 'order'=>6,
|
||||
'children' => [
|
||||
['title' => '监测点位', 'icon' => 'icon-park:monitor-camera', 'url' => '/monitor-modes', 'order'=>1],
|
||||
['title' => '设备管理', 'icon' => 'icon-park:devices', 'url' => '/devices', 'order'=>2],
|
||||
]
|
||||
],
|
||||
['title' => '监测数据', 'icon' => 'icon-park:data-switching', 'url' => '', 'order'=>7,
|
||||
'children' => [
|
||||
['title' => '实时监控', 'icon'=>'icon-park:videocamera', 'url'=> '/custom-region-monitor', 'order'=>1],
|
||||
['title' => '历史视频', 'icon'=>'icon-park:film', 'url'=> '/custom-region-monitor-video', 'order'=>2],
|
||||
['title' => '气象数据', 'icon'=>'icon-park:brightness', 'url'=> '/custom-region-meteorological', 'order'=>3],
|
||||
['title' => '土壤数据', 'icon'=>'icon-park:floor-tile', 'url'=> '/custom-region-water', 'order'=>4],
|
||||
['title' => '气象监测', 'icon'=>'icon-park:brightness', 'url'=> '/custom-region-meteorological', 'order'=>3],
|
||||
['title' => '土壤监测', 'icon'=>'icon-park:floor-tile', 'url'=> '/custom-region-water', 'order'=>4],
|
||||
// ['title' => '水质数据', 'icon'=>'icon-park:diving-bottle', 'url'=> '/custom-region-soil', 'order'=>5],
|
||||
]
|
||||
],
|
||||
['title' => '设备预警', 'icon' => 'icon-park:alarm', 'url' => '', 'order'=>8,
|
||||
['title' => '监测预警', 'icon' => 'icon-park:alarm', 'url' => '', 'order'=>8,
|
||||
'children' => [
|
||||
['title' => '预警设置', 'icon'=>'icon-park:six-circular-connection', 'url'=> '/warning-setting', 'order'=>1],
|
||||
['title' => '报警记录', 'icon'=>'icon-park:massage-chair-one', 'url'=> '/warning-notice', 'order'=>2],
|
||||
]
|
||||
]
|
||||
],
|
||||
// ['title' => '友情链接', 'icon' => 'icon-park:copy-link', 'url' => '/friend-links', 'order'=>9],
|
||||
['title' => '系统管理', 'icon' => 'icon-park:setting', 'url' => '/system', 'order'=>10,
|
||||
|
|
|
|||
Loading…
Reference in New Issue