diff --git a/app/Admin/Controllers/WarningNoticeController.php b/app/Admin/Controllers/WarningNoticeController.php index a95dc29..2419c9d 100644 --- a/app/Admin/Controllers/WarningNoticeController.php +++ b/app/Admin/Controllers/WarningNoticeController.php @@ -2,6 +2,7 @@ namespace App\Admin\Controllers; +use App\Models\MonitorMode; use Slowlyo\OwlAdmin\Controllers\AdminController; use Slowlyo\OwlAdmin\Renderers\Form; use Slowlyo\OwlAdmin\Renderers\Page; @@ -13,7 +14,7 @@ class WarningNoticeController extends AdminController { protected string $serviceName = WarningNoticeService::class; - protected string $pageTitle = '报警记录';//待完善-todo + protected string $pageTitle = '报警记录'; public function list(): Page { @@ -24,6 +25,10 @@ class WarningNoticeController extends AdminController ]) ->columns([ TableColumn::make()->name('id')->label('ID')->sortable(true), + TableColumn::make()->name('device.modes')->type('each')->items([ + 'type' => 'tpl', + 'tpl' => "<%= data.name %>", + ])->valueField('id')->label('监测点位'), TableColumn::make()->name('device.name')->label('设备名称'), TableColumn::make()->name('lv')->type('mapping')->map(WarningNotice::lvMap())->label('报警等级')->className('text-primary'), TableColumn::make()->name('content')->label('报警内容'), diff --git a/app/Models/Device.php b/app/Models/Device.php index 174e3a4..c9acc7d 100644 --- a/app/Models/Device.php +++ b/app/Models/Device.php @@ -55,6 +55,10 @@ class Device extends Model ]; } + public function modes(){ + return $this->belongsToMany(MonitorMode::class, MonitorDevice::class, 'device_id', 'monitor_id')->withPivot('fields'); + } + public function logs(): HasMany { return $this->hasMany(DeviceLog::class); diff --git a/app/Services/Admin/WarningNoticeService.php b/app/Services/Admin/WarningNoticeService.php index 47466fd..15b1e1e 100644 --- a/app/Services/Admin/WarningNoticeService.php +++ b/app/Services/Admin/WarningNoticeService.php @@ -12,5 +12,5 @@ class WarningNoticeService extends BaseService { protected string $modelName = WarningNotice::class; - protected array $withRelationships = ['device']; + protected array $withRelationships = ['device.modes']; }