1
0
Fork 0

补充实验田基础模块样式

develop
vine_liutk 2023-03-21 17:46:30 +08:00
parent 4b2d6f95ac
commit 001e78a111
20 changed files with 554 additions and 6 deletions

View File

@ -25,10 +25,24 @@ class Components extends BaseRenderer {
public function sortControl($name ='sort', $label = '排序'){
return amisMake()->NumberControl()
->name($name)->label($label)
->displayMode('enhance')
->value(0)
->min(0);
}
/**
* 2位小数输入框
*/
public function decimalControl($name ='decimal', $label = '数值'){
return amisMake()->NumberControl()
->name($name)->label($label)
->kilobitSeparator(true)
->percision(2)
->step(0.01)
->value(0.00)
->min(0);
}
/**
* 富文本编辑器
*/

View File

@ -27,6 +27,10 @@ class ArticleController extends AdminController
->columns([
TableColumn::make()->name('id')->label('ID')->sortable(true),
TableColumn::make()->name('title')->label('标题'),
TableColumn::make()->name('category_id')->label('分类')->className('text-primary'),
TableColumn::make()->name('sub_title')->label('副标题'),
TableColumn::make()->name('is_enable')->type('switch')->label('显示'),
TableColumn::make()->name('published_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'),

View File

@ -0,0 +1,91 @@
<?php
namespace App\Admin\Controllers;
use Illuminate\Http\Request;
use Slowlyo\OwlAdmin\Renderers\Page;
use Slowlyo\OwlAdmin\Controllers\AdminController;
use App\Admin\Components;
class CustomRegionController extends AdminController
{
protected string $pageTitle = '标题';
protected string $queryPath = 'custom-region';
public function index()
{
$page = $this->basePage()->body([
\amisMake()->GridNav()->options(
$this->regionList()
)
]);
return $this->response()->success($page);
}
private function regionList(){
$regionList = [
[
'id' => 1,
'name' => '实验田1',
'cover' => 'https://internal-amis-res.cdn.bcebos.com/images/icon-1.png'
]
];
return array_map(function($region){
return [
"icon"=> $region['cover'],
"text"=> $region['name'],
'clickAction' => [
'actionType'=> 'dialog',
'dialog' => \amisMake()->Dialog()->title($region['name'])
->size('full')->body([
\amisMake()->Tabs()->tabsMode('simple')->name('detailTab')->tabs([
[
'title' => '基地详情',
'value' => 'detail',
'tab'=>\amisMake()->Service()->schemaApi(admin_url('custom-region-detail?type=detail'))
],
[//有监控设备才有
'title' => '监控视频',
'value' => 'video',
'tab'=>\amisMake()->Service()->schemaApi(admin_url('custom-region-detail?type=video'))
],
[//有气象设备才有
'title' => '气象数据',
'value' => 'qixiang',
'tab'=>\amisMake()->Service()->schemaApi(admin_url('custom-region-detail?type=qixiang'))
],
[//有水质设备才有
'title' => '水质数据',
'value' => 'shuizi',
'tab'=>\amisMake()->Service()->schemaApi(admin_url('custom-region-detail?type=shuizi'))
],
[//有土壤设备才有
'title' => '土壤数据',
'value' => 'turang',
'tab'=>\amisMake()->Service()->schemaApi(admin_url('custom-region-detail?type=turang'))
],
[//有通风设备才有
'title' => '通风设备',
'value' => 'tongfeng',
'tab'=>\amisMake()->Service()->schemaApi(admin_url('custom-region-detail?type=tongfeng'))
],
[//有喷灌设备才有
'title' => '喷灌设备',
'value' => 'penguan',
'tab'=>\amisMake()->Service()->schemaApi(admin_url('custom-region-detail?type=penguan'))
],
]),
])
]
];
}, $regionList);
}
public function regionDetail(Request $request)
{
return \amisMake()->Wrapper()->body($request->type ?? '找不到type');
}
}

View File

@ -17,8 +17,6 @@ use Slowlyo\OwlAdmin\Controllers\AdminController;
class HomeController extends AdminController
{
protected string $queryPath = 'dashboard';
protected string $pageTitle = '首页';
public function index(): JsonResponse|JsonResource

View File

@ -0,0 +1,66 @@
<?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\RegionCategoryService;
use App\Admin\Components;
class RegionCategoryController extends AdminController
{
protected string $serviceName = RegionCategoryService::class;
protected string $pageTitle = '区域分类';
public function list(): Page
{
$crud = $this->baseCRUD()
//关闭查询
->filterTogglable(false)
//去掉分页-start
->loadDataOnce(true)
->footerToolbar([])
//去掉分页-end
->headerToolbar([
$this->createButton(true),
...$this->baseHeaderToolBar(),
])
->columns([
TableColumn::make()->name('id')->label('ID')->sortable(true),
TableColumn::make()->name('name')->label('名称'),
// TableColumn::make()->name('parent.name')->label('父级ID'),
TableColumn::make()->name('sort')->label('排序'),
TableColumn::make()->name('is_enable')->type('switch')->label('显示'),
TableColumn::make()->name('created_at')->label('创建时间')->type('datetime')->sortable(true),
$this->rowActions(true),
]);
return $this->baseList($crud);
}
public function form(): Form
{
return $this->baseForm()->body([
amisMake()->TextControl()->name('name')->label('名称')->required(true),
amisMake()->ImageControl()->name('icon')->label('封面图')->autoUpload(true),
amisMake()->TextControl()->name('description')->label('描述'),
Components::make()->parentControl(),
Components::make()->sortControl(),
amisMake()->SwitchControl()->name('is_enable')->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('created_at')->label('创建时间'),
TextControl::make()->static(true)->name('updated_at')->label('更新时间')
]);
}
}

View File

@ -0,0 +1,66 @@
<?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\RegionService;
use App\Admin\Components;
class RegionController extends AdminController
{
protected string $serviceName = RegionService::class;
protected string $pageTitle = '实验田';
public function list(): Page
{
$crud = $this->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('category_id')->label('分类')->className('text-primary'),
TableColumn::make()->name('area')->label('面积'),
TableColumn::make()->name('device_count')->label('设备数量'),
TableColumn::make()->name('is_enable')->type('switch')->label('显示'),
TableColumn::make()->name('created_at')->label('创建时间')->type('datetime')->sortable(true),
// TableColumn::make()->name('updated_at')->label('更新时间')->type('datetime')->sortable(true),
$this->rowActions(true, 'lg'),
]);
return $this->baseList($crud);
}
public function form(): Form
{
return $this->baseForm()->body([
TextControl::make()->name('name')->label('名称')->required(true),
Components::make()->parentControl('', 'category_id', '分类'),
Components::make()->fuEditorControl('description', '介绍'),
Components::make()->decimalControl('area', '面积m²'),
Components::make()->sortControl(),
\amisMake()->SwitchControl()->name('is_enable')->label('显示'),
\amisMake()->TransferControl()->name('devices')->label('关联设备')
->selectMode('chained')->searchable(true)->options(),
]);
}
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('created_at')->label('创建时间'),
TextControl::make()->static(true)->name('updated_at')->label('更新时间')
]);
}
}

