diff --git a/app/Admin/Controllers/WarningSettingController.php b/app/Admin/Controllers/WarningSettingController.php index 1fed150..5355f93 100644 --- a/app/Admin/Controllers/WarningSettingController.php +++ b/app/Admin/Controllers/WarningSettingController.php @@ -2,6 +2,9 @@ namespace App\Admin\Controllers; +use App\Models\Device; +use App\Models\MonitorMode; +use App\Models\WarningNotice; use Illuminate\Http\Request; use Slowlyo\OwlAdmin\Controllers\AdminController; @@ -22,29 +25,42 @@ class WarningSettingController extends AdminController [ 'title' => '气象预警', 'value' => 'meteorological', - 'tab'=>$this->meteorologicalForm(), - 'unmountOnExit' => true//每次切换tab都要销毁 - ], - [ - 'title' => '水质预警', - 'value' => 'detail', - 'tab'=>'', + 'tab'=>$this->modeForm(MonitorMode::TYPE_METEOROLOGICAL), 'unmountOnExit' => true//每次切换tab都要销毁 ], + // [ + // 'title' => '水质预警', + // 'value' => 'detail', + // 'tab'=>'', + // 'unmountOnExit' => true//每次切换tab都要销毁 + // ], [ 'title' => '土壤预警', 'value' => 'detail', - 'tab'=>'', + 'tab'=>$this->modeForm(MonitorMode::TYPE_SOIL), 'unmountOnExit' => true//每次切换tab都要销毁 ], ]); } - public function meteorologicalForm(){ - return \amisMake()->Form()->title('')->body([ - \amisMake()->TextControl()->label('设备名称'), - \amisMake()->DateRangeControl()->label('时间范围'), - amis('submit')->label(__('admin.save'))->level('primary'), - ]); + public function modeForm($type) + { + $formBody = $fields = []; + foreach(MonitorMode::fieldMap($type) as $field => $fieldName){ + $fields[] = [ + 'label' => $fieldName, 'type'=>'number','step'=>'0.01','name'=>$field, + 'operators'=> ['between'] + ]; + } + + foreach(WarningNotice::lvMap() as $lv => $lvName){ + $formBody[] = amisMake()->ConditionBuilderControl(str($lv), $lvName)->fields( $fields); + } + + return \amisMake()->Form()->title('')->body(array_merge($formBody, [ + amisMake()->TextControl('type', '类别')->value($type)->hidden(true), + amis('submit')->label(__('admin.save'))->level('primary') + ]) + ); } } \ No newline at end of file diff --git a/app/Models/WarningNotice.php b/app/Models/WarningNotice.php index 856b5f8..67e98d1 100644 --- a/app/Models/WarningNotice.php +++ b/app/Models/WarningNotice.php @@ -14,6 +14,15 @@ class WarningNotice extends Model 'reported_at', ]; + public static function lvMap(){ + return [ + '1' => 'Ⅰ级预警', + '2' => 'Ⅱ级预警', + '3' => 'Ⅲ级预警', + '4' => 'Ⅳ级预警', + ]; + } + public function device(){ return $this->belongsTo(Device::class, 'device_id'); } diff --git a/app/Services/Admin/DeviceService.php b/app/Services/Admin/DeviceService.php index 566e7b6..cafaacb 100644 --- a/app/Services/Admin/DeviceService.php +++ b/app/Services/Admin/DeviceService.php @@ -137,8 +137,8 @@ class DeviceService extends BaseService //特殊字段,特殊统计图; switch($field){ - //点状图; - //柱状图 + //点状图;-todo + //柱状图;-todo default://折线图 $_chartCard = amisMake()->Card()->body( amisMake()->Chart()->config(