1
0
Fork 0

Compare commits

..

No commits in common. "96bb016325a16a94b6080df0a5f619ce44861fc1" and "418e227866a18ce124993b4013cca871d7f95fc0" have entirely different histories.

7 changed files with 9 additions and 21 deletions

View File

@ -95,9 +95,9 @@ class DeviceController extends AdminController
$regionId = request()->input('region_id', 0); $regionId = request()->input('region_id', 0);
if($regionId){ if($regionId){
$region = Region::find($regionId); $region = Region::find($regionId);
$query = $region->monitorModes()->where('type', MonitorMode::TYPE_MONITOR)->pluck('name','monitor_id'); $query = $region->monitorModes();
}else{ }else{
$query = MonitorMode::where('type', MonitorMode::TYPE_MONITOR)->pluck('name','id'); $query = MonitorMode::query();
} }
return CRUDTable::make() return CRUDTable::make()
->mode('cards') ->mode('cards')
@ -111,7 +111,7 @@ class DeviceController extends AdminController
->footerToolbar(['statistics', 'pagination']) ->footerToolbar(['statistics', 'pagination'])
->headerToolbar([]) ->headerToolbar([])
->filter($this->baseFilter()->actions([])->body([ ->filter($this->baseFilter()->actions([])->body([
amisMake()->SelectControl('monitor_mode', '点位名称')->size('md')->options($query->toArray())->selectFirst(true), amisMake()->SelectControl('monitor_mode', '点位名称')->size('md')->options($query->where('type', MonitorMode::TYPE_MONITOR)->pluck('name','id')->toArray()),
Button::make()->label(__('admin.reset'))->actionType('clear-and-submit'), Button::make()->label(__('admin.reset'))->actionType('clear-and-submit'),
Component::make()->setType('submit')->label(__('admin.search'))->level('primary'), Component::make()->setType('submit')->label(__('admin.search'))->level('primary'),
])) ]))

View File

@ -29,12 +29,12 @@ class DeviceFilter extends ModelFilter
return $this->where('type', $type); return $this->where('type', $type);
} }
public function monitorMode($monitorMode){ // public function monitorMode($monitorMode){
if($monitorMode){ // if($monitorMode){
$deviceIds = MonitorMode::find($monitorMode)?->devices()->get()->pluck('id')->toArray(); // $monitorMode = MonitorMode::find($monitorMode)?->;
} // }
return $this->whereIn('id', $deviceIds); // return $this->whereIn();
} // }
/** /**
* 类型 * 类型

View File

@ -14,7 +14,6 @@ return new class extends Migration
public function up() public function up()
{ {
Schema::create('devices', function (Blueprint $table) { Schema::create('devices', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->id(); $table->id();
$table->string('name')->comment('设备名称'); $table->string('name')->comment('设备名称');
$table->string('sn')->comment('设备唯一编码'); $table->string('sn')->comment('设备唯一编码');

View File

@ -14,7 +14,6 @@ return new class extends Migration
public function up() public function up()
{ {
Schema::create('regions', function (Blueprint $table) { Schema::create('regions', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->id(); $table->id();
$table->string('name'); $table->string('name');
$table->string('cover')->nullable()->comment('封面图'); $table->string('cover')->nullable()->comment('封面图');

View File

@ -14,7 +14,6 @@ return new class extends Migration
public function up() public function up()
{ {
Schema::create('monitor_modes', function (Blueprint $table) { Schema::create('monitor_modes', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->id(); $table->id();
$table->string('name')->comment('名称'); $table->string('name')->comment('名称');
$table->unsignedTinyInteger('type')->comment('类型: 1 视频监控, 2 土壤监测, 3 水质监测, 4 气象监测, 5 通风控制'); $table->unsignedTinyInteger('type')->comment('类型: 1 视频监控, 2 土壤监测, 3 水质监测, 4 气象监测, 5 通风控制');

View File

@ -14,15 +14,10 @@ return new class extends Migration
public function up() public function up()
{ {
Schema::create('monitor_devices', function (Blueprint $table) { Schema::create('monitor_devices', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->id(); $table->id();
$table->unsignedBigInteger('monitor_id'); $table->unsignedBigInteger('monitor_id');
$table->unsignedBigInteger('device_id'); $table->unsignedBigInteger('device_id');
$table->text('fields')->nullable()->comment('监测字段'); $table->text('fields')->nullable()->comment('监测字段');
$table->unsignedInteger('sort')->default(0)->comment('排序');
$table->foreign('monitor_id')->references('id')->on('monitor_modes')->onDelete('cascade');
$table->foreign('device_id')->references('id')->on('devices')->onDelete('cascade');
}); });
} }

View File

@ -14,15 +14,11 @@ return new class extends Migration
public function up() public function up()
{ {
Schema::create('region_monitors', function (Blueprint $table) { Schema::create('region_monitors', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->id(); $table->id();
$table->unsignedBigInteger('region_id'); $table->unsignedBigInteger('region_id');
$table->unsignedBigInteger('monitor_id'); $table->unsignedBigInteger('monitor_id');
$table->text('config')->nullable()->comment('配置信息'); $table->text('config')->nullable()->comment('配置信息');
$table->timestamps(); $table->timestamps();
$table->foreign('monitor_id')->references('id')->on('monitor_modes')->onDelete('cascade');
$table->foreign('region_id')->references('id')->on('regions')->onDelete('cascade');
}); });
} }