View File

@ -14,7 +14,7 @@ Route::group([
$router->get('keywords/tree-list', '\App\Admin\Controllers\KeywordController@getTreeList')->name('api.keywords.tree-list');
});
$router->resource('dashboard', \App\Admin\Controllers\HomeController::class);
$router->get('dashboard', '\App\Admin\Controllers\HomeController@index');
//公告管理
$router->resource('admin-notices', \App\Admin\Controllers\AdminNoticeController::class);
@ -32,6 +32,15 @@ Route::group([
$router->resource('keywords', \App\Admin\Controllers\KeywordController::class);
//设备管理
$router->resource('devices', \App\Admin\Controllers\DeviceController::class);
//区域分类
$router->resource('region-categories', \App\Admin\Controllers\RegionCategoryController::class);
//区域列表
$router->resource('regions', \App\Admin\Controllers\RegionController::class);
//特殊菜单
$router->get('custom-region', '\App\Admin\Controllers\CustomRegionController@index');
$router->post('custom-region-detail', '\App\Admin\Controllers\CustomRegionController@regionDetail');
$router->resource('system/settings', \App\Admin\Controllers\SettingController::class);
});

View File

@ -0,0 +1,11 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class PlantHarvestLog extends Model
{
use HasFactory;
}

View File

@ -0,0 +1,11 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Region extends Model
{
use HasFactory;
}

View File

@ -0,0 +1,41 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use EloquentFilter\Filterable;
class RegionCategory extends Model
{
use HasFactory;
use Filterable;
protected $fillable = ['name', 'icon', 'description', 'parent_id', 'level', 'sort', 'path', 'is_enable'];
protected static function boot()
{
parent::boot();
// 监听 Category 的创建事件,用于初始化 path 和 level 字段值
static::creating(function ($category) {
// 如果创建的是一个根类目
if (! $category->parent_id) {
// 将层级设为 1
$category->level = 1;
// 将 path 设为 -
$category->path = '-';
} else {
// 将层级设为父类目的层级 + 1
$category->level = $category->parent->level + 1;
// 将 path 值设为父类目的 path 追加父类目 ID 以及最后跟上一个 - 分隔符
$category->path = $category->parent->path.$category->parent_id.'-';
}
});
}
public function parent()
{
return $this->belongsTo(self::class, 'parent_id');
}
}

View File

@ -0,0 +1,11 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class RegionDevice extends Model
{
use HasFactory;
}

View File

@ -0,0 +1,11 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class RegionPlantLog extends Model
{
use HasFactory;
}

View File

@ -0,0 +1,15 @@
<?php
namespace App\Services\Admin;
use App\Models\RegionCategory;
use Slowlyo\OwlAdmin\Services\AdminService;
/**
* @method RegionCategory getModel()
* @method RegionCategory|\Illuminate\Database\Query\Builder query()
*/
class RegionCategoryService extends AdminService
{
protected string $modelName = RegionCategory::class;
}

View File

@ -0,0 +1,15 @@
<?php
namespace App\Services\Admin;
use App\Models\Region;
use Slowlyo\OwlAdmin\Services\AdminService;
/**
* @method Region getModel()
* @method Region|\Illuminate\Database\Query\Builder query()
*/
class RegionService extends AdminService
{
protected string $modelName = Region::class;
}

View File

@ -0,0 +1,39 @@
<?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_categories', function (Blueprint $table) {
$table->id();
$table->string('name')->comment('分类名称');
$table->string('icon')->nullable()->comment('封面图');
$table->string('description')->nullable()->comment('描述');
$table->unsignedBigInteger('parent_id')->default(0)->comment('父级ID');
$table->unsignedInteger('level')->default(1)->comment('层级');
$table->unsignedInteger('sort')->default(0)->comment('排序');
$table->unsignedTinyInteger('is_enable')->default(1)->comment('状态');
$table->string('path')->default('-')->comment('所有的父级ID');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('region_categories');
}
};

View File

@ -0,0 +1,40 @@
<?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('regions', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('cover')->nullable()->comment('封面图');
$table->decimal('area')->default(0.00)->comment('面积');
$table->text('description')->nullable()->comment('描述');
$table->unsignedBigInteger('category_id')->nullable()->comment('分类');
$table->unsignedTinyInteger('is_recommend')->default(0)->comment('推荐开关');
$table->unsignedTinyInteger('is_enable')->default(1)->comment('显示开关');
$table->unsignedInteger('sort')->default(0)->comment('排序');
$table->unsignedTinyInteger('status')->default(0)->comment('0未使用1种植中2维护中3已废弃');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('regions');
}
};

View File

@ -0,0 +1,35 @@
<?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_devices', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('region_id');
$table->unsignedBigInteger('device_id');
$table->unsignedTinyInteger('device_type')->comment('类型: 1 监控设备, 2 土壤设备, 3 水质设备, 4 气象设备');
$table->text('config')->nullable()->comment('配置信息');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('region_devices');
}
};

View File

@ -0,0 +1,36 @@
<?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_plant_logs', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('region_id');
$table->string('plant_name')->comment('种植名称');
$table->text('description')->nullable()->comment('描述');
$table->timestamp('start_at')->nullable()->comment('种植开始时间');
$table->unsignedTinyInteger('status')->default(0)->comment('0未开始1种植中2已结束');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('region_plant_logs');
}
};

View File

@ -0,0 +1,35 @@
<?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('plant_harvest_logs', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('plant_id');
$table->decimal('area')->default(0.00)->comment('面积/平米');
$table->decimal('output')->default(0.00)->comment('产量/千克');
$table->timestamp('harvest_at')->nullable()->comment('收获时间');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('plant_harvest_logs');
}
};

View File

@ -32,20 +32,20 @@ class AdminMenuSeeder extends Seeder
['title' => '区域管理', 'icon' => 'icon-park:category-management', 'url' => '',
'children' => [
['title' => '分类管理', 'icon' => 'icon-park:graphic-stitching-four', 'url' => '/region-categories'],
['title' => '区域分类', 'icon' => 'icon-park:graphic-stitching-four', 'url' => '/region-categories'],
['title' => '实验田', 'icon' => 'icon-park:freezing-line-column', 'url' => '/regions'],
]
],
['title' => '育秧中心', 'icon' => 'icon-park:lotus', 'url' => '',
'children' => [
['title' => '大棚控制', 'icon' => 'icon-park:link-one', 'url' => 'https://www.baidu.com', 'url_type'=>2],
['title' => '育秧列表', 'icon' => 'icon-park:more-app', 'url' => '/yuyang1'],
['title' => '育秧列表', 'icon' => 'icon-park:more-app', 'url' => '/custom-region'],
]
],
['title' => '实验稻田', 'icon' => 'icon-park:four-leaves', 'url' => '',
'children' => [
['title' => '农机控制', 'icon' => 'icon-park:link-one', 'url' => 'https://www.baidu.com', 'url_type'=>2],
['title' => '稻田列表', 'icon' => 'icon-park:more-app', 'url' => '/daotian2'],
['title' => '稻田列表', 'icon' => 'icon-park:more-app', 'url' => '/custom-region'],
]
